Relay Module Modbus Management/en: различия между версиями
(Новая страница: «{| border="1" class="wikitable" style="text-align:center; width:1000px;" !Register / address !Type !Read/write !Value by default !Format !Function |- | 110 || h…») |
(Новая страница: «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:») |
||
Строка 195: | Строка 195: | ||
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" | {| class="wikitable" |
Версия 14:49, 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:
Модуль | Сигнатура |
---|---|
WB-MRPS6 | MRPS6 |
WB-MR6C | WBMR6 |
WB-MR3xV | WBMR3 |
WB-MR6xV | WBMR6 |
WB-MR14 | WBMR14 |
WB-MR11 | WBMR11 |
WB-MRM2 | WBMR2
WBMR2m |
Для получения сигнатуры нужно выполнить команду READ_HOLDING_REGISTERS по адресу 200 (длина 6 регистров). Запись в эту область памяти не поддерживается, при попытке записи в недопустимое место возвращается ошибка 3. Пустые места в тексте сигнатуры забиваются значением 0x00. Начиная с регистра 220 записана дата сборки прошивки, в формате "числоx00времяx00" в виде строки (пример: 'Jan 27 2017 17:01:13'). Длина записи — 21 регистр.
Значение состояния каждого реле хранится в регистрах флагов (coil). У 1-го реле адрес регистра 0, у 2-го — 1 и т.д.
Управление модулем из командной строки
Программное обеспечение контроллера Wiren Board включает в себя утилиту modbus_client для работы с устройствами, подключенными к выходам RS-485, по протоколу Modbus, подробное описание команды находится на странице Modbus-client. Доступ к командной строке описан в статье SSH.
Пример чтения регистров
Проверим, верно ли, что мы подключились именно к модулю нужного типа. (Сервис wb-mqtt-serial должен быть предварительно остановлен). По адресу 200 хранится уникальная сигнатура длиной в 6 регистров. Прочтем 6 регистров, начиная с адреса 200, и преобразуем полученный шестнадцатеричный ответ в символьную строку:
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'`
В результате выполнения команды получаем строку, например WBMR6. Релейный модуль WB-MR6 имеет Modbus-адрес 1.
Выбор типа управления внешними входами
В релейных модулях предусмотрено два режима управления каналами реле: с помощью внешних входов и по протоколу RS-485. В релейных модулях можно выбрать режим 0, когда ко внешнему входу подключена кнопка (без фиксации), или режим 1, когда для управления используется обычный выключатель (с фиксацией). Режим 3 отключает внешнее управление, но при этом все равно сохраняется возможность управления по RS-485 и чтение состояния внешних входов. По умолчанию включен режим 0.
В режиме внешнего управления реле срабатывает по падению логического уровня: к внешним входам подключены резисторы подтяжки к линии +5V и реле соответствующего канала срабатывает при соединении входа с GND. Состояние реле каждого канала хранится в памяти контроллера до перезагрузки, по умолчанию при включении питания все реле выключены. После инициализации модуля опрашиваются внешние входы и реле всех каналов переводятся в соответствующее состояние.
Тип внешнего управления можно выбрать для каждого канала отдельно через регистры 9 — (9+x). Для этого в holding-регистре 5 должно быть записано значение 0:
modbus_client --debug -mrtu -pnone -s2 /dev/ttyAPP1 -a1 -t0x06 -r5 0
Инициализировать регистр при старте можно и через настройки web-интерфейса, смотрите страницу RS-485:Настройка_через_веб-интерфейс.