Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Getting Started with LabVIEW Virtual Instruments

6 ratings | 3.83 out of 5
Print | PDF

Overview

LabVIEW programs are called virtual instruments, or VIs, because their appearance and operation 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.

In LabVIEW, you build a user interface, or front panel, with controls and indicators. Controls are knobs, push buttons, dials, and other input mechanisms. Indicators are graphs, LEDs, and other output displays. After you build the user interface, you add code using VIs and structures to control the front panel objects. The block diagram contains this code.

You can use LabVIEW to communicate with hardware such as data acquisition, vision, and motion control devices, as well as GPIB, PXI, VXI, RS232, and RS485 instruments.

Building a Virtual Instrument

In the following exercises, you will build a VI that generates a signal and displays that signal in a graph. After you complete the exercises, the front panel of the VI will look similar to the front panel in Figure 1-1.

You can complete the exercises in this chapter in approximately 40 minutes.

Figure 1-1. Front Panel of the Acquiring a Signal VI

 

Launching LabVIEW

The Getting Started window, shown in Figure 1-2, appears when you launch LabVIEW. Use this window to create new VIs, select among the most recently opened LabVIEW files, find examples, and launch the LabVIEW Help. You also can access information and resources to help you learn about LabVIEW, such as specific manuals, help topics, and resources
on the National Instruments Web site, ni.com.

Figure 1-2. Getting Started Window

The Getting Started window disappears when you open an existing file or create a new file. The Getting Started window reappears when you close all open front panels and block diagrams. You also can display the window
from the front panel or block diagram by selecting View»Getting Started Window.

 

Opening a New VI from a Template

LabVIEW provides built-in template VIs that include the subVIs, functions, structures, and front panel objects you need to get started building common measurement applications. 

Complete the following steps to create a VI that generates a signal and displays it on the front panel.

  1. Launch LabVIEW.
  2. In the Getting Started window, click the New or VI from Template link to display the New dialog box.
  3. From the Create New list, select VI»From Template»Tutorial (Getting Started)»Generate and Display. This template VI generates and displays a signal.
    A preview and a brief description of the template VI appear in the Description section. Figure 1-3 shows the New dialog box and the preview of the Generate and Display template VI.

Figure 1-3. New Dialog Box

  1. Click the OK button to create a VI from the template. You also can double-click the name of the template VI in the Create New list to create a VI from a template.
    LabVIEW displays two windows: the front panel window and the block diagram window.
  2. Examine the front panel window.
    The user interface, or front panel, appears with a gray background and includes controls and indicators. The title bar of the front panel indicates that this window is the front panel for the Generate and Display VI.

Note If the front panel is not visible, you can display the front panel by selecting Window»Show Front Panel. You also can switch between the front panel window and block diagram window at any time by pressing the <Ctrl-E> keys. The <Ctrl> key in keyboard shortcuts corresponds to the (Mac OS) <Option> or <Command> key or (Linux) <Alt> key.

  1. Select Window»Show Block Diagram and examine the block diagram of the VI.
    The block diagram appears with a white background and includes VIs and structures that control the front panel objects. The title bar of the block diagram indicates that this window is the block diagram for the Generate and Display VI.
  2. On the front panel toolbar, click the Run button. You also can press the <Ctrl-R> keys to run a VI.
    A sine wave appears on the graph on the front panel.
  3. Stop the VI by clicking the STOP button, on the front panel.

 

Adding a Control to the Front Panel

Controls on the front panel simulate the input mechanisms on a physical instrument and supply data to the block diagram of the VI. Many physical instruments have knobs you can turn to change an input value.
Complete the following steps to add a knob control to the front panel.

Tip Throughout these exercises, you can undo recent edits by selecting Edit»Undo or pressing the <Ctrl-Z> keys.

  1. If the Controls palette, shown in Figure 1-4, is not visible on the front panel, select View»Controls Palette.

Tip You can right-click any blank space on the front panel or the block diagram to display
a temporary version of the Controls or Functions palettes. The Controls or Functions
palette appears with a thumbtack icon in the upper left corner. Click the thumbtack to pin
the palette so it is no longer temporary.

  1. If you are a new LabVIEW user, the Controls palette opens with the Express subpalette visible by default. If you do not see the Express subpalette, click Express on the Controls palette to display the Express subpalette.

Figure 1-4. Controls Palette

  1. Move the cursor over the icons on the Express subpalette to locate the Numeric Controls palette.
    When you move the cursor over icons on the Controls palette, the
    name of the subpalette, control, or indicator appears in a tip strip below
    the icon.
  2. Click the Numeric Controls icon to display the Numeric Controls palette.
  3. Click the knob control on the Numeric Controls palette to attach the control to the cursor, and then place the knob on the front panel to the left of the waveform graph.
    You will use this knob in a later exercise to control the amplitude of a signal.
  4. Select File»Save As and save the VI as Acquiring a Signal.vi in an easily accessible location.

 

Changing a Signal Type

The block diagram has a blue icon labeled Simulate Signal. This icon represents the Simulate Signal Express VI. The Simulate Signal Express VI simulates a sine wave by default.

Complete the following steps to change this signal to a sawtooth wave.

  1. Display the block diagram by pressing the <Ctrl-E> keys or by clicking the block diagram.
    Locate the Simulate Signal Express VI. An Express VI is a component of the block diagram that you can configure to perform common measurement tasks. The Simulate Signal Express VI simulates a signal based on the configuration that you specify.
  2. Right-click the Simulate Signal Express VI and select Properties from the shortcut menu to display the Configure Simulate Signal dialog box. (Mac OS) Press <Command>-click to perform the same action as right-click.
    You also can double-click the Express VI to display the Configure Simulate Signal dialog box. If you wire data to an Express VI and run it, the Express VI displays real data in the configuration dialog box. If you close and reopen the Express VI, the VI displays sample data in the configuration dialog box until you run the VI again.
  3. Select Sawtooth from the Signal type pull-down menu.
    The waveform on the graph in the Result Preview section changes to a sawtooth wave. The Configure Simulate Signal dialog box should appear similar to Figure 1-5.

Figure 1-5. Configure Simulate Signal Dialog Box

  1. Click the OK button to save the current configuration and close the Configure Simulate Signal dialog box.
  2. Move the cursor over the down arrows at the bottom of the Simulate Signal Express VI. The down arrows indicate you can reveal hidden inputs and outputs by extending the border of the Express VI.
  3. When a double-headed arrow appears, click and drag the border of the Express VI to add two rows. When you release the border, the Amplitude input appears.
    Because the Amplitude input appears on the block diagram, you can configure the amplitude of the sawtooth wave on the block diagram.
    In Figure 1-5, notice that Amplitude is an option in the Configure Simulate Signal dialog box. When inputs, such as Amplitude, appear on the block diagram and in the configuration dialog box, you can configure the inputs in either location.

 

Wiring Objects on the Block Diagram

To use the knob to change the amplitude of the signal, you must connect two objects on the block diagram.

Complete the following steps to wire the knob to the Amplitude input of the Simulate Signal Express VI.

  1. On the block diagram, move the cursor over the Knob terminal.
    The cursor becomes an arrow, or the Positioning tool. Use the Positioning tool to select, position, and resize objects.
  2. Use the Positioning tool to select the Knob terminal and make sure it is to the left of the Simulate Signal Express VI and inside the gray loop.
    The terminals inside the loop are representations of front panel controls and indicators. Terminals are entry and exit ports that exchange information between the front panel and block diagram.
  3. Deselect the Knob terminal by clicking a blank space on the block diagram. If you want to use a different tool with an object, you must deselect the object to switch the tool.
  4. Move the cursor over the arrow on the Knob terminal.
    The cursor becomes a wire spool, or the Wiring tool. Use the Wiring tool to wire objects together on the block diagram.
  5. When the Wiring tool appears, click the arrow on the Knob terminal and then click the arrow on the Amplitude input of the Simulate Signal Express VI, to wire the two objects together.
    A wire appears and connects the two objects. Data flows along this
6 ratings | 3.83 out of 5
Print | PDF

Reader Comments | Submit a comment »

Nice Tutorial, Bug in PDF
The tutorial is nice, but the pdf has a line where it states: "You also can switch between the front panel window and block diagram window at any time by pressing the keys. The key in keyboard shortcuts corresponds to the (Mac OS)

 

Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).