Board index » delphi » Serial port and reading the RX buffer?

Serial port and reading the RX buffer?

I'm trying to write a little app to read the serial port for a stream
of continuous data. Certain messages are repeatedly sent that I want to
capture and parse. It is concievable that the device that is sending
this ascii data may have been sending it for several minutes (repeating
the message with slightly different values each second) before I care
to actually use it. What's the best way to approach this?

I've thought about queing up each message into a TString list, but this
leaves me with old data at the beginning which is not what I want. I
also imagine that I run the possibility of over flowing my TString list
if it isn't "purged" once in a while.

I'm using the Varian Async32 control which is really a nice little
component, but am unsure how to handle all of this. Maybe I could use a
button to "open" the port for rx and a timer control set for 5 seconds
or so to "close" the port. Then use what's in the TString list to look
for what I want.

Any ideas?

Sent via Deja.com
http://www.deja.com/

 

Re:Serial port and reading the RX buffer?


Quote
In article <947iqu$pa...@nnrp1.deja.com>, kevinolenic...@my-deja.com writes:
>I'm trying to write a little app to read the serial port for a stream
>of continuous data. Certain messages are repeatedly sent that I want to
>capture and parse. It is concievable that the device that is sending
>this ascii data may have been sending it for several minutes (repeating
>the message with slightly different values each second) before I care
>to actually use it. What's the best way to approach this?

>I've thought about queing up each message into a TString list, but this
>leaves me with old data at the beginning which is not what I want. I
>also imagine that I run the possibility of over flowing my TString list
>if it isn't "purged" once in a while.

>I'm using the Varian Async32 control which is really a nice little
>component, but am unsure how to handle all of this. Maybe I could use a
>button to "open" the port for rx and a timer control set for 5 seconds
>or so to "close" the port. Then use what's in the TString list to look
>for what I want.

If you can recognise the MYW (message you want) amongst the other data, why not
just put that into a string which may be empty or have the latest data. If you
want the last n MYW then put every one into a stringlist and delete the
StringList.Items[0] when it get to a StringList.Count of n+1.

If you opened the port, waited m secs etc, then m would have to be at least 2 *
longest period between MYW. If you want other things to happen while waiting
for MYW then you could use another thread to monitor the input data and call an
event handler when it has n messages.

Alternatively you could have another program running continuously, keeping the
last n MYW and putting them into file-mapped memory, to be accessed by your
"reading" program.

Alan Lloyd
alangll...@aol.com

Other Threads