01-20-2025 09:25 AM
I have a problem with a text string that I am parsing
I have a controller with 3 pressure sensors hooked up to labview. (Vac1, vac2 and vac3). pressure data is output via a text string that I have to parse.
Often during the experiments one sensor will go out of its detectable range during measurement, and instead of outputting a number it will say "RANGE" (or sometimes error).
For example the text string may read:
ERR0\r\nVAC1=RANGE\sVAC2=RANGE\sVAC3=1.03e-05\sSP1U=2.66e+00\sSP1L=1.33e+00\sSP2U=1
here Vac 3 is measuring 1E-5 mbar but vac1 and 2 are out of their detectable range.
I want to be able to plot and write the data if there is a number, but plot/write NaN (or some other equivalent) if it goes out range or reads an error.
i.e. something like:
VAC = %f, if ="RANGE" then ="NaN"
currently the whole programme just stops running if any of the sensors go out of "range" and hits the error 85. I've attached an image of my block diagram for help
I'm new to labview so any help would be great
Solved! Go to Solution.
01-20-2025 10:06 AM - edited 01-20-2025 10:26 AM
You need to handle errors, i.e. wire them to something. If they are unwired, the program will pause with a dialog if an error occurs. (You can turn off automatic error handling, but I recommend you don't)
To output NaN if the scan fails, Just use a select node, for example.
(you can use the error or any other suitable condition)
For better help, attach your VI and explain exactly how the scanned string looks looks like. It is nearly impossible to debug truncated pictures.
I am sure the raw "read buffer" could be turned into the three DBLs much easier.
01-20-2025 10:14 AM
the orange integer types, especially double, do support "NaN", "inf e.g. 1/0 = inf
there is a NaN related function in the comparison palette:
01-20-2025 12:05 PM
@altenbach wrote:I am sure the raw "read buffer" could be turned into the three DBLs much easier.
See if this quick draft can give you some ideas....
Note that if we know more about the incoming string and its possible formats, we could probably improve things even more.
(make sure the strings have the correct display style)
and if you only want to get the first three values, wire a 3 to the N of the FOR loop.
01-27-2025 10:18 AM
As an alternative to the explicit Select node wired to the error out of the Scan From String, you can also wire an NaN float constant to the default value input on the Scan From String node. Whatever value you enter there is returned in case of a scan failure. Also, it's good practice to define the datatype you want returned, rather than let it be inferred by the format string - perhaps you really want single precision, or a smaller integer type, and this can make your intention clear to the next reviewer, and/or save you a bullet cast.
01-27-2025 11:39 AM
@DavidBoyd wrote:
As an alternative to the explicit Select node wired to the error out of the Scan From String, you can also wire an NaN float constant to the default value input on the Scan From String node.
Yes, this came to me right after posting, but I got side tracked. 😄
We still should wire the error out to "somewhere" to avoid popups from automatic error handling.
01-27-2025 11:42 AM
Agreed! ...do something with the error out!
Seasoned software developers recommend two belts, plus suspenders, for safety!