000
12.03.2005, 10:26 Uhr
focus
|
Hi, habe ein Problem mit WaitCommEvent habe an DSR extern einen Schalter angeschlossen und will nun mit WaitCommEvent herausfinden wann er gedrückt wurde. Wenn ich mit
| Code: |
DWORD Flag; if(hwndCOM != INVALID_HANDLE_VALUE){ if(GetCommModemStatus(hwndCOM, &Flag)) return((Flag & MS_DSR_ON) > 0); } return(false);
|
den Status abfrage bekomme ich das richtige Ergebnis zurück. Wenn ich allerdings mein Programm auf das WaitCommEvent auflaufen lasse merkt es nicht das der Taster gedrückt wurde.
Selbst folgendes Beispiel aus der MSDN funktioniert nicht:
| Code: |
#include <windows.h> #include <assert.h> #include <stdio.h>
void main( ) { HANDLE hCom; OVERLAPPED o; BOOL fSuccess; DWORD dwEvtMask;
hCom = CreateFile( "COM1", GENERIC_READ | GENERIC_WRITE, 0, // exclusive access NULL, // default security attributes OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL );
if (hCom == INVALID_HANDLE_VALUE) { // Handle the error. printf("CreateFile failed with error %d.\n", GetLastError()); return; }
// Set the event mask.
fSuccess = SetCommMask(hCom, EV_CTS | EV_DSR);
if (!fSuccess) { // Handle the error. printf("SetCommMask failed with error %d.\n", GetLastError()); return; }
// Create an event object for use by WaitCommEvent.
o.hEvent = CreateEvent( NULL, // default security attributes FALSE, // auto reset event FALSE, // not signaled NULL // no name );
// Intialize the rest of the OVERLAPPED structure to zero. o.Internal = 0; o.InternalHigh = 0; o.Offset = 0; o.OffsetHigh = 0;
assert(o.hEvent);
if (WaitCommEvent(hCom, &dwEvtMask, &o)) { if (dwEvtMask & EV_DSR) { // To do. }
if (dwEvtMask & EV_CTS) { // To do. } } else { DWORD dwRet = GetLastError(); if( ERROR_IO_PENDING == dwRet) { printf("I/O is pending...\n");
// To do. } else printf("Wait failed with error %d.\n", GetLastError()); } }
|
Ich hoffe jemand kann mir helfen... es ist wirklich wichtig.
Gruss Michael Dieser Post wurde am 12.03.2005 um 10:28 Uhr von focus editiert. |