Modbus Simulator Guide
About
The Modbus Simulator is a Modbus Server that can be used as an endpoint for testing communication with the Modbus Device Service Component.
Running
Environment Variables
As the simulator can run in either TCP or RTU modes, an environment variable, RUN_MODE
must be set to specify which mode to run in.
Option | Expected Values | Description |
---|---|---|
RUN_MODE | TCP / RTU | Controls whether the simulator will run as a TCP or RTU device |
Note
If this is not set, the device will default to TCP
Downloading the Simulator
docker pull iotechsys/modbus-sim:1.0
Running the simulator
To run the TCP simulator:
docker run --rm --name modbus-sim iotechsys/modbus-sim:1.0
Alternatively, if you want to run the RTU variant in a dockerized format, use the following command instead:
docker run --rm --name modbus-sim -e RUN_MODE=RTU iotechsys/modbus-sim:1.0
Stopping the simulator
docker stop modbus-sim
Networking Configuration
TCP
If the TCP version of the simulator is being run on a separate host from the Modbus device service, the following flag must be included in the docker run command:
--network=host
If the TCP version simulator is running on the same host as the Modbus device service, run the simulator as instructed. Once running find the IP of the docker container with the following command:
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' modbus-sim
Using this IP, set the device address in the relevant device file.
RTU
To connect to the RTU version of the simulator on the same host as the Modbus device service, run the simulator as instructed. Once running find the IP of the docker container with the following command:
MODBUS_SIM_ADDRESS=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' modbus-sim)
With socat
, create a serial connection to the container using its IP and set the port to /tmp/virtualport
(socat pty,link=/tmp/virtualport,raw,echo=0 tcp:${MODBUS_SIM_ADDRESS}:50103) &
/tmp/virtualport
to make it reachable in conjunction with the above socat command.