Overlapped serial communications

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Overlapped serial communications

Bill Schwab-2
Blair, Ian,

How hard do you think it would be to make overlapped serial communications
calls?  By that I mean get Windows to do the blocking, which would obviously
need to happen on an OS thread.  It took some doing, but I now have an
RS-232 barcode reader :)  which means I have to make it work =:0

I've done quite well by telling Windows to return immediately when there is
no data, and then "polling" at reasonable intervals.  When I know a data
source is a little sluggish, I have the corresponding thread sleep a little
more.

Barcodes can arrive at any time, so more aggressive polling would be
appropriate.  A 0.1 second sleep in my existing code will likely suffice, so
please don't loose any sleep over this question.

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Overlapped serial communications

Ian Bartholomew-18
Bill,

> How hard do you think it would be to make overlapped serial
> communications calls?  By that I mean get Windows to do the blocking,
> which would obviously need to happen on an OS thread.

The Windows serial api has the ability to do overlapped i/o (outside of
the "normal" Windows overlapped calls - I think) so, although I haven't
tried it, it might not be too difficult.  If you haven't seen it the
msdn document at the following address is quite helpful, albeit a bit
old now.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnfiles/html/msdn_serial.asp

> Barcodes can arrive at any time, so more aggressive polling would be
> appropriate.  A 0.1 second sleep in my existing code will likely
> suffice, so please don't loose any sleep over this question.

By polling I am guessing you mean doing reads and letting the comms
timeouts take effect to indicate whether there is data or not?.  If so
you might get a better response (so you can poll more often) if you use
the ClearCommError api call.  This, as it's name suggests, clears any
comms error flags but also returns the number of bytes that have been
received by the low level driver but not yet read through the api.

--
Ian

Use the Reply-To address to contact me.
Mail sent to the From address is ignored.


Reply | Threaded
Open this post in threaded view
|

Re: Overlapped serial communications

Schwab,Wilhelm K
Ian,

> > How hard do you think it would be to make overlapped serial
> > communications calls?  By that I mean get Windows to do the blocking,
> > which would obviously need to happen on an OS thread.
>
> The Windows serial api has the ability to do overlapped i/o (outside of
> the "normal" Windows overlapped calls - I think)

It sure sounds that way, which is what scares me =:0


> > Barcodes can arrive at any time, so more aggressive polling would be
> > appropriate.  A 0.1 second sleep in my existing code will likely
> > suffice, so please don't loose any sleep over this question.
>
> By polling I am guessing you mean doing reads and letting the comms
> timeouts take effect to indicate whether there is data or not?.

Correct, but I further arrange for the timeouts to be zero, and then control
how often I call the function.  That turns out to be fairly easy to do for
most devices, but clearly a barcode reader would deserve more frequent
polling.


> you might get a better response (so you can poll more often) if you use
> the ClearCommError api call.  This, as it's name suggests, clears any
> comms error flags but also returns the number of bytes that have been
> received by the low level driver but not yet read through the api.

Thanks for that and the link.  For now, I will probably just stay with the
0.1 second delay, and keep overlapped I/O as a longer term goal.

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]