LabVIEW Data Tools User Guide

This is a work in progress. Please feel free to improve upon it.

=LabVIEW Data Tools Library Organization= There are three main groups of VIs within the LabVIEW Data Tools library:
 * 1) High-Level Variant Handling VIs – These are the majority of the VIs, within the lvdata library. They are polymorphic (because they accept variant data to which LabVIEW will coerce any other data type).  They perform type checking of the data to ensure that desired operation is possible.  And finally they call the appropriate type descriptor and data parsing VIs in order to parse, inspect, and/or transform the data.
 * 2) Low-level String/Data Manipulation VIs – these VIs are used to chop up the data according to the organization specified by the data’s type descriptor.
 * 3) Low-level Type Descriptor Parsing VIs – these are used to get the type information of the data that is being operated on.

=Nomenclature= You will often see the letter “V” prefixed to the names of variants when referring to the inputs and outputs of VIs in the LabVIEW Data Tools library. This is done to define the type of data that a function “expects” to be found in that variant at run-time. Due to the fact that type-checking in variants can only occur are run-time, a VI or subroutine will not know what type of data is inside a variant until the data flows into it. Remember that nothing is contained within a variant at edit-time (unless there is a variant control or indicator with a default value).

An array of VArrays, for example is an array of variants that contain arrays. If a Variant input of a VI says “VCluster”, the VI expects a cluster to be inside of the Variant. If an output says “VEnum” an Enum will be inside the variant output upon completion – however, a null value is also acceptable if, for example, an error was generated inside the VI. If a data type different from what the VI expects flows into it at run-time, it will produce an “Unexpected Data-type” error. Run-time type checking must be rigorous and well tested to ensure reliable operation. It is enormously difficult to debug applications that use variant data, because most of the errors are related to incorrect or unexpected data types.

=Run-time Type Checking= Get TD Enum - Case structure that handles each type. Error out if wrong type. The “Default” case is almost always used as the “Type Error” case

=Ordered Lists – Arrays and Clusters= Clusters and arrays are both ordered lists. Arrays differ from clusters in that all elements of an array are required to be the same type. In Clusters, the elements are allowed to be of different type, but LabVIEW requires (of statically typed cluster) that the element names be different. In arrays, items are commonly indexed by position, whereas in clusters, items are commonly indexed by name. Because of their similarities the possible operations that can be done on each of these types tend to mirror each other. If you look at the VCluster and VArray palettes you will notice this similarity.

Operating sequentially on Cluster elements - Converting a Cluster to an Array of Variants
Both arrays and clusters are ordered sequences of elements. One pattern that was quickly discovered is that a cluster could be converted into an array of variants, with each variant element containing an element of the cluster. The names of the cluster elements are preserved in the data name of the variant data. This means that inside of a loop we can programmatically access the names of each of the elements.

Converting an Array into a Cluster
Unlike a strictly typed LabVIEW cluster, a cluster encapsulated in a variant can have any number and type of elements. This means that we can programmatically add or remove elements from a cluster. Another side-effect is that we can create a function which converts an array into a cluster, but that does not require specifying the length of the cluster. This is in sharp contrast to the “Array to Cluster” function that outputs a strictly typed cluster with a number of elements defined statically at edit-time

Special care to preserve restore data names
When iterating over a cluster, one typically converts the cluster to an array of variants and then converts the array of variants back into a cluster. However, the cluster name can easily be lost. To avoid this, pass the cluster name as a string from the point where it is converted to an array of variants to the point where the array of variants is converted back into a cluster.

Arrays can be empty
This requires knowing the element type, we cannot simply convert an array into an array of variant elements. We will loose the type information if the array is empty

Arrays are usually larger in length than clusters
For optimization, it is better to operate in the type-descriptor space as long as possible, and jump into the array element data as needed. This may or may not be feasible for arrays of compound objects (clusters).

Recursion

 * Recursion for arrays of flat data is probably not efficient
 * Recursion is important for Arrays and Clusters of Clusters of Arrays and Clusters of…

=Common programming mistakes made when doing variant manipulation=
 * Not performing type checking & related error handling
 * Wiring an Array of Variants into a Variant input (which will coerce it to a VArray of Variants)
 * Not assigning a data name to VCluster created from an array of variants.
 * Not assigning a data name to an VArray created from an array of variants
 * Not using chaining “error in” and “error out” – losing error information

=Example Use Cases= Transforming Data “Formatting”
 * LabVIEW Data to Python Data
 * LabVIEW Data to/from XML
 * LabVIEW Data to/from INI File
 * Interacting with LabVIEW Data in a Tree Control
 * SQL Queries