Modbus
SPX Server provides three Modbus components:
modbus_slave— Modbus TCP slave/server based onpymodbusmodbus_tcp— Modbus TCP slave/server based onmodbus-tk(legacy/compat; avoid for new models)modbus_master— Modbus TCP master/client that polls and/or writes bindings
Addressing vocabulary
SPX uses short area codes (the same values appear in spx-examples):
h_r— holding registersi_r— input registersc_o— coilsd_i— discrete inputs
Value codecs commonly used in mappings/bindings:
float,bool,int_16,int_32,uint_16,uint_32,str,raw
Addresses can be a single integer or a [start, end] pair (use a pair for multi-register values like float).
modbus_slave (pymodbus server)
modbus_slave (pymodbus server)YAML key: modbus_slave
Example model (spx-examples): library/domains/iot/generic/energy_meter_iem3000__modbus.yaml
Connectivity simulation:
detach()enters “blackhole” mode (keeps TCP listener, suppresses responses → client timeouts).attach()exits blackhole mode and restarts the server to drop stale connections.
modbus_tcp (modbus-tk server)
modbus_tcp (modbus-tk server)YAML key: modbus_tcp
Legacy adapter:
modbus_tcpexists for backward compatibility. Avoid it for new models; prefermodbus_slavefor Modbus TCP server simulations.
Example model (spx-examples): library/domains/thermal_controllers/generic/thermal_controller__modbus.yaml
Connectivity simulation uses detach() / attach() (removes/re-adds the slave from the shared Modbus master).
modbus_master (client / poller)
modbus_master (client / poller)YAML key: modbus_master
Minimal example:
Notes:
Dependency:
modbus_masterusesmodbus_tk(TcpMaster) under the hood (same family asmodbus_tcp). Ifmodbus_tkis missing, reads/writes will fail.Per-binding
host/port/slave_idlet onemodbus_mastertalk to multiple devices.direction:inbound(read → write attribute),outbound(read attribute → write registers/coils),bidirectional(both). If omitted, SPX defaults toinboundfor polling.
Top-level fields
host/port— default connection target for bindings (defaults:127.0.0.1:502)timeout— per-operation timeout in seconds (default:1.0)poll_interval— default poll interval in seconds (default:0.2)ops_per_cycle— max binding ops per worker cycle (default:16)max_retries/retry_delay— retry policy for one read/write attempt (defaults:1/0.05)max_failures— after this many failures the binding is disabled (default:3)min_poll_interval— lower bound for polling cadence (default:0.05)
Binding fields
Each entry under bindings is a Modbus master binding:
Connection overrides:
host,port,slave_idRegister selection:
area(alias:group),address(int or[start, end]),lengthEncoding:
codec(alias:type),bit_order(alias:byte_order)Attribute mapping:
attribute(shorthand) or explicitread_attribute/write_attributeTiming/stability overrides:
poll_interval,timeout,max_retries,retry_delay,max_failures
Write semantics:
Coils (
area: c_o) and holding registers (area: h_r) are writable.Discrete inputs (
d_i) and input registers (i_r) are read-only (outbound writes will error).Codec/length must match (for example
floatrequireslength: 2;uint_16requireslength: 1).
Last updated

