Wiren Board Device Modbus Address/en: различия между версиями

Материал из Wiren Board
(Новая страница: «Modbus address of the Wiren Board devices is printed on the label (the address is in decimal format). If the device has already been in use and its address has be…»)
м (FuzzyBot переименовал страницу Определение и изменение Modbus-адреса устройств Wirenboard/en в Wiren Board Device Modbus Address/en без оставления перенаправления: Часть переводимой страницы Определение и изменение Modbus-адреса устройств Wirenboard.)
 
(не показано 7 промежуточных версий 1 участника)
Строка 1: Строка 1:
<languages/>
<languages/>
See also[[UART_Communication_Settings/en|UART_Communication_Settings]].
See also [[UART_Communication_Settings/en|UART_Communication_Settings]].


== Сurrent Modbus address resolution ==
== Сurrent Modbus address resolution ==


Modbus address of the Wiren Board devices is printed on the label (the address is in decimal format). If the device has already been in use and its address has been changed, the address must be found in some way. The Wiren Board controller software includes the modbus_client utility to work with devices connected to RS-485 outputs via the Modbus Protocol (the Modbus address of the Wiren Board devices is stored in the 0x80 register). Help on the command can be obtained by running it without any parameters, a detailed description is on the  [[Modbus-client/en|Modbus-client]]. Access to the command line is described in the SSH article.
Modbus address of the Wiren Board devices is printed on the label (the address is in decimal format). If the device has already been in use and its address has been changed, the address must be found in some way. The Wiren Board controller software includes the modbus_client utility to work with devices connected to RS-485 outputs via the Modbus Protocol (the Modbus address of the Wiren Board devices is stored in the 0x80 register). Help on the command can be obtained by running it without any parameters, a detailed description is on the  [[Modbus-client/en|Modbus-client]]. Access to the command line is described in the [[SSH/en|SSH]] article.
[[Файл:modbus_address_mr14.png|150px|thumb|left|The Modbus address set by manufacturer]]
'''Stop the wb-mqtt-serial driver before working with the port from the command line:'''


<syntaxhighlight lang="bash">root@wirenboard:~# service wb-mqtt-serial stop</syntaxhighlight>
<syntaxhighlight lang="bash">root@wirenboard:~# service wb-mqtt-serial stop</syntaxhighlight>
Попробуем определить текущий адрес модуля. Для этого в командной строке выполним циклическую команду опроса регистра 0x80 устройств с адресами с 1 по 247:
Let's try to determine the current address of the module. 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 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:       
         Data: 0x0072</syntaxhighlight>
         Data: 0x0072</syntaxhighlight>
Результат: адрес подключенного устройства — 0x0072, то есть 114. Перебор всех адресов от 1 до 247 занимает чуть больше 2 минут. В параметрах вызова команды modbus_client мы указываем 2 стоп-бита( -s2), отсутствие контроля четности ( -pnone), скорость 9600 бит/с устанавливается автоматически. Чтение выполняем командой READ_HOLDING_REGISTERS с кодом 3 (-t3) из регистра с адресом 0x80 ( -r0x80), адрес меняется в цикле от 1 до 247 ( -a$i).
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. In the parameters of the modbus_client command call, we specify 2 stop bits( -s2), no parity ( -pnone), the speed of 9600 bit/s is set automatically. Read the command READ_HOLDING_REGISTERS with code 3 (-t3) from the register with the address 0x80 ( -r0x80), the address changes in the cycle from 1 to 247 ( -a$i). On some devices, the led blinks when communicating with them.
На некоторых устройствах при обмене с ними данными мигает индикатор.
[[Файл:Status_flash_mr14.gif|300px|thumb|left|Status led blinks when communication via RS-485 module WB-MR14]]
[[Файл:Status_flash_mr14.gif|300px|thumb|left|Светодиод Status мигает при обмене данными по RS-485 с модулем WB-MR14]]




== Изменение Modbus-адреса ==
== Modbus address change ==


Мы можем задать устройству адрес, который нам необходим (например, 1), командой
We can set the device address we need (for example, 1) with the command
<syntaxhighlight lang="bash">root@wirenboard:~# modbus_client --debug -mrtu -pnone -s2 /dev/ttyAPP1 -a0 -t0x06 -r0x80 1</syntaxhighlight>
<syntaxhighlight lang="bash">root@wirenboard:~# modbus_client --debug -mrtu -pnone -s2 /dev/ttyAPP1 -a0 -t0x06 -r0x80 1</syntaxhighlight>
Для записи адреса мы используем широковещательный адрес 0 ( -a0) и Modbus RTU-команду WRITE_SINGLE_REGISTER с кодом 6 ( -t0x06). В регистр 0x80 ( -r0x80) мы записываем значение 1.  
We use the broadcast address 0 ( -a0) and Modbus RTU command WRITE_SINGLE_REGISTER with code 6 ( -t0x06) to write the address. In register 0x80 ( -r0x80) we write the value 1.  


'''Использование адреса 0 сбросит все адреса всем устройствам на шине! Никогда не используете эту команду, если к порту RS-485 подключено больше одного устройства!'''
'''Using address 0 will reset all addresses to all devices on the bus! Never use this command if more than one device is connected to the RS-485 port!'''


<syntaxhighlight lang="bash">root@wirenboard:~# modbus_client --debug -mrtu -pnone -s2 /dev/ttyAPP1 -a0 -t0x06 -r0x80 1
<syntaxhighlight lang="bash">root@wirenboard:~# modbus_client --debug -mrtu -pnone -s2 /dev/ttyAPP1 -a0 -t0x06 -r0x80 1
Строка 31: Строка 32:
ERROR occured!
ERROR occured!
</syntaxhighlight>
</syntaxhighlight>
Сообщение об ошибке не должно пугать: устройства Modbus не отвечают на команды, отправленные на широковещательный адрес. Проверим, сохранился ли адрес в адресном регистре:
The error message should not be frightening: Modbus devices do not respond to commands sent to the broadcast address. Check if the address is still in the address register:
<syntaxhighlight lang="bash">root@wirenboard:~# modbus_client --debug -mrtu -pnone -s2 /dev/ttyAPP1 -a1 -t0x03 -r0x80  
<syntaxhighlight lang="bash">root@wirenboard:~# modbus_client --debug -mrtu -pnone -s2 /dev/ttyAPP1 -a1 -t0x03 -r0x80  
Opening /dev/ttyAPP1 at 9600 bauds (N, 8, 2)
Opening /dev/ttyAPP1 at 9600 bauds (N, 8, 2)
Строка 40: Строка 41:
         Data: 0x0001  
         Data: 0x0001  
</syntaxhighlight>
</syntaxhighlight>
Отлично, устройство с адресом 0x01 при чтении регистра 0x80 вернуло значение 1 (мы помним, что один регистр хранит два восьмибитных значения, поэтому вывод команды содержит четыре шестнадцатеричных цифры: 0x0001). Желтый светодиод снова моргнул при обращении к устройству.
Fine, the device with address 0x01 returned value 1 when reading register 0x80 (we remember that one register stores two eight-bit values, so the output of the command contains four hexadecimal digits: 0x0001). The yellow led blinked again when referring to the device.

Текущая версия на 16:50, 27 мая 2021

Другие языки:

See also UART_Communication_Settings.

Сurrent Modbus address resolution

Modbus address of the Wiren Board devices is printed on the label (the address is in decimal format). If the device has already been in use and its address has been changed, the address must be found in some way. The Wiren Board controller software includes the modbus_client utility to work with devices connected to RS-485 outputs via the Modbus Protocol (the Modbus address of the Wiren Board devices is stored in the 0x80 register). Help on the command can be obtained by running it without any parameters, a detailed description is on the Modbus-client. Access to the command line is described in the SSH article.

The Modbus address set by manufacturer

Stop the wb-mqtt-serial driver before working with the port from the command line:

root@wirenboard:~# service wb-mqtt-serial stop

Let's try to determine the current address of the module. To do this, at the command line, run a cyclic command to poll the register of 0x80 devices with addresses from 1 to 247:

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:      
        Data: 0x0072

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. In the parameters of the modbus_client command call, we specify 2 stop bits( -s2), no parity ( -pnone), the speed of 9600 bit/s is set automatically. Read the command READ_HOLDING_REGISTERS with code 3 (-t3) from the register with the address 0x80 ( -r0x80), the address changes in the cycle from 1 to 247 ( -a$i). On some devices, the led blinks when communicating with them.

Status led blinks when communication via RS-485 module WB-MR14


Modbus address change

We can set the device address we need (for example, 1) with the command

root@wirenboard:~# modbus_client --debug -mrtu -pnone -s2 /dev/ttyAPP1 -a0 -t0x06 -r0x80 1

We use the broadcast address 0 ( -a0) and Modbus RTU command WRITE_SINGLE_REGISTER with code 6 ( -t0x06) to write the address. In register 0x80 ( -r0x80) we write the value 1.

Using address 0 will reset all addresses to all devices on the bus! Never use this command if more than one device is connected to the RS-485 port!

root@wirenboard:~# modbus_client --debug -mrtu -pnone -s2 /dev/ttyAPP1 -a0 -t0x06 -r0x80 1
Data to write: 0x1
Opening /dev/ttyAPP1 at 9600 bauds (N, 8, 2)
[00][06][00][80][00][01][48][33]
Waiting for a confirmation...
ERROR Connection timed out: select
ERROR occured!

The error message should not be frightening: Modbus devices do not respond to commands sent to the broadcast address. Check if the address is still in the address register:

root@wirenboard:~# modbus_client --debug -mrtu -pnone -s2 /dev/ttyAPP1 -a1 -t0x03 -r0x80 
Opening /dev/ttyAPP1 at 9600 bauds (N, 8, 2)
[01][03][00][80][00][01][85][E2]
Waiting for a confirmation...
<01><03><02><00><01><79><84>
SUCCESS: read 1 of elements:
        Data: 0x0001

Fine, the device with address 0x01 returned value 1 when reading register 0x80 (we remember that one register stores two eight-bit values, so the output of the command contains four hexadecimal digits: 0x0001). The yellow led blinked again when referring to the device.