From 5dccf88fc9e1c847e72c2a790a0a8911e65363d9 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 11 Nov 2026 07:39:16 +0000 Subject: [PATCH 1/2] feat(slave): accept unit ids up to 255 The slave refused unit 255 ("not a unit or range in 1..247"), the unit most Modbus TCP devices answer as. The limit lived only in the frontend: parseUnits, parseProject and the simulation editor. The backend keeps units as u8 and rmodbus 0.13 broadcasts only on unit 0, so 255 is served like any other unit; measured with pymodbus 3.16.2 as master over TCP, UDP and RTU over TCP (docs/superpowers/verification/2026-11-11-slave- unit-255.md). On serial lines 248..255 stay reserved by the spec; the tool allows them, as the master side already does (0..255). Tests changed with the behaviour: "248" is now a valid unit, so the rejection cases move to 256 and 250-256. Cases that only failed through the empty-list error ("5-2", "a") gain a valid unit beside them, and the project check rejects a mixed [1, 256], so the range checks themselves are exercised (Stryker on units.ts: 93.1%). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013Rdii2xv4WTmCWzFBdAPnv --- CHANGELOG.md | 8 +++++ .../verification/2026-11-11-slave-unit-255.md | 31 +++++++++++++++++++ messages/en.json | 2 +- messages/it.json | 2 +- src-tauri/src/master_tests.rs | 12 ++++--- src/lib/components/SimulationForm.svelte | 2 +- src/lib/project.test.ts | 7 +++-- src/lib/project.ts | 4 +-- src/lib/units.test.ts | 4 ++- src/lib/units.ts | 8 +++-- 10 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 docs/superpowers/verification/2026-11-11-slave-unit-255.md diff --git a/CHANGELOG.md b/CHANGELOG.md index f66a545..f1364ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ Notable changes to ModbusTool, newest first. Each section is also the text of it [GitHub release](https://github.com/chetto1983/ModbusTool/releases): the Release workflow publishes the section whose heading matches the pushed `vX.Y.Z` tag. The full history is in git. +## Unreleased + +### Changed + +- The slave serves unit ids up to 255 (it stopped at 247), in the unit list, the simulations and + project files. 255 is the unit most TCP devices answer as; on serial lines 248..255 are reserved + by the Modbus specification, so a serial master may not address them. + ## v3.5.0 — 2026-11-06 Import a device's register map as a dashboard, and record a dashboard's values to file. diff --git a/docs/superpowers/verification/2026-11-11-slave-unit-255.md b/docs/superpowers/verification/2026-11-11-slave-unit-255.md new file mode 100644 index 0000000..111e111 --- /dev/null +++ b/docs/superpowers/verification/2026-11-11-slave-unit-255.md @@ -0,0 +1,31 @@ +# Verifica: unità dello slave fino a 255 + +Data: 2026-11-11. Richiesta: lo slave rifiutava l'unità 255 ("non è un'unità o un intervallo in +1..247"). Il limite stava solo nel frontend (`parseUnits`, `parseProject`, editor delle +simulazioni): il backend tiene le unità come `u8` e rmodbus 0.13 tratta come broadcast solo +l'unità 0 (`ModbusFrame::new`, `broadcast_units: &[0]`), quindi 255 è servita come ogni altra. + +## Cosa è stato misurato + +- **Riferimento indipendente**: pymodbus 3.16.2 (la versione della CI) come master contro il + `SlaveServer` reale configurato con la sola unità 255, su TCP, UDP e RTU over TCP, in una + worktree usa-e-getta. Su ogni trasporto: lettura di 3 holding register con `device_id=255` → + `[11, 22, 33]`; scrittura di `[7, 8]` all'indirizzo 10 → presente nello store dell'unità 255; + lettura con `device_id=254` (non configurata) → nessuna risposta. +- **Test**: `all_operations_over_tcp_udp_and_rtu_over_tcp` esegue tutte le operazioni del master + anche sull'unità 255; `parseUnits` accetta 255 e 247-248, rifiuta 256 e 250-256; + `parseProject` accetta `[1, 255]`, rifiuta `[0]` e `[1, 256]`. +- **Gate**: `cargo fmt --check`, `cargo clippy -D warnings`, `cargo test` (61); `npm run check`, + `lint`, `format:check`, `deadcode`, `dup`, `coverage` (146 test, 99,13% righe), `build`, + `file-size`, `check:i18n`. Stryker: `units.ts` 93,1% (i 4 sopravvissuti sono equivalenti: + `trim`/`filter` ridondanti con `Number()` e gli argomenti del messaggio), nessun sopravvissuto + sulle righe toccate di `project.ts`. + +## Cosa NON dimostra + +- L'app non è stata avviata: la UI (campo unità, simulazioni, caricamento progetto) è coperta da + test unitari e svelte-check, non dall'E2E con tauri-driver, che gira in CI. +- Linee seriali RTU/ASCII non misurate con l'unità 255: lì 248..255 sono riservati (Modbus over + Serial Line v1.02 §2.2) e un master seriale conforme può non indirizzarli. +- `project.ts` resta al 54,5% di mutation score: il file non è nello scope di Stryker e i + sopravvissuti sono sulle righe non toccate. diff --git a/messages/en.json b/messages/en.json index 595a4ff..4dca23a 100644 --- a/messages/en.json +++ b/messages/en.json @@ -200,7 +200,7 @@ "slave_stop": "Stop", "slave_first": "Start", "slave_count": "Count", - "units_invalid": "\"{part}\" is not a unit or range in 1..247", + "units_invalid": "\"{part}\" is not a unit or range in 1..255", "units_empty": "At least one unit is required", "csv_invalid_entry": "Invalid entry \"{entry}\"", "sim_title": "Simulation", diff --git a/messages/it.json b/messages/it.json index b3daaa2..c148e94 100644 --- a/messages/it.json +++ b/messages/it.json @@ -200,7 +200,7 @@ "slave_stop": "Ferma", "slave_first": "Inizio", "slave_count": "Numero", - "units_invalid": "\"{part}\" non è un'unità o un intervallo in 1..247", + "units_invalid": "\"{part}\" non è un'unità o un intervallo in 1..255", "units_empty": "Serve almeno un'unità", "csv_invalid_entry": "Voce non valida \"{entry}\"", "sim_title": "Simulazione", diff --git a/src-tauri/src/master_tests.rs b/src-tauri/src/master_tests.rs index 3b5860b..374429b 100644 --- a/src-tauri/src/master_tests.rs +++ b/src-tauri/src/master_tests.rs @@ -123,10 +123,14 @@ fn every_operation(master: &mut Master, store: &UnitStore, unit: u8) { #[test] fn all_operations_over_tcp_udp_and_rtu_over_tcp() { - for kind in [tcp, udp, rtu_over_tcp] { - let (server, store) = slave(local(kind, 0), 4); - let mut m = master(local(kind, server.local_addr.unwrap().port()), 0); - every_operation(&mut m, &store, 4); + // 255 is the unit TCP devices answer as (MODBUS Messaging on TCP/IP Implementation Guide + // V1.0b); rmodbus 0.13 broadcasts only on unit 0, so it is served like any other unit. + for unit in [4, 255] { + for kind in [tcp, udp, rtu_over_tcp] { + let (server, store) = slave(local(kind, 0), unit); + let mut m = master(local(kind, server.local_addr.unwrap().port()), 0); + every_operation(&mut m, &store, unit); + } } } diff --git a/src/lib/components/SimulationForm.svelte b/src/lib/components/SimulationForm.svelte index c0bace8..73cb69c 100644 --- a/src/lib/components/SimulationForm.svelte +++ b/src/lib/components/SimulationForm.svelte @@ -17,7 +17,7 @@