I'm trying to get data from a heat counter via the serial, the format of the response is:
t1=ХХХ.ХХ t2=ХХХ.ХХ t3=ХХХ.ХХ t4=ХХХ.ХХ
P1=ХХ.ХХ P2=ХХ.ХХ
VolSpd1=ХХ.ХХХ VolSpd2=ХХ.ХХХ
MassSpd1=ХХ.ХХХ MassSpd2=ХХ.ХХХ
HeatSpd1=Х.ХХХ HeatSpd2=Х.ХХХ
SumVolume1=Х.ХХХХХХХ SumVolume2=Х.ХХХХХХХ
SumMass1=Х.ХХХХХХХ SumMass2=Х.ХХХХХХХ
SumHeat1=Х.ХХХХХХХ SumHeat2=Х.ХХХХХХХ
PowTime=Х.ХХХХХХХ PowOffTime=Х.ХХХХХХХ
MeasTime1=Х.ХХХХХХХ MeasTime2=Х.ХХХХХХХ
UnMeasTime1=Х.ХХХХХХХ UnMeasTime2=Х.ХХХХХХХ
I managed to get the data and parce it on arduino but only from the first line. I do not know how to get all other data.
1 Answer 1
Since the format is just = , I'd parse it this way, instead of relying on newlines.
Just treat them as whitespace. So buffer all data till an =
sign is found, store the buffer as the variable name, then read until you get something other than a digit or decimal point. Then store this as the value. Then do something with the value based on the variable name. Then read and ignore all following whitespace (spaces, tabs, newlines, carriage-returns). And start back from the top.
That way the parse will never get out of whack when some data get missing or something else goes wrong in the serial stream.