Re: WaitCommEvent



Dave Cullen <none@xxxxxxxx> wrote:
I want to count pulses appearing on the CTS and DSR lines of a serial
port. The example "Monitoring Communications Events" in MSDN is
perfect, except that I can't get the code to work. I'd like to put
this block into a do-while loop, but it generates an error 87
(ERROR_INVALID_PARAMETER) on the 2nd pass through the loop.

if (WaitCommEvent(hCom, &dwEvtMask, &o))
{
if (dwEvtMask & EV_DSR)
{
// To do.... count DSR pulses
}

if (dwEvtMask & EV_CTS)
{
// To do.... count CTS pulses
}
}
else
{
DWORD dwRet = GetLastError();
if( ERROR_IO_PENDING == dwRet)
{
printf("I/O is pending...\n");

// To do... continue loop

Is that your actual code? At this point, you need to wait for an
asynchronous operation to complete. You can't issue a second call while
that operation is in progress (as you appear to be doing).
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


.



Relevant Pages

  • RE: more CommEvents than expected
    ... times even if WaitCommEvent is not called in the for loop. ... if (proc) ... 1> clear dwEvtMask every time when you get into the new loop, ...
    (microsoft.public.win32.programmer.kernel)
  • Re: more CommEvents than expected
    ... He resets proc to 0 at the beginning of the loop and only sets it to 1 when ... times even if WaitCommEvent is not called in the for loop. ... 1> clear dwEvtMask every time when you get into the new loop, ...
    (microsoft.public.win32.programmer.kernel)
  • Re: WaitCommEvent
    ... The example "Monitoring Communications Events" in MSDN is perfect, except that I can't get the code to work. ... I'd like to put this block into a do-while loop, but it generates an error 87 on the 2nd pass through the loop. ... if (WaitCommEvent(hCom, &dwEvtMask, &o)) ... If you loop and call WaitCommEvent a second time you are attempting to launch a second overlapped operation, but using an OVERLAPPED struct and its event that are already in use. ...
    (microsoft.public.vc.language)
  • RE: more CommEvents than expected
    ... times even if WaitCommEvent is not called in the for loop. ... 1> clear dwEvtMask every time when you get into the new loop, ... Please let me know if my answer helps you resolve the problem. ...
    (microsoft.public.win32.programmer.kernel)