In this tutorial, I will be discussing with you the significance of different data types used in LabView and their working. You might have seen in previous tutorials that different data type blocks have different colors i.e. strings type indicators and constants have pink color. After the introduction to different data types, I have written an example program and at the end of the session you are provided with a mini exercise to do it by yourself, so that you can make you concepts of data types clear.
Introduction to data types in labview
Data types as the name suggest represents the type of the data or variables that can be used in LabView. Data type is a very important term to be kept in mind while programming in LabView. In a VI every data type has unique color which can’t be mixed or interconnected with other. For example, if a data variable is of type integer then the indicator connected to display its value must also be of type integer, otherwise the VI will give you an error or it may not connect the two blocks in the first place. If you are a programmer of any other programming language you must be familiar with the term data type. However, in this tutorial we assume that you are a beginner and let me explain a little about types of data.
In programming the most common data types are Integer, Float, Boolean, Double, Array, and String. Whereas, in LabView, an addition data types namely waveform and errors are also introduced. Each data type has a specific type of data stored in it, i.e. an integer type variable can only store and display integer type data and a string type can never be connected to a float indicator. Float however can store only floating point data types.
Programming Example of labview data types
Let’s now do a write a program which includes different data. Create a program using the information provided in tutorial 1 overview of labview and save it by using the path file>>save as or by pressing <Ctrl+S>
- Now on the block diagram click right and from the function palette select Numeric and then Numeric constant and on the front panel click right and from control palette select Numeric and then Numeric Indicator.
- If the color of the associated block of the indicator on the block diagram is blue, it shows that the indicator is of integer type. But if it is other then blue then we cannot connect it to an integer type data constant.
- Right click on the indicators block on the block diagram select representations and then select long as shown in the figure below. This action will convert the indicator into integer data type too.
Figure 1: Changing data types
- Now, connect the associated block of the numeric indicator on the block diagram with the numeric constant already present there through wires. The resulting diagram will look like one shown in the figure below.
Figure 2: Integer constant and indicator.
- Changing the value of the constant will change the display value in the indicator too. This was simple, now let’s see how to place floating point data type blocks. Float is also a numeric data type. Double and float are similar to each other, just float means a generalized precision floating point data, whereas double means double precision floating point data.
- From the function palette select numeric and then double numeric constant. Also, place a numeric indicator on the front panel to display its value. If both of the blocks are of orange color connect them with a wire otherwise, change the data type to double by right clicking on the block select representation and then select double precision as described above for integers. The resulting diagram will look like the one shown in the figure below.
Figure 3: Floating point blocks
- String is also a data type. We have used string indicator and constant in previous tutorials. Let’s drop a string constant and indicator along with thses two block pairs.
Exercise on String data types in Labview
Do yourself: Use you knowledge from the previous tutorials and place a string indicator and string constant on the same VI.
Figure 4: String blocks
- NOTE: Always give labels to the blocks in order to remember the purpose or use of the block in the future.
- Let me show you first how to label a block. Right click on the block you want to label. Select visible and then check the label item in the dropdown menu. It will allow you to right on the place above the block.
Boolean Data types in Labview
- Coming back to the data types, another type of data is Boolean data type. Boolean is a logical type of data. It only gives output in the form of 0s and 1s or False and True. If the output of a specific condition is true i.e. the switch is on, a button is pressed, or the output of an equal to 0? (Used in previous tutorials) function block is 1 then the Boolean indicator will give true as a data type. From the control block on the front panel select Boolean and then select vertical slide switch.
Figure 5: Vertical slide switch
- The purpose of this switch is to provide a true (when on) and a false (when off) to the Boolean indicator. But where is the Boolean indicator. An LED can act as a Boolean indicator. From control palette select Boolean and then select Round LED, this LED will blink whenever we turn the switch on.
Figure 6: Round LED as indicator
- Connect the respective blocks of Boolean through a wire and label them accordingly, as shown in the figure.
Figure 7: Boolean Blocks
Array data types in labview
- Another data type is ‘Arrays’, I will not discuss them in detail because we have a separate tutorial about arrays, and you will learn about them in detail in the coming tutorials. The color of the array depends on the type of constants or data we want to store in an array.
- In an array we can store integer, double, string as well as Boolean constants. Right now we are using a double type array. Don’t wonder how I did that I will explain arrays in detail in the upcoming tutorial, just skip it right now. See the figure below, it shows an array data type.
Figure 8: Array constant
- It will pop a respective indicator in the front panel. Right click on the array block in the front panel and from numeric select numeric constant and drop it inside the array block. Doing so will change the color of the associated array block in block diagram.
Figure 9: Array indicator with double constants
- Now extend the size of the array in order to increase the number of elements in the array. For example
Figure 10: Array size
To store a variable in an array simply write in the blocks available on the array constant. So this is all about data types in labview
- Try to explore and use waveform data type by yourself.
Hint: You can use the waveform graphs charts from the control palette in the waveforms sections build waveform block from the function palette to fulfill the task. Don’t panic, I will be using graphs and charts in the upcoming tutorials.
2 thoughts on “Data types in labview – tutorial 4”
Thanks for giving these articles, all they are important ..
Very good article it resolved all my queries thanks