Because the contents of a given cluster are not uniform or generically defined, you cannot directly wire a cluster to a structure like a For Loop and iteratively obtain its contents. However, using Property Nodes, you can acquire an array of refnums that contains a reference for each element in the cluster. This array of refnums can then be used to access the properties and methods of each element in the cluster. The steps to build code to achieve this are listed below - note that your cluster needs to be a control or indicator on your front panel in order to perform this method.
- Create a Property Node for the cluster. Right-click on the cluster control or indicator and select Create»Property Node»Controls[]. The Controls[] property is an array of references to the cluster elements in the cluster order.
- Wire the Controls[] terminal of the cluster Property Node to a For Loop. The array will have an auto-indexing input tunnel by default.
- Create a Property Node for the Controls[] array: On the Block Diagram, perform a right-click to open the Functions Palette. Find Programming»Application Control»Property Node. Place the Property Node function inside the For Loop.
- Wire the loop's input tunnel created by the Controls[] array to the reference input terminal of the Property Node:
- Expand the Property Node so that you can access two properties. Change the first property to ClassName. The ClassName property is the data class (e.g. Digital, Boolean, String) 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 function 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 steps 3 to 5 above you can use this information to activate a specific case that will read the variant data correctly.