hallo erstmal
Ich arbeite mit einem RS232 Programm(im Anhang) und habe es in mein
Projekt implementiert. Das Senden und empfangen von einzelnen Bytes
funktioniert einwandfrei, jedoch möchte ich mit der
WaitForMultipleObjects() Funktion arbeiten, da ich gerne mehr als ein
Byte sednen möchte.
Im Code Kommentar steht folgendes:
If WaitCommEvent() returns TRUE, check to be sure there are
actually bytes in the buffer to read.
If you are reading more than one byte at a time from the buffer
(which this program does not do) you will have the situation occur
where the first byte to arrive will cause the WaitForMultipleObjects()
function to stop waiting. The WaitForMultipleObjects() function
resets the event handle in m_OverlappedStruct.hEvent to the
non-signelead state as it returns.
If in the time between the reset of this event and the call to
ReadFile() more bytes arrive, the m_OverlappedStruct.hEvent handle will
be set again to the signeled state. When the call to ReadFile() occurs,
it will read all of the bytes from the buffer, and the program will
loop back around to WaitCommEvent().
At this point you will be in the situation where
m_OverlappedStruct.hEvent is set, but there are no bytes available to
read. If you proceed and call
ReadFile(), it will return immediatly due to the async port setup, but
GetOverlappedResults() will not return until the next character arrives.
It is not desirable for the GetOverlappedResults() function to be in
this state. The thread shutdown event (event 0) and the WriteFile()
event (Event2) will not work if the thread is blocked by
GetOverlappedResults().
The solution to this is to check the buffer with a call to
ClearCommError().
This call will reset the event handle, and if there are no bytes to read
we can loop back through WaitCommEvent() again, then proceed.
If there are really bytes to read, do nothing and proceed.
Nun blicke ich da nicht ganz durch vorallem mit den Funktionen:
GetOverlappedResults(), ClearCommError().
Wäre froh wenn mir wer mal aufzeigen kann wie ich vorgehen muss.
Danke