Enumerated data types in labview : tutorial 16




In this tutorial you will learn about enumerated type controls in LabView. If you are familiar with any other text based programming language, you must have used enumerated types before. The explanatory discussion on enumerated data type is, however, given in the introduction section. After that the use and functionality of enumerated data types in LabView is explained with the help of a VI. 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 Enumerated data type in labview

An enumeration can be declared using the keyword “enum”, an enumerator list is a distinct type that consists of a set of named constants. To define it directly within a namespace is the best way to define an enumerator so that all classes in the namespace can access it with equal convenience.

An enumerated data type is a type consisting of a set of named valued called as enumerals, members or elements (same as we define for a set in mathematics) or an enumerator of the type, in computer programming. Identifiers, that acts as normal constants are enumerator names or elements in a programming language. A degenerate tagged union of unit type can also be defined as an enumerated data type. All elements of an enumerator set are distinguishable i.e. no two elements of the same data set can be similar in an enumeration. All the elements of a single enumerator are different from each other and therefore can be compared and assigned but are not specified, however, compilers and interpreters can represent them arbitrarily.




Enumerated type control provides the user with a list of ite from which the data is selected for further processing. Information about the numeric values and the string labels in the control, however, is included in the data type of an enumerated type control. Numeric data type is by default assigned to the ring control.

In LabView, the user is not allowed to enter the undefined values in enumerated type controls, and the items in enumerated type controls cannot be assigned specific numeric values, as you will see the in explanation using VI section. Enumerated type control can also be used to select the cases of a case structure in LabView.

Examples of  Enumerated data type in labview

  • Let’s explain the working of enumerated data types using a VI. I have tried my best to explain the working and functionality of enumerated controls individually and there use with case structures also.
  • Create a VI as we have discussed in tutorial 1 and save it as we have done in all previous tutorials. On the front panel right click and from the control palette select Ring & enum and then select enum as shown in the figure below,Enumerated data types in labview

Figure 1: Placement of enum control

  • We are looking for an enumerated control here to understand its working, below is shown the front panel block of an enum block.Enumerated data types in labview

Figure 2: Enum block

  • Currently, this block has no variables stored in it. If you want to edit the variables of the enumerated block i.e. the elements or enumerals of the data type right click on the block a dropdown will appear, select edit items from the drop down as shown in the figure below,Enumerated data types in labview

Figure 3: Edit Items

  • After you click on this block an edit window will appear as shown in the figure below,Enumerated data types in labview

Figure 4: Edit window

  • This window will let you edit the elements of the enum. As the picture shows you can insert delete or move up an element in this window. If you want to insert an element in the enum simply click on the insert button it will let you right a name of the variable you want to be the element of you enum as shown in the figure below,Enumerated data types in labview

Figure 5: Insertion

  • You can write the desired name of your element and not the value because in enumerated data type the numeric value assigned to the elements are not editable. You can however change the sequence of the enumerals but not there value. See the figure below,Enumerated data types in labview

Figure 6: Inserting variables

  • From the block available at the front panel you can select which variable to be accessed from the enum. You can only access one of all the elements of the enum at a time. By clicking on the front panels’ block on enum you can select which of the element to be accessed. See the figure below,Enumerated data types in labview

Figure 7: Variable selection

  • Now if you want to place an indicator to see the output of the enum, there is no need to look for it in the control palette. Simply right click on the block diagram windows’ block of the enum and select create and then select indicator as shown in the figure below,Enumerated data types in labview

Figure 8: Indicator creation

  • This will create an indicator of type enum as shown in the figure below,Enumerated data types in labview

Figure 9: Enum indicator

  • The front panel blocks of enum control indicator pair is shown in the figure below,Enumerated data types in labview

Figure 10: Front panel blocks

  • Now if you change the variable to any other elements as shown in the figure below,Enumerated data types in labview

Figure 11: Changing the variables

  • Now if you run the VI the indicator will display the name of the variable you assigned to the enum control.Enumerated data types in labview

Figure 12: Running the VI

  • The question here may arise that how to access the integer values assigned to the elements of the enum control?? It is not a difficult task. From the function palette select numeric then conversion and then select to long integer. This will covert you value from enumerated type to integer type.Enumerated data types in labview

Figure 13: Conversion block placement

  • Connect the input side of this block to the output of enum control and at the output of the conversion block create an indicator as we have been doing in all previous tutorials. The resulting figure will look like the one shown below,Enumerated data types in labview

Figure 14: Block diagram

  • This indicator block on the front panel will display the integer value of the particular selected enum element after running the VI. The figure below shows the results of the VI after running itEnumerated data types in labview

Figure 15: Integer values

  • From the edit item window you can also change the place of the variables and hence the integer number assigned to them. By clicking on the move up button after selecting a particular element we can move its integer values as shown in the figure below,Enumerated data types in labview

Figure 16: Moving an element up

  • Now if I run the VI the output at the integer indicator will not be the same as shown in the figure below,Enumerated data types in labview

Figure 17: Changed value of same variable

After you move an element up or down, your VI might give you an error. This error could be removed by deleting the enum indicator block from the block diagram and creating a new indicator because on indicator can not be used for different sequences of elements

Exercise:

  • Use enum variable we just created as a case selector of a case structure and perform three different operations i.e. add, subtract and multiply

(Hint: You may need to add a case for third element as we have done in case structure tutorial)

<<Previous tutorial                                           Next tutorial>> 




Add Comment