Modbus RTU
Modbus RTU is a version of the Modbus protocol that is based on serial communication. Unlike the Modbus TCP protocol, Modbus RTU is typically used to connect sensors, actuators, and other control devices on a factory production line. It is a fast, reliable, and flexible serial communication protocol that provides reliable data transmission and control functions.
For the generic steps, see Create a Southbound Driver and Groups and Tags.
The Modbus RTU protocol uses binary encoding and can transmit data over RS-232, RS-485, or other serial communication media. EMQX Neuron Modbus RTU driver adds an implementation based on Ethernet TCP and enables remote device data acquisition and control through a DTU device.
Add Driver
On Data Collection → South Devices, click Add Device.
- Name: The name of this device node.
- Driver: Select the Modbus RTU driver.
Connection Parameters
Click the driver card to open the Device Configuration page and fill in:
| Parameter | Description |
|---|---|
| Physical Link | Selects the communication medium, either serial or Ethernet. |
| Connection Timeout | The time the system waits for a device to respond to a command. |
| Maximum Retry Times | The maximum number of retries after a failed attempt to send a read command. |
| Retry Interval | Resend reading instruction interval(ms) after a failed attempt to send a read command. |
| Send Interval | The waiting time between sending each read/write command. Some serial devices may discard certain commands if they receive consecutive commands in a short period of time. |
| 4-byte Endianness | Byte order of tags with 32 bits, ABCD corresponds to 1234. |
| 8-byte Endianness | Byte order of tags with 64 bits, with each number representing one byte. |
| Enable 0x16 | Enable or disable the 0x16 function. |
| Start Address | Address starts from 1 or 0. |
| Serial Device | Only needed in Serial mode, the path to the serial device when using a serial connection, e.g., /dev/ttyS0 in Linux systems. |
| Stop Bits | Only for the Serial mode, the serial connection parameter. |
| Parity | Only for the Serial mode, the serial connection parameter. |
| Baud Rate | Only for the Serial mode, the serial connection parameter. |
| Data Bits | Only for the Serial mode, the serial connection parameter. |
| Connection Mode | Only for the Ethernet mode, you can choose EMQX Neuron as the TCP client or server. |
| IP Address | Only for the Ethernet mode, the IP address of the device when using TCP connection with EMQX Neuron as the client, or the IP address of EMQX Neuron when using TCP connection with EMQX Neuron as the server. The default value is 0.0.0.0. |
| Port | Only for the Ethernet mode, the port number of the device when using TCP connection with EMQX Neuron as the client, or the port number of EMQX Neuron when using TCP connection with EMQX Neuron as the server. |
| Device Degradation | Enable or disable device degradation mechanism. |
| Failure Threshold for Degradation | The number of consecutive failure cycles required to trigger device degradation. |
| Recovery Time After Degradation | The time in seconds after which the device recovers from degradation. |
TIP
The above configuration can meet the individualized needs of the device:
- Retry requests are considered as the same request, i.e., a successful retry is regarded as a successful request.
- In the same read cycle, if a certain tag under a slave id does not receive a response, requests for other tags under the same slave id in that cycle will be skipped.
- The device degradation is triggered when a certain tag under a slave id fails to respond for multiple consecutive cycles (or can be configured to trigger after just one failed cycle). Once triggered, all requests for that slave will be stopped for the configured period.
Tag Configuration
The data types and address formats supported by this driver are listed below.
Data Types
- INT16
- UINT16
- INT32
- UINT32
- INT64
- UINT64
- FLOAT
- DOUBLE
- BIT
- STRING
- BYTES
Address Format
SLAVE!ADDRESS[.BIT][#ENDIAN][.LEN[H][L][D][E]][.BYTES]
SLAVE
Required, Slave is the slave address or site number.
ADDRESS
Required, Address is the register address. The Modbus protocol has four areas, each area has a maximum of 65536 registers, and the address range of each area is shown in the table below. In practice a storage area that large is rarely needed: most PLC vendors use addresses below 10000. Enter the address that matches the area and function code of the device.
| Area | Address Range | Attribute | Register Size | Function Code | Data Type |
|---|---|---|---|---|---|
| Coil | 000001 ~ 065536 | Read/Write | 1Bit | 0x01, 0x05, 0x0f | BIT |
| Input | 100001 ~ 165536 | Read | 1Bit | 0x02 | BIT |
| Input Register | 300001 ~ 365536 | Read | 16Bit,2Byte | 0x04 | BIT, INT16, UINT16, INT32, UINT32, INT64, UINT64, FLOAT, DOUBLE, STRING |
| Hold Register | 400001 ~ 465536 | Read/Write | 16Bit,2Byte | 0x03, 0x06, 0x10 | BIT, INT16, UINT16, INT32, UINT32, INT64, UINT64, FLOAT, DOUBLE, STRING |
.BIT
Optional, specify a specific bit in a register.
| Address | Data Type | Description |
|---|---|---|
| 1!300004.0 | bit | Refers to station 1, input register area, address 300004, bit 0 |
| 1!400010.4 | bit | Refers to station 1, hold register area, address 400010, bit 4 |
| 2!400001.15 | bit | Refers to station 2, hold register area, address 400001, bit 15 |
#ENDIAN
Optional, byte order, applicable to data types int16/uint16/int32/uint32/float, see the table below for details.
| Symbol | Byte Order | Supported Data Types | Note |
|---|---|---|---|
| #B | 2,1 | int16/uint16 | |
| #L | 1,2 | int16/uint16 | Default byte order if not specified |
| #LL | 1,2,3,4 | int32/uint32/float | Default byte order if not specified |
| #LB | 2,1,4,3 | int32/uint32/float | |
| #BL | 3,4,1,2 | int32/uint32/float | |
| #BB | 4,3,2,1 | int32/uint32/float |
Byte order also applies to int64/uint64/double data types. Each digit represents one byte. See the following table for detailed information.
| Symbol | Byte Order | Supported Data Types | Note |
|---|---|---|---|
| #LL | 12,34,56,78 | int64/uint64/double | Default byte order if not specified |
| #LB | 21,43,65,87 | int64/uint64/double | |
| #BL | 78,56,34,12 | int64/uint64/double | |
| #BB | 87,65,43,21 | int64/uint64/double |
TIP
The byte order of a tag has a higher priority than the byte order configuration of a node. That is to say, once the byte order is configured for a tag, it follows the configuration of that tag and ignores the node configuration. The byte order can be illustrated using the notation ABCD, which corresponds directly to the sequence 1234. As an example, the ABCD designation represents the standard or default Endianness 1234. (#LL).
.LEN[H][L][D][E]
When the data type is STRING, .LEN is a required field, indicating the number of bytes the string occupies. Each register contains four storage methods: H, L, D, and E, as shown in the table below.
| Symbol | Description |
|---|---|
| H | One register stores two bytes, with the high byte first |
| L | One register stores two bytes, with the low byte first |
| D | One register stores one byte, and it is stored in the low byte |
| E | One register stores one byte, and it is stored in the high byte |
.BYTES
Optional, read and write the length of bytes type data, applicable to bytes data type.
TIP
A register of the Modbus driver contains 2 bytes. When reading and writing Modbus register data in the bytes data type, please ensure that the bytes parameter is set to an even number.
Example Addresses
| Address | Data Type | Description |
|---|---|---|
| 1!300004 | int16 | Refers to station 1, input register area, address 300004, byte order #L |
| 1!300004#B | int16 | Refers to station 1, input register area, address 300004, byte order #B |
| 1!300004#L | uint16 | Refers to station 1, input register area, address 300004, byte order #L |
| 1!400004 | int16 | Refers to station 1, hold register area, address 400004, byte order #L |
| 1!400004#L | int16 | Refers to station 1, hold register area, address 400004, byte order #L |
| 1!400004#B | uint16 | Refers to station 1, hold register area, address 400004, byte order #B |
| 1!300004 | int32 | Refers to station 1, input register area, address 300004, byte order #LL |
| 1!300004#BB | uint32 | Refers to station 1, input register area, address 300004, byte order #BB |
| 1!300004#LB | uint32 | Refers to station 1, input register area, address 300004, byte order #LB |
| 1!300004#BL | float | Refers to station 1, input register area, address 300004, byte order #BL |
| 1!300004#LL | int32 | Refers to station 1, input register area, address 300004, byte order #LL |
| 1!400004 | int32 | Refers to station 1, hold register area, address 400004, byte order #LL |
| 1!400004#LB | uint32 | Refers to station 1, hold register area, address 400004, byte order #LB |
| 1!400004#BB | uint32 | Refers to station 1, hold register area, address 400004, byte order #BB |
| 1!400004#LL | int32 | Refers to station 1, hold register area, address 400004, byte order #LL |
| 1!400004#BL | float | Refers to station 1, hold register area, address 400004, byte order #BL |
| 1!300001.10 | String | Refers to station 1, input register area, address 300001, character length 10, byte order L, which occupies addresses 300001 to 300005 |
| 1!300001.10H | String | Refers to station 1, input register area, address 300001, character length 10, byte order H, which occupies addresses 300001 to 300005 |
| 1!300001.10L | String | Refers to station 1, input register area, address 300001, character length 10, byte order L, which occupies addresses 300001 to 300005 |
| 1!400001.10 | String | Refers to station 1, hold register area, address 400001, character length 10, byte order L, which occupies addresses 400001 to 400005 |
| 1!400001.10H | String | Refers to station 1, hold register area, address 400001, character length 10, byte order H, which occupies addresses 400001 to 400005 |
| 1!400001.10L | String | Refers to station 1, hold register area, address 400001, character length 10, byte order L, which occupies addresses 400001 to 400005 |
| 1!400001.10D | String | Refers to station 1, hold register area, address 300001, character length 10, byte order D, which occupies addresses 400001 to 400005 |
| 1!400001.10E | String | Refers to station 1, hold register area, address 300001, character length 10, byte order E, which occupies addresses 400001 to 400005 |
Use Case
This chapter also provides practical examples to facilitate a quick start.