RS232, WaitForMultipleObjects()

OP #829869
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
Angehängte Dateien:
Die Funktion WaitForMultipleObjects() ist nicht dafür gedacht, auf 
mehrmaliges Eintreten eines Events zu warten, sondern auf ein oder 
mehrere Events, die in einem Event-Array stecken. Du müsstest also eher 
jedes Byte einzeln auslesen, in einen Buffer schreiben und erst wenn der 
einen bestimmten Füllstand erreicht hat, das Hauptprogamm mit 
SendMessage benachrichtigen.

Antwort schreiben

Eine eigene Frage? Dieser Thread ist über 18 Jahre alt. Stell sie in einem eigenen Thread – dort lesen mehr Leute mit, und sie wird öfter und schneller beantwortet.

Neuen Thread starten

Eine Lösung, Ergänzung oder Rückmeldung zu diesem Thread? Dann antworte hier.

Formatierung
  • [c]C-Code[/c]
  • [code]Code in anderen Sprachen, ASCII-Zeichnungen[/code]
  • [math]Formel in LaTeX-Syntax[/math]
  • [[Titel]] – Link zu einem Artikel
  • Verweis auf einen anderen Beitrag: Rechtsklick auf dessen Beitrags-ID (#8078628), „Adresse kopieren“, in den Text einfügen

Mehr zur Formatierung

Längeren Sourcecode als Anhang, nicht in den Text. JPG nur für Fotos und Scans; Zeichnungen und Screenshots als PNG oder GIF. Siehe Bildformate.

Schon registriert? Anmelden

Wird nicht angezeigt. Wir schicken dir einen Link; sobald du damit bestätigst, erscheint dein Beitrag.

Mit dem Abschicken legst du einen kostenlosen Account an und erkennst die Nutzungsbedingungen und die Datenschutzerklärung an.