Modbus RTU Server/Slave Codec
Simulates a Modbus RTU slave. It answers requests addressed to its Slave ID from an in-memory data store, so you can test a master (a PLC, a gateway, your firmware) without the real device. Use it on a serial port with an RS-485 or USB-UART adapter wired to the master.
The device's data store is set by Initial State, a JSON object with coils, discrete_inputs,
holding_registers and input_registers (address → value). Writes from the client change the store, so the client
reads back what it wrote. An optional effects list makes values move on their own: sine, cosine, triangle,
sawtooth, square, ramp, random_walk, step_sequence, noise, gaussian_noise, offset, scale and
clamp for registers; toggle, pulse, invert and random_bool for coils and discrete inputs. Each effect names
a target and an address (or address_range).
Configuration reference
| Config ID | modbus_rtu_server_codec |
| Selected by | app_codec = "modbus_rtu_server_codec" |
| Platforms | Linux, Windows, Android |
| License | Premium |
Modbus RTU slave/server simulator with configurable data store
Simulates a Modbus RTU slave device, responds to client requests based on internal register/coil state
| Setting | Key | Type | Default | Notes |
|---|---|---|---|---|
| Slave ID | modbus_rtu_server_codec_slave_id | Integer | 1 | Required |
| Silent Interval (ms) | with_receive_timeout | Integer | 20 | Required |
| Initial State (JSON) | modbus_rtu_server_codec_initial_state | Code | see below |
Setting details
Slave ID
Device address 1-247
Silent Interval (ms)
Minimum silent interval between frames, typically more than 3.5 character times
Initial State (JSON)
JSON object with initial values for coils, discrete_inputs, holding_registers, input_registers. Keys are address numbers, values are booleans (coils/discrete) or integers (registers). An optional "effects" array overlays dynamic transforms at read time (sine, cosine, triangle, sawtooth, square, ramp, noise, gaussian_noise, step_sequence, random_walk, offset, scale, clamp for registers; toggle, pulse, invert, random_bool, force for coils/discrete inputs). Each effect item has a "type", "target", and either "address" or "address_range": [lo, hi]. Effects are applied in array order, so listing sine then noise yields a sine wave with random noise on top.
Default:
{
"coils": {
"0": true,
"1": false,
"2": true,
"3": false
},
"discrete_inputs": {
"0": true,
"1": false,
"2": false,
"3": true
},
"holding_registers": {
"0": 100,
"1": 200,
"2": 300,
"3": 400
},
"input_registers": {
"0": 1000,
"1": 2000,
"2": 3000,
"3": 4000
},
"effects": [
{ "type": "sine", "target": "input_registers", "address": 0,
"amplitude": 200, "period_ms": 5000 },
{ "type": "noise", "target": "input_registers", "address": 0, "amplitude": 10 },
{ "type": "toggle", "target": "discrete_inputs", "address": 0, "period_ms": 2000 }
]
}
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_server_codec"
},
"modbus_rtu_server_codec": {
"modbus_rtu_server_codec_slave_id": 1,
"with_receive_timeout": 20,
"modbus_rtu_server_codec_initial_state": "{\n \"coils\": {\n \"0\": true,\n \"1\": false,\n \"2\": true,\n \"3\": false\n },\n \"discrete_inputs\": {\n \"0\": true,\n \"1\": false,\n \"2\": false,\n \"3\": true\n },\n \"holding_registers\": {\n \"0\": 100,\n \"1\": 200,\n \"2\": 300,\n \"3\": 400\n },\n \"input_registers\": {\n \"0\": 1000,\n \"1\": 2000,\n \"2\": 3000,\n \"3\": 4000\n },\n \"effects\": [\n { \"type\": \"sine\", \"target\": \"input_registers\", \"address\": 0,\n \"amplitude\": 200, \"period_ms\": 5000 },\n { \"type\": \"noise\", \"target\": \"input_registers\", \"address\": 0, \"amplitude\": 10 },\n { \"type\": \"toggle\", \"target\": \"discrete_inputs\", \"address\": 0, \"period_ms\": 2000 }\n ]\n}"
}
}