Add README and LICENCE

- Document features, installation, and usage
- Add MIT licence with British English spellings
This commit is contained in:
zihluwang committed 2026-06-10 19:54:23 +08:00
1 parent 9466936bc3
commit 3382b91c50
2 files changed
+121

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
MIT Licence
Copyright (c) 2026
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicence, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+100
View File
@@ -0,0 +1,100 @@
# Modbus Slave Simulator
A configurable Modbus slave simulator for testing Modbus TCP, RTU, and TLS connections.
## Features
- **Multiple Protocols**: TCP, RTU (serial), and TLS support
- **Configurable Data Store**: Customisable sizes for coils, discrete inputs, holding registers, and input registers
- **Initial Values**: Set default values for all data types
- **Device Identity**: Configurable vendor name, product code, model, and version
- **Docker Support**: Ready-to-use Docker image
## Installation
### From Source
```bash
git clone <repository-url>
cd modbus-slave
pip install -r requirements.txt
```
### With Docker
```bash
docker pull <username>/modbus-slave
```
## Usage
### Command Line
```bash
# TCP server (default: 127.0.0.1:5020)
python main.py
# Custom port
python main.py --port 5020
# RTU mode
python main.py --type rtu --serial-port /dev/ttyUSB0 --slave-id 2
# Custom data store sizes
python main.py --holding-registers-size 1000 --input-registers-size 500
# Set initial values
python main.py --holding-registers-default 100 --coils-default true
```
### Docker
```bash
# Run with defaults
docker run -p 5020:5020 <username>/modbus-slave
# Run with custom arguments
docker run -p 5020:5020 <username>/modbus-slave --holding-registers-size 1000
```
## Command Line Options
| Option | Description | Default |
|--------|-------------|---------|
| `-t, --type` | Server type (tcp, rtu, tls) | tcp |
| `-h, --host` | TCP bind host | 127.0.0.1 |
| `-p, --port` | TCP/TLS port | 5020 |
| `-s, --slave-id` | Modbus slave ID | 1 |
| `--serial-port` | Serial port (RTU) | /dev/ttyUSB0 |
| `--baudrate` | Serial baudrate | 9600 |
| `--coils-size` | Number of coils | 100 |
| `--holding-registers-size` | Number of holding registers | 100 |
| `--input-registers-size` | Number of input registers | 100 |
| `--holding-registers-default` | Default value for holding registers | 0 |
| `-v, --verbose` | Increase verbosity | - |
## Modbus Data Model
| Function Code | Data Type | Access |
|--------------|-----------|--------|
| 0x01/0x05/0x0F | Coil | Read/Write |
| 0x02 | Discrete Input | Read Only |
| 0x03/0x06/0x10 | Holding Register | Read/Write |
| 0x04 | Input Register | Read Only |
## Testing
Test with `pymodbus` client:
```python
from pymodbus.client import ModbusTcpClient
client = ModbusTcpClient('127.0.0.1', port=5020)
result = client.read_holding_registers(0, 10)
print(result.registers)
client.close()
```
## Licence
See [LICENCE](LICENCE) file.