sme-modbus-sim 0.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. sme_modbus_sim-0.3.1/LICENSE +21 -0
  2. sme_modbus_sim-0.3.1/PKG-INFO +205 -0
  3. sme_modbus_sim-0.3.1/README.md +174 -0
  4. sme_modbus_sim-0.3.1/pyproject.toml +48 -0
  5. sme_modbus_sim-0.3.1/setup.cfg +4 -0
  6. sme_modbus_sim-0.3.1/sme_modbus_sim/__init__.py +3 -0
  7. sme_modbus_sim-0.3.1/sme_modbus_sim/__main__.py +298 -0
  8. sme_modbus_sim-0.3.1/sme_modbus_sim/behaviors.py +21 -0
  9. sme_modbus_sim-0.3.1/sme_modbus_sim/config.py +425 -0
  10. sme_modbus_sim-0.3.1/sme_modbus_sim/data/sunspec/LICENSE +201 -0
  11. sme_modbus_sim-0.3.1/sme_modbus_sim/data/sunspec/README.md +13 -0
  12. sme_modbus_sim-0.3.1/sme_modbus_sim/data/sunspec/model_1.json +110 -0
  13. sme_modbus_sim-0.3.1/sme_modbus_sim/data/sunspec/model_103.json +477 -0
  14. sme_modbus_sim-0.3.1/sme_modbus_sim/data/sunspec/model_113.json +388 -0
  15. sme_modbus_sim-0.3.1/sme_modbus_sim/data/sunspec/model_120.json +275 -0
  16. sme_modbus_sim-0.3.1/sme_modbus_sim/data/sunspec/model_121.json +339 -0
  17. sme_modbus_sim-0.3.1/sme_modbus_sim/data/sunspec/model_122.json +356 -0
  18. sme_modbus_sim-0.3.1/sme_modbus_sim/data/sunspec/model_123.json +307 -0
  19. sme_modbus_sim-0.3.1/sme_modbus_sim/data/sunspec/model_160.json +380 -0
  20. sme_modbus_sim-0.3.1/sme_modbus_sim/data/sunspec/model_203.json +748 -0
  21. sme_modbus_sim-0.3.1/sme_modbus_sim/data/sunspec/model_213.json +624 -0
  22. sme_modbus_sim-0.3.1/sme_modbus_sim/data/sunspec/model_701.json +1021 -0
  23. sme_modbus_sim-0.3.1/sme_modbus_sim/data/sunspec/model_702.json +742 -0
  24. sme_modbus_sim-0.3.1/sme_modbus_sim/data/sunspec/model_703.json +175 -0
  25. sme_modbus_sim-0.3.1/sme_modbus_sim/data/sunspec/model_704.json +899 -0
  26. sme_modbus_sim-0.3.1/sme_modbus_sim/data/sunspec/model_705.json +425 -0
  27. sme_modbus_sim-0.3.1/sme_modbus_sim/data/sunspec/model_802.json +799 -0
  28. sme_modbus_sim-0.3.1/sme_modbus_sim/data/sunspec/model_803.json +801 -0
  29. sme_modbus_sim-0.3.1/sme_modbus_sim/engine.py +642 -0
  30. sme_modbus_sim-0.3.1/sme_modbus_sim/faults.py +373 -0
  31. sme_modbus_sim-0.3.1/sme_modbus_sim/protocol/__init__.py +34 -0
  32. sme_modbus_sim-0.3.1/sme_modbus_sim/protocol/client.py +413 -0
  33. sme_modbus_sim-0.3.1/sme_modbus_sim/protocol/constants.py +73 -0
  34. sme_modbus_sim-0.3.1/sme_modbus_sim/protocol/datatypes.py +180 -0
  35. sme_modbus_sim-0.3.1/sme_modbus_sim/protocol/diagnostics.py +241 -0
  36. sme_modbus_sim-0.3.1/sme_modbus_sim/protocol/errors.py +17 -0
  37. sme_modbus_sim-0.3.1/sme_modbus_sim/protocol/framer.py +275 -0
  38. sme_modbus_sim-0.3.1/sme_modbus_sim/protocol/pdu.py +265 -0
  39. sme_modbus_sim-0.3.1/sme_modbus_sim/protocol/pty_port.py +95 -0
  40. sme_modbus_sim-0.3.1/sme_modbus_sim/protocol/serial_server.py +391 -0
  41. sme_modbus_sim-0.3.1/sme_modbus_sim/protocol/server.py +460 -0
  42. sme_modbus_sim-0.3.1/sme_modbus_sim/protocol/store.py +141 -0
  43. sme_modbus_sim-0.3.1/sme_modbus_sim/protocol/tls.py +177 -0
  44. sme_modbus_sim-0.3.1/sme_modbus_sim/scan.py +843 -0
  45. sme_modbus_sim-0.3.1/sme_modbus_sim/static/app.js +1500 -0
  46. sme_modbus_sim-0.3.1/sme_modbus_sim/static/favicon.svg +6 -0
  47. sme_modbus_sim-0.3.1/sme_modbus_sim/static/i18n/en.js +300 -0
  48. sme_modbus_sim-0.3.1/sme_modbus_sim/static/i18n/ja.js +298 -0
  49. sme_modbus_sim-0.3.1/sme_modbus_sim/static/i18n/zh.js +298 -0
  50. sme_modbus_sim-0.3.1/sme_modbus_sim/static/index.html +319 -0
  51. sme_modbus_sim-0.3.1/sme_modbus_sim/static/style.css +250 -0
  52. sme_modbus_sim-0.3.1/sme_modbus_sim/sunspec.py +206 -0
  53. sme_modbus_sim-0.3.1/sme_modbus_sim/templates.py +635 -0
  54. sme_modbus_sim-0.3.1/sme_modbus_sim/web.py +429 -0
  55. sme_modbus_sim-0.3.1/sme_modbus_sim/xlsx.py +288 -0
  56. sme_modbus_sim-0.3.1/sme_modbus_sim.egg-info/PKG-INFO +205 -0
  57. sme_modbus_sim-0.3.1/sme_modbus_sim.egg-info/SOURCES.txt +85 -0
  58. sme_modbus_sim-0.3.1/sme_modbus_sim.egg-info/dependency_links.txt +1 -0
  59. sme_modbus_sim-0.3.1/sme_modbus_sim.egg-info/entry_points.txt +2 -0
  60. sme_modbus_sim-0.3.1/sme_modbus_sim.egg-info/requires.txt +14 -0
  61. sme_modbus_sim-0.3.1/sme_modbus_sim.egg-info/top_level.txt +1 -0
  62. sme_modbus_sim-0.3.1/tests/test_ascii.py +172 -0
  63. sme_modbus_sim-0.3.1/tests/test_behaviors.py +64 -0
  64. sme_modbus_sim-0.3.1/tests/test_cli_validate.py +51 -0
  65. sme_modbus_sim-0.3.1/tests/test_config.py +192 -0
  66. sme_modbus_sim-0.3.1/tests/test_coupled_demo.py +80 -0
  67. sme_modbus_sim-0.3.1/tests/test_diagnostics.py +264 -0
  68. sme_modbus_sim-0.3.1/tests/test_e2e.py +113 -0
  69. sme_modbus_sim-0.3.1/tests/test_engine.py +209 -0
  70. sme_modbus_sim-0.3.1/tests/test_faults.py +279 -0
  71. sme_modbus_sim-0.3.1/tests/test_i18n.py +23 -0
  72. sme_modbus_sim-0.3.1/tests/test_protocol_datatypes.py +100 -0
  73. sme_modbus_sim-0.3.1/tests/test_protocol_framer.py +92 -0
  74. sme_modbus_sim-0.3.1/tests/test_protocol_pdu.py +277 -0
  75. sme_modbus_sim-0.3.1/tests/test_protocol_server.py +186 -0
  76. sme_modbus_sim-0.3.1/tests/test_pty.py +131 -0
  77. sme_modbus_sim-0.3.1/tests/test_replay.py +107 -0
  78. sme_modbus_sim-0.3.1/tests/test_scan.py +524 -0
  79. sme_modbus_sim-0.3.1/tests/test_serial.py +203 -0
  80. sme_modbus_sim-0.3.1/tests/test_static.py +67 -0
  81. sme_modbus_sim-0.3.1/tests/test_sunspec.py +309 -0
  82. sme_modbus_sim-0.3.1/tests/test_template_identification.py +30 -0
  83. sme_modbus_sim-0.3.1/tests/test_templates.py +195 -0
  84. sme_modbus_sim-0.3.1/tests/test_tls.py +320 -0
  85. sme_modbus_sim-0.3.1/tests/test_udp.py +223 -0
  86. sme_modbus_sim-0.3.1/tests/test_web.py +277 -0
  87. sme_modbus_sim-0.3.1/tests/test_xlsx.py +177 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 smartedge-tech-dev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,205 @@
1
+ Metadata-Version: 2.4
2
+ Name: sme-modbus-sim
3
+ Version: 0.3.1
4
+ Summary: SME ModbusSim: a free Modbus TCP / RTU over TCP device simulator with a web UI
5
+ License: MIT
6
+ Project-URL: Homepage, https://github.com/smartedge-tech-dev/sme-modbus-sim
7
+ Keywords: modbus,simulator,energy-management,ems,bess
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Topic :: System :: Hardware
14
+ Requires-Python: >=3.11
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: fastapi>=0.110
18
+ Requires-Dist: uvicorn[standard]>=0.29
19
+ Requires-Dist: pyyaml>=6.0
20
+ Requires-Dist: python-multipart>=0.0.9
21
+ Requires-Dist: openpyxl>=3.1
22
+ Requires-Dist: pydantic>=2
23
+ Requires-Dist: pyserial>=3.5
24
+ Requires-Dist: sme-sim-common[xlsx]<2,>=1.1
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest>=8; extra == "dev"
27
+ Requires-Dist: httpx>=0.27; extra == "dev"
28
+ Requires-Dist: pymodbus==3.16.2; extra == "dev"
29
+ Requires-Dist: cryptography>=42; extra == "dev"
30
+ Dynamic: license-file
31
+
32
+ <p align="center"><img src="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/logo.svg" width="112" alt="SME ModbusSim logo"></p>
33
+
34
+ <h1 align="center">SME ModbusSim</h1>
35
+
36
+ <p align="center"><strong>Simulate Modbus devices on your laptop.</strong> PCS, BMS, meters and sensors on TCP, UDP, TLS and serial,<br>with a live web UI.</p>
37
+
38
+ <p align="center"><a href="https://smartedge-tech.com/open-source/#modbus-sim"><b>Website</b></a> · <a href="https://smartedge-tech-dev.github.io/sme-modbus-sim/"><b>Docs</b></a> · <a href="https://github.com/smartedge-tech-dev/sme-modbus-sim/releases/latest"><b>Download</b></a></p>
39
+
40
+ <p align="center"><a href="https://github.com/smartedge-tech-dev/sme-modbus-sim/actions/workflows/ci.yml"><img src="https://github.com/smartedge-tech-dev/sme-modbus-sim/actions/workflows/ci.yml/badge.svg" alt="CI"></a> <a href="https://github.com/smartedge-tech-dev/sme-modbus-sim/releases/latest"><img src="https://img.shields.io/github/v/release/smartedge-tech-dev/sme-modbus-sim" alt="release"></a> <a href="https://github.com/smartedge-tech-dev/sme-modbus-sim/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-5b5bd6" alt="license MIT"></a> <img src="https://img.shields.io/badge/platform-Windows%20%7C%20Linux%20%7C%20Docker-0a7bbb" alt="platform"> <img src="https://img.shields.io/badge/python-3.11%2B-3776ab" alt="python 3.11+"></p>
41
+
42
+ <p align="center"><strong>English</strong> | <a href="README.ja.md">日本語</a> | <a href="README.zh-CN.md">简体中文</a></p>
43
+
44
+ <p align="center"><img src="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/screenshots/en/live.gif" alt="Live register values, trend and Modbus traffic" width="100%"></p>
45
+
46
+ A Modbus TCP / RTU device simulator with a live web UI. Simulate battery PCS, BMS, power meters, environment
47
+ sensors — or any register map you describe in YAML — and watch the values change in the browser while a real
48
+ Modbus master (your EMS, a gateway, modpoll, pymodbus…) reads and writes them.
49
+
50
+ - **Many devices, one port.** One listener serves many unit IDs; a device can also be attached to several listeners.
51
+ Modbus TCP, Modbus UDP, Modbus/TCP Security (TLS), Modbus RTU over TCP (for serial gateways) serial RTU and serial ASCII (COM port / tty) are supported side by side.
52
+ - **Own protocol core.** Function codes 01, 02, 03, 04, 05, 06, 0F, 10, 16, 17 and 2B/0E (hex) with standard exception responses; serial listeners also answer the diagnostic function codes 07, 08, 0B, 0C and 11.
53
+ Modbus TCP / RTU compatible framing (MBAP and CRC-16).
54
+ - **All the data types.** `bool`, `int16` / `uint16`, `int32` / `uint32`, `int64` / `uint64`, `float32` / `float64`,
55
+ `string`, `enum`, bit-in-register, with byte order and word order (ABCD / CDAB / BADC / DCBA), scale and offset.
56
+ - **Realistic behavior.** A PCS ramps toward its power set point, the BMS integrates SOC from the PCS power, the
57
+ meter shows site load minus PCS power. Sine, random walk, expressions, counters, pulses and CSV replay.
58
+ - **Live UI.** Point table with live values over WebSocket, write from the browser, history per point, a Modbus
59
+ traffic log, statistics push. English, Japanese and Simplified Chinese.
60
+ - **Templates.** Generic battery PCS / BMS / meter / sensor templates, SunSpec PV inverter and meter templates, user-local templates, and "save device as template".
61
+ - **Fault injection.** Delay, no response, exceptions, bad CRC, disconnects and more, from the UI, REST or presets.
62
+ - **Configurable.** Edit YAML or an Excel point list, manage devices and browse templates in the UI, save back to the config file.
63
+
64
+ Built on an asyncio protocol core written for this project, FastAPI and pyserial. No front-end build step.
65
+
66
+ SME ModbusSim is free and MIT-licensed, developed by [smart-edge (智届科技)](https://smartedge-tech.com) —
67
+ custom development is available, see [Commercial support & custom development](#commercial-support--custom-development).
68
+
69
+ ## Screenshots
70
+
71
+ <table>
72
+ <tr>
73
+ <td width="50%"><a href="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/screenshots/en/overview.png"><img src="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/screenshots/en/overview.png" alt="Devices, live register values, SOC trend and Modbus traffic with an injected exception"></a><br><sub>Devices, live register values, SOC trend and Modbus traffic with an injected exception</sub></td>
74
+ <td width="50%"><a href="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/screenshots/en/faults.png"><img src="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/screenshots/en/faults.png" alt="Fault injection: active rules and the new-rule form"></a><br><sub>Fault injection: active rules and the new-rule form</sub></td>
75
+ </tr>
76
+ <tr>
77
+ <td width="50%"><a href="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/screenshots/en/stats.png"><img src="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/screenshots/en/stats.png" alt="Per-listener statistics and a register trend"></a><br><sub>Per-listener statistics and a register trend</sub></td>
78
+ <td width="50%"><a href="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/screenshots/en/add-device.png"><img src="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/screenshots/en/add-device.png" alt="Add device: built-in templates"></a><br><sub>Add device: built-in templates</sub></td>
79
+ </tr>
80
+ <tr>
81
+ <td width="50%"><a href="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/screenshots/en/scan.png"><img src="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/screenshots/en/scan.png" alt="Scan a real device (read-only)"></a><br><sub>Scan a real device (read-only)</sub></td>
82
+ <td width="50%"><a href="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/screenshots/en/overview-dark.png"><img src="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/screenshots/en/overview-dark.png" alt="Dark theme"></a><br><sub>Dark theme</sub></td>
83
+ </tr>
84
+ </table>
85
+
86
+ ## Quick start
87
+
88
+ ### Windows exe
89
+
90
+ Download `sme-modbus-sim-<version>-windows.exe` from the [Releases](https://github.com/smartedge-tech-dev/sme-modbus-sim/releases/latest)
91
+ page and run it. The browser opens the UI at http://127.0.0.1:8081/ .
92
+
93
+ ### Docker
94
+
95
+ ```bash
96
+ docker run --rm -p 8081:8081 -p 5020:5020 -p 5021:5021 ghcr.io/smartedge-tech-dev/sme-modbus-sim
97
+ ```
98
+
99
+ Images are published for `linux/amd64`, `linux/arm64` and `linux/arm/v7`. Offline archives
100
+ (`docker load -i`) are attached to each release. Set `-e TZ=Asia/Tokyo` for a local clock (default UTC).
101
+ To use your own config: `-v ./my.yaml:/app/configs/my.yaml ... -c configs/my.yaml`.
102
+
103
+ ### Serial RTU and RTU over TCP
104
+
105
+ Serial RTU defaults to 19200 baud, 8E1 (`type: rtu`, `port: COM5` or `/dev/ttyUSB0`). RTU over TCP serves RTU frames on a TCP port, for serial gateways and masters in RTU-over-TCP mode. Serial ASCII (`type: ascii`) defaults to 19200 baud, 7E1, and drops an unfinished frame after 1 s without characters (`char_timeout`).
106
+
107
+ ```yaml
108
+ listeners:
109
+ - {id: com1, type: rtu, port: COM5, baudrate: 19200, parity: E} # serial RTU, 8E1
110
+ - {id: gw1, type: rtu_over_tcp, host: 0.0.0.0, port: 5021} # RTU over TCP
111
+ ```
112
+
113
+ Pass the serial adapter into the container with `--device` (Linux hosts; the container runs as a non-root user, so add the device group):
114
+
115
+ ```bash
116
+ docker run --rm --device /dev/ttyUSB0 --group-add dialout -p 8081:8081 \
117
+ -v ./serial.yaml:/app/configs/serial.yaml ghcr.io/smartedge-tech-dev/sme-modbus-sim \
118
+ python -m sme_modbus_sim run -c configs/serial.yaml --host 0.0.0.0 --no-browser
119
+ ```
120
+
121
+ Masters: `modpoll -m rtu -b 19200 -d 8 -p even -a 1 -0 -r 0 -c 4 -t 4 COM6` (the other end of the serial link) and `modpoll -m enc -p 5021 -a 4 -0 -r 0 -c 2 -t 3 127.0.0.1` (RTU over TCP).
122
+
123
+ One Windows PC: Windows has no built-in virtual COM port pair. Options: [SerialLoom](https://github.com/RahulP5/SerialLoom) (free, MIT; builds on the Microsoft-signed usbip-win2 host controller, so the COM ports come from Windows' own usbser driver), a signed commercial virtual serial port driver, or two USB-RS485 adapters wired to each other (A-A, B-B). Windows' usbser driver starts the inter-byte timeout (`ReadIntervalTimeout`) before the first byte arrives, so a master that sets pyserial's `inter_byte_timeout` (modbus_tk does by default) reads 0 bytes whenever a reply takes longer than about one system timer tick (~16 ms); set it to `None` on the master side when testing over SerialLoom ([SerialLoom#16](https://github.com/RahulP5/SerialLoom/issues/16), [known limitations](https://github.com/RahulP5/SerialLoom/blob/main/docs/USB_PORTS.md#limitations)). Since SerialLoom 0.4.0, DTR reaches the other end as DSR and DCD ([SerialLoom#17](https://github.com/RahulP5/SerialLoom/issues/17)); RTS is not passed (CTS stays on), nor is BREAK. Virtual pairs may not pass RTS / DTR and do not pace bytes at the baud rate; com0com 3.0's 64-bit driver is not production-signed and does not load with Secure Boot on. To test RTU framing without any driver, use an `rtu_over_tcp` listener. On Linux, macOS and WSL2, an `rtu` listener with `port: pty` (and optionally `link: /tmp/ttyV0`) creates the virtual pair itself, with no driver; `socat -d -d pty,raw,echo=0 pty,raw,echo=0` also works.
124
+
125
+ ### From source / pip
126
+
127
+ ```bash
128
+ python -m venv .venv
129
+ .venv/bin/pip install -r requirements.txt # Windows: .venv\Scripts\pip
130
+ .venv/bin/python -m sme_modbus_sim run -c configs/demo-site.yaml
131
+ ```
132
+
133
+ Open http://127.0.0.1:8081/ . Python 3.11 or newer.
134
+
135
+ | Command / option | Meaning |
136
+ |---|---|
137
+ | `sme-modbus-sim [run]` | Start the simulator (`run` is the default) |
138
+ | `-c, --config FILE` | YAML config (defaults to `configs/demo-site.yaml`) |
139
+ | `--host 0.0.0.0` | Web UI bind address (default localhost only) |
140
+ | `--http-port 8081` | Web UI port |
141
+ | `--no-browser` | Do not open the browser |
142
+ | `validate [-c] CONFIG` | Check a config file, including behavior expressions, and exit (0 = valid, 2 = error) |
143
+ | `templates` | List the device templates |
144
+
145
+ The demo config has four devices: a battery PCS (unit 1), a BMS (unit 2), a grid meter (unit 3) on Modbus TCP
146
+ port **5020**, and a room sensor (unit 4) reachable only through the RTU-over-TCP listener on port **5021**.
147
+
148
+ ## Testing with a Modbus master
149
+
150
+ ```bash
151
+ # modpoll (addresses are 1-based by default; -0 for protocol addresses)
152
+ modpoll -m tcp -p 5020 -a 1 -0 -r 0 -c 4 -t 4 127.0.0.1
153
+ modpoll -m enc -p 5021 -a 4 -0 -r 0 -c 2 -t 3 127.0.0.1 # RTU over TCP
154
+ ```
155
+
156
+ ```python
157
+ from pymodbus.client import ModbusTcpClient
158
+
159
+ client = ModbusTcpClient("127.0.0.1", port=5020)
160
+ client.connect()
161
+ print(client.read_holding_registers(0, count=2, device_id=1).registers)
162
+ client.write_register(0, 200, device_id=1) # PCS-1 p_setpoint = 20.0 kW (int16 x0.1)
163
+ client.close()
164
+ ```
165
+
166
+ ## Roadmap
167
+
168
+ Released in 0.1.0: Modbus TCP, RTU over TCP and serial RTU; function codes
169
+ 01 / 02 / 03 / 04 / 05 / 06 / 0F / 10 / 16 / 17 / 2B-0E; fault injection (UI, REST, presets); Excel point-list
170
+ import / export; user-local templates and "save device as template"; generic templates and SunSpec PV inverter /
171
+ meter / DER (701-705) / battery (802, 803) templates; read-only scan / record of real devices; web UI with device management and a template browser; Windows exe, multi-arch Docker, offline archives.
172
+
173
+ Released in 0.2.0: serial Modbus ASCII; built-in pty pair for serial testing without drivers (Linux / macOS / WSL2); serial diagnostic function codes 07 / 08 / 0B / 0C / 11.
174
+
175
+ Released in 0.3.0: Modbus UDP listener; Modbus/TCP Security (TLS) listener with client certificates and role-based authorization; UDP and TLS for the read-only scan / record client.
176
+
177
+ > Not affiliated with, endorsed by, or certified by SunSpec Alliance. The `sunspec_pv_inverter` (models 1, 103, 120-123, 160) and `sunspec_meter` (models 1, 203), `sunspec_der` (models 1, 701-705) and `sunspec_battery` (models 1, 802, 803) templates are generated from the public SunSpec model definitions (Apache-2.0) and implement SunSpec Modbus models. No vendor register maps are built in; import your own privately via Excel or user-local templates.
178
+
179
+ ## Commercial support & custom development
180
+
181
+ SME ModbusSim is developed by **smart-edge** — Nanjing Smart-Edge Technology Co., Ltd. (南京智届科技有限公司, 智届科技).
182
+ Since its founding in 2023 the company has developed end-to-end software for distributed energy resources
183
+ such as solar, batteries and EVs, from equipment control to the cloud and electricity markets. Its products
184
+ include the AERIS RA platform (リソースアグリゲーター向け) and an AC system (アグリゲーションコーディネーター) for
185
+ the Japanese electricity markets. The team supports projects in Japanese, from requirements definition
186
+ through design, implementation, operation and maintenance.
187
+
188
+ Services:
189
+
190
+ - Energy management systems (EMS), cloud and on-site
191
+ - RA / AC systems for electricity markets (JEPX, EPRX, OCCTO)
192
+ - Edge IoT and equipment-control software
193
+ - Equipment integration: Modbus, MQTT, BACnet, ECHONET Lite, OpenADR 2.0b
194
+ - Energy forecasting and data analytics
195
+ - Cloud infrastructure design, build and operation
196
+
197
+ Need a feature added to SME ModbusSim, or help integrating your devices or EMS? Get in touch:
198
+
199
+ - Website: <https://smartedge-tech.com>
200
+ - Contact page: <https://smartedge-tech.com/contact/>
201
+ - E-mail: [business@smartedge-tech.com](mailto:business@smartedge-tech.com)
202
+
203
+ ## License
204
+
205
+ [MIT](LICENSE)
@@ -0,0 +1,174 @@
1
+ <p align="center"><img src="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/logo.svg" width="112" alt="SME ModbusSim logo"></p>
2
+
3
+ <h1 align="center">SME ModbusSim</h1>
4
+
5
+ <p align="center"><strong>Simulate Modbus devices on your laptop.</strong> PCS, BMS, meters and sensors on TCP, UDP, TLS and serial,<br>with a live web UI.</p>
6
+
7
+ <p align="center"><a href="https://smartedge-tech.com/open-source/#modbus-sim"><b>Website</b></a> · <a href="https://smartedge-tech-dev.github.io/sme-modbus-sim/"><b>Docs</b></a> · <a href="https://github.com/smartedge-tech-dev/sme-modbus-sim/releases/latest"><b>Download</b></a></p>
8
+
9
+ <p align="center"><a href="https://github.com/smartedge-tech-dev/sme-modbus-sim/actions/workflows/ci.yml"><img src="https://github.com/smartedge-tech-dev/sme-modbus-sim/actions/workflows/ci.yml/badge.svg" alt="CI"></a> <a href="https://github.com/smartedge-tech-dev/sme-modbus-sim/releases/latest"><img src="https://img.shields.io/github/v/release/smartedge-tech-dev/sme-modbus-sim" alt="release"></a> <a href="https://github.com/smartedge-tech-dev/sme-modbus-sim/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-5b5bd6" alt="license MIT"></a> <img src="https://img.shields.io/badge/platform-Windows%20%7C%20Linux%20%7C%20Docker-0a7bbb" alt="platform"> <img src="https://img.shields.io/badge/python-3.11%2B-3776ab" alt="python 3.11+"></p>
10
+
11
+ <p align="center"><strong>English</strong> | <a href="README.ja.md">日本語</a> | <a href="README.zh-CN.md">简体中文</a></p>
12
+
13
+ <p align="center"><img src="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/screenshots/en/live.gif" alt="Live register values, trend and Modbus traffic" width="100%"></p>
14
+
15
+ A Modbus TCP / RTU device simulator with a live web UI. Simulate battery PCS, BMS, power meters, environment
16
+ sensors — or any register map you describe in YAML — and watch the values change in the browser while a real
17
+ Modbus master (your EMS, a gateway, modpoll, pymodbus…) reads and writes them.
18
+
19
+ - **Many devices, one port.** One listener serves many unit IDs; a device can also be attached to several listeners.
20
+ Modbus TCP, Modbus UDP, Modbus/TCP Security (TLS), Modbus RTU over TCP (for serial gateways) serial RTU and serial ASCII (COM port / tty) are supported side by side.
21
+ - **Own protocol core.** Function codes 01, 02, 03, 04, 05, 06, 0F, 10, 16, 17 and 2B/0E (hex) with standard exception responses; serial listeners also answer the diagnostic function codes 07, 08, 0B, 0C and 11.
22
+ Modbus TCP / RTU compatible framing (MBAP and CRC-16).
23
+ - **All the data types.** `bool`, `int16` / `uint16`, `int32` / `uint32`, `int64` / `uint64`, `float32` / `float64`,
24
+ `string`, `enum`, bit-in-register, with byte order and word order (ABCD / CDAB / BADC / DCBA), scale and offset.
25
+ - **Realistic behavior.** A PCS ramps toward its power set point, the BMS integrates SOC from the PCS power, the
26
+ meter shows site load minus PCS power. Sine, random walk, expressions, counters, pulses and CSV replay.
27
+ - **Live UI.** Point table with live values over WebSocket, write from the browser, history per point, a Modbus
28
+ traffic log, statistics push. English, Japanese and Simplified Chinese.
29
+ - **Templates.** Generic battery PCS / BMS / meter / sensor templates, SunSpec PV inverter and meter templates, user-local templates, and "save device as template".
30
+ - **Fault injection.** Delay, no response, exceptions, bad CRC, disconnects and more, from the UI, REST or presets.
31
+ - **Configurable.** Edit YAML or an Excel point list, manage devices and browse templates in the UI, save back to the config file.
32
+
33
+ Built on an asyncio protocol core written for this project, FastAPI and pyserial. No front-end build step.
34
+
35
+ SME ModbusSim is free and MIT-licensed, developed by [smart-edge (智届科技)](https://smartedge-tech.com) —
36
+ custom development is available, see [Commercial support & custom development](#commercial-support--custom-development).
37
+
38
+ ## Screenshots
39
+
40
+ <table>
41
+ <tr>
42
+ <td width="50%"><a href="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/screenshots/en/overview.png"><img src="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/screenshots/en/overview.png" alt="Devices, live register values, SOC trend and Modbus traffic with an injected exception"></a><br><sub>Devices, live register values, SOC trend and Modbus traffic with an injected exception</sub></td>
43
+ <td width="50%"><a href="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/screenshots/en/faults.png"><img src="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/screenshots/en/faults.png" alt="Fault injection: active rules and the new-rule form"></a><br><sub>Fault injection: active rules and the new-rule form</sub></td>
44
+ </tr>
45
+ <tr>
46
+ <td width="50%"><a href="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/screenshots/en/stats.png"><img src="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/screenshots/en/stats.png" alt="Per-listener statistics and a register trend"></a><br><sub>Per-listener statistics and a register trend</sub></td>
47
+ <td width="50%"><a href="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/screenshots/en/add-device.png"><img src="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/screenshots/en/add-device.png" alt="Add device: built-in templates"></a><br><sub>Add device: built-in templates</sub></td>
48
+ </tr>
49
+ <tr>
50
+ <td width="50%"><a href="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/screenshots/en/scan.png"><img src="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/screenshots/en/scan.png" alt="Scan a real device (read-only)"></a><br><sub>Scan a real device (read-only)</sub></td>
51
+ <td width="50%"><a href="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/screenshots/en/overview-dark.png"><img src="https://raw.githubusercontent.com/smartedge-tech-dev/sme-modbus-sim/main/docs/assets/screenshots/en/overview-dark.png" alt="Dark theme"></a><br><sub>Dark theme</sub></td>
52
+ </tr>
53
+ </table>
54
+
55
+ ## Quick start
56
+
57
+ ### Windows exe
58
+
59
+ Download `sme-modbus-sim-<version>-windows.exe` from the [Releases](https://github.com/smartedge-tech-dev/sme-modbus-sim/releases/latest)
60
+ page and run it. The browser opens the UI at http://127.0.0.1:8081/ .
61
+
62
+ ### Docker
63
+
64
+ ```bash
65
+ docker run --rm -p 8081:8081 -p 5020:5020 -p 5021:5021 ghcr.io/smartedge-tech-dev/sme-modbus-sim
66
+ ```
67
+
68
+ Images are published for `linux/amd64`, `linux/arm64` and `linux/arm/v7`. Offline archives
69
+ (`docker load -i`) are attached to each release. Set `-e TZ=Asia/Tokyo` for a local clock (default UTC).
70
+ To use your own config: `-v ./my.yaml:/app/configs/my.yaml ... -c configs/my.yaml`.
71
+
72
+ ### Serial RTU and RTU over TCP
73
+
74
+ Serial RTU defaults to 19200 baud, 8E1 (`type: rtu`, `port: COM5` or `/dev/ttyUSB0`). RTU over TCP serves RTU frames on a TCP port, for serial gateways and masters in RTU-over-TCP mode. Serial ASCII (`type: ascii`) defaults to 19200 baud, 7E1, and drops an unfinished frame after 1 s without characters (`char_timeout`).
75
+
76
+ ```yaml
77
+ listeners:
78
+ - {id: com1, type: rtu, port: COM5, baudrate: 19200, parity: E} # serial RTU, 8E1
79
+ - {id: gw1, type: rtu_over_tcp, host: 0.0.0.0, port: 5021} # RTU over TCP
80
+ ```
81
+
82
+ Pass the serial adapter into the container with `--device` (Linux hosts; the container runs as a non-root user, so add the device group):
83
+
84
+ ```bash
85
+ docker run --rm --device /dev/ttyUSB0 --group-add dialout -p 8081:8081 \
86
+ -v ./serial.yaml:/app/configs/serial.yaml ghcr.io/smartedge-tech-dev/sme-modbus-sim \
87
+ python -m sme_modbus_sim run -c configs/serial.yaml --host 0.0.0.0 --no-browser
88
+ ```
89
+
90
+ Masters: `modpoll -m rtu -b 19200 -d 8 -p even -a 1 -0 -r 0 -c 4 -t 4 COM6` (the other end of the serial link) and `modpoll -m enc -p 5021 -a 4 -0 -r 0 -c 2 -t 3 127.0.0.1` (RTU over TCP).
91
+
92
+ One Windows PC: Windows has no built-in virtual COM port pair. Options: [SerialLoom](https://github.com/RahulP5/SerialLoom) (free, MIT; builds on the Microsoft-signed usbip-win2 host controller, so the COM ports come from Windows' own usbser driver), a signed commercial virtual serial port driver, or two USB-RS485 adapters wired to each other (A-A, B-B). Windows' usbser driver starts the inter-byte timeout (`ReadIntervalTimeout`) before the first byte arrives, so a master that sets pyserial's `inter_byte_timeout` (modbus_tk does by default) reads 0 bytes whenever a reply takes longer than about one system timer tick (~16 ms); set it to `None` on the master side when testing over SerialLoom ([SerialLoom#16](https://github.com/RahulP5/SerialLoom/issues/16), [known limitations](https://github.com/RahulP5/SerialLoom/blob/main/docs/USB_PORTS.md#limitations)). Since SerialLoom 0.4.0, DTR reaches the other end as DSR and DCD ([SerialLoom#17](https://github.com/RahulP5/SerialLoom/issues/17)); RTS is not passed (CTS stays on), nor is BREAK. Virtual pairs may not pass RTS / DTR and do not pace bytes at the baud rate; com0com 3.0's 64-bit driver is not production-signed and does not load with Secure Boot on. To test RTU framing without any driver, use an `rtu_over_tcp` listener. On Linux, macOS and WSL2, an `rtu` listener with `port: pty` (and optionally `link: /tmp/ttyV0`) creates the virtual pair itself, with no driver; `socat -d -d pty,raw,echo=0 pty,raw,echo=0` also works.
93
+
94
+ ### From source / pip
95
+
96
+ ```bash
97
+ python -m venv .venv
98
+ .venv/bin/pip install -r requirements.txt # Windows: .venv\Scripts\pip
99
+ .venv/bin/python -m sme_modbus_sim run -c configs/demo-site.yaml
100
+ ```
101
+
102
+ Open http://127.0.0.1:8081/ . Python 3.11 or newer.
103
+
104
+ | Command / option | Meaning |
105
+ |---|---|
106
+ | `sme-modbus-sim [run]` | Start the simulator (`run` is the default) |
107
+ | `-c, --config FILE` | YAML config (defaults to `configs/demo-site.yaml`) |
108
+ | `--host 0.0.0.0` | Web UI bind address (default localhost only) |
109
+ | `--http-port 8081` | Web UI port |
110
+ | `--no-browser` | Do not open the browser |
111
+ | `validate [-c] CONFIG` | Check a config file, including behavior expressions, and exit (0 = valid, 2 = error) |
112
+ | `templates` | List the device templates |
113
+
114
+ The demo config has four devices: a battery PCS (unit 1), a BMS (unit 2), a grid meter (unit 3) on Modbus TCP
115
+ port **5020**, and a room sensor (unit 4) reachable only through the RTU-over-TCP listener on port **5021**.
116
+
117
+ ## Testing with a Modbus master
118
+
119
+ ```bash
120
+ # modpoll (addresses are 1-based by default; -0 for protocol addresses)
121
+ modpoll -m tcp -p 5020 -a 1 -0 -r 0 -c 4 -t 4 127.0.0.1
122
+ modpoll -m enc -p 5021 -a 4 -0 -r 0 -c 2 -t 3 127.0.0.1 # RTU over TCP
123
+ ```
124
+
125
+ ```python
126
+ from pymodbus.client import ModbusTcpClient
127
+
128
+ client = ModbusTcpClient("127.0.0.1", port=5020)
129
+ client.connect()
130
+ print(client.read_holding_registers(0, count=2, device_id=1).registers)
131
+ client.write_register(0, 200, device_id=1) # PCS-1 p_setpoint = 20.0 kW (int16 x0.1)
132
+ client.close()
133
+ ```
134
+
135
+ ## Roadmap
136
+
137
+ Released in 0.1.0: Modbus TCP, RTU over TCP and serial RTU; function codes
138
+ 01 / 02 / 03 / 04 / 05 / 06 / 0F / 10 / 16 / 17 / 2B-0E; fault injection (UI, REST, presets); Excel point-list
139
+ import / export; user-local templates and "save device as template"; generic templates and SunSpec PV inverter /
140
+ meter / DER (701-705) / battery (802, 803) templates; read-only scan / record of real devices; web UI with device management and a template browser; Windows exe, multi-arch Docker, offline archives.
141
+
142
+ Released in 0.2.0: serial Modbus ASCII; built-in pty pair for serial testing without drivers (Linux / macOS / WSL2); serial diagnostic function codes 07 / 08 / 0B / 0C / 11.
143
+
144
+ Released in 0.3.0: Modbus UDP listener; Modbus/TCP Security (TLS) listener with client certificates and role-based authorization; UDP and TLS for the read-only scan / record client.
145
+
146
+ > Not affiliated with, endorsed by, or certified by SunSpec Alliance. The `sunspec_pv_inverter` (models 1, 103, 120-123, 160) and `sunspec_meter` (models 1, 203), `sunspec_der` (models 1, 701-705) and `sunspec_battery` (models 1, 802, 803) templates are generated from the public SunSpec model definitions (Apache-2.0) and implement SunSpec Modbus models. No vendor register maps are built in; import your own privately via Excel or user-local templates.
147
+
148
+ ## Commercial support & custom development
149
+
150
+ SME ModbusSim is developed by **smart-edge** — Nanjing Smart-Edge Technology Co., Ltd. (南京智届科技有限公司, 智届科技).
151
+ Since its founding in 2023 the company has developed end-to-end software for distributed energy resources
152
+ such as solar, batteries and EVs, from equipment control to the cloud and electricity markets. Its products
153
+ include the AERIS RA platform (リソースアグリゲーター向け) and an AC system (アグリゲーションコーディネーター) for
154
+ the Japanese electricity markets. The team supports projects in Japanese, from requirements definition
155
+ through design, implementation, operation and maintenance.
156
+
157
+ Services:
158
+
159
+ - Energy management systems (EMS), cloud and on-site
160
+ - RA / AC systems for electricity markets (JEPX, EPRX, OCCTO)
161
+ - Edge IoT and equipment-control software
162
+ - Equipment integration: Modbus, MQTT, BACnet, ECHONET Lite, OpenADR 2.0b
163
+ - Energy forecasting and data analytics
164
+ - Cloud infrastructure design, build and operation
165
+
166
+ Need a feature added to SME ModbusSim, or help integrating your devices or EMS? Get in touch:
167
+
168
+ - Website: <https://smartedge-tech.com>
169
+ - Contact page: <https://smartedge-tech.com/contact/>
170
+ - E-mail: [business@smartedge-tech.com](mailto:business@smartedge-tech.com)
171
+
172
+ ## License
173
+
174
+ [MIT](LICENSE)
@@ -0,0 +1,48 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "sme-modbus-sim"
7
+ dynamic = ["version"]
8
+ description = "SME ModbusSim: a free Modbus TCP / RTU over TCP device simulator with a web UI"
9
+ readme = "README.md"
10
+ license = { text = "MIT" }
11
+ requires-python = ">=3.11"
12
+ keywords = ["modbus", "simulator", "energy-management", "ems", "bess"]
13
+ classifiers = [
14
+ "License :: OSI Approved :: MIT License",
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3.11",
17
+ "Programming Language :: Python :: 3.12",
18
+ "Programming Language :: Python :: 3.13",
19
+ "Topic :: System :: Hardware",
20
+ ]
21
+ dependencies = [
22
+ "fastapi>=0.110",
23
+ "uvicorn[standard]>=0.29",
24
+ "pyyaml>=6.0",
25
+ "python-multipart>=0.0.9",
26
+ "openpyxl>=3.1",
27
+ "pydantic>=2",
28
+ "pyserial>=3.5",
29
+ "sme-sim-common[xlsx]>=1.1,<2",
30
+ ]
31
+
32
+ [project.optional-dependencies]
33
+ dev = ["pytest>=8", "httpx>=0.27", "pymodbus==3.16.2", "cryptography>=42"]
34
+
35
+ [project.urls]
36
+ Homepage = "https://github.com/smartedge-tech-dev/sme-modbus-sim"
37
+
38
+ [project.scripts]
39
+ sme-modbus-sim = "sme_modbus_sim.__main__:main"
40
+
41
+ [tool.setuptools.dynamic]
42
+ version = { attr = "sme_modbus_sim.__version__" }
43
+
44
+ [tool.setuptools.packages.find]
45
+ include = ["sme_modbus_sim*"]
46
+
47
+ [tool.setuptools.package-data]
48
+ sme_modbus_sim = ["static/**/*", "data/sunspec/*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ """SME ModbusSim: a Modbus device simulator with a web UI."""
2
+
3
+ __version__ = "0.3.1"