I'm calling WriteFile to send data to a modem:
BOOL writeResult = WriteFile(m_hPort, p_message, length, &numOut, NULL);
where:
m_hPort
is a valid HANDLE
unsigned char*
containing ate0\r
int
with a value of 5unsigned long
initialised to 0Occasionally I'm seeing this method succeed but numOut != length
How is it possible for WriteFile to return success without sending any data?
Edit This is how I'm creating the handle:
HANDLE hPort = CreateFileA("\\\\.\\COM5", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
I've checked the return and it's not INVALID_HANDLE_VALUE
which suggests it's valid.
Turned out to be a hardware issue after all.
Power cycling the converter would clear the hardware buffer leading us to suspect that it was a problem with the drivers for that device. From Hans' suggestion we dropped the timeouts and then started probing the error reports in more detail.
Reducing the timeout to something sensible meant we were able to identify that the buffers were filling up until they cannae' take nae' more! Which is why power cycling the converter fixed it (we tried re-routing power through engineering and reversing the polarity, but unusually, neither resolved the issue).
The root cause was some flaky hardware flow control causing the software to block indefinitely. Disabling the flow control solved the issue.