https://github.com/pyfunc/modbusim
MODBUS PORT SIMULATOR
https://github.com/pyfunc/modbusim
Last synced: 8 months ago
JSON representation
MODBUS PORT SIMULATOR
- Host: GitHub
- URL: https://github.com/pyfunc/modbusim
- Owner: pyfunc
- License: apache-2.0
- Created: 2025-08-01T08:17:24.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-08-01T09:41:35.000Z (8 months ago)
- Last Synced: 2025-08-01T10:49:48.914Z (8 months ago)
- Language: Python
- Size: 20.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# ModbusIM - Modbus Device Simulator
A Python package for simulating Modbus RTU/ASCII/TCP devices for testing and development purposes.
[](https://badge.fury.io/py/modbusim)
[](https://www.python.org/downloads/)
[](https://opensource.org/licenses/Apache 2.0 )
## Features
- 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
## Installation
### Using pip
```bash
pip install modbusim
```
### Using Poetry (for development)
```bash
git clone https://github.com/yourusername/modbusim.git
cd modbusim
poetry install
```
### Using Docker
```bash
# Build the image
docker build -t modbusim .
# Run the Modbus TCP simulator
docker run -p 5020:5020 modbusim
```
Or using Docker Compose:
```bash
docker-compose up -d
```
## Usage
### Command Line Interface
Start a Modbus RTU simulator:
```bash
modbusim rtu --port /tmp/ptyp0 --baudrate 9600
```
Start a Modbus TCP simulator:
```bash
modbusim tcp --host 0.0.0.0 --port 5020
```
### Python API
```python
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()
```
## Development
### Running Tests
```bash
make test
```
### Linting and Formatting
```bash
make lint # Run linters
make format # Format code
```
### Building and Publishing
```bash
make build # Build the package
make publish # Publish to PyPI
```
## Docker Development
### Build the development image
```bash
docker-compose -f docker-compose.dev.yml build
```
### Run tests in Docker
```bash
docker-compose -f docker-compose.dev.yml run --rm modbusim make test
```
### Start a development shell
```bash
docker-compose -f docker-compose.dev.yml run --rm --service-ports modbusim bash
```
## License
Apache 2.0 - See [LICENSE](LICENSE) for more information.