12 063
правки
(Новая страница: «In older firmware versions <syntaxhighlight lang="bash">| xxd -r -p</syntaxhighlight> wasn't necessary») |
(Новая страница: «More detailed description of the request and response data structure can be found on the Modbus Protocol page.») |
||
(не показано 9 промежуточных версий этого же участника) | |||
Строка 124: | Строка 124: | ||
---- | ---- | ||
4. | 4. Determine the current address of the device connected to the Wiren Board. The address is unknown to us and we do not want to change it. To do this, at the command line, run a cyclic command to poll the register of 0x80 devices with addresses from 1 to 247: | ||
<syntaxhighlight lang="bash">root@wirenboard:~# for i in {1..247}; do modbus_client -mrtu /dev/ttyAPP1 --debug -a$i -t3 -r0x80 -s2 -pnone; done 2>/dev/null | grep Data: </syntaxhighlight> | <syntaxhighlight lang="bash">root@wirenboard:~# for i in {1..247}; do modbus_client -mrtu /dev/ttyAPP1 --debug -a$i -t3 -r0x80 -s2 -pnone; done 2>/dev/null | grep Data: </syntaxhighlight> | ||
Answer | |||
<syntaxhighlight lang="bash"> Data: 0x0072</syntaxhighlight> | <syntaxhighlight lang="bash"> Data: 0x0072</syntaxhighlight> | ||
Result: the address of the connected device is 0x0072, i.e. 114. It takes a little more than 2 minutes to search all addresses from 1 to 247. | |||
---- | ---- | ||
5. | 5.5. Let's turn on relay 6 on WB-MR14 relay module(addresses of flags registers start from zero, remember that!). Use the command 0x05 (Write Single Coil): | ||
<syntaxhighlight lang="bash">modbus_client --debug -mrtu -pnone -s2 /dev/ttyAPP1 -a1 -t0x05 -r0x05 0x01</syntaxhighlight> | <syntaxhighlight lang="bash">modbus_client --debug -mrtu -pnone -s2 /dev/ttyAPP1 -a1 -t0x05 -r0x05 0x01</syntaxhighlight> | ||
Answer: | |||
<syntaxhighlight lang="bash">Data to write: 0x1 | <syntaxhighlight lang="bash">Data to write: 0x1 | ||
Opening /dev/ttyAPP1 at 9600 bauds (N, 8, 2) | Opening /dev/ttyAPP1 at 9600 bauds (N, 8, 2) | ||
Строка 142: | Строка 141: | ||
SUCCESS: written 1 elements!</syntaxhighlight> | SUCCESS: written 1 elements!</syntaxhighlight> | ||
Note that the modbus_client utility replaced 1 with 0x00FF when recording, because this value is used to turn on the relay. Any nonzero value is changed to 0x00FF, give it a try. | |||
---- | ---- | ||
6. | 6. Turn on all the odd relays and turn off all the even ones. To do this, use the function 15 (Write Multiple Coils). There are only 14 relays in the module, so we have to pass values for 14 registers from 0 to 13. | ||
<syntaxhighlight lang="bash">modbus_client --debug -mrtu -pnone -s2 /dev/ttyAPP1 -a1 -t0x0f -r0x00 -c 14 0x00FF 0x0000 0x00FF 0x0000 0x00FF 0x0000 0x00FF 0x0000 0x00FF 0x0000 0x00FF 0x0000 0x00FF 0x0000</syntaxhighlight> | <syntaxhighlight lang="bash">modbus_client --debug -mrtu -pnone -s2 /dev/ttyAPP1 -a1 -t0x0f -r0x00 -c 14 0x00FF 0x0000 0x00FF 0x0000 0x00FF 0x0000 0x00FF 0x0000 0x00FF 0x0000 0x00FF 0x0000 0x00FF 0x0000</syntaxhighlight> | ||
Answer: | |||
<syntaxhighlight lang="bash">Data to write: 0xff 0x00 0xff 0x00 0xff 0x00 0xff 0x00 0xff 0x00 0xff 0x00 0xff 0x00 | <syntaxhighlight lang="bash">Data to write: 0xff 0x00 0xff 0x00 0xff 0x00 0xff 0x00 0xff 0x00 0xff 0x00 0xff 0x00 | ||
Opening /dev/ttyAPP1 at 9600 bauds (N, 8, 2) | Opening /dev/ttyAPP1 at 9600 bauds (N, 8, 2) | ||
Строка 157: | Строка 156: | ||
Note the structure of the query data: | |||
*[01] — | *[01] — address | ||
*[0F] — | *[0F] — write Multiple Coils function code | ||
*[00][00] — | *[00][00] — address of the first flag register to be recorded | ||
*[00][0E] — | *[00][0E] — number of items to record (14) | ||
*[02] — | *[02] — number of data bytes (14 bits are placed in 2 bytes) | ||
*[55][15] — 01010101 00010101 ( | *[55][15] — 01010101 00010101 (the first relay is the lowest bit of the first byte, 8th relay is the highest bit of the first byte, 9th relay is the lowest bit of the second byte) | ||
*[1A][97] — CRC16 | *[1A][97] — CRC16 | ||
As well as note the structure of the answer: | |||
*<01> — | *<01> — address | ||
*<0F> — | *<0F> — write Multiple Coils function code | ||
*<00><00> — | *<00><00> — address of the first flag register to be recorded | ||
*<00><0E> — | *<00><0E> — number of recorded flag registers | ||
*<D4><0F> — CRC16 | *<D4><0F> — CRC16 | ||
More detailed description of the request and response data structure can be found on the [[Протокол Modbus/en|Modbus Protocol]] page. |
правки