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 ? Good buy Rico Salfer
-
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 ? Good buy Rico Salfer
I also use the ReadFile for serial comm and I found that the problem I was having was that I was using the same overlapped object for both Put and Get. If I did a Put while a Get was waiting for data, the stuff would get trashed. I made sure that only one was doing overlapped operation and the other was just doing a WaitCommEvent. I also found that the number of bytes read that ReadFile returns was not correct. I just figure out the length on my own with a strlen(). Vern ================== The original message was: 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 ?Good buy
Rico Salfer