Cluster functions in LabView : tutorial 12

In this tutorial, I will explain the working of clusters in LabView. Structures in C language are named as Clusters in LabView. At the start you are provided with a brief but explanatory explanation of clusters. After that I tried to explain the working principles of clusters using a simple example. At the end of the tutorial you are provided with an exercise to do it by yourself, and in the next tutorials I will assume that you have done those exercises and I will not explain the concept regarding them.

Introduction to Cluster functions of labview

Data elements, of different data types, when stored in one place, results in a cluster. Group of data is known as a cluster. In LabView an error cluster, which combines a Boolean value, a numeric value, and a string, is an example of a cluster. If you are familiar with any other programming environment you must be well aware of the term structures. In LabView, a cluster is the same thing as a structure in any other programming language. In simple words you can say, clusters are block diagram representation of a structure. In C programming language structures, are same as clusters in LabView.Types of variables than can hold several data items of the same kind are defined using arrays. In a similar fashion another data type available in C language that allows us combining data items of different kinds are known as structures in C or clusters in LabView.

We have studied about arrays in detail in previous tutorials; a cluster can either be a control, or an indicator depending upon the need and use of clusters, they function similar to that of an array. However, clusters have a fixed size whereas array can vary in size; this is one of the major differences between clusters and arrays. Also note that one array can only have one data type, however, in one cluster we can store as many different types of data as we want.

Examples of cluster functions n labview

  • I will now explain the working of cluster function with the help of VI. Create a program or VI as discussed in tutorial 1 and save it for future use, as we have been doing in all previous tutorials. Right click on the block diagram and from the function palette select Clusters and then select bundle, see the figure belowBundle by name in labview

Figure 1: Placement of a bundle

  • In the cluster section, you can see various blocks namely bundle, unbundle, bundle by name, unbundle by name, cluster array, cluster constant. I will try to explain as many as I can and the rest will be left for you as an exercise in exercise section.
  • The use of bundle block is to form a cluster. As the name suggest bundle is used to bundle or pack up all the different data types at one place so that we can access them at the time of need by only one name.
  • The input of this block is any data type and the output is just a single wire through which all these data types can be transferred to any other place. Refer to the figure below,bundle block labview

Figure 2: Bundle block

  • This block has only one input by default i.e. only one data element of a single type can be stored in it by default, but according to your need you can change the cluster size and the number of elements to as many numbers as you want. See the figure below,Size extension of a bundle

Figure 3: Size extension of a bundle

  • Now, the question is how to give different inputs to one single cluster. Let’s move to this portion. From the function palette select one numeric control, one Boolean control and a string control, this is just to give you an example of using different data elements of different types in one place. You can also you any other data type of your choice like float double or special characters etc, refer to the figure below,Different data types

Figure 4: Different data types

  • Connect each data type to each different block of the cluster, through a wire as shown in the figure below,

Figure 5: Connections of data types

  • Now when you hover over the bundle by name block, you can see there are two connection pins left, whereas so far we have only discussed about the input and output pins, what is the purpose of the remaining pin??

Figure 6: Pins

  • The second pin at the top is used to tell the cluster the content type of the data elements connected on it. Right click on that pin and from the drop down menu select create and then select constant. This will create a cluster constant having all the data types to which your corresponding bundle block is connected at the input side, see the figure below

Figure 7: Constant placement

  • The resulting constant cluster block will appear, connect this block to the upper pin of the bundle block, and the resulting block diagram will look like the one as shown in the figure belowConstant cluster labview

Figure 8: Constant cluster

  • This portion of the code is used for writing input data for the cluster. One may ask how to read the data at the output of the cluster after processing it as a single wire. For this purpose again from the function palette, select clusters, and then select Unbundle as shown in the figure below,

Figure 9: Placement of unbundle block

  • The unbundle block have 2 inputs by default, and the block looks like the one shown in the figure below,

Figure 10: Unbundle block

  • You can see that, as it is the output block it do not have any constant pin at the top. Constant pin is only available on the bundle block and you only have to declare the data type once, as we do for structures in other programming language.
  • Size of unbundle block cannot be extended, however, connect the input side of unbundle block to the output of the bundle block, it will automatically adjust the size of unbundle block too according to its input, and will also select the data types of all the portions of the cluster. Refer to the figure below,

Figure 11: Size adjustment of unbundle cluster

  • Now at any of the output pin of unbundle block, right click and create an indicator, it will result like the diagram shown in the figure below,

Figure 12: Indicator placement

  • Do the same with the remaining two output pins of the unbundle block, the resulting, refer to the figure below to see the resulting block diagram.

Figure 13: Complete block diagram

  • The front panel of this block diagram is shown in the figure below,

Figure 14: Complete front panel

  • Set desired values of the indicator, write a desired line in the string control, and turn the Boolean button on. Now, run the program using the run button or by pressing <CTRL+R>, the same value as that of the control, will be displayed on the indicator in front.
  • This shows, that through a single wire (between bundle and unbundle blocks) you can transmit as many data types as you want, as we have done in the tutorial. Same functionality can be achieved by using bundle by name, only it will bundle the elements according to their names but not there data types.
  • The figure below shows the output of the VI we designed in the tutorial.Output cluster functions in labview

Figure 15: Output


  • Design a VI doing the same function as above, using bundle by name and unbundle by name blocks.

<< Previous tutorial                                                               Next tutorial>>

Leave a Comment