LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

if a text string changes from number to "error" or similar text, how do i output as NaN

Solved!
Go to solution

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

 

Jkodak28_2-1737385946194.png

 

 

0 Kudos
Message 1 of 7
(326 Views)
Solution
Accepted by Jkodak28

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)

 

altenbach_0-1737389064804.png

 

 

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. 

Message 2 of 7
(311 Views)

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:

 

nan-string.png

 

 

0 Kudos
Message 3 of 7
(302 Views)

@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)

 

altenbach_0-1737396018618.png

 

and if you only want to get the first three values, wire a 3 to the N of the FOR loop.

 

altenbach_1-1737396232022.png

 

Message 4 of 7
(277 Views)

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.

David Boyd
Sr. Test Engineer
Abbott Labs
(lapsed) Certified LabVIEW Developer
Message 5 of 7
(104 Views)

@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.

Message 6 of 7
(87 Views)

Agreed! ...do something with the error out!

 

Seasoned software developers recommend two belts, plus suspenders, for safety!

David Boyd
Sr. Test Engineer
Abbott Labs
(lapsed) Certified LabVIEW Developer
0 Kudos
Message 7 of 7
(81 Views)