Integration guide

Connect SimplePLC to an SPX Tank over Modbus TCP

Map SimplePLC holding registers, write the enable signal and verify that an SPX tank fills and drains over Modbus TCP.

Before you begin

Use Docker Desktop in Linux container mode, Docker Compose, PowerShell and a local SPX Product Key. Extract the tank demo ZIP. The verified pair is the SimplePLC 2.0.0 software PLC and SPX Server 1.0.0 from the SPX 1.1.0 stable version set. The verifier uses PyModbus 3.11.4 in the SPX image.

Run the test

1. Start the Modbus variant

With SPX_PRODUCT_KEY set in the current PowerShell session, run this command from the extracted directory:

./run.ps1 -Protocol modbus

To use the environment file created by an existing Windows SPX installation, run this command instead:

$keyFile = "$env:LOCALAPPDATA/SPX/generated/.env"
./run.ps1 -Protocol modbus -ProductKeyEnvFile $keyFile

-Protocol modbus runs only Modbus TCP. Without -Protocol, the runner tests both protocols. The runner starts SimplePLC at plc:502 on the private network, loads tank_modbus.yaml and starts the SPX instance.

2. Watch the automatic read and write

The verifier automatically reads three holding registers starting at offset 0 with FC03, uses FC06 to set offset 0 to 1, then reads the same range again. The PLC program sets the pump command and SPX responds by increasing the simulated level. The readback checks all three values, including the level SPX returns to the PLC.

3. Watch the automatic recovery

The verifier writes 0 to the enable register with FC06. It polls until the pump is off and the level falls, then waits for the 20% baseline. It checks SPX runtime attributes independently through API v3. The runner removes the demo resources on exit.

Check the result

For a successful Modbus-only run, look for PASS modbus: wire read/write, SPX response and cleanup and let the whole command exit without error. The verifier checks the enable write and readback, the pump turning on, a level of at least 25% and a falling level after disabling the pump. The recovered record must show enable=0, pump=0 and level_pct=20. A protocol verification failure produces The demo verification failed. The runner can still report Cleanup failed after a PASS line if Docker cleanup fails.

For comparison, the ZIP’s evidence.log records these FC03 samples from a Windows x86-64 Docker run. The values are ordered as enable, pump and level: [0, 0, 20] before enable, [1, 1, 25] while filling, [0, 0, 24] while draining and [0, 0, 20] at recovery. Your intermediate samples can vary with polling.

Protocol communication

OffsetSignalOwner and direction
0enableThe verifier writes the test input and reads it back.
1pumpSimplePLC calculates the command. SPX reads it.
2level_pctSPX calculates the level and writes it back to SimplePLC.

The endpoint is plc:502, unit ID 1, inside the Compose network. All three registers are single-word UInt16 values. The level has no scale factor. Use the zero-based wire offsets shown above. This lab publishes no Modbus port to the host.

Next steps

See the full tank control loop, run the same process over OPC UA or explore the Modbus TCP simulator.