Перейти к содержанию

Навигация

Relay Module Modbus Management/en: различия между версиями

Нет описания правки
(Новая страница: «== Command-line device management == The Wiren Board controller software includes modbus_client utility to work with devices connected to the RS-485 outputs, via…»)
 
(не показана 21 промежуточная версия 3 участников)
Строка 2: Строка 2:
<!-- {{DISPLAYTITLE:Управление модулями реле  Wiren Board по протоколу Modbus}} -->
<!-- {{DISPLAYTITLE:Управление модулями реле  Wiren Board по протоколу Modbus}} -->


== Modbus parameters ==
{{:Modbus_control_common}}


=== Modbus address ===
== Device Setup ==
[[Файл:modbus_address_mr14.png|150px|thumb|left|Modbus-address set on manufacture]]
Modbus-address of the Wiren Board devices is easy to determine — it is printed on the sticker (the address is in decimal format). The new address of the device is written by the command WRITE_SINGLE_REGISTER to the storage register (holding register) with the address 128 (0x80). For details on how to determine (if the address has been changed) or change the Modbus address of the module, see [[Определение и изменение Modbus-адреса устройств Wirenboard/en|Define and change the Modbus address of Wiren Board devices]].
 
=== Modbus commands supported by the device ===
 
The Wirenboard relay modules support all major Modbus commands. Read more here: [[Протокол_Modbus/en#Register reading and writing function codes|Register reading and writing function codes]].


=== Safe mode ===
=== Safe mode ===
Строка 34: Строка 28:
** '''Mapping-matrix''' (see detailed description below)
** '''Mapping-matrix''' (see detailed description below)


The mode can be set separately for each channel. To do this, register 5 must have a value of "0", and the mode for each channel is written to the storage registers starting from address 9 for the first channel, etc.
The mode set separately for each channel. To select mode, write mode number to corresponding holding register, starting with register 9 for the first channel etc. You should keep default value in register 5.


There is an outdated method - setting the mode for all channels at the same time. To do this, write the appropriate number in the storage register with address 5.
There could be no registers 9 etc. in outdated firmware. You can only set mode for all their channels at once. To do so, write corresponding number to holding register 5.


==== Mapping-matrix ====
==== Mapping-matrix ====
Строка 42: Строка 36:
Starting from firmware v.1.9.0, '''mode 2''' is also provided for individual channels-disable all outputs, and '''operating modes (4 and 5)''' in accordance with the mapping matrix (see below).In this and later versions of firmware versions modules have flexible settings of the interaction of inputs and outputs of relay modules using a special mapping matrix: a table in which for each input is encoded change of any relay output state when the state of this input changes. A detailed description can be found in [[I/O_Mapping_Matrix/en|I/O Mapping Matrix]].
Starting from firmware v.1.9.0, '''mode 2''' is also provided for individual channels-disable all outputs, and '''operating modes (4 and 5)''' in accordance with the mapping matrix (see below).In this and later versions of firmware versions modules have flexible settings of the interaction of inputs and outputs of relay modules using a special mapping matrix: a table in which for each input is encoded change of any relay output state when the state of this input changes. A detailed description can be found in [[I/O_Mapping_Matrix/en|I/O Mapping Matrix]].


=== Relay module register card ===
= Relay module register card =
 
In table:
* '''x''' — number of relay outputs;  
* '''x''' — number of relay outputs;  
* '''y''' is the number of digital inputs.
* '''y''' number of digital inputs.
(for modules WB-MRM2 see registers map at the description page of [[WB-MRM2/en|this module]])
For outdated WB-MRM2 devices (not to be confused with modern WB-MRM2-mini) find register card on separate page [[WB-MRM2]].


{| border="1" class="wikitable" style="text-align:center; width:1000px;"
{| border="1" class="wikitable" style="text-align:center; width:1000px;"
Строка 67: Строка 61:
| 0  
| 0  
| style="text-align:left;" |
| style="text-align:left;" |
* '''0''': buttons without locking
default value should be kept
* '''1''': switch with lock
|| not used in modern firmware.<br>In outdated versions of firmware was used to set mode of interaction of digital inputs with relay outputs for all inputs at once.
* '''3''': disable interaction
|| not used in modern firmware.<br>In outdated versions of firmware was used to set mode of interaction of digital inputs with relay outputs for all inputs at once. Configuration values were the same as now used in registers 9 .. (9+'''x'''-1), but applied to all inputs at once.
|| mode of interaction of digital inputs with relay outputs. The input status registers and the pressure counter continue to operate in all modes. || The register was used in the old configuration mechanism. It is recommended to leave it set to 0 and the inputs are configured via the individual registers 9 .. (9+'''x'''-1)
|-
|-
| 6
| 6
Строка 90: Строка 83:
* '''1''': switch with lock
* '''1''': switch with lock
* '''3''': disable interaction  
* '''3''': disable interaction  
| rowspan="3" | single digital input interaction mode with corresponding relay output;
| rowspan="3" | mode of interaction between digital input and corresponding relay output.<br>There should be default value in register 5   
"0" should be written in register 5   
|
|
|-
|-
Строка 130: Строка 122:




 
| 20 .. (20+'''x'''-1) || holdreg || RW || 50 || 0 - 100 || debouncing time in ms || Since firmware 1.13.0
 
|-
 
 
 




| 32 .. (32+'''y'''-1) || input || R|| 0 || 16-bit unsigned int || input counter 1 .. '''y''' ||  
| 32 .. (32+'''y'''-1) || input || R|| 0 || 16-bit unsigned int || input counter 1 .. '''y''' ||  
|-
|-
 
| 384-447 || holding || RW || 0 || || [[I/O_Mapping_Matrix|Mapping Matrix]] registers || Since firmware 1.9.0  
| 104-105 || input || R|| || 32-bit unsigned int || uptime counter in seconds ||
|-
 
| 120 (0x78) || holding || RW|| 0 || other than 0 || writing to the register causes the module to restart without saving the state ||
|-
| 121 (0x79) || holding || R || - || mV || module current supply voltage ||
|-
| 128 (0x80) || holding || RW|| 1 || 1 — 247
|| Modbus device address ||
|-
| 129 (0x81) || holding || RW|| 0 || 0 or 1 || Go to [[WB-MCU-Flasher|bootloader mode]]
|1.10.0
|-
| 200-205 || holding || R || {'X','X','X','X','X','X'} || || device signature (see table below) ||
|-
| 220-241 || holding || R | | | / _date__ _ _ time__|| firmware build date ||
|-
|250-266
|input
|R
|
|string, null-terminated
|firmware version|| 
|-
|270-271
|input
|R
|
|32-bit unsigned int
|unique identifier (S/N)
|-
| 384-447 || holding || RW|| 0 || || registers [[I/O_Mapping_Matrix/en|mapping-matrix]] || Since firmware version 1.9.0  
|-
|}
|}


In firmware version 1.6.0 and later, additional registers for setting data exchange parameters via RS-485 are supported:
{|  border="1" class="wikitable" style="text-align:center; width:1000px;"
!Register / address
!Type
!Read/write
!Value by default
!Format
!Function
|-
| 110 || holding || RW || 96 ||  baud rate / 100 ||  RS-485 port speed, '''divided by 100'''. Permissible speeds: 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200 <br>([[UART_Communication_Settings/en|UART Communication Settings for Wiren Board devices  ]])
|-
| 111 || holding || RW || 0 || || set the parity bit of the RS-485 port. Valid values: 0 - no parity bit (none), 1 - odd , 2 - even
|-
| 112 || holding || RW || 2 || || umber of stop bits of RS-485 port. Valid values: 1, 2
|-
|}
The 6-byte module signature is stored at address 200. The signature is unique for each model of Wiren Board devices and allows to identify the model by Modbus:
{| class="wikitable"
! style="font-weight: bold;" | Module
! style="font-weight: bold;" | Signature
|-
|WB-MRPS6
|MRPS6
|-
| WB-MR6C
| WBMR6
|-
| WB-MR3xV
| WBMR3
|-
| WB-MR6xV
| WBMR6
|-
| WB-MR14
| WBMR14
|-
| WB-MR11
| WBMR11
|-
| WB-MRM2
| WBMR2
WBMR2m
|}
To get the signature of a device you need to run command READ_HOLDING_REGISTERS at 200 (length of 6 registers). Writing to this area of memory is not supported, and error 3 is returned when attempting to write to an invalid location. Empty spaces in the signature text are clogged with the value 0x00.
Starting from register 220, the firmware build date is recorded, in the format ''number'''x00'''time'''x00''''' as a string (example: 'Jan 27 2017 17:01:13'). The length of the record is 21 registers.
The status value of each relay is stored in flag registers (coil). The 1st relay register address is 0, the 2nd it's 1, etc.
== Command-line device management ==
The Wiren Board controller software includes  modbus_client utility to work with devices connected to the RS-485 outputs, via Modbus Protocol, the detailed description of the command is on the page [[Modbus client/en| Modbus client]]. Access to the command line is described in [[SSH/en| SSh]].
=== Пример чтения регистров ===
Проверим, верно ли, что мы подключились именно к модулю нужного типа. (Сервис wb-mqtt-serial должен быть предварительно остановлен). По адресу 200 хранится уникальная сигнатура длиной в 6 регистров. Прочтем 6 регистров, начиная с адреса 200, и преобразуем полученный шестнадцатеричный ответ в символьную строку:
<syntaxhighlight lang="bash">echo  -e `modbus_client --debug -mrtu -pnone -s2 /dev/ttyAPP1 \
-a1 -t0x03 -r200 -c 6 | \
grep Data | sed -e 's/0x00/\\\x/g' -e 's/Data://' -e 's/\s//g'` </syntaxhighlight>
В результате выполнения команды получаем строку, например '''WBMR6'''. Релейный модуль WB-MR6 имеет Modbus-адрес 1.
=== Выбор типа управления внешними входами ===
В релейных модулях предусмотрено два режима управления каналами реле: с помощью внешних входов и по протоколу RS-485.
В релейных модулях можно выбрать режим 0, когда ко внешнему входу подключена кнопка (без фиксации), или режим 1, когда для управления используется обычный выключатель (с фиксацией). Режим 3 отключает внешнее управление, но при этом все равно сохраняется возможность управления по RS-485 и чтение состояния внешних входов. По умолчанию включен режим 0.


В режиме внешнего управления реле срабатывает по падению логического уровня: к внешним входам подключены резисторы подтяжки к линии +5V и реле соответствующего канала срабатывает при соединении входа с GND.
Состояние реле каждого канала хранится в памяти контроллера до перезагрузки, по умолчанию при включении питания все реле выключены. После инициализации модуля опрашиваются внешние входы и реле всех каналов переводятся в соответствующее состояние.


Тип внешнего управления можно выбрать для каждого канала отдельно через регистры 9 — (9+x). Для этого в holding-регистре 5 должно быть записано значение 0:
{{:Common_Modbus_Registers}}
<syntaxhighlight lang="bash">
modbus_client --debug -mrtu -pnone -s2 /dev/ttyAPP1 -a1 -t0x06 -r5 0
</syntaxhighlight>


Инициализировать регистр при старте можно и через настройки web-интерфейса, смотрите страницу [[RS-485:Настройка_через_веб-интерфейс]].
Registers for setting data exchange parameters for RS-485 are supported since firmware 1.6.0.