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.
I have a project using
@serialport/bindings-cpp
that works without issues on MacOS and Linux, but on windows every read fails withThe 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 usingReadFileEx
, and then, unconditionally reads "the rest of the data" usingReadFile
. 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 theReadFile
.I don't know how to write a test that would fail without the fix.