powering up…
powering up…
powering up…
Try these in order:
Break something:
The live demo could not start here.
This is what it looks like. Everything below works the same with pip install modbus-sim.
What you just used
Every command above became a real Modbus TCP frame (the tx and rx lines)
and went through the same code that answers on a network port. modbus-sim normally runs on your
laptop or in CI and speaks Modbus TCP, RTU over TCP and RTU on a serial line. The devices
behave: the meter's counters count, the controller heats towards its set point, the inverter
follows the sun. And they keep the details that break integrations: word order, scale factors,
gaps in the map, write protection, exception codes.
The three profiles follow public documentation: the Eastron SDM630 Modbus protocol, Omron's E5CC communications manual and the SunSpec model definitions. Where they simplify, the README says so.
The same thing from Python
pip install modbus-sim
modbus-sim serve --bench real-devices.yaml # the bench from this page
from pymodbus.client import ModbusTcpClient
c = ModbusTcpClient("127.0.0.1", port=5020)
c.connect()
r = c.read_input_registers(0, count=2, device_id=1) # SDM630: L1 voltage
print(c.convert_from_registers(r.registers, c.DATATYPE.FLOAT32)) # 230.1
r = c.write_register(0x2103, 1500, device_id=2) # E5CC: set point 150.0
print(r.exception_code) # 4: writing is off
c.write_register(0x0000, 0x0001, device_id=2) # communications writing on
c.write_register(0x2103, 1500, device_id=2) # now it works
The bench file is examples/real-devices.yaml.
What else it does
- Fault injection from tests or a control port: no answer, late answers, exceptions, bad CRC, wrong transaction or unit ID, truncated frames, dropped connections, drifting values, device faults.
- pytest plugin: the
modbus_benchfixture starts devices for a test run. - Your own devices from a YAML file: points in all four tables, 16/32/64-bit integers,
floats and strings, word order, scale, limits, signal sources.
modbus-sim mapprints the register map. - Profiles: Eastron SDM630 · Omron E5CC · SunSpec inverter (models 1 + 103), plus an invented energy meter, temperature controller and frequency converter.