03-03-2014 06:32 AM
I am having big trouble with extracting measurement results from a string from serial port.
I get a report through serial connectio from some device. It looks like that:
Plane 1 Angle 1 Plane 2 Angle 2 In RotorID rpm [g·mm] [°] [g·mm] [°] Tol 1964.7 0.145999 201.6 0.151779 346.5 Y 2014.5 0.156608 197.6 0.139722 340.9 Y ealon ok 2012.1 0.143454 199.8 0.150243 344.6 Y ealon nok 2023.3 0.430547 217.7 0.833347 313.3 Y DN-3259824_001 2135.9 0.305822 246.2 0.296502 305.2 Y DN-3259824_002 2051.4 0.324227 241.1 0.327651 299.0 Y DN-3259824_020 2045.9 0.139268 150.2 0.281890 21.6 Y
I cannot separate data with spaces, because sometimes there is no "RotorID" so all data shifts to the left.
There are always 7 columns. Sometimes RotorID is empty sometimes it consists some chars and some numbers. I never know its length. Other data is always present and separated with space.
Can you help me please.
Solved! Go to Solution.
03-03-2014 08:02 AM
First use "Scan String For Tokens" then pull the float out of that.
This is from my library that I use to do exactly that.
03-03-2014 08:51 AM - edited 03-03-2014 08:55 AM
If you wish to use a regular exprission.
03-03-2014 10:56 AM
Of Course, There are easier ways to get those floats out of the serial device string.
The worst part is getting rid of all the extra spaces. Use match pattern (regex option) to help out a bit:
03-04-2014 01:36 AM
Thank you so much for this. I am almost ashame of my previous attempts to parse this thing. You don't want to see my code. 🙂
Now I understand that regular expression thing.