WaitCommEvent
-
Hallo,
ich kann kein Event mit WaitCommEvent ermitteln. Kurz zur Erklärung des unten stehenden Codes:
Die Steuerleitungen DTR und RTS werden gesetzt/nicht gesetzt und lassen eine LED leuchten. Zusätzlich soll ein Signal auf RI registriert werden. Die Hardware funktioniert definitiv, es kommen also korrekte Signale am RI an.
Der Fehler liegt also wohl im Code.
void __fastcall TForm1::Button1Click(TObject *Sender) { DWORD event_mask; HANDLE hComm = NULL; OVERLAPPED Overlapped; hComm = CreateFile("COM2", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0); EscapeCommFunction(hComm,SETDTR); EscapeCommFunction(hComm,CLRRTS); Overlapped.Internal = 0; Overlapped.InternalHigh = 0; Overlapped.Offset = 0; Overlapped.OffsetHigh = 0; Overlapped.hEvent = CreateEvent(NULL,TRUE,FALSE,NULL); SetCommMask(hComm,EV_RING); if(WaitCommEvent(hComm,&event_mask,&Overlapped)) Label1->Caption="Ring"; }Leider zeigt Label1 nie etwas an! Warum?
Wenns jemand weiss, dann bitte antworten.
Danke!
Hubi
-
Hi
Anscheinend wird das Event nicht sofort ausgelöst, und WaitCommEvent gitb FALSE zurück.
Siehe MSDN:
If the overlapped operation cannot be completed immediately, the function returns FALSE and the GetLastError function returns ERROR_IO_PENDING, indicating that the operation is executing in the background. When this happens, the system sets the hEvent member of the OVERLAPPED structure to the not-signaled state before WaitCommEvent returns, and then it sets it to the signaled state when one of the specified events or an error occurs. The calling process can use one of the wait functions to determine the event object's state and then use the GetOverlappedResult function to determine the results of the WaitCommEvent operation. GetOverlappedResult reports the success or failure of the operation, and the variable pointed to by the lpEvtMask parameter is set to indicate the event that occurred.
Weitere Infos siehe MSDN
Falls es immernoch Probleme gibt, könnte ich dir Quellcode posten, hatte das ganze mal benutzt, um eine ordentliche Modem-Kommunikation bereitzustellen.
Mfg Reinhold Fischer