[1library.net] Labview Tutorial
[1library.net] Labview Tutorial
Collection Editor:
National Instruments
LabVIEW Graphical Programming Course
Collection Editor:
National Instruments
Authors:
National Instruments
Malan Shiralkar
Online:
< http://cnx.org/content/col10241/1.4/ >
CONNEXIONS
7 Plotting Data
7.1 Waveform Charts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . 113
7.2 Temperature Monitor VI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
7.3 Temperature Running Average VI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
7.4 Waveform and XY Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
7.5 Graph Waveform Array VI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
7.6 Temperature Analysis VI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
7.7 Graph Circle VI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
7.8 Intensity Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
7.9 Intensity Graph Example VI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . 135
7.10 Summary, Tips, and Tricks on Plotting Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
7.11 Additional Exercises for Plotting Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
8 Making Decisions in a VI
8.1 Making Decisions with the Select Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
8.2 Case Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
8.3 Square Root VI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
8.4 Temperature Control VI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . 146
8.5 Formula Node . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
8.6 Formula Node Exercise VI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . 150
8.7 Summary, Tips, and Tricks on Making Decisions in a VI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
8.8 Additional Exercises for Making Decisions in a VI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
9 Strings and File I/O
9.1 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
9.2 String Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . 156
9.3 Create String VI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
9.4 File I/O VIs and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
9.5 High-Level File I/O VIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
9.6 Spreadsheet Example VI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
9.7 Low-Level File I/O VI and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
9.8 File Writer VI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
9.9 File Reader VI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
9.10 Formatting Spreadsheet Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
9.11 Temperature Logger VI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
9.12 Temperature Application VI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
9.13 Summary, Tips, and Tricks on Strings and File I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
9.14 Additional Exercises for Strings and FileI/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . 184
10 Data Acquisition and Waveforms
10.1 Overview and Conguration of DAQ Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
10.2 Measurement & Automation Explorer (Windows Only) . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . 191
10.3 Data Acquisition in LabVIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
10.4 Analog Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
10.5 Voltmeter VI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . 197
10.6 Measurement Averaging VI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . 199
10.7 Data Logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
10.8 Simple Data Logger VI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . 201
10.9 Analog Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . 204
10.10 Voltage Output VI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . 205
10.11 Counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . 208
10.12 Simple Event Counting VI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
10.13 Digital I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Available for free at Connexions <http://cnx.org/content/col10241/1.4>
v
Student Guide
Several exercises in this manual use one of the following National Instruments hardware products:
• A plug-in multifunction data acquisition (DAQ) device connected to a DAQ Signal Accessory containing
a temperature sensor, function generator, and LEDs
• A GPIB interface connected to an NI Instrument Simulator
If you do not have this hardware, you still can complete most of the exercises. Be sure to use the demo
versions of the VIs when you are working through exercises. Exercises that explicitly require hardware
are indicated with an icon, shown in Figure 1. You also can substitute other hardware for those previously
mentioned. For example, you can use a GPIB instrument in place of the NI Instrument Simulator, or another
National Instruments DAQ device connected to a signal source, such as a function generator.
• A serial cable
• A GPIB cable
• (Optional) A word processing application such as Notepad or WordPad
• The following les provided
Filename Description
Exercises6 Folder for saving VIs created during the course
and for completing certain course exercises; also in-
cludes subVIs necessary for some exercises
nidevsim.zip Zip le containing the LabVIEW instrument driver
for the NI Instrument Simulator (Contained in Ex-
ercises.zip)
Solutions7 Folder containing the solutions to all the course ex-
ercises
Table 1.1
Introduction
2.1 LabVIEW1
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
your code.
LabVIEW VIs contain three components-the front panel, the block diagram, and the icon and con-
nector pane. This lesson describes the front panel and the block diagram; refer to Modular Programming
(Section 3.1) for more information about the icon and the connector pane.
In LabVIEW, you build a user interface, or front panel, with controls and indicators. Controls are knobs,
push buttons, dials, and other input devices. Indicators are graphs, LEDs, and other 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. In some ways, the block diagram resembles a owchart.
Use LabVIEW to communicate with hardware such as data acquisition, vision, and motion control devices,
and GPIB, PXI, VXI, RS-232, and RS-484 devices. LabVIEW also has built-in features for connecting your
application to the Web using the LabVIEW Web Server and software standards such as TCP/IP networking
and ActiveX.
Using LabVIEW, you can create test and measurement, data acquisitions, instrument control, datalog-
ging, measurement analysis, and report generation applications. You also can create stand-alone executables
and shared libraries, like DLLs, because LabVIEW is a true 32-bit compiler.
VI appear in the Front panel preview and the Block diagram preview sections, and a description of the
template appears in the Description section. Figure 2.2 shows the New dialog box and the SubVI with
Error Handling VI template.
Click the OK button to open the template. You also can double-click the name of the template VI in the
Create new list to open the template. If no template is available for the task you want to create, you can
start with a blank VI and create a VI to accomplish the specic task. In the LabVIEW dialog box, click the
arrow on the New button and select Blank VI from the shortcut menu or press the Ctrl-N keys to open a
blank VI.
note: You also can open a blank VI by selecting Blank VI from the Create new list in the New
dialog box or by selecting FileNew VI.
2.2.1.1 Open/Templates
Use the New dialog box to create dierent components in LabVIEW to help you build an application. You
can start with a blank VI to write a VI from scratch, or start with a template to simplify the programming.
The New dialog box includes the following components:
Create new - Displays templates you can use to start building VIs and other LabVIEW documents.
Select from the following templates and click the OK button to start building a VI or other
LabVIEW document.
Blank VI - Opens a blank front panel and blank block diagram.
VI from Template - Opens a front panel and block diagram with components you need to
build dierent types of VIs.
Other Document Types - Opens the tools you use to build other LabVIEW objects.
Browse for Template - Displays the Browse dialog box so you can navigate to a VI, control, or
template. If you previously have browsed for and selected a template from this dialog box, use
the pull-down menu of the Browse button to select a template to reopen it.
Front panel preview - Displays the front panel for the VI template you selected in the Create new
list.
Block diagram preview - Displays the block diagram for the VI template you selected in the
Create new list.
Description - Displays a description of the template you selected in the Create new list if the
template includes a description.
Figure 2.3
The Loading section lists the subVIs of the VI as they are loaded into memory. Number Loaded is the
number of subVIs loaded into memory so far. You can cancel the load at any time by clicking the Stop
button.
If LabVIEW cannot immediately locate a subVI, it begins searching through all directories specied by
the VI Search Path. You can edit the VI Search Path by selecting ToolsOptions and selecting Paths
from the top pull-down menu. The Searching section lists directories or VIs as LabVIEW searches through
them. You can have LabVIEW ignore a subVI by clicking the Ignore SubVI button, or you can click the
Browse button to search for the missing subVI.
note: Certain operating system-specic VIs are not portable between platforms, such as DDE
(Dynamic Data Exchange) VIs, ActiveX VIs, and AppleEvents.
Refer to the Porting and Localizing LabVIEW VIs Application Note, available by selecting HelpSearch
the LabVIEW Bookshelf, for more information about porting VIs.
2.2.2 Menus
The menus at the top of a VI window contain items common to other applications, such as Open, Save, Copy,
and Paste, and other items specic to LabVIEW. Some menu items also list shortcut key combinations.
(Mac OS) The menus appear at the top of the screen.
(Windows and UNIX) The menus display only the most recently used items by default. Click the
arrows at the bottom of a menu to display all items. You can display all menu items by default by selecting
ToolsOptions and selecting Miscellaneous from the top pull-down menu.
• The File menu contains items used for basic le operations, such as opening, closing, saving, and
printing les.
• The Edit menu contains items that allow you to search for and modify LabVIEW les and their
components.
• The Operate menu contains items you use to control the operation of VIs.
• The Tools menu contains items for conguring LabVIEW, your projects, and your VIs.
• The Browse menu contains items that allow you to view aspects of the current VI and its hierarchy.
• The Window menu contains items that allow you to congure the appearance of the current windows
and palettes. You also can access the Error List window and view the contents of the clipboard.
• The Help menu contains items to explain and dene LabVIEW features and other components, provide
full LabVIEW documentation, and access National Instruments technical support.
Figure 2.4: 1. Toolbar, 2. Owned Label, 3. Numeric Control, 4. Free Label, 5. Numeric Control
Terminal, 6. Knob Terminal, 7. Numeric Constant, 8. Multiply Function, 9. Icon, 10. Knob Control,
11. Plot Legend, 12. XY Graph, 13. Wire Data Path, 14. XY Graph Terminal, 15. Bundle Function,
16. SubVI, 17. For Loop Structure
Figure 2.5
Click the Run button to run a VI. LabVIEW compiles the VI, if necessary. You can run a VI if the
Run button appears as a solid white arrow. The solid white arrow, shown above, also indicates you can use
the VI as a subVI if you create a connector pane for the VI.
While the VI runs, the Run button appears as shown at left if the VI is a top-level VI, meaning it
has no callers and therefore is not a subVI.
If the VI that is running is a subVI, the Run button appears as shown at left.
The Run button appears broken, shown at left, when the VI you are creating or editing contains
errors. If the Run button still appears broken after you nish wiring the block diagram, the VI is broken and
cannot run. Click this button to display the Error list window, which lists all errors and warnings.
Click the Run Continuously button, shown at left, to run the VI until you abort or pause execution.
You also can click the button again to disable continuous running.
While the VI runs, the Abort Execution button, shown at left, appears. Click this button to stop
the VI immediately if there is no other way to stop the VI. If more than one running top-level VI uses the
VI, the button is dimmed.
note: Avoid using the Abort Execution button to stop a VI. Either let the VI complete its data
ow or design a method to stop the VI programmatically. By doing so, the VI is at a known state.
For example, place a button on the front panel that stops the VI when you click it.
Click the Pause button, shown at left, to pause a running VI. When you click the Pause button,
LabVIEW highlights on the block diagram the location where you paused execution, and the Pause button
appears red. Click the button again to continue running the VI.
Select the Text Settings pull-down menu, shown at left, to change the font
settings for the selected portions of the VI, including size, style, and color.
Select the Align Objects pull-down menu, shown at left, to align objects along axes, including
vertical, top edge, left, and so on.
Select the Distribute Objects pull-down menu, shown at left, to space objects evenly, including
gaps, compression, and so on.
Select the Resize Objects pull-down menu, shown at left, to resize multiple front panel objects
to the same size.
Select the Reorder pull-down menu, shown at left, when you have objects that overlap each
other and you want to dene which one is in front or back of another. Select one of the objects with the
Positioning tool and then select from Move Forward, Move Backward, Move To Front, and Move To Back.
Select the Show Context Help Window button, shown at left, to toggle the display of the Context
Help window.
Type appears to remind you that a new value is available to replace an old value. The Enter button
disappears when you click it, press the Enter key, or click the front panel or block diagram workspace.
Figure 2.6
Click the Highlight Execution button, shown at left, to display an animation of the block diagram
execution when you click the Run button. see the ow of data through the block diagram. Click the button
again to disable execution highlighting.
Click the Step Into button, shown at left, to open a node and pause. When you click the Step
Into button again, it executes the rst action and pauses at the next action of the subVI or structure. You
also can press the Ctrl and down arrow keys. Single-stepping through a VI steps through the VI node by
node. Each node blinks to denote when it is ready to execute. By stepping into the node, you are ready to
single-step inside the node.
Click the Step Over button, shown at left, to execute a node and pause at the next node. You
also can press the Ctrl and right arrow keys. By stepping over the node, you execute the node without
single-stepping through the node.
Click the Step Out button, shown at left, to nish executing the current node and pause. When
the VI nishes executing, the Step Out button becomes dimmed. You also can press the Ctrl and up arrow
keys. By stepping out of a node, you complete single-stepping through the node and go to the next node.
The Warning button, shown at left, appears if a VI includes a warning and you placed a checkmark
in the Show Warnings checkbox in the Error List window. A warning indicates there is a potential problem
with the block diagram, but it does not stop the VI from running.
2.2.6 Palettes
LabVIEW has graphical, oating palettes to help you create and run VIs. The three palettes include the
Tools, Controls, and Functions palettes. You can place these palettes anywhere on the screen.
If automatic tool selection is enabled and you move the cursor over objects on the front panel or block
diagram, LabVIEW automatically selects the corresponding tool from the Tools palette. You can disable
automatic tool selection and select a tool manually by clicking the tool you want on the Tools palette.
If you want to use the Tab key to cycle through the four most common tools on the Tools
palette, click the Automatic Tool Selection button, shown at left, on the Tools palette to disable auto-
matic tool selection. Press the Shift-Tab keys or click the Automatic Tool Selection button to enable
automatic tool selection again. You also can manually select a tool on the Tools palette to disable auto-
matic tool selection. Press the Tab or Shift-Tab keys or click the Automatic Tool Selection button on
the Tools palette to enable automatic tool selection again. If automatic tool selection is disabled, you can
press the spacebar to switch to the next most useful tool.
Use the Operating tool, shown at left, to change the values of a control or select the text
within a control. The Operating tool changes to the icon shown at left when it moves over a text control,
such as a numeric or string control.
Use the Positioning tool, shown at left, to select, move, or resize objects. The Positioning tool
changes to resizing handles when it moves over the edge of a resizable object.
Use the Labeling tool, shown at left, to edit text and create free labels. The Labeling tool
changes to the following icon when you create free labels.
Use the Wiring tool, shown at left, to wire objects together on the block diagram.
Use the Object Shortcut Menu, shown at left, tool to access an object shortcut menu with the
left mouse button.
Use the Scrolling tool, shown at left, to scroll through windows without using scrollbars.
Use the Breakpoint tool, shown at left, to set breakpoints on VIs, functions, nodes, wires, and
structures to pause execution at that location.
Use the Probe tool, shown at left, to create probes on wires on the block diagram. Use the Probe
tool to check intermediate values in a VI that produces questionable or unexpected results.
Use the Color Copy tool, shown at left, to copy colors for pasting with the Coloring tool.
Use the Coloring tool, shown at left, to color an object. It also displays the current
foreground and background color settings.
The Functions palette, shown in the Figure 2.9, is available only on the block diagram. The Functions
palette contains the VIs and functions you use to build the block diagram. Refer to the Block Diagram
(Section 2.4) section of this lesson for more information about using the Functions palette on the block
diagram. The VIs and functions located on the Functions palette depend on the palette view currently
selected. The VIs and functions are located on subpalettes based on the types of VIs and functions.
1. Click the Options button, shown at left, on the Controls or Functions palette toolbar to
display the Controls/Functions Palettes page of the Options dialog box.
2. Select a palette view from the Palette View pull-down menu.
3. Select a format from the Format pull-down menu, such as Standard, All Icons, All Text, or Icons
and Text.
4. Click the OK button. The Controls and Functions palettes change to the palette view and format
you selected.
Search - Changes the palette to search mode. In search mode, you can perform text-based
searches to locate controls, VIs, or functions on the palettes. For example, if you want to nd 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 2.10.
Figure 2.10
Double-click the search result to highlight its location on the palette. You then can click the Up to Owning
Palette button to view the hierarchy of where the object resides.
gure. The options available on the property dialog box for an object are similar to the options available on
the shortcut menu for that object.
Controls and All Functions subpalettes. In the Advanced palette view, toolsets and modules
install subpalettes on the top level.
Click the Options button on the Controls or Functions palette to change to another palette view or format.
Figure 2.14: 1. Increment and Decrement Buttons, 2. Numeric Control, 3. Numeric Indicator
To enter or change values in a numeric control, click the increment and decrement buttons with the
Operating tool or double-click the number with either the Labeling tool or the Operating tool, type a new
number, and press the Enter key.
Figure 2.15
2.4.2.2 VIs
When you place a VI on the block diagram, LabVIEW considers the VI to be a subVI. When you double-
click a subVI, its front panel and block diagram appear, rather than a dialog box in which you can congure
options. The front panel includes controls and indicators. The block diagram includes wires, front panel
icons, functions, possibly subVIs, and other LabVIEW objects.
The upper right corner of the front panel and block diagram displays the icon for the VI. This is the icon
that appears when you place the VI on the block diagram.
You can create a VI to use as a subVI. Refer to Modular Programming (Section 3.1) for more information
about creating VIs and conguring them as subVIs.
2.4.2.3 Functions
Functions are the fundamental operating elements of LabVIEW. Functions do not have front panels or block
diagrams but do have connector panes. Double-clicking a function only selects the function.
2.4.3 Nodes
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, or structures. Structures are process control elements, such as
Case structures, For Loops, or While Loops. The Add and Subtract functions in Figure 2.16 are function
nodes.
Figure 2.17
note: If you display a subVI or Express VI as an expandable node, you cannot display the terminals
for that node and you cannot enable database access for that node.
2.4.3.2 Terminals
Front panel objects appear as terminals on the block diagram. The terminals represent the
data type of the control or indicator. You can congure front panel controls or indicators to appear as icon
or data type terminals on the block diagram. By default, front panel objects appear as icon terminals. For
example, a knob icon terminal, shown at left, represents a knob on the front panel. The DBL at the bottom
of the terminal represents a data type of double-precision, oating-point numeric. To display a terminal as
a data type on the block diagram, right-click the terminal and select View As Icon from the shortcut menu
to remove the checkmark. A DBL data type terminal, shown above at left, represents a double-precision,
oating-point numeric control or indicator.
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 Figure 2.16)
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 internal calculations, they produce new data values.
The data ow to the indicator terminals, where they exit the block diagram, reenter the front panel, and
appear in front panel indicators ( a + b and a − b in Figure 2.16). The terminals in Figure 2.16 belong to four
front panel controls and indicators. The connector panes of the Add and Subtract functions, shown in this
media, have three node terminals. To display the terminals of the function on the block diagram, right-click
the function node and select Visible ItemsTerminals from the shortcut menu.
2.4.3.3 Wires
You transfer data among block diagram objects through wires. Wires are analogous to variables in text-based
programming languages. In Figure 2.16, wires connect the control and indicator terminals to the Add and
Subtract functions. Each wire has a single data source, but you can wire it to many VIs and functions that
read the data. Wires are dierent colors, styles, and thicknesses, depending on their data types. A broken
wire appears as a dashed black line with a red X in the middle. The examples in Table 2.1 are the most
common wire types.
Table 2.1
In LabVIEW, you use wires to connect multiple terminals together to pass data in a VI. The wires must
be connected to inputs and outputs that are compatible with the data that is transferred with the wire. For
example, you cannot wire an array output to a numeric input. In addition the direction of the wires must be
correct. The wires must be connected to only one input and at least one output. For example, you cannot
wire two indicators together. The components that determine wiring compatibility include the data type of
the control and/or indicator and the data type of the terminal.
options that let you specify how you want to format the data that the Convert from Dynamic Data Express
VI returns.
When you wire a dynamic data type to an array indicator, LabVIEW automatically places the Convert
from Dynamic Data Express VI on the block diagram. Double-click the Convert from Dynamic Data Ex-
press VI to open the Configure Convert from Dynamic Data dialog box to control how the data appears
in the array.
Use the Convert to Dynamic Data Express VI to convert numeric, Boolean, waveform, and array data
types to the dynamic data type for use with Express VIs. When you place the Convert to Dynamic Data
Express VI on the block diagram, the Configure Convert to Dynamic Data dialog box appears. Use this
dialog box to select the kind of data to convert to the dynamic data type.
Figure 2.18
Figure 2.19
4. Click the OK button to open the template. You also can double-click the name of the template
VI in the Create new list to open the template.
5. Examine the front panel of the VI. 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
WindowShow Front Panel.
6. 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.
note: If the block diagram is not visible, you can display the block diagram by selecting
WindowShow Block Diagram.
7. On the front panel toolbar, click the Run button, shown at left. Notice that a sine wave
appears on the graph.
8. Stop the VI by clicking the Stop button, shown at left, on the front panel.
1. If the Controls palette is not visible on the front panel, select WindowShow Controls
Palette to display it.
2. Move the cursor over the icons on the Controls palette to locate the Numeric Controls
palette. Notice that when you move the cursor over icons on the Controls palette, the name
of that subpalette appears in the gray space above all the icons on the palette. When you idle
the cursor over any icon on any palette, the full name of the subpalette, control, or indicator
appears.
3. Click the Numeric Controls icon to access the Numeric Controls palette.
4. Select the knob control on the Numeric Controls palette and place it 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.
5. Select FileSave As and save this VI as Acquiring a Signal.vi in the
C:\Exercises\LabVIEW Basics I directory.
note: Save all the VIs you edit or create in this course in the C:\Exercises\LabVIEW
Basics I directory.
block diagram. Notice the Simulate Signal Express VI, shown in this media.
An Express VI is a component of the block diagram that you can congure to perform
common measurement tasks. The Simulate Signal Express VI simulates a signal based on
the conguration 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.
3. Select Sawtooth from the Signal type pull-down menu. Notice that 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 2.20.
Figure 2.20
4. Click the OK button to apply the current conguration and close the Configure Simulate
Signal dialog box.
5. Move the cursor over the down arrows at the bottom of the Simulate Signal Express VI.
6. When a double-headed arrow appears, shown at left, click and drag the border of
the Express VI until the Amplitude input appears. Notice how you expanded the Simulate
Signal Express VI to display a new input. Because the Amplitude input appears on the
block diagram, you can congure the amplitude of the sawtooth wave on the block diagram.
In Figure 2.20, notice how Amplitude is an option in the Configure Simulate Signal dialog
box. When inputs, such as Amplitude, appear on the block diagram and in the conguration
dialog box, you can congure the inputs in either location.
1. Move the cursor over the Knob terminal, shown at left, until the Positioning tool
appears. Notice how the cursor becomes an arrow, or the Positioning tool, shown
in this media. Use the Positioning tool to select, position, and resize objects.
2. Click the Knob terminal to select it, then drag the terminal to the left of the
Simulate Signal Express VI. Make sure the Knob terminal is inside the loop, shown in this
media. The terminals 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.
4. Move the cursor over the arrow of the Knob terminal, shown in this media.
Notice how the cursor becomes a wire spool, or the Wiring tool, shown at left. Use the
Wiring tool to wire objects together on the block diagram.
note: The cursor does not switch to another tool while an object is selected.
5. When the Wiring tool appears, click the arrow and then click the
Amplitude input of the Simulate Signal Express VI, shown in this media, to wire the
two objects together. Notice that a wire appears and connects the two objects. Data ows
along this wire from the terminal to the Express VI.
6. Select FileSave to save this VI.
3. Move the cursor over the knob control. Notice how the cursor becomes a hand, or the
Operating tool, shown at left. Use the Operating tool to change the value of a control or
select the text within a control.
4. Using the Operating tool, turn the knob to adjust the amplitude of the sawtooth wave. Notice
how the amplitude of the sawtooth wave changes as you turn the knob. Also notice that the
y-axis on the graph autoscales to account for the change in amplitude. To indicate that
the VI is running, the Run button changes to a darkened arrow, shown at left. You cannot
edit the front panel or block diagram while the VI runs.
1. On the block diagram, use the Positioning tool to double-click the wire
that connects the Simulate Signal Express VI to the Waveform Graph terminal shown in
this media.
2. Press the Delete key to delete this wire.
3. If the Functions palette is not visible on the block diagram, select WindowShow Functions
Palette to display it.
4. Select the Scaling and Mapping Express VI, shown at left, on the Arithmetic
& Comparison palette and place it on the block diagram inside the loop between the Simulate
Signal Express VI and the Waveform Graph terminal. If there is no room between the
Express VI and the terminal, move the Waveform Graph terminal to the right. Notice that
the Configure Scaling and Mapping dialog box automatically opens when you place the
Express VI on the block diagram.
5. Dene the value of the scaling factor by entering 10 in the Slope (m) text box. The Configure
Scaling and Mapping dialog box should appear similar to Figure 2.21.
Figure 2.21
6. Click the OK button to apply the current conguration and close the Configure Scaling and
Mapping dialog box.
7. Move the cursor over the arrow on the Sawtooth output of the Simulate Signal Express VI.
8. When the Wiring tool appears, click the arrow and then click the
arrow on the Signals input of the Scaling and Mapping Express VI, shown in this media,
to wire the two objects together.
9. Using the Wiring tool, wire the Scaled Signals output of the Scaling and Mapping Ex-
press VI to the Waveform Graph terminal. Notice the wires connecting the Express VIs and
terminals. The arrows on the Express VIs and terminals indicate the direction that the data
ows along these wires. The block diagram should appear similar to Figure 2.22.
Figure 2.22
note: The terminals in the block diagram are set to display as icons. To display a terminal
as a data type on the block diagram, right-click the terminal and select View As Icon from
the shortcut menu to remove the checkmark.
10. Select FileSave to save this VI.
Figure 2.23
3. Select FileSave to save this VI. You also can press the Ctrl-S keys to save a VI.
4. Return to the front panel, run the VI, and turn the knob control. Notice that the graph plots
the sawtooth wave and the scaled signal. Also notice that the maximum value on the y-axis
automatically changes to be 10 times the knob value. This scaling occurs because you set the
slope to 10 in the Scaling and Mapping Express VI.
5. Click the Stop button.
Figure 2.24
3. Click the Scale tab and, in the Scale Range section, change the maximum value to 5.0.
Notice how the knob on the front panel instantly updates to reect these changes.
4. Click the OK button to apply the current conguration and close the Knob Properties dialog
box.
5. Save this VI.
tip: As you build VIs, you can experiment with dierent properties and congurations.
You also can add and delete objects. Remember, you can undo recent edits by selecting
EditUndo or pressing the Ctrl-Z keys.
6. Experiment with other properties of the knob by using the Knob Properties dialog box. For
example, try changing the colors for the Marker Text Color by clicking the color box located
on the Scale tab.
7. Click the Cancel button to avoid applying the changes you made while experimenting. If you
want to keep the changes you made, click the OK button.
2. When a double-headed arrow appears, shown in Figure 2.25, click and drag the border of the
plot legend until the second plot name appears.
Figure 2.25
3. Right-click the waveform graph and select Properties from the shortcut menu to display
the Graph Properties dialog box.
4. On the Plots tab, select Sawtooth from the pull-down menu. Click the Line Color color
box to display the color picker. Select a new line color.
5. Select Sawtooth (Scaled) from the pull-down menu.
6. Place a checkmark in the Don't use waveform names for plot names checkbox.
7. In the Name text box, delete the current label and change the name of this plot to Scaled
Sawtooth.
8. Click the OK button to apply the current conguration and close the Graph Properties dialog
box. Notice how the plot color on the front panel changes.
9. Experiment with other properties of the graph by using the Graph Properties dialog box.
For example, try disabling the autoscale feature located on the Scales tab.
10. Click the Cancel button to avoid applying the changes you made while experimenting. If you
want to keep the changes you made, click the OK button.
11. Save and close this VI.
Example 2.1
For a dataow programming example, consider a block diagram (Figure 2.26) that adds two
numbers and then subtracts 50.00 from the result of the addition. In this case, the block diagram
executes from left to right, not because the objects are placed in that order, but because the
Subtract function cannot execute until the Add function nishes executing and passes the data to
the Subtract function. Remember that a node executes only when data are available at all of its
input terminals, and it supplies data to its output terminals only when it nishes execution.
Figure 2.26
Example 2.2
In the following example (Figure 2.27), consider which code segment would execute rst-the Add,
Random Number, or Divide function. You cannot know because inputs to the Add and Divide
functions are available at the same time, and the Random Number function has no inputs. In a
situation where one code segment must execute before another, and no data dependency exists
between the functions, use other programming methods, such as error clusters, to force the order
of execution. Refer to the Error Handling (Section 6.5) section of Clusters for more information
about error clusters.
Figure 2.27
Figure 2.28
6. Click the Highlight Execution button, shown at left, on the toolbar to slow down the
execution of the program so you can observe the execution order on the block diagram.
7. Click the Run button
8. Observe the block diagram. Notice the ow of data on the block diagram. For example, notice
that the Tone Measurements2 Express VI cannot output data until it receives data from the
Filter Express VI.
9. Close the VI when nished. Do not save changes.
The Context Help window displays basic information about LabVIEW objects when you move the
cursor over each object. The Context Help window is visible by default. To toggle display of the Context
Help window, select HelpShow Context Help, press the Ctrl-H keys, or click the Show Context Help
Window button, shown in this media, on the toolbar.
When you move the cursor over front panel and block diagram objects, the Context Help window displays
the icon for subVIs, functions, constants, controls, and indicators, with wires attached to each terminal.
When you move the cursor over dialog box options, the Context Help window displays descriptions of those
options. In the window, required connections are bold, recommended connections are plain text, and optional
connections are dimmed or do not appear. Figure 2.29 shows an example Context Help window.
Click the Hide Optional Terminals and Full Path button located on the lower left corner of the
Context Help window to display the optional terminals of a connector pane and to display the full path to
a VI. Optional terminals are shown by wire stubs, informing you that other connections exist. The detailed
mode displays all terminals, as shown in Figure 2.30.
Click the Lock Context Help button to lock the current contents of the Context Help window.
When the contents are locked, moving the cursor over another object does not change the contents of the
window. To unlock the window, click the button again. You also can access this option from the Help menu.
If a corresponding LabVIEW Help topic exists for an object the Context Help window describes, a
blue Click here for more help. link appears in the Context Help window. Also, the More Help button,
shown at left, is enabled. Click the link or the button to display the LabVIEW Help for more information
about the object.
• LabVIEW Bookshelf, which includes PDF versions of all the LabVIEW manuals and Application Notes.
• Technical support resources on the National Instruments Web site9 , such as the NI Developer Zone10
, the Knowledge Base11 , and the Product Manuals Library12 .
Figure 2.31
2. If the Functions palette is not visible, right-click any blank space on the block
diagram to display the Functions palette. Click the thumbtack, shown in this media, in the
upper left corner of the Functions palette to place the palette on the screen.
note: You can right-click a blank space on the block diagram or the front panel to display the
Functions or Controls palettes.
1. If the Context Help window is not visible, press the Ctrl-H keys to open the Context
Help window. You also can press the Show Context Help Window button, shown in this
media, to open the Context Help window.
2. Select the Input palette on the Functions palette and move the cursor over the Express VIs
on the Input palette. Notice that the Context Help window displays information about the
function of each Express VI.
3. From the information provided in the Context Help window, nd the Express VI that can
simulate a sine wave signal.
4. Select the Express VI and place it on the block diagram. The Configure Simulate Signal
dialog box appears.
5. Idle the cursor over the various options in the Configure Simulate Signal dialog box, such
as Frequency (Hz), Amplitude, and Samples per second (Hz). Read the information that
appears in the Context Help window.
6. Congure the Simulate Signal Express VI to generate a sine wave with a frequency of 10.7
and amplitude of 2.
7. Notice how the signal displayed in the Result Preview window changes to reect the cong-
ured sine wave.
8. Close the Configure Simulate Signal dialog box by clicking the OK button.
9. Move the cursor over the Simulate Signal Express VI and read the information that ap-
pears in the Context Help window. Notice that the Context Help window now displays the
conguration of the Simulate Signal Express VI.
10. Save this VI as Reduce Samples.vi in the C:\Exercises\LabVIEW Basics I directory.
Figure 2.32
1. Right-click the Mean output in the Sample Compression Express VI and select
CreateNumeric Indicator from the shortcut menu to create a numeric indicator.
2. Right-click the Mean output of the Sample Compression Express VI and select Insert
Input/Output from the shortcut menu to insert the Enable input.
3. Right-click the Enable input and select CreateControl from the shortcut menu to create
the Enableswitch.
4. Right-click the wire linking the Sine output in the Simulate Signal Express VI to the
Signals input in the Signal Compression Express VI and select CreateGraph Indicator
from the shortcut menu. Notice that you can create controls and indicators from the block di-
agram. When you create controls and indicators using this method, LabVIEW automatically
creates terminals that are labeled and formatted correctly.
5. Using the Wiring tool, wire the Mean output in the Sample Compression Express VI to the
Sine graph indicator terminal created in the previous step. Notice that the Merge Signals
function appears.
6. Arrange the objects on the block diagram so that they appear similar to Figure 2.32.
tip: You can right-click any wire and select Clean Up Wire from the shortcut menu to
automatically route an existing wire.
7. Display the front panel. Notice that the controls and indicators you added automatically
appear on the front panel with labels that correspond to their function.
8. Save this VI.
2. Display the block diagram and select the While Loop on the FunctionsExecution Control
palette.
3. Move the cursor to the upper left corner of the block diagram. Place the top left corner of
the While Loop here.
4. Click and drag the cursor diagonally to enclose all the Express VIs and wires, as shown in
Figure 2.33.
Figure 2.33
Notice that the While Loop, shown in this media, appears with a Stop
button wired to the condition terminal. This While Loop is congured to stop when the user
clicks the Stop button.
5. Display the front panel and run the VI. Notice that the VI now runs until you click the
Stop button. A While Loop executes the functions inside the loop until the user presses the
Stop button. Refer to Repetition and Loops (Section 4.1) for more information about While
Loops.
6. Click the Enable switch and notice the change on the graph. Notice how if the Enable switch
is on, the graph displays the reduced signal. If the Enable switch is o, the graph does not
display the reduced signal.
7. Click the Stop button to stop the VI.
3. If the Build Table Express VI and the Table terminal are not selected
already, click an open space on the block diagram to the left of the Build Table Express VI
and the Table terminal. Drag the cursor diagonally until the selection rectangle encloses the
Build Table Express VI and the Table terminal, shown in this media. A moving dashed
outline called a marquee highlights the Build Table Express VI, the Table terminal, and the
wire joining the two.
4. Drag the objects into the While Loop to the right of the Mean terminal. Notice that the While
Loop automatically resizes to enclose the Build Table Express VI and the Table terminal.
5. Using the Wiring tool, wire the Mean terminal of the Sample Compression Express VI to the
Signals input of the Build Table Express VI. The block diagram should appear similar to
Figure 2.34.
Figure 2.34
View an animation of the execution of the block diagram by clicking the Highlight Execution button,
shown in this media. Execution highlighting shows the ow of data on the block diagram from one node
to another using bubbles that move along the wires. Use execution highlighting in conjunction with single-
stepping to see how data move from node to node through a VI.
note: Execution highlighting greatly reduces the speed at which the VI runs.
2.10.3 Single-Stepping
Single-step through a VI to view each action of the VI on the block diagram as the VI runs. The single-
stepping buttons aect execution only in a VI or subVI in single-step mode. Enter single-step mode by
clicking the Step Over or Step Into button. Move the cursor over the Step Over, Step Into, or Step Out
button to view a tip strip that describes the next step if you click that button. You can single-step through
subVIs or run them normally.
If you single-step through a VI with execution highlighting on, an execution glyph, shown in this
media, appears on the icons of the subVIs that are currently running.
2.10.4 Probes
Use the Probe tool, shown in this media, to check intermediate values on a wire as a VFI runs. When
execution pauses at a node because of single-stepping or a breakpoint, you also can probe the wire that just
executed to see the value that owed through that wire.
You also can create a custom probe to specify which indicator you use to view the probed data. For
example, if you are viewing numeric data, you can choose to see that data in a chart within the probe. To
create a custom probe, right-click a wire and select Custom ProbeNew from the shortcut menu.
2.10.5 Breakpoints
Use the Breakpoint tool, shown in this media, to place a breakpoint on a VI, node, or wire on the
block diagram and pause execution at that locatiFon. When you set a breakpoint on a wire, execution pauses
after data pass through the wire. Place a breakpoint on the block diagram workspace to pause execution
after all nodes on the block diagram execute. When a VI pauses at a breakpoint, LabVIEW brings the
block diagram to the front and uses a marquee to highlight the node or wire that contains the breakpoint.
LabVIEW highlights breakpoints with red borders for nodes and block diagrams and red bullets for wires.
When you move the cursor over an existing breakpoint, the black area of the Breakpoint tool cursor appears
white. Use the Breakpoint tool to click an existing breakpoint to remove it.
Figure 2.35
Notice the Run button on the toolbar appears broken, shown in this media, indicating
that the VI is broken and cannot run.
Figure 2.36
number to multiply by the random number. The Debug Exercise (Sub) VI, located
in the C:\Exercises\ LabVIEW Basics I directory, adds 100.0 and calculates the square
root of the value.
2. Find and x each error.
a. Click the broken Run button to display the Error list window, which lists all the errors.
b. Select an error description in the Error list window. The Details section describes
the error and in some cases recommends how to correct the error.
c. Click the Help button to display a topic in the LabVIEW Help that describes the error
in detail and includes step-by-step instructions for correcting the error.
d. Click the Show Error button or double-click the error description to highlight the area
on the block diagram that contains the error.
e. Use the Error list window to x each error.
3. Select FileSave to save the VI.
4. Display the front panel by clicking it or by selecting WindowShow Front Panel.
a. Click the Highlight Execution button, shown in this media, on the toolbar to
enable execution highlighting.
b. Click the Step Into button, shown in this media, to start single-stepping. Exe-
cution highlighting shows the movement of data on the block diagram from one node to
another using bubbles that move along the wires. Nodes blink to indicate they are ready
to execute.
c. Click the Step Over button, shown in this media, after each node to step through
the entire block diagram. Each time you click the Step Over button, the current node
executes and pauses at the next node. Data appear on the front panel as you step
through the VI. The VI generates a random number and multiplies it by 10.0. The
subVI adds 100.0 and takes the square root of the result.
d. When a blinking border surrounds the entire block diagram, click the Step Out but-
ton, shown in this media, to stop single-stepping through the Debug Exercise (Main)
VI.
4. Single-step through the VI and its subVI.
a. Click the Step Into button to start single-stepping.
b. When the Debug Exercise (Sub) VI blinks, click the Step Into button. Notice
the run button on the subVI.
c. Display the Debug Exercise (Main) VI block diagram by clicking it. A green
glyph, shown in this media, appears on the subVI icon on the Debug Exercise (Main)
VI block diagram, indicating that the subVI is running.
d. Display the Debug Exercise (Sub) VI block diagram by clicking it.
e. Click the Step Out button twice to nish single-stepping through the subVI block dia-
gram. The Debug Exercise (Main) VI block diagram is active.
f. Click the Step Out button to stop single-stepping.
5. Use a probe to check intermediate values on a wire as a VI runs.
a. Use the Probe tool, shown this media, to click any wire. A window similar to
Figure 2.37 appears.
Figure 2.37
LabVIEW numbers the Probe window automatically and displays the same number in
a glyph on the wire you clicked.
b. Single-step through the VI again. The Probe window displays data passed along the
wire.
6. Place breakpoints on the block diagram to pause execution at that location.
a. Use the Breakpoint tool, shown in this media, to click nodes or wires. Place a
breakpoint on the block diagram to pause execution after all nodes on the block diagram
execute.
b. Click the Run button to run the VI. When you reach a breakpoint during execution, the
VI pauses and the Pause button on the toolbar appears red.
c. Click the Continue button, shown this media, to continue running to the next
breakpoint or until the VI nishes running.
d. Use the Breakpoint tool to click the breakpoints you set and remove them.
7. Click the Highlight Execution button to disable execution highlighting.
8. Select FileClose to close the VI and all open windows.
2.12.1 Summary
• Virtual instruments (VIs) contain three main components-the front panel, the block diagram, and the
icon and connector pane.
• The front panel is the user interface of a VI and species the inputs and displays the outputs of the
VI.
• The block diagram contains the graphical source code composed of nodes, terminals, and wires.
• Use the Tools palette to create, modify, and debug VIs. Press the Shift key and right-click to display
a temporary version of the Tools palette at the location of the cursor.
• Use the Controls palette to place controls and indicators on the front panel. Right-click an open space
on the front panel to display the Controls palette.
• Use the Functions palette to place VIs and functions on the block diagram. Right-click an open space
on the block diagram to display the Functions palette.
• Use the Search button on the Controls and Functions palettes to search for controls, VIs, and
functions.
• All LabVIEW objects and empty space on the front panel and block diagram have associated shortcut
menus, which you access by right-clicking an object, the front panel, or the block diagram.
• Use the Help menu to display the Context Help window and the LabVIEW Help, which describes
most palettes, menus, tools, VIs, functions, and features.
• Select HelpSearch the LabVIEW Bookshelf to display the LabVIEW Bookshelf, which you can use
to search PDF versions of all the LabVIEW manuals and Application Notes.
• You build the front panel with controls and indicators, which are the interactive input and output
terminals of the VI, respectively.
• Control terminals have a thicker border than indicator terminals. To change a control to an indicator or
to change an indicator to a control, right-click the object and select Change to Indicator or Change
to Control from the shortcut menu.
• The block diagram is composed of nodes, terminals, and wires.
• The broken Run button appears on the toolbar to indicate the VI is broken. Click the broken Run
button to display the Error list window, which lists all the errors.
• Use execution highlighting, single-stepping, probes, and breakpoints to debug VIs by animating the
ow of data through the block diagram.
• To increment or decrement numeric controls faster, use the Operating or Labeling tools to place the
cursor in the control and press the Shift key while pressing the up or down arrow keys.
• You can disable the debugging tools to reduce memory requirements and to increase performance
slightly. Select FileVI Properties, select Execution from the top pull-down menu, and remove
the checkmark from the Allow Debugging checkbox.
2.12.2.2 Wiring
• Click the Show Context Help Window button on the toolbar to display the Context Help window.
Use the Context Help window to determine which terminals are required. Required terminals are
bold, recommended connections are plain text, and optional connections are dimmed.
• Press the spacebar to toggle the wire direction.
• To move objects one pixel, press the arrow keys. To move objects several pixels, press the Shift key
while you press the arrow keys.
• To cancel a wire you started, press the Esc key, right-click, or click the terminal where you started the
wire.
• Use the tip strips that appear as you move the Wiring tool over terminals.
• Display the connector pane by right-clicking the node and selecting Visible ItemsTerminals from
the shortcut menu.
• You can bend a wire by clicking to tack the wire down and moving the cursor in a perpendicular
direction. To tack down a wire and break it, double-click.
Figure 2.38: 1. Tack Down a Wire by Clicking, 2. Tack and Break the Wire by Double-clicking
2.12.2.3 Editing
• Use the following shortcuts to create constants, controls, and indicators:
- Right-click a function terminal and select CreateConstant, CreateControl, or
CreateIndicator from the shortcut menu.
- Drag controls and indicators from the front panel to the block diagram to create a constant.
- Drag constants from the block diagram to the front panel to create a control.
• To duplicate an object, press the Ctrl key while using the Positioning tool to click and drag a selection.
• To restrict an object's direction of movement horizontally or vertically, use the Positioning tool to
select the object and press the Shift key while you move the object.
• To keep an object proportional to its original size as you resize it, press the Shift key while you drag
the resizing handles or circles.
• To resize an object as you place it on the front panel, press the Ctrl key while you click to place the
object and drag the resizing handles or circles.
• To replace nodes, right-click the node and select Replace from the shortcut menu.
• To display the block diagram of a subVI from the calling VI, press the Ctrl key and use the Operating
or Positioning tool to double-click the subVI on the block diagram.
• To display the front panel of a subVI from the calling VI, use the Operating or Positioning tool to
double-click the subVI on the block diagram. You also can select BrowseThis VI's SubVIs.
• After you type a label, press the Enter key to end text entry.
• To add items quickly to ring controls and Case structures, press the Shift-Enter keys after each item.
Pressing Shift-Enter accepts the item and positions the cursor to add the next item. Refer to Making
Decisions in a VI (Section 8.2) for more information about Case structures.
• To copy the color of one object and transfer it to a second object without using a color picker, use the
Color Copy tool to click the object whose color you want to copy. Use the Coloring tool to click the
object to which you want to apply the color. You also can copy the color of one object by using the
Coloring tool and pressing the Ctrl key.
• Select EditUndo if you make a mistake.
• To create more blank space on the block diagram, press the Ctrl key while you use the Positioning
tool to draw a rectangle on the block diagram.
2.12.2.4 Debugging
• When single-stepping, use the following keyboard shortcuts:
Modular Programming
After you build a front panel and block diagram, build the icon and the connector pane so you can
use the VI as a subVI. Every VI displays an icon, such as the one shown in this media, in the upper right
corner of the front panel and block diagram windows. An icon is a graphical representation of a VI. It can
contain text, images, or a combination of both. If you use a VI as a subVI, the icon identies the subVI on
the block diagram of the VI. You can double-click the icon to customize or edit it.
You also need to build a connector pane, shown in this media, to use the VI as a subVI. The
connector pane is a set of terminals that correspond to the controls and indicators of that VI, similar to
the parameter list of a function call in text-based programming languages. The connector pane denes the
inputs and outputs you can wire to the VI so you can use it as a subVI. A connector pane receives data
at its input terminals and passes the data to the block diagram code through the front panel controls and
receives the results at its output terminals from the front panel indicators.
As you create VIs, you might nd that you perform a certain operation frequently. Consider using subVIs
or loops to perform that operation repetitively. For example, the block diagram in Figure 3.1 contains two
identical operations.
1 This content is available online at <http://cnx.org/content/m12204/1.2/>.
Figure 3.1
You can create a subVI that performs that operation and call the subVI twice. The example in Figure 3.2
calls the Temperature VI as a subVI twice on its block diagram and functions the same as the previous
block diagram.You also can reuse the subVI in other VIs. Refer to Repetition and Loops (Section 4.1) for
more information about using loops to combine common operations.
Figure 3.2
Refer to the LabVIEW Basics II: Development Course Manual for more information about application
development. The following pseudo-code and block diagrams demonstrate the analogy between subVIs and
subroutines.
main { average (point1, point2, pointavg) function average (in1, in2, out) { out =
} (in1 + in2)/2.0; }
Table 3.1
Every VI displays an icon, shown in this media, in the upper right corner of the front panel and block
diagram windows. An icon is a graphical representation of a VI. It can contain text, images, or a combination
of both. If you use a VI as a subVI, the icon identies the subVI on the block diagram of the VI.
The default icon contains a number that indicates how many new VIs you have opened since launching
LabVIEW. Create custom icons to replace the default icon by right-clicking the icon in the upper right corner
of the front panel or block diagram and selecting Edit Icon from the shortcut menu or double-clicking the
icon in the upper right corner of the front panel. You also can edit icons by selecting FileVI Properties
selecting General from the Category pull-down menu, and clicking the Edit Icon button.
Use the tools on the left side of the Icon Editor dialog box to create the icon design in the editing
area. The normal size image of the icon appears in the appropriate box to the right of the editing area, as
shown in the dialog box in Figure 3.3.
2 This content is available online at <http://cnx.org/content/m12205/1.2/>.
Figure 3.3
Depending on the type of monitor you use, you can design a separate icon for monochrome, 16-color, and
256-color mode. LabVIEW uses the monochrome icon for printing unless you have a color printer.
Use the Edit menu to cut, copy, and paste images from and to the icon. When you select a portion of
the icon and paste an image, LabVIEW resizes the image to t into the selection area. You also can drag a
graphic from anywhere in your le system and drop it in the upper right corner of the front panel or block
diagram. LabVIEW converts the graphic to a 32 × 32 pixel icon.
Use the Copy from option on the right side of the Icon Editor dialog box to copy from a color icon
to a black-and-white icon and vice versa. After you select a Copy from option, click the OK button to
complete the change.
note: If you do not draw a complete border around a VI icon, the icon background appears
transparent. When you select the icon on the block diagram, a selection marquee appears around
each individual graphic element in the icon.
Use the tools on the left side of the Icon Editor dialog box to create the icon design in the editing
area. The normal size image of the icon appears in the appropriate box to the right of the editing area. The
following tasks can be performed with these tools:
• Use the Line tool to draw straight lines. To draw horizontal, vertical, and diagonal lines, press
the <Shift> key while you use this tool to drag the cursor.
• Use the Color Copy tool to copy the foreground color from an element in the icon.
• Use the Fill tool to ll an outlined area with the foreground color.
• Use the Rectangle tool to draw a rectangular border in the foreground color. Double-click this
tool to frame the icon in the foreground color.
• Use the Filled Rectangle tool to draw a rectangle with a foreground color frame and lled with
the background color. Double-click this tool to frame the icon in the foreground color and ll it with
the background color.
• Use the Select tool to select an area of the icon to cut, copy, move, or make other changes.
Double-click this tool and press the <Delete> key to delete the entire icon.
• Use the Text tool to enter text into the icon. Double-click this tool to select a dierent font.
(Windows) The Small Fonts option works well in icons.
• Use the Foreground/Background tool to display the current foreground and background
colors. Click each rectangle to display a color palette from which you can select new colors.
• Use the options on the right side of the editing area to perform the following tasks:
Show Terminals - Displays the terminal pattern of the connector pane.
OK - Saves the drawing as the icon and returns to the front panel.
Cancel - Returns to the front panel without saving any changes.
• The menu bar in the Icon Editor dialog box contains more editing options such as Undo, Redo,
Cut, Copy, Paste , and Clear .
To use a VI as a subVI, you need to build a connector pane, shown in this media. The connector
pane is a set of terminals that corresponds to the controls and indicators of that VI, similar to the parameter
list of a function call in text-based programming languages. The connector pane denes the inputs and
outputs you can wire to the VI so you can use it as a subVI.
Dene connections by assigning a front panel control or indicator to each of the connector pane terminals.
To dene a connector pane, right-click the icon in the upper right corner of the front panel window and select
Show Connector from the shortcut menu. The connector pane replaces the icon. Each rectangle on the
connector pane represents a terminal. Use the rectangles to assign inputs and outputs. The number of
terminals LabVIEW displays on the connector pane depends on the number of controls and indicators on
the front panel. The following front panel has four controls and one indicator, so LabVIEW displays four
input terminals and one output terminal on the connector pane.
Figure 3.4
The most commonly used pattern is shown in this media. This pattern is used as a standard to
assist in simplifying wiring. The top inputs and outputs are commonly used for passing references and the
bottom inputs and outputs are used for error handling. Refer to the section on Clusters (Section 6.5) for
more information about error handling.
note: Try not to assign more than 16 terminals to a VI. Too many terminals can reduce the
readability and usability of the VI.
To change the spatial arrangement of the connector pane patterns, right-click the connector pane and
select Flip Horizontal, Flip Vertical, or Rotate 90 Degrees from the shortcut menu.
Figure 3.5
2. (Optional) Select WindowTile Left and Right to display the front panel and block
diagram side by side or WindowTile Up and Down to display the front panel and block
diagram stacked.
3. Create a numeric control. You will use this control to enter the value for degrees Celsius.
a. Select ControlsNumeric Controls to display the Numeric Controls palette.
If the Controls palette is not visible, right-click an open space on the front panel
workspace to display it.
b. Select the Numeric Control. Move the control to the front panel and click to
place the control.
c. Type deg C in the label of the control and press the <Enter> key or click the Enter
button, shown in this media, on the toolbar. If you do not type the name immediately,
LabVIEW uses a default label.
note: You can edit a label at any time by double-clicking the label, using the Labeling tool,
or right-clicking and selecting Properties from the shortcut menu to display the property
dialog box.
4. Create a numeric indicator. You will use this indicator to display the value for degrees
Fahrenheit.
6. Use the Wiring tool, shown in this media, to wire the icons as shown in Figure 3.6.
Figure 3.6
• To wire from one terminal to another, use the Wiring tool to click the rst terminal,
move the tool to the second terminal, and click the second terminal. You can start wiring
at either terminal.
• You can bend a wire by clicking to tack down the wire and moving the cursor in a
perpendicular direction. Press the spacebar to toggle the wire direction.
• To identify terminals on the nodes, right-click the Multiply and Add functions and
select Visible ItemsTerminals from the shortcut menu to display the connector
pane on the block diagram. Return to the icons after wiring by right-clicking the func-
tions and selecting Visible ItemsTerminals from the shortcut menu to remove
the checkmark.
• When you move the Wiring tool over a terminal, the terminal area blinks, indicating
that clicking will connect the wire to that terminal and a tip strip appears, displaying
the name of the terminal. If the Context Help window is open, the terminal area also
blinks in the Context Help window.
• To cancel a wire you started, press the <Esc> key, right-click, or click the terminal
where you started the wire.
7. Display the front panel by clicking it or by selecting WindowShow Front Panel.
8. Save the VI as Convert C to F.vi in the C:\Exercises\LabVIEW Basics I directory.
a. Use the Operating tool, shown in this media, or the Labeling tool to double-click
the numeric control and type a new number.
2. Double-click the Select tool, shown in this media, on the left side of the Icon Editor
dialog box to select the default icon.
3. Press the <Delete> key to remove the default icon.
4. Double-click the Rectangle tool, shown in this media, to redraw the border.
5. Create the icon in Figure 3.7.
Figure 3.7
a. Double-click the Text tool, shown in this media, and change the font to Small
Fonts .
b. Use the Text tool to click the editing area where you will begin typing.
c. Type C and F. While the text is active, you can move the text by pressing the arrow
keys.
d. Use the Pencil tool, shown in this media, to create the arrow.
note: To draw horizontal or vertical straight lines, press the <Shift> key while you
use the Pencil tool to drag the cursor.
e. Use the Select tool and the arrow keys to move the text and arrow you created.
f. Select the B & W icon and click the 256 Colors button in the Copy from section
to create a black and white icon, which LabVIEW uses for printing unless you have a
color printer.
g. Select the 16 Colors icon and click the 256 Colors button in the Copy from
section.
h. When you complete the icon, click the OK button to close the Icon Editor dialog
box. The icon appears in the upper right corner of the front panel and block diagram.
6. Right-click the icon on the front panel and select Show Connector from the shortcut
menu to dene the connector pane terminal pattern. LabVIEW selects a default connector
pane pattern based on the number of controls and indicators on the front panel. For example,
this front panel has two terminals, deg C and deg F , so LabVIEW selects a connector
pane pattern with two terminals, shown in this media.
7. Assign the terminals to the numeric control and numeric indicator.
a. Select HelpShow Context Help to display the Context Help window.
b. Click the left terminal in the connector pane. The tool automatically changes to the
Wiring tool, and the terminal turns black.
c. Click the deg C control. A marquee highlights the control on the front panel.
d. Click an open space on the front panel. The marquee disappears, and the terminal
changes to the data type color of the control to indicate that you connected the terminal.
e. Click the right terminal in the connector pane, and click the deg F indicator.
f. Click an open space on the front panel. Both terminals of the connector pane are orange.
g. Move the cursor over the connector pane. The Context Help window shows that both
terminals are connected to double-precision, oating-point values.
8. Save and close the VI. You will use this VI later in the course.
You can designate which inputs and outputs are required, recommended, and optional to prevent users
from forgetting to wire subVI terminals.
Right-click a terminal in the connector pane and select This Connection Is from the shortcut menu.
A checkmark indicates the terminal setting. Select Required, Recommended, or Optional .
For terminal inputs, required means that the block diagram on which you placed the subVI will be broken
if you do not wire the required inputs. Required is not available for terminal outputs. For terminal inputs
and outputs, recommended or optional means that the block diagram on which you placed the subVI can
execute if you do not wire the recommended or optional terminals. If you do not wire the terminals, the VI
does not generate any warnings.
LabVIEW sets inputs and outputs of VIs you create to Recommended by default. Set a terminal setting
to required only if the VI must have the input or output to run properly. Refer to the Read File function
located on the FunctionsAll FunctionsFile I/O palette for examples of required, recommended,
and optional inputs and outputs.
Figure 3.8
b. Type Temperature in the label and press the <Enter> key or click the Enter
button on the toolbar, shown at left.
c. Right-click the thermometer and select Visible Items Digital Display from the
shortcut menu to show the digital display for the thermometer.
5 This content is available online at <http://cnx.org/content/m12209/1.1/>.
d. Place a vertical toggle switch control, located on the ControlsButtons & Switches
palette, on the front panel.
e. Type Temp Scale in the label and press the <Enter> key or click the Enter button.
f. Use the Labeling tool, shown in this media, to place a free label, deg C, next to
the True position of the switch. If you are using automatic tool selection, double-click
the blank area of the front panel to begin typing a free label.
g. Place a free label, deg F , next to the False position of the switch.
Figure 3.9
2. Place the DAQ Assistant Express VI, located on the FunctionsInput palette, on
the block diagram. When you place this Express VI on the block diagram the DAQ Assistant
conguration dialog box appears.
a. Select Analog InputVoltage for the type of measurement to make.
b. Select Dev1ai0 (or Dev2ai0) for the physical channel and click the Finish button.
c. You must multiply the temperature by 100 to convert it from voltage to Celsius. On the
Settings tab, select Custom ScalingCreate New. Select a Linear scale. Name the
scale Temperature. Enter a slope scale of 100. Click the OK button.
d. Set min = 0. Set max = 100
e. Select the Acquire 1 Sample option on the Task Timing tab. Click the OK button.
note: If you do not have a DAQ device with a temperature sensor connected to your
computer, use the (Demo) Read Voltage VI, located in the C:\Exercises LabVIEW
Basics I directory.
3. Place the Convert from Dynamic Data Express VI, located on the
FunctionsSignal Manipulation palette, on the block diagram. This VI converts
the dynamic data type. In the conguration dialog box, select Single scalar in the
Resulting data type listbox.
2. Click the Run Continuously button, shown at left, to run the VI continuously.
3. Put your nger on the temperature sensor and notice the temperature increase.
4. Click the Run Continuously button again to stop the VI. This allows the VI to nish the
current run of the VI.
Figure 3.10
a. Right-click the icon in the upper right corner of the front panel and select Edit Icon
from the shortcut menu. The Icon Editor dialog box appears.
b. Double-click the Select tool, shown at left, on the left side of the Icon Editor
dialog box to select the default icon.
c. Press the <Delete> key to remove the default icon.
d. Double-click the Rectangle tool, shown at this media, to redraw the border.
e. Use the Pencil tool, shown in this media, to draw an icon that represents the
thermometer.
f. Use the Foreground and Fill tools to color the thermometer red.
note: To draw horizontal or vertical straight lines, press the <Shift> key while you
use the Pencil tool to drag the cursor.
g. Double-click the Text tool, shown in this media, and change the font to Small
Fonts.
h. Type Temp. Reposition the text if necessary.
i. Select the B & W icon and select 256 Colors in the Copy from section to create a
black and white icon, which LabVIEW uses for printing unless you have a color printer.
j. When the icon is complete, click the OK button. The icon appears in the upper right
corner of the front panel.
2. Right-click the icon and select Show Connector from the shortcut menu and assign terminals
to the switch and the thermometer.
a. Click the left terminal in the connector pane.
b. Click the Temp Scale control. The left terminal turns green.
c. Click the right terminal in the connector pane.
d. Click the Temperature indicator. The right terminal turns orange.
e. Click an open space on the front panel.
3. Save the VI as Thermometer.vi in the C:\Exercises\ LabVIEW Basics I directory.You
will use this VI later in the course.
4. Close the VI.
Figure 3.11
The new subVI uses a default pattern for the connector pane and a default icon. Double-click the subVI
to edit the connector pane and icon, and to save the subVI.
note: Do not select more than 28 objects to create a subVI because 28 is the maximum number
of connections on a connector pane.
Figure 4.1
The While Loop is located on the FunctionsExecution Control palette. Select the While Loop
from the palette then use the cursor to drag a selection rectangle around the section of the block diagram
you want to repeat. When you release the mouse button, a While Loop boundary encloses the section you
selected.
Add block diagram objects to the While Loop by dragging and dropping them inside the While Loop.
note: The While Loop always executes at least once.
The While Loop executes the subdiagram until the conditional terminal, an input terminal, receives
a specic Boolean value. The default behavior and appearance of the conditional terminal is Stop If True,
shown in this media. When a conditional terminal is Stop If True, the While Loop executes its subdiagram
until the conditional terminal receives a True value.
The iteration terminal, an output terminal, shown in this media, contains the number of completed
iterations. The iteration count always starts at zero. During the rst iteration, the iteration terminal returns
0.
In the block diagram in Figure 4.2, the While Loop executes until the subVI output is greater than or
equal to 10.00 and the Enable control is True. The And function returns True only if both inputs are True.
Otherwise, it returns False.
1 This content is available online at <http://cnx.org/content/m12212/1.2/>.
Figure 4.2
In the previous example (Figure 4.2), there is an increased probability of an innite loop. Generally, the
desired behavior is to have one condition met to stop the loop, rather than requiring both conditions to be
met.
You can change the behavior and appearance of the conditional terminal by right-clicking the terminal
or the border of the While Loop and selecting Continue if True, shown at left. You also can use the
Operating tool to click the conditional terminal to change the condition. When a conditional terminal is
Continue if True, the While Loop executes its subdiagram until the conditional terminal receives a False
value, as shown in Figure 4.3.
Figure 4.3
The While Loop executes until the subVI output is less than 10.00 or the Enable control is False.
Figure 4.4
Only the last value of the iteration terminal displays in the Iteration Number indicator.
Figure 4.5
Figure 4.6
Each time the loop executes, the iteration terminal increments by one. The iteration
count passes out of the loop upon completion. Increment this value by one outside the
loop because the count starts at 0.
3. To see how the VI updates the indicators, enable execution highlighting. On the block
diagram toolbar, click the Highlight Execution button, shown at left, to enable execution
highlighting. Execution highlighting shows the movement of data on the block diagram from
one node to another so you can see each number as the VI generates it.
4. Change Number to Match to a number that is out of the data range, which is 0 to 10000 with
an increment of 1.
5. Run the VI. LabVIEW coerces the out-of-range value to the nearest value in the specied
data range.
6. Close the VI.
Figure 4.7
The For Loop is located on the FunctionsAll FunctionsStructures palette. You also can
place a While Loop on the block diagram, right-click the border of the While Loop, and select Replace
3 This content is available online at <http://cnx.org/content/m12214/1.2/>.
with For Loop from the shortcut menu to change a While Loop to a For Loop. The value in the count
terminal (an input terminal), shown in this media, indicates how many times to repeat the subdiagram.
The iteration terminal (an output terminal), shown in this media, contains the number of completed
iterations. The iteration count always starts at zero. During the rst iteration, the iteration terminal returns
0.
The For Loop diers from the While Loop in that the For Loop executes a set number of times. A
While Loop stops executing the subdiagram only if the value at the conditional terminal exists.
The For Loop in Figure 4.8 generates a random number every second for 100 seconds and displays the
random numbers in a numeric indicator.
Figure 4.8
The Wait Until Next ms Multiple function, shown in this media, monitors a millisecond counter
and waits until the millisecond counter reaches a multiple of the amount you specify. Use this function to
synchronize activities. Place this function within a loop to control the loop execution rate.
The Wait (ms) function, shown in this media, adds the wait time to the code execution time.
This can cause a problem if code execution time is variable.
note: The Time Delay Express VI, located on the FunctionsExecution Control palette,
behaves similar to the Wait (ms) function with the addition of built-in error clusters. Refer to
Clusters (Section 6.5) for more information about error clusters.
Figure 4.9
If you wire two dierent numeric data types to a numeric function that expects the inputs to be the
same data type, LabVIEW converts one of the terminals to the same representation as the other terminal.
LabVIEW chooses the representation that uses more bits. If the number of bits is the same, LabVIEW
chooses unsigned over signed.
In the example in Figure 4.10, a 32-bit signed integer (I32) and a double-precision, oating-point numeric
value (DBL) are wired to the Divide function. The 32-bit signed integer is coerced since it uses fewer bits
than the double-precision, oating-point numeric value.
Figure 4.10
To change the representation of a numeric object, right-click the object and select Representation from
the shortcut menu. Select the data type that best represents the data.ut data types.
When LabVIEW converts double-precision, oating-point numeric values to integers, it rounds to the
nearest integer. LabVIEW rounds x.5 to the nearest even integer. For example, LabVIEW rounds 2.5 to 2
and 3.5 to 4.
Refer to the Data Types section of Introduction to LabVIEW, of this manual or to the LabVIEW Help
for more information about data types.
Figure 4.11
Figure 4.12
note: If you do not have a DAQ device with a temperature sensor on Channel 0, use
the (Demo) Thermometer VI instead.
4.4.3 Optional
1. Build a VI that generates random numbers in a While Loop and stops when you click a stop
button on the front panel.
2. Save the VI as General While Loop.vi in the C:\Exercises\LabVIEW Basics I directory.
4.4.4 Challenge
1. Modify the General While Loop VI to stop when the stop button is clicked or when the
While Loop reaches a number of iterations specied by a front panel control.
2. Select FileSave As to save the VI as Combo While-For Loop.vi in the
C:\Exercises\LabVIEW Basics I directory.
A shift register transfers any data type and automatically changes to the data type of the rst object
wired to the shift register. The data you wire to the terminals of each shift register must be the same type.
To initialize a shift register, wire any value from outside the loop to the left terminal. If you do not
initialize the shift register, the loop uses the value written to the shift register when the loop last
executed or the default value for the data type if the loop has never executed.
Use a loop with an uninitialized shift register to run a VI repeatedly so that each time the VI runs, the
initial output of the shift register is the last value from the previous execution. Use an uninitialized shift
register to preserve state information between subsequent executions of a VI. After the loop executes, the
last value stored in the shift register remains at the right terminal. If you wire the right terminal outside
the loop, the wire transfers the last value stored in the shift register.
You can add more than one shift register to a loop. If you have multiple operations within a loop,
use multiple shift registers to store the data values from those dierent processes in the structure. The
block diagram in Figure 4.13 uses two initialized shift registers.
Figure 4.13
Figure 4.14
If you add two more elements to the left terminal, values from the last three iterations carry over to
the next iteration, with the most recent iteration value stored in the top shift register. The second
terminal stores the data passed to it from the previous iteration, and the bottom terminal stores data from
two iterations ago.
Figure 4.15
Figure 4.16
The 1 wired to the left terminals on the For Loop initializes the Feedback Node to 1. The
Wait Until Next ms Timer slows the operation of the code. You also could use Highlight
Execution instead of the wait function to slow the operation. The same code is used twice
in this block diagram with the Feedback Node in a dierent portion of the wire.
2. Click the Highlight Execution button, shown in this media, to enable execution high-
lighting. Run the VI again to observe the order of execution. Turn o execution highlighting
when you understand the execution order. The VI continues executing at normal speed.
3. Replace the bottom Feedback Node with a shift register, as shown in Figure 4.17.
Figure 4.17
a. Select the bottom Feedback Node and press the <Delete key to delete it.
b. Right-click the border of the For Loop and select Add Shift Register.
c. Initialize the shift register by wiring 1 to the left shift register.
d. Change the label of the bottom indicator to Shift Register and the top indicator to
Feedback Node.
4. Run the VI. Notice that both the Feedback Node and the shift register portions of the
block diagram have the same functionality.
5. If time permits, complete the following optional steps; otherwise, close the VI and do not save
changes.
4.6.4 Optional
1. Revise the shift register to display the last three iterations of the For Loop data, as shown
in Figure 4.18.
Figure 4.18
a. Resize the left shift register to three elements. Right-click the shift register and
select Add Element from the shortcut menu to add each shift register.
b. Initialize each elements of the shift register to 1.
c. Right-click each element of the shift register and select CreateIndicator. Label
each indicator.
2. Run the VI.
3. Close the VI. Do not save changes.
Arrays
5.1 Arrays1
Arrays group data elements of the same type. An array consists of elements and dimensions. Elements are
the data that make up the array. A dimension is the length, height, or depth of an array. An array can have
one or more dimensions and as many as 231 − 1 elements per dimension, memory permitting.
You can build arrays of numeric, Boolean, path, string, waveform, and cluster data types. Consider
using arrays when you work with a collection of similar data and when you perform repetitive computations.
Arrays are ideal for storing data you collect from waveforms or data generated in loops, where each iteration
of a loop produces one element of the array.
You cannot create an array of arrays. However, you can create an array of clusters, where each cluster
contains one or more arrays. Refer to Clusters (Section 6.1) for more information about clusters.
Array elements are ordered. An array uses an index so you can readily access any particular element.
The index is zero-based, which means it is in the range 0 to n − 1, where n is the number of elements in the
array. For example, if you create an array of the planets in the solar system, n = 9 for the nine planets, so
the index ranges from 0 to 8. Earth is the third planet, so it has an index of 2.
You must insert an object in the array shell before you use the array on the block diagram. Otherwise,
the array terminal appears black with an empty bracket.
1 This content is available online at <http://cnx.org/content/m12220/1.2/>.
Figure 5.2
To add dimensions to an array one at a time, right-click the index display and select Add Dimension
from the shortcut menu. You also can use the Positioning tool to resize the index display until you have
as many dimensions as you want. Figure 5.3 is an example of an uninitialized 2D array control.
Figure 5.3
5.2 Auto-Indexing2
If you wire an array to a For Loop or While Loop input tunnel, you can read and process every element
in that array by enabling auto-indexing. When you auto-index an array output tunnel, the output array
receives a new element from every iteration of the loop. The wire from the output tunnel to the array
indicator becomes thicker as it changes to an array at the loop border, and the output tunnel contains
square brackets representing an array, as shown in Figure 5.4.
2 This content is available online at <http://cnx.org/content/m12221/1.1/>.
Figure 5.4
Disable auto-indexing by right-clicking the tunnel and selecting Disable Indexing from the shortcut
menu. For example, disable auto-indexing if you need only the last value passed to the tunnel in the
previous example.
Because you can use For Loops to process arrays an element at a time, LabVIEW enables auto-indexing
by default for every array you wire to a For Loop and for each output tunnel that is created. Auto-indexing
for While Loops is disabled by default. To enable auto-indexing, right-click a tunnel and select Enable
Indexing from the shortcut menu.
Figure 5.5
Figure 5.6
If you enable auto-indexing for more than one tunnel or if you wire the count terminal, the count changes
to the smaller of the two. For example, if you wire an array with 10 elements to a For Loop input tunnel
and you set the count terminal to 15, the loop executes only 10 times.
Array Size - Returns the number of elements in each dimension of an array. If the array is
n-dimensional, the size output is an array of n elements. For example, the Array Size function
returns a size of 3 for the following array.
7 4 2
Table 5.1
4 4 4
Table 5.2
7 4 2
4 4 4
Table 5.3
To concatenate the inputs into a longer array of the same dimension as shown in the following
array, right-click the function node and select Concatenate Inputs from the shortcut menu to
create the following array.
7 4 2 4 4 4
Table 5.4
Array Subset - Returns a portion of an array starting at index and containing length
elements. For example, if you use the previous array as the input, the Array Subset function
returns the following array for an index of 2 and a length of 3.
2 4 4
Table 5.5
Index Array - Returns the element or sub-array of n-dimension array at index. For
example, if you use the previous array as the input, the Index Array function returns 2 for an
index of 0. You also can use the Index Array function to extract a row or column of a 2D array
to create a subarray of the original. To do so, wire a 2D array to the input of the function. Two
index terminals are available. The top index terminal indicates the row, and the second terminal
indicates the column. You can wire inputs to both index terminals to index a single element,
or you can wire only one terminal to extract a row or column of data. For example, wire the
following array to the input of the function.
7 4 2
4 4 4
Table 5.6
The Index Array function returns the following array for an index (row) of 0:
7 4 2
Table 5.7
5.4 Polymorphism4
The Numeric functions located on the FunctionsExpress Numeric and FunctionsAll
FunctionsNumeric palettes are polymorphic. This means that the inputs to these functions can
be dierent data structures, such as scalar values and arrays. For example, you can use the Add function
to add a scalar value to an array or to add two arrays together. If you wire a scalar value of 2 and the
following array to the Add function.
1 3 2
Table 5.8
The function adds the scalar value to each element of the array and returns the following array:
3 5 4
Table 5.9
If you wire the previous two arrays to the Add function, the function adds each element of one array to
the corresponding element of the other array and returns the following array:
4 8 6
Table 5.10
Wire two arrays of dierent sizes to the Add function, such as the previous array and the following array:
3 1 2 3
Table 5.11
The function adds corresponding elements and returns the following array, which is the size of the smaller
input array:
7 9 8
Table 5.12
You use the Numeric functions with clusters the same way you use them with arrays of numeric values.
Refer to Clusters (Section 6.1) for more information about clusters.
Figure 5.7
Figure 5.8
tip: Use the Decimate 1D Array function located on the FunctionsAll FunctionsArray
palette.
Save the VI as Array Pair Multiplier.vi in the C:\Exercises\LabVIEW Basics I directory.
Clusters
6.1 Clusters1
Clusters group data elements of mixed types, such as a bundle of wires, as in a telephone cable, where each
wire in the cable represents a dierent element of the cluster. A cluster is similar to a record or a struct in
text-based programming languages.
Bundling several data elements into clusters eliminates wire clutter on the block diagram and reduces
the number of connector pane terminals that subVIs need. The connector pane has, at most, 28 terminals.
If a front panel contains more than 28 controls and indicators that you want to use programmatically, group
some of them into a cluster and assign the cluster to a terminal on the connector pane. Like an array, a
cluster is either a control or an indicator. A cluster cannot contain a mixture of controls and indicators.
Although cluster and array elements are both ordered, you must unbundle all cluster elements at once
rather than index one element at a time. You also can use the Unbundle By Name function to access specic
cluster elements.
Figure 6.1
Figure 6.2: 1. Conrm Button, 2. Cancel Button, 3. Cluster Order Cursor, 4. Current Order, 5. New
Order
The white box on each element shows its current place in the cluster order. The black box shows the new
place in the order for an element. To set the order of a cluster element, type the new order number in the
Click to set to text box and click the element. The cluster order of the element changes, and the cluster
order of other elements adjusts. Save the changes by clicking the Confirm button on the toolbar. Revert to
the original order by clicking the Cancel button.
Corresponding elements, determined by the cluster order, must have compatible data types. For example,
in one cluster, element 0 is a numeric control, and element 1 is a string control. In a second cluster, element
0 is a numeric indicator, and element 1 is a string indicator. The cluster control correctly wires to the cluster
indicator.
However, if you change the cluster order of the indicator so the string is element 0, and the numeric is
element 1, the wire from the cluster control to the cluster indicator appears broken, indicating that the data
types do not match.
The Bundle and Unbundle functions automatically contain the correct number of terminals. The Bundle by
Name and Unbundle by Name functions appear with the rst element in the cluster. Use the Positioning
tool to resize the Bundle by Name and Unbundle by Name functions to show the other elements of the
cluster.
Figure 6.3
If you know the cluster order, you can use the Bundle function to change the Command value by wiring
the elements shown in Figure 6.4.
Figure 6.4
order, it references them by their owned labels. You can access only elements with owned labels. The
number of inputs does not need to match the number of elements in output cluster.
Use the Operating tool to click an input terminal and select an element from the pull-down menu. You
also can right-click the input and select the element from the Select Item shortcut menu.
In Figure 6.5, you can use the Bundle by Name function to change Command and Function.
Figure 6.5
Use the Bundle by Name function for data structures that might change during development. If you add
a new element to the cluster or modify its order, you do not need to rewire the Bundle by Name function
because the names still are valid.
Figure 6.6
Figure 6.7
a. Place a stop button, located on the ControlsButtons & Switches palette, a numeric
indicator, located on the ControlsNumeric Indicators palette, and a round LED,
located on the ControlsLEDs palette, on the front panel.
b. Place a cluster, located on the ControlsAll ControlsArray & Cluster palette,
on the front panel.
c. Place a numeric control, located on the ControlsNumeric Controls palette, two
vertical toggle switches, located on the ControlsButtons & Switches palette, and a
horizontal ll slide, located on the ControlsNumeric Controls palette, in the cluster.
d. Create the Modified Cluster by duplicating the rst cluster and relabeling it. Right-
click the shell of Modified Cluster, and select Change to Indicator from the shortcut
menu.
e. Copy Modified Cluster and relabel it to create Small Cluster. Remove the second
toggle switch and horizontal ll slide indicators. Relabel the numeric indicator to
Slide value. Resize the cluster as shown in Figure 6.7.
2. Verify the cluster order of Cluster and Small Cluster. Modified Cluster should have the
same order as Cluster.
a. Right-click the boundary of each cluster and select Reorder Controls in Cluster
from the shortcut menu.
3 This content is available online at <http://cnx.org/content/m12229/1.1/>.
Figure 6.8
Figure 6.9
Figure 6.10
Figure 6.11
Figure 6.12
Figure 6.13
• status is a Boolean value that reports True if an error occurred. Most VIs, functions, and structures
that accept Boolean data also recognize this parameter. For example, you can wire an error cluster
to the Boolean inputs of the Stop, Quit LabVIEW, or Select functions. If an error occurs, the error
cluster passes a True value to the function.
• code is a 32-bit signed integer that identies the error numerically. A non-zero error code coupled with
a status of False signals a warning rather than a fatal error.
• source is a string that identies where the error occurred.
Use the error cluster controls and indicators to create error inputs and outputs in subVIs.
Figure 6.14
When an error cluster is wired to the conditional terminal, the shortcut menu items Stop if True and
Continue if True change to Stop on Error and Continue while Error.
Plotting Data
Figure 7.1
Charts use three dierent modes to scroll data, as shown in the Figure 7.2. Right-click the chart and
select AdvancedUpdate Mode from the shortcut menu. Select Strip Chart, Scope Chart, or Sweep Chart
. The default mode is Strip Chart.
Figure 7.2
A strip chart shows running data continuously scrolling from left to right across the chart. A scope
chart shows one item of data, such as a pulse or wave, scrolling partway across the chart from left to the
right. A sweep chart is similar to an EKG display. A sweep chart works similarly to a scope except it
1 This content is available online at <http://cnx.org/content/m12233/1.2/>.
Available for free at Connexions <http://cnx.org/content/col10241/1.4>
113
114 CHAPTER 7. PLOTTING DATA
shows the older data on the right and the newer data on the left separated by a vertical line. The scope
chart and sweep chart have retracing displays similar to an oscilloscope. Because there is less overhead
in retracing a plot, the scope chart and the sweep chart display plots signicantly faster than the strip
chart.
Figure 7.3
Waveform charts can display multiple plots. Bundle multiple plots together using the Bundle function
located on the Cluster palette. In Figure 7.4, the Bundle function bundles the outputs of the three VIs
to plot on the waveform chart.
Figure 7.4
The waveform chart terminal changes to match the output of the Bundle function. To add more plots,
use the Positioning tool to resize the Bundle function.
Figure 7.5
a. Place the vertical toggle switch, located on the ControlsButtons & Switches palette,
on the front panel. Label this switch Power. You use the switch to stop the acquisition.
b. Place a waveform chart, located on the ControlsGraph Indicators palette, on the
front panel. Label the chart Temperature History. The waveform chart displays the
temperature in real time.
c. The waveform chart legend labels the plot Plot 0. Use the Labeling tool to
triple-click Plot 0 in the chart legend, and change the label to Temp.
d. The temperature sensor measures room temperature. Use the Labeling tool to double-
click 10.0 in the y-axis and type 90 to rescale the chart. Leave the x-axis in its default
state.
e. Change −10.0 in the y-axis to 70.
f. Label the y-axis Temp (Deg F) and the x-axis Time (sec).
Figure 7.6
Figure 7.7
d. Select the Scales tab and select the Time (sec) (X-axis) in the top pull-down menu.
Set the scale options as shown in Figure 7.8. Set the Multiplier to 0.50 to account for
the 500 ms Wait function.
Figure 7.8
e. In the Scales tab, select the Deg F (Y-axis) in the top pull-down menu. Set the scale
options as shown in Figure 7.9.
Figure 7.9
3. Each time you run the VI, you rst must turn on the vertical toggle switch and then click
the Run button due to the current mechanical action of the switch. Modify the mechanical
action of the vertical toggle switch so temperature is plotted on the graph each time you run
the VI, without having to rst set the toggle switch.
a. Stop the VI if it is running.
b. Use the Operating tool to click the vertical toggle switch and turn it to the ON position.
c. Right-click the switch and select Data OperationsMake Current Value Default
from the shortcut menu. This sets the ON position as the default value.
d. Right-click the switch and select Mechanical ActionLatch When Pressed from
the shortcut menu. This setting changes the control value when you click it and retains
the new value until the VI reads it once. At this point the control reverts to its default
value, even if you keep pressing the mouse button. This action is similar to a circuit
breaker and is useful for stopping While Loops or for getting the VI to perform an action
only once each time you set the control.
2. Use the Operating tool to click the vertical switch to stop the acquisition. The switch changes
to the OFF position and changes back to ON after the conditional terminal reads the value.
3. Save the VI. You will use this VI in the Temperature Running Average (Section 7.3) VI.
Figure 7.10
a. Press the <Ctrl> key while you click the Thermometer VI and drag it out-
side the While Loop to create a copy of the subVI. The Thermometer VI returns one
3 This content is available online at <http://cnx.org/content/m12235/1.2/>.
temperature measurement from the temperature sensor and initializes the left shift
registers before the loop starts.
Figure 7.11
2. Save the VI. You will use this VI later in the course.
7.3.6 Optional
Customize the waveform chart as shown in Figure 7.12. You can display a plot legend, a scale
legend, a graph palette, a digital display, and a scrollbar. By default, a waveform chart displays
the plot legend.
Figure 7.12
a. Use the Labeling tool to double-click 70.0 in the y-axis, type 75.0, and press the
<Enter> key.
b. b - Use the Labeling tool to double-click the second number from the bottom on the
y-axis, type 80.0, and press the <Enter> key. This number determines the numerical
spacing of the y-axis divisions. For example, if the number above 75.0 is 77.5, it indicates
a y-axis division of 2.5, changing the 77.5 to 80.0 reformats the y-axis to multiples of 5.0
(75.0, 80.0, 85.0, and so on).
note: The waveform chart size has a direct eect on the display of axis scales. Increase
the waveform chart size if you encounter problems while customizing the axis.
2. Right-click the waveform chart and select Visible ItemsScale Legend from the shortcut
menu to display the scale legend, as shown in Figure 7.13. You can place the scale legend
anywhere on the front panel.
Figure 7.13: 1. X-axis, 2. Y-axis, 3. Scale Labels, 4. Scale Lock Button, 5. Autoscale Button, 6.
Scale Format Button
Figure 7.14: 1. Cursor Movement Tool, 2. Zoom Button, 3. Panning Tool, 4. Zoom Pull-down Menu
Use the Zoom button on the graph palette to zoom in or out of sections of the chart or the
whole chart. Use the Panning tool to pick up the plot and move it around on the display.
Use the Cursor Movement tool to move the cursor on the graph.
6. Run the VI. While the VI runs, use the buttons in the scale legend and graph palette to
modify the waveform chart.
note: If you modify the axis labels, the display might become larger than the maximum
size that the VI can correctly present.
7. Use the Operating tool to click the Power switch and stop the VI.
8. Save and close the VI.
Figure 7.15
The graphs located on the ControlsGraph Indicators palette include the waveform graph and XY
graph. The waveform graph plots only single-valued functions, as in y = f (x), with points evenly dis-
tributed along the x-axis, such as acquired time-varying waveforms. XY graphs display any set of points,
evenly sampled or not.
Resize the plot legend to display multiple plots. Use multiple plots to save space on the front panel and
to make comparisons between plots. XY and waveform graphs automatically adapt to multiple plots.
Graph VI in the NI Example Finder for an example of single-plot XY graph data types.
Figure 7.16
Figure 7.17
Figure 7.18
Figure 7.19
7.5.6 Optional
1. Right-click the waveform graph and select Visible ItemsGraph Palette from the short-
cut menu to display the graph palette. Click the Zoom button to see the data on the graph in
more detail.
2. Right-click the graph and select Visible ItemsScale Legend from the shortcut menu
to display the scale legend.
3. Return to the block diagram. Create a multiple-plot waveform graph by building a 2D array
of the data type normally passed to a single-plot graph. Modify the block diagram as shown
in Figure 7.20.
Figure 7.20
gram. Use this function to build an array of points that represents one cycle of a sine
wave.
b. Place the Build Array function, located on the FunctionsAll
FunctionsArray palette, on the block diagram. This function creates the data
structure to plot two arrays on a waveform graph.
c. Place the pi constant, located on the FunctionsArithmetic &
ComparisonExpress NumericExpress Numeric Constants palette, on the
block diagram.
d. Wire the block diagram as shown Figure 7.20.
4. Save the VI.
5. Display the front panel and run the VI. The two waveforms plot on the same waveform graph.
6. Display the block diagram.
7. Right-click the wire to Waveform Array , select Custom ProbesControlsGraph
Indicators from the shortcut menu, and select a waveform graph to place a graph probe on
the wire.
8. Display the front panel and run the VI. The probe shows only the data array. The sine wave
is not present because you did not place the probe on the wire to which the sine wave is
bundled.
9. Close the Probe window.
10. Zoom in on a portion of the graph.
a. Click the Zoom button on the graph palette, shown in this media, to display the
Zoom pull-down menu.
b. Select Zoom by X Rectangle, as shown in Figure 7.21.
Figure 7.21
c. Click and drag a selection rectangle on the graph. When you release the mouse button,
the graph display zooms in on the selected area.
d. You also can select Zoom by Y Rectangle or Zoom by Selected Area. Experiment
with these options.
e. Select Undo Zoom from the lower left corner of the pull-down menu to undo
a zoom or click the x-axis single t button and the y-axis single t button on the scale
legend, shown in this media and this media.
11. Use the Panning tool, shown in this media, to click and drag the graph display. Click
the x-axis and y-axis single t buttons again to restore the display to its original position.
12. Use the Cursor Movement tool, shown in this media, to return the cursor to standard
mode.
13. Save and close the VI.
Figure 7.22
Figure 7.23
c. Place the Array Max & Min function, located on the FunctionsAll
FunctionsArray palette, on the block diagram. This function returns the maximum
and minimum temperature.
data. The ∆ (x) value of 0.25 is required so that the VI plots the temperature array
points every 0.25 seconds on the waveform graph.
h. Place the Build Array function, located on the FunctionsAll
FunctionsArray palette, on the block diagram. This function creates an array
of clusters from the temperature cluster and the best t cluster.
i. Complete the block diagram as shown.
2. Save the VI as Temperature Analysis.vi in the C:\Exercises\LabVIEW Basics I direc-
tory.
Figure 7.24
Figure 7.25
Figure 7.26
a. Place the Sine & Cosine function, located on the FunctionsArithmetic &
ComparisonExpress NumericExpress Trigonometric palette, on the block dia-
gram. This function builds an array of points that represents one cycle of a sine wave
and a cosine wave.
Figure 7.27
menu. In addition, because the intensity graphs and charts include color as a third dimension, a scale similar
to a color ramp control denes the range and mappings of values to colors. Figure 7.28 shows the elements
of an intensity graph.
Figure 7.28
Use the Operating or Positioning tools to right-click the marker next to the color ramp, select Marker
Color from the shortcut menu to change the color associated with a marker, and select the color you want
from the color picker that appears. To add markers to a color ramp, right-click the color ramp and select
Add Marker from the shortcut menu. To change the value of an arbitrary marker on a color ramp, use the
Operating tool to drag the marker to the value you want or use the Labeling tool to highlight the text of
the marker and enter a new value.
Figure 7.29
2. Change the Plot switch on the front panel to User Data and enter values between 0.0 and
10.0 in the User Data array control. Run the VI. Notice how the magnitude of each element
is mapped to the intensity graph.
Figure 7.30
Making Decisions in a VI
The Select function, located on the FunctionsExpress Comparison palette, selects between two
values dependent on a Boolean input. If the Boolean input s is True, this function returns the value wired
to the t input. If the Boolean input is False, this function returns the value wired to the f input.
You used the Select function in the Thermometer VI (Section 3.5) exercise to determine whether to
output a Fahrenheit value or a Celsius value, as shown in the block diagram in Figure 8.1.
Figure 8.1
If the decision to be made is more complex than a Select function can execute, a Case structure may
be required.
1 This content is available online at <http://cnx.org/content/m12244/1.2/>.
A Case structure has two or more subdiagrams, or cases. Only one subdiagram is visible at a time,
and the structure executes only one case at a time. An input value determines which subdiagram executes.
The Case structure is similar to case statements or if...then...else statements in text-based programming
languages.
The case selector identifier at the top of the Case structure contains the case selector
identier in the center and decrement and increment buttons on each side. Use the decrement and increment
buttons to scroll through the available cases.
Wire an input value, or selector, to the selector terminal to determine which case executes. You
must wire an integer, Boolean value, string, or enumerated type value to the selector terminal. You can
position the selector terminal anywhere on the left border of the Case structure. If you wire a Boolean to
the selector terminal, the structure has a True case and a False case. If you wire an integer, string, or
enumerated type value to the selector terminal, the structure can have up to 231 − 1 cases.
You can specify a default case for the Case structure. You must specify a default case to handle out-of-
range values or explicitly list every possible input value. For example, if you specied cases for 1, 2, and 3
but you get an input of 4, the Case structure executes the default case.
You can specify a default case for the Case structure. You must specify a default case to handle
out-of-range values or explicitly list every possible input value. For example, if you specied cases for 1, 2,
and 3 but you get an input of 4, the Case structure executes the default case.
Right-click the Case structure border to add, duplicate, remove, or rearrange cases and to select a default
case.
Figure 8.2
To select a case, type the value in the case selector identier or use the Labeling tool to edit the values,
as shown in the block diagram in Figure 8.3.
2 This content is available online at <http://cnx.org/content/m12245/1.2/>.
Figure 8.3
Once you have selected another case, that case appears foremost, as shown in the block diagram in
Figure 8.4.
Figure 8.4
If you enter a selector value that is not the same type as the object wired to the selector terminal, the
value appears red to indicate that you must delete or edit the value before the structure can execute, and
the VI will not run. Also, because of the possible round-o error inherent in oating-point arithmetic, you
cannot use oating-point numeric values as case selector values. If you wire a oating-point value to the
case, LabVIEW rounds the value to the nearest even integer. If you type a oating-point value in the case
selector, the value appears red to indicate that you must delete or edit the value before the structure can
execute.
8.2.3 Examples
In the following examples, the numeric values pass through tunnels to the Case structure and are either
added or subtracted, depending on the value wired to the selector terminal.
Example 8.1: Boolean Case Structure
The example in Figure 8.5 is a Boolean Case structure. The cases are shown overlapped to simplify
the illustration.
Figure 8.5
If the Boolean control wired to the selector terminal is True, the VI adds the numeric values.
Otherwise, the VI subtracts the numeric values.
Example 8.2: Integer Case Structure
The example in Figure 8.6 is an integer Case structure.
Figure 8.6
Integer is a text ring control located on the ControlsText Controls palette that associates
numeric values with text items. If the text ring control wired to the selector terminal is 0 (add),
the VI adds the numeric values. If the value is 1 (subtract), the VI subtracts the numeric values.
If the text ring control is any other value than 0 (add) or 1 (subtract), the VI adds the numeric
values, because that is the default case.
Example 8.3: String Case Structure
The example in Figure 8.7 is a string Case structure.
Figure 8.7
If String is add, the VI adds the numeric values. If String is subtract, the VI subtracts the
numeric values.
Example 8.4: Enumerated Case Structure
The example in Figure 8.8 is an enumerated Case structure.
Figure 8.8
An enumerated control gives users a list of items from which to select. The data type of
an enumerated control includes information about the numeric values and string labels in the
control. When you wire an enumerated control to the selector terminal of a Case structure, the
case selector displays a case for each item in the enumerated control. The Case structure executes
the appropriate case subdiagram based on the current item in the enumerated control. In the block
diagram (Figure 8.8), if Enum is add, the VI adds the numeric values. If Enum is subtract, the VI
subtracts the numeric values.
Example 8.5: Error Case Structure
The example in Figure 8.9 is an error cluster Case structure.
Figure 8.9
When you wire an error cluster to the selector terminal of a Case structure, the case selector label
displays two cases, Error and No Error, and the border of the Case structure changes colorred
for Error and green for No Error. The Case structure executes the appropriate case subdiagram
based on the error state.
When an error cluster is wired to the selection terminal, the Case structure recognizes only
the status Boolean of the cluster.
Figure 8.10
Figure 8.11
d. Place the One Button Dialog function, located on the Functions All
FunctionsTime & Dialog palette, on the block diagram. This function displays a
dialog box that contains the message Error...Negative Number.
2. Select the True case of the Case structure. Place the Square Root function, located
on the FunctionsArithmetic & ComparisonExpress Numeric palette, on the block di-
agram. This function returns the square root of Number. Wire the function as shown in
Figure 8.12.
Figure 8.12
Figure 8.13
Figure 8.14
Figure 8.15
a. Right-click the tunnel that connects to the Warning Indicator and select
CreateConstant. Use the Operating tool to change the Boolean constant to False.
b. Right-click the tunnel that connects to the High Value indicator and select
CreateConstant. Enter -99999 for the value of the constant.
3. Save the VI. You will use this VI later in the course.
Figure 8.16
The Formula Node can perform many dierent operations. Refer to the LabVIEW Help for more infor-
mation about functions, operations, and syntax for the Formula Node.
note: The Formula Express VI located on the FunctionsArithmetic & Comparison palette
uses a calculator interface to create mathematical formulas. You can use this Express VI to perform
most math functions that a basic scientic calculator can compute. Refer to the LabVIEW Help
for more information about the Formula Express VI.
Figure 8.17
Figure 8.18
a = tanh(x) + cos(x);
y = a**3 + a;
y2 = mx + b
Use only one Formula Node for both equations and use a semicolon (;) after each equation in
the node.
Save the VI as Equations.vi in the C:\Exercises\LabVIEW Basics I directory.
Exercise 8.8.2
Build a VI that functions like a calculator. On the front panel, use numeric controls to input two
numbers and a numeric indicator to display the result of the operation (Add, Subtract, Divide, or
Multiply) that the VI performs on the two numbers. Use a slide control to specify the operation
to perform.
Save the VI as Calculator.vi in the C:\Exercises\LabVIEW Basics I directory.
Exercise 8.8.3
Modify the Square Root VI (Section 8.3) so the VI performs all calculations and condition checking
using the Formula Node.
Select FileSave As to save the VI as Square Root 2.vi in the C:\Exercises\LabVIEW
Basics I directory.
Exercise 8.8.4
Build a VI that has two inputs, Threshold and Input Array, and one output, Output Array.
Output Array contains values from Input Array that are greater than Threshold.
Save the VI as Array Over Threshold.vi in the C:\Exercises\LabVIEW Basics I directory.
Create another VI that generates an array of random numbers between 0 and 1 and uses the
Array Over Threshold VI to output an array with the values greater than 0.5.
7 This content is available online at <http://cnx.org/content/m12250/1.1/>.
8 This content is available online at <http://cnx.org/content/m12251/1.2/>.
9.1 Strings1
A string is a sequence of displayable or non-displayable ASCII characters. Strings provide a platform-
independent format for information and data. Some of the more common applications of strings include the
following:
• Creating simple text messages.
• Passing numeric data as character strings to instruments and then converting the strings to numeric
values.
• Storing numeric data to disk. To store numeric values in an ASCII le, you must rst convert numeric
values to strings before writing the numeric values to a disk le.
• Instructing or prompting the user with dialog boxes.
On the front panel, strings appear as tables, text entry boxes, and labels.
Table 9.1
9.1.2 Tables
Use the table control located on the ControlsAll ControlsList & Table palette or the Express
Table VI located on the ControlsText Indicators palette to create a table on the front panel. Each
cell in a table is a string, and each cell resides in a column and a row. Therefore, a table is a display for a
2D array of strings. The illustration in Figure 9.1 shows a table and all its parts.
Figure 9.1: 1. Cell Indicated by Index Values, 2. Column Headings, 3. Vertical Scrollbar, 4. Horizontal
Scrollbar, 5. Row Headings, 6. Horizontal Index, 7. Vertical Index
Dene cells in the table by using the Operating tool or the Labeling tool to select a cell and typing text
in the selected cell.
The table displays a 2D array of strings, so you must convert 2D numeric arrays to 2D string arrays before
you can display them in a table indicator. The row and column headers are not automatically displayed as
in a spreadsheet. You must create 1D string arrays for the row and column headers.
Concatenate Strings - Concatenates input strings and 1D arrays of strings into a single output
string. For array inputs, this function concatenates each element of the array. Add inputs to
the function by right-clicking an input and selecting Add Input from the shortcut menu or by
resizing the function. For example, concatenate the previous string with the following array of
strings:
Table 9.2
String Subset - Returns the substring of the input string beginning at oset and containing
length number of characters. The oset of the rst character in string is 0. For example,
if you use the previous string as the input, the String Subset function returns the following
substring for an oset of 4 and a length of 5:
quick
Match Pattern - Searches for regular expression in string beginning at oset, and if it nds a
match, splits string into three substrings. If no match is found, match substring is empty and
oset past match is −1. For example, use a regular expression of : and use the following
string as the input:
The Match Pattern function returns a before substring of VOLTS DC, a match substring of
:, an after substring of +1.22863E+1;, and an oset past match of 9.
9.2.1 Converting Numeric Values to Strings with the Build Text Express VI
Use the Build Text Express VI to convert numeric values into strings. The Build Text Express VI, located
on the FunctionsOutput palette, concatenates an input string. If the input is not a string, this Express
VI converts the input into a string based on the conguration of the Express VI.
When you place the Build Text Express VI on the block diagram, the Congure Build Text (Figure 9.2)
dialog box appears. The dialog box (Figure 9.2) shows the Express VI congured to accept one input,
voltage, and change it to a fractional number with a precision of 4. The input concatenates on the end of
the string Voltage is. A space has been added to the end of the Voltage is string.
Figure 9.2
This conguration produces the block diagram shown in Figure 9.3. A probe has been added to view
the value of the output string. The Build Text Express VI concatenates the Beginning Text input, in this
case the voltage value, at the end of the congured text.
Figure 9.3
9.2.2 Converting Strings to Numeric Values with the Scan From String Function
The Scan From String function converts a string containing valid numeric characters, such as 0-9, +, -,
e, E, and period (.), to a numeric value. This function scans the input string and converts the string
according to format string. Use this function when you know the exact format of the input text. This
function can scan input string into various data types, such as numeric or Boolean, based on the format
string. Resize the function to increase the number of outputs.
Example 9.1
For example, use a format string of %f, an initial search location of 8, and VOLTS DC+1.28E+2
as the input string, to produce an output of 128, as shown in the block diagram shown in
Figure 9.4. Change the precision of the output by changing the precision of the indicator.
Figure 9.4
In format string, % begins the format specier and f indicates a oating-point numeric with
fractional format. Right-click the function and select Edit Scan String from the shortcut menu to
create or edit a format string. The Edit Scan String (Figure 9.5) dialog box shows a conguration
for the format string %4f.
Figure 9.5
Refer to the LabVIEW Help for more information about format specier syntax.
Figure 9.6
Figure 9.7
a. Place the Build Text Express VI, located on the FunctionsOutput palette,
on the block diagram. This function converts Number to a string. The Build Text
conguration dialog box appears.
Figure 9.8
searches String 2 for a colon, converts the string following the colon to Number Out, and
displays the index of the rst character after the colon in Offset Past Match.
2. Save and close the VI.
Refer to the Data Acquisition and Waveforms (Section 10.1) section, for more information on using the
File I/O Express VIs.
Read Characters From File - Reads a specied number of characters from a byte stream le be-
ginning at start of read oset. The VI opens the le before reading from it and closes it
afterwards.
Read Lines From File - Reads a specied number of lines from a text or binary le beginning at
a specied character oset. The VI opens the le before reading from it and closes it afterwards.
Binary File VIs - These VIs read from and write to binary les. Data can be integers or single-
precision numbers.
Figure 9.9
Figure 9.10
Figure 9.11
Figure 9.12
Figure 9.13
9.6.4 Optional
Open the wave.txt le using a word processor or spreadsheet application and view its contents.
1. Open a word processor or spreadsheet application, such as (Windows) Notepad or WordPad,
(Mac OS) SimpleText, or (UNIX) Text Editor.
2. Open wave.txt. The sine waveform data appear in the rst column, the random waveform
data appear in the second column, and the cosine waveform data appear in the third column.
3. Exit the word processor or spreadsheet application and return to LabVIEW.
Open/Create/Replace File - Opens an existing le, creates a new le, or replaces an existing
le, programmatically or interactively using a le dialog box. You can optionally specify a dialog
prompt, default le name, start path, or lter pattern. If le path is empty, the VI displays a
dialog box from which you can select a le.
Read File - Reads data from an open le specied by refnum and returns it in data. Reading
begins at the current le mark or a location specied by pos mode and pos oset. How the data
is read depends on the format of the specied le.
Write File - Writes data to an open le specied by refnum. Writing begins at a location
specied by pos mode and pos oset for byte stream les and at the end of the le for datalog
les. data, header, and the format of the specied le determine the amount of data written.
Close File - Closes an open le specied by refnum and returns the path to the le associated
with the refnum. Error I/O operates uniquely in this function, which closes regardless of whether
an error occurred in a preceding operation. This ensures that les are closed correctly.
The low-level File I/O VIs and functions return error information. Wire the error information from the
beginning of the VI to the end. Include an error handler VI, such as the Simple Error Handler (p. 169) VI
located on the Time & Dialog palette, at the end of the VI to determine if the VI ran without errors. Use
the error in and error out clusters in each VI you use or build to pass the error information through the VI.
7 This content is available online at <http://cnx.org/content/m12258/1.1/>.
Available for free at Connexions <http://cnx.org/content/col10241/1.4>
170 CHAPTER 9. STRINGS AND FILE I/O
Platform Pathname
Windows Consists of the drive name, a colon, backslash-
separated directory names, and the lename. For
example, c:\testdata\test1.dat is the pathname
to a le named test1.dat in the testdata direc-
tory.
UNIX UNIX Consists of forward slash-separated direc-
tory names and the lename. For example,
/home/testdata/test1.dat is the pathname to a
le named test1.dat in the testdata directory in
the /home directory. Filenames and pathnames are
case sensitive.
Mac OS Consists of the volume name (the name of
the disk), a colon, colon-separated folder
names, and the lename. For example, Hard
Disk:testdata:test1.dat is the pathname to a
le named test1.dat in a folder named testdata
on a disk named Hard Disk.
Table 9.3
The block diagram shown in Figure 9.14 shows how to write string data to a le while programmatically
wiring the lename and pathname. If the le already exists, it is replaced; otherwise a new le is created.
Figure 9.14
The Open/Create/Replace File VI opens the le test1.dat. The VI also generates a refnum and an
error cluster.
When you open a le, device, or network connection, LabVIEW creates a refnum associated with that
le, device, or network connection. All operations you perform on open les, devices, or network connections
use refnums to identify each object.
The error cluster and refnum pass in sequence from one node to the next. Because a node cannot execute
until it receives all its inputs, passing these two parameters forces the nodes to run in order and creates a
data dependency. The Open/Create/Replace File VI passes the refnum and error cluster to the Write
File function, which writes the data to disk. When the Write File function nishes execution, it passes
the refnum and error cluster to the Close File function, which closes the le. The Simple Error Handler
VI examines the error cluster and displays a dialog box if an error occurred. If an error occurs in one node,
subsequent nodes do not execute, and the VI passes the error cluster to the Simple Error Handler VI.
Figure 9.15
a. Place a path indicator located on the ControlsText Indicators palette on the front
panel. This indicator displays the path for the data le you create.
b. Right-click the String to Write control and select Visible ItemsScrollbar from
the shortcut menu to display a scrollbar.
Figure 9.16
a. Place the Create String VI from the previous exercise on the block
diagram. Select FunctionsAll FunctionsSelect a VI and navigate to
C:\Exercises\LabVIEW Basics I\Create String.vi. This subVI concatenates the
three input strings to one combined string.
2. Type demofile.txt and click the Save or OK button to save the le. The VI writes the
String to Write, Numeric to Write, and Unit to Write values to the le.
3. Close the VI.
Figure 9.17
Figure 9.18
9.9.4 Challenge
1. Modify the VI so it parses the numeric value and displays the numeric value in a numeric
indicator. After you nish, save and close the VI.
tip: Use the Match Pattern function to search for the rst numeric character.
note: Use the end of line constant located on the FunctionsAll FunctionsString palette
to ensure portability of VIs among platforms. (Windows) The constant inserts a carriage return
and a linefeed. (Mac OS) The constant inserts a carriage return. (UNIX) The constant inserts a
linefeed.
Use the Write To Spreadsheet File VI or the Array To Spreadsheet String function to convert a set
of numbers from a graph, a chart, or an acquisition into a spreadsheet string. If you want to write numbers
and text to a spreadsheet or word processing application, use the String functions and the Array functions
to format the data and to combine the strings. Then write the data to a le.
Figure 9.19
This VI creates this text le, where an arrow (→) indicates a tab, and a paragraph symbol (¶) indicates
an end of line character.
0→ 0.798141¶
1→ 0.659364¶
2→ 0.581409¶
3→ 0.526433¶
4→ 0.171062¶
You can open the previous text le in a spreadsheet application to display the spreadsheet shown in
Figure 9.20.
Figure 9.20
Figure 9.21
The dialog box in Figure 9.22 shows the conguration for the Write LabVIEW Measurement File Express
VI.
Figure 9.22
This VI creates a .lvm le which you can open in a spreadsheet application. Figure 9.23 shows an
example of the spreadsheet created by the previous conguration of the Write LabVIEW Measurement File
Express VI.
Figure 9.23
Refer to the lesson on Data Acquisition and Waveforms (Section 9.7), for more information about the
Write LabVIEW Measurement File and Read LabVIEW Measurement File Express VIs.
Figure 9.24
constant with the Operating tool to change the constant from False to True. The True
Boolean constant sets the function to include seconds in the string.
c. Place the Build Text Express VI, located on the FunctionsOutput palette, on
the block diagram. This Express VI converts the inputs to one string. The Configure
Build Text dialog box appears.
1. Type %tab%%temp%%end% in the Text with Variables in Percents text box to
set up three variables; one for the tab constant, one for the temperature and one for
the end of line constant. Because time uses the Beginning Text input of the Build
Text Express VI, it does not need a variable.
2. Select temp in the Configure Variables section. Select the Number option, and a
format of Format fractional number. The tab and end variables do not need to
be formatted. You can leave them in the default state.
3. Click the OK button to close the conguration dialog box.
4. Right-click the Build Text Express VI and select View As Icon to conserve block
diagram space.
d. Place a Tab constant and an End of Line constant, located on the
FunctionsAll FunctionsString palette, on the block diagram.
9.11.3 Optional
When using error handling in a VI, the While Loop should stop executing when an error occurs.
Complete the following steps to modify the VI so it stops when the user clicks the Power switch or
an error occurs.
1. Edit the block diagram as shown in Figure 9.25.
Figure 9.25
9.11.4 Challenge
1. Replace the Build Text Express VI and the Write File function with the Format Into
File function.
2. Run the VI.
3. Close the VI. Do not save changes.
Figure 9.26
e. After you stop the acquisition, plots both the raw temperature data and a best-t curve
in an XY graph and displays the average, maximum, and minimum temperatures.
tip: Start with the Temperature Logger VI (Section 9.11). To complete this step (list,
item 5, p. 182), use portions of the Temperature Analysis VI (Section 7.6).
tip: The Build Text Express VI is limited to eight inputs. Use multiple Build Text
Express VIs or use the Format into String function. You can build the delimiters into
the format string to require fewer inputs.
The front panel should be similar to Figure 9.27.
12 This content is available online at <http://cnx.org/content/m12263/1.2/>.
Figure 9.27
tip: Delete the Format Into File function and replace it with the Format Into String and
Write File functions. Use the pos mode and pos offset parameters of the Write File function
to move the current le mark.
Select FileSave As to save the VI as Temperature Logger 2.vi in the C:\Exercises\LabVIEW
Basics I directory.
10.1.1.1 NI-DAQ
NI-DAQ 7.0 contains two NI-DAQ driversTraditional NI-DAQ and NI-DAQmxeach with its own applica-
tion programming interface (API), hardware conguration, and software conguration.
• Traditional NI-DAQ is an upgrade to NI-DAQ 6.9.x, the earlier version of NI-DAQ. Traditional NI-DAQ
has the same VIs and functions and works the same way as NI-DAQ 6.9.x. You can use Traditional
NI-DAQ on the same computer as NI-DAQmx, which you cannot do with NI-DAQ 6.9.x.
• NI-DAQmx is the latest NI-DAQ driver with new VIs, functions, and development tools for controlling
measurement devices. The advantages of NI-DAQmx over previous versions of NI-DAQ include the
DAQ Assistant for conguring channels and measurement tasks for a device; increased performance,
including faster single-point analog I/O and multithreading; and a simpler API for creating DAQ
applications using fewer functions and VIs than earlier versions of NI-DAQ.
Traditional NI-DAQ and NI-DAQmx support dierent sets of devices. Refer to the National Instruments
Web site3 for the list of supported devices. This lesson describes the NI-DAQmx API.
Figure 10.1 shows the measurement software framework.
Figure 10.1
When programming an NI measurement device, you can use NI application software such as LabVIEW,
LabWindows/CVI, and Measurement Studio, or open ADEs that support calling dynamic link libraries
(DLLs) through ANSI C interfaces. Using NI application software greatly reduces development time for data
acquisition and control applications regardless of which programming environment you use:
• LabVIEW supports data acquisition with the LabVIEW DAQ VIs, a series of VIs for programming
with NI measurement devices.
• For C developers, LabWindows/CVI is a fully integrated ANSI C environment that provides the
LabWindows/CVI Data Acquisition library for programming NI measurement devices.
3 http://ni.com/daq
Available for free at Connexions <http://cnx.org/content/col10241/1.4>
189
• Measurement Studio development tools are for designing your test and measurement software in Mi-
crosoft Visual Studio .NET. Measurement Studio includes tools for Visual C#, Visual Basic .NET,
and Visual C++ .NET.
10.1.2.1 Windows
The Windows Conguration Manager keeps track of all the hardware installed in the computer, including
National Instruments DAQ devices. If you have a Plug & Play (PnP) device, such as an E Series MIO
device, the Windows Conguration Manager automatically detects and congures the device. If you have
a non-PnP device, or legacy device, you must congure the device manually using the Add New Hardware
option in the Control Panel.
You can verify the Windows Conguration by accessing the Device Manager. You can see Data
Acquisition Devices, which lists all DAQ devices installed in the computer. Double-click a DAQ de-
vice to display a dialog box with tabbed pages. The General tab displays overall information regarding the
device. The Resources tab species the system resources to the device such as interrupt levels, DMA, and
base address for software-congurable devices. The NI-DAQ Information tab species the bus type of the
DAQ device. The Driver tab species the driver version and location for the DAQ device.
LabVIEW installs Measurement & Automation Explorer (MAX), which establishes all device and channel
conguration parameters. After installing a DAQ device in the computer, you must run this conguration
utility. MAX reads the information the Device Manager records in the Windows Registry and assigns a logical
device number to each DAQ device. Use the device number to refer to the device in LabVIEW. Access MAX
either by double-clicking the icon on the desktop or selecting ToolsMeasurement & Automation Explorer
in LabVIEW. The window in Figure 10.2 is the primary MAX window. MAX is also the means for SCXI
and SCC conguration.
Figure 10.2
MAX detects all the National Instruments hardware including the GPIB interface. Refer to Instrument
Control (Section 11.2), for more information about GPIB.
The device parameters that you can set using the conguration utility depend on the device. MAX saves
the logical device number and the conguration parameters in the Windows Registry.
The plug and play capability of Windows automatically detects and congures switchless DAQ devices,
such as the PCI-6024E. When you install a device in the computer, the device is automatically detected.
Figure 10.3
MAX displays the National Instruments hardware and software in the computer. The device
number appears in quotes following the device name. The Data Acquisition VIs use this
device number to determine which device performs DAQ operations. MAX also displays the
attributes of the device such as the system resources that are being used by the device.
note: You might have a dierent device installed, and some of the options shown might be
dierent. Click the Show Help/Hide Help button in the top right corner of MAX to hide the
online help and show the DAQ device information.
3. The Device Routes (Figure 10.4) tab provides detailed information about the internal signals
that can be routed to other destinations on the device. This is a powerful resource that
gives you a visual representation of the signals that are available to provide timing and
synchronization with components that are on the device and other external devices.
4 This content is available online at <http://cnx.org/content/m12267/1.1/>.
Figure 10.4
4. The Calibration (Figure 10.5) tab provides information about the last time the device was
calibrated both internally and externally.
Figure 10.5
5. Right-click the NI-DAQmx device in the conguration tree and select Self Calibrate to
calibrate the DAQ device using a precision voltage reference source and update the built-in
calibration constants. When the device has been calibrated, the Self Calibration informa-
tion updates in the Calibration tab.
e. Click the Digital I/O tab to test the digital lines on the DAQ device. Set lines 0
through 3 as output and toggle the Logic Level checkboxes. As you toggle the boxes,
the LEDs on the DAQ signal accessory turn on or o. The LEDs use negative logic.
f. Click the Counter I/O tab to determine if the DAQ device counter/timers are function-
ing properly. To verify counter/timer operation, change the Counter Mode tab to Edge
Counting and click the Start button. The Counter Value increments rapidly. Click
Stop to stop the counter test.
g. Click the Close button to close the Test Panel and return to MAX.
3. Close MAX by selecting FileExit.
The DAQ Assistant Express VI allows you to easily congure the data acquisition device. When
you place the DAQ Assistant Express VI on the block diagram, a dialog box (Figure 10.6) appears where
you congure a local task to perform a specic measurement function. Creating a local task allows you to
specify the exact type of measurement to take.
Figure 10.6
After you create a task, the information for the local task is stored in the DAQ Assistant Express VI.
You can recongure the DAQ Assistant Express VI by double-clicking the VI and creating a new task.
5 This content is available online at <http://cnx.org/content/m12268/1.1/>.
Figure 10.7
Each measurement type has its own characteristics, such as resistor values for current measurements or
strain gauge parameters for strain measurements.
channel on the measurement device and initiate a single-channel, single-point acquisition when you want to
know the uid level.
Figure 10.8
a. Place the Meter, located on the ControlsNumeric Indicators palette, on the front
panel. Congure the meter scale for 0.0 to 0.4. Use the Labeling tool to double-click
10.0 and type 0.4. You might need to enlarge the meter to display the scale as shown
in the example (Figure 10.8).
b. Place a Vertical Toggle Switch, located on the ControlsButtons & Switches
palette, on the front panel. Congure the toggle switch to a default value of False
and a mechanical action of Latch When Pressed.
c. Create two free labels, Off and On, using the Labeling tool.
Figure 10.9
10.5.3 Scales
The temperature sensor on the DAQ Signal Accessory outputs the voltage in degrees Celsius, scaled
by 100. In order to convert the voltage into degrees Celsius, it is necessary to multiply the voltage
by 100. You could multiply the output of the DAQ Assistant Express VI by 100, or congure the
DAQ Assistant Express VI to automatically scale the voltage. Using the capabilities that exist
within the VI reduces block diagram clutter.
1. Double-click the DAQ Assistant to display the Analog Input Voltage Task
Configuration dialog box.
2. Select Create New in the Custom Scaling pull-down menu.
3. Select Linear and name the scale temperature. Click the Finish button.
4. A dialog box appears where you can scale the data by a multiplier and an oset.
a. Set the slope to 100 and the Scaled Units to Celsius.
b. Click the OK button to close the dialog box.
5. In the Analog Input Voltage Task Configuration dialog box, set the minimum input
range to 0, set the maximum input range to 100, and click the OK button to return to
the block diagram.
6. Run the VI. The temperature displays in the meter. The temperature values are 100 times
greater than the voltage values. Change the meter scale to see the correct values.
7. Stop the VI. Save the VI but do not close it. You will use the VI in the Measurement Averaging
VI (Section 10.6) exercise.
Figure 10.10
LabVIEW includes the ability to create a LabVIEW measurement le, an ASCII text le that can be
read by a spreadsheet, or a text editor. The LabVIEW measurement le is easy to create in LabVIEW, and
easy to read in LabVIEW or other applications.
The Write LabVIEW Measurement File Express VI located on the FunctionsOutput palette writes
signals to a LabVIEW measurement le. When you place this Express VI on the block diagram, a congu-
ration dialog box appears where you can specify how to store the le.
The Read LabVIEW Measurement File Express VI located on the FunctionsInput palette reads sig-
nals in a LabVIEW measurement le. This Express VI reads data one point at a time, so it is necessary to
place this Express VI in a loop.
Figure 10.11
Place the Write LabVIEW Measurement File Express VI, located on the
FunctionsOutput palette, on the block diagram. This Express VI stores the data ac-
quired from the DAQ device. In the Configure Write LabVIEW Measurement File dialog
box that appears, set the following options:
a. Set the Action to Ask user to choose file for the lename.
b. Set the Segment Headers to One header only to provide a header for all of the data.
The header contains information about the sampling rate and the time when the sample
was taken.
10 This content is available online at <http://cnx.org/content/m12273/1.1/>.
c. Set X Value Columns to One column per channel to provide a table of data that can
be read by any spreadsheet editor or an ASCII text le editor.
d. Set the Delimiter to Tab to make it easy for a spreadsheet editor to determine where a
column of data starts in the le.
e. Click the OK button to close the dialog box.
Place the Merge Errors VI, located on the FunctionsAll FunctionsTime &
Dialog palette, on the block diagram. It is important to catch errors with both DAQ and le
I/O, and because the code has a parallel structure it is necessary to merge the errors from all
of the parallel operations to determine if the code is functioning properly.
3. Select FileSave As to save the VI as Simple Data Logger.vi in the
C:\Exercises\LabVIEW Basics I directory.
4. Run the VI. A lename prompt appears. Name the le logger.lvm in the
C:\Exercises\LabVIEW Basics I directory.
5. Stop and close the VI.
Figure 10.12
Figure 10.13
a. Place the Read LabVIEW Measurement File Express VI, located on the
FunctionsInput palette, on the block diagram. Because this Express VI reads data
located in a LabVIEW measurement le one data point at a time, it must be placed in
a loop. In the Configure Read LabVIEW Measurement File dialog box that appears,
set the following options:
• In the Action section, place a checkmark in the Ask user to choose file check-
box.
• Set the Segment Size to Retrieve segments of original size so that all the
data stored in the le is retrieved.
• Set Time Stamps to Relative to start of measurement. Because the dynamic
data type stores information about the signal timing, this setting aligns the data
with the time of the measurement.
• In the Generic Text File section, remove the checkmark from the Read generic
text files checkbox because the data is stored in a LabVIEW measurement le.
• Click the OK button to close the dialog box.
b. Place the Unbundle by Name function, located on the FunctionsAll
FunctionsCluster palette, on the block diagram.
c. Place the Or function, located on the FunctionsArithmetic &
ComparisonExpress Boolean palette, on the block diagram.
d. Wire the EOF? output of the Read LabVIEW Measurement File function to the Or func-
tion. Wire the status output of the error cluster to the second input of the Or function.
This stops the While Loop when the entire LabVIEW Measurement File has been read
or when an error occurs.
2. Save the VI as Simple Data Reader.vi in the C:\Exercises\LabVIEW Basics I directory.
3. Display the front panel, and run the VI. In the lename prompt that appears, select the
logger.lvm le that you created earlier (list, item 4, p. 202).
4. The data that was stored in the LabVIEW Measurement File appears in the waveform chart.
note: You might need to rescale or autoscale the y-axis of the waveform chart to display
the data.
5. Close the Simple Data Reader VI.
Figure 10.14
To perform a voltage or current task, a compatible device must be installed that can generate that form
of signal.
Figure 10.15
Figure 10.16
Figure 10.17
Place the DAQ Assistant Express VI, located on the FunctionsOutput palette,
in the For Loop. Complete the following steps to congure this Express VI to generate an
analog output voltage.
a. Select Analog OutputVoltage for the measurement to make.
b. Select Dev1ao0 for the physical channel and click the Finish button.
c. In the Analog Output Voltage Task Configuration dialog box that appears, cong-
ure the Task Timing to Generate 1 Sample. Change the output range minimum to 0
and maximum to 10.
d. Click the OK button to close the Analog Output Voltage Task Configuration dialog
box. This saves the settings specied for the task in the DAQ Assistant Express VI.
3. Save the VI.
4. Close the block diagram but leave the front panel open.
7. To acquire and display the voltage output, run the Voltage Output VI. The Voltage Output
(Figure 10.18) VI outputs the voltage in 0.5 V increments from 0 to 9.5 V. When the For
Loop executes its last iteration, the VI outputs 0 V to reset the analog output channel.
Figure 10.18
10.11 Counters13
A counter is a digital timing device. You typically use counters for event counting, frequency measurement,
period measurement, position measurement, and pulse generation.
A counter contains the following four main components:
Count Register - Stores the current count of the counter. You can query the count register with
software.
Source - An input signal that can change the current count stored in the count register. The counter
looks for rising or falling edges on the source signal. Whether a rising or falling edge changes
the count is software selectable. The type of edge selected is referred to as the active edge of the
signal. When an active edge is received on the source signal, the count changes. Whether an
active edge increments or decrements the current count is also software selectable.
Gate - An input signal that determines if an active edge on the source will change the count. Counting
can occur when the gate is high, low, or between various combinations of rising and falling edges.
Gate settings are made in software.
Output - An output signal that generates pulses or a series of pulses, otherwise known as a pulse
train.
When you congure a counter for simple event counting, the counter increments when an active edge is
received on the source. In order for the counter to increment on an active edge, the counter must be armed
or started. A counter has a xed number it can count to as determined by the resolution of the counter. For
example, a 24-bit counter can count to:
2Counter Resolution − 1 = 242 − 1 = 16, 777, 215
When a 24-bit counter reaches the value of 16, 777, 215, it has reached the terminal count. The next
active edge will force the counter to roll over and start at 0.
13 This content is available online at <http://cnx.org/content/m12276/1.1/>.
Available for free at Connexions <http://cnx.org/content/col10241/1.4>
209
Figure 10.19
Figure 10.20
Place the DAQ Assistant Express VI, located on the FunctionsInput palette, in a
While Loop. Complete the following steps to congure the counter to perform event counting.
d. Click the OK button to close the Counter Input Edge Count Task Configuration dia-
log box. This saves all the settings specied for the task in the DAQ Assistant Express
VI.
2. Save the VI as Simple Event Counting.vi in the C:\Exercises\LabVIEW Basics I direc-
tory.
3. On the DAQ Signal Accessory, wire the A output of the quadrature encoder to the SOURCE
input of counter 0.
4. Run the VI. Rotate the quadrature encoder knob on the DAQ Signal Accessory. Notice that
the Number of Events indicator increments as you rotate the knob. The quadrature encoder
knob produces pulses as you rotate the knob. The counter counts these pulses.
5. Stop the VI.
6. Double-click the DAQ Assistant Express VI, and change the Count Direction pull-down
menu to Externally Controlled. Click the OK button to close the conguration dialog
box. The DAQ Signal Accessory internally connects phase B of the quadrature encoder to
the Up/Down line for counter 0. This can be used to determine the direction the knob has
turned.
7. Run the VI. Rotate the quadrature encoder knob on the DAQ Signal Accessory. Notice
that the Number of Events indicator decrements when you rotate the knob clockwise, and
increments when you rotate the knob counterclockwise.
8. Save and close the VI.
1. Open the Digital Example VI, located in the C:\Exercises\LabVIEW Basics I directory,
and modify the block diagram as shown in Figure 10.21.
15 This content is available online at <http://cnx.org/content/m12278/1.1/>.
16 This content is available online at <http://cnx.org/content/m12279/1.1/>.
Figure 10.21
Place the DAQ Assistant Express VI, located on the FunctionsInput palette, in
the While Loop. Complete the following steps to congure the counter to perform event
counting.
a. Select Digital I/OPort Output for the measurement to make.
b. Select Dev1port0 for the physical channel and click the Finish button.
c. In the Digital Output Port Task Configuration dialog box that appears, select
Invert All Lines In Port because the LEDs use negative logic.
d. Click the OK button to close the conguration dialog box. All of the settings specied
for the task are saved internally in the DAQ Assistant VI.
Instrument Control
11.2.3 Restrictions
To achieve the high data transfer rate that the GPIB was designed for, you must limit the number of devices
on the bus and the physical distance between devices. The following restrictions are typical:
• A maximum separation of 4 m between any two devices and an average separation of 2 m over the
entire bus
• A maximum total cable length of 20 m
• A maximum of 15 devices connected to each bus, with at least two-thirds powered on
For high-speed operation, the following restrictions apply:
• All devices in the system must be powered on
• Cable lengths must be as short as possible with up to a maximum of 15 m of cable for each system
• There must be at least one equivalent device load per meter of cable
If you want to exceed these limitations, you can use a bus extender to increase the cable length or a bus
expander to increase the number of device loads. You can order bus extenders and expanders from National
Instruments.
note: Refer to the National Instruments GPIB support Web site3 for more information about
GPIB.
Always install the newest version of these drivers unless otherwise instructed in the release notes for either
the GPIB interface or LabVIEW.
(Windows)
Use MAX to congure and test the GPIB interface. MAX interacts with the various diagnostic and
conguration tools installed with the driver and also with the Windows Registry and Device Manager. The
driver-level software is in the form of a DLL and contains all the functions that directly communicate with
the GPIB interface. The Instrument I/O VIs and functions directly call the driver software.
Figure 11.1
The Remote Systems section in the Configuration pane allows you to view and congure remote sys-
tems, such as RT Series PXI Controllers. Congure the objects listed in MAX by right-clicking each item
and selecting an option from the shortcut menu.
Figure 11.2
2. Power on the NI Instrument Simulator and verify that both the Power and Ready LEDs are lit.
3. Launch MAX by either double-clicking the icon on the desktop or by selecting ToolsMeasurement
& Automation Explorer in LabVIEW.
4. Expand the Devices and Interfaces section to display the installed interfaces. If a GPIB interface
is listed, the NI-488.2 software is correctly loaded on the computer.
5 This content is available online at <http://cnx.org/content/m12285/1.1/>.
Available for free at Connexions <http://cnx.org/content/col10241/1.4>
217
5. Select the GPIB interface and click the Properties button on the toolbar to display the Properties
dialog box.
6. Examine but do not change the settings for the GPIB interface, and click the OK button.
7. Make sure the GPIB interface is still selected in the Devices and Interfaces section and click the
Scan for Instruments button on the toolbar.
8. Expand the GPIB board section. One instrument named Instrument0 appears.
9. Click Instrument0 to display information about it in the right pane of MAX. The NI Instrument
Simulator has a GPIB primary address (PAD) of 2.
10. Click the Communicate with Instrument button on the toolbar. An interactive window appears. You
can use it to query, write to, and read from that instrument.
11. Type *IDN? in Send String and click the Query button. The instrument returns its make and model
number in String Received. You can use this window (Figure 11.3) to debug instrument problems
or to verify that specic commands work as described in the instrument documentation.
Figure 11.3
12. Type MEAS:DC? in Send String and click the Query button. The NI Instrument Simulator returns a
simulated voltage measurement.
13. Click the Query button again to return a dierent value.
14. Click the Exit button.
15. Set a VISA alias for the NI Instrument Simulator so you can use the alias instead of having to remember
the primary address.
a. While Instrument0 is selected in MAX, click the VISA Properties button to display the
Properties dialog box.
b. Type devsim in the VISA Alias eld and click the OK button. You will use this alias throughout
this lesson.
16. Select FileExit to exit MAX.
with message-based instruments and graphically parse the response. For example, you can communicate
with an instrument that uses a serial, Ethernet, or GPIB interface. Use the Instrument I/O Assistant
when an instrument driver is not available.
The Instrument I/O Assistant organizes instrument communication into ordered steps. To use
Instrument I/O Assistant, you place steps into a sequence. As you add steps to the sequence, they
appear in the Step Sequence window. Use the view associated with a step to congure instrument I/O.
To launch the Instrument I/O Assistant, place the Instrument I/O Assistant Express VI on the
block diagram. The Instrument I/O Assistant conguration dialog box appears. If it does not appear,
double-click the Instrument I/O Assistant icon. Complete the following steps (p. 218) to congure the
Instrument I/O Assistant.
1. Select an instrument. Instruments that have been congured in MAX appear in the Select an
instrument pull-down menu.
2. Choose a Code generation type. VISA code generation allows for more exibility and modularity
than GPIB code generation.
3. Select from the following communication steps using the Add Step button:
Query and Parse - Sends a query to the instrument, such as *IDN? and parses the returned
string. This step combines the Write command and Read and Parse command.
Write - Sends a command to the instrument.
Read and Parse - Reads and parses data from the instrument.
4. After adding the desired number of steps, click the Run button to test the sequence of communication
that you have congured for the Express VI.
5. Click the OK button to exit the Instrument I/O Assistant conguration dialog box.
LabVIEW adds input and output terminals to the Instrument I/O Assistant Express VI on the block
diagram that correspond to the data you will receive from the instrument.
To view the code generated by the Instrument I/O Assistant, right-click the Instrument I/O
Assistant icon and select Open Front Panel from the shortcut menu. This converts the Express VI to a
subVI. Switch to the block diagram to see the code generated.
note: Once an Express VI has been converted to a subVI, it cannot be converted back.
Figure 11.4
Figure 11.5
7. Click the OK button to exit the I/O Assistant and return to the block diagram.
b. Right-click the ID String output and select CreateIndicator from the shortcut
menu.
c. Right-click the Voltage output and select CreateIndicator from the shortcut menu.
d. Wire the Error Out output to the Simple Error Handler VI.
2. Display the front panel and run the VI. Resize the string indicator if necessary.
3. Save the VI as Read Instrument Data.vi in the C:\Exercises\LabVIEW Basics I direc-
tory.
4. Right-click the I/O Assistant and select Open Front Panel. Click the Convert button
when asked if you want to convert to a subVI.
5. View the code generated by the I/O Assistant. Where is the command *IDN? written to
the Instrument Simulator? Where is the voltage being read?
6. Select FileExit to exit the subVI. Do not save changes.
11.6 VISA8
11.6.1 Overview
In 1993, National Instruments joined with GenRad, Racal Instruments, Tektronix, and Wavetek to form the
VXIplug&play Systems Alliance. The goals of the alliance are to ensure multivendor interoperability for
VXI systems and to reduce the development time for an operational system.
A key part of these goals was to develop a new standard for instrument drivers, soft front panels, and I/O
interface software. The term VXIplug&play has come to indicate the conformity of hardware and software
to these standards.
In directing their eorts toward software standardization, VXIplug&play members identied the following
set of guiding principles:
• Maximize ease of use and performance
• Maintain long-term compatibility with the installed base
• Maintain multivendor open architectures
• Maximize multiplatform capability
• Maximize expandability and modularity in frameworks
• Maximize software reuse
• Standardize the use of system software elements
• Treat instrument drivers as part of the instrument
• Accommodate established standards
• Maximize cooperative support of users
VISA is the VXIplug&play I/O software language that is the basis for the software standardization eorts
of the VXIplug&play Systems Alliance. VISA by itself does not provide instrumentation programming
capability. It is a high-level API that calls in low-level drivers. VISA can control VXI, GPIB, serial, or
computer-based instruments and makes the appropriate driver calls depending on the type of instrument
used. When debugging VISA problems, remember this hierarchy. An apparent VISA problem could be an
installation problem with one of the drivers that VISA calls.
In LabVIEW, VISA is a single library of functions you use to communicate with GPIB, serial, VXI, and
computer-based instruments. You do not need to use separate I/O palettes to program an instrument. For
example, some instruments give you a choice for the type of interface. If the LabVIEW instrument driver
were written with functions on the FunctionsAll FunctionsInstrument I/OGPIB palette, those
8 This content is available online at <http://cnx.org/content/m12288/1.1/>.
Available for free at Connexions <http://cnx.org/content/col10241/1.4>
221
instrument driver VIs would not work for the instrument with the serial port interface. VISA solves this
problem by providing a single set of functions that work for any type of interface. Therefore, all LabVIEW
instrument drivers use VISA as the I/O language.
Interface Syntax
Asynchronous serial ASRL[board][::INSTR]
GPIB GPIB[board]::primary address[::secondary
address][::INSTR]
VXI instrument through embedded or MXIbus con- VXI[board]::VXI logical address[::INSTR]
troller
GPIB-VXI controller GPIB-VXI[board][::GPIB-VXI primary
address]::VXI logical address[::INSTR]
Table 11.1
You can use an alias you assign in MAX instead of the instrument descriptor. (Mac OS) Edit the
visaconf.ini le to assign a VISA alias. (UNIX) Use the visaconf utility.
If you choose not to use the Instrument I/O Assistant to automatically generate code for you, you
can still write a VI to communicate with the instrument. The most commonly used VISA communication
functions are the VISA Write and VISA Read functions. Most instruments require you to send information
in the form of a command or query before you can read information back from the instrument. Therefore,
the VISA Write function is usually followed by a VISA Read function.
Figure 11.6
Figure 11.7
e. Place the Simple Error Handler VI, located on the FunctionsAll FunctionsTime
& Dialog palette, on the block diagram. This VI checks error conditions and opens a dialog box
with error information if an error occurs.
2. Save the VI as My VISA Write & Read.vi in the C:\Exercises\LabVIEW Basics I directory.
3. Display the front panel. Enter devsim in the VISA resource name input and set byte count to 200
to make sure you read all the information. Type *IDN? in the write buffer and run the VI.
4. The top of the instrument simulator lists other commands that are recognized by this instrument. Try
other commands in this VI.
5. Close the VI when nished.
Figure 11.8
The high-level functions are built from the low-level functions. For the most control over the instrument,
use the low-level functions. The high-level functions are easy to use and have soft front panels that resemble
the instrument. Instrument drivers have VIs in the following categories:
Initialize - Initializes the communication channel to the instrument. This VI also can perform an
identication query and reset operation, and it can perform any necessary actions to place the
instrument in its default power-on state or other specied state.
Conguration - Congures the instrument to perform operations, such as setting up the trigger
rate.
Action/Status - Contains two types of VIs. Action VIs cause the instrument to initiate or terminate
test and measurement operations. Status VIs obtain the current status of the instrument or the
status of pending operations. An example of an action VI is Acquire Single Shot. An example
of a status VI is Query Transfer Pending.
Data - Transfers data to or from the instrument, such as reading a measured waveform from the
instrument or downloading a waveform to the instrument.
Utility - Performs a wide variety of functions, such as reset, self-test, error query, and revision query.
Close - Terminates the communication channel to the instrument and deallocates the resources for
that instrument.
All National Instruments instrument drivers are required to implement the following functions:
initialize, close, reset, self-test, revision query, error query, and error message.
Optional parameters are shown in square brackets [ ]. For example, GPIB::2::INSTR is the instrument
descriptor for a GPIB instrument at address 2.
The VISA resource name control located on the ControlsAll ControlsI/O palette is similar to the
DAQ channel name control, but it is specically used for instrument control. Refer to the VISA (Section 11.6)
section for more information about VISA.
You can use MAX to determine what resources and instrument addresses are available, as you did
in GPIB Conguration with MAX (Section 11.3) when you assigned a VISA alias of devsim to the NI
Instrument Simulator. The alias makes it easier to communicate with instruments because you no longer
need to memorize which interface and address each instrument uses. You can use the alias in the VISA
resource name control instead of the instrument descriptor. For example, you can type devsim instead of
GPIB::2::INSTR.
Figure 11.9
Figure 11.10
Use the following guidelines to help you construct the front panel.
• Place a VISA resource name control, located on the ControlsAll ControlsI/O palette, on
the front panel.
• Set the x-axis scale of the waveform chart to show incremental values.
Figure 11.11
a. Create two shift registers by right-clicking the right or left border of the loop and selecting Add
Shift Register from the shortcut menu.
f. Place the Max & Min function, located on the FunctionsAll FunctionsComparison
palette, on the block diagram. Use two of these functions to check the current voltage against the
minimum and maximum values stored in the shift registers.
g. Place the Simple Error Handler VI, located on the FunctionsAll FunctionsTime
& Dialog palette, on the block diagram. This VI displays a dialog box if an error occurs and
displays the error information.
h. Place the Unbundle by Name function, located on the FunctionsAll
FunctionsCluster palette, on the block diagram. This function accepts status from
the error cluster.
i. Place the Or function, located on the FunctionsArithmetic & ComparisonExpress
Boolean palette, on the block diagram. This function controls when the While Loop ends. If
there is an error or you click the Stop button, the While Loop stops.
Serial communication requires that you specify the following four parameters:
• The baud rate of the transmission
• The number of data bits encoding a character
• The sense of the optional parity bit
• The number of stop bits
14 This content is available online at <http://cnx.org/content/m12293/1.1/>.
Each transmitted character is packaged in a character frame that consists of a single start bit followed
by the data bits, the optional parity bit, and the stop bit or bits. Figure 11.13 shows a typical character
frame encoding the letter m.
Figure 11.13
Baud rate is a measure of how fast data are moving between instruments that use serial communication.
RS-232 uses only two voltage states, called MARK and SPACE. In such a two-state coding scheme, the baud
rate is identical to the maximum number of bits of information, including control bits, that are transmitted
per second.
MARK is a negative voltage, and SPACE is positive. Figure 11.13 shows how the idealized signal looks on
an oscilloscope. The following is the truth table for RS-232:
Signal > 3V = 0
11.11.2.1 RS-232
The RS-232 is a standard developed by the Electronic Industries Association (EIA) and other inter-
ested parties, specifying the serial interface between Data Terminal Equipment (DTE) and Data Com-
munications Equipment (DCE). The RS-232 standard includes electrical signal characteristics (voltage
levels), interface mechanical characteristics (connectors), functional description of interchange circuits (the
function of each electrical signal), and some recipes for common kinds of terminal-to-modem connections.
The most frequently encountered revision of this standard is called RS-232C. Parts of this standard have
been adopted (with various degrees of delity) for use in serial communications between computers and
printers, modems, and other equipment. The serial ports on standard IBM-compatible personal computers
follow RS-232.
Figure 11.14
Table 11.2
The DB-9 connector is occasionally found on smaller RS-232 lab equipment. It is compact, yet has
enough pins for the core set of serial pins (with one pin extra).
note: The DB-9 pin numbers for transmit and receive (3 and 2) are opposite of those on the
DB-25 connector (2 and 3). Be careful of this dierence when you are determining if a device is
DTE or DCE.
The DB-25 connector (Figure 11.15) is the standard RS-232 connector, with enough pins to cover all the
signals specied in the standard. Table 11.3 shows only the core set of pins that are used for most RS-232
interfaces.
Figure 11.15
Table 11.3
Figure 11.16
Figure 11.17
These switch settings congure the instrument as a serial device with the following settings:
• Baud rate = 9, 600
• Data bits = 8
• Parity = no parity
• Stop bits = 1
• Flow control parameters = hardware handshaking
Handshaking is a means of data ow control. Software handshaking involves embedding control char-
acters in transmitted data. For example, XON/XOFF ow control works by enclosing a transmitted
message between the two control characters XON and XOFF. Hardware handshaking uses voltages on
physical wires to control data ow. The RTS and CTS lines of the RS-232 device are frequently used
for this purpose. Most lab equipment uses hardware handshaking.
2. Make sure the NI Instrument Simulator is connected to a serial port on the computer with a serial
cable. Make a note of the port number.
3. Power on the NI Instrument Simulator. The Power, Ready, and Listen LEDs are lit to indicate that
the device is in serial communication mode.
Figure 11.18
a. Place the Instrument I/O Express VI, located on the FunctionsInput palette, on the
block diagram. Complete the following steps in the Instrument I/O Assistant dialog box that
appears to congure the Express VI.
1. Choose COM1 (or COM2 depending on the connection port of the NI Instrument Simulator)
from the Select an instrument pull-down menu.
2. Click the Add Step button and click Write. In the command eld, type *IDN? and select \n
as the Termination character.
3. Click the Add Step button and click Read and Parse.
4. Click the Add Step button and click Read and Parse again.
note: The Instrument Simulator returns the byte size of the response, the termi-
nation character, the response, then another termination character. Therefore, after
*IDN? is sent to the instrument, the response must be read twice.
5. Click the Run button (not the Run this step button). The Run button runs the entire
sequence.
6. Return to the rst Read and Parse step.
7. Click the Auto parse button. The value returned is the size in bytes of the query response.
8. Rename Token to String Length in the Token name text box.
9. Select the second Read and Parse step.
10. Click the Auto parse button. The value returned is the identication string of the NI In-
strument Simulator.
11. Rename Token to String in the Token name text box. The conguration window should be
similar to the Figure 11.19.
Figure 11.19
bytes for the value of the point and 1 byte for the separator, such as a comma). You would need a maximum
of 4,096 ( 4 × 1, 024) bytes plus any header and trailer bytes to represent the waveform as an ASCII string.
Figure 11.20 is an ASCII waveform string.
Figure 11.20
You can use the Extract Numbers VI located in the C:\Exercises\LabVIEW Basics I directory to
convert an ASCII waveform into a numeric array, as follows. This VI outputs the waveform as a double
precision array (Figure 11.21).
Figure 11.21
Figure 11.22
Converting the binary string to a numeric array is a little more complex. You must convert the string
to an integer array. You can do this by using the String To Byte Array (Figure 11.23) function located
on the FunctionsAll FunctionsStringString/Array/Path Conversion palette. You must remove
all header and trailer information from the string before you can convert it to an array. Otherwise, this
information also is converted.
Figure 11.23
Figure 11.24
The block diagram in Figure 11.25 shows how you can use the Type Cast function to cast the binary
waveform string into an array of 16-bit integers.
Figure 11.25
You might need to use the Swap Bytes (Figure 11.26) function located on the FunctionsAll
FunctionsAdvancedData Manipulation palette to swap the most signicant 8 bits and the least sig-
nicant 8 bits for every element. Remember, the GPIB is an 8-bit bus. It can transfer only one byte at a
time. If the instrument rst sends the low byte and then the high byte, you do not need to use the Swap
Bytes function.
In the example (Figure 11.25), you needed to use the Swap Bytes (Figure 11.26) function because the
instrument sent the most signicant byte rst. Because the most signicant byte is received rst, it is placed
in a lower memory location than the least signicant byte sent after the most signicant byte.
Figure 11.26
For the binary waveform string, the waveform consists of 128 points. Each point is represented
as a 1-byte unsigned integer. The following header precedes the data points:
Complete the following steps to examine a VI that converts the waveform to an array of numbers.
The VI graphs the array and reads the waveform string from the NI Instrument Simulator or from
a previously stored array.
Figure 11.27
These switch settings congure the instrument as a GPIB device with an address of 2.
2. Power on the NI Instrument Simulator. Only the Power and Ready LEDs are lit to indicate
that the NI Instrument Simulator is in GPIB communication mode.
Figure 11.28
Data Format species an ASCII waveform or a binary waveform. Data Source species
whether the data is simulated or read from the NI Instrument Simulator through the GPIB.
Figure 11.29
• The Extract Numbers VI, located in the Exercises directory, extracts numbers
from the ASCII waveform string and places them in an array. Non-numeric characters,
such as commas, separate numbers in the string.
• The VISA Write and VISA Read functions, located on the FunctionsAll
FunctionsInstrument I/OVISA palette, query the NI Instrument Simulator for a
square wave in either ASCII or 1-byte binary format.
4. Set Data Format to Binary and run the VI again. The binary waveform string and string
length display, the VI converts the string to a numeric array, and displays it in the graph.
note: The binary waveform is similar to the ASCII waveform. However, the number of
bytes in the string is signicantly lower. It is more ecient to transfer waveforms as binary
strings than as ASCII strings because binary encoding requires fewer bytes to transfer the
same information.
5. Close the VI. Do not save changes.
Figure 11.30
Customizing VIs
By default, the VI window title is the same as the VI name. You can customize the VI window title to
make it more descriptive than the VI lename. This is useful for localized VIs so the VI window title can
be translated to the local language. Remove the checkmark from the Same as VI Name checkbox to edit
Window title.
To congure the window appearance, select one of the following window styles. A graphical representation
of each style displays on the right when you select the style.
Top-level Application Window - Shows the title bar and menu bar, hides the scrollbars and tool-
bar, allows the user to close the window, allows run-time shortcut menus, does not allow resizing,
and shows the front panel when called.
Dialog - The VI functions as a dialog box in the operating system, so the user cannot interact with
other LabVIEW windows while this VI window is open. This option does not prevent you from
bringing windows of other applications to the front. (UNIX) You cannot make a window stay
in front of all other windows. Dialog style windows stay on top, have no menu bar, scrollbars, or
toolbar, allow the user to close the window but not resize it, allow run-time shortcut menus, and
show the front panel when called. Also, if a Boolean parameter on the front panel is associated
with the <Enter> or <Return> key, LabVIEW highlights the parameter with a dark border.
Default - Same window style used in the LabVIEW development environment.
Custom - Custom window style.
Customize - Displays the Customize Window Appearance dialog box.
When LabVIEW calls a subVI, ordinarily the subVI runs without opening its front panel. If you want a
single instance of the subVI to open its front panel when called, use the SubVI Node Setup dialog box. If
you want every instance of the subVI to open its front panel when called, use the VI Properties dialog
box.
Figure 12.1
Use the following guidelines to assist you in building the front panel.
• The indicator to the right of the thermometer is a digital display belonging to the thermome-
ter. Right-click the thermometer and select Visible ItemsDigital Display from the
shortcut menu to display the digital value.
• Change # of data values to signed 32-bit integer (I32) representation.
Figure 12.2
a. Place the Thermometer VI from a previous exercise (Section 3.5) on the block
diagram. This VI acquires the current temperature value.
Figure 12.3
e. Click the OK button twice and save and close the subVI. If the front panel is not closed,
it will not close after the subVI runs.
4. Run the Use Pop-up Graph VI. After the VI acquires 10 seconds of temperature data, the
front panel of the Pop-up Graph VI displays and plots the temperature data. Click the DONE
button to return to the calling VI.
5. Change the window appearance settings for the Pop-up Graph subVI to the Dialog window
style.
6. Save and close the subVI.
7. Run the Use Pop-up Graph VI again. The Pop-up Graph subVI front panel window behaves
as a dialog box. For example, the window stays on top of all other windows and uses the
system colors.
8. Close all open VIs.
Select the shortcut key you want to assign to the control in the Key Assignment section. The front panel
control names that appear in the Current Assignments listbox correspond to the owned labels of those
controls.
To prevent users from accessing a control by pressing the <Tab> key while the VI runs, place a checkmark
in the Skip this control when tabbing checkbox.
Figure 12.4
The front panel contains four Boolean buttons (Figure 12.4). The mechanical action of the
rst three buttons is Latch When Pressed. This setting changes the control value when you
click it and retains the new value until the VI reads it once. At this point the control reverts
to its default value, even if you keep pressing the mouse button. This action is similar to a
circuit breaker and is useful for stopping While Loops or for getting the VI to perform an
action only once each time you set the control. The mechanical action of the Stop button
is Latch When Released. This setting changes the control value only after you release the
mouse button within the graphical boundary of the control. When the VI reads it once, the
control reverts to the old value. This action guarantees at least one new value. This action is
similar to dialog box buttons and system buttons.
2. Right-click a control and select AdvancedKey Navigation from the shortcut menu to dis-
play the Key Navigation dialog box.
3. In the Key Assignment section, assign the shortcut key shown in the Figure 12.4.
4. Repeat list, item 2, p. 248 and list, item 3, p. 248 for each control.
Figure 12.5
• The Display and Log Temp VI simulates a temperature measurement every 500
ms, plots it on a strip chart, and logs it to a le.
• The Display Logged Temp VI opens a le that you select, reads the logged data,
and displays them on a graph.
2. Congure each subVI to display its front panel when called.
a. Right-click the subVI and select SubVI Node Setup from the shortcut menu.
b. Place checkmarks in the Show Front Panel when called and Close afterwards if
originally closed checkboxes.
c. Click OK to close the SubVI Node Setup dialog box.
d. Repeat list, item 1, p. 249 through list, item 3, p. 249 for the remaining two subVIs.
3. Save the VI. Display the front panel and run the VI.
4. Click each button and press the corresponding keyboard shortcuts. The three subVIs return
to the Temperature System VI front panel when you press the <Enter> key. Try pressing
the <Enter> key to do so.
5. Stop the VI.
6. Congure the Temperature System VI to run automatically when you open the VI.
a. Select FileVI Properties.
b. Select Execution from the Category pull-down menu.
c. Place a checkmark in the Run When Opened checkbox.
7. Congure the VI so the menu bar and toolbar are not visible while the VI runs.
a. Select Window Appearance from the Category pull-down menu.
b. Click the Customize button.
c. Remove the checkmarks from the Show Menu Bar and Show Toolbar When Running
checkboxes.
d. Click the OK button twice.
8. Save and close all VIs.
9. Open the Temperature System VI again. The VI runs automatically when you open it. Click
the buttons on the front panel or use the keyboard shortcuts.
10. Stop and close all VIs.
Figure 12.6
The VI is already running when it opens. While the VI runs, you cannot use the menu bar,
toolbar, or keyboard shortcuts to edit or abort the VI.
2. Click the Start button. After 10 seconds, the VI stops running and quits LabVIEW.
3. Relaunch LabVIEW and open a blank VI.
4. If the VI you want to edit either does not have subVIs or you do not know what it contains,
complete list, item 5, p. 251 through list, item 13, p. 251. However, if the VI you want to
edit has subVIs, open one of the subVIs and modify the block diagram to break the subVI.
For example, place an Add function on the block diagram and do not wire the inputs. Open
the VI you want to edit. Because its subVI is nonexecutable, the VI that calls it is also
nonexecutable. It opens in edit mode and the Run button appears broken. Make sure to x
the subVI after you edit the calling VI.
5. Display the block diagram of the new VI.
6. Place the Edit Me VI, which is already built, on the block diagram. The front panel for the
Edit Me VI displays. Although you can display the block diagram of the Edit Me VI, you
cannot edit it.
7. Select OperateChange to Edit Mode. A dialog box informs you that the VI is locked.
8. Click the Unlock button. You now can edit the VI. You also can unlock a VI by selecting
FileVI Properties and selecting Security from the Category pull-down menu.
9. Select and delete the Quit LabVIEW function from the block diagram.
10. Save and close the Edit Me VI. Close the new VI and do not save changes.
11. Open the Edit Me VI again.
12. After the VI runs, try to edit it.
13. Close the Edit Me VI.
12.8.1 Adding VIs and Controls to the User Library and the Instrument Library
The simplest method for adding VIs and controls to the Controls and Functions palettes is to save them in
the labview\user.lib directory. When you restart LabVIEW, the FunctionsExpress User Libraries
8 This content is available online at <http://cnx.org/content/m12306/1.1/>.
Available for free at Connexions <http://cnx.org/content/col10241/1.4>
252 CHAPTER 12. CUSTOMIZING VIS
and ControlsExpress User Controls palettes contain subpalettes for each directory, VI library (.llb),
or menu (.mnu) le in the labview\user.lib directory, and icons for each le in the labview\user.lib
directory. After you add les to or remove les from specic directories, LabVIEW automatically updates
the palettes when you restart LabVIEW.
The FunctionsAll FunctionsInstrument I/O palette corresponds to the labview\instr.lib di-
rectory. Save instrument drivers in this directory to add them to the Functions palette.
When you add VIs or controls to the Controls and Functions palettes using this method, you cannot
set the name of each subpalette or the exact location of the VIs or controls on the palettes.
13.1 Appendix1
13.1.1 Additional Information
This section describes how you can receive more information regarding LabVIEW, instrument drivers, and
other topics related to this course.
advanced users. In addition, every issue contains a disk of LabVIEW VIs and utilities that implement
methods covered in that issue. To order LabVIEW Technical Resource, contact LTR publishing at (214)
706-0587 or visit www.ltrpub.com5 .
5 http://www.ltrpub.com
6 http://cnx.org/content/m12308/latest/ftp://ftp.pica.army.mil/pub/labview/
Available for free at Connexions <http://cnx.org/content/col10241/1.4>
APPENDIX 257
0A 012 10 LF 2A 052 42 *
0B 013 11 VT 2B 053 43 +
0C 014 12 FF 2C 054 44 ,
0D 015 13 CR 2D 055 45 -
0E 016 14 SO 2E 056 46 .
0F 017 15 SI 2F 057 47 /
10 020 16 DLE 30 060 48 0
11 021 17 DC1 31 061 49 1
12 022 18 DC2 32 062 50 2
13 023 19 DC3 33 063 51 3
14 024 20 DC4 34 064 52 4
15 025 21 NAK 35 065 53 5
16 026 22 SYN 36 066 54 6
17 027 23 ETB 37 067 55 7
18 030 24 CAN 38 070 56 8
19 031 25 EM 39 071 57 9
1A 032 26 SUB 3A 072 58 :
1B 033 27 ESC 3B 073 59 ;
1C 034 28 FS 3C 074 60 <
1D 035 29 GS 3D 075 61 =
1E 036 30 RS 3E 076 62 >
1F 037 31 US 3F 077 63 ?
40 100 64 @ 60 140 93 `
41 101 65 A 61 141 97 a
42 102 66 B 62 142 98 b
43 103 67 C 63 143 99 c
44 104 68 D 64 144 100 d
45 105 69 E 65 145 101 e
continued on next page
Table 13.1
2. Copy the les from the CD accompanying this manual as described in the Installing the Course Software
section of the Student Guide and the readme.txt le on the disks.
3. Test the station by starting LabVIEW by selecting StartProgramsStation TestsLV Station
Test to run the LV Station Test VI. Refer to the customer education resources coordinator for this VI.
4. Open MAX to verify that both the DAQ device and GPIB interface are working properly.
5. Verify that the NI DEVSIM instrument driver is installed and that the NI Instrument Simulator works
in both the GPIB and serial modes.
Glossary
Attributions
Collection: LabVIEW Graphical Programming Course
Edited by: National Instruments
URL: http://cnx.org/content/col10241/1.4/
License: http://creativecommons.org/licenses/by/1.0
Module: "LabVIEW Course Exercise Code"
By: National Instruments
URL: http://cnx.org/content/m14634/1.3/
Pages: 2-4
Copyright: National Instruments
License: http://creativecommons.org/licenses/by/2.0/
Module: "LabVIEW"
By: National Instruments
URL: http://cnx.org/content/m12192/1.2/
Page: 6
Copyright: National Instruments
License: http://creativecommons.org/licenses/by/1.0
Module: "LabVIEW Environment"
By: National Instruments
URL: http://cnx.org/content/m12193/1.3/
Pages: 7-18
Copyright: National Instruments
License: http://creativecommons.org/licenses/by/1.0
Module: "Front Panel"
By: National Instruments
URL: http://cnx.org/content/m12194/1.1/
Pages: 18-20
Copyright: National Instruments
License: http://creativecommons.org/licenses/by/1.0
Module: "Block Diagram"
By: National Instruments
URL: http://cnx.org/content/m12195/1.2/
Pages: 20-25
Copyright: National Instruments
License: http://creativecommons.org/licenses/by/1.0
Module: "Acquiring a Signal VI"
By: National Instruments
URL: http://cnx.org/content/m12196/1.3/
Pages: 25-36
Copyright: National Instruments
License: http://creativecommons.org/licenses/by/1.0
Module: "Counters"
By: National Instruments
URL: http://cnx.org/content/m12276/1.1/
Page: 208
Copyright: National Instruments
License: http://creativecommons.org/licenses/by/1.0
Module: "Simple Event Counting VI"
By: National Instruments
URL: http://cnx.org/content/m12277/1.1/
Pages: 209-210
Copyright: National Instruments
License: http://creativecommons.org/licenses/by/1.0
Module: "Digital I/O"
By: National Instruments
URL: http://cnx.org/content/m12278/1.1/
Page: 210
Copyright: National Instruments
License: http://creativecommons.org/licenses/by/1.0
Module: "Digital Example VI"
By: National Instruments
URL: http://cnx.org/content/m12279/1.1/
Pages: 210-211
Copyright: National Instruments
License: http://creativecommons.org/licenses/by/1.0
Module: "Summary, Tips, and Tricks on Data Acquisition and Waveforms"
By: National Instruments
URL: http://cnx.org/content/m12280/1.1/
Page: 212
Copyright: National Instruments
License: http://creativecommons.org/licenses/by/1.0
Module: "Additional Exercises for Data Acquisition and Waveforms"
By: National Instruments
URL: http://cnx.org/content/m12281/1.1/
Page: 212
Copyright: National Instruments
License: http://creativecommons.org/licenses/by/1.0
Module: "Instrument Control Overview"
By: National Instruments
URL: http://cnx.org/content/m12282/1.1/
Page: 213
Copyright: National Instruments
License: http://creativecommons.org/licenses/by/1.0
About Connexions
Since 1999, Connexions has been pioneering a global system where anyone can create course materials and
make them fully accessible and easily reusable free of charge. We are a Web-based authoring, teaching and
learning environment open to anyone interested in education, including students, teachers, professors and
lifelong learners. We connect ideas and facilitate educational communities.
Connexions's modular, interactive courses are in use worldwide by universities, community colleges, K-12
schools, distance learners, and lifelong learners. Connexions materials are in many languages, including
English, Spanish, Chinese, Japanese, Italian, Vietnamese, French, Portuguese, and Thai. Connexions is part
of an exciting new information distribution system that allows for Print on Demand Books. Connexions
has partnered with innovative on-demand publisher QOOP to accelerate the delivery of printed course
materials and textbooks into classrooms worldwide at lower prices than traditional academic publishers.