http://tinyurl.com/8un6 I am using the serial tutorial there. I am trying to perform overlapped communication so I can monitor both a keyboard event and the event where the CTS line changes state. Here is my code: Code: SetCommMask(serial,EV_CTS); [b]osReader.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);[/b] EscapeCommFunction(serial,SETRTS); printf("\n\nConnecting... (F1 to quit)\n"); printlog("Establishing connection..."); DWORD BytesReadOV; int err; unsigned int undef = 1; while(undef & 1){ [b]dwRes = WaitForSingleObject(osReader.hEvent, 100);[/b] if(dwRes == WAIT_TIMEOUT){ if(kbhit()){ if(getch() == 0x00){ if(getch() == KEY_F1) undef = -1; } } } if(dwRes == WAIT_OBJECT_0){ undef = 0; } if(undef == -1){ printf(" cancelled!"); CancelIo(s); CloseHandle(s); close_connection(); exit(-1); } } The osReader.hEvent never gets signalled, so it always times out. I should mention that the device I am communicating with does work. I have a beta terminal program that does not use overlapped IO, but it has a few leak problems. Most notibly, Ctrl+C'ing out of the program left me with file handle leaks. Anyone see something I didnt do right? PS: The osReader is an OVERLAPPED structure and the serial HANDLE is set for overlapped IO.
You can try out couple of things. 1. Try to see if there is any SetEvent for osReader.hEvent handle. 2. Try giving INFINITE time instead of 100 and see if it gets signalled. I dont see anything wrong in the above program but your other thread for which you are waiting should signal the even for the current thread to continue with the execution.