Re: WaitCommEvent() problem

From: Chris Tacke, eMVP (ctacke_at_spamfree-opennetcf.org)
Date: 06/16/04


Date: Wed, 16 Jun 2004 09:04:01 -0400

Here's a snip from one of my projects:

<snip>
void OpenPort()
{
 hCommPort = CreateFile (......);

COMMTIMEOUTS ct;
ct.ReadIntervalTimeout = MAXDWORD;
ct.ReadTotalTimeoutMultiplier = 0;
 ct.ReadTotalTimeoutConstant = 0;
 ct.WriteTotalTimeoutMultiplier = 10;
 ct.WriteTotalTimeoutConstant = 1000;

 if(!SetCommTimeouts(hPort, &ct)) { .... }

 DCB dcb;
 dcb.DCBlength = sizeof(DCB);

 if(!GetCommState(hPort, &dcb)) {...}

// set new DCB info
....
 if(!SetCommState(hPort, &dcb)) {...}

// start read thread
}

void ReadThread(void*)
{
   SetCommMask (hCommPort, EV_RXCHAR);

   while(hCommPort != INVALID_HANDLE_VALUE)
   {
      WaitCommEvent (hCommPort, &fdwCommMask, 0);
      SetCommMask (hCommPort, EV_RXCHAR);

      ReadFile(...);
   }
}
</snip>

-- 
Chris Tacke, eMVP
Co-Founder and Advisory Board Member
www.OpenNETCF.org
---
---
Principal Partner
OpenNETCF Consulting
www.OpenNETCF.com
"dice" <dice@discussions.microsoft.com> wrote in message
news:1EC2B767-AD82-42FF-AEE3-ADDD22E51BE5@microsoft.com...
> To the best of my knowlege there is no way to apply a timeout with the
WaitCommEvent() call - this is the crux of my problem as I would prefer not
to loop on ReadFile() with a timeout - this would defeat the purpose of
having a reader thread at all.
>
> If there is a way of applying a timeout that I have missed I would love to
receive details - this could save me a very large rethink of my apps
architecture.