Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix single character reads on windows #165

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

markw65
Copy link

@markw65 markw65 commented Dec 18, 2023

I have a project using @serialport/bindings-cpp that works without issues on MacOS and Linux, but on windows every read fails with

[Error: Reading from COM port (ReadFile): Unknown error code 1784]

The device I'm talking to has a binary protocol, and all exchanges begin with a single character write to the device, a single character response from the device, and then further, longer exchanges. The single character read always fails.

This is because ReadThread does a single character read using ReadFileEx, and then, unconditionally reads "the rest of the data" using ReadFile. But in the case of a single character read there is no "rest of the data". This pull request fixes it by checking for no more data before issuing the ReadFile.

I don't know how to write a test that would fail without the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant