A Python package for simulating Modbus RTU/ASCII/TCP devices for testing and development purposes.
[](https://opensource.org/licenses/Apache 2.0 )
- Simulate Modbus RTU/ASCII/TCP devices
- Support for all standard Modbus function codes
- Easy-to-use CLI interface
- Programmatic API for integration with tests
- Configurable device behavior
- Docker support for easy deployment
pip install modbusim
git clone https://github.com/yourusername/modbusim.git
cd modbusim
poetry install
# Build the image
docker build -t modbusim .
# Run the Modbus TCP simulator
docker run -p 5020:5020 modbusim
Or using Docker Compose:
docker-compose up -d
Start a Modbus RTU simulator:
modbusim rtu --port /tmp/ptyp0 --baudrate 9600
Start a Modbus TCP simulator:
modbusim tcp --host 0.0.0.0 --port 5020
from modbusim import ModbusSimulator
# Create a simulator instance
simulator = ModbusSimulator(
mode="rtu", # or "tcp"
port="/tmp/ptyp0", # or host="0.0.0.0" for TCP
baudrate=9600
)
# Start the simulator
simulator.start()
try:
# Your test code here
while True:
# Keep the simulator running
pass
except KeyboardInterrupt:
# Stop the simulator
simulator.stop()
make test
make lint # Run linters
make format # Format code
make build # Build the package
make publish # Publish to PyPI
docker-compose -f docker-compose.dev.yml build
docker-compose -f docker-compose.dev.yml run --rm modbusim make test
docker-compose -f docker-compose.dev.yml run --rm --service-ports modbusim bash
Apache 2.0 - See LICENSE for more information.