LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Cluster with some NaN values - I need to remove the NaN values

I have a cluster that has eight double values. Sometimes the function that is feeding values to each of these is resulting in "NaN". I am taking that cluster and then creating a JSON string. The NaN is not working downstream outside of LabView. If my data looks like this:

 

"Iso SP entering Meter - Max" 123.45

"Iso SP entering Meter - Min" NaN

"Poly SP entering Meter - Max" 654.1

"Poly SP entering Meter - Min" 159.45

 

I'd like to output the JSON string using and prevent the NaN from getting emitted:

"Iso SP entering Meter - Max" 123.45

"Poly SP entering Meter - Max" 654.1

"Poly SP entering Meter - Min" 159.45

 

Any ideas?

 

"Iso SP entering Meter - Max" 123.45

"Iso SP entering Meter - Min" NaN

"Poly SP entering Meter - Max" 654.1

"Poly SP entering Meter - Min" 159.45

 

Here is a screenshot of the VI area. I cannot release the VI source:

flycast_0-1651256736078.png

 

0 Kudos
Message 1 of 4
(985 Views)

@flycast wrote:

 I am taking that cluster and then creating a JSON string. The NaN is not working downstream...

 

Any ideas?

 

 


Here are the first two ideas:

1) Ignore the NaN when you are collecting the data

2) Before writing the JSON file, do a search-n-replace of the `NaN`

 

---------------------------------------------
Former Certified LabVIEW Developer (CLD)
0 Kudos
Message 2 of 4
(959 Views)

Writing to the JSON file that way won't work since you're writing the whole cluster. You also can't create a cluster on the fly or modify a cluster once running. This means you'll have to write the cluster line by line.

 

See this thread for info on how to get cluster element names (which you can use to create a JSON field). I'd highly recommend using the JSONText toolkit rather than the official NI one. That will let you write a single JSON element with a single name.

0 Kudos
Message 3 of 4
(950 Views)

Instead of using the built-in LabVIEW JSON, you could instead use a toolkit (such as the i3 JSON Toolkit or JSONtext by JDP Science).   Those have some tools that allow manual assembly/editing of JSON instead of just using the built-in LabVIEW node, which has zero flexibility besides using predefined data types exactly.

 

The other thing you could consider it converting your data to an array (since it's all the same data type) and converting that array to JSON and sending that instead, assuming the format decoder on the other side is something you control.  You'd probably want to change your data to be name/value pairs instead of just the numeric value.

0 Kudos
Message 4 of 4
(925 Views)