Pre-Experiment Introduction to LabView and NI ELVIS III

NI Learning Center - NI

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 the code you write.

image-20241018-102934.png
Front Panel (left) and Block Diagram (Right)

When you create a new VI, you see two windows: the front panel and the block diagram. The front panel is the user interface for the VI, and the block diagram contains the graphical source code of the LabVIEW program.

1. LabView Front Panel

The front panel window is the user interface for the VI. You create the user interface of a VI by placing controls and indicators on its front panel. Controls define inputs, and indicators display outputs.

When you interact with a front panel as a user interface, you can modify controls to supply inputs and see the results in indicators. You can also use the front panel to pass inputs and receive outputs when you call your VI from the block diagram of a different VI.

  • Controls Palette

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.

image-20241018-103246.png
Controls Palette (right)

ย 

After opening the Controls palette, place controls and indicators on the front panel by clicking on icons from the palettes. Then, click on the front panel where you would like the control or indicator to be placed.

ย 

  • Controls and Indicators

    Controls simulate instrument input devices and supply data to the block diagram of the VI. They are typically knobs, push buttons, dials, sliders, and strings.ย 

    ย 

    Indicators simulate instrument output devices and display data the block diagram acquires or generates. They are typically graphs, charts, LEDs, and status strings.

2. LabVIEW Block Diagram

ย 

After you create the front panel window, you add code to the LabVIEW block diagram using graphical representations of functions to complete calculations and control the front panel objects. To bring up the block diagram, selectโ€ฏWindow ยป Show Block Diagramโ€ฏ from the menu bar. Additionally, you can toggle between the block diagram and the front panel by pressingโ€ฏ <Ctrl-E>.

ย 

Block diagram objects include terminals, subVIs, functions, constants, structures, and wires, which transfer data among other block diagram objects.

ย 

  • Terminals

Front panel objects appear as terminals on the block diagram. Terminals on the block diagram reflect the changes made to their corresponding front panel objects and vice versa.

Terminals are entry and exit ports that exchange information between the front panel and block diagram. They are analogous to parameters and constants in text-based programming languages.

ย 

  • Constants

In addition to controls and indicators, you can have constants on the block diagram for static values needed in your code. You can have constants for any data type.

Consider an algorithm for computing the area of a triangle. You might have the following front panel and corresponding block diagram.

ย 

The constantโ€ฏTriangular Multiplierโ€ฏdoes not appear on the front panel window. It simply passes the value ofโ€ฏ.5โ€ฏinto the multiply function.

Notice that theโ€ฏBase(cm)โ€ฏandโ€ฏHeight(cm)โ€ฏblock diagram terminals look different from theโ€ฏArea(cm^2)โ€ฏ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.

ย 

  • Block Diagram Nodes

Nodes are objects on the block diagram with 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, or structures. Structures are process control elements, such as case structures, for loops, or while loops.

  • Functions

To place objects on the block diagram, simply drag and drop them from theโ€ฏFunctionsโ€ฏpalette. Theโ€ฏFunctionsโ€ฏpalette automatically appears when you right-click anywhere on the block diagram workspace. It contains functions, constants, structures, and some subVIs.

Theโ€ฏ Search โ€ฏbutton on the Functions palette opens a search dialog box that you can use to search for functions by name. It takes a few moments to launch.

ย 

ย 

ย 

ย 

After you see the function you want, double-click it, and LabVIEW jumps to the place on the Functions palette where you can find it.

ย 

Functions are the fundamental operating elements of LabVIEW. Functions do not have front panel windows or block diagram windows, but they have input and output terminals for passing data in and out, similar to controls and indicators. You can tell if a block diagram object is a function by the pale-yellow background on its icon. The Functions palette has functions arranged in groups based on the type of function they perform. For example, you can look in the Numeric subpalette for functions that perform numeric operations.

3. Example Application

Using the information we have learned thus far, we can build a program to calculate the area of a triangle. We will start by creating the block diagram below.

  1. Open a blank VI from the toolbar. Selectโ€ฏ File ยป New VI.

  2. Put two multiply functions on the block diagram by dragging them onto the block diagram from the Programming >> Numericโ€ฏsubpalette.

    • Tip: To copy an object on the block diagram, hold down while you click and drag the object.

  3. Hover your mouse over the left-most multiply function to make the input and output terminals appear.

    • If you hold your mouse over one of the terminals, the wire spool appears along with the name of the terminal you are hovering over.

    • To create a control for theโ€ฏyโ€ฏterminal, simply hover your mouse over it and right-click. Do the same for theโ€ฏxโ€ฏterminal on the left-most multiply function so that you have control for each input terminal.

ย 

ย 

  1. Wire the output terminal of the left multiply function to the x input of the right multiply function by hovering your mouse over the output terminal. When it turns into the wiring spool, click and hold while you drag the wire to the desired input.

  1. Create the Triangular Multiplier constant .5 by right-clicking on the y input terminal of the right-most multiply function and selectingโ€ฏCreate ยป Constant. You can change the value of a constant by double-clicking it to highlight the text and typing in the new value. Type in .5 and pressโ€ฏ<enter>.

  1. Right-click the output of the right multiply function and select Create ยป Indicator to create an indicator that passes the value of the block diagram logic to the front panel.

    • Tip:โ€ฏYou can comment on the block diagram or the front panel by double-clicking the block diagram and typing your comment into the automatically created text box.

    • You can change the names of indicators, controls, and constants by double-clicking the label and typing the desired name. If no label is shown, right-click the desired object and selectโ€ฏVisible Items ยป Label.

ย 

ย 

  1. Look at the front panel that was generated from your work on the block diagram by pressing <Ctrl+E>ย or selecting WindowยปShow Front Panel. Notice that the two controls Base(cm) and Height(cm) and the indicator Area(cm^2) were automatically generated and placed on the front panel.

  1. On the block diagram, select a While Loop from the Programming >> Structures subpalette. To add the While Loop to your block diagram, left-click and drag the mouse until your code is contained within the loop

  2. In the bottom right corner of the while loop is the Conditional Terminal. Add a Stop button by right-clicking the terminal and selecting Create Control. The button created is automatically displayed on the front panel.

  3. Inside the While Loop, add a Wait (ms) function from the Programming >> Timing subpalette. Right-click on the milliseconds to wait terminal on the left and select Create Constant. Specify how often you would like the while loop to run, like every 500 ms.

  4. The Wait (ms) function controls how often a loop executes, allowing time for the processor to complete other tasks, such as updating and responding to the user interface. If you do not configure loop timing, a while loop will continuously execute and not relinquish the processor to other tasks.

ย 

ย 

  1. Click the Run button on the VI you just created and change the values on the front panel. Watch how changing the control values of a and b updates the indicator value of a*b.

  2. Click the Stop button to stop the VI. Save and close the VI by selecting File ยป Save from the menu bar and then clicking the Close button in the top right corner of the front panel window.

ย