Modbus RTU
The element allows to get data from MODBUS RTU device and to write data to MODBUS RTU device.
Requests for management:
addvirtual - add a virtual sensor. Extra options are:
- k - user session ID;
- id - the identifier of the element; if the identifier is absent, a new element is created; otherwise the existing one is modified;
- name - the name of the element, the length is not more than 63 characters;
- virtual_type - type of virtual sensor:
- modbus rtu - for reading Modbus data;
- modbus rtu write - for writing Modbus data.
Options for reading Modbus data only (analog virtual sensor):
- vmax - maximum value for the measuring range;
- vmin - minimum value for the measuring range;
- low_alarm - threshold level for notification;
- low_warning - threshold level for notification;
- high_warning - threshold level for notification;
- high_alarm - threshold level for notification;
- hyst_type - the type of algorithm used to calculate the hysteresis:
- disable - the hysteresis is disabled;
- value - hysteresis by the value measured by the sensor value;
- time - hysteresis using time (used by default).
- hyst_value - the value of the deviation of the sensor value when calculating the hysteresis by value, the value with a floating point (minimum 0, maximum 10,000, default 0.3);
- hyst_low_alarm - the time in seconds, during which the sensor should keep its value in this range, for transition of the sensor to this state (minimum 0, maximum 1000, default 1);
- hyst_low_warning - same as previous (default 1);
- hyst_normal - same as previous (default is 0);
- hyst_high_warning - same as previous (default 1);
- hyst_high_alarm - same as previous (default 1).
- expr - expression for calculating the output value, by default "x";
- um - unit of measurement of this element;
- utype - custom type, defines the sensor icon: current, factor, frequency, humidity, power, temperature, vibration, voltage;
Options for Modbus protocol (reading only):
- mb_addr - slave address of device on bus, decimal (1-255);
- mb_reg - register index for modbus function, hexademal string;
- mb_func - function code for modbus:
- Read Coil Status (0x01);
Read Input Status (0x02);
Read Holding Register (0x03);
Read Input Register (0x04).
- mb_type - data type:
16 bits signed int;
16 bits unsigned int;
32 bits signed int;
32 bits unsigned int;
32 bits IEEE 754 floating point.
- mb_order - data ordering:
low byte first, low word first;
low byte first, high word first;
high byte first, low word first;
high byte first, high word first.
- mb_period - the polling period, seconds.
Options for Modbus protocol (writing only):
- mb_addr - slave address of device on bus, decimal (1-255);
- mb_reg - register index for modbus function, hexademal string;
- mb_func - function code for modbus:
- Write Single Coil (0x05);
Write Single Register (0x06).
- mb_wrval - writing value, integer.
If the new element is successfully created, the response is:
<error type="no error" id="213002" /> |
When creating a new sensor (id is not specified), some parameters are mandatory. For reading: name, virtual_type, vmax, vmin, mb_addr, mb_reg, mb_func, mb_type, mb_order, mb_period. For writing: name, virtual_type, mb_addr, mb_reg, mb_func, mb_wrval. The rest of the query parameters are optional, and if not set, they will be set to the default values.
When editing an element, you can change individual fields.
delvirtual - remove the virtual sensor. Extra options:
- k - user session ID;
- id - ID of the element.
getelement - read the element. Extra options are:
- k - the user session ID;
- id - the ID of the item.
Information about the element looks like:
<element id="213003" index="4" module="2009" clas="analog" type="modbus rtu" name="Virtual modbus" state="normal" hwport="99" value="12.1" vmax="110.0" vmin="-55.0" low_alarm="-31.4" low_warning="-27.9" high_warning="35.0" high_alarm="69.7" expr="2.3*x" um="C" hyst_type="value" hyst_low_alarm="1" hyst_low_warning="1" hyst_normal="0" hyst_high_warning="1" hyst_high_alarm="1" hyst_value="0.340" mb_addr="31" mb_reg="00F2" mb_func="4" mb_type="5" mb_order="1" mb_period="30" > |
Modbus RTU configuration
Requests for management:
setmodbus - communication settings of Modbus RTU. Extra options are:
- k - user session ID;
- enable - enable Modbus interface and Modbus RTU virtual sensors (0 by default);
- baud - baud rate of the communication (1200, 2400, 4800, 9600, 19200, 57600, 115200);
- parity - parity check of the communication (none, even, odd);
- stopbit - number of stop bits (1 or 2);
getmodbus - read the communication configuration of Modbus.
- k - the user session ID.
Information about the communication looks like:
<modbus name="Espada USB-RS485" enable="1" baud="9600" parity="none" stopbit="2" /> |
If no hardware support:
<error type="not supported" /> |
Modbus RTU communication test
Requests for management:
testvirtual - communication test of Modbus RTU. Extra options are:
- k - user session ID;
- virtual_type - type of virtual sensor:
- modbus rtu - for reading Modbus data;
- modbus rtu write - for writing Modbus data.
- mb_addr - slave address of device on bus, decimal (1-255);
- mb_reg - register index for modbus function, hexademal string;
- mb_func - function code for modbus:
- Read Coil Status (0x01);
Read Input Status (0x02);
Read Holding Register (0x03);
Read Input Register (0x04);
- Write Single Coil (0x05);
Write Single Register (0x06).
- mb_type - data type (for reading only):
16 bits signed int;
16 bits unsigned int;
32 bits signed int;
32 bits unsigned int;
32 bits IEEE 754 floating point.
- mb_order - data ordering (for reading only):
low byte first, low word first;
low byte first, high word first;
high byte first, low word first;
high byte first, high word first.
- mb_wrval - writing value, integer (for writing only).
Information about the reading test looks like:
<modbusrtu mb_raw_req="1F 04 00 00 00 02" mb_raw_ans="1F 04 04 43 63 55 19" mb_value="227.332413" /> |
If an error occurs, example:
<modbusrtu mb_raw_req="20 04 00 00 00 02" mb_raw_ans="answer error" mb_value="value error"/> |
If no error occurs, the writing test looks like:
<error type="no error" /> |
If Modbus is disabled or not supported:
<error type="disable" /> |