Go4Expert

Go4Expert (http://www.go4expert.com/)
-   MFC (http://www.go4expert.com/forums/mfc/)
-   -   WaitForSingleObject never signalled? (http://www.go4expert.com/forums/waitforsingleobject-never-signalled-t1496/)

AP2k 30Sep2006 02:06

WaitForSingleObject never signalled?
 
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);
    osReader.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
   
    EscapeCommFunction(serial,SETRTS);
    printf("\n\nConnecting...    (F1 to quit)\n");
    printlog("Establishing connection...");
   
    DWORD BytesReadOV;
    int err;
   
    unsigned int undef = 1;
    while(undef & 1){
                dwRes = WaitForSingleObject(osReader.hEvent, 100);
                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.

shabbir 30Sep2006 05:52

Re: WaitForSingleObject never signalled?
 
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.


All times are GMT +5.5. The time now is 22:21.