Skip to main content

Modbus TCP Client/Master Codec

The client (master) side of Modbus TCP, used with a TCP Client connection to a device or gateway (port 502 by default on most devices). It adds the MBAP header with transaction ID and the configured Unit ID, matches responses to requests, labels every field and decodes registers and coils into values such as modbus_tcp_1:30001 (see Modbus Helpers).

Send requests with the Modbus TCP message inputs or the modbus_tcp_* Lua helpers. To try it without a device, load cycbox/examples/modbus_tcp_loopback_demo.lua: it pairs this codec with a simulated device from the Modbus TCP Server codec on the same computer.

A TCP client connection to 127.0.0.1:1502 using the Modbus TCP codec.

Configuration reference​

Config IDmodbus_tcp_codec
Selected byapp_codec = "modbus_tcp_codec"
PlatformsLinux, Windows, Android
LicensePremium

Modbus TCP protocol over TCP/IP with MBAP header framing

Modbus TCP uses MBAP header for framing, no CRC required (TCP handles integrity)

SettingKeyTypeDefaultNotes
Unit ID (Slave Address)unit_idInteger1Required

Setting details​

Unit ID (Slave Address)​

Device address 0-247 (typically 1 for single slave, 255 for broadcast)

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_tcp_codec"
},
"modbus_tcp_codec": {
"unit_id": 1
}
}