|
|
This is a work in progress. Please feel free to improve upon it. [edit] LabVIEW Data Tools Library OrganizationThere are three main groups of VIs within the LabVIEW Data Tools library:
[edit] NomenclatureYou 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. [edit] Run-time Type CheckingGet 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 [edit] Ordered Lists – Arrays and ClustersClusters 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. [edit] Operating sequentially on Cluster elements - Converting a Cluster to an Array of VariantsBoth 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. [edit] Converting an Array into a ClusterUnlike 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 [edit] Special care to preserve restore data namesWhen 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. [edit] Array vs. Cluster Handling[edit] Arrays can be emptyThis 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 [edit] Arrays are usually larger in length than clustersFor 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). [edit] Recursion
[edit] Common programming mistakes made when doing variant manipulation
[edit] Example Use CasesTransforming Data “Formatting”
|
| This page was last modified 23:11, 14 March 2008. This page has been accessed 2,010 times. Content is available under Attribution 3.0 . Privacy policy About OpenG Disclaimers |