This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
sdk:dio2modbustcp [2015/05/12 09:46] – fachet | sdk:dio2modbustcp [2018/01/24 15:53] (current) – juraschek | ||
---|---|---|---|
Line 3: | Line 3: | ||
/* DESC: This script can be used to access to the digital I/Os via Modbus TCP | /* DESC: This script can be used to access to the digital I/Os via Modbus TCP | ||
* Copyright (C) 2015 NetModule AG, Switzerland | * Copyright (C) 2015 NetModule AG, Switzerland | ||
- | | + | * |
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
| | ||
| | ||
| | ||
| | ||
+ | * | ||
*/ | */ | ||
Line 33: | Line 41: | ||
break; | break; | ||
} | } | ||
- | | + | |
} | } | ||
Line 48: | Line 56: | ||
exit(3); | exit(3); | ||
} | } | ||
+ | |||
cfd = -1; | cfd = -1; | ||
for(;;) { | for(;;) { | ||
Line 63: | Line 72: | ||
} | } | ||
} | } | ||
+ | | ||
if ((r = nb_modbus_receive(cfd)) == NULL) { | if ((r = nb_modbus_receive(cfd)) == NULL) { | ||
printf(" | printf(" | ||
Line 70: | Line 80: | ||
continue; | continue; | ||
} | } | ||
+ | | ||
if (r[6] != SLAVEID) | if (r[6] != SLAVEID) | ||
continue; // not for us | continue; // not for us | ||
+ | | ||
cmd = r[7]; // command | cmd = r[7]; // command | ||
switch (cmd) { // write commands | switch (cmd) { // write commands | ||
Line 80: | Line 92: | ||
continue; // error | continue; // error | ||
break; | break; | ||
- | case 15: | + | case 15: // write to multiple coils |
addr = r[8]<< | addr = r[8]<< | ||
cnt = r[10]<< | cnt = r[10]<< | ||
Line 94: | Line 106: | ||
case 5: // write to a single coil | case 5: // write to a single coil | ||
case 4: // read input register | case 4: // read input register | ||
- | case 15: // write to multiple | + | case 15: // write to multiple |
syst = nb_status(" | syst = nb_status(" | ||
wwan = nb_status(" | wwan = nb_status(" | ||
Line 100: | Line 112: | ||
" | " | ||
" | " | ||
- | " | + | " |
" | " | ||
); | ); |