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

Материал из Wiren Board
(Обновление для соответствия новой версии исходной страницы.)
Строка 2: Строка 2:
<!-- {{DISPLAYTITLE:Управление модулями реле  Wiren Board по протоколу Modbus}} -->
<!-- {{DISPLAYTITLE:Управление модулями реле  Wiren Board по протоколу Modbus}} -->


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


=== 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 ===
=== Безопасный режим ===
 
В этом режиме при прекращении обмена данными по Modbus устройство отключает реле по прошествии заданного времени.  
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 ===
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.
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.
Строка 19: Строка 13:
===Relay operation in case of power failure ===
===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.
Для устройств WB-MR существует возможность запоминать состояние выхода при отключении питания. Режим контролируется Modbus-регистром 6. Если в регистре записано значение '0', то состояние выходов не сохраниться и при подаче питания все реле буду выключены. Если в регистре записана единица, то после возобновления питания все включенные до аварии реле включатся снова.
Этот функционал появился в модулях с прошивкой, начиная с версии 1.5.3.


=== Digital inputs ===
=== Digital inputs ===
Строка 34: Строка 29:
** '''Mapping-matrix''' (see detailed description below)
** '''Mapping-matrix''' (see detailed description below)


<div class="mw-translate-fuzzy">
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 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.
</div>


<div class="mw-translate-fuzzy">
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 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.
</div>


==== Mapping-matrix ====
==== Mapping-matrix ====
Строка 42: Строка 41:
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 ===
= Карта регистров модулей реле =
 
В таблице:
* '''x''' — number of relay outputs;  
* '''x''' — количество релейных выходов;  
* '''y''' is the number of digital inputs.
* '''y''' — количество цифровых входов.
(for modules WB-MRM2 see registers map at the description page of [[WB-MRM2/en|this module]])
Для устаревших модулей WB-MRM2 (не путать с современными WB-MRM2-mini) карту регистров смотрите на отдельной странице [[WB-MRM2]].


<div class="mw-translate-fuzzy">
{| border="1" class="wikitable" style="text-align:center; width:1000px;"
{| border="1" class="wikitable" style="text-align:center; width:1000px;"
!Register / address
!Register / address
Строка 81: Строка 81:
| 8 || holding || RW|| 0 || seconds || safe mode timeout ||
| 8 || holding || RW|| 0 || seconds || safe mode timeout ||
|-
|-
</div>


<div class="mw-translate-fuzzy">
| rowspan="3"  | 9 .. (9+'''x'''-1)  
| rowspan="3"  | 9 .. (9+'''x'''-1)  
| rowspan="3"  | holding  
| rowspan="3"  | holding  
Строка 94: Строка 96:
|
|
|-
|-
</div>




Строка 130: Строка 133:




| 20 .. (20+'''x'''-1) || holdreg || RW || 50 || 0 - 100 || время защиты от дребезга в миллисекундах || Начиная с прошивки 1.13.0
|-




 
<div class="mw-translate-fuzzy">
 
 
 
 
| 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''' ||  
|-
|-
</div>


| 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:
{{:Common_Modbus_Registers}}
<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]].
Регистры настройки параметров обмена данными по RS-485 поддерживаются начиная с прошивки версии 1.6.0

Версия 18:32, 18 апреля 2020

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

Modbus control common

Настройка устройства

Безопасный режим

В этом режиме при прекращении обмена данными по Modbus устройство отключает реле по прошествии заданного времени.

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

Для устройств WB-MR существует возможность запоминать состояние выхода при отключении питания. Режим контролируется Modbus-регистром 6. Если в регистре записано значение '0', то состояние выходов не сохраниться и при подаче питания все реле буду выключены. Если в регистре записана единица, то после возобновления питания все включенные до аварии реле включатся снова. Этот функционал появился в модулях с прошивкой, начиная с версии 1.5.3.

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.

Карта регистров модулей реле

В таблице:

  • x — количество релейных выходов;
  • y — количество цифровых входов.

Для устаревших модулей WB-MRM2 (не путать с современными WB-MRM2-mini) карту регистров смотрите на отдельной странице WB-MRM2.



Внимание: Отображаемое название «Таблица общих регистров» переопределяет ранее заданное отображаемое название «Relay Modules Modbus Management».

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
  • 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 holding RW
  • 0: do not restore relay state after power is restored
  • 1: restore relay state after power is restored
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
  • 0: non-locking buttons
  • 1: switch with lock
  • 3: disable interaction
single digital input interaction mode with corresponding relay output;

"0" should be written in register 5

  • 2: disable all relays when pressed
  • 4: to operate in accordance with the I/O mapping- matrix
  • 5: to operate in accordance with the I/O mapping-matrix, after 20 minutes to re-simulate the input state
Since firmware v.1.9.0
1 Since firmware v.1.12.0
16 holding RW
  • 0: non-locking button
  • 1: switch with lock
  • 3: disable interaction
digital input operating mode 0 to disable all relays
2
  • 2: disable all relays when pressed
  • 4: to operate in accordance with the mapping-matrix
  • 5: to operate in accordance with the mapping-matrix, after 20 minutes to re-simulate the input state
digital input mode 0; register 5 must be set to "0" Since firmware 1.9.0
20 .. (20+x-1) holdreg RW 50 0 - 100 время защиты от дребезга в миллисекундах Начиная с прошивки 1.13.0
32 .. (32+y-1) input R 0 16-bit unsigned int input counter 1 .. y
Параметры подключения, версия прошивки и другие служебные регистры
Адрес Параметры регистра Описание Значения Примечание
Dec Hex Тип Доступ Формат
Параметры подключения
110 0x006E Holding RW u16 Скорость порта RS-485.
Настройка параметров подключения по RS-485
x100, Боды
12 — 1200 бит/с,
24 — 2400 бит/с,
48 — 4800 бит/с,
96 — 9600 бит/с,
192 — 19 200 бит/с,
384 — 38 400 бит/с,
576 — 57 600 бит/с,
1152 — 115 200 бит/с
111 0x006F Holding RW u16 Настройка бита чётности порта RS-485 0 — нет бита чётности (none),
1 — нечётный,
2 — чётный
112 0x0070 Holding RW u16 Количество стоп-битов порта RS-485 1, 2
128 0x0080 Holding RW u16 Modbus-адрес устройства (подробнее)
Модель устройства и версия прошивки
200-205 0x00C8 - 0x00CD Input RO string Модель устройства
206-219 0x00CE - 0x00DB Input RO string Расширение модели устройства. Для чтения модели устройства нужно читать диапазон из 20 регистров (200 - 219) Только с «быстрым Modbus»
220-248 0x00DC - 0x00F8 Input RO string Хэш коммита и название ветки откуда собрана прошивка (2 символа в регистре)
250-265 0x00FA - 0x0109 Input RO string Версия прошивки
266-269 0x010A - 0x010D Input RO u64 Расширение серийного номера
270-271 0x010E - 0x010F Input RO u32 Серийный номер
290-301 0x0122 - 0x012D Holding RO string Сигнатура прошивки
320 0x0140 Input RO u16 Версия прошивки в числовом формате (подробнее) MAJOR Только с «быстрым Modbus»
321 0x0141 MINOR
322 0x0142 PATCH
323 0x0143 s16 SUFFIX
324-325 0x0144 - 0x0145 Input RO u32 Версия прошивки в числовом формате Только с «быстрым Modbus»
326-327 0x0146 - 0x0147 Input RO u32 Версия прошивки в Big Endian формате Только с «быстрым Modbus»
Прочее
104­-105 0x0068 - 0x0069 Input RO u32 Время работы с момента загрузки секунды
120 0x0078 Holding RW u16 Перезагрузка устройства без сохранения состояния любое, отличное от 0 перезагружает устройство
123 0x007B Input RO u16 Напряжение на микроконтроллере мВ
129 0x0081 Holding RW u16 Перевод в режим обновления прошивки на 2 минуты любое, отличное от 0 переводит устройство в режим обновления прошивки
330-336 0x014A - 0x0150 Holding RO string Версия загрузчика
131 0x0083 Holding RW u16 Перевод в режим обновления прошивки на текущих настройках соединения запись 1 переводит устройство в режим обновления прошивки
113 0x0071 Holding RW u16 Время перед отправкой ответа на modbus запрос 0 - 254 мс Только с «быстрым Modbus»
114 0x0072 Holding RW u16 Режим непрерывного чтения регистров с зазором 0 - отключен
1 - включен
2 - включение сохраняется после перезагрузки
Только с «быстрым Modbus»
121 0x0079 Input RO u16 Текущее напряжение питания мВ
125 0x007D Input RO u16 Текущее напряжение питания (без фильтра) мВ
124 0x007C Input RO u16 Внутренняя температура микроконтроллера x0.1, °C

Регистры настройки параметров обмена данными по RS-485 поддерживаются начиная с прошивки версии 1.6.0