Skip to content

halmodule: fix inverted success check in port read() and peek() - #4593

Merged
BsAtHome merged 1 commit into
LinuxCNC:masterfrom
grandixximo:halmodule-port-read
Sep 28, 2026
Merged

BsAtHome merged 1 commit into
LinuxCNC:masterfrom
grandixximo:halmodule-port-read

Conversation

@grandixximo

Copy link
Copy Markdown
Contributor

hal_port_read() and hal_port_peek() return true when the bytes were copied, but pyhal_port_read_peek() treated true as failure. A successful read()/peek() on a port pin returned False, and read() had already consumed the data, so reading a port from Python never worked. Introduced in da53107 (#4061); master only.

The fix inverts the check, giving the behavior the docs describe ("Returns a bytes buffer upon success or False on failure", python-hal-interface.adoc) and the old pyhal module had. The new tests/halmodule/port writes to a port and checks peek, peek_commit and read. It fails without the fix and passes with it.

Found while adding port pins to #4251.

hal_port_read() and hal_port_peek() return true when the bytes were copied. The check was inverted, so a successful read or peek returned False, and read() had already consumed the data. Add tests/halmodule/port covering write, peek, peek_commit and read.
@BsAtHome
BsAtHome merged commit 8d3e540 into LinuxCNC:master Sep 28, 2026
17 checks passed
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.

2 participants