At 22:41 -0800 02/01/2004, Joe wrote:
> I'm trying to read data packets from a sensor that
> is connected through a serial port and is
> configured to transfer data every 100ms. what is
> the best way to synchronize the reading intervals?

Set up a read to timeout after 200 ms if you know your termination characters, or the 
message length.  If you don't then it gets a bit trickier.

It depends on how long your string is and how much dead time you are trying to detect. 
 Then set you time out to a little less than the dead time between transmissions.  
Then put the whole thing in a loop doing the reads.  Pass the data thru a queue to a 
processing loop so it won't stall your read loop and mess up the timing.  It will take 
a bit of playing around to get the timing right and reliable.

If you can handle non synchronous reading of the data, then just keep grabbing however 
many characters you can and keep pushing them into a buffer then parse the buffer.  I 
dislike serial port intensely becasuse of this lack of handshaking and timing 
problems!  And don't even get started on the myriad of connectors and wiring 
possiblilities.  Recommended Standard Indeed!  Pfui!

-Scott


Reply via email to