LabVIEW Basics I Course Manual
LabVIEW Basics I Course Manual
Course Manual
Copyright
Copyright © 1993, 2000 by National Instruments Corporation, 11500 North Mopac Expressway, Austin, Texas 78759-3504.
Under the copyright laws, this publication may not be reproduced or transmitted in any form, electronic or mechanical, including
photocopying, recording, storing in an information retrieval system, or translating, in whole or in part, without the prior written
consent of National Instruments Corporation.
Trademarks
LabVIEW™, National Instruments™, ni.com™, and PXI™ are trademarks of National Instruments Corporation.
Product and company names mentioned herein are trademarks or trade names of their respective companies.
Worldwide Technical Support and Product Information
ni.com
Worldwide Offices
Australia 03 9879 5166, Austria 0662 45 79 90 0, Belgium 02 757 00 20, Brazil 011 284 5011, Canada (Calgary) 403 274 9391,
Canada (Ontario) 905 785 0085, Canada (Québec) 514 694 8521, China 0755 3904939, Denmark 45 76 26 00,
Finland 09 725 725 11, France 01 48 14 24 24, Greece 30 1 42 96 427, Germany 089 741 31 30, Hong Kong 2645 3186,
India 91805275406, Israel 03 6120092, Italy 02 413091, Japan 03 5472 2970, Korea 02 596 7456, Mexico (D.F.) 5 280 7625,
Mexico (Monterrey) 8 357 7695, Netherlands 0348 433466, New Zealand 09 914 0488, Norway 32 27 73 00,
Poland 0 22 528 94 06, Portugal 351 1 726 9011, Singapore 2265886, Spain 91 640 0085, Sweden 08 587 895 00,
Switzerland 056 200 51 51, Taiwan 02 2528 7227, United Kingdom 01635 523545
Contents
Student Guide
A. About This Manual ............................................................................................... SG-1
B. What You Need to Get Started ............................................................................. SG-3
C. Installing the Course Software.............................................................................. SG-4
D. Course Goals and Non-Goals ............................................................................... SG-5
E. Course Map........................................................................................................... SG-6
F. Course Conventions.............................................................................................. SG-7
Lesson 1
Introduction to LabVIEW
A. LabVIEW.............................................................................................................. 1-2
B. Virtual Instruments ............................................................................................... 1-3
C. LabVIEW Environment........................................................................................ 1-6
D. LabVIEW Help Options ....................................................................................... 1-18
Summary, Tips, and Tricks......................................................................................... 1-22
Lesson 2
Creating, Editing, and Debugging a VI
A. Creating a VI......................................................................................................... 2-2
B. Editing Techniques ............................................................................................... 2-11
C. Debugging Techniques ......................................................................................... 2-20
Summary, Tips, and Tricks......................................................................................... 2-25
Additional Exercises................................................................................................... 2-29
Lesson 3
Creating a SubVI
A. SubVIs .................................................................................................................. 3-2
B. Icon and Connector Pane ...................................................................................... 3-3
C. Using SubVIs........................................................................................................ 3-9
D. Creating a SubVI from Sections of a VI............................................................... 3-16
Summary, Tips, and Tricks......................................................................................... 3-17
Additional Exercise .................................................................................................... 3-18
Lesson 4
Loops and Charts
A. While Loops..........................................................................................................4-2
B. Waveform Charts ..................................................................................................4-4
C. Shift Registers.......................................................................................................4-17
D. For Loop ...............................................................................................................4-26
Summary, Tips, and Tricks.........................................................................................4-29
Additional Exercises ...................................................................................................4-30
Lesson 5
Arrays, Graphs, and Clusters
A. Arrays....................................................................................................................5-2
B. Creating Arrays with Loops..................................................................................5-5
C. Array Functions ....................................................................................................5-7
D. Polymorphism .......................................................................................................5-10
E. Graphs ...................................................................................................................5-13
F. Clusters .................................................................................................................5-30
G. Cluster Functions ..................................................................................................5-36
Summary, Tips, and Tricks.........................................................................................5-45
Additional Exercises ...................................................................................................5-47
Lesson 6
Case and Sequence Structures
A. Case Structure .......................................................................................................6-2
B. Sequence Structure ...............................................................................................6-11
C. Formula Node .......................................................................................................6-16
D. Replacing Sequence Structures.............................................................................6-20
Summary, Tips, and Tricks.........................................................................................6-22
Additional Exercises ...................................................................................................6-23
Lesson 7
Strings and File I/O
A. Strings ...................................................................................................................7-2
B. String Functions ....................................................................................................7-4
C. File I/O ..................................................................................................................7-11
D. Formatting Spreadsheet Strings ............................................................................7-21
E. High-Level File VIs ..............................................................................................7-26
Summary, Tips, and Tricks.........................................................................................7-36
Additional Exercises ...................................................................................................7-37
Lesson 8
Data Acquisition and Waveforms
A. Overview and Configuration ................................................................................8-2
B. Data Acquisition VI Organization ........................................................................8-19
C. Performing a Single Analog Input ........................................................................8-21
D. The DAQ Wizards ................................................................................................8-27
E. Waveform Analog Input .......................................................................................8-32
F. Writing Waveform Data to File ............................................................................8-36
G. Scanning Multiple Analog Input Channels...........................................................8-39
H. Analog Output.......................................................................................................8-43
I. Digital Input and Output .......................................................................................8-47
J. Buffered Data Acquisition (Optional) ..................................................................8-50
Summary, Tips, and Tricks.........................................................................................8-56
Additional Exercise.....................................................................................................8-57
Lesson 9
Instrument Control
A. Instrument Control Overview ...............................................................................9-2
B. GPIB Communication and Configuration ............................................................9-3
C. Instrument Driver Overview .................................................................................9-11
D. Using Instrument Driver VIs ................................................................................9-15
E. VISA Overview ....................................................................................................9-23
F. Using VISA Functions and VIs ............................................................................9-26
G. Serial Port Communication...................................................................................9-31
H. Waveform Transfers (Optional)............................................................................9-41
Summary, Tips, and Tricks.........................................................................................9-49
Additional Exercises ...................................................................................................9-50
Lesson 10
VI Customization
A. Customizing VI Properties....................................................................................10-2
B. Creating Pop-Up Panels........................................................................................10-6
C. Key Navigation .....................................................................................................10-11
D. Editing VIs with Difficult VI Setup Options (Optional) ......................................10-17
E. Customizing Palettes (Optional) ...........................................................................10-21
Summary, Tips, and Tricks.........................................................................................10-27
Appendix
A. Additional Information .........................................................................................A-2
B. ASCII Character Code Equivalents Table ............................................................A-4
C. VI Quick Reference ..............................................................................................A-7
D. Instructor’s Notes..................................................................................................A-13
Thank you for purchasing the LabVIEW Basics I course kit. You can begin
developing an application soon after you complete the exercises in this
manual. This course manual and the accompanying software are used in the
three-day, hands-on LabVIEW Basics I course. You can apply the full
purchase of this course kit towards the corresponding course registration fee
if you register within 90 days of purchasing the kit. Visit the Customer
Education section of ni.com for online course schedules, syllabi, training
centers, and class registration.
The course manual is divided into lessons, each covering a topic or a set of
topics. Each lesson consists of the following:
• An introduction that describes the purpose of the lesson and what you
will learn
• A description of the topics in the lesson
• A set of exercises to reinforce those topics
• A set of additional exercises to complete if time permits
• A summary that outlines important concepts and skills taught in the
lesson
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 at left. 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.
Each exercise shows a picture of a finished front panel and block diagram
after you run the VI, as shown in the following illustration. After each block
diagram picture is a description of each object in the block diagram.
1 2
❑ A serial cable
❑ A GPIB cable
Filename Description
Disk 1
LV Basics I Directory for saving VIs created during the course
and for doing certain course exercises
basics1.llb VI library containing subVIs used during the course
nidevsim.zip Zip file containing the LabVIEW instrument driver
for the NI Instrument Simulator
Disk 2
bas1soln.exe Self-extracting archive containing the solutions to all
the course exercises
Note Class exercises that use the Thermometer VI use the (Demo) Thermometer VI in
the solutions. The (Demo) Thermometer VI is in the basics1.llb.
Windows
1. Copy the basics1.llb file from course disk 1 to the
labview\user.lib directory. After you start LabVIEW, the contents
of this directory are located on the Functions»User Libraries palette.
2. Extract the contents of nidevsim.zip to the labview\instr.lib
directory. After you start LabVIEW, the NI DevSim instrument driver is
located on the Functions»Instrument I/O»Instrument Drivers
palette.
3. Copy the LV Basics I directory to the c:\exercises directory.
4. (Optional) Double-click bas1soln.exe to install the solutions to all
exercises in the c:\solutions\LV BasI Soln directory.
Macintosh
1. Copy the basics1.llb file from course disk 1 to the user.lib folder
in the labview directory. After you start LabVIEW, the contents of this
directory are located on the Functions»User Libraries palette.
2. On a Windows computer, unzip the contents of the nidevsim.zip file.
Copy the resulting directory to the labview:instrlib directory.
After you start LabVIEW, the NI DevSim instrument driver is located
on the Functions»Instrument I/O»Instrument Drivers palette.
3. Copy the LV Basics I directory to the exercises folder.
4. (Optional) On a Windows computer, extract the contents of
bas1soln.exe and copy them to your hard drive to an appropriate
folder to install the solutions to all exercises.
UNIX
1. Log in as a superuser.
2. Make sure the course disks are not write protected.
3. Mount course disk 1 and copy the basics1.llb file to the
/labview/user.lib directory. After you start LabVIEW, the
contents of this directory are located on the Functions»User Libraries
palette.
E. Course Map
Introduction to
LabVIEW
Creating, Editing,
and Debugging a VI
Creating a SubVI
Arrays, Graphs,
and Clusters
Strings and
File I/O
VI Customization
F. Course Conventions
The following conventions appear in this course manual:
» The » symbol leads you through nested menu items and dialog box options
to a final action. The sequence File»Page Setup»Options directs you to pull
down the File menu, select the Page Setup item, and select Options from
the last dialog box.
bold Bold text denotes items that you must select or click in the software, such as
menu items and dialog box options. Bold text also denotes parameter names,
controls and buttons on the front panel, dialog boxes, sections of dialog
boxes, menu names, and palette names.
monospace Text in this font denotes text or characters that you should enter from the
keyboard, sections of code, programming examples, and syntax examples.
This font is also used for the proper names of disk drives, paths, directories,
programs, subprograms, subroutines, device names, functions, operations,
variables, filenames and extensions, and code excerpts.
Platform Text in this font denotes a specific platform and indicates that the text
following it applies only to that platform.
A. LabVIEW
LabVIEW is a graphical programming language that uses icons instead of
lines of text to create applications. In contrast to text-based programming
languages, where instructions determine program execution, LabVIEW
uses dataflow programming, where the flow of data determines execution.
In LabVIEW, you build a user interface by using a set of tools and objects.
The user interface is known as the front panel. You then add code using
graphical representations of functions to control the front panel objects.
The block diagram contains this code. In some ways, the block diagram
resembles a flowchart.
Using LabVIEW, you can create test and measurement, data acquisition,
instrument control, datalogging, 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.
B. Virtual Instruments
LabVIEW programs are called virtual instruments (VIs). 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 the VI. The following example shows
a front panel.
You build the front panel with controls and indicators, which are the
interactive input and output terminals of the VI, respectively. Controls are
knobs, push buttons, dials, and other input devices. Indicators are graphs,
LEDs, and other displays. Controls simulate instrument input devices and
supply data to the block diagram of the VI. Indicators simulate instrument
output devices and display data the block diagram acquires or generates.
After you build the front panel, you add code using graphical
representations of functions to control the front panel objects. The block
diagram contains this graphical source code. Front panel objects appear as
terminals, shown at left, on the block diagram. You cannot delete a terminal
from the block diagram. The terminal disappears only after you delete its
corresponding object on the front panel. Block diagram objects include
terminals, subVIs, functions, constants, structures, and wires, which transfer
data among other block diagram objects.
The following example shows a block diagram and its corresponding front
panel.
After you build a front panel and block diagram, build the icon and the
connector pane so you can use it in another VI. AVI within another VI is
called a subVI. A subVI corresponds to a subroutine in text-based
programming languages. Every VI displays an icon, shown at left, 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 identifies the subVI
on the block diagram of the VI.
You also need to build a connector pane, shown at left, to use the VI as a
subVI. 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 defines 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.
The power of LabVIEW lies in the hierarchical nature of the VI. After
you create a VI, you can use it as a subVI on the block diagram of a
high-level VI. There is no limit on the number of layers in the hierarchy.
Using subVIs helps you manage changes and debug the block diagram
quickly.
As you create VIs, you might find that you perform a certain operation
frequently. Consider using subVIs or loops to perform that operation
repetitively. Refer to Lesson 4, Loops and Charts, for more information
about using loops. For example, the following block diagram contains two
identical operations.
You can create a subVI that performs that operation and call the subVI
twice.You also can reuse the subVI in other VIs. The following example
uses the Temperature VI as a subVI on its block diagram.
C. LabVIEW Environment
When you launch LabVIEW, the following dialog box appears.
9
1
2 2
10
2 11
12
4
13
5
14
6 15
7 16
17
Click the Run button to run the VI. While the VI runs, the button changes
to the following if the VI is a high-level VI.
The Run button often appears broken, shown at left, when you create or edit
a VI. This button indicates that the VI is broken and cannot run. Click this
button to display the Error list window, which lists all errors.
Click the Run Continuously button to run the VI until you abort or pause
it. You also can click the button again to disable continuous running.
While the VI runs, the Abort Execution button appears. Click this button to
stop the VI immediately.
Note Avoid using the Abort Execution button to stop a VI, and either let the VI run to
completion or design a method to stop the VI programmatically. By doing so, the VI is
at a known state. For example, you can programmatically stop a VI using a switch on the
front panel.
Click the Pause button to pause a running VI. When you click the Pause
button, LabVIEW highlights on the block diagram the location where you
paused execution. Click the button again to continue running the VI.
Select the Text Settings pull-down menu to change the font settings for
the VI, including size, style, and color.
Select The Align Objects pull-down menu to align objects along axes,
including vertical, top edge, left, and so on.
Select the Reorder pull-down menu when you have objects that overlap
each other and you want to define 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.
Click the Highlight Execution button to see the flow of data through the
block diagram. Click the button again to disable execution highlighting.
Click the Step Into button to single-step into a loop, subVI, and so on.
Single-stepping through a VI steps through the VI node to 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 to step over a loop, subVI, and so on. By
stepping over the node, you execute the node without single-stepping
through the node.
Click the Step Out button to step out of a loop, subVI, and so on. By
stepping out of a node, you complete single-stepping through the node and
go to the next node.
The Warning button appears when there is a potential problem with the
block diagram, but it does not stop the VI from running. You can enable the
Warning button by selecting Tools»Options and selecting Debugging
from the top pull-down menu.
Shortcut Menus
The most often-used menu is the object shortcut menu. All LabVIEW
objects and empty space on the front panel and block diagram have
associated shortcut menus. Use the shortcut menu items to change the look
or behavior of front panel and block diagram objects. To access the shortcut
menu, right-click the object, front panel, or block diagram.
(Macintosh) Press the <Command> key and click the object, front panel,
or block diagram.
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 specific
to LabVIEW. Some menu items also list shortcut key combinations.
• Use the File menu primarily to open, close, save, and print VIs.
• Use the Edit menu to search for and modify components of a VI.
• Use the Operate menu to run, abort, and change other execution options
for the VI.
• Use the Tools menu to communicate with instruments and DAQ
devices, compare VIs, build applications, enable the Web Server, and
configure LabVIEW.
• Use the Browse menu to navigate through the VI and its hierarchy.
• Use the Window menu to display LabVIEW windows and palettes.
• Use the Help menu to view information about palettes, menus, tools,
VIs, and functions, to view step-by-step instructions for using
LabVIEW features, to access the LabVIEW manuals, and to view the
LabVIEW version number and information about computer memory.
Palettes
LabVIEW has graphical, floating 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.
Tools Palette
You can create, modify, and debug VIs using the tools located on the
floating Tools palette. The Tools palette is available on the front panel and
the block diagram. A tool is a special operating mode of the mouse cursor.
When you select a tool, the cursor icon changes to the tool icon. Use the
tools to operate and modify front panel and block diagram objects.
Select Window»Show Tools Palette to display the Tools palette. You can
place the Tools palette anywhere on the screen. Press the <Shift> key and
right-click to display a temporary version of the Tools palette at the location
of the cursor.
Use the Operating tool to change the values of a control or select the text
within a control. The Operating tool changes to the following icon when it
moves over a text control, such as a digital or string control.
Use the Positioning tool to select, move, or resize objects. The Positioning
tool changes to one of the following icons when it moves over a corner of a
resizable object.
Use the Labeling tool to edit text and create free labels. The Labeling tool
changes to the following icon when you create free labels.
Use the Wiring tool to wire objects together on the block diagram.
Use the Object Shortcut Menu tool to access an object shortcut menu with
the left mouse button.
Use the Scrolling tool to scroll through windows without using scrollbars.
Use the Breakpoint tool to set breakpoints on VIs, functions, nodes, wires,
and structures to pause execution at that location.
Use the Probe tool 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 to copy colors for pasting with the Coloring tool.
Use the Coloring tool to color an object. It also displays the current
foreground and background color settings.
Controls Palette
Use the Controls palette to place controls and indicators on the front
panel. The Controls palette is available only on the front panel. Select
Window»Show Controls Palette or right-click the front panel workspace
to display the Controls palette. You also can display the Controls palette
by right-clicking an open area on the front panel. Tack down the Controls
palette by clicking the pushpin on the top left corner of the palette.
Functions Palette
Use the Functions palette to build the block diagram. The Functions palette
is available only on the block diagram. Select Window»Show Functions
Palette or right-click the block diagram workspace to display the Functions
palette. You also can display the Functions palette by right-clicking an open
area on the block diagram. Tack down the Functions palette by clicking the
pushpin on the top left corner of the palette.
Loading VIs
You load a VI into memory by selecting File»Open. The Choose the VI to
open dialog box appears, so you can navigate to the VI you want to open.
The Loading field 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.
Saving VIs
Select Save, Save As, Save All, or Save with Options from the File menu
to save VIs as individual files or group several VIs together and save them
in a VI library. VI library files end with the extension .llb. National
Instruments recommends that you save VIs as individual files, organized in
directories, especially if multiple developers are working on the same
project.
LabVIEW uses native file dialogs for loading and saving. You can disable
this feature by selecting Tools»Options and selecting Miscellaneous from
the top pull-down menu.
Because VIs are files, you can use any file transfer method or utility to
move VIs between platforms. You can port VIs over networks using FTP,
Z or XModem protocols, or similar utilities. Such network transfers
eliminate the need for additional file translation software. If you port VIs
using magnetic media, such as floppy disks or a moveable external hard
drive, you need a generic file transfer utility program, such as the following:
• (Windows) MacDisk and TransferPro transfer Macintosh files to the
PC format and vice versa.
• (Macintosh) DOS Mounter, MacLink, and Apple File Exchange convert
PC files to the Macintosh format and vice versa.
• (Sun) PC File System (PCFS) converts PC files to the Sun format and
vice versa.
• (HP-UX) The doscp command mounts PC disks and copies their files.
Note Certain operating system-specific VIs are not portable between platforms, such as
DDE (Dynamic Data Exchange) VIs, ActiveX VIs, and AppleEvents.
Note You also can open the VI by clicking the Open VI button and navigating to the
labview\examples\apps\freqresp.llb\Frequency Response.vi.
Front Panel
4. Click the Run button on the toolbar, shown at left, to run this VI.
This VI simulates sending a stimulus signal to a Unit Under Test (UUT)
and then reading back the response. The resulting frequency response
curve is displayed in the graph on the front panel, as shown in the
following illustration.
5. Use the Operating tool, shown at left, to change the Amplitude knob
value. Click the mark on the knob and drag it to the desired location, use
the increment or decrement arrows on the digital control, or place the
cursor in the digital display and enter a number.
If you enter a number in the digital display, the Enter button, shown at
left, appears on the toolbar. The number is not passed to the VI until you
click this button or press the <Enter> key.
(Macintosh and Sun) Press the <Return> key.
6. Click the Run button to run the VI again. Try adjusting the other
controls on the panel and running the VI to see what changes occur.
Block Diagram
7. Select Window»Show Diagram or press the <Ctrl-E> keys to display
the following block diagram for the Frequency Response VI.
(Macintosh) Press the <Command-E> keys. (Sun) Press the <Meta-E>
keys. (HP-UX and Linux) Press the <Alt-E> keys.
This icon is a subVI called Demo Fluke 8840A VI. After you
double-click it, the following front panel of that subVI opens.
(Macintosh) Press the <Command-H> keys. (Sun) Press the <Meta-H> keys.
(HP-UX and Linux) Press the <Alt-H> keys.
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. The following is an example Context Help
window.
Click the Simple/Detailed Context Help button located on the lower left
corner of the Context Help window to change between simple and detailed
context help. The simple mode emphasizes the important connections.
Optional terminals are shown by wire stubs, informing you that other
connections exist. The detailed mode displays all terminals, as shown in the
following example.
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.
Click the More Help button to display the corresponding topic in the
LabVIEW Help, which describes the object in detail.
LabVIEW Help
The LabVIEW Help contains detailed descriptions of most palettes, menus,
tools, VIs, and functions. The LabVIEW Help also includes step-by-step
instructions for using LabVIEW features and links to the LabVIEW
Tutorial, example VIs, PDF versions of all the LabVIEW manuals and
Application Notes, and technical support resources on the National
Instruments Web site.
You can access this information either by clicking the More Help button in
the Context Help window, selecting Help»Contents and Index, or
clicking the sentence Click here for more help in the Context Help
window.
Exercise 1-2
Objective: To use LabVIEW help utilities for information about front panel and block diagram
objects and features.
Part A
1. Select Help»Contents and Index to open the LabVIEW Help.
2. Access the technical support resources on the National Instruments Web
site.
a. Locate the Technical Support Resources book at the bottom of the
Contents tab.
b. Click the book to expand it and click the Technical Support
Resources page. The Technical Support Resources topic appears.
c. Click the Technical Support link to open the Technical Support
section of ni.com in the LabVIEW Help window.
d. Click the Back button on the toolbar to return to the Technical
Support Resources topic.
3. Open the PDF version of the LabVIEW User Manual.
a. Click the Related Documentation page at the top of the Contents
tab. The Related Documentation topic appears.
b. Click the LabVIEW User Manual link to open the PDF version of
the manual in the LabVIEW Help window.
c. Click the Help Topics button on the toolbar to hide the Contents tab
of the LabVIEW Help window.
d. Click the Help Topics button again to display the Contents tab.
e. Click the Back button to return to the Related Documentation topic.
4. Browse through a few of the other sections of the LabVIEW Help.
Part B
5. The Frequency Response VI should still be open from Exercise 1-1.
If not, open it as described in Exercise 1-1.
6. Select Window»Show Diagram to display the block diagram.
7. Select Help»Show Context Help or press the <Ctrl-H> keys to display
the Context Help window.
(Macintosh) Press the <Command-H> keys. (Sun) Press the <Meta-H>
keys. (HP-UX and Linux) Press the <Alt-H> keys.
Notes
Notes
A. Creating a VI
VIs contain three main components—the front panel, the block diagram,
and the icon and connector pane. Refer to Lesson 3, Creating a SubVI, for
more information about the icon and connector pane.
Front Panel
You build the front panel with controls and indicators, which are the
interactive input and output terminals of the VI, respectively. Controls are
knobs, push buttons, dials, and other input devices. Indicators are graphs,
LEDs, and other displays. Controls simulate instrument input devices and
supply data to the block diagram of the VI. Indicators simulate instrument
output devices and display data the block diagram acquires or generates.
Use the Controls palette to place controls and indicators on the front
panel. The Controls palette is available only on the front panel. Select
Window»Show Controls Palette or right-click the front panel workspace
to display the Controls palette.
1 2
To enter or change values in a digital control, you can click the increment
arrow 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.
Block Diagram
The block diagram is composed of nodes, terminals, and wires, as shown in
the following illustration.
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.
Node types include functions, subVIs, and structures. Functions are built-in
execution elements, comparable to an operator, function, or statement.
SubVIs are VIs used on the block diagram of another VI, comparable to
subroutines. Structures are process control elements, such as Sequence
structures, Case structures, For Loops, or While Loops. The Add and
Subtract nodes in the previous block diagram are function nodes.
Terminals
Front panel objects appear as terminals on the block diagram. The terminals
represent the data type of the control or indicator. For example, a DBL
terminal, shown at left, represents a double-precision, floating-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 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 flow to the indicator terminals, where
they exit the block diagram, reenter the front panel, and appear in front panel
indicators.
The terminals in the previous block diagram belong to four front panel
controls and indicators. The connector panes of the Add and Subtract
functions, shown at left, have three node terminals. To display the connector
pane, right-click the function node and select Visible Items»Terminals
from the shortcut menu.
Wires
You transfer data among block diagram objects through wires. They are
analogous to variables in text-based programming languages. Each wire has
a single data source, but you can wire it to many VIs and functions that read
the data. Wires are different colors, styles, and thicknesses, depending on
their data types. The following examples are the most common wire types.
As you move a selected object close to other objects on the block diagram,
LabVIEW draws temporary wires to show you valid connections. When you
release the mouse button to place the object on the block diagram,
LabVIEW automatically connects the wires.
Toggle automatic wiring by pressing the spacebar while you move an object
using the Positioning tool. You can adjust the automatic wiring settings by
selecting Tools»Options and selecting Block Diagram from the top
pull-down menu.
Showing Terminals
To make sure you wire the correct terminals on functions, display the
connector pane by right-clicking the function node and selecting Visible
Items»Terminals from the shortcut menu.
To return to the icon, right-click the function node and select Visible
Items»Terminals from the shortcut menu to remove the checkmark.
Dataflow Programming
LabVIEW follows a dataflow model for running VIs. A block diagram node
executes when all its inputs are available. When a node completes execution,
it supplies data to its output terminals and passes the output data to the next
node in the dataflow path.
For example, consider a block diagram that adds two numbers and then
subtracts 50.0 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 one of the inputs of the Subtract function is not valid until
the Add function has finished executing and passed 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 finishes execution.
For example, if you want to find the Random Number function, click the
Search button on the Functions palette toolbar and start typing Random
Number in the textbox 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 the
following example.
Double-click the search result to highlight its location on the palette. You
can then click the Up to Owning Palette button to view the hierarchy of
where the object resides.
Front Panel
Block Diagram
1 1
• You can bend a wire by clicking to tack the wire down 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 Items»Terminals from the shortcut
menu to display the connector pane. Return to the icons after
wiring by right-clicking the functions and selecting Visible
Items»Terminals 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, listing the name of the terminal.
• To cancel a wire you started, press the <Esc> key, right-click, or
click the source terminal.
10. Display the front panel by clicking it or by selecting Window»Show
Panel.
11. Save the VI, because you will use this VI later in the course.
a. Select File»Save.
b. Navigate to c:\exercises\LV Basics I.
Note Save all the VIs you edit in this course in c:\exercises\LV Basics I.
B. Editing Techniques
Creating Objects
In addition to creating front panel objects from the Controls palette, you
also can create controls, indicators, and constants by right-clicking a node
terminal and selecting Create from the shortcut menu.
You cannot delete a control or indicator terminal from the block diagram.
The terminal disappears only after you delete its corresponding object on the
front panel.
Selecting Objects
Use the Positioning tool to click an object to select it on the front panel and
block diagram.
When the object is selected, a moving dashed outline surrounds it. To select
more than one object, press the <Shift> key while you click each additional
object you want to select.
You also can select multiple objects by clicking an open area and dragging
the cursor until all the objects are in the selection rectangle.
Moving Objects
You can move an object by clicking it with the Positioning tool and dragging
it to a desired location. You also can move selected objects by pressing the
arrow keys. Press the <Shift> key while you press the arrow keys to move
objects several pixels at a time.
Deleting Objects
You can delete objects by using the Positioning tool to select the object(s)
and pressing the <Delete> key or selecting Edit»Clear.
Undo/Redo
If you make a mistake while editing a VI, you can undo or redo those steps
by selecting Undo or Redo from the Edit menu. You can set the number of
actions that you can undo or redo by selecting Tools»Options and selecting
Block Diagram from the top pull-down menu.
Duplicating Objects
You can duplicate most objects by pressing the <Ctrl> key while using the
Positioning tool to click and drag a selection.
(Macintosh) Press the <Option> key. (Sun) Press the <Meta> key. (HP-UX and
Linux) Press the <Alt> key.
(HP-UX) You also can duplicate objects by clicking and dragging the object
with the middle mouse button.
After you drag the selection to a new location and release the mouse button,
a copy of the icon appears in the new location, and the original icon remains
in the old location. This process is called cloning.
Labeling Objects
Use labels to identify objects on the front panel and block diagram.
LabVIEW includes two kinds of labels—owned labels and free labels.
Owned labels belong to and move with a particular object and annotate that
object only. You can move an owned label independently, but when you
move the object that owns the label, the label moves with the object. Free
labels are not attached to any object, and you can create, move, rotate, or
delete them independently. Use them to annotate front panels and block
diagrams.
To create a free label, use the Labeling tool to click any open area and type
the text you want to appear in the label in the box that appears. After you
type the label, click anywhere outside the label or click the Enter button on
the toolbar. By default, pressing the <Enter> key adds a new line. Press the
<Shift-Enter> keys to end text entry. To end text entry with the <Enter> key,
select Tools»Options, select Front Panel from the top pull-down menu,
and place a checkmark in the End text entry with Return key checkbox.
2
4
1 2 3
3 5 6 7
Wire Stretching
You can move one or more wired objects by using the Positioning tool to
drag the selected objects to a new location.
1 2 3
Broken Wires
A broken wire appears as a dashed black line, as shown in the following
example. Broken wires occur for a variety of reasons, such as when you try
to wire two objects with incompatible data types.
Move the Wiring tool over a broken wire to view the tip strip that describes
why the wire is broken. Triple-click the wire with the Positioning tool and
press the <Delete> key to remove a broken wire. You can remove all broken
wires by selecting Edit»Remove Broken Wires.
Caution Use caution when removing all broken wires. Sometimes a wire appears broken
because you are not finished wiring the block diagram.
Certain controls and indicators use text in more than one display. Examples
include graph axes and digital indicators or scale markers on numeric scales.
You can modify each text display independently by using the Labeling tool
to highlight the text, as shown in the following graph. Then select the Text
Settings pull-down menu on the toolbar.
Resizing Objects
You can change the size of most front panel objects. When you move the
Positioning tool over a resizable object, resizing handles, shown at left,
appear at the corners of a rectangular object, and resizing circles appear on
a circular object. When you resize an object, the font size remains the same.
Drag the resizing handles or circles until the dashed border outlines the size
you want and release the mouse button. Press the <Shift> key while you
drag the resizing handles or circles to keep the object proportional to its
original size.
You also can resize block diagram objects, such as structures and constants.
Coloring Objects
You can change the color of many objects but not all of them. For example,
block diagram terminals of front panel objects and wires use specific colors
for the type and representation of data they carry, so you cannot change
them.
You also can make front panel objects transparent to layer them. Right-click
an object with the Coloring tool and select the box with a T in it to make an
object transparent.
Note Remember that you can select Edit»Undo if you make a mistake.
Front Panel
1. Select File»Open and navigate to c:\exercises\LV Basics I to
open the Editing Exercise VI.
(Windows, Sun, and HP-UX) If you closed all open VIs, click the Open VI
button on the LabVIEW dialog box.
2. Reposition the digital control.
a. Use the Positioning tool, shown at left, to click the digital control
and drag it to another location. The control label follows the position
of the control.
b. Click a blank space on the front panel to deselect the control.
c. Click the label and drag it to another location. The control does not
follow. You can position an owned label anywhere relative to the
control. The label follows its owner if you move the owner.
Block Diagram
13. Select Window»Show Diagram to display the block diagram. Wire the
block diagram terminals as shown in the following block diagram.
The Not function inverts the value of the Boolean switch A and passes
the value to the round LED.
14. Right-click the lower left terminal of the Multiply function and select
Create»Constant from the shortcut menu to create a numeric constant,
shown at left.
15. Type 5 in the textbox and click the Enter button on the toolbar.
16. Use the Wiring tool, shown at left, and the following techniques to wire
the block diagram:
• Select Help»Show Context Help 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 gray.
• To identify terminals on the nodes, right-click the icon and select
Visible Items»Terminal from the shortcut menu to display the
connector pane. When wiring is complete, right-click the connector
pane and select Visible Items»Terminal from the shortcut menu to
remove the checkmark.
• To add a branch to a wire, click the location on the wire where you
want to start the branch.
• To cancel a wire you started, press the <Esc> key, right-click, or
click the source terminal.
17. Select File»Save to save the VI.
18. Display the front panel by clicking it or by selecting Window»Show
Panel.
19. Use the Operating tool to change the value of the front panel controls.
20. Click the Run button on the toolbar to run the VI.
21. Select File»Close to close the VI.
C. Debugging Techniques
If a VI does not run, it is a broken, or nonexecutable, VI. The Run button
often appears broken, shown at left, when you create or edit a VI. If it is still
broken when you finish wiring the block diagram, the VI is broken and will
not run.
Finding Errors
Click the broken Run button or select Windows»Show Error List to
display the Error list window, which lists all the errors. Double-click an
error description to display the relevant block diagram or front panel and
highlight the object that contains the error.
Execution Highlighting
View an animation of the execution of the block diagram by clicking the
Highlight Execution button, shown at left. Execution highlighting shows
the movement 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.
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 affect 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.
Probes
Use the Probe tool, shown at left, to check intermediate values on a wire as
a VI 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 flowed 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 Probe from the shortcut menu.
Breakpoints
Use the Breakpoint tool, shown at left, to place a breakpoint on a VI, node,
or wire on the block diagram and pause execution at that location. 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. Breakpoints are red frames for
nodes and block diagrams and red dots for wires.
The broken Run button, shown at left, appears on the toolbar, indicating
the VI is broken.
2. Select Window»Show Diagram to display the following block
diagram.
The number in the titlebar of the Probe window matches the number
on the block diagram where you placed the probe.
b. Single-step through the VI again. The Probe window displays the
data as they flow through each wire segment.
11. Place breakpoints on the block diagram to pause execution at that
location.
a. Use the Breakpoint tool, shown at left, to click nodes or wires.
Clicking the block diagram workspace is analogous to a break on the
first line.
b. Click the Run button to run the VI. The VI pauses at the breakpoints
you set.
c. Click the Continue button, shown at left, to continue running the VI.
d. Use the Breakpoint tool to click the breakpoints you set and remove
them.
12. Click the Highlight Execution button to disable execution highlighting.
13. Select File»Close to close the VI and all open windows.
(Macintosh) Press the <Option> key instead of the <Ctrl> key. (Sun) Press the
<Meta> key. (HP-UX and Linux) Press the <Alt> key.
Operating
• Frequently used menu options have equivalent keyboard shortcuts. For
example, to save a VI, you can select File»Save or press the <Ctrl-S>
keys. Common keyboard shortcuts include the following:
• To alternate among tools on the Tools palette, press the <Tab> key. To
toggle between the Positioning and Wiring tools on the block diagram
or the Positioning and Operating tools on the front panel, press the
spacebar.
• To increment or decrement digital 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 File»VI Properties, select
Execution from the top pull-down menu, and remove the checkmark
from the Allow Debugging checkbox.
Editing
• Use the following shortcuts to create constants, controls, and indicators:
– Right-click a function terminal and select Create»Constant,
Create»Control, or Create»Indicator 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 Browse»This VI’s SubVIs.
• After you type a label, press the <Shift-Enter> keys 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.
• 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 Edit»Undo 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.
Wiring
• Select Help»Show Context Help 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 gray.
• Press the spacebar to toggle the wire direction.
• 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.
1
2
1 2
1 Tack down a wire by clicking 2 Tack and break the wire by double-clicking
• 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 Items»Terminals from the shortcut menu.
Debugging
• When single-stepping, use the following keyboard shortcuts:
Additional Exercises
2-4 Build a VI that compares two numbers and turns on an LED if the
first number is greater than or equal to the second number.
Save the VI and name it Compare.vi.
Tip Use the Greater Or Equal? function located on the Functions»Comparison palette.
2-5 Build a VI that generates a random number between 0.0 and 10.0
and divides the random number by a number specified on the front
panel. If the number input is 0, the VI should turn on a front panel
LED to indicate a divide by zero error.
Save the VI and name it Divide.vi.
Notes
This lesson introduces the icon and connector pane of a VI and describes
how you can use a VI as a subVI in other VIs.
A. SubVIs
After you build a VI and create its icon and connector pane, you can use it in
another VI. A VI within another VI is called a subVI. A subVI corresponds
to a subroutine in text-based programming languages. A subVI node
corresponds to a subroutine call in text-based programming languages. The
node is not the subVI itself, just as a subroutine call statement in a program
is not the subroutine itself. Using subVIs helps you manage changes and
debug the block diagram quickly. Refer to the LabVIEW Basics II Course
Manual for more information about application development.
Creating an Icon
Every VI displays an icon, shown at left, 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 identifies 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
by double-clicking the icon in the upper right corner of the front panel. You
also can edit icons by selecting File»VI 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 following
dialog box.
You also can drag a graphic from anywhere in your file system and drop it
in the upper right corner of the front panel or block diagram.
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. The default
is 256-color mode. Select the Copy from options to change modes.
Use the tools on the left side of the Icon Editor dialog box to perform the
following tasks:
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 fill 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 filled with the background color. Double-click this tool to frame
the icon in the foreground color and fill 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 different font. (Windows) Small Fonts works well in icons.
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.
A solid border highlights the pattern currently associated with the icon.
The maximum number of terminals available for a subVI is 28.
Note Try not to assign more than 16 terminals to a VI. Too many terminals can reduce
the readability and usability of the VI.
You also can select the control or indicator first and then select the terminal.
Note Although you use the Wiring tool to assign terminals on the connector pane to
front panel controls and indicators, no wires are drawn between the connector pane and
these controls and indicators.
Front Panel
1. Select File»Open and navigate to c:\exercises\LV Basics I to
open the Convert C to F VI.
(Windows, Sun, and HP-UX) If you closed all open VIs, click the Open VI
button on the LabVIEW dialog box.
The following front panel appears.
2. 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.
3. Double-click the Select tool, shown at left, on the left side of the Icon
Editor dialog box to select the default icon.
4. Press the <Delete> key to remove the default icon.
5. Double-click the Rectangle tool, shown at left, to redraw the border.
6. Create the following icon.
a. Use the Text tool, shown at left, to click the editing area.
b. Type C and F.
c. Double-click the Text tool and change the font to Small Fonts.
d. Use the Pencil tool, shown at left, 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 select 256 Colors in the Copy from field
to create a black and white icon, which LabVIEW uses for printing
unless you have a color printer.
g. When the icon is complete, click the OK button to close the Icon
Editor dialog box. The icon appears in the icon in the upper right
corner of the front panel and block diagram.
7. Right-click the icon on the front panel and select Show Connector from
the shortcut menu to define the connector pane terminal pattern.
LabVIEW selects a 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 at left.
8. Assign the terminals to the digital control and digital indicator.
a. Select Help»Show Context Help to display the Context Help
window. View each connection in the Context Help window as you
make it.
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. The left terminal turns orange and a
marquee highlights the control.
d. Click an open area of 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. The right terminal turns orange.
f. Click an open area on the front panel. Both terminals are orange.
g. Move the cursor over the connector pane. The Context Help
window shows that both terminals are connected to floating-point
values.
9. Select File»Save to save the VI, because you will use this VI later in the
course.
10. Select File»Close to close the Convert C to F VI.
C. Using SubVIs
After you build a VI and create its icon and connector pane, you can use it
as a subVI. To place a subVI on the block diagram, select Functions»Select
a VI. Navigate to and double-click the VI you want to use as a subVI and
place it on the block diagram.
You also can place an open VI on the block diagram of another open VI by
using the Positioning tool to click the icon in the upper right corner of the
front panel or block diagram of the VI you want to use as a subVI and drag
the icon to the block diagram of the other VI.
(Macintosh) Press the <Option> key. (Sun) Press the <Meta> key. (HP-UX and
Linux) Press the <Alt> key.
Any changes you make to a subVI affect only the current instance of the
subVI until you save the subVI. When you save the subVI, the changes
affect all calls to the subVI, not just the current instance.
You can designate which inputs and outputs are required, recommended,
and optional to prevent users from forgetting to wire subVI connections.
Measure the voltage using the plug-in DAQ device in your computer and
convert the voltage into a temperature reading. The sensor is hard-wired to
Channel 0 of the DAQ device.
Front Panel
1. Select File»New to open a new front panel.
(Windows, Sun, and HP-UX) If you closed all open VIs, click the New VI
button on the LabVIEW dialog box.
2. Create the thermometer indicator, as shown in the following front panel.
Block Diagram
8. Select Window»Show Diagram to display the block diagram.
9. Build the following block diagram.
Note If a DAQ device and/or DAQ Signal Accessory is not available, use the (Demo)
Read Voltage VI located on the Functions»User Libraries»Basics I Course palette
instead of the Read Voltage VI to simulate the Read Voltage VI operation.
Tip To identify terminals on the nodes, right-click the icon and select Visible
Items»Terminal from the shortcut menu to display the connector pane.
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 left, to redraw the border.
e. Use the Pencil tool, shown at left, 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 at left, and change the font to
Small Fonts.
h. Select the B & W icon and select 256 Colors in the Copy from field
to create a black and white icon, which LabVIEW uses for printing
unless you have a color printer.
i. When the icon is complete, click the OK button. The icon appears
in the upper right corner of the front panel.
15. 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 area on the front panel.
16. Save the VI, because you will use this VI later in the course.
a. Select File»Save.
b. Navigate to c:\exercises\LV Basics I.
c. Type Thermometer.vi in the dialog box.
d. Click the Save button.
17. Select File»Close to close the VI.
Note You cannot convert a section with more than 28 inputs and outputs, because 28 is
the maximum number of terminals available on a connector pane.
Additional Exercise
3-3 Build a VI that calculates the slope between two X-Y pairs, as shown
in the following front panel and block diagram.
Notes
Notes
This lesson introduces the While Loop, For Loop, and the waveform chart
and shift register.
A. While Loops
Similar to a Do Loop or a Repeat-Until Loop in text-based programming
languages, a While Loop, shown at left, executes a subdiagram until a
condition is met. You place a While Loop on the block diagram by first
selecting it on the Functions»Structures palette.
Then use the cursor to click-and-drag a selection area around the code you
want to repeat. When you release the mouse button, a While Loop boundary
encloses the code you have selected as shown in the following block
diagram.
The completed While Loop is a resizable box. You can add additional block
diagram elements to the While Loop by dragging and dropping them inside
the boundary.
Iteration Conditional
Terminal Terminal
The While Loop executes the subdiagram until the conditional terminal, an
input terminal, receives a specific Boolean value. The default behavior and
appearance of the conditional terminal is Continue If True, shown at left.
When a conditional terminal is Continue If True, the While Loop executes
its subdiagram until the conditional terminal receives a FALSE value. The
iteration terminal (an output terminal), shown at left, contains the number of
completed iterations. The iteration count always starts at zero. During the
first iteration, the iteration terminal returns 0.
In the following block diagram, the While Loop executes until the value
output from the subVI is less than 10 or the Enable control is FALSE. The
And function outputs a TRUE only if both inputs are TRUE; otherwise, it
outputs a FALSE.
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
Stop If True, shown at left. When a conditional terminal is Stop If True,
the While Loop executes its subdiagram until the conditional terminal
receives a TRUE value, as shown in the following block diagram.
Now the While Loop stops when the subVI value is greater than or equal to
10.0 AND the Enable control is pushed (TRUE).
B. Waveform Charts
The waveform chart is a special numeric indicator that displays one or more
plots. The waveform chart is located on the Controls»Graph palette.
Waveform charts can display single or multiple traces. The following front
panel shows an example of a multiple-plot waveform chart.
Charts use three different modes to scroll data, as shown in the following
front panel. Right-click the chart and select Advanced»Update Mode from
the shortcut menu. Select Strip Chart, Scope Chart, or Sweep Chart. The
default mode is Strip Chart.
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
display is similar to an EKG display. A sweep works similarly to a scope
except it shows the old data on the right and the new 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
significantly faster than the strip chart.
Front Panel
Block Diagram
12. Save the VI as Temperature Monitor.vi, because you will use this
VI later in the course.
13. Display the front panel by clicking it or by selecting Window»Show
Panel.
14. Use the Operating tool to click the vertical toggle switch and turn it to
the ON position.
15. Run the VI.
The While Loop is an indefinite looping structure. The diagram within
its border executes as long as the specified condition is true. In this
example, as long as the switch is on (TRUE), the Thermometer VI takes
and returns a new measurement and displays it on the waveform chart.
16. Click the vertical toggle switch to stop the acquisition. This changes the
loop condition to FALSE and the loop ends.
17. Format and customize the X and Y scales of the waveform chart to suit
your display preferences and data.
a. Right-click the chart and select Y Scale»Formatting from the
shortcut menu. The following dialog box appears.
b. Click the grid style selector and select different styles for the axes
from the sub-menu that appears to experiment with different x- and
y-axis grid options. You also can experiment with scale styles,
scaling factors, mapping mode, and the format and precision of the
axis displays.
c. Select the values shown in the previous dialog box and click the OK
or Cancel buttons.
18. Right-click the waveform chart and select Data Operations»Clear
Chart from the shortcut menu to clear the display buffer and reset the
waveform chart. If the VI is running, select Clear Chart from the
shortcut menu.
For example, consider the following vertical toggle switch. The default
value of the switch is off (FALSE).
Switch When Pressed—Changes the control value each time you click the
control with the Operating tool. The action is similar to that of a ceiling light
switch. How often the VI reads the control does not affect this action.
Switch When Released—Changes the control value only after you release
the mouse button during a click within the graphical boundary of the
control. How often the VI reads the control does not affect this action.
Switch Until Released—Changes the control value when you click the
control and retains the new value until you release the mouse button, at
which time the control reverts to its original value. The action is similar to
that of a door buzzer. How often the VI reads the control does not affect this
action.
Latch When Pressed—Changes the control value when you click the
control and retains the new value until the VI reads it once, at which time
the control reverts to its default value. This action happens whether or not
you continue to hold down the mouse button. This action is similar to that
of a circuit breaker and is useful for stopping While Loops or having the VI
do something only once each time you set the control.
Latch When Released—Changes the control value only after you release
the mouse button. When the VI reads the value once, the control reverts to
the old value. This action guarantees at least one new value.
Latch Until Released—Changes the control value when you click the
control and retains the value until the VI reads the value once or until you
release the mouse button, whichever occurs last.
19. Modify the vertical toggle switch so temperature is plotted on the graph
each time you run the VI.
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 Operations»Make Current
Value Default from the shortcut menu. This sets the ON position as
the default value.
d. Right-click the switch and select Mechanical Action»Latch When
Pressed from the shortcut menu.
20. Run the VI.
21. 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 While Loop condition terminal reads the value.
Adding Timing
When this VI runs, the While Loop executes as quickly as possible.
However, you might want to take data at certain intervals, such as once per
second or once per minute.
Control loop timing with the Wait Until Next ms Multiple function located
on the Functions»Time & Dialog palette. This function ensures that no
iteration is shorter than the specified number of milliseconds.
Hints:
1. Right-click the waveform chart plot legend and select Visible
Items»Plot Legend from the shortcut menu to hide the legend.
2. Right-click the word Time and select Visible Scale Label from the
shortcut menu to remove the x-axis scale label.
3. Use the Random Number (0-1) function located on the
Functions»Numeric palette to generate the data.
4. Multiply the knob terminal by 1,000 to convert the seconds to
milliseconds. Use this value as the input to the Wait Until Next ms
Multiple function located on the Functions»Time & Dialog palette.
5. Right-click the chart and select Advanced»Update Mode from the
shortcut menu to set the chart mode.
6. Save the VI as Random Signal.vi, because you will use this VI later
in the course.
Front Panel
1. Open a new front panel.
2. Build the following front panel. Modify the controls and indicators as
shown and described in this exercise.
The Number to Match control specifies the number you want to match.
The Current Number indicator displays the current random number.
The # of iterations indicator displays the number of iterations before a
match.
Block Diagram
9. Build the following block diagram.
C. Shift Registers
With While Loops and For Loops, you can use shift registers to transfer
values from one iteration to the next. Create a shift register by right-clicking
the left or right loop border and selecting Add Shift Register from the
shortcut menu.
The shift register contains a pair of terminals directly opposite each other on
the vertical sides of the loop border.
The right terminal stores the data on the completion of an iteration. Those
data are shifted at the end of the iteration and they appear in the left terminal
at the beginning of the next iteration, as shown in the following figure. A
shift register can hold any data type, such as numeric, Boolean, string, array,
and so on. The shift register automatically adapts to the data type of the first
object wired to the shift register.
You can configure the shift register to remember values from previous
iterations. This feature is useful when you average data points. To create
additional terminals to access values from previous iterations, right-click the
left terminal and select Add Element from the shortcut menu. For example,
if you add two more elements to the left terminal, you access values from
the last three iterations.
Note LabVIEW does not discard values stored in the shift register until you close the VI
and remove it from memory. In other words, if you run a VI containing uninitialized shift
registers, the initial values for the subsequent run are the values left from the previous
run.
Run 1 Run 1
Run 2 Run 2
Front Panel
1. Open the Shift Register Example.vi. The front panel has the
following four digital indicators.
The X(i) indicator displays the current value, which shifts to the left
terminal at the beginning of the next iteration. The X(i-1) indicator
displays the value one iteration ago, the X(i-2) indicator displays the
value two iterations ago, and so on.
2. Display the block diagram and make sure both the front panel and block
diagram are visible. If necessary, close or move the Tools and
Functions palettes. The 0 wired to the left terminals initializes the
elements of the shift register to 0.
Block Diagram
Front Panel
1. Open the Temperature Monitor VI, which you built in Exercise 4-1.
Block Diagram
3. Display the block diagram.
4. Right-click the right or left border of the While Loop and select Add
Shift Register from the shortcut menu to create a shift register.
5. Right-click the left terminal of the shift register and select Add Element
from the shortcut menu to add an element to the shift register.
6. Modify the block diagram as shown in the previous block diagram.
7. Select Functions»Select a VI, navigate to c:\exercises\LV
Basics I, double-click the Thermometer VI, which you built in
Exercise 3-2, and place the VI on the block diagram. This VI returns one
temperature measurement from the temperature sensor and is used to
initialize the left shift registers before the loop starts.
The Compound Arithmetic function located on the
Functions»Numeric palette returns the sum of the current temperature
and the two previous temperature readings. Place the Positioning tool at
the corner of the function until the cursor changes to the resizing
handles, shown at left. Click the corner and drag to stretch the function
into a three-input Add function.
The Divide function located on the Functions»Numeric palette returns
the average of the last three temperature readings.
During each iteration of the While Loop, the Thermometer VI takes one
temperature measurement. The VI adds this value to the last two
measurements stored in the left terminals of the shift register. The VI
divides the result by three to find the average of the three measurements,
the current measurement plus the previous two. The VI displays the
average on the waveform chart. Notice that the VI initializes the shift
register with a temperature measurement.
8. Save the VI, because you will use this VI later in the course.
9. Run the VI.
Multiplot Charts
Charts can accommodate more than one plot. You must bundle the data
together in the case of multiple scalar inputs.
10. Modify the block diagram to display both the average and the current
temperature measurement on the same waveform chart.
a. Modify the block diagram as shown in the following block diagram.
Customizing Charts
You can customize waveform charts to match your data display
requirements or to display more information. Features available for
waveform charts include: a plot legend, a scale legend, a graph palette,
a digital display, a scroll bar, and a buffer. By default, a waveform chart
displays the graph legend showing when you place it on a front panel.
Note The waveform chart size has a direct effect on the display of axis scales. Increase
the waveform chart size if you encounter problems customizing the axis.
12. Right-click the waveform chart and select Visible Items»Scale Legend
from the shortcut menu to show the scale legend. You can place the scale
legend anywhere on the front panel. The scale legend contains the
following components.
X Axis
Y Axis
the new text. Change Plot 1 to Current Temp in the same way. If the
text does not fit, resize the plot legend from the left corner of the plot
legend with the Positioning tool. The Positioning tool changes to a
frame corner when you can resize the plot legend.
Right-click the plot in the plot legend to set the plot line style and point
style. You also can color the plot background or traces by right-clicking
the plot legend and selecting Color from the shortcut menu.
15. Right-click the waveform chart and select Visible Items»Graph
Palette from the shortcut menu to show the graph palette. You can place
the graph palette anywhere on the front panel. The graph palette contains
the following options.
Zoom Subpalette
Note Often, modifying the axis text format requires more physical space than was
originally set aside for the axis. If you change the axis, the display might become larger
than the maximum size that the VI can correctly present.
D. For Loop
A For Loop repeats part of the block diagram code a predetermined number
of times. You select a For Loop on the Functions»Structures palette and
enclose the code you want to repeat in the For Loop boundary. A For Loop
is a resizable box with two terminals: the count terminal (an input terminal)
and the iteration terminal (an output terminal). The count terminal specifies
the number of times to execute the loop. The iteration terminal contains the
number of times the loop has executed.
The For Loop differs from the While Loop in that the For Loop executes a
predetermined number of times. A While Loop stops repeating the code it
encloses only if the value at the conditional terminal is met. The For Loop
is equivalent to the following pseudo-code:
For i = 0 to N-1
Execute Diagram Inside The Loop
The following example shows a For Loop that generates 100 random
numbers and displays the points on a waveform chart.
Numeric Conversion
Until now, all the numeric controls and indicators have been
double-precision floating-point numbers. LabVIEW, however, can represent
numeric data types as integers (byte, word, or long), floating-point numbers
(single, double, or extended precision), or complex numbers (single, double,
or extended precision). If you wire together two terminals that are of
different data types, LabVIEW converts one of the terminals to the same
representation as the other terminal. As a reminder, LabVIEW places a dot,
called a coercion dot, on the terminal where the conversion takes place.
For example, consider the For Loop count terminal. The terminal
representation is long integer. If you wire a double-precision floating-point
number to the count terminal, LabVIEW converts the number to a long
integer. Notice the gray dot in the count terminal of the first For Loop.
Gray Dot
Use a For Loop (N = 200) instead of a While Loop. Try to make the sweep
chart look like the following chart.
Additional Exercises
4-7 Using only a While Loop, build a combination For Loop/While
Challenge
Loop that stops either when it reaches a user-specified number of
iterations, specified on a front panel control, or when a user pushes
a stop button.
Save the VI and name it Combo While-For Loop.vi.
4-9 Modify the VI you created in Exercise 4-8 to display the maximum
and minimum values of the temperature trace.
Tip You must use shift registers and two Max & Min functions located on the
Functions»Comparison palette.
Notes
Notes
Introduction
This lesson describes how to use LabVIEW arrays, display data in
waveform and XY graphs, and use clusters.
A. Arrays
An array is a collection of data elements that are all the same type. An array
has one or more dimensions and up to 231 elements per dimension, memory
permitting. Arrays in LabVIEW can be of any type. However, you cannot
have an array of arrays, charts, or graphs. Access each array element by its
index. The index is in the range 0 to N-1, where N is the number of elements
in the array. The one-dimensional (1D) array shown below illustrates this
structure. Notice that the first element has index 0, the second element has
index 1, and so on.
index 0 1 2 3 4 5 6 7 8 9
10-element array 1.2 3.2 8.2 8.0 4.8 5.1 6.0 1.0 2.5 1.7
Step 1
Select an empty array shell from the Controls»Array & Cluster palette.
Step 2
To create an array, drag a data object into the array shell.
Note Remember that you must assign a data object to the empty array shell before using
the array on the block diagram. If you do not assign a data object, the array terminal will
appear black with an empty bracket.
Two-Dimensional Arrays
A two-dimensional (2D) array requires two indexes—a row index and a
column index, both of which are zero based—to locate an element. The
example below is an N-row by M-column array, where N=5 and M=7.
0 1 2 3 4 5 6
0
1
2
3
4
Row index
Column index
Step 1
Select an empty Array Constant shell from the Functions»Array palette.
Step 2
To create an array, drag a data object into the array shell. Different data
objects include numeric, Boolean, string, or cluster constants from the
Functions palette.
1D Array
0 1 2 3 4 5
If you need the last array value passed to the tunnel out of a loop without
creating an array, disable auto-indexing by right-clicking the tunnel (the
black square on the border) and selecting Disable Indexing from the
shortcut menu. In the illustration below, auto-indexing is disabled, and only
the last value returned from the Random Number (0-1) function passes out
of the loop. Notice that the wire remains the same size after it leaves the loop
and that the tunnel is solid.
Auto-Indexing Disabled
Note Because For Loops are often used to process arrays, LabVIEW enables
auto-indexing by default when you wire an array into or out of For Loops. By default,
LabVIEW does not enable auto-indexing for While Loops. You must right-click the
While Loop tunnel and select Enable Indexing from the shortcut menu.
1D Array 2D Array
For Loop
count is
set to 10,
not 100.
Array Size = 10
C. Array Functions
LabVIEW has many functions to manipulate arrays, available on the
Functions»Array palette. Some common functions are discussed below.
Array Size returns the number of elements in the input array. If the input
array is N-dimensional, the output size is an array of N elements. Each
element records the number of elements in each dimension.
The VI below uses the Array Subset function to return a portion of an array
starting at index and containing length elements.
Index Array accesses an element of an array. The VI below uses the Index
Array function to access the third element of an array. Notice that the third
element’s index is 2 because the index starts at zero; that is, the first element
has index 0.
In the previous example, the Index Array function extracts a scalar element
from an array. You also can use this function to slice off a row or column
of a 2D array to create a subarray of the original. To do this, wire a 2D array
to the input of the Index Array function. Two index terminals are now
available. The top index terminal specifies the row, and the second terminal
specifies the column. You can wire inputs to both index terminals to index a
single element, or you can wire the row or the column terminal to extract a
row or column of data. The VI below indexes the second row from a 2D
array.
D. Polymorphism
The LabVIEW numeric functions are polymorphic. This means that the
inputs to these functions can be different data structures—scalars and
arrays. For example, you can add a scalar to an array or add two arrays
together. The example below shows some of the polymorphic combinations
of the Add function.
Combination Result
In the first combination, the result is a scalar. In the second combination, the
scalar is added to each element of the array. In the third combination, each
element of one array is added to the corresponding element of the other
array. In the fourth combination, the result is calculated like the third
combination, but because one array is smaller than the other, the resulting
array is the size of the smaller input array.
In the following example, each iteration of the For Loop generates one
random number stored in the array created at the border of the loop. After
the loop finishes execution, the Multiply function multiplies each element
in the array by the scaling factor. The front panel indicator then displays the
array.
Front Panel
1. Open a new VI and build the front panel shown below.
Block Diagram
E. Graphs
A graph indicator is a 2D display of one or more data arrays called plots.
LabVIEW features two types of graphs, XY graphs and waveform graphs.
Both types look identical on the front panel of your VI. An example of a
graph is shown below.
Plot Legend
(Point and
Line Styles)
Graph Palette
Scale Legend
1D array
You can bundle data consisting of the initial X value, the delta X value, and
a data array to the waveform graph. With this feature, you have the
flexibility to change the timebase for the array. Notice that the graph icon
changes, as shown below.
1D Array
2D array
1D array
The example above assumes the initial X value is 0 and the delta X value is
1 for both arrays. In the following multiple-plot graph example, the initial X
value and a delta X value for each array is specified. These X parameters do
not need to be the same for both sets of data.
XY Graphs
The XY Graph, available on the Controls»Graph palette, is a
general-purpose Cartesian graphing object ideal for plotting multivalued
functions such as circular shapes or waveforms with a varying timebase.
Build a VI that generates and plots an array in a waveform graph and modify
the VI to graph multiple plots.
Front Panel
1. Open a new VI and build the front panel shown below. Be sure to modify
the controls and indicators as shown.
Block Diagram
3. Wire the waveform array directly to the waveform graph terminal. Each
iteration of the For Loop will generate a temperature value and store it
in an array at the loop border (tunnel).
4. Save the VI. Name it Graph Waveform Array.vi.
5. Return to the front panel and run the VI. The VI plots the auto-indexed
waveform array on the waveform graph.
6. You can view any element in the Waveform Array on the front panel by
entering the index of that element in the index display. If you enter a
number greater than the array size, the display dims.
To view more than one element at a time, resize the array indicator. Place
the Positioning tool on the lower-right corner of the array until the tool
Positioning tool
appears as shown at left and drag. The indicator now displays several
elements in an ascending index order, beginning with the element
Positioning tool corresponding to the specified index, as shown below.
over the corner
of an array
Index 9 10 11 12 13
In the previous block diagram, you used the default value of the initial X and
delta X value for the waveform. There are often cases where the initial X and
delta X value will be a specific value. In these instances, you can use the
Bundle function to specify an initial and delta X value for a waveform array.
7. Return to the block diagram. Delete the wire between the waveform
array and waveform graph. Finish wiring the block diagram as shown
above.
Bundle function, available on the Functions»Cluster
palette—Assembles the plot components into a single cluster in this
exercise. The components include the initial X value (10), the delta X
value (1.5), and the Y array (waveform data). Use the Positioning tool to
resize the function by dragging one of the corners.
∆X You can draw the delta by first typing “DX” for the label of the constant.
Select the D using the Labeling tool and then select the Symbol font from
Labeling tool the Font Ring. The letter D then converts to the delta symbol.
After the loop finishes execution, the Bundle function bundles the initial
value of X (Xo), the delta value of X, and the array for plotting on the
Font ring graph.
8. Return to the front panel. Save and run the VI. The VI plots the
auto-indexed waveform array on the waveform graph. The initial
X value is 10 and the delta X value is 1.5.
9. Change the delta X value to 0.5 and the initial X value to 20.
Notice that the graph now displays the same 100 points of data with a
starting value of 20 and a delta X of 0.5 for each point (see the X axis).
In a timed test, this graph would correspond to 50 seconds worth of data
starting at 20 seconds. Experiment with several combinations for the
initial and delta X values.
10. Graphs contain scale legends and graph palettes just as charts do. View
the graph palette by right-clicking the waveform graph and selecting
Visible Items»Graph Palette from the shortcut menu. You can use the
zooming features on the palette to see the data on the graph in more
detail. View the scale legend by right-clicking the graph and selecting
Visible Items»Scale Legend from the shortcut menu.
11. With LabVIEW, you can specify a time and date format for numerics
and Graphs. Right-click the waveform graph and select X Scale»
Formatting from the shortcut menu. Change the formatting options as
shown below.
Note The Xo and ∆X parameters in the X Scale Formatting screen interact with the Xo
and ∆X from the Bundle function. Change the bundle’s Xo and ∆X to 0 and 1,
respectively, to match the example. For example:
Change the starting and delta scale times in just one location—either the Bundle function
or X Scale»Formatting.
Note If the x-axis text is not clearly visible, shrink the inner display (black area) of the
graph with the Positioning tool to increase the border area around the graph.
Multiple-Plot Graphs
You can create multiple-plot waveform graphs by building a 2D array of the
data type normally passed to a single-plot graph.
Y axis single
fit button Zoom by X Rectangle
Zooming Subpalette
17. Scroll through your data using the Pan feature. Click the Panning button
once, available on the Controls»Graph palette. Notice that the mouse
Panning button
cursor changes to a hand. Now click and drag inside the graph display.
As long as you hold down the mouse button, you can drag the display.
Restore the display to its original position by clicking the X axis and
Y axis single fit buttons again. Finally, return the mouse to standard
Return to
standard mode by clicking the Return to standard mode button.
mode button
18. Save and close the Graph Waveform Array VI.
You will use this VI later, so be sure to save it as the instructions below
describe.
Front Panel
1. Open a new VI and build the front panel shown below.
Block Diagram
2. Build the block diagram shown below. Refer to the following
instructions.
You can display more than one plot on a graph. This feature not only
saves space on the front panel, it is also an effective means of making
comparisons between plots. XY and waveform graphs automatically
adapt to multiple plots.
Thermometer VI, available on the Functions»User Libraries»Basics 1
Course palette—Returns one temperature measurement.
Wait Until Next ms Multiple function, available on the Functions»Time
& Dialog palette—Causes the For Loop to execute every 0.25 s
(250 ms) in this exercise.
Array Max & Min function, available on the Functions»Array
palette—Returns the maximum and minimum temperature measured
during the acquisition in this exercise.
Mean VI, available on the Functions»Mathematics»Probability and
Statistics palette—Returns the average of the temperature
measurements in this exercise.
Bundle function, available on the Functions»Cluster
palette—Assembles the plot components into a single cluster in this
exercise. The components include the initial X value (0), the delta X
value (0.25), and the Y array (temperature data). Use the Positioning
tool to resize the function by dragging one of the corners.
General Polynomial Fit VI, available on the
Functions»Mathematics»Curve Fitting palette—Returns an array
that is a polynomial fit to the temperature array in this exercise. This
exercise uses five as the polynomial order. The General Polynomial Fit
VI determines the best fit for the points in the temperature array.
b. Right-click the Fitted plot display in the Legend of the Temp Graph
and select the second choice from Bar Plots in the plot legend
shortcut menu.
Front Panel
Block Diagram
The Context Help window shows you what data types to wire to the
Waveform Graph, how to specify point spacing with the Bundle function,
and which example to use when you want to see the different ways
you can use a Waveform Graph. These examples are located in the
Help»Examples»Fundamentals»Graphs and Charts category. The
Context Help window shows similar information for XY Graphs and
Waveform Charts.
Note The waveform data type mentioned in the Context Help window is described in
Lesson 8, Data Acquisition and Waveforms.
F. Clusters
You used the Bundle function with charts and graphs to group information
for the plots. The Bundle function creates a data type in LabVIEW known
as a cluster. A cluster is a data structure that combines one or more data
components into a new data type. Unlike an array, where all the data
components are exactly the same, the components that form a cluster may
contain different data types such as Boolean, string, and numeric data types.
A cluster is analogous to a record in Pascal or a struct in C.
On the block diagram, a wire that carries the data stored in a cluster may be
thought of as a bundle of smaller wires, much like a telephone cable. Each
wire in the cable represents a different component of the cluster. Because a
cluster constitutes only one wire in the block diagram, clusters reduce wire
clutter and the number of connector terminals that subVIs need.
Unbundle the cluster in the diagram to access its components. You may
think of unbundling a cluster as unwrapping a telephone cable and accessing
the individual wires within the cable.
You can place any objects inside the cluster that you normally place on the
front panel. You can deposit objects directly inside the cluster by dragging
an object into a cluster. Objects inside a cluster must be all controls or all
indicators; you cannot combine both controls and indicators inside the same
cluster. The cluster assumes the data direction (control or indicator) of the
first object you place inside the cluster. For example, if you drop an indicator
into a cluster containing controls, the indicator changes to a control.
A cluster of four controls is shown below:
If you have a cluster control or indicator on the front panel and want to
create a cluster constant containing the same components on the block
diagram, you can either drag that cluster from the front panel to the block
diagram or select Create»Constant from the shortcut menu.
Cluster Order
When LabVIEW manipulates clusters of data, the data types of the
individual components within the cluster and the order of the components in
the cluster are both important. Cluster components have a logical order
unrelated to their position within the shell. The first object placed in the
cluster shell is component 0, the second is component 1, and so on. If you
delete a component, the order adjusts automatically.
You can change the order of the objects within the cluster by right-clicking
the cluster border and selecting Reorder Controls in Cluster from the
shortcut menu. A new set of buttons replaces the toolbar, and the cluster
appearance changes as shown. The white box on each component shows its
current place in the cluster order. The black box shows a component’s new
place in the order.
Keep Changes
Revert to Original
Cluster Order
Cursor
Current Order
New Order
To set a cluster component to a particular index in the cluster order, first type
the desired order number into the Click to set to field. Then click the desired
component. You will notice that the component’s cluster order index
changes. You will also notice that the cluster order indices of the other
components adjust automatically. Save your changes by clicking the OK
button in the palette. You can revert to the original settings by clicking the
Revert to Original button. You use this technique to set the cluster order for
constants on both the front panel and block diagram.
The example shown below shows the importance of cluster order. The front
panel contains two simple clusters. In the first cluster, component 0 is a
numeric control and component 1 is a string control. In the second cluster,
component 0 is a numeric indicator and component 1 is a string indicator.
The cluster control correctly wires to the cluster indicator as shown.
However, if you change the cluster order of the indicator so the string
indicator is component 0 and the numeric is component 1, the wire
connecting the cluster control to the cluster indicator is broken. If you try to
run the VI, you get an error message stating that there is a type conflict
because the data types do not match.
You can use clusters to group related controls together. One cluster control
uses one terminal on the connector pane, but that cluster can contain several
controls. Similarly, one terminal assigned to a cluster indicator can pass
several outputs from the subVI. Because your subVI uses clusters
containing several items each, you can use fewer, and therefore larger,
terminals on the connector pane. This makes for cleaner wiring on the block
diagram, as shown below.
G. Cluster Functions
LabVIEW uses several functions to manipulate clusters. The Bundle and
Bundle by Name functions assemble and modify clusters, and the Unbundle
and Unbundle by Name functions disassemble clusters.
Assembling Clusters
The Bundle function, available on the Functions»Cluster palette,
assembles individual components into a single cluster or replaces
components within an existing cluster. The topmost component wired to the
Bundle function is component 0 in the cluster order, the second component
is component 1, and so on. To increase the number of inputs, resize the
function with the Positioning tool or right-click the icon and select Add
Input from the shortcut menu. If the cluster of n components terminal is
wired, the number of input terminals to the Bundle function must match the
number of items in the input cluster.
When you use the cluster of n components terminal, you do not need to
wire data to every input terminal of the function. Instead, you can wire data
only to the items you want to change. For example, consider the cluster
shown below, which contains three controls—a string labeled Command,
a numeric labeled Function, and a Boolean labeled Trigger.
You can use the Bundle function to change the string value by wiring the
components as shown below. You must know the cluster order to do this
correctly.
If you need to modify both Command and Function, you can resize the
Bundle by Name function as shown below.
Use the Bundle by Name function when working with data structures that
might change during the development process. If you add a new component
to the cluster or modify its order, you do not need to rewire the Bundle by
Name function on the diagram because the names still are valid.
Disassembling Clusters
The Unbundle function, available on the Functions»Cluster palette, splits
a cluster into each of its individual components. The components are
arranged from top to bottom according to the cluster order of the input
cluster. You can increase the number of outputs by resizing the function with
the Positioning tool or by using the shortcut menu. The number of output
terminals for this function must match the number of components on the
Positioning tool
input cluster.
For example, if you use the Unbundle function with the cluster shown
below, it has four output terminals. These four terminals correspond to the
four controls inside the cluster. Notice that you need to know the cluster
order so that you can associate the correct Boolean (TF) terminal of the
unbundled cluster with the corresponding switch inside the cluster. In this
example, the components are ordered from top to bottom starting with
component 0. Notice that when you use the Unbundle by Name function,
you can have an arbitrary number of terminals and access specific
components by name in any order.
As shown below, you can also create the Bundle, Bundle by Name,
Unbundle, and Unbundle by Name functions by right-clicking a cluster
terminal in the block diagram and selecting Cluster Tools from the shortcut
menu. The Bundle and Unbundle functions will automatically contain the
correct number of terminals. The Bundle by Name and Unbundle by Name
functions will appear with the first component in the cluster.
Cluster Arithmetic
Front Panel
1. Open a new VI and build the front panel shown below.
a. Place a round LED, digital indicator, and Stop button on the front
panel.
b. Place a cluster shell on the front panel by right-clicking and selecting
Controls»Array & Cluster»Cluster. Enlarge the shell by dragging
one of the corners with the Positioning tool.
c. Place the four control objects inside the cluster.
d. Repeat the process for the Modified Cluster. The cluster becomes an
indicator when you place a digital indictor inside it. Keep in mind
that in this case, the toggle switch inside Modified Cluster is an
indicator and not a control. That is, the toggle switch becomes an
indicator because the cluster itself is an indicator.
Tip To create Modified Cluster, you can duplicate Cluster, relabel it, and change it to an
indicator. To duplicate Cluster, select it using the Positioning tool, select Edit»Copy,
click to a new area in the front panel, and select Edit»Paste.
e. Repeat the process for the Small Cluster. Place the two indicators
inside the shell.
f. Verify the cluster order of the Small Cluster and Cluster. The
Modified Cluster should have the same order as the Cluster.
Right-click the boundary of each cluster and select Reorder
Controls in Cluster from the shortcut menu. Complete the cluster
orders as shown below.
Block Diagram
Front Panel
1. Open the Cluster Scaling VI. The front panel is already built for you.
Finish building the block diagram.
Block Diagram
2. Build the block diagram shown above. Make sure you apply the correct
scale factors to each component in the raw data cluster.
3. Save and run the VI. Test several alternatives to ensure that the VI works
properly.
4. Close the VI when you are finished.
Additional Exercises
5-7 Build a VI that reverses the order of an array containing 100 random
numbers. For example, array[0] becomes array[99], array[1]
becomes array[98], and so on.
Hint: Use the Reverse 1D Array function, available on the
Functions»Array palette, to reverse the array order.
Name the VI Reverse Random Array.vi.
5-10 Build a VI that simulates the roll of a die with possible values 1–6
Challenge and keeps track of the number of times that the die rolls each value.
The input is the number of times to roll the die, and the outputs
include the number of times the die falls on each possible value. Do
this using only one shift register. Name the VI Die Roller.vi.
Notes
Introduction
This lesson discusses the two other LabVIEW structures: the Case structure
and the Sequence structure. This lesson also introduces the Formula Node.
A. Case Structure
You place the Case structure on the block diagram by selecting it from the
Structures subpalette of the Functions palette. You can either enclose
nodes with the Case structure or drag nodes inside the structure.
Note You must define the output tunnel for each case. When you create an output tunnel
in one case, tunnels appear at the same position in the other cases. Unwired tunnels look
like white squares. Be sure to wire to the output tunnel for each unwired case, clicking
on the tunnel itself each time. You also can wire constants or controls to unwired cases by
right-clicking the white square and selecting Create»Constant or Create»Control.
When you place a Case structure on a block diagram, you type the selector
values directly into the Case structure selector label. You can also edit the
selector values using the labeling tool. You can specify a single value, lists,
or ranges of values that select the case. To indicate a list, separate the values
by commas, such as -1, 0, 5, 10. A range is specified as 10..20,
meaning all numbers from 10 to 20 inclusively. You can also use open-ended
ranges such as ..0 (all numbers less than or equal to 0), or 100.. (all
numbers greater than or equal to 100). Lists and ranges can be combined
such as ..5, 7..10, 12, 13, 14. When you type in a selector that
Note If you type in a selector value that is not the same type as the object wired to the
selector terminal, the value displays in red and your VI cannot run. Also, because of the
possible round-off error inherent in floating-point arithmetic, using floating-point
numbers in a case selector is discouraged. If you wire a floating point type to the case,
the type is converted to an integer. If you try to type in a floating point value into the Case
selector, it will display in red.
The shortcut menu options for the Case structure are shown above. You can
add, duplicate, or remove cases. You can also rearrange the cases to sort
them or otherwise put them into a different order. The Make This The
Default Case option in the menu specifies a particular case to execute if the
selector value is not listed in the Case structure. The word “Default” is listed
in the selector value at the top of the case structure. You must specify a
default case for a Case structure if it does not contain selectors for every
possible selector value (numeric and string cases).
You will build a VI that checks a number to see if it is positive. If it is, the
VI calculates the square root of the number; otherwise, the VI returns a
message.
Front Panel
Block Diagram
Note If both cases do not have data wired to the tunnel, the tunnel remains white. Ensure
that a value is wired to the output tunnel from each case.
One Button Dialog function (Time & Dialog palette). In this exercise,
this function displays a dialog box that contains the message
Error...Negative Number.
String Constant (String palette). Enter text inside the box with the
Operating tool. (You will study strings in detail in Lesson 7, Strings and
File I/O.)
In this exercise, the VI will execute either the True case or the False case.
If the number is greater than or equal to zero, the VI will execute the
True case. The True case returns the square root of the number. The
False case outputs a –99999.0 and displays a dialog box with the
message Error...Negative Number.
6. Save the VI. Name it Square Root.vi.
7. Return to the front panel and run the VI. Try a number greater than zero
and one less than zero.
8. Close the VI.
You will use this VI later, so be sure to save it as the instructions below
describe.
Block Diagram
Note On the Macintosh, you must provide values for the Frequency, Duration, and
Intensity inputs to the Beep VI.
Notice that there are no icons in the False case of the Case structure. If
the temperature that the Thermometer VI returns is greater than the set
limit, the LED turns on, the VI executes the True case, and a beep
sounds. If the temperature is less than the set limit, the LED turns off,
the VI executes the False case, and there is no beep.
5. Save the VI. Return to the front panel and enter 80 in the High Limit
control. Run the VI.
Place your finger on the temperature sensor. When the temperature
exceeds 80°, the LED will turn on and a beep will sound.
6. Close the VI.
End of Exercise 6-2
B. Sequence Structure
You place the Sequence structure on the block diagram by selecting it from
the Structures subpalette of the Functions palette. You can either enclose
nodes with the Sequence structure or drag nodes inside the structure.
The Sequence structure, which looks like a frame of film, executes diagrams
sequentially. In conventional text-based languages, the program statements
execute in the order in which they appear. In data flow programming, a node
executes when data is available at all of the node inputs, but sometimes it
is necessary to execute one node before another. The Sequence structure is
LabVIEW’s way of controlling the order in which nodes execute. The
diagram to be executed first is placed inside the border of Frame 0 (0..x), the
diagram to be executed second is placed inside the border of Frame 1(0..x),
and so on. (0..x) represents the range of frames in the Sequence structure. As
with the Case structure, only one frame is visible at a time.
Sequence Locals
Sequence locals are variables that pass data between frames of a Sequence
structure. You create sequence locals on the border of a frame. The data
wired to a sequence local is then available in subsequent frames. The data,
however, is not available in frames preceding the frame in which you created
the sequence local.
You will build a VI that computes the time it takes to generate a random
number that matches a number you specify. This VI uses the Auto Match VI
you built in Exercise 4-3.
Front Panel
Free Label
Block Diagram
First, the Tick Count (ms) function reads the operating system’s
software clock and returns its value in milliseconds. In Frame 0, the VI
executes the While Loop as long as the number specified does not match
the number that the Random Number (0–1) function returns. In Frame
1, the Tick Count (ms) function again reads the operating system’s
software timer. The VI then subtracts the new value from the initial time
read and returns the elapsed time in seconds to the front panel.
8. Save the VI and return to the front panel.
9. Enter a number inside the Number to Match control. Run the VI.
(Remember that you can use the <Ctrl | ◊ | M | -R> shortcut keys to
run the VI.) Win Sun H-P Mac
10. If Time to Match always reads 0.000, your VI may be running too
quickly. To slow the VI, either run with Execution Highlighting enabled
or increase the value on the diagram that is multiplied by the random
number to a very large value such as 100,000.
11. Close the VI when you are finished.
C. Formula Node
You place the Formula Node on the block diagram by selecting it from the
Structures subpalette of the Functions palette. You can enter equations into
the formula node by using the Labeling tool.
The Formula Node is a resizable box that you use to enter algebraic
formulas directly into the block diagram. This feature is extremely useful
when the function equation has many variables or is otherwise complicated.
For example, consider the equation y = x2 + x + 1. If you implement this
equation using regular LabVIEW arithmetic functions, the block diagram
looks like the one shown below.
You can implement the same equation using a Formula Node, as shown
below.
Note semicolon
With the Formula Node, you can directly enter a multivariable equation, or
formulas, instead of creating block diagram subsections. You create the
input and output terminals of the Formula Node by right-clicking on the
border of the node and choosing Add Input (Add Output) from the
shortcut menu. You enter the formula or formulas inside the box. Each
formula statement must terminate with a semicolon (;).
The Formula Node has many features and can perform many different
operations. Use the LabVIEW Help (Help»Contents and Index) for a
complete listing of functions, operations, and syntax for the Formula Node.
The following example shows how you can perform conditional branching
inside a Formula Node. Consider the following code fragment that
computes the square root of x if x is positive, and assigns the result to y.
If x is negative, the code assigns –99 to y.
if (x >= 0) then
y = sqrt(x)
else
y = -99
end if
You can implement the code fragment using a Formula Node, as shown
below.
Conditional Operator
False Condition
Note The Formula Node can implement more than just equations. Refer to the
LabVIEW Help for more information.
You will build a VI that uses the Formula Node to evaluate a complex
mathematical expression and graphs the results.
Front Panel
Block Diagram
Broken wire—
broken Run arrow
gives the following
error message:
"Sequence Tunnel:
multiple assignment
to tunnel."
You cannot use the “status” indicator as shown above because according to
the data flow paradigm, nothing leaves a node until the node finishes
running. Therefore, the sequence structure will not pass data outside its
borders until frames have completed. You can use Local variables to solve
this problem, but a better solution would be to replace the Sequence
structure with a loop and a Case structure.
Additional Exercises
6-5 Build a VI that uses the Formula Node to calculate the following
equations.
y1 = x3 + x2 + 5
y2 = m * x + b
Use only one Formula Node for both equations. Remember to put a
semicolon (;) after each equation in the node. Name the VI
Equations.vi.
6-6 Build a VI that functions like a calculator. The front panel should
have digital controls to input two numbers and a digital 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 be performed. Name the VI
Calculator.vi.
6-7 Modify the Square Root Exercise (Exercise 6-1) so that the VI
performs all calculations and condition checking using the Formula
Node. Name the VI Square Root 2.vi.
6-8 Build a subVI that has two inputs and one output. The inputs are
Challenge “Threshold” and “Input Array,” and the output is “Output Array.”
Output Array will contain values from Input Array that are greater
than Threshold. Save your subVI as Array Over Threshold.vi.
Test your subVI by creating another VI that generates an array of
random numbers between 0 and 1, and uses the Array Over
Threshold subVI to output an array with the values above 0.5. Save
the test VI as Using Array Over Threshold.vi.
Notes
Introduction
This lesson introduces LabVIEW strings and file I/O operations.
A. Strings
A string is a sequence of displayable or nondisplayable characters. Often,
you use strings for more than simple text (for example, ASCII) messages.
For example, in instrument control, you pass numeric data as character
strings. You then convert these strings to numbers. In many cases, storing
numeric data to disk also requires strings, which means that you first must
convert numbers to strings before writing the numbers to a file on disk.
You also can configure string controls and indicators for different types of
display. For example, you can choose password display by enabling the
Password Display option from the string shortcut menu. With this option
selected, only asterisks appear in the string front panel display. On the block
diagram, the string data reflects what was typed.
String controls and indicators also can display and accept characters that are
usually nondisplayable, such as backspaces, carriage returns, tabs, and so
on. To display these characters, choose ‘\’ Codes Display from the string
shortcut menu.
After shifting the key focus, the display shows the spaces
the user enters and the New Line character at the end.
B. String Functions
LabVIEW has many functions to manipulate strings. These functions are
available from the Functions»String palette. Some common functions are
discussed below.
String Length
Concatenate Strings concatenates all input strings and arrays of strings into
a single output string.
The function appears as shown at left when you place it in the block
diagram. You can resize the function with the Positioning tool to increase
Concatenate
Strings function the number of inputs.
when placed in
block diagram
Match Pattern returns the matched substring. The function searches for the
regular expression in string beginning at the offset, and if it finds a match,
splits the string into three substrings. If no match is found, the match
substring is empty and the offset past match is –1.
Format Into String converts any format argument (for example, numeric)
to the specified formatted resulting string. You can expand the function to
have multiple values converted to a single string simultaneously.
The function can format the output string with the initial string and
argument(s) based on the format string.
In the example below, the function converts the floating-point number 1.28
to the 6-byte string “1.2800.”
Both Format Into String and Scan From String have an Edit Scan String
dialog box to create the format string. The format string specifies the format,
precision, data type, and width of the converted value. You can access the
Edit Scan String dialog box by right-clicking the node and choosing Edit
Format String or simply double-clicking the function. After you configure
the format string and select Create String, the dialog box creates the string
constant and wires it to the format string input for you. Refer to the
following example of using the Edit Scan String to create the format string
for a floating-point number, precision of 2 digits, width of 8 digits, and
padded with spaces.
You will build a VI that converts a number to a string and concatenates the
string to other strings to form a single output string. The VI also determines
the output string length. The VI also matches a pattern in a string and
converts the remaining string to a number.
You will use this VI later, so be sure to save it as the instructions below
describe.
Front Panel
Block Diagram
C. File I/O
File input and output (I/O) operations store information to and retrieve
information from files on disk. LabVIEW has many built-in functions and
VIs to handle file I/O. All File I/O functions are in the Functions»File I/O
palette. These functions and VIs are organized into three levels of hierarchy:
• High-Level File VIs
• Intermediate File Functions
• Advanced File Functions
In this lesson, we will cover the intermediate functions in detail for better
understanding of basic File I/O operations and then will continue the
discussion on high-level File VIs.
As you become more familiar with LabVIEW, you will find that the
intermediate File functions handle most of your file I/O needs.
This section discusses the Open/Create/Replace File VI, the Read File
function, the Write File function, and the Close File function. It also
discusses the Simple Error Handler VI.
Note Use the LabVIEW Help, which you can access by selecting Help»Contents and
Index to demonstrate and learn more about the details of these functions.
Open/Create/Replace File
Read File reads count bytes of data from the file that refnum specifies and
returns it in data. We will discuss refnums in the next section. Reading
begins at the location specified by the pos mode and pos offset.
Read File
Write File writes to the file that refnum specifies. Writing begins at the
location specified by the pos offset and pos mode.
Write File
Close File closes the file associated with refnum. This function closes files
of all data types.
Close File
Checking Errors
An advantage of using the Intermediate File functions is that you can
develop your own error handling routines. Each Intermediate function has
an error in input and an error out output. Both of these are clusters
containing status, code, and source, as shown below.
When the functions execute, they first check the error in cluster to see if an
error has occurred in any preceding VI or function. If the status is True
an error has occurred, and the VIs or functions do not continue execution.
They simply pass the error in information to their error out cluster for the
next node. If the status is False, an error has not occured, and the nodes
continue with the operation and set their error out cluster to reflect whether
an error occurred during their execution.
Simple Error Handler (Time & Dialog subpalette) checks for errors in the
file operations and displays a dialog box if an error occurs.
The following example shows the steps for writing string data to an existing
file while programmatically wiring the filename and pathname:
The following example shows the steps for reading the entire contents of a
string file using an interactive file dialog box to select the file:
You will build a VI that will concatenate a message string, a number, and
unit string to a file. You will use the subVI created in Exercise 7-1, Build
String.vi. In the next exercise, you will build a VI to read the file and
display its contents.
Front Panel
Block Diagram
1. Build the diagram shown above. The functions are described below.
Build String VI (Select a VI palette). The subVI concatenates the three
input strings to one combined string.
Open/Create/Replace File VI (File I/O palette). This VI displays an
interactive file dialog box to open or create a file.
Close File function (File I/O palette). This function closes the file.
Simple Error Handler VI (Time & Dialog palette). This VI checks the
error cluster and displays a dialog box if an error occurred.
You will build a VI that reads the file created in the previous exercise and
displays the information read in a string indicator if the user’s password
matches the specified password from the Build String VI.
Front Panel
Block Diagram
Simple Error Handler VI (Time & Dialog palette). This VI checks the
error cluster and displays a dialog box if an error occurred.
2. Save the VI. Name it File Reader.vi.
3. Run the VI. A dialog box appears. Find the file demofile.txt and
click Open or OK. The String Read from File indicator should display
the file contents.
Hint: Use the Match Pattern function to search for the first numeric
character.
The Format Into File function combines the functionality of the Format Into
String function and the Write File function where it formats the data as
specified and writes that data directly to a file. You can either wire a file
refnum or file path to the input file terminal, or you can leave this input
unwired and a dialog box will open and query you for the data file. Also
notice that there are error in and error out terminals you can wire to track
error conditions just like the other File I/O functions you have used.
The block diagram below creates the text file shown below it. The file is first
opened with the Open/Create/Replace File VI, then a For Loop executes five
times. The Format Into File function converts the iteration count and the
random number to strings and places the tab and end of line characters in the
correct positions to create two columns and one row in spreadsheet format.
After the loop completes five iterations, the file is closed and the error
condition is checked.
0 0.4258 ¶ Tab
1 0.3073 ¶ ¶ End of Line
2 0.9453 ¶
3 0.9640 ¶
4 0.9517 ¶
Note The End of Line constant (String palette) behaves differently depending on the
platform. You should use this constant to ensure portability of your VIs between
platforms.
End of Line Windows The End of Line constant inserts a carriage return character
constant and a line feed character.
You will modify the Temperature Control VI to save the time and current
temperature to a data file. You will use this VI later, so be sure to save it as
the instructions below describe.
Front Panel
Block Diagram
Format Into File function (File I/O palette). This function converts the
temperature measurement (a number) to a string and builds and writes
to file the following formatted data string:
Time String (tab) Temperature String (end of line).
Resize the function to have four argument terminals.
Simple Error Handler VI (Time & Dialog palette). This VI checks the
error cluster and displays a dialog box if an error occurred.
Windows
5. Start the WordPad or NotePad application or another word processor or
a spreadsheet. Find and open the file temp.txt.
UNIX
5. Run the Text Editor application. Load the file temp.txt.
Macintosh
5. Switch to the Finder and launch TeachText or another word processor or
a spreadsheet. Find and open the file temp.txt.
6. After you load the file into the word processor or spreadsheet, notice that
the time appears in the first column and the temperature data appears in
the second column. Quit your word processor or spreadsheet and return
to LabVIEW.
Note Use the Help»Contents and Index to demonstrate/learn more about these
functions.
Read From Spreadsheet File reads a specified number of lines or rows from
a numeric text file beginning at a specified character offset and converts the
data to a 2D single-precision array of numbers. The VI opens the file before
reading to the file and closes it afterwards. You can use this VI to read a
spreadsheet file saved in text format.
Read Lines From File reads a specified number of lines from an ASCII
format file beginning at a specified character offset. The VI opens the file
before reading the file and closes it afterwards.
Tables
A table is a front panel control used to pass or display data in tabular form.
The data type of a table is a 2D array of strings; tables can be of any size,
memory permitting. The table shown below has three rows and seven
columns. The optional row and column headers for the table also are shown.
Column
Row headers
headers
A table control appears on the front panel. You define cells within the table
by clicking inside a cell with either the Operating tool or the Labeling tool.
You can now type text within the selected cell.
The example uses a property node to write values in the row and column
header. Property nodes are discussed in the LabVIEW Basics II course.
In the previous exercise, you formatted the string so that tabs separated the
columns and end of lines separated the rows. In this exercise, you will
examine a VI that saves numeric arrays to a file in a format you can access
with a spreadsheet.
Front Panel
Block Diagram
Sine Array
..
.
Cosine Array
..
.
.. .. ..
. . .
Note This example had only three arrays stored in the file. To include more arrays,
you can increase the number of inputs to the Build Array function.
Windows
3. Open any word processing or spreadsheet application such as Notepad
or WordPad.
4. Find and open the file wave.txt and observe that the sine waveform
data appears in the first column, the random waveform data appears in
the second column, and the cosine waveform data appears in the third
column.
5. Exit the word processor and return to LabVIEW.
UNIX
3. Run the Text Editor application.
4. Find and open the file wave.txt and observe that the sine waveform
data appears in the first column, the random waveform data appears in
the second column, and the cosine waveform data appears in the third
column.
5. Exit the Text Editor and return to LabVIEW.
Macintosh
3. Switch to the Finder and launch TeachText (or any word processor or
spreadsheet) by double-clicking on its icon.
4. Find and open the file wave.txt and observe that the sine waveform
data appears in the first column, the random waveform data appears in
the second column, and the cosine waveform data appears in the third
column.
5. Quit TeachText and return to LabVIEW.
Log your data as shown below in the example spreadsheet. Remember that
in a spreadsheet, tabs separate columns and end of lines separate rows.
Additional Exercises
7-7 Build a VI that generates a 2D array of 3 rows × 100 columns of
Challenge random numbers and writes the data transposed to a spreadsheet file.
The file should contain a header for each column, as shown below.
Use the high-level File VIs from the File I/O subpalette for this
exercise. Save the VI as More Spreadsheets.vi.
Hint: Use the Write Characters To File VI to write the header and
then the Write To Spreadsheet File VI to write the numerical data to
the same file.
Header
.
.
.
7-9 Modify the Temperature Logger VI from Exercise 7-4 so that the VI
does not create a new file each time you run the VI. The VI should
append the data to the end of the existing file, temp.dat, that the
Temperature Logger VI created earlier. Run the VI several times
and then use a word processor to confirm that the VI appended new
temperature readings. Save the VI as Temperature Logger
2.vi.
Hint: 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
file mark.
Notes
Introduction
This lesson introduces the use of plug-in data acquisition (DAQ) boards and
associated LabVIEW software.
d
ne
itio
al g o nd nals
gn in C Sig
Si ition
n d
Co
SCX
I-100
1
SCXI
1140
SCXI
1140
SCXI
1140
SCXI
1140
SCX
MAINFR
I
AME
-In d
ug ar
Pl Bo
r s A Q
u ce D
sd
an
Tr
e
ar
ftw
So
Option A
SCX
I-100
1
SCXI
1140
SCXI
1140
SCXI
1140
SCXI
1140
e
SCXI
SCX
MAINFR
I
ar
ftw
1140 AME
So
Data Acquisition
and Control Module
Option B
conditioning accessory must condition the signals before the plug-in DAQ
board converts them to digital information. Finally, software controls the
DAQ system—acquiring the raw data, analyzing the data, and presenting the
results.
The figure on the previous page shows two of the many options for a DAQ
system. In Option A, the plug-in DAQ board resides in the computer. This
computer can be a tower or desktop model or a laptop with PCMCIA slots.
In Option B, the DAQ board is external to the computer. With this approach,
you can build DAQ systems using computers without available plug-in slots,
such as some laptops. The computer and DAQ module communicate
through various buses, such as the parallel port, USB, or PCMCIA. These
types of systems are practical for remote data acquisition and control
applications.
Analog Input
When measuring analog signals with a DAQ board, you must consider the
following factors that affect the digitized signal quality: mode (single-ended
and differential inputs), resolution, range, sampling rate, accuracy, and
noise.
Single-ended inputs are all referenced to a common ground point. Use these
inputs when the input signals are high level (greater than 1 V), the leads
from the signal source to the analog input hardware are short (less than
15 ft.), and all input signals share a common ground reference. If the signals
do not meet these criteria, use differential inputs. With differential inputs,
each input can have its own reference. Differential inputs also reduce or
eliminate noise errors because the common-mode noise picked up by the
leads is canceled out.
Range refers to the minimum and maximum voltage levels that the ADC can
quantize. DAQ boards offer selectable ranges, typically 0 to 10 V or –10 to
10 V, so you can match the signal range to that of the ADC to take best
advantage of the resolution available to accurately measure the signal.
The range, resolution, and gain available on a DAQ board determine the
smallest detectable change in the input voltage. This change in voltage
represents 1 least significant bit (LSB) of the digital value and is often called
the code width. The smallest detectable change is calculated as:
For example, a 12-bit DAQ board with a 0 to 10 V input range and a gain of
1 detects a 2.4 mV change, while the same board with a –10 to 10 V input
range would detect only a change of 4.8 mV.
range 10 20
----------------------------------------
resolution
- = ---------------
12
- = 2.4 mV ---------------
- = 4.8mV
12
gain × 2 1×2 1×2
Adequately sampled
For example, if you average 100 points, the effect of the noise in the signal
is reduced by a factor of 10.
Windows
This section describes the setup for the PCI, PCMCIA, or ISA bus computer.
The LabVIEW Setup program copies the required files for LabVIEW DAQ
onto your computer. LabVIEW for Windows DAQ VIs access the National
Instruments standard NI-DAQ for Windows 32-bit dynamic link library
(DLL). The LabVIEW setup program installs the NI-DAQ DLL in the
WINDOWS\SYSTEM directory. NI-DAQ for Windows supports all National
Instruments DAQ boards and SCXI.
The nidaq32.dll file, the high-level interface to your board, is loaded into
the Windows\System directory. The nidaq32.dll file then interfaces
with the Windows Registry to obtain the configuration parameters defined
by Measurement & Automation Explorer. Because Measurement &
Automation Explorer is an integral part of DAQ, it is described in more
detail later in this section.
Windows Registry
DAQ Board
1: AT-MIO-64E-3
Notice that Measurement & Automation Explorer detected all the National
Instruments hardware including the GPIB board. Refer to Lesson 9,
Instrument Control, for more information about GPIB.
The board parameters that you can set using the configuration utility depend
on the board. Measurement & Automation Explorer saves the logical device
number and the configuration parameters in the Windows registry.
Macintosh
The LabVIEW installation program installs the NI-DAQ for Macintosh
software drivers necessary to communicate with National Instruments DAQ
boards. You use the NI-DAQ Configuration utility to configure your DAQ
board and accessories.
DAQ Board
When you install NI-DAQ for Macintosh, install version 4.9 if you have an
NB or a Lab Series board. Otherwise, install NI-DAQ version 6.0 or later for
the PCI and DAQCard boards.
You will open Measurement & Automation Explorer and examine the
configuration for the DAQ board in your machine. The test routines in
Measurement & Automation Explorer confirm operation of your board. You
will also configure three virtual channels to be used with the DAQ Signal
Accessory.
2. Open the Devices and Interfaces section. The window below shows
what Measurement & Automation Explorer looks like for a
PCI-MIO-16XE-50 and a PCI-GPIB.
Note You may have a different board installed and some of the options shown may be
different. Click the Show/Hide button in the top right corner of the Measurement &
Automation Explorer window to hide the online help and show the DAQ board
information.
This window contains several tabs. The first tab, System, reports the
system resources assigned to the board through the Windows registry.
Use the remaining tabs to configure the various analog input, output, and
accessory parameters for the DAQ board. Switch to these additional tabs
to view the different DAQ parameters that may be configured for this
board.
4. Switch back to the System tab in the configuration window and click the
Test Resources button. This tests the system resources assigned to the
board according to the Windows Device Manager. Your device should
pass this test, because it has been preconfigured.
6. The Test Panel dialog box allows you to test a specific board in several
different areas. The Analog Input tab tests the various analog input
channels on the DAQ board. Remember that Channel 0 is connected to
the temperature sensor on the DAQ Signal Accessory. Place your finger
on the sensor to see the voltage rise. You can also move the Noise switch
to On to see the signal change in this window.
In this window, you can set up either a single voltage or sine wave on
one of the DAQ board analog output channels. For this exercise, change
the Output Mode to Sine Generator and then press the Start Sine
Generator button. A sine wave will be generated continuously on
analog output channel 0.
8. On the external DAQ Signal Accessory box, wire Analog Out Ch0 to
Analog In Ch1.
9. Switch to the Analog Input tab and change the Channel to 1. You
should now see the sine wave from analog output channel 0 on the
graphical display.
10. Click to the Counter I/O tab, which you can use to determine if the
DAQ board counter-timers are functioning properly.
11. Click the Digital I/O tab, shown below, which you can use to test the
digital lines on the DAQ board.
For this test, set lines 0 through 3 as output and then toggle their Logic
Level checkboxes. As you toggle the boxes, the LEDs on the DAQ
signal accessory should turn on or off. The LEDs use negative logic.
Click the Close button to close the Test Panel and return to the
Measurement & Automation Explorer configuration screen.
Units: Deg C
Range: Leave at default values
Scale: New Custom Scale
Scale Name: tempscale
Scale Description: V * 100 = deg C
Scale Type: Linear
m = 100.0, b = 0.0
DAQ Hardware used: Dev1 (your DAQ board)
Channel: 0
Analog Input Mode: Differential
15. Create a second channel by right-clicking on the Data Neighborhood
icon and selecting Create New. Select Virtual Channel and press the
Finish button. Input the following settings:
Measurement Type: Analog Input
Channel Name: chan1
Channel Description: This is Analog Input ch1 on the DAQ
Signal Accessory.
Type of Sensor: Voltage
Units: V
Range: –10.0 V to 10.0 V
Scale: No Scaling
DAQ Hardware used: Dev1 (your DAQ board)
Channel: 1
Analog Input Mode: Differential
16. Create the third and last channel by right-clicking on chan1 and
selecting Duplicate. The Copy Virtual Channel dialog box appears;
leave the values at default and click the OK button. You should get a
virtual channel named chan2 that has the same parameters as chan1.
Verify these settings and update the description by right-clicking chan2
and selecting Properties.
17. The Measurement & Automation Explorer window should resemble the
following figure when you are finished and all the categories are
expanded:
Intermediate VIs
Although this course addresses the Intermediate VIs, most exercises use the
Easy I/O VIs. The Advanced VIs are beyond the scope of this course.
The Easy I/O VIs include a simplified error handling method. When a DAQ
error occurs in your VI, a dialog box shows error information. With the box,
you have the option to halt execution of the VI or ignore the error.
Intermediate VIs
Compared to the Easy I/O VIs, the Intermediate VIs have more hardware
functionality, flexibility, and efficiency for developing your application. The
Intermediate VIs feature capabilities that the Easy I/O VIs lack, such as
external timing and counter I/O. As you become acquainted with LabVIEW,
you will discover that the Intermediate VIs are better suited for most of your
applications.
The Intermediate VIs feature more flexible error handling than the Easy I/O
VIs. With each VI, you can pass error status information to other VIs and
handle errors programmatically.
Advanced VIs
The Advanced VIs are the lowest-level interfaces to the NI-DAQ driver. Few
applications require the Advanced VIs; the Easy I/O and Intermediate VIs
will suffice for most DAQ applications.
Utility VIs
The Utility VIs consist of convenient groupings of the Intermediate VIs.
They are for situations where you need more functionality control than the
Easy I/O VIs provide, but want to limit the number of VIs you call.
To acquire a single point from your signal connected to your DAQ board,
use AI Sample Channel.
To acquire a single point from several analog input channels on your DAQ
board, use AI Sample Channels.
You enter the channel names into the control in two different ways. You can
use the Operating tool to click on the DAQ Channel Name control and
choose the channel name as defined in the MAX utility as shown below.
You will now create a VI that acquires data from an analog input channel on
the DAQ board and displays that value in a meter.
You will use this VI later, so be sure to save it as the instructions below
describe.
Front Panel
Block Diagram
Note If you do not have a DAQ board or a DAQ Signal Accessory, use the following VI
in place of the AI Sample Channel VI:
Note If you do not have a DAQ board or a DAQ Signal Accessory, replace the AI
Sample Channel VI with the following VI:
The DAQ Solution Wizard also uses the DAQ Channel Wizard to define
which signals are connected to which channels on your DAQ board. When
you press the Go to DAQ Channel Wizard button, the MAX utility opens.
You can then modify or add new virtual channels and scales for your data
acquisition application. You can then reference the channel name for the
input signal throughout the application, and all of the conversion processes
are performed transparently.
Now you will use the DAQ wizards to create a VI that acquires data from
multiple channels, displays that information in a chart, and writes that
information to a data file.
You will use the DAQ Solution Wizard to create a VI that acquires several
channels of data, shows that data in a strip chart, and logs that data to file.
You will use the virtual channels you previously defined in the MAX utility.
For this exercise, connect the sine wave output to Analog In CH1 and the
square wave output to Analog In CH2 on the DAQ Signal Accessory.
1. Open a new VI.
2. Launch the DAQ Solution Wizard by selecting DAQ Solution Wizard
from the Tools»Data Acquisition menu in LabVIEW. The following
window will open:
You can see the channels you defined by clicking on the View Current
Wizard Configuration button. You will be using these channels for this
exercise—temp, chan1, and chan2. These correspond to the temperature
sensor and analog input channels 1 and 2 on the DAQ Signal Accessory.
You can look at these channel definitions in more detail by launching
the DAQ Channel Wizard by clicking on the Go to DAQ Channel
Wizard button.
3. From the opening DAQ Solution Wizard window, make sure the selected
option is Use channel names specified in DAQ Channel Wizard and
select the Next button. Here you have the option to either make a custom
application or view the VIs in the Common Solutions Gallery.
4. Select Solutions Gallery and press the Next button to get the following
window:
5. Select Data Logging from the Gallery Categories section and Simple
Data Logger from Common Solutions. When you press the Next
button, you will be asked which channels of data to log. Select all the
analog input channels shown by holding down <Shift> and clicking on
each choice as shown:
Front Panel
7. Notice that the channels are already defined. Open and examine the
diagram. It uses the AI Sample Channels VI to acquire the data and the
Write Characters to File VI to log the data to disk. Both of these are
high-level I/O VIs, and a dialog box will open if an error occurs.
8. Return to the panel, set the Time Between Points to be 1 sec, and run
the VI. You will get a prompt for a filename. Create the file called
logger.txt in the LabVIEW directory.
9. Stop the VI, close the Simple Data Logger VI, and quit the Solution
Wizard.
Waveform Data
The DAQ VIs return waveform data. The waveform datatype is a LabVIEW
datatype that combines the data read from the DAQ board with time
information. You can place a waveform on the panel by selecting it from the
I/O subpalette of the Controls palette as shown below:
Now you will build a VI that acquires a waveform from the DAQ board.
You will build a VI that uses the DAQ VIs to acquire a signal and plot it on
a graph.
For this exercise, on the DAQ Signal Accessory connect Analog Input CH1
to the sine wave output of the function generator.
Front Panel
Block Diagram
Note If you do not have a DAQ board or a DAQ Signal Accessory, use the following VI
in place of the AI Acquire Waveform VI:
The Write Waveforms to File and Read Waveforms from File VIs write data
in a special LabVIEW binary data file called a datalog file. Datalog files are
discussed in more detail in the LabVIEW Basics II course.
You use the Export Waveforms to Spreadsheet File VI to write the waveform
data to a spreadsheet format.
You will now use this function to write data acquired with the DAQ board
to a spreadsheet file.
You modify the previous VI that acquires data from an analog input channel
on the DAQ board to write the data to a file in spreadsheet format.
1. Open the Acquire Waveform VI that you built in the previous exercise if
it is not already open.
2. Rename the VI Acquire Waveform to File.vi by selecting
File»Save As.
3. You will not modify the panel. Switch to the block diagram.
Block Diagram
You will examine and run a VI that acquires two different waveforms and
plots each waveform on a graph.
For this exercise, connect the sine wave output to Analog In CH1 and the
square wave output to Analog In CH2 on the DAQ Signal Accessory.
Front Panel
Note If you do not have a DAQ board or a DAQ Signal Accessory, replace the AI
Acquire Waveforms VI with the following VI:
Create a VI that scans data from Channel 1 and Channel 2 and plots both
waveforms on a single waveform graph. Acquire 500 points from each
channel at 10,000 Hz. The VI also should write the scanned data to a
spreadsheet file so that when the file is opened using a spreadsheet, each
channel is displayed in a column.
Note If you do not have a DAQ board or a DAQ Signal Accessory, replace the AI
Acquire Waveforms VI with the following VI:
Save the VI as Scan Two Waveforms.vi. Use the front panel shown to
get started.
H. Analog Output
The Analog Output library contains VIs that perform digital-to-analog
(D/A) conversions or multiple conversions.
Waveform Generation
In many applications, generating one point at a time may not be fast enough.
In addition, it is difficult to attain a constant sample interval between each
point because the interval depends on a number of factors: loop execution
speed, call software overhead, and so on. With the AO Generate Waveform
VI, you can generate multiple points at rates greater than the AO Update
Channel VI can achieve. Furthermore, the VI can accept user-specified
update rates.
You will examine a VI that outputs voltage from 0 to 9.5 V in 0.5 V steps.
You will measure the voltage output using the Voltmeter VI that you created
in Exercise 9-2.
For this exercise, connect Analog Out CH0 to Analog In CH1 on the DAQ
Signal Accessory.
Front Panel
Block Diagram
Note If you do not have a DAQ board or a DAQ Signal Accessory, replace the two AO
Update Channel VIs with the following VI:
Read from Digital Line reads the logical state of a digital line on a
user-configured port. Device is the device number of the DAQ board.
Digital Channel specifies the port where the line is located. Line specifies
the digital line you will read. Line State returns the logical state of the given
line.
Read from Digital Port reads a user-configured port. Device is the device
number of the DAQ board. Digital Channel specifies the digital port to
read. The reading is displayed in a decimal number in pattern. Port Width
specifies the total number of bits in the port.
If an error occurs during the operation of digital I/O VI, a dialog box
displays the error code, and you have the option to abort the operation or
continue execution.
Note The LEDs use negative logic. That is, writing a one to the LED digital line turns
off the LED. Writing a zero to the LED digital line turns on the LED.
Intermediate VIs
Compared to the Easy I/O VIs, the Intermediate VIs have more hardware
functionality, flexibility, and efficiency for developing your application. The
Intermediate VIs feature capabilities that the Easy I/O VIs lack, such as
controlling interchannel sampling rates, using external timing and triggering
signals, acquiring unscaled data, performing digital handshaking,
performing continuous I/O operations, controlling onboard counters,
and supporting flexible error handling. The second tier of the Data
Acquisition»Analog Input subpalette consists of the Intermediate Analog
Input VIs. As you become acquainted with LabVIEW, you will discover that
you can build most DAQ applications with the Intermediate DAQ VIs.
Note Use the LabVIEW online reference (Help»Contents and Index menu) to
demonstrate and learn more about the details of these functions. The LabVIEW DAQ
Basics course describes these VIs in much more detail.
Intermediate VIs
The following figure shows how to use the Intermediate Analog Input VIs
in your block diagram. All necessary inputs are not wired to the VIs in these
figures. The figures are presented to demonstrate the order of execution of
the VIs and the use of the taskID to control data flow. The figure shows a
simplified block diagram for applications that acquire waveforms of data
using a buffer in computer memory and hardware timing from onboard
counters. The block diagram calls AI Config, AI Start, AI Read, AI Clear,
and Simple Error Handler.
error cluster propagates through the VIs and Simple Error Handler displays
a dialog box if an error occurs.
Note In the figure above, the buffer size parameter for AI Config is set to 2,000. The
number of scans to acquire parameter of AI Start is left unwired and has a default input
of –1. The –1 value informs AI Start to acquire the number of scans for which memory
has been allocated (buffer size) in AI Config. Similarly, the number of scans to read
parameter of AI Read is also unwired and has a default input of –1. Again, the –1 value
tells AI Read to read the number of scans that AI Start specifies.
a. b.
End of Data Current Read Mark End of Data
Incoming
Board > > >
Data
c. Current Read Mark End of Data d. End of Data Current Read Mark
Front Panel
Block Diagram
Additional Exercise
8-12 Build a VI that continuously measures temperature twice per second
and displays the temperature on a waveform chart. If the temperature
goes over a preset limit, the VI should turn on a front panel LED and
LED 0 on the DAQ Signal Accessory. The LEDs on the box are
labeled. The chart should plot both the temperature and limit. Name
the VI Temp Monitor with LED.vi.
8-13 Use the DAQ Solution Wizard to open a VI that reads and displays
the data logged in Exercise 8-4 and is called Simple Data
Reader.vi.
Notes
Introduction
This lesson introduces how you can communicate with GPIB and serial port
instruments using LabVIEW. Instrument drivers are discussed and used,
along with the lower-level functions for performing instrument I/O.
The previous lesson showed you how to use LabVIEW to communicate with
and acquire data from data acquisition (DAQ) boards. This lesson discusses
how you can use LabVIEW to control and acquire data from an external
instrument. As described above, there are many different ways to connect an
instrument to the computer. This lesson focuses on the two most common
instrument communication methods—GPIB and serial port communication.
Every device, including the computer interface board, must have a unique
GPIB address between 0 and 30. Address 0 is normally assigned to the
GPIB interface board. The instruments on the GPIB can use addresses 1
through 30. The GPIB has one Controller (your computer) that controls the
bus. To transfer instrument commands and data on the bus, the Controller
addresses one Talker and one or more Listeners. The data strings are then
handshaked across the bus from the Talker to the Listener(s). The LabVIEW
GPIB VIs automatically handle the addressing and most other bus
management functions.
There are three ways to signal the end of a data transfer. In the preferred
method, the GPIB includes a hardware line (EOI) that can be asserted with
the last data byte. Alternately, you may place a specific end-of-string (EOS)
character at the end of the data string itself. Some instruments use this
method instead of, or in addition to, the EOI line assertion. Finally, the
listener can count the bytes handshaked and stop reading when the listener
reaches a byte count limit. The byte count method is often used as a default
termination method because the transfer stops on the logical OR of EOI,
EOS (if used) in conjunction with the byte count. Thus, you typically set the
byte count to equal or exceed the expected number of bytes to be read.
GPIB Instruments
COMPUTER
GPIB Interface
43687.2356
43687.2356
GPIB Cable
If you exceed any of these limits, you can use additional hardware to extend
the bus cable lengths or expand the number of devices allowed.
Note For more information about GPIB, visit the National Instruments GPIB support
Web site at ni.com/support/gpibsupp.htm.
Software Architecture
The software architecture for GPIB instrument control using LabVIEW is
similar to the architecture for DAQ. Regardless of what operating system
you use, your GPIB interface card will ship with a set of drivers for that
board. These drivers are also available on your LabVIEW installation CD.
Always install the newest version of these drivers unless you are instructed
otherwise in the release notes for either the GPIB interface board or
LabVIEW. The figure below shows the software architecture on the
Windows platforms.
Configuration and
Diagnostic Tools
LabVIEW
LabVIEW Instrument
I/O VIs and Functions
Measurement
& Automation
Driver Software
(*.DLL)
Windows Registry
and Device Manager
You use the Measurement & Automation Explorer (MAX) to configure and
test the GPIB interface. MAX interacts with the various diagnostic and
configuration tools installed with the driver and also with the Windows
Registry and Device Manager. The driver-level software is in the form of a
dynamically linked library (DLL) and contains all the functions that directly
communicate with the GPIB board. The LabVIEW Instrument I/O VIs and
functions directly call the driver software.
Note The configuration utilities and hierarchy described above and in the next section
are specific to the Windows platforms. If you are using a different operating system, refer
to the manuals that came with your GPIB interface board for the appropriate information
for configuring and testing that board.
Configuration Software
Measurement & Automation Explorer (MAX) is the configuration utility
for your National Instruments software and hardware. It can also execute
system diagnostics, add new channels, interfaces, and virtual channels, and
view devices and instruments connected to your system. You open MAX by
double-clicking on its icon on the desktop or by selecting
Tools»Measurement & Automation Explorer.
You configure the objects listed in the MAX by right-clicking on the item
and making a selection from the shortcut menu. The graphic above shows
the GPIB interface board in the MAX utility and the results of pressing the
Scan for Instruments button at the top of the window. You will now use the
MAX utility to observe the GPIB board settings and communicate with the
NI Instrument Simulator.
2. Power on the NI Instrument Simulator and verify that both the Power
and Ready LEDs are lit.
5. Select the GPIB board by clicking on it. Click on the Properties button
below the menu to examine the settings for the GPIB interface as shown
below.
Note You may need to close the online help by pressing the Show/Hide button in the top
right corner of the MAX window to see the Instrument0 information.
10. Notice that the NI Instrument Simulator has a GPIB Primary Address
(PAD) of 2.
11. Click on the Communicate with Instrument button under the menu. An
interactive window opens where you can query, write to, and read from
that instrument.
12. With the Send String set to *IDN?, press the Query button. The
instrument should return its make and model number. You can use this
window to debug instrument problems or to verify that specific
commands work as described in the instrument manual.
13. Type MEAS:DC? into the Send String and press the Query button. The
NI Instrument Simulator returns a simulated voltage measurement.
14. Press the Query button again and a different value is returned.
15. Press the Exit button to quit the interactive communication window
when you are finished.
16. You will set a VISA alias for the NI Instrument Simulator. Therefore,
instead of having to remember the primary address, you can just specify
the name if the alias. While Instrument0 is selected in the MAX
window, press the VISA Properties button. Type devsim into the VISA
Alias as shown below and press the OK button.
Note Be sure to remember the alias you assign to the NI Instrument Simulator. You will
be using this alias throughout this lesson.
17. Close the MAX utility by selecting Exit from the File menu.
Because you can see the GPIB board, see the instrument, and communicate
with the instrument, you can be assured that the GPIB interface and software
driver are properly installed and configured. Next, you will learn how to
communicate with the GPIB instrument using LabVIEW.
Instrument drivers can help make test programs more maintainable in the
long term because instrument drivers contain all of the I/O for an instrument
within one library, separate from your other code. You are protected against
hardware changes and upgrades because it is much easier to upgrade your
test code when all of the code specific to that particular instrument is
self-contained within the instrument driver.
In the next exercise, you will open and use the instrument driver example for
the NI Instrument Simulator.
Note If you are working on your own and have a different instrument, you can install a
LabVIEW driver for it from the NI Web site or the CD. Instrument drivers are available
free of charge. If you have LabVIEW and a Web browser installed on your machine,
choose Instrumentation»Instrument Driver Network from the LabVIEW Tools
menu. LabVIEW automatically takes you to the Instrument Driver Network on ni.com.
Front Panel
6. Run the VI. The simulator supplies a random DC voltage and generates
the requested waveform on the graph. (The simulator may take several
seconds to acquire the waveform.) You can simulate different
waveforms by moving the Waveform slider and running the VI again.
Block Diagram
7. Examine the block diagram. The device is first initialized with the
Initialize VI, then commands are sent to configure and request
information from the instrument in the Application Example VI, and
finally the communication is ended with the Close VI. All programs
using instrument drivers implement this structure of initialization,
communication, and shutdown.
8. Close the VI. Do not save any changes.
In the last exercise, you used the NI DEVSIM Getting Started VI from the
NI Instrument Simulator instrument driver. When you examined the block
diagram for that VI, you noticed that the programming was broken down
into general functions for the simulator. LabVIEW instrument drivers
simplify instrument programming to high-level commands, so you do not
need to learn the low-level instrument-specific syntax needed to control
your instruments.
Getting Started
Application Examples
Application functions are also provided and are examples that demonstrate
how to use the component VIs to perform common tasks. Typically, this
means configuring, triggering, and returning measurements from an
instrument. An application VI does not initialize or close the instrument
driver. The application VI is not intended to be a soft front panel for the
instrument, but rather demonstrates of some instrument driver capabilities.
These VIs guide you in developing your own program.
You create the VISA Resource Name control by selecting it from the I/O
subpalette of the Controls palette as shown in the next figure. This control
works similarly to the DAQ Channel Name control, but it is specifically
used for instrument control.
Note VISA stands for Virtual Instrument Software Architecture and is the underlying
layer of software whenever you do instrument communication. VISA will be covered in
more detail in the next section.
You can use the MAX utility to determine what resources and instrument
addresses are available as in the first exercise. In addition, you gave the
NI Instrument Simulator a VISA Alias of devsim in that first exercise. The
VISA Alias should make it easier to communicate with your instruments
because you no longer need to memorize what interface and address
each instrument uses. You specify the VISA Alias for the Resource
Name/Instrument Descriptor in the instrument driver VIs. The example
below shows two different ways to specify the resource name for the
NI Instrument Simulator.
VISA Sessions
When a connection to an instrument is made with the Initialize VI, a VISA
session number is returned. That VISA session is a connection or link to a
resource, your instrument. You do not need to display this value; however,
each time you communicate with that device again, you need to wire the
VISA session input on the instrument driver VIs. After you finish
communicating with the instrument, you call the Close instrument driver VI,
and all references or resources for the instrument are closed.
Now that you have learned all the instrument driver-specific inputs and
outputs, you are ready to use those VIs to communicate with an instrument.
The diagram above initializes the devsim with its VISA Alias, uses a
configuration VI to select a waveform, uses two data VIs to read the
waveform and the waveform scaling information, and closes the instrument,
and then the error status is checked. You will see this same sequence of
events in every application that uses an instrument driver. Notice how the
Instrument Descriptor, VISA Sessions, and Error I/O terminals are wired.
Remember that you can right-click on the instrument driver VI terminals
and choose Create»Constant, Create»Control, or Create»Indicator as
needed.
You will start using the instrument driver VIs to build LabVIEW
applications.
Front Panel
Block Diagram
1. Open and build the diagram shown above using the following
components:
While Loop (Structures subpalette). Structures the VI to continue to
take DC voltage measurements until the user presses the Stop button.
Right-click on the Conditional terminal and select Stop If True. Create
two shift registers by right-clicking on the right or left edge of the loop
and selecting Add Shift Register from the shortcut menu.
NI DEVSIM Initialize VI (Instrument I/O»nstrument Drivers»NI
Device Simulator subpalette). Opens the communication between
LabVIEW and the NI Instrument Simulator. Right-click on the ID
Query input terminal and select Create»Constant from the shortcut
menu. Change it to a False value with the Operating tool. Wire the
Boolean constant also to the Reset input terminal.
NI DEVSIM Multimeter Configuration VI (Instrument I/O»
Instrument Drivers»NI Device Simulator subpalette). Configures the
range of voltage measurements that the NI Instrument Simulator
generates. The default is 0.0 to 10.0 V DC.
NI DEVSIM Measure DC Voltage VI (Instrument I/O»Instrument
Drivers»NI Device Simulator subpalette). Returns a simulated voltage
measurement from the NI Instrument Simulator.
NI DEVSIM Close VI (Instrument I/O»Instrument Drivers»NI
Device Simulator subpalette). Ends the communication between
LabVIEW and the NI Instrument Simulator.
Wait Until Next ms Multiple function (Time & Dialog subpalette). This
function causes the While Loop to execute every second. Create the
constant by right-clicking on the input terminal and selecting
Create»Constant.
Max & Min function (Comparison subpalette). You will use two of
these functions to check the current voltage against the minimum and
maximum values stored in the shift registers.
Simple Error Handler VI (Time & Dialog subpalette). This VI pops
open a dialog box if an error occurs and displays the error information.
Note You do not need to wire every terminal for each VI node. Wire only the necessary
inputs for each VI—Instrument Descriptor, VISA Sessions, and Error I/O.
E. VISA Overview
Virtual Instrument Software Architecture (VISA) is the underlying layer of
function calls used in the LabVIEW instrument driver VIs to communicate
with the driver software. This section describes what VISA is and how you
use VISA functions in LabVIEW instrument drivers.
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.
VISA is the VXIplug&play I/O software language that is the basis for the
software standardization efforts of the VXIplug&play Systems Alliance.
VISA by itself does not provide instrumentation programming capability.
It is a high-level API that calls into lower-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, you should remember this hierarchy. An
apparent VISA problem could really be the result of an installation problem
with one of the drivers VISA calls.
VISA
You can think of the instrument descriptor as a telephone number and the
resource as the person with whom you want to speak. The session is like the
telephone line. Each call uses its own line, and crossing these lines would
result in an error. The table below shows the proper syntax for the
instrument descriptor.
Interface Grammar
SERIAL ASRL[board][::INSTR]
When you previously communicated with the GPIB instruments, you used
the MAX utility to assign a VISA alias for the instrument descriptor. The
VISA alias is a name assigned to the instrument descriptor that you can use
to communicate with an instrument without having to type in the instrument
descriptor.
Note The MAX utility is not available on the Macintosh and UNIX platforms. On
Macintosh, you edit a file called visaconf.ini to assign a VISA alias, and on UNIX,
you assign VISA aliases through the visaconf utility.
The VISA Write function writes the write buffer string to the device
specified by the VISA resource name. dup VISA resource name returns
the same handle to that session. On UNIX platforms, data is written
synchronously; on all other platforms, it is written asynchronously. return
count contains the number of bytes actually transferred across the GPIB.
The error in and error out clusters contain the error information.
The VISA Read function reads data from the device specified by the VISA
resource name. byte count indicates the number of bytes to be read into the
returned read buffer string. dup VISA resource name returns the same
handle to that session. On UNIX platforms, data is read synchronously; on
all other platforms, it is read asynchronously. return count contains the
number of bytes actually transferred across the GPIB. The error in and
error out clusters contain the error information.
Front Panel
Block Diagram
1. Open and build the diagram shown above using the following
components:
Array constant (Array subpalette). This constant is used to build the
command string for the NI Instrument Simulator. Each of the five
waveform types is represented by an element in this array.
String constant (String subpalette). You will need three of these string
constants. The first one goes inside the array constant; resize the array
constant to show five elements and use the Labeling tool to enter the five
string elements as shown above. The second and third string constants
are used to build the command string for the NI Instrument Simulator.
Index Array function (Array subpalette). This function extracts the
string array element that matches the choice made with the Waveform
Type ring control.
Concatenate Strings function (String subpalette). This function
combines the string fragments into the complete command string for the
NI Instrument Simulator.
VISA Write function (Instrument I/O»VISA subpalette). This function
writes the command string to the NI Instrument Simulator.
Note If you do not have a GPIB card or an NI Instrument Simulator, use (Demo) VISA
Write VI (User Libraries»Basics I Course subpalette) to simulate writing a command
to the instrument.
Note If you do not have a GPIB card or an NI Instrument Simulator, use (Demo) VISA
Read VI (User Libraries»Basics I Course subpalette) to simulate reading a string from
the instrument.
Note If an error is returned from the VISA functions, the most common reason is that
the command string is not formatted correctly. Check the spelling, punctuation, spaces,
and capitalization carefully. Sometimes an instrument will lock up or get into a confused
state if the wrong command string is sent. Reinitialize the instrument by turning the
Power switch off and on again.
4. Run the VI a few times requesting different waveforms each time to see
how the waveform is read from the NI Instrument Simulator. Notice that
it takes a second or so for the instrument to process the information and
send the waveform to your computer.
5. Close this VI when you are finished.
RS-232 Instrument
Serial Port
76.6F
RS-232 Cable
Serial communication requires that you specify four parameters: the baud
rate of the transmission, the number of data bits encoding a character,
the sense of the optional parity bit, and the number of stop bits. 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. A typical character frame encoding the letter “m” is shown here.
Baud rate is a measure of how fast data is 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.
The output signal level usually swings between +12 V and –12 V. The “dead
area” between +3 V and –3 V is designed to absorb line noise.
Data bits are transmitted “upside down and backwards.” That is, inverted
logic is used and the order of transmission is from least significant bit (LSB)
to most significant bit (MSB). To interpret the data bits in a character frame,
you must read from right to left, and read 1 for negative voltage and 0 for
positive voltage. For the figure above, this yields 1101101 (binary) or 6D
(hex). An ASCII conversion table shows that this is the letter “m”.
An optional parity bit follows the data bits in the character frame. The parity
bit, if present, also follows inverted logic (1 for negative voltage and 0 for
positive voltage.) This bit is included as a simple means of error checking.
You specify ahead of time whether the parity of the transmission is to be
even or odd. If the parity is chosen to be odd, the transmitter will then set the
parity bit in such a way as to make an odd number of 1’s among the data bits
and the parity bit. The transmission in the figure above uses odd parity.
There are five 1’s among the data bits, already an odd number, so the parity
bit is set to 0.
The last part of a character frame consists of 1, 1.5, or 2 stop bits. These bits
are always represented by a negative voltage. If no further characters are
transmitted, the line stays in the negative (MARK) condition. The
transmission of the next character frame, if any, is heralded by a start bit of
positive (SPACE) voltage.
Hardware Overview
There are many different kinds (recommended standards) of serial port
communication. The most common are described below.
RS-232
The RS-232 is a standard developed by the Electronic Industries
Association (EIA) and other interested parties, specifying the serial
interface between Data Terminal Equipment (DTE) and Data
Communications 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 fidelity) 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.
RS-232 Cabling
Devices that use serial cables for their communication are split into two
categories. These are DCE (Data Communications Equipment) and DTE
(Data Terminal Equipment.) DCE are devices such as your modem, TA
adapter, plotter, etc., while DTE is your computer or terminal. RS-232 serial
ports come in two “sizes,” the D-Type 25-pin connector and the D-Type
9-pin connector. Both of these connectors are male on the back of the PC;
thus, you will require a female connector on your device. Below is a table of
pin connections for the 9-pin and 25-pin D-Type connectors.
This is the “standard” RS-232 connector, with enough pins to cover all the
signals specified in the standard. The table shows only the “core” set of pins
that are used for most RS-232 interfaces.
Software Overview
The LabVIEW Instrument I/O»Serial subpalette contains functions and
VIs used for serial port communication and is shown below:
You should notice that some of the functions in this subpalette are the VISA
functions you used previously for GPIB communication. The VISA Write
and VISA Read functions will work with any type of instrument
communication and are the same whether you are doing GPIB or serial
communication. However, because serial communication requires you to
configure extra parameters, you must start the serial port communication
with the VISA Configure Serial Port VI.
The VISA Configure Serial Port VI initializes the port identified by VISA
resource name to the specified settings. timeout sets the timeout value for
the serial communication. baud rate, data bits, parity, and flow control
specify those specific serial port parameters. The error in and error out
clusters maintain the error conditions for this VI.
The example above shows how to send the identification query command
*IDN? to the instrument connected to the COM2 serial port. The VISA
Configure Serial Port VI opens communication with COM2 and sets it to
9600 baud, 8 data bits, odd parity, one stop bit, and XON/XOFF software
handshaking. Then the VISA Write function sends the command. The VISA
Read function reads back up to 200 bytes into the read buffer, and the error
condition is checked by the Simple Error Handler VI.
Note The VIs and functions contained in the Instrument I/O»Serial subpalette are also
used for parallel port communication. You just specify the VISA resource name as being
one of the LPT ports. For example, you can use the MAX utility to determine that LPT1
has a VISA resource name of ASRL10::INSTR.
3. Turn on the NI Instrument Simulator and observe that the Power, Ready,
and Listen LEDs are lit. This is an indication that the device is in serial
communication mode.
Front Panel
Block Diagram
1. Open and build the diagram shown above using the following
components:
VISA Configure Serial Port VI (Instrument I/O»Serial subpalette).
This subVI initializes the serial port to the same settings the NI
Instrument Simulator uses. Right-click on each of the input terminals
and select Create»Constant to provide the serial port parameters shown
above.
Note If you do not have a serial port or an NI Instrument Simulator, use (Demo) VISA
Write VI (User Libraries»Basics I Course subpalette) to simulate writing a command
to the instrument.
Note If you do not have a serial port or an NI Instrument Simulator, use (Demo) VISA
Read VI (User Libraries»Basics I Course subpalette) to simulate reading a string from
the instrument.
Note It can take several seconds for the simulator to generate the waveform data.
ASCII Waveforms
As an example, consider a waveform composed of 1,024 points, each point
having a value between 0 and 255. Using ASCII encoding, you would need
a maximum of 4 bytes to represent each point (a maximum of 3 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. Below is an example of an
ASCII waveform string.
Extract Numbers.vi
Waveform
ASCII Waveform Numeric
String Array
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 function (String»String/Array/Path Conversion
subpalette). 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.
DATA«HB1»«LB1» «HB2»«LB2»...«HB1024»«LB1024»«CR»«LF»
Memory
«LF»«CR»«LB1024»«HB1024»...«LB2»«HB2»«LB1»«HB1»ATAD A D 0
GPIB
from instrument A T 2
LB1 HB1 4
LB2 HB2 6
2050
LB1024 HB1024
LF CR 2052
The following block diagram shows how you can use the Type Cast function
to cast the binary waveform string into an array of 16-bit integers.
In the previous example, you needed to use the Swap Bytes function because
the instrument sent the high-order byte first. Because the high-order byte is
received first, it is placed in a lower memory location than the low-order
byte sent after the high-order byte.
Memory Memory
A D 0 D A 0
A T 2 T A 2
LB1 HB1 4 HB1 LB1 4
LB2 HB2 6 HB2 LB2 6
LB1024
2050
HB1024 HB1024
2050
LB1024
LF CR 2052 CR LF 2052
Now you will examine a VI that reads data from the NI Instrument
Simulator in either ASCII or binary format and converts that waveform
string to an array of numbers to be plotted in a graph.
For the binary waveform string, assume that the waveform consists of
128 points. Each point is represented as a 1-byte unsigned integer. A header
precedes the data points, as shown below:
CURVE % {Bin Count MSB}{Bin Count LSB}{åå¤Å...128 bytes in
total...} {Checksum} CR LF
Front Panel
Block Diagram
Additional Exercises
9-8 Use the NI DEVSIM Getting Started VI as you did in Exercise 9-2
to test and examine the NI Instrument Simulator instrument driver as
it communicates in serial mode.
9-9 Open the Voltage Monitor VI you built in Exercise 9-3. Modify the
diagram so that the data is written to a spreadsheet file named
voltage.txt in the following format:
Notes
Notes
Introduction
This lesson introduces several VI Properties and features for customizing
your VIs. You also can customize the LabVIEW environment by making
your own custom subpalettes in the Controls and Functions palettes.
A. Customizing VI Properties
Once you have built an application with LabVIEW, you might want to
customize a VI so that an end user can more easily operate that VI. For
example, you can remove the LabVIEW menus and toolbar so that the user
does not need to worry about options that are unfamiliar or unnecessary for
the operation of the application. You can customize almost every aspect of
the front panel through the VI Properties setting. Access these options by
right-clicking the icon pane in the upper-right corner of the front panel or
block diagram and selecting VI Properties, or by selecting File»VI
Properties. The following window appears:
Window Appearance
When you open the VI Properties and select Window Appearance from
the Category menu ring, the following options appear:
These options affect the front panel while the VI is running. By default, the
front panel title is the same as the VI name. To change the string that appears
in the title bar, you can uncheck the option for Same as VI Name and type
a new name for the Window Title.
To customize the panel window appearance, you can either select one of the
predefined styles for the panel window from the radio buttons or create a
custom appearance. A graphical representation of each setting is displayed
on the right side of the option choices:
• Top-Level Application Window—This style window shows the title
bar and menu, hides the scroll bars and toolbar, allows the user to close
the window but does not allow the user to resize the window, uses the
runtime shortcut menus, and shows the front panel when called.
• Dialog—This style window is modal (stays on top of all other
windows), has no menu, scroll bars, or toolbar, has a highlighted
<Return> Boolean, allows the user to close the window but does not
allow the user to resize the window, uses the runtime shortcut menus,
and shows the front panel when called.
• Default—This style window is the same as the window style used in the
development environment of LabVIEW. All options such as scrollbars,
menus, toolbars, etc. are shown.
The settings shown above are for the Default style window. To set an option,
click in the checkbox next to that option, and a checkmark appears in the
checkbox beside the selected option. To clear an option, click on the
checkmark next to the option, and the checkmark disappears. You can use
these options to control the user’s ability to interact with the program by
restricting access to LabVIEW and operating system features and forcing
the user to respond to the options the front panel presents. For example, you
can hide the Abort and Continuous Run buttons so that the user cannot
select either one.
Window Size
You also can control the sizing of the front panel and front panel objects.
The Window Size category of the VI Properties dialog box contains the
following options:
There are two ways to create pop-up panels in LabVIEW. The first method
is to use the VI Properties»Window Appearance options. Both the
Top-Level Application Window and the Dialog styles contain the correct
settings to make a front panel open when called and close afterwards.
However, these options also contain other settings you might not want. The
best thing to do is to set up your VI for each style, run the VI, and see if this
is the window appearance you want. You can use the Custom option to
make pop-up panels by making the following selections from the
Customize window settings:
Build a VI that acquires temperature once every 0.5 s for 10 s. After the
acquisition is complete, the VI pops open a subVI panel that shows the
acquired data in a graph. The front panel remains open until you click on a
button.
Front Panel
1. Open a new VI and build the front panel shown above. The thermometer
displays the current temperature and the number of data values shown.
Block Diagram
Front Panel
3. Select the Custom style and click the Customize button. Configure the
window appearance as shown below:
5. Close the Pop-Up Graph front panel. If it is not closed, it will not close
after the subVI finishes running.
6. Run the main VI, Use Pop-Up Graph.
After the VI acquires 10 s of temperature data, the front panel of Pop-Up
Graph pops open and plots the temperature data. Click the DONE button
to return to the calling VI.
7. Change the window appearance settings for the Pop-Up Graph subVI
again. This time, choose the Dialog option. Close and save as Pop-Up
Graph.vi.
8. Run the top-level VI again and see if you notice a difference in the
Pop-Up Graph subVI window appearance.
9. Close all open windows when you are finished.
C. Key Navigation
While a VI is running, you can press <Tab> to change the key focus from
one control to the next. The key focus is the same as if you had used the
mouse to click a control. While a control has the key focus, you can use the
keyboard to assign the control’s value. If the control is a text or digital
control, the value entered in the control is highlighted when the control has
key focus. Whatever keystrokes you type are directly entered into the
control. If the control is a Boolean, its state is toggled when it is the key
focus and you press the space bar or <Enter>.
All front panel controls also have a Key Navigation option. Use this option
to associate a keystroke with a front panel control. When you perform the
keystroke while the VI is running, LabVIEW acts as if you clicked the
appropriate control. Thus, the associated control becomes the key focus. To
associate a front panel control with a keystroke, select the Key Navigation
option from the control’s Advanced shortcut menu as shown:
The Key Navigation dialog box appears as shown in the following figure.
Select the keystroke you want to assign from the Key Assignment ring
menu.
The Key Navigation dialog box also allows you to define the action of the
<Tab> key while the VI is running. The Key Navigation option is grayed
out for indicators because you cannot enter data into an indicator.
Note The front panel control names that appear in the Current Assignments list
correspond to the owned labels of those controls.
Block Diagram
2. Configure the Display Temp subVI to pop open its front panel when
called by right-clicking the Display Temp VI icon and selecting SubVI
Node Setup from the shortcut menu. Set the following options in the
SubVI Node Setup dialog box.
3. Repeat Step 2 for the Display and Log Temp subVI and Display Logged
Temp subVI.
4. Save the VI.
5. Return to the front panel and run the VI. Test run all options. Try the key
assignments to display the temperature, display and log the temperature,
and so on.
Note The three subVIs called from the block diagram all have their “RETURN” buttons
assigned to <Return>. Try pressing <Return> to return to the main front panel.
9. Save all subVIs and save and close the Temperature System VI.
10. Open the Temperature System VI again. The VI automatically executes
when you load it.
11. Test run the VI again. When you have finished, close the VI.
The Quit LabVIEW function aborts all executing VIs and ends the current
session of LabVIEW. Quit LabVIEW has one input, and if that input is
wired, the end of your LabVIEW session occurs only if that input is TRUE.
If the input is not wired, the end of the session occurs when this node
executes.
The first step in preventing you from making it difficult to edit your own
VIs is for you to save the VI to a new location before you modify the VI
Properties. The easiest way to save a VI to a new location is by selecting
File»Save with Options. The Save with options dialog box appears.
Note If you select the Remove diagrams option, you remove the source code to your
VI. This means you can no longer edit it. Select this option only if you are certain you
will never need to edit the VI again, and make sure that you have saved a backup copy of
the VI, with the diagrams, to a safe place.
Modify a VI that has been configured to run when opened and then quit
LabVIEW when it ends.
Front Panel
1. Close any open VIs and open the Edit Me VI, available in the
Exercises\LV Basics I directory.
2. The VI is already running when it opens. Notice that the toolbar and
menu bar are disabled along with the shortcut keystrokes that
accompany the menu options, such as the command to abort the VI.
Try several methods of quitting the VI.
3. Press the Start button. After 10 seconds, the VI ends and then quits
LabVIEW.
4. Relaunch LabVIEW and open a New VI. There are a few options you
can try to edit a VI that behaves similarly to the Edit Me VI.
a. If you know that the VI you want to edit has subVIs and not just
LabVIEW functions, you can open one of the subVIs. The VI
Properties will most likely not be set on the subVI. You can then
make a simple modification to the diagram of that subVI that breaks
the Run arrow. Such a modification could involve placing an Add
function on the diagram. Leaving the inputs unwired makes the
subVI have a broken Run arrow. Now you can open the VI you want
to edit. Because its subVI is nonexecutable, the VI that calls it is also
nonexecutable. It will then open in Edit mode and have a broken
Run arrow. Be sure to fix the subVI after you have edited the
calling VI.
b. If the VI you want to edit either does not have subVIs or you do not
know what it contains, you can follow the rest of the steps in this
exercise.
In addition to having different palette sets to choose from, you also can
select icon-based palettes or text-based palettes. Click the Format ring to
get the options shown below:
For more control over the layout and contents of the Controls and
Functions palettes, you can use the Palettes Editor to modify the existing
palettes. Access the Palettes Editor by pressing the Edit Palettes button.
When you select this option, you enter the editor, and the Edit Control and
Function Palettes dialog box appears.
You also can switch to another view by selecting the desired view from the
Palette Set ring. To edit the top-level Controls or Functions palettes or any
other predefined menus, or views, you first must create a new view by
selecting new setup from the Palette Set ring in the Edit Palettes dialog
box. This protects the built-in palettes and ensures that you can experiment
with the palettes without corrupting the default view.
Create a new menu file (.mnu)—Use this option to insert a new, empty
palette. You are then prompted for a name for the palette and a file to contain
it. Add a .mnu extension to the file to indicate than it is a menu, or palette.
Create a new view and customize the Functions palette to include the VIs
from the Exercises\LV Basics I directory.
1. Open a new front panel by selecting File»New. (Windows, Sun, and
HP-UX—If you have closed all VIs, select New VI from the initial
LabVIEW dialog box.)
2. Tack down either the Controls or Functions palette and click the
Options button.
3. Click the Edit Palettes button to enable the Palettes Editor.
4. Select new setup from the Palette Set ring in the Edit Palettes dialog
box.
5. Type LabVIEW Course in the Submenu Name dialog box and
click OK.
6. Right-click the Functions palette and select Insert»Submenu.
7. Select the Link to a directory option from the Insert Submenu dialog
box and click OK. A file dialog box displays the contents of the
LabVIEW Course view directory.
8. Select a directory to associate with the submenu (subpalette). Select the
Exercises\LV Basics I directory. A subpalette is created with the
contents of LV Basics I directory. A default icon is associated with
the subpalette.
9. Click the newly created LV Basics I subpalette. Observe the icons of the
VIs in the LV Basics I directory visible in the Basclass VIs
subpalette.
10. Delete blank icons and rearrange icons by right-clicking the icons and
selecting the respective operation. The final palette should resemble the
following figure:
Notes
A. Additional Information
This section describes how you can receive more information regarding
LabVIEW, instrument drivers, and other topics related to this course.
The support page for the National Instruments Web site contains links to
application notes, the support knowledgebase, hundreds of examples, and
troubleshooting wizards for all topics discussed in this course and more.
The NI Developer Zone also includes direct links to the instrument driver
network and to Alliance Program member Web pages.
LabVIEW Publications
LabVIEW Books
Many books have been written about LabVIEW programming and
applications. The National Instruments Web site contains a list of all the
LabVIEW books and links to places to purchase these books. Publisher
information is also included so you can directly contact the publisher for
more information on the contents and ordering information for LabVIEW
and related computer-based measurement and automation books.
The archives contain a large set of donated VIs for doing a wide variety of
tasks.
C. VI Quick Reference
This section contains a list of the VIs and functions used in the course.
Arrays
Array Max & Min function (Array subpalette). Returns the
maximum and minimum values and their indices in a 1D array.
Boolean
Not function (Boolean subpalette). Inverts the current Boolean
value.
Clusters
Bundle function (Cluster subpalette). Creates data necessary for
graphs and multiplot strip charts.
Comparison
Greater? function (Comparison subpalette). Returns a True if the
top input value is greater than the bottom input value.
Data Acquisition
AI Acquire Waveform VI (Data Acquisition»Analog Input
subpalette). Acquires the specified number of samples at the
specified sample rate from one input channel and returns the
acquired data.
Dialog
Beep VI (Graphics & Sound»Sound subpalette). Sounds a beep.
Format Into File function (File I/O subpalette). Formats the input
parameters into a string and writes that string to a file.
Instrument Control
NI DEVSIM Close VI (Instrument I/O»Instrument Drivers»NI
Device Simulator subpalette). Ends the communication between
LabVIEW and the NI Instrument Simulator.
Mathematics
General Polynomial Fit VI (Mathematics»Curve Fitting
subpalette). Returns an array that is a polynomial fit to the input
array.
Numeric
Add function (Numeric subpalette). Adds two numeric values,
arrays, or clusters.
Signal Processing
Sine Pattern VI (Analyze»Signal Processing»Signal Generation
subpalette). Creates an array of values representing a sinusoid
waveform.
String
Concatenate Strings function (String subpalette). Concatenates
strings into a single output string.
Timing
Get Date/Time String function (Time & Dialog subpalette).
Returns the current date and time in string format.
Tick Count (ms) function (Time & Dialog subpalette). Returns the
current value of the operating system’s software timer in
milliseconds since the computer was powered on.
D. Instructor’s Notes
1. Each station consists of the following:
DAQ Signal
Accessory
ER
N
Y
D
TE
LK
W
Q
EA
N
LIS
PO
SR
TA
AT
R
NI Instrument
NI Software—LabVIEW 6i PDS Simulator (addr 2)
Other Items:
a. Cable to connect the DAQ MIO Board to the DAQ Signal Accessory
b. GPIB cable to connect the instrument simulator to the GPIB Board
c. Power supply for the instrument simulator
d. Wires (two per station)
e. Serial cable to connect the instrument simulator to the computer
2. Copy the files from the disks accompanying this manual as described in
the Self-Paced Use section in the Student Guide and the ReadMe.txt
file on the disks.
3. Test the station by starting LabVIEW and running the LV Station
Test VI from Start»Programs»Station Tests»LV Station Test (see the
customer education resources coordinator for the VI).
4. Launch the Measurement & Automation Explorer to verify that both the
DAQ and GPIB cards 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.
Notes
If you find errors in the manual, please record the page numbers and describe the errors.
____________________________________________________________________________________________
____________________________________________________________________________________________
____________________________________________________________________________________________
____________________________________________________________________________________________
____________________________________________________________________________________________
____________________________________________________________________________________________
____________________________________________________________________________________________
Instructor
Please evaluate the instructor by checking the appropriate circle. Unsatisfactory Poor Satisfactory Good Excellent
Course
Training facility quality ❍ ❍ ❍ ❍ ❍
Training equipment quality ❍ ❍ ❍ ❍ ❍
Was the hardware set up correctly? ❍ Yes ❍ No
The course length was ❍ Too long ❍ Just right ❍ Too short
The detail of topics covered in the course was ❍ Too much ❍ Just right ❍ Not enough
The course material was clear and easy to follow. ❍ Yes ❍ No ❍ Sometimes
Did the course cover material as advertised? ❍ Yes ❍ No
I had the skills or knowledge I needed to attend this course. ❍ Yes ❍ No If no, how could you have been better
prepared for the course? _________________________________________________________________________
_____________________________________________________________________________________________
What were the strong points of the course? __________________________________________________________
_____________________________________________________________________________________________
What topics would you add to the course? ___________________________________________________________
_____________________________________________________________________________________________
What part(s) of the course need to be condensed or removed? ____________________________________________
_____________________________________________________________________________________________
What needs to be added to the course to make it better? ________________________________________________
_____________________________________________________________________________________________
Are there others at your company who have training needs? Please list. ____________________________________
_____________________________________________________________________________________________
_____________________________________________________________________________________________
Do you have other training needs that we could assist you with? _________________________________________
_____________________________________________________________________________________________
How did you hear about this course? ❍ National Instruments web site ❍ National Instruments Sales Representative
❍ Mailing ❍ Co-worker ❍ Other _____________________________________________________________
Customer Education Student Profile
Name ____________________________________________ Title _____________________________________
Company _________________________________________ Mail Stop _________________________________
Mailing Address _______________________________________________________________________________
City __________________ State/Province ____________ Country ______________ Zip ______________
Telephone ________________________________________ Fax ______________________________________
E-Mail _______________________________________________________________________________________
Date _____________________________________________ Event Location _____________________________
If you are currently a customer of National Instruments, please check the products you use:
❏ LabVIEW™ ❏ HiQ™ ❏ DAQ ❏ Fieldbus™
❏ LabWindows/CVI™ ❏ ComponentWorks™ ❏ SCXI™ ❏ IMAQ™ Vision
❏ BridgeVIEW™ ❏ VirtualBench™ ❏ GPIB ❏ Serial
❏ Lookout™ ❏ Measure™ ❏ VXI ❏ Motion control
Which statement best describes your function in the company? (check only one)
❏ Education ❏ Calibration ❏ Government/legal ❏ Production test
❏ Manufacturing/ ❏ Engineering ❏ Research/R&D/grad ❏ Systems integrator/
automation management student hardware
❏ Reseller/sales ❏ Purchasing/contracts ❏ Software developer ❏ Software consultant
❏ Service/repair ❏ Student/co-op ❏ Design ❏ Compliance testing
Industry-specific Literature
❏ Aerospace ❏ Semiconductor ❏ Analytical chemistry ❏ Industrial automation
❏ Telecommunications ❏ Vibration/acoustics ❏ Education ❏ Laboratory automation
❏ Automotive ❏ Physiology ❏ Test and measurement
Additional Literature
❏ NI Global Services ❏ LabVIEW Technical Resource Subscription Card
❏ Customer Education Course Schedule
Product and company names mentioned herein are trademarks or trade names of their respective companies.
© Copyright 1997, 1999 National Instruments Corporation. All rights reserved. 340812C-01