It depends on the message. For instance, GPS data is variable length, but
since the message format is defined by the header label, it's relatively
easy to detect the end of the message. Just keep retrieving data from the
buffer and adding it to a data queue. Handle the serial port in the
separate thread and add received characters to the queue as received. When
the data in the queue is a complete message remove it from the queue and
process it. Or, if your messages have an end of message indicator, process
into the queue until the EoM indicator appears, then remove and process the
queue contents. You don't need a timer unless you want to watch for
interruptions to the transmission, or perhaps you want to process a partial
message if the remainder isn't received within a reasonable time (for GPS,
partial messages are usually discarded, as they can't be checked for
accuracy). Depending on what other processing is required, you may also want
to use a timer to control how frequently the queue is checked for a complete
message.
"seegoon" <se*******@yahoo.comwrote in message
news:95**********************************@l42g2000 hsc.googlegroups.com...
On Oct 29, 2:04 pm, "Armin Zingler" <az.nos...@freenet.dewrote:
snip <
Thanks.
Used a different timer(system.timers.timer) , and it works great.
Is there a more elegant way of handling unknown serial data lengths?
Cheers
Rob