Skip to content

Conversation

@markw65
Copy link
Contributor

@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.

Copy link
Member

@reconbot reconbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great catch, thank you. Just need's one change. I'll merge as is and add that in so I can do a release today.

baton->offset += bytesTransferred;
}
if (!baton->bytesToRead) {
baton->complete = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a CloseHandle(ov->hEvent); here

@reconbot reconbot merged commit f8bfc1e into serialport:main Dec 23, 2024
reconbot added a commit that referenced this pull request Dec 23, 2024
Makes sure we always close the event handle when we're done reading.

Finishes up #165
@github-actions
Copy link

🎉 This PR is included in version 13.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Development

Successfully merging this pull request may close these issues.

2 participants