LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Constructing a text header string from a cluster

A common method for measurement settings we use involves the use of clusters, which may contain different controls (numeric, boolean, string, etc.) that are set by the user at run-time to specify measurement conditions.

 

It is helpful to be able to dump these to the header of a measurement text .csv file so that during data analysis, there is no ambiguity about the important measurement parameters.

 

This can be done by unbundling the cluster (which one has to usually anyways) and then manually wiring the controls with string constants at coding time to a text file VI. This is a messy solution, is not robust with a change in cluster content during code edits that happen at some times, and takes up block diagram real estate.

 

I want to be able to programmatically (by defining a sub VI) extract key-value pairs (name of control, value of control) at run-time and then dump the text to a header string (which would perhaps be the output port of this sub VI). I have played around with Property Nodes to do this, but cannot figure out how to get both keys and their values in a loop (will need to find out number of elements).

0 Kudos
Message 1 of 4
(2,563 Views)

Hi m-s,

 

using the cluster reference

  1. Get all elements from the cluster.
  2. Get the label of each element.
  3. Get the type of each element.
  4. Get the value of each element, based on its type.

All "Gets" are done using property nodes…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 4
(2,559 Views)

ValuePairs.png

Depending on the amount of data types you need it can be some work, but it's a one time job.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 3 of 4
(2,535 Views)

You can set this in a functional global.

Use the VI Flatten to string and save this to a text file. you can encode it basically to prevent modification by doing a XOR on the string.

Then redo the save XOR on the string at the application initialization and Unflatten from string with you cluster prototype to get your data back.

The magic of this method is that if you ever change the type def that defines your parameter, everything id done automatically.

Of course if it needs to be human readable, why not using the JSON tools?

Or do as specified above... it's a one time hard work.

Benoit

 

0 Kudos
Message 4 of 4
(2,509 Views)