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. Thanks.

Timothy Dean

Re: WaitCommEvent timout by Henryk

Henryk
Tue Feb 19 19:22:55 CST 2008

"Timothy Dean" <tim.dean@mobiledataforce.com> wrote:

>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. Thanks.
>

I think that doing a SetCommMask(hPort, mask) should release
WaitCommEvent, but I think it may also be driver implementation
dependent, which means that it is not guaranteed.

Cheers,
Henryk Birecki

Re: WaitCommEvent timout by Uncle

Uncle
Wed Feb 20 03:56:05 CST 2008

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".



Re: WaitCommEvent timout by Timothy

Timothy
Wed Feb 20 09:41:47 CST 2008

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".
>



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".




Re: WaitCommEvent timout by Uncle

Uncle
Wed Feb 20 10:01:08 CST 2008

In reply to Me (I'm losing my grip) (paul.r@deletethisbitfortescue.org.uk)
who wrote this in 6230rjF21es72U1@mid.individual.net, I, Marvo, say :


BTW -
1. you're not hiding your email address at all, you WILL get chopped ham and
pork, and lots of it.
2. If you email me I have a piece of code you're welcome to, which works.

Regards - Unc