Re: WaitCommEvent problem

From: Olivier (olivier.vigliengo_at_tma.no_spam.fr)
Date: 08/05/04


Date: Thu, 05 Aug 2004 09:05:32 +0200

Hi,

It is normal that that works such as you describe it :

1) Don't use WaitForSingleObject with an event which is never signaled
(SetEvent, PulseEvent). If the event you are waiting is never signaled,
the WaitForSingleObject function is returning when the Timeout (of
WaitForSingleObject) occurs.

2) WaitCommEvent trigger when a Communication event occurs, according to
the SetCommMask parameters (RXCHAR, TXEMPTY, ...) , but don't trigger
when timeout occurs.

3) The ReadFile function returns when nNumberOfBytesToRead are received
*OR* when timeout occurs according to the SetCommTimeouts parameters.
Comparing of nNumberOfBytesToRead and NumberOfByteRead allow you to know
if timeout is occured or if all of the bytes are received.

In conclusion, if you want to work with reception timeouts, directly use
ReadFile function instead of WaitCommEvent function.

I hope this helps you.

Regards.

Olivier.

PseudoCode :

CreateFile(...); // Open the Comm Port
SetCommState(...); // Configuring the Port (Baudrate, parity, ...)
SetCommTimeouts(...); // Set the Read and Write timeouts

ReadFile(hCom,
          lpBuffer,
          nNumberOfBytesToRead,
          &dwNumberOfBytesRead,
          NULL);

// Timeout ?
if(nNumberOfBytesToRead != dwNumberOfBytesRead)
{
    // Timeout occurs
}
else // No timeout !
{
    // Treatment of bytes
}



Relevant Pages

  • Re: WaitForSingleObject and Sleep never time out
    ... The exact same problem is with the WaitForSingleObject timeout. ... Sleep problem XSCInitialize function between the startTick and endtick ...
    (microsoft.public.windowsce.platbuilder)
  • Re: setTimer - what have I missed?
    ... WaitForSingleObject with timeout 10ms is what I've used and that is what ... > SetTimer routine is included in display based devices as part of the GWES ... > Jernej Turnsek ...
    (microsoft.public.windowsce.platbuilder)
  • Re: MFC DLL - ExitInstance hang on WaitForSingleObject
    ... return value of WaitForSingleObject. ... implement the WAIT_TIMEOUT for good programming as Joseph propose? ... // Check for startup event ... If you get this timeout then the thread has not yet started. ...
    (microsoft.public.vc.mfc)
  • Re: Error in schedule.c file
    ... I do have a couple of WaitForSingleObject ... target will reset/halt once that debugchk is hit. ... we can't do much for debug builds with that debugchk in ... a single object, of an interrupt event, with non-infinite timeout. ...
    (microsoft.public.windowsce.embedded)