RE: more CommEvents than expected

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hello
After checking your code, it seems that following lines are called several
times even if WaitCommEvent is not called in the for loop. Since dwEvtMask
works like a global variable to the for(::) loops, that is why you always
get the EV code repeated.
//-----------------------------------------
if (proc)
{

if (dwEvtMask & EV_DSR) printf("ev_dsr pin six fPending = %d ",
fPending);
if (dwEvtMask & EV_CTS) printf("ev_cts pin eight fPending = %d ",
fPending);
if (dwEvtMask & EV_RING) printf("ev_ring pin nine fPending = %d ",
fPending);
if (dwEvtMask & EV_RLSD) printf("ev_rlsd pin one fPending = %d ",
fPending);
if (GetCommModemStatus(hCom, &dwCommStatus))
printf("commStatus = %x\n", dwCommStatus);
else
printf("Error = %d\n", GetLastError());
}
//----------------------------------------
You may use following ways to resolve this issue:
1> clear dwEvtMask every time when you get into the new loop, I suggest you
add dwEvtMask=0 as following:
for(;;)
{
dwEvtMask =0;
proc = 0;
if (!fPending)
/.....
2> or you can add the " if(proc) ..." above when WaitCommEvent return TRUE,
like following:
if (WaitCommEvent(hCom, &dwEvtMask, &o))
{
proc = 1;
// add them
here
}

Please let me know if my answer helps you resolve the problem. If there is
anything more I can assist you, please feel free to let me know.

Thanks,
Rhett Gong [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.

.



Relevant Pages

  • Re: moving pairs
    ... what won't loop on it's own unless the whole machine's set position is ... the moving pairs problem i can't find a webpage for. ... a whole machine that altogether has one position to be in, ... resolve another way. ...
    (comp.lang.c)
  • Re: WaitCommEvent
    ... on the 2nd pass through the loop. ... if (WaitCommEvent(hCom, &dwEvtMask, &o)) ... count DSR pulses ... asynchronous operation to complete. ...
    (microsoft.public.vc.language)
  • Re: acceptance of forth
    ... Resolve `branch` to jump here. ... Push a marker so that we can branch (loop) back to it. ... UNTIL/AGAIN (addr --) ...
    (comp.lang.forth)
  • Re: controls go dead
    ... > I have an application that goes into a loop and waits (using WaitCommEvent) ... You are seeing how Windows works. ... For a multithreaded serial port example, ...
    (microsoft.public.vc.mfc)
  • Re: Multi-bytes received event on rs232?
    ... //until 1 character is ... ---end of main while loop ... and add it to your local buffer (this local buffer ... You do not want to use WaitCommEvent in a loop -- rather, ...
    (microsoft.public.windowsce.app.development)