Skip to content

Rule out a bit-banged board without writing to it - #3

Merged
Boernsman merged 1 commit into
mainfrom
probe-without-writing
Sep 9, 2026
Merged

Boernsman merged 1 commit into
mainfrom
probe-without-writing

Conversation

@Boernsman

Copy link
Copy Markdown

Follow-up to #2, which claimed this was already handled. It was not.

What was wrong

#2 made a bit-banged board give itself away by handing over bytes with nothing
asked of it, and skipped the write when it did. That check passed in testing only
because a libftdi session had just run against the board — which is what wakes the
read side of an FT245's FIFO. On a fresh port the board stays silent for as long as
it is listened to (measured: nothing in 2 s), so the probe went ahead and wrote.

The result on main today, with the relays at 0x5a:

$ denkovi status
type16 DAE00745 on /dev/cu.usbserial-DAE00745, 16 relays
...
on: 3, 5-8, 10-11, 16  [0x86f4]

ask// landed on the relays and left them holding a / (0x2f), and the bytes the
FIFO handed back were taken for a status reply, so an 8 relay board was reported as a
type16 with sixteen relays that are not there.

The fix

Read the chip's data lines before anything else. read_data_lines opens the chip in
its ordinary serial mode and only reads: no byte is sent, no pin is switched to an
output, so it is safe to do to a board of any kind. But it wakes the FIFO, so a
bit-banged board then answers the port unprompted and is recognised before a single
byte is written to it.

Measured across three patterns — 0x5a, 0xa5, 0xf0 — the auto-probe now leaves
the relays exactly where they were and asks for --board type8 instead of inventing
a type16.

probe_board_type and resolve_board_type take the Device rather than the port
name, since the serial number is what finds the chip.

When libftdi is not there

Nothing can be told about the data lines, so the board falls through to the protocol
probe exactly as before. The worst that comes of it is a board that has to be named
with --board, which is already the documented answer for these boards. There is a
test for that path.

Testing

Against the 8 relay board (FT245) on macOS 26: the three-pattern probe check above,
and on, toggle, off still driving the board. 80 tests pass; the probe tests
stub both the FTDI chip and the serial port, including the no-libftdi fallback.

The probe that identifies a board still wrote to one it must not write
to. A bit-banged board was meant to give itself away by handing over
bytes with nothing asked of it, but it only does that once something has
read its FTDI chip, which nothing had. On a fresh port it stays silent
for as long as it is listened to, so the probe went ahead and wrote:
'ask//' landed on the relays and left them holding a '/', and the bytes
that came back were taken for a status reply, so an 8 relay board was
reported as a type16 with sixteen relays that were not there.

Read the chip's data lines first. That changes nothing on any board --
no byte is sent, no pin becomes an output -- but it wakes the read side
of an FT245's FIFO, and the board then answers the port unprompted and
is recognised before anything is written to it. Relays are left where
they were, measured across three patterns.

Without libftdi nothing can be told about the data lines, so the board
falls through to the protocol probe as before; the worst that comes of
it is a board that has to be named with --board.
@Boernsman
Boernsman merged commit 024da38 into main Sep 9, 2026
11 checks passed
@Boernsman
Boernsman deleted the probe-without-writing branch September 9, 2026 14:53
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