Relay Module Modbus Management/en: различия между версиями
Admin (обсуждение | вклад) |
|||
(не показано 13 промежуточных версий 2 участников) | |||
Строка 2: | Строка 2: | ||
<!-- {{DISPLAYTITLE:Управление модулями реле Wiren Board по протоколу Modbus}} --> | <!-- {{DISPLAYTITLE:Управление модулями реле Wiren Board по протоколу Modbus}} --> | ||
== Modbus parameters == | |||
== | === Modbus address === | ||
[[Файл: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 === | ||
Строка 28: | Строка 34: | ||
** '''Mapping-matrix''' (see detailed description below) | ** '''Mapping-matrix''' (see detailed description below) | ||
The mode set separately for each channel. To | 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. | ||
There | 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. | ||
==== Mapping-matrix ==== | ==== Mapping-matrix ==== | ||
Строка 36: | Строка 42: | ||
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 === | ||
* '''x''' — number of relay outputs; | * '''x''' — number of relay outputs; | ||
* '''y''' | * '''y''' is the number of digital inputs. | ||
(for modules WB-MRM2 see registers map at the description page of [[WB-MRM2/en|this module]]) | |||
{| border="1" class="wikitable" style="text-align:center; width:1000px;" | {| border="1" class="wikitable" style="text-align:center; width:1000px;" | ||
Строка 61: | Строка 67: | ||
| 0 | | 0 | ||
| style="text-align:left;" | | | style="text-align:left;" | | ||
* '''0''': buttons without locking | |||
|| | * '''1''': switch with lock | ||
|| | * '''3''': disable interaction | ||
|| 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 | ||
Строка 83: | Строка 90: | ||
* '''1''': switch with lock | * '''1''': switch with lock | ||
* '''3''': disable interaction | * '''3''': disable interaction | ||
| rowspan="3" | | | rowspan="3" | single digital input interaction mode with corresponding relay output; | ||
"0" should be written in register 5 | |||
| | | | ||
|- | |- | ||
Строка 122: | Строка 130: | ||
| | |||
| 32 .. (32+'''y'''-1) || input || R|| 0 || 16-bit unsigned int || input counter 1 .. '''y''' || | |||
|- | |- | ||
| 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]]. | |||
==== Register reading example === | |||
Let's check whether it is true that we are connected to the module of the desired type. (Service wb-mqtt-serial needs to be stopped). At address 200, a unique signature of 6 registers is stored. Let's read 6 registers, starting with the address 200, and convert the received hexadecimal answer into a character string: | |||
<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> | |||
As a result of the command we receive string '''WBMR6'''. The WB-MR6 module in the example has Modbus address 1. | |||
=== External input control type selection === | |||
The relay modules have two modes of relay channel control: via external inputs and via RS-485 Protocol. | |||
In relay modules, you can select mode 0 when a button is connected to the external input (without locking), or mode 1 when a conventional switch (with locking) is used to control. Mode 3 disables external control, but it still retains the ability to control RS-485 and read the status of external inputs. Mode 0 is enabled by default. | |||
In the external control mode, the relay is triggered by the fall of the logic level: the external inputs are connected to the pull-up resistors to the +5V line and the relay of the corresponding channel is triggered when the input is connected to the GND. | |||
The relay status of each channel is stored in the controller memory until reboot, by default, when power is on, all relays are off. After initialization of the module, external inputs are polled and relays of all channels are transferred to the appropriate state. | |||
The type of external control can be selected for each channel separately via 9 — (9+x) registers. To do this, the value 0 must be written in the holding register 5: | |||
<syntaxhighlight lang="bash"> | |||
modbus_client --debug -mrtu -pnone -s2 /dev/ttyAPP1 -a1 -t0x06 -r5 0 | |||
</syntaxhighlight> | |||
To initialize the register at the start and through setup web-interface, see [[RS-485:Configuration_via_Web_Interface/en| RS-485: Configuration via web interface]]. |
Версия 15:27, 16 июля 2019
Modbus parameters
Modbus address
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 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: Register reading and writing function codes.
Safe mode
In this mode, when the Modbus communication is terminated, the device disconnects the relay after a specified time.
To enable Safety timer, you must write a value other than 0 to the storage register with the WRITE_SINGLE_REGISTER command at 8. This value is a timeout in seconds. A value of "0" disables safe mode.
Relay operation in case of power failure
In the latest firmware versions (starting with 1.5.3) for WB-MR devices, it is now possible to remember the output status when power is off. The mode is controlled by the Modbus register 6. If the register is set to '0', the state of the outputs will not be saved and all relays will be switched off when power is supplied. If the entry in the register unit, when the power is resumed everything is included before the crash relay is switched on again.
Digital inputs
The input state can be obtained by reading the Discrete Inputs 0—x registers (where x = (number of managed channels - 1)). If the input is connected to GND, the register value is 1, if not connected - it's 0.
Modes of interaction between digital inputs and relay outputs
You can enable direct control of the relay outputs from the digital inputs in the relay module. There are several options for such management:
- Simple:
- Mode 0: managing switch without detent (click "self-released back"). You press the button (close the digital input with GND), it is "pressed back", the relay state is switched to the opposite.
- Mode 1: switch control with locking. The relay is always set according to the position of the switch. If the switch is "on" (closes the digital input with GND), the relay is also closed. If the switch is "off", the relay is open.
- Mode 3: relay output control from digital input is disabled.
- Complex:
- 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.
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.
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.
Relay module register card
- x — number of relay outputs;
- y is the number of digital inputs.
(for modules WB-MRM2 see registers map at the description page of this module)
Register / address | Type | Read-write | Default | Format | Appointment | Note |
---|---|---|---|---|---|---|
0 .. (x-1) | coil | RW | - | 1 or 0 | relay status with number 1 .. x | |
0 .. (y-1) | discrete | R | - | 1 or 0 | entry status with number 1 .. y | |
5 | holding | RW | 0 |
|
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 | holding | RW |
|
relay operation mode in case of power failure | (only in firmware 1.5.3 and later) | |
8 | holding | RW | 0 | seconds | safe mode timeout | |
9 .. (9+x-1) | holding | RW | 0 |
|
single digital input interaction mode with corresponding relay output;
"0" should be written in register 5 |
|
|
Since firmware v.1.9.0 | |||||
1 | Since firmware v.1.12.0 | |||||
16 | holding | RW |
|
digital input operating mode 0 to disable all relays | ||
2 |
|
digital input mode 0; register 5 must be set to "0" | Since firmware 1.9.0 | |||
32 .. (32+y-1) | input | R | 0 | 16-bit unsigned int | input counter 1 .. y | |
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 bootloader mode | 1.10.0 |
200-205 | holding | R | {'X','X','X','X','X','X'} | device signature (see table below) | ||
220-241 | holding | | | / _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 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:
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 (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:
Module | 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 numberx00timex00 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. Access to the command line is described in SSh.
= Register reading example
Let's check whether it is true that we are connected to the module of the desired type. (Service wb-mqtt-serial needs to be stopped). At address 200, a unique signature of 6 registers is stored. Let's read 6 registers, starting with the address 200, and convert the received hexadecimal answer into a character string:
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'`
As a result of the command we receive string WBMR6. The WB-MR6 module in the example has Modbus address 1.
External input control type selection
The relay modules have two modes of relay channel control: via external inputs and via RS-485 Protocol. In relay modules, you can select mode 0 when a button is connected to the external input (without locking), or mode 1 when a conventional switch (with locking) is used to control. Mode 3 disables external control, but it still retains the ability to control RS-485 and read the status of external inputs. Mode 0 is enabled by default.
In the external control mode, the relay is triggered by the fall of the logic level: the external inputs are connected to the pull-up resistors to the +5V line and the relay of the corresponding channel is triggered when the input is connected to the GND. The relay status of each channel is stored in the controller memory until reboot, by default, when power is on, all relays are off. After initialization of the module, external inputs are polled and relays of all channels are transferred to the appropriate state.
The type of external control can be selected for each channel separately via 9 — (9+x) registers. To do this, the value 0 must be written in the holding register 5:
modbus_client --debug -mrtu -pnone -s2 /dev/ttyAPP1 -a1 -t0x06 -r5 0
To initialize the register at the start and through setup web-interface, see RS-485: Configuration via web interface.