
Efficient handling of strings from serial port device?
:>
:> Hi:
:>
:> I am writing a program that gets data from a remote device by sensing
a
:> single word command. The device responds by sending a set of data for
up
:> to 16 different sensors. I am trying to figure out the best way of
:> dealing with the data. Typically, the smallest interval will be 1
minute,
:> so there is plenty of time between readings, and I have a
parseString()
:> routine set up that can handle the individual strings very well.
:> However, my 'test' code deals with data in a text file, inputting it
one
:> line at a time (i.e. 'line Input ...') and dealing with it. So, my
Comm
:> code just take all input until the 'data done' code (in my case, a
">OK")
:> and dumps it into a file. I think that this will work, but it seems
very
:> clumsy. Is there a better way I should be looking at?
What do you want to do with this data, other than save it to disk? If
saving
to disk is all you seek, then your method seems fine to me. If your
sensors
give you more than just a value via serial, then parse the data
accordingly.
EXAMPLE:
Message from sensor:
"Sensor#1,Temp=88,Status=1,>OK"
or
"1,88,1,>OK"
In the above case, you would parse the info based upon the comma
delimiters.
The raw data may then be written to a sensor specific file based upon
which
sensor has responded.
Open "Sensor1.dat" for.... as ....
(At this point, it might be a good idea to time stamp the reading.)
DataToWrite$ = SerialData$ + ",(" + Time$ + ")"
Put DataToWrite$,,
Close File#
:>
:> Thanks,
:>
:> Mike