Re: WaitCommEvent timout by Uncle
Uncle
Wed Feb 20 09:55:48 CST 2008
Yep. What I always do is to set the Timeouts and then NOT use WaitCommEvent.
When the Read (which is most likely) times out you check the number of
characters returned, then if appropriate go back to the read, unless your
flag is set to exit the thread.
I have had loads of trouble with WaitCommEvent and indeed serial comms on
both PCs and CE/WM devices, Microsoft will deny that there is a problem as
will many people on this ng, but I can assure you that it is flaky.
The method I use has always worked though (so far) :-)
Regards - Unc
In reply to Timothy Dean (tim.dean@mobiledataforce.com) who wrote this in
ObAubc9cIHA.4436@TK2MSFTNGP05.phx.gbl, I, Marvo, say :
> I am using SetCommTimeouts, but that only sets the timeouts for
> ReadFile and WriteFile, right? It doesn't seem to affect
> WaitCommEvent. Let me know if I am missing something. Thanks.
>
> Timothy Dean
>
> "Uncle Marvo" <paul.r@deletethisbitfortescue.org.uk> wrote in message
> news:622bt7F21qvhaU1@mid.individual.net...
>> In reply to Timothy Dean (tim.dean@mobiledataforce.com) who wrote
>> this in uEoPhv1cIHA.6024@TK2MSFTNGP06.phx.gbl, I, Marvo, say :
>>
>>> I have a loop in a separate thread that reads data from a COM port.
>>> The loop in the thread checks a flag to determine when to exit. My
>>> problem is when I try to stop the read loop it hangs on
>>> WaitCommEvent when there is not data coming from the COM port. Since
>>> overlapped is not supported in CE, what is the best way to
>>> make the WaitCommEvent time out? I can force the issue by using
>>> TerminateThread or closing the COM port, but I want to let it exit
>>> gracefully if possible.
>>
>> Have you done a SetCommTimeouts? I believe that it defaults to "not".