Modbus RTU

The simulator can talk SunSpec over a real serial line (Modbus RTU) in addition to (or instead of) the TCP server. Use this when your test harness is a vendor gateway, a serial-to-TCP bridge, or any hardware that talks to DERs over RS-485.

CLI flag reference

Flag Default Notes
-rtu / --rtu_enable no Set to yes to bring up the RTU interface
--rtu_port COM10 Serial device path. Windows COM3, Linux /dev/ttyUSB0, virtual PTY /dev/pts/3
--rtu_baud 9600 Baud rate. Common SunSpec values: 9600, 19200, 38400, 57600, 115200
--rtu_parity N N (none), E (even), O (odd)
--rtu_stopbits 1 1 or 2

RTU and TCP can run together — --mb_enable yes --rtu_enable yes exposes the same SunSpec model set on both transports.

Lab setups

There are three common ways to drive the RTU interface in a lab.

Real hardware via USB-to-RS-485

The straightforward case — a USB-to-RS-485 adapter plugged into the host, an external SunSpec client wired to the other end.

./sim --device_type PV-3Phase \
      --rtu_enable yes \
      --rtu_port /dev/ttyUSB0 \
      --rtu_baud 19200 \
      --rtu_parity E

The serial parameters have to match what your client is configured for; RTU has no auto-negotiation.

Virtual PTY pair via socat

For host-only testing without serial hardware, pair two pseudo-TTYs with socat and run the simulator against one end:

socat -d -d pty,raw,echo=0,link=/tmp/dersim-rtu \
            pty,raw,echo=0,link=/tmp/client-rtu &
./sim --device_type PV-3Phase \
      --rtu_enable yes \
      --rtu_port /tmp/dersim-rtu \
      --rtu_baud 9600

Your SunSpec client connects to /tmp/client-rtu and the simulator sees its writes at /tmp/dersim-rtu. The make run-rtu target in the dersim repo wraps this pattern with a Docker container.

Multi-drop bus simulation

RS-485 supports multiple devices on one bus, each addressed by a unique unit ID. The simulator's -N COUNT flag spins up COUNT DERs in one process; each gets its own unit ID starting at 1. With a single shared serial port you get a multi-drop bus that test harnesses can poll device-by-device.

./sim --device_type PV-3Phase -N 4 \
      --rtu_enable yes \
      --rtu_port /dev/ttyUSB0

A SunSpec scanner walking unit IDs 1..4 sees four distinct DERs with their own nameplates, energy registers, and grid-support state. Useful for testing aggregator software that's supposed to discover devices on a bus.

Stopping cleanly

The RTU interface holds the serial port open exclusively. When you stop the simulator (Ctrl-C or via the dashboard's Stop button), it releases the port within ~1 s. Running make stop-rtu in the dersim repo tears down the socat PTY pair too.

Limitations

  • No TLS on RTU. Modbus RTU has no encryption analog to Secure SunSpec Modbus TCP. If you need encryption, use TCP.
  • No byte-level injection. The simulator emits well-formed SunSpec frames; for fuzz-testing the wire protocol use a separate serial fuzzer talking to a loopback bus.
  • One bus per process. A second --rtu_enable yes invocation on the same port fails with "device or resource busy" — use -N COUNT to multiplex within a single process instead.