Serial communication with Win32 API
-
Hello, I'm a software developer and have following problem with Win32 API and serial communication : In my protocol is a read thread to receive bytes. The function ReadFile() reads one Byte from serial interface (COM1 or COM2). I use an overlapped structure to receive data. If there is an error the function WaitForSingleObject() is called. Usually the receive is correct. Sometimes the function ReadFile() don't read a Byte although the InQueue has a byte. The function WaitForSingleObject() is called. This function returns with WAIT_TIMEOUT, the current Byte is lost. If I call in this case PurgeComm(), the lost Byte is in the buffer which was in ReadFile() the input buffer. But this algorithm don't works correct every time. How can I read the Byte in the InQueue if this byte can't read from a Win32 API function ? How can I avoid this problem ? Rico Salfer