I have a file handle to a serial (COM) port. I need to read whatever data is available immediately and not wait for additional data to be sent.
How can I determine how much data is available? I can call
SetCommMask(myHandle, EV_RXCHAR) and then wait for an event to tell me that some data is available, but that won’t tell me how much I can now read without blocking.
At the moment I am using CreateFile() and overlapping I/O to perform my reads so they are asynchronous, but they still wait until the buffer is filled to report the I/O as complete.
The ClearCommError() function is what you are looking for – it returns in the COMSTAT structure how many chars are in the input and output queues.