fix(keyence): read full barcode reply and release the read beam (LOFF)#1114
Open
dinukajayalath wants to merge 4 commits into
Open
fix(keyence): read full barcode reply and release the read beam (LOFF)#1114dinukajayalath wants to merge 4 commits into
dinukajayalath wants to merge 4 commits into
Conversation
send_command did a single io.read(), which returns one byte and truncated every \r-terminated reply. Accumulate bytes until \r — or until a byte-less read, which means the port timeout elapsed with no reply (e.g. no barcode). Replies now come back whole, and a present barcode returns the instant the terminator lands instead of blocking on a fixed byte count. scan_barcode never turned the read beam off. LON latches it on, so release it with LOFF in a finally, whether the read succeeded or raised. LOFF runs through a try/except that logs instead of propagating, so a LOFF failure can't mask the scan's result or error. Fixes PyLabRobot#1101 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Regression tests for the send_command and scan_barcode fix. Each fails against the pre-fix code: send_command's single io.read() truncated multi-byte replies, and scan_barcode never sent LOFF. - send_command accumulates bytes until \r, stops at the terminator, and treats a byte-less read as an empty reply. - scan_barcode sends LOFF after LON on success, on NG, and on ERR99; a failing LOFF is swallowed and masks neither the result nor the error. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The committed tests added new mypy errors under `make typecheck`: mock attributes (io.read.side_effect, send_command.assert_has_calls) aren't on the real method signatures. Match the existing PLR convention (proflex_tests, agrowdosepump_tests) with targeted `# type: ignore` and annotate replies/ raise_on. No behaviour change; the module is now mypy-clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1101
Problem:
KeyenceBarcodeScannerBackend.scan_barcode() returns only the first character of a barcode, and leaves the reader's beam latched on:
The reader's \r-terminated reply is truncated to one character.
Verified on hardware (Keyence BL-600HA, Code 128 label Test): PLR returned data='T'; the same reader driven directly (LON →read to \r → LOFF) returned Test.
Fix:
elapsed with no reply — e.g. no barcode present, a valid empty result). Replies now come back whole, and a present barcode returns the instant the terminator lands instead of blocking on a fixed byte count.
Tests
keyence_backend_tests.py. Each fails against pre-fix code and passes after:
commands.
Glad to make any change upon reviewing.