mt-sics-emulator 0.1.0__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 (28) hide show
  1. mt_sics_emulator-0.1.0/LICENSE +21 -0
  2. mt_sics_emulator-0.1.0/PKG-INFO +331 -0
  3. mt_sics_emulator-0.1.0/README.md +306 -0
  4. mt_sics_emulator-0.1.0/pyproject.toml +42 -0
  5. mt_sics_emulator-0.1.0/setup.cfg +4 -0
  6. mt_sics_emulator-0.1.0/src/mt_sics_emulator.egg-info/PKG-INFO +331 -0
  7. mt_sics_emulator-0.1.0/src/mt_sics_emulator.egg-info/SOURCES.txt +26 -0
  8. mt_sics_emulator-0.1.0/src/mt_sics_emulator.egg-info/dependency_links.txt +1 -0
  9. mt_sics_emulator-0.1.0/src/mt_sics_emulator.egg-info/entry_points.txt +4 -0
  10. mt_sics_emulator-0.1.0/src/mt_sics_emulator.egg-info/requires.txt +8 -0
  11. mt_sics_emulator-0.1.0/src/mt_sics_emulator.egg-info/top_level.txt +1 -0
  12. mt_sics_emulator-0.1.0/src/mtsics/__init__.py +0 -0
  13. mt_sics_emulator-0.1.0/src/mtsics/cli.py +110 -0
  14. mt_sics_emulator-0.1.0/src/mtsics/core/__init__.py +0 -0
  15. mt_sics_emulator-0.1.0/src/mtsics/core/simulator.py +267 -0
  16. mt_sics_emulator-0.1.0/src/mtsics/core/state.py +179 -0
  17. mt_sics_emulator-0.1.0/src/mtsics/profiles.py +177 -0
  18. mt_sics_emulator-0.1.0/src/mtsics/protocol/__init__.py +0 -0
  19. mt_sics_emulator-0.1.0/src/mtsics/protocol/engine.py +241 -0
  20. mt_sics_emulator-0.1.0/src/mtsics/transport/__init__.py +0 -0
  21. mt_sics_emulator-0.1.0/src/mtsics/transport/control.py +296 -0
  22. mt_sics_emulator-0.1.0/src/mtsics/transport/serial.py +371 -0
  23. mt_sics_emulator-0.1.0/src/mtsics/transport/tcp.py +408 -0
  24. mt_sics_emulator-0.1.0/tests/test_engine.py +380 -0
  25. mt_sics_emulator-0.1.0/tests/test_profiles.py +206 -0
  26. mt_sics_emulator-0.1.0/tests/test_serial.py +374 -0
  27. mt_sics_emulator-0.1.0/tests/test_simulator.py +423 -0
  28. mt_sics_emulator-0.1.0/tests/test_tcp.py +555 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Matthew Curtis
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,331 @@
1
+ Metadata-Version: 2.4
2
+ Name: mt-sics-emulator
3
+ Version: 0.1.0
4
+ Summary: Software emulator for MT-SICS compatible industrial scales (Ohaus, Mettler Toledo, Sartorius)
5
+ License-Expression: MIT
6
+ Project-URL: Homepage, https://github.com/mdcurt/mt-sics-emulator
7
+ Project-URL: Issues, https://github.com/mdcurt/mt-sics-emulator/issues
8
+ Keywords: mt-sics,scale,emulator,ohaus,mettler-toledo,sartorius,weighing
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Topic :: Software Development :: Testing
15
+ Requires-Python: >=3.11
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Provides-Extra: serial
19
+ Requires-Dist: pyserial>=3.5; extra == "serial"
20
+ Provides-Extra: dev
21
+ Requires-Dist: pytest>=8.0; extra == "dev"
22
+ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
23
+ Requires-Dist: pyserial>=3.5; extra == "dev"
24
+ Dynamic: license-file
25
+
26
+ # MT-SICS-Emulator
27
+
28
+ The first open-source server-side implementation of the **MT-SICS** (Mettler Toledo Standard Interface Command Set) protocol. Emulates major industrial bench scales over TCP and RS-232 so client applications (WMS integrations, label printers, custom scripts, etc) can be developed and tested without physical hardware.
29
+
30
+ ---
31
+
32
+ ## Why this exists
33
+
34
+ MT-SICS is the dominant protocol for industrial scales. Dozens of client libraries exist for it in every language. As far as I could find, no one had written a server, something that actually responds as a scale, until this project. The gap meant developers either borrowed bench time on a physical unit or built one-off stubs from scratch.
35
+
36
+ ---
37
+
38
+ ## Features
39
+
40
+ - **MT-SICS Level 0 + 1** — `S`, `SI`, `SIR`, `Z`, `ZI`, `T`, `TI`, `TAR`, `TAC`, `@`, and `I0`–`I4`
41
+ - **8 built-in scale profiles** — Ohaus, Mettler Toledo, and Sartorius scales from 0.1 mg analytical balances to 300 kg industrial terminals
42
+ - **TCP transport** — raw socket server matching each scale's Ethernet / WiFi mode; multiple concurrent clients supported
43
+ - **Serial transport** — RS-232 / USB via `pyserial`; works with real or virtual COM ports
44
+ - **Realistic weight physics** — exponential settle curve, Gaussian noise, stability detection
45
+ - **Programmatic control** — drive the simulated weight from test code with a single call
46
+
47
+ ---
48
+
49
+ ## Scale profiles
50
+
51
+ | Profile | Scale | Capacity | Graduation | Segment |
52
+ |---|---|---|---|---|
53
+ | `ohaus-defender5000` | Ohaus Defender 5000 (TD52P) | 150 kg | 0.05 kg | Warehouse / receiving |
54
+ | `ohaus-ranger7000` | Ohaus Ranger 7000 (R71MHD35) | 35 kg | 0.005 kg | Parts counting / bench |
55
+ | `ohaus-scout` | Ohaus Scout (SPX4201) | 4200 g | 0.1 g | Portable / general purpose |
56
+ | `mt-xs204` | Mettler Toledo XS204 | 220 g | 0.0001 g | Analytical lab |
57
+ | `mt-ms3002s` | Mettler Toledo MS3002S | 3100 g | 0.01 g | Precision / formulation |
58
+ | `mt-ind570` | Mettler Toledo IND570 | 300 kg | 0.1 kg | Heavy industrial |
59
+ | `sartorius-quintix224` | Sartorius Quintix 224-1S | 220 g | 0.0001 g | Pharma / research |
60
+ | `sartorius-practum6100` | Sartorius Practum 6100-1S | 6100 g | 0.1 g | Teaching / production |
61
+
62
+ Default profile when no `--profile` flag is given: `ohaus-defender5000`.
63
+
64
+ ---
65
+
66
+ ## Quick start
67
+
68
+ ```bash
69
+ pip install mt-sics-emulator # TCP only
70
+ pip install "mt-sics-emulator[serial]" # + serial support
71
+ ```
72
+
73
+ Or from source:
74
+
75
+ ```bash
76
+ git clone https://github.com/mdcurt/mt-sics-emulator.git
77
+ cd mt-sics-emulator
78
+ pip install -e ".[dev]"
79
+ ```
80
+
81
+ ### TCP server
82
+
83
+ ```bash
84
+ mtsics-tcp --port 8000
85
+ mtsics-tcp --port 8000 --profile mt-xs204
86
+ mtsics-tcp --list-profiles
87
+ ```
88
+
89
+ ```
90
+ $ nc localhost 8000
91
+ SI
92
+ SI S 0.00 kg
93
+ T
94
+ T S 0.00 kg
95
+ SIR
96
+ S S 0.00 kg
97
+ S S 0.00 kg
98
+ ...
99
+ ```
100
+
101
+ ### Serial port
102
+
103
+ Linux / macOS (virtual port pair via socat):
104
+
105
+ ```bash
106
+ socat PTY,link=/tmp/scale-emu,rawer PTY,link=/tmp/scale-client,rawer &
107
+ mtsics-serial --port /tmp/scale-emu --profile ohaus-ranger7000
108
+ ```
109
+
110
+ Windows (com0com or HHD Virtual Serial Port):
111
+
112
+ ```bash
113
+ mtsics-serial --port COM3 --profile sartorius-quintix224
114
+ ```
115
+
116
+ ### Interactive REPL
117
+
118
+ ```bash
119
+ mtsics # default profile
120
+ mtsics --profile mt-xs204 # analytical balance
121
+ ```
122
+
123
+ ```
124
+ WEIGHT 0.1234 → sets platform to 0.1234 g (stable)
125
+ SI → SI S 0.1234 g
126
+ T → T S 0.1234 g
127
+ WEIGHT 0.2500 → add more load
128
+ SI → SI S 0.1266 g (net)
129
+ PROFILES → list all profiles
130
+ CONFIG → show current scale config
131
+ ```
132
+
133
+ ### Python API
134
+
135
+ ```python
136
+ import asyncio
137
+ from mtsics.core.state import ScaleState
138
+ from mtsics.core.simulator import WeightSimulator, SimConfig
139
+ from mtsics.protocol.engine import MTSICSEngine
140
+ from mtsics.transport.tcp import TCPTransport, TCPConfig
141
+ from mtsics.profiles import load
142
+
143
+ async def main():
144
+ state = ScaleState(config=load("mt-xs204"))
145
+ engine = MTSICSEngine(state)
146
+ sim = WeightSimulator(state)
147
+
148
+ transport = TCPTransport(engine, simulator=sim)
149
+ host, port = await transport.start()
150
+ print(f"Emulator on {host}:{port}")
151
+
152
+ # Drive the scale from your tests:
153
+ sim.set_target(0.1234) # place 0.1234 g on the platform
154
+ sim.advance_to_stable() # skip the settle curve
155
+
156
+ await transport.serve_forever()
157
+
158
+ asyncio.run(main())
159
+ ```
160
+
161
+ ---
162
+
163
+ ---
164
+
165
+ ## HTTP control API
166
+
167
+ The control API is a second, optional HTTP port that exposes the simulator: the "physical world" interface for tests, scripts, and GUIs.
168
+
169
+ ```bash
170
+ mtsics-tcp --port 8000 --control-port 8001
171
+ ```
172
+
173
+ | Endpoint | Description |
174
+ |---|---|
175
+ | `GET /state` | Full scale state: gross, net, tare, stability, ranges, target, profile info |
176
+ | `POST /weight` | `{"target": 12.5}` settles naturally; `{"value": 12.5, "snap": true}` jumps immediately |
177
+ | `POST /reset` | Clears tare and zero offset, returns platform to 0 |
178
+
179
+ ```bash
180
+ # Place 12.5 kg on the platform (settles over ~2 s)
181
+ curl -X POST localhost:8001/weight -d '{"target": 12.5}'
182
+
183
+ # Jump straight to 5 kg, no settling
184
+ curl -X POST localhost:8001/weight -d '{"value": 5.0, "snap": true}'
185
+
186
+ # Read everything
187
+ curl localhost:8001/state
188
+ ```
189
+
190
+ The control API binds to loopback (`127.0.0.1`) only and is disabled unless `--control-port` is given. It has zero dependencies — implemented directly on asyncio.
191
+
192
+ A typical integration test: start the emulator, `POST /weight` to simulate a parcel landing on the scale, then assert your application under test reads the correct weight through its normal MT-SICS connection.
193
+
194
+ ---
195
+
196
+ ## Supported MT-SICS commands
197
+
198
+ | Command | Description | Response |
199
+ |---|---|---|
200
+ | `S` | Send stable weight | `S S <weight> <unit>` |
201
+ | `SI` | Send immediately | `SI S/D <weight> <unit>` |
202
+ | `SIR` / `SNR` | Start continuous output | stream of `S S/D ...` lines |
203
+ | `Z` | Zero (within ±2 % capacity) | `Z A` or `Z I` / `Z +` / `Z -` |
204
+ | `ZI` | Zero immediately | `ZI A` or `ZI I` |
205
+ | `T` | Tare (stable) | `T S <tare> <unit>` or `T I` |
206
+ | `TI` | Tare immediately | `TI S/D <tare> <unit>` |
207
+ | `TAR <value>` | Set explicit tare | `TAR A` or `TAR I` |
208
+ | `TAC` | Clear tare | `TAC A` |
209
+ | `@` | Full reset | `I4 A "<serial>"` |
210
+ | `I0` | Scale data summary | `I0 A "..." ...` |
211
+ | `I1` | Model name | `I1 A "<model>"` |
212
+ | `I2` | Serial number | `I2 A "<serial>"` |
213
+ | `I3` | Software version | `I3 A "<version>"` |
214
+ | `I4` | SW ID | `I4 A "<serial>"` |
215
+
216
+ Unknown commands return `ES`. Condition failures return `<CMD> I`.
217
+
218
+ ---
219
+
220
+ ## Adding a custom profile
221
+
222
+ ```python
223
+ from mtsics.core.state import ScaleConfig
224
+ from mtsics.core.state import ScaleState
225
+ from mtsics.protocol.engine import MTSICSEngine
226
+
227
+ my_scale = ScaleConfig(
228
+ capacity=500.0,
229
+ graduation=0.2,
230
+ unit="kg",
231
+ model="MyScale 500",
232
+ serial_number="MS0000001",
233
+ sw_version="1.0",
234
+ )
235
+
236
+ state = ScaleState(config=my_scale)
237
+ engine = MTSICSEngine(state)
238
+ ```
239
+
240
+ To contribute a profile, open a PR adding an entry to `src/mtsics/profiles.py` with a source citation for the capacity and graduation values.
241
+
242
+ ---
243
+
244
+ ## Connecting BarTender
245
+
246
+ **Important:** BarTender's built-in "Ohaus" driver does not speak MT-SICS and will not work with current Defender 5000 firmware or this emulator. Use the **Mettler Toledo MT-SICS Level 1** driver instead — it works with any MT-SICS compatible scale regardless of manufacturer.
247
+
248
+ In BarTender's Scale/Device settings, select manufacturer → **Mettler Toledo**, protocol → **MT-SICS Level 1**, then enter the host/port for TCP or the COM port for serial.
249
+
250
+ ---
251
+
252
+ ## Development
253
+
254
+ ```bash
255
+ git clone https://github.com/mdcurt/mt-sics-emulator.git
256
+ cd mt-sics-emulator
257
+ pip install -e ".[dev]"
258
+ pytest tests/ -v
259
+ ```
260
+
261
+ ### Project structure
262
+
263
+ ```
264
+ src/mtsics/
265
+ ├── profiles.py # Named scale configs (Ohaus, MT, Sartorius)
266
+ ├── core/
267
+ │ ├── state.py # ScaleState — weight, tare, zero, stability
268
+ │ └── simulator.py # WeightSimulator — settle curve, noise, stability detection
269
+ ├── protocol/
270
+ │ └── engine.py # MTSICSEngine — pure text-in / text-out, no I/O
271
+ ├── transport/
272
+ │ ├── tcp.py # TCPTransport — asyncio server, multi-client, SIR streaming
273
+ │ └── serial.py # SerialTransport — pyserial thread bridge
274
+ │ └── control.py # ControlAPI — HTTP control plane (dependency-free)
275
+ └── cli.py # Interactive REPL
276
+
277
+ tests/
278
+ ├── test_profiles.py # 120 profile + engine integration tests
279
+ ├── test_engine.py # MT-SICS protocol command tests
280
+ ├── test_simulator.py # Physics / stability tests
281
+ ├── test_tcp.py # Network integration tests
282
+ └── test_serial.py # Serial transport tests (mock-based)
283
+ └── test_control.py # HTTP control API tests
284
+ ```
285
+
286
+ ---
287
+
288
+ ## Contributing
289
+
290
+ Issues and pull requests are welcome.
291
+
292
+ **Good first issues** — areas where contributions would have immediate impact:
293
+
294
+ - Additional scale profiles (open a PR with a source citation for capacity and graduation values)
295
+ - MT-SICS Level 2 commands (`C`, `CA`, `CDP`, `D`, `DW`, `K`, `SA`, `SR`)
296
+ - Checkweighing mode — above/within/below threshold bands
297
+ - Parts counting mode
298
+
299
+ **Long term goals** - areas that will require far more work but will greatly enhance the value of this tool:
300
+
301
+ - Emulating scale model specific functionality
302
+ - Scale face GUI — a visual representation of a scale display that connects to the emulator over TCP and shows live weight, stability indicator, and unit; useful as a demo and as a manual testing tool, ant framework (Tkinter, PyQt, web-based) welcome
303
+ - Platform simulator GUI — a control panel for setting the target weight and watching the settle curve in real time, as an alternative to driving the simulator programmatically
304
+
305
+ **To contribute code:**
306
+
307
+ 1. Open an issue first if the change is non-trivial — helps avoid duplicate effort
308
+ 2. Fork the repo and create a branch from `main`
309
+ 3. Add tests alongside your code — every new command or feature should have test coverage
310
+ 4. Run `pytest tests/` before opening a PR
311
+ 5. Open a pull request with a short description of what the change does and why
312
+
313
+ **To report a behavior difference from a real scale:**
314
+
315
+ Include the exact command you sent, the response you received from the emulator, and the response from the real unit. That is the most useful possible bug report and will get a fast response.
316
+
317
+ ## Attribution and disclaimer
318
+
319
+ This project is an independent implementation of a publicly documented communication protocol and is not affiliated with, endorsed by, or sponsored by any scale manufacturer.
320
+
321
+ **MT-SICS** (Mettler Toledo Standard Interface Command Set) is a protocol specification published by **Mettler Toledo International Inc.** Referenced here under fair use for interoperability purposes.
322
+
323
+ **Ohaus Defender 5000**, **Ranger 7000**, and **Scout** are products of **Ohaus Corporation**. **XS204**, **MS3002S**, and **IND570** are products of **Mettler Toledo International Inc.** **Quintix** and **Practum** are products of **Sartorius AG**. Capacity and graduation specifications are taken from the respective manufacturers' published product documentation.
324
+
325
+ No proprietary firmware, binary code, or trade secrets are used or reproduced in this project.
326
+
327
+ ---
328
+
329
+ ## License
330
+
331
+ [MIT](LICENSE)
@@ -0,0 +1,306 @@
1
+ # MT-SICS-Emulator
2
+
3
+ The first open-source server-side implementation of the **MT-SICS** (Mettler Toledo Standard Interface Command Set) protocol. Emulates major industrial bench scales over TCP and RS-232 so client applications (WMS integrations, label printers, custom scripts, etc) can be developed and tested without physical hardware.
4
+
5
+ ---
6
+
7
+ ## Why this exists
8
+
9
+ MT-SICS is the dominant protocol for industrial scales. Dozens of client libraries exist for it in every language. As far as I could find, no one had written a server, something that actually responds as a scale, until this project. The gap meant developers either borrowed bench time on a physical unit or built one-off stubs from scratch.
10
+
11
+ ---
12
+
13
+ ## Features
14
+
15
+ - **MT-SICS Level 0 + 1** — `S`, `SI`, `SIR`, `Z`, `ZI`, `T`, `TI`, `TAR`, `TAC`, `@`, and `I0`–`I4`
16
+ - **8 built-in scale profiles** — Ohaus, Mettler Toledo, and Sartorius scales from 0.1 mg analytical balances to 300 kg industrial terminals
17
+ - **TCP transport** — raw socket server matching each scale's Ethernet / WiFi mode; multiple concurrent clients supported
18
+ - **Serial transport** — RS-232 / USB via `pyserial`; works with real or virtual COM ports
19
+ - **Realistic weight physics** — exponential settle curve, Gaussian noise, stability detection
20
+ - **Programmatic control** — drive the simulated weight from test code with a single call
21
+
22
+ ---
23
+
24
+ ## Scale profiles
25
+
26
+ | Profile | Scale | Capacity | Graduation | Segment |
27
+ |---|---|---|---|---|
28
+ | `ohaus-defender5000` | Ohaus Defender 5000 (TD52P) | 150 kg | 0.05 kg | Warehouse / receiving |
29
+ | `ohaus-ranger7000` | Ohaus Ranger 7000 (R71MHD35) | 35 kg | 0.005 kg | Parts counting / bench |
30
+ | `ohaus-scout` | Ohaus Scout (SPX4201) | 4200 g | 0.1 g | Portable / general purpose |
31
+ | `mt-xs204` | Mettler Toledo XS204 | 220 g | 0.0001 g | Analytical lab |
32
+ | `mt-ms3002s` | Mettler Toledo MS3002S | 3100 g | 0.01 g | Precision / formulation |
33
+ | `mt-ind570` | Mettler Toledo IND570 | 300 kg | 0.1 kg | Heavy industrial |
34
+ | `sartorius-quintix224` | Sartorius Quintix 224-1S | 220 g | 0.0001 g | Pharma / research |
35
+ | `sartorius-practum6100` | Sartorius Practum 6100-1S | 6100 g | 0.1 g | Teaching / production |
36
+
37
+ Default profile when no `--profile` flag is given: `ohaus-defender5000`.
38
+
39
+ ---
40
+
41
+ ## Quick start
42
+
43
+ ```bash
44
+ pip install mt-sics-emulator # TCP only
45
+ pip install "mt-sics-emulator[serial]" # + serial support
46
+ ```
47
+
48
+ Or from source:
49
+
50
+ ```bash
51
+ git clone https://github.com/mdcurt/mt-sics-emulator.git
52
+ cd mt-sics-emulator
53
+ pip install -e ".[dev]"
54
+ ```
55
+
56
+ ### TCP server
57
+
58
+ ```bash
59
+ mtsics-tcp --port 8000
60
+ mtsics-tcp --port 8000 --profile mt-xs204
61
+ mtsics-tcp --list-profiles
62
+ ```
63
+
64
+ ```
65
+ $ nc localhost 8000
66
+ SI
67
+ SI S 0.00 kg
68
+ T
69
+ T S 0.00 kg
70
+ SIR
71
+ S S 0.00 kg
72
+ S S 0.00 kg
73
+ ...
74
+ ```
75
+
76
+ ### Serial port
77
+
78
+ Linux / macOS (virtual port pair via socat):
79
+
80
+ ```bash
81
+ socat PTY,link=/tmp/scale-emu,rawer PTY,link=/tmp/scale-client,rawer &
82
+ mtsics-serial --port /tmp/scale-emu --profile ohaus-ranger7000
83
+ ```
84
+
85
+ Windows (com0com or HHD Virtual Serial Port):
86
+
87
+ ```bash
88
+ mtsics-serial --port COM3 --profile sartorius-quintix224
89
+ ```
90
+
91
+ ### Interactive REPL
92
+
93
+ ```bash
94
+ mtsics # default profile
95
+ mtsics --profile mt-xs204 # analytical balance
96
+ ```
97
+
98
+ ```
99
+ WEIGHT 0.1234 → sets platform to 0.1234 g (stable)
100
+ SI → SI S 0.1234 g
101
+ T → T S 0.1234 g
102
+ WEIGHT 0.2500 → add more load
103
+ SI → SI S 0.1266 g (net)
104
+ PROFILES → list all profiles
105
+ CONFIG → show current scale config
106
+ ```
107
+
108
+ ### Python API
109
+
110
+ ```python
111
+ import asyncio
112
+ from mtsics.core.state import ScaleState
113
+ from mtsics.core.simulator import WeightSimulator, SimConfig
114
+ from mtsics.protocol.engine import MTSICSEngine
115
+ from mtsics.transport.tcp import TCPTransport, TCPConfig
116
+ from mtsics.profiles import load
117
+
118
+ async def main():
119
+ state = ScaleState(config=load("mt-xs204"))
120
+ engine = MTSICSEngine(state)
121
+ sim = WeightSimulator(state)
122
+
123
+ transport = TCPTransport(engine, simulator=sim)
124
+ host, port = await transport.start()
125
+ print(f"Emulator on {host}:{port}")
126
+
127
+ # Drive the scale from your tests:
128
+ sim.set_target(0.1234) # place 0.1234 g on the platform
129
+ sim.advance_to_stable() # skip the settle curve
130
+
131
+ await transport.serve_forever()
132
+
133
+ asyncio.run(main())
134
+ ```
135
+
136
+ ---
137
+
138
+ ---
139
+
140
+ ## HTTP control API
141
+
142
+ The control API is a second, optional HTTP port that exposes the simulator: the "physical world" interface for tests, scripts, and GUIs.
143
+
144
+ ```bash
145
+ mtsics-tcp --port 8000 --control-port 8001
146
+ ```
147
+
148
+ | Endpoint | Description |
149
+ |---|---|
150
+ | `GET /state` | Full scale state: gross, net, tare, stability, ranges, target, profile info |
151
+ | `POST /weight` | `{"target": 12.5}` settles naturally; `{"value": 12.5, "snap": true}` jumps immediately |
152
+ | `POST /reset` | Clears tare and zero offset, returns platform to 0 |
153
+
154
+ ```bash
155
+ # Place 12.5 kg on the platform (settles over ~2 s)
156
+ curl -X POST localhost:8001/weight -d '{"target": 12.5}'
157
+
158
+ # Jump straight to 5 kg, no settling
159
+ curl -X POST localhost:8001/weight -d '{"value": 5.0, "snap": true}'
160
+
161
+ # Read everything
162
+ curl localhost:8001/state
163
+ ```
164
+
165
+ The control API binds to loopback (`127.0.0.1`) only and is disabled unless `--control-port` is given. It has zero dependencies — implemented directly on asyncio.
166
+
167
+ A typical integration test: start the emulator, `POST /weight` to simulate a parcel landing on the scale, then assert your application under test reads the correct weight through its normal MT-SICS connection.
168
+
169
+ ---
170
+
171
+ ## Supported MT-SICS commands
172
+
173
+ | Command | Description | Response |
174
+ |---|---|---|
175
+ | `S` | Send stable weight | `S S <weight> <unit>` |
176
+ | `SI` | Send immediately | `SI S/D <weight> <unit>` |
177
+ | `SIR` / `SNR` | Start continuous output | stream of `S S/D ...` lines |
178
+ | `Z` | Zero (within ±2 % capacity) | `Z A` or `Z I` / `Z +` / `Z -` |
179
+ | `ZI` | Zero immediately | `ZI A` or `ZI I` |
180
+ | `T` | Tare (stable) | `T S <tare> <unit>` or `T I` |
181
+ | `TI` | Tare immediately | `TI S/D <tare> <unit>` |
182
+ | `TAR <value>` | Set explicit tare | `TAR A` or `TAR I` |
183
+ | `TAC` | Clear tare | `TAC A` |
184
+ | `@` | Full reset | `I4 A "<serial>"` |
185
+ | `I0` | Scale data summary | `I0 A "..." ...` |
186
+ | `I1` | Model name | `I1 A "<model>"` |
187
+ | `I2` | Serial number | `I2 A "<serial>"` |
188
+ | `I3` | Software version | `I3 A "<version>"` |
189
+ | `I4` | SW ID | `I4 A "<serial>"` |
190
+
191
+ Unknown commands return `ES`. Condition failures return `<CMD> I`.
192
+
193
+ ---
194
+
195
+ ## Adding a custom profile
196
+
197
+ ```python
198
+ from mtsics.core.state import ScaleConfig
199
+ from mtsics.core.state import ScaleState
200
+ from mtsics.protocol.engine import MTSICSEngine
201
+
202
+ my_scale = ScaleConfig(
203
+ capacity=500.0,
204
+ graduation=0.2,
205
+ unit="kg",
206
+ model="MyScale 500",
207
+ serial_number="MS0000001",
208
+ sw_version="1.0",
209
+ )
210
+
211
+ state = ScaleState(config=my_scale)
212
+ engine = MTSICSEngine(state)
213
+ ```
214
+
215
+ To contribute a profile, open a PR adding an entry to `src/mtsics/profiles.py` with a source citation for the capacity and graduation values.
216
+
217
+ ---
218
+
219
+ ## Connecting BarTender
220
+
221
+ **Important:** BarTender's built-in "Ohaus" driver does not speak MT-SICS and will not work with current Defender 5000 firmware or this emulator. Use the **Mettler Toledo MT-SICS Level 1** driver instead — it works with any MT-SICS compatible scale regardless of manufacturer.
222
+
223
+ In BarTender's Scale/Device settings, select manufacturer → **Mettler Toledo**, protocol → **MT-SICS Level 1**, then enter the host/port for TCP or the COM port for serial.
224
+
225
+ ---
226
+
227
+ ## Development
228
+
229
+ ```bash
230
+ git clone https://github.com/mdcurt/mt-sics-emulator.git
231
+ cd mt-sics-emulator
232
+ pip install -e ".[dev]"
233
+ pytest tests/ -v
234
+ ```
235
+
236
+ ### Project structure
237
+
238
+ ```
239
+ src/mtsics/
240
+ ├── profiles.py # Named scale configs (Ohaus, MT, Sartorius)
241
+ ├── core/
242
+ │ ├── state.py # ScaleState — weight, tare, zero, stability
243
+ │ └── simulator.py # WeightSimulator — settle curve, noise, stability detection
244
+ ├── protocol/
245
+ │ └── engine.py # MTSICSEngine — pure text-in / text-out, no I/O
246
+ ├── transport/
247
+ │ ├── tcp.py # TCPTransport — asyncio server, multi-client, SIR streaming
248
+ │ └── serial.py # SerialTransport — pyserial thread bridge
249
+ │ └── control.py # ControlAPI — HTTP control plane (dependency-free)
250
+ └── cli.py # Interactive REPL
251
+
252
+ tests/
253
+ ├── test_profiles.py # 120 profile + engine integration tests
254
+ ├── test_engine.py # MT-SICS protocol command tests
255
+ ├── test_simulator.py # Physics / stability tests
256
+ ├── test_tcp.py # Network integration tests
257
+ └── test_serial.py # Serial transport tests (mock-based)
258
+ └── test_control.py # HTTP control API tests
259
+ ```
260
+
261
+ ---
262
+
263
+ ## Contributing
264
+
265
+ Issues and pull requests are welcome.
266
+
267
+ **Good first issues** — areas where contributions would have immediate impact:
268
+
269
+ - Additional scale profiles (open a PR with a source citation for capacity and graduation values)
270
+ - MT-SICS Level 2 commands (`C`, `CA`, `CDP`, `D`, `DW`, `K`, `SA`, `SR`)
271
+ - Checkweighing mode — above/within/below threshold bands
272
+ - Parts counting mode
273
+
274
+ **Long term goals** - areas that will require far more work but will greatly enhance the value of this tool:
275
+
276
+ - Emulating scale model specific functionality
277
+ - Scale face GUI — a visual representation of a scale display that connects to the emulator over TCP and shows live weight, stability indicator, and unit; useful as a demo and as a manual testing tool, ant framework (Tkinter, PyQt, web-based) welcome
278
+ - Platform simulator GUI — a control panel for setting the target weight and watching the settle curve in real time, as an alternative to driving the simulator programmatically
279
+
280
+ **To contribute code:**
281
+
282
+ 1. Open an issue first if the change is non-trivial — helps avoid duplicate effort
283
+ 2. Fork the repo and create a branch from `main`
284
+ 3. Add tests alongside your code — every new command or feature should have test coverage
285
+ 4. Run `pytest tests/` before opening a PR
286
+ 5. Open a pull request with a short description of what the change does and why
287
+
288
+ **To report a behavior difference from a real scale:**
289
+
290
+ Include the exact command you sent, the response you received from the emulator, and the response from the real unit. That is the most useful possible bug report and will get a fast response.
291
+
292
+ ## Attribution and disclaimer
293
+
294
+ This project is an independent implementation of a publicly documented communication protocol and is not affiliated with, endorsed by, or sponsored by any scale manufacturer.
295
+
296
+ **MT-SICS** (Mettler Toledo Standard Interface Command Set) is a protocol specification published by **Mettler Toledo International Inc.** Referenced here under fair use for interoperability purposes.
297
+
298
+ **Ohaus Defender 5000**, **Ranger 7000**, and **Scout** are products of **Ohaus Corporation**. **XS204**, **MS3002S**, and **IND570** are products of **Mettler Toledo International Inc.** **Quintix** and **Practum** are products of **Sartorius AG**. Capacity and graduation specifications are taken from the respective manufacturers' published product documentation.
299
+
300
+ No proprietary firmware, binary code, or trade secrets are used or reproduced in this project.
301
+
302
+ ---
303
+
304
+ ## License
305
+
306
+ [MIT](LICENSE)
@@ -0,0 +1,42 @@
1
+ [build-system]
2
+ requires = ["setuptools>=70"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "mt-sics-emulator"
7
+ version = "0.1.0"
8
+ description = "Software emulator for MT-SICS compatible industrial scales (Ohaus, Mettler Toledo, Sartorius)"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.11"
13
+ keywords = ["mt-sics", "scale", "emulator", "ohaus", "mettler-toledo", "sartorius", "weighing"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Intended Audience :: Developers",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.11",
19
+ "Programming Language :: Python :: 3.12",
20
+ "Topic :: Software Development :: Testing",
21
+ ]
22
+ dependencies = []
23
+
24
+ [project.optional-dependencies]
25
+ serial = ["pyserial>=3.5"]
26
+ dev = ["pytest>=8.0", "pytest-asyncio>=0.23", "pyserial>=3.5"]
27
+
28
+ [project.urls]
29
+ Homepage = "https://github.com/mdcurt/mt-sics-emulator"
30
+ Issues = "https://github.com/mdcurt/mt-sics-emulator/issues"
31
+
32
+ [project.scripts]
33
+ mtsics = "mtsics.cli:main"
34
+ mtsics-tcp = "mtsics.transport.tcp:main"
35
+ mtsics-serial = "mtsics.transport.serial:main"
36
+
37
+ [tool.setuptools.packages.find]
38
+ where = ["src"]
39
+
40
+ [tool.pytest.ini_options]
41
+ asyncio_mode = "auto"
42
+ pythonpath = ["src"]