examples/Modbus PLC Simulator/README.md
This project demonstrates Serial Studio's Modbus TCP/RTU connectivity using a physics-based hydraulic test stand simulator. The simulator acts as a Modbus TCP server, providing realistic industrial telemetry data with automatic failure modes and recovery sequences.
This example showcases Serial Studio's Pro feature for Modbus protocol support, including real-time data acquisition, custom frame parsing, and industrial dashboard visualization.
Note: Modbus support requires a Serial Studio Pro license. Visit serial-studio.com for more details.
The simulator models a 50HP hydraulic power unit with the following components:
The simulator automatically cycles through realistic test sequences:
The simulator provides 9 holding registers (function code 0x03) starting at address 0:
| Address | Name | Range | Units | Description |
|---|---|---|---|---|
| HR[0] | E-Stop | 0-1 | - | Emergency stop status (0=Normal, 1=E-Stop) |
| HR[1] | Start LED | 0-1 | - | Motor running indicator (0=Off, 1=Running) |
| HR[2] | Temperature | 72-180 | °F | Hydraulic oil temperature |
| HR[3] | Pressure | 0-3000 | PSI | System pressure (alarm at 2800 PSI) |
| HR[4] | Motor RPM | 0-3600 | RPM | Motor speed |
| HR[5] | Valve Position | 0-100 | % | Control valve opening percentage |
| HR[6] | Flow Rate | 0-500 | GPM×10 | Pump flow rate (divide by 10) |
| HR[7] | Motor Load | 0-100 | % | Motor load percentage |
| HR[8] | Vibration | 0-150 | mm/s×10 | Vibration velocity RMS (divide by 10) |
pip install pymodbus
The simulator supports both pymodbus 3.x and 4.x automatically.
Run the Python script to start the Modbus TCP server:
python3 plc_simulator.py
Expected output:
======================================================================
HYDRAULIC TEST STAND SIMULATOR
======================================================================
Server: 0.0.0.0:5020 | Update: 50ms (20Hz)
Registers (FC03 Holding):
0:E-Stop 1:Start 2:Temp(°F) 3:PSI 4:RPM 5:Valve(%)
6:GPM(÷10) 7:Load(%) 8:Vibration(÷10 mm/s)
Phases: STARTUP → RUNNING → PRESSURE_TEST → (FAILURE → SHUTDOWN)
Flags: E=E-Stop A=Alarm(>2800PSI) F=Failure
======================================================================
[STARTUP ] - R: 0 P: 14 F: 0.0 L: 0 V:0.1 T: 72
[STARTUP ] - R: 180 P: 110 F: 4.8 L:17 V:1.8 T: 72
...
Load the project file:
Modbus PLC Simulator.ssprojConfigure Modbus connection:
ModbusModbus TCP127.0.0.1 (or the IP address of the machine running the simulator)50201Holding Registers (0x03)09100 ms (recommended)Connect:
The included project file (Modbus PLC Simulator.ssproj) provides:
The project includes a comprehensive JavaScript frame parser that:
The parser is embedded in the .ssproj file and requires Binary (Direct) decoder mode.
The simulator includes realistic failure sequences that occur randomly (~0.02% probability per update):
To force a failure for testing, modify the FAILURE_PROBABILITY constant in plc_simulator.py (set to 0.1 for ~10% chance).
SERVER_PORT constant)Serial Studio supports multi-group mode for polling non-contiguous register ranges. To poll specific registers:
This simulator can be used as a template for connecting to real industrial PLCs:
Problem: Serial Studio shows "Connection Failed"
python3 plc_simulator.py)Problem: No data updates in Serial Studio
Problem: Erratic readings or NaN values
This example is dual-licensed under GPL-3.0 and the Serial Studio Commercial License.
For more information about Serial Studio and Modbus integration, visit the Serial Studio documentation.