NI LabVIEW Environment Basics
Included in the Section
Video: Intro the LabVIEW Environment
Welcome to LabVIEW – the purpose of this manual is to get you up to speed with the basic concepts of LabVIEW and graphical programming.
LabVIEW programs are called virtual instruments, or VIs, because their appearance and operation often imitate physical instruments, such as oscilloscopes and multimeters. LabVIEW contains a comprehensive set of tools for acquiring, analyzing, displaying, and storing data, as well as tools to help you troubleshoot code you write.
When you create a new VI you will see two windows—the front panel window and the block diagram.
When you open a new or existing VI, the front panel window of the VI appears. The front panel window is the user interface for the VI. Figure 1 shows an example of a front panel window.
Figure 1. Example of a Front Panel
The Controls palette contains the controls and indicators you use to create the front panel. You access the Controls palette from the front panel window by selecting View»Controls Palette or by right clicking on any empty space in the front panel window. The Controls palette is broken into various categories; you can expose some or all of these categories to suit your needs. Figure 2 shows a Controls palette with all of the categories exposed and the Modern category expanded.
Figure 2. Controls Palette
To view or hide categories (subpalettes), click the Customize button and select Change Visible Palettes.
Every VI has a front panel that you can design as a user interface. You also can use front panels as a way to pass inputs and receive outputs when you call the VI from another block diagram. You create the user interface of a VI by placing controls and indicators on the front panel of a VI. When you interact with a front panel as a user interface, you can modify controls to supply inputs and see the results in indicators. Controls define inputs, and indicators display outputs.
Controls are typically knobs, push buttons, dials, sliders, and strings. Controls simulate instrument input devices and supply data to the block diagram of the VI. Indicators are typically graphs, charts, LEDs, and status strings. Indicators simulate instrument output devices and display data the block diagram acquires or generates.
Figure 1 has two controls: Number of Measurements and Delay (sec). It has one indicator: an XY graph named Temperature Graph.
The user can change the input value for the Number of Measurements and Delay (sec) controls. The user can see the value generated by the VI on the Temperature Graph indicator. The VI generates the values for the indicators based on the code created on the block diagram.
Every control or indicator has a data type associated with it. For example, the Delay (sec) horizontal slide is a numeric data type. The most commonly used data types are numeric, Boolean, and string.
Numeric Controls and Indicators
The numeric data type can represent numbers of various types, such as integer or real. The two common numeric objects are the numeric control and the numeric indicator, as shown in Figure 3. Objects such as meters and dials also represent numeric data.
Figure 3. Numeric Controls and Indicators
To enter or change values in a numeric control, click the increment and decrement or double-click the number, enter a new number, and press the <Enter> key.
Boolean Controls and Indicators
The Boolean data type represents data that has only two possible states, such as TRUE and FALSE or ON and OFF. Use Boolean controls and indicators to enter and display Boolean values. Boolean objects simulate switches, push buttons, and LEDs. The vertical toggle switch and the round LED Boolean objects are shown in Figure 4.
Figure 4. Boolean Controls and Indicators
String Controls and Indicators
The string data type is a sequence of ASCII characters. Use string controls to receive text from the user such as a password or user name. Use string indicators to display text to the user. The most common string objects are tables and text entry boxes as shown in Figure 5.
Figure 5. String Controls and Indicators
Block diagram objects include terminals, subVIs, functions, constants, structures, and wires, which transfer data among other block diagram objects.
Figure 6. Example of a Block Diagram and Corresponding Front Panel
After you create the front panel window, you add code using graphical representations of functions to control the front panel objects. The block diagram window contains this graphical source code.
Figure 7. Block Diagram
Objects on the front panel window appear as terminals on the block diagram. Terminals are entry and exit ports that exchange information between the front panel and block diagram. Terminals are analogous to parameters and constants in text-based programming languages. Types of terminals include control or indicator terminals and node terminals. Control and indicator terminals belong to front panel controls and indicators. Data you enter into the front panel controls (a and b in the previous front panel) enter the block diagram through the control terminals. The data then enter the Add and Subtract functions. When the Add and Subtract functions complete their calculations, they produce new data values. The data values flow to the indicator terminals, where they update the front panel indicators (a+b and a–b in the previous front panel).
Controls, indicators, and constants behave as inputs and outputs of the block diagram algorithm. Consider the implementation of the algorithm for the area of a triangle:
Area = .5 * Base * Height
In this algorithm, Base and Height are inputs and Area is an output, as shown in Figure 8.
Figure 8. Area of a Triangle Front Panel
The user will not change or access the constant .5, so it will not appear on the front panel unless included as documentation of the algorithm.
Figure 9 shows a possible implementation of this algorithm on a LabVIEW block diagram. This block diagram has four different terminals created by two controls, one constant, and one indicator.
Figure 9. Area of a Triangle Block Diagram with Icon Terminal View
Notice that the Base (cm) and Height (cm) block diagram terminals have a different appearance from the Area (cm2) terminal. There are two distinguishing characteristics between a control and an indicator on the block diagram. The first is an arrow on the terminal that indicates the direction of data flow. The controls have arrows showing the data leaving the terminal, whereas the indicator has an arrow showing the data entering the terminal. The second distinguishing characteristic is the border around the terminal. Controls have a thick border and indicators have a thin border.
You can view terminals with or without icon view. Figure 10 shows the same block diagram without using the icon view of the terminals; however, the same distinguishing characteristics between controls and indicators exist.
Figure 10. Area of a Triangle Block Diagram without Icon Terminal View
Nodes are objects on the block diagram that have inputs and/or outputs and perform operations when a VI runs. They are analogous to statements, operators, functions, and subroutines in text-based programming languages. Nodes can be functions, subVIs, Express VIs, or structures. Structures are process control elements, such as Case structures, For Loops, or While Loops.
Functions are the fundamental operating elements of LabVIEW. The Add and Subtract functions in the Figure 6 are function nodes. Functions do not have front panel windows or block diagram windows but do have connector panes. Double-clicking a function only selects the function. A function has a pale yellow background on its icon.
After you build a VI, you can use it in another VI. A VI called from the block diagram of another VI is called a subVI. You can reuse a subVI in other VIs. To create a subVI, you need to build a connector pane and create an icon.
A subVI node corresponds to a subroutine call in text-based programming languages. The node is not the subVI itself, just as a subroutine call statement in a program is not the subroutine itself. A block diagram that contains several identical subVI nodes calls the same subVI several times.The subVI controls and indicators receive data from and return data to the block diagram of the calling VI. When you double-click a subVI on the block diagram, its front panel window appears. The front panel includes controls and indicators. The block diagram includes wires, icons, functions, possibly subVIs, and other LabVIEW objects.
Every VI displays an icon in the upper right corner of the front panel window and block diagram window. An example of the default icon is shown here. An icon is a graphical representation of a VI. The icon can contain both text and images. If you use a VI as a subVI, the icon identifies the subVI on the block diagram of the VI. The default icon contains a number that indicates how many new VIs you opened after launching LabVIEW.
To use a VI as a subVI, you need to build a connector pane, shown above. The connector pane is a set of terminals on the icon that corresponds to the controls and indicators of that VI, similar to the parameter list of a function call in text-based programming languages. Access the connector pane by right-clicking the icon in the upper right corner of the front panel window. You cannot access the connector pane from the icon in the block diagram window. A subVI icon has a white background on its icon.
Express VIs are nodes that require minimal wiring because you configure them with dialog boxes. Use Express VIs for common measurement tasks. Refer to the Express VIs topic of the LabVIEW Help for more information about Express VIs. Express VIs appear on the block diagram as expandable nodes with icons surrounded by a blue field.
The Functions palette contains the VIs, functions and constants you use to create the block diagram. You access the Functions palette from the block diagram by selecting View»Functions Palette. The Functions palette is broken into various categories; you can show and hide categories to suit your needs. Figure 11 shows a Functions palette with all of the categories exposed and the Programming category expanded.
Figure 11. Functions Palette
To view or hide categories, click the Customize button and select Change Visible Palettes.
When you select View»Controls or View»Functions to open the Controls and Functions palettes, two buttons appear at the top of the palette.
Search—Changes the palette to search mode so you can perform text-based searches to locate controls, VIs, or functions on the palettes. While a palette is in search mode, click the Return button to exit search mode and return to the palette.
Customize—Provides options for selecting a format for the current palette, showing and hiding categories for all palettes, and sorting items in the Text and Tree formats alphabetically. Select Options from the shortcut menu to display the Controls/Functions Palettes page of the Options dialog box, in which you can select a format for all palettes. This button appears only if you click the thumbtack in the upper left corner of a palette to pin the palette.
Until you are familiar with the location of VIs and functions, search for the function or VI using the Search button. For example, if you want to find the Random Number function, click the Search button on the Functions palette toolbar and start typing Random Number in the text box at the top of the palette. LabVIEW lists all matching items that either start with or contain the text you typed. You can click one of the search results and drag it to the block diagram, as shown in Figure 12.
Figure 12. Searching for an Object in the Functions Palette
Double-click the search result to highlight its location on the palette.
Alternatively, you can find and place VIs and front panel objects by name in the Quick Drop dialog box. To launch Quick Drop, press the <Ctrl-Space> keys.
Quick Drop is especially useful when searching for a very specific function or operation. As you type, Quick Drop automatically completes the name with matching functions. After you highlight the appropriate function, click the block diagram or front panel to place the object in that location.