Skip to main content

Modbus RTU Client/Master Codec

The client (master) side of Modbus RTU, usually on a serial port with an RS-485 adapter. It adds the CRC-16 to every request, checks it on responses, matches each response to its request, labels every field in the message list and decodes registers and coils into values such as modbus_rtu_1:40001 (see Modbus Helpers for the IDs). Exception responses are decoded too.

Send requests with the Modbus RTU message inputs or the modbus_rtu_* Lua helpers. Frames are delimited by bus silence: raise Silent Interval if responses arrive split in two (slow USB adapters, long cables). The codec works over any byte stream, so a transparent serial-to-Ethernet converter can be used through a TCP Client connection.

A serial port connection using the Modbus RTU codec.

Message inputs with ready-made Modbus RTU requests from the example.

Configuration reference​

Config IDmodbus_rtu_codec
Selected byapp_codec = "modbus_rtu_codec"
PlatformsLinux, Windows, Android
LicensePremium

Binary Modbus RTU protocol with automatic append and validate CRC-16 checksums

Modbus RTU will automatically handle CRC-16 checksum calculation when send message and verification when receive message

SettingKeyTypeDefaultNotes
Silent Interval (ms)with_receive_timeoutInteger20Required

Setting details​

Silent Interval (ms)​

Minimum silent interval between frames, typically more than 3.5 character times

Example config​

Default values as they appear in a saved configuration (for example the JSON block at the end of a cycbox/examples/*.lua file). Settings detected at runtime are omitted.

{
"app": {
"app_codec": "modbus_rtu_codec"
},
"modbus_rtu_codec": {
"with_receive_timeout": 20
}
}