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.

Configuration reference
| Config ID | modbus_tcp_codec |
| Selected by | app_codec = "modbus_tcp_codec" |
| Platforms | Linux, Windows, Android |
| License | Premium |
Modbus TCP protocol over TCP/IP with MBAP header framing
Modbus TCP uses MBAP header for framing, no CRC required (TCP handles integrity)
| Setting | Key | Type | Default | Notes |
|---|---|---|---|---|
| Unit ID (Slave Address) | unit_id | Integer | 1 | Required |
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
}
}