Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ 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.

## v3.6.0 — 2026-11-11

Unit 255 for the slave, the unit most Modbus TCP devices answer as.

### Changed

- The slave's unit list, simulations and project files accept unit ids up to 255 (they stopped at
247). 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.
Expand Down
31 changes: 31 additions & 0 deletions docs/superpowers/verification/2026-11-11-slave-unit-255.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion messages/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "modbus-tool",
"private": true,
"version": "3.5.0",
"version": "3.6.0",
"license": "MIT",
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "modbus-tool"
version = "3.5.0"
version = "3.6.0"
description = "Modbus TCP/UDP/RTU/ASCII master and slave tool"
authors = ["ModbusTool contributors"]
license = "MIT"
Expand Down
12 changes: 8 additions & 4 deletions src-tauri/src/master_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "ModbusTool",
"version": "3.5.0",
"version": "3.6.0",
"identifier": "io.github.chetto1983.modbustool",
"build": {
"beforeDevCommand": "npm run dev",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/SimulationForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div class="grid-3">
<label class="field">
{m.common_unit()}
<input type="number" min="1" max="247" required bind:value={rule.unit} />
<input type="number" min="1" max="255" required bind:value={rule.unit} />
</label>
<label class="field">
{m.sim_table()}
Expand Down
7 changes: 5 additions & 2 deletions src/lib/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { decode } from "./datatypes";
describe("project files", () => {
it("round-trips", () => {
const project = defaultProject();
project.slave.units = [1, 255];
project.master.polls.push({
id: "a",
name: "Boiler",
Expand All @@ -25,8 +26,10 @@ describe("project files", () => {
expect(() => parseProject("{")).toThrow(ProjectError);
expect(() => parseProject('{"version":2}')).toThrow(/unsupported version/);
const bad = defaultProject();
bad.slave.units = [0];
expect(() => parseProject(JSON.stringify(bad))).toThrow(/units/);
for (const units of [[0], [1, 256]]) {
bad.slave.units = units;
expect(() => parseProject(JSON.stringify(bad))).toThrow(/units/);
}
const badPoll = defaultProject() as unknown as { master: { polls: unknown[] } };
badPoll.master.polls.push({
id: "x",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ export function parseProject(json: string): Project {
check(isObject(slave.config) && Array.isArray(slave.units) && Array.isArray(slave.simulations), "slave section");
(master.polls as unknown[]).forEach(checkPoll);
check(
(slave.units as unknown[]).every((u) => isInt(u, 1, 247)),
"slave units must be 1..247",
(slave.units as unknown[]).every((u) => isInt(u, 1, 255)),
"slave units must be 1..255",
);
check(data.labels === undefined || isObject(data.labels), "labels");
return {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/units.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { parseUnits, runs } from "./units";
describe("unit lists", () => {
it("parses lists and ranges", () => {
expect(parseUnits("3, 1, 10-12, 3")).toEqual([1, 3, 10, 11, 12]);
expect(parseUnits("255, 247-248")).toEqual([247, 248, 255]);
});
it("rejects invalid entries", () => {
for (const bad of ["", "0", "248", "5-2", "a", "1-x"]) expect(() => parseUnits(bad), bad).toThrow();
for (const bad of ["", "0", "256", "250-256", "1, 5-2", "a", "2, a", "2, 1-x"])
expect(() => parseUnits(bad), bad).toThrow();
});
});

Expand Down
8 changes: 6 additions & 2 deletions src/lib/units.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
import { m } from "../paraglide/messages.js";
import type { AddressValue } from "./csv";

/** Parses "1, 2, 10-12" into sorted unique unit ids 1..247 (Modbus serial addresses). */
/**
* Parses "1, 2, 10-12" into sorted unique unit ids 1..255. 0 is the broadcast address; 248..255
* are reserved on serial lines (Modbus over Serial Line v1.02 §2.2) but 255 is the usual unit on
* TCP, so the whole byte is accepted.
*/
export function parseUnits(text: string): number[] {
const units = new Set<number>();
for (const part of text
.split(",")
.map((p) => p.trim())
.filter(Boolean)) {
const [from, to = from] = part.split("-").map((n) => Number(n.trim()));
if (!Number.isInteger(from) || !Number.isInteger(to) || from < 1 || to > 247 || from > to) {
if (!Number.isInteger(from) || !Number.isInteger(to) || from < 1 || to > 255 || from > to) {
throw new Error(m.units_invalid({ part }));
}
for (let u = from; u <= to; u++) units.add(u);
Expand Down
Loading