Indexing Through a Cluster in LabVIEW

Updated Jan 18, 2018

Reported In

Software

  • LabVIEW Full
  • LabVIEW Professional
  • LabVIEW Base

Issue Details

How do I iterate through a cluster like an array to programmatically modify each cluster element in a For Loop?

Solution

Using Property Nodes, you can acquire an array of refnums that contains a reference for each element in the cluster. The array can be used to access the properties and methods of each element in the cluster. To do this, follow the steps below: 
  1. Create a Property Node for the cluster. Right-click on the cluster control or indicator and select Create » Property Node. 
  2. Choose the Controls[] property for your cluster Property Node. The Controls[] property is an array of references to the cluster elements in the cluster order. 
  3. Wire the Controls[] terminal of the cluster Property Node to a For Loop. The array will have an auto-indexing tunnel by default.
  4. Create a Property Node for the  Controls[] array. On the Block Diagram, right-click open the Functions Palette. Find the Application Control sub-palette and choose the Property Node VI. Place the Property Node VI inside of the For Loop and wire its reference input terminal to the loop tunnel created by the Controls[] array.


  • Expand the  Controls[] array Property Node so that you can access two properties. Change the first property to ClassName. The ClassName property is the data class (Digital, Boolean, String, etc.) of the particular cluster element. Change the second property to Value. The Value property is the data value of the particular cluster element.
  • You can wire the ClassName property to a Case Selector of a Case Structure to perform operations on cluster elements based on the class. 
  • Use the Variant to Data VI. in order to convert the Value property of a particular cluster element into its appropriate data type. See the image below for the final result.



    Note: It is mandatory to rename the cases to match the data type that will be passed through.  If you receive an Error 91 in the Variant to Data VI, probe the ClassName string going into the case selector with highlight execution on and make sure that your values are labeled correctly.  Numeric values should be labeled as "Digital".

  • If the cluster contains an array, use the To More Specific Class primitive to access the properties that are specific to the array data structure. Then, you can use the Property Node to access the array element refnum. This will return a refnum for a single element of the array. Then, you can use another Property Node to access the class name for that array element. Similar to step 4 above, you can use this information to activate a specific case that will read the variant data correctly. 

WAS THIS ARTICLE HELPFUL?

Not Helpful