Skip to content

Remember each port's choices between visits in the serial tool - #19

Open
SantaClaas wants to merge 1 commit into
mainfrom
claude/serial-app-refresh-clicks-hnxcba
Open

SantaClaas wants to merge 1 commit into
mainfrom
claude/serial-app-refresh-clicks-hnxcba

Conversation

@SantaClaas

Copy link
Copy Markdown
Owner

The page is static and gets reloaded often — to pick up a new build, or because an adapter was unplugged and came back as a fresh panel — and every choice it offers is one that was made last time and would be made again. Getting back to a device read meant six interactions: the preset, the open, the tab, the device, its address, the read.

What it remembers

Per port, in localStorage, under a key made from the adapter's USB ids:

  • the port settings, and which preset they are
  • which tab the panel was on — watch the bus, or talk to a device
  • which device was chosen, and the address each device was last reached at (per device id, so a fan given 0x03 keeps it independently of the relay's 0x01)
  • whether to reopen the port automatically

That takes getting back to a device read from six interactions to one — Read all registers — or two with auto-open left off.

Two ports of the same model are indistinguishable through the Web Serial API, so a second identical CH340 gets 1a86:7523#1 rather than the first one's settings.

Two judgement calls

Readings are not remembered, only choices. A restored register value sitting beside a live one would make the page claim to know something about the device that it does not, and the read is the click at which the user takes responsibility for putting frames on a bus the controller may be driving.

Reopening the port on load is opt-in per port, with a checkbox beside Open port, off until asked for. Opening a port asserts the adapter's control lines, and on an adapter that drives its RS-485 transceiver from RTS that is the one thing a tool meant to be passive must not do unasked. Once asked, it is remembered, and a refresh then costs no clicks at all to get back to a live port.

Also fixed

The preset select never reflected the settings and always showed the first entry. With settings now restored, that would have put 9600 8N1 under a label reading "RadiCal fans — 19200 8E1". It shows the matching preset, or "Custom" when the settings are nobody's preset.

Verification

pnpm build and pnpm test pass — 165 tests, 25 of them new, covering key assignment, the round trip, and what the parser makes of a record written by an older build. preferences.ts takes its storage as an argument for exactly that reason, so the parsing is checked without a browser, the same way everything under src/modbus is.

The built page was also driven in Chromium against a stubbed navigator.serial: a relay session was set up, the page reloaded, and the port came back open at 9600 8N1 on the device tab with the relay at address 4 — and unchecking auto-open keeps the settings while leaving the port closed. That script lives outside the repository.

Documentation

A "What it remembers" section in serial/README.md, and a sixth entry in the serial tool's list of things to know in CLAUDE.md — including that anything added to Remembered has to be parsed as if written by an older build.

🤖 Generated with Claude Code

https://claude.ai/code/session_012EsZhBCaL9NHU6ySsMm7Kw


Generated by Claude Code

The page is static and gets reloaded often — to pick up a new build, or
because an adapter was unplugged and came back as a fresh panel — and
every choice it offers is one the user made last time and would make
again. Getting back to a device read meant six interactions: the preset,
the open, the tab, the device, its address, the read.

Each port's settings, tab, device and last-used address per device now
live in localStorage under a key made from the adapter's USB ids, so a
reload lands back where the bench session was. Only choices are kept,
never readings: a restored register value beside a live one would make
the page lie about what it knows, and the read stays the click at which
the user takes responsibility for putting frames on the bus.

Reopening the port on load is opt-in per port, with a checkbox beside
Open port. Opening a port asserts the adapter's control lines, and on an
adapter that drives its RS-485 transceiver from RTS that is the one
thing a tool meant to be passive must not do unasked — so it is a
decision, made once and then remembered.

The preset select now shows which preset the settings actually are,
rather than always the first: restored 9600 8N1 under a label reading
"RadiCal fans — 19200 8E1" would be worse than no label. Settings that
are nobody's preset say "Custom".

preferences.ts takes its storage as an argument, so what it makes of a
record written by an older build is tested without a browser. The
parsing is forgiving by design — every field is checked and falls back
on its own rather than discarding the record.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012EsZhBCaL9NHU6ySsMm7Kw

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant