WaitForSingleObject never signalled?

Discussion in 'MFC' started by AP2k, Sep 29, 2006.

  1. AP2k

    AP2k New Member

    Joined:
    Sep 29, 2006
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
    Last edited: Sep 29, 2006
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice