Getting Started With Labview
Getting Started With Labview
with LabVIEW
Evaluation Version 6.0
Getting Started with LabVIEW
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,
Germany 089 741 31 30, Greece 30 1 42 96 427, 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
For further support information, see the Technical Support Resources appendix. To comment on the
documentation, send e-mail to techpubs@ni.com
Warranty
The media on which you receive National Instruments software are warranted not to fail to execute programming instructions,
due to defects in materials and workmanship, for a period of 90 days from date of shipment, as evidenced by receipts or other
documentation. National Instruments will, at its option, repair or replace software media that do not execute programming
instructions if National Instruments receives notice of such defects during the warranty period. National Instruments does not
warrant that the operation of the software shall be uninterrupted or error free.
A Return Material Authorization (RMA) number must be obtained from the factory and clearly marked on the outside of
the package before any equipment will be accepted for warranty work. National Instruments will pay the shipping costs of
returning to the owner parts which are covered by warranty.
National Instruments believes that the information in this document is accurate. The document has been carefully reviewed
for technical accuracy. In the event that technical or typographical errors exist, National Instruments reserves the right to
make changes to subsequent editions of this document without prior notice to holders of this edition. The reader should consult
National Instruments if errors are suspected. In no event shall National Instruments be liable for any damages arising out of
or related to this document or the information contained in it.
EXCEPT AS SPECIFIED HEREIN, NATIONAL INSTRUMENTS MAKES NO WARRANTIES, EXPRESS OR IMPLIED, AND SPECIFICALLY DISCLAIMS ANY
WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. CUSTOMER’S RIGHT TO RECOVER DAMAGES CAUSED BY FAULT OR
NEGLIGENCE ON THE PART OF NATIONAL INSTRUMENTS SHALL BE LIMITED TO THE AMOUNT THERETOFORE PAID BY THE CUSTOMER. NATIONAL
INSTRUMENTS WILL NOT BE LIABLE FOR DAMAGES RESULTING FROM LOSS OF DATA, PROFITS, USE OF PRODUCTS, OR INCIDENTAL OR
CONSEQUENTIAL DAMAGES, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. This limitation of the liability of National Instruments will
apply regardless of the form of action, whether in contract or tort, including negligence. Any action against National Instruments
must be brought within one year after the cause of action accrues. National Instruments shall not be liable for any delay in
performance due to causes beyond its reasonable control. The warranty provided herein does not cover damages, defects,
malfunctions, or service failures caused by owner’s failure to follow the National Instruments installation, operation, or
maintenance instructions; owner’s modification of the product; owner’s abuse, misuse, or negligent acts; and power failure or
surges, fire, flood, accident, actions of third parties, or other events outside reasonable control.
Copyright
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™, NI-DAQ™, and PXI™ are trademarks of National Instruments Corporation.
Product and company names mentioned herein are trademarks or trade names of their respective companies.
» 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 on in the software,
such as menu items and dialog box options. Bold text also denotes palette
and parameter 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.
Chapter 1
Introduction to LabVIEW
What Is LabVIEW? .......................................................................................................1-1
Why Should I Use LabVIEW? ......................................................................................1-2
How Does LabVIEW Work? .........................................................................................1-2
Front Panel.......................................................................................................1-3
Block Diagram.................................................................................................1-3
Palettes.............................................................................................................1-3
Tools Palette......................................................................................1-3
Controls Palette .................................................................................1-4
Functions Palette ...............................................................................1-5
Navigating the Controls and Functions Palettes ...............................1-6
Data Flow ........................................................................................................1-6
Where Do I Start? ..........................................................................................................1-7
LabVIEW Tutorial...........................................................................................1-7
Chapter 2
Virtual Instruments
Search for Examples ......................................................................................................2-1
Build a Virtual Instrument .............................................................................................2-2
Create a User Interface ....................................................................................2-2
Build the Block Diagram.................................................................................2-4
Wire and Run the VI........................................................................................2-5
Add Timing to the VI ......................................................................................2-8
Add Analysis and File I/O to the VI................................................................2-9
Chapter 3
Measurement
Instrument I/O................................................................................................................3-1
Run the Demo Scope VI..................................................................................3-2
Data Acquisition ............................................................................................................3-2
Using the DAQ Solution Wizard.....................................................................3-3
Configuring Analog Input Channels .................................................3-3
Generating a Solution from the Solutions Gallery............................3-5
Adding Analog Input to the VI........................................................................3-6
Chapter 4
Debugging
Use Execution Highlighting .......................................................................................... 4-1
Single-Step with Probes ................................................................................................ 4-1
Chapter 5
Where to Go from Here
Online Help ................................................................................................................... 5-1
National Instruments’ Commitment to You .................................................................. 5-2
Customer Education........................................................................................ 5-2
Alliance Program ............................................................................................ 5-2
Appendix A
System Requirements
Appendix B
Technical Support Resources
Glossary
What Is 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 data determine 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. If organized properly, the block
diagram resembles a flowchart.
Using LabVIEW, you can create 32-bit compiled applications that give
you the fast execution speeds needed for custom data acquisition, test,
measurement, and control solutions. You also can create stand-alone
executables and shared libraries, like DLLs, because LabVIEW is a true
32-bit compiler.
LabVIEW also gives you the benefits of a large installed user base, years
of product feedback, and powerful add-on tools. Finally, National
Instruments technical support and Developer Zone ensure successful
development of your solutions.
Front Panel
The front panel is the user interface of the VI. 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.
Block Diagram
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 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.
Palettes
LabVIEW palettes give you the options you need to create and edit the front
panel and block diagram.
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.
Controls Palette
The Controls palette is available only on the front panel. The Controls
palette contains the front panel controls and indicators you use to create the
user interface. Select Window»Show Controls Palette or right-click the
front panel workspace to display the Controls palette. You can place the
Controls palette anywhere on the screen.
Functions Palette
The Functions palette is available only on the block diagram. The
Functions palette contains the objects you use to program your VI, such as
arithmetic, instrument I/O, file I/O, and data acquisition operations. Select
Window»Show Functions Palette or right-click the block diagram
workspace to display the Functions palette. You can place the Functions
palette anywhere on the screen.
Data Flow
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.
Where Do I Start?
If you are new to LabVIEW, use this Getting Started with LabVIEW
manual and the LabVIEW Tutorial to help you get started quickly. The
LabVIEW Tutorial introduces you to the LabVIEW environment. Getting
Started with LabVIEW teaches you how to build VIs for data acquisition
and instrument control and how to debug them. It also teaches you how to
use the Search Examples feature and the DAQ Solution Wizard.
LabVIEW Tutorial
Use this tutorial to learn basic LabVIEW concepts. The tutorial guides you
through several activities to familiarize you with graphical programming.
Access the LabVIEW Tutorial by selecting Help»Contents and Index or
by clicking the LabVIEW Tutorial button in the LabVIEW dialog box,
shown in the following illustration.
If you are already running LabVIEW, either launch LabVIEW or close all
open VIs including the Demo VI to access the LabVIEW dialog box.
After you finish the LabVIEW Tutorial, continue with the activities in
this manual to learn how to build LabVIEW programs for instrument I/O,
data acquisition, and control.
You should complete the activities in this book in the order in which they
appear because subsequent activities build on the sample programs you
create. Approximate completion times are given for each activity and each
section within an activity.
Tip Use the keyboard shortcut <Ctrl-E> to switch between the front panel and block
diagram.
2. The two terminals on the block diagram correspond to the Stop button
and the Random Plot waveform chart on the front panel. Select
Window»Show Functions Palette to show the Functions palette.
3. Select Functions»Numeric»Random Number (0–1). As you drag
the Random Number (0–1) function close to the Random Plot
terminal, LabVIEW automatically draws a wire. When you release the
mouse button to place the function, LabVIEW automatically connects
the function to the terminal with a wire.
2. Wire the Stop button terminal to the While Loop conditional terminal.
To do this, click the Stop button terminal, move the mouse cursor to
the conditional terminal to create a wire and click again to connect the
wire.
Tip When you position the Wiring tool over a terminal, the terminal blinks, and a tip strip
with the name of the terminal appears.
3. Because this VI uses a Stop button, you must change the behavior of
the While Loop conditional terminal to Stop if True. Right-click the
conditional terminal or the border of the While Loop and select Stop
if True. The appearance of the conditional terminal changes as shown
at left. The block diagram should now match the following illustration.
5. Click the Run button on the toolbar to run the VI. The front panel
should now resemble the following illustration.
4. On the front panel, use the Operating tool to click the Run button
to run the VI and observe the delay effect. Select File»Save As
and save this VI as Random Number Example.vi in
labview\vi.lib\tutorial.llb.
Note It is important to place the Mean VI outside the While Loop because you want to
compute the data mean only after the While Loop completes collecting the data.
3. Use the Wiring tool to right-click the mean terminal on the upper right
side of the Mean VI and select Create»Indicator from the shortcut
menu to create a numeric indicator on the front panel to display the
mean of the random data.
4. Select Functions»File I/O»Write To Spreadsheet File.vi and place
the VI on the block diagram outside the While Loop.
5. Use the Wiring tool to create a wire branch connecting the Random
Number function and the X input terminal of the Mean VI. Click the
existing wire segment between the Random Number function and the
Random Plot terminal. Connect this wire to the X input terminal of
the Mean VI. The broken wire segment indicates that you are trying to
wire terminals of different data types. You will correct the broken
wires in Step 7.
Tip The wire segment blinks when the Wiring tool is positioned over it.
6. Create another wire branch from the branch you created in the
previous step. Wire this new branch from the segment outside the loop
to the 1D data input of the Write to Spreadsheet File VI. You use the
1D data input because the While Loop creates a one-dimensional row
of data from the generated random numbers. The wires will be broken,
but you will correct that in Step 7.
7. The orange square on the While Loop is a data exit terminal called a
tunnel. Right-click the tunnel and select Enable Indexing from the
shortcut menu to allow the While Loop to collect the data and pass it
to the Mean VI as a cumulative data set when the loop terminates. The
broken wires change to solid orange wires because the terminals are
now of the same data type. The block diagram should now match the
following illustration.
8. Return to the front panel and click the Run button to run the VI. When
you click the Stop button, you see the mean of the data and the Choose
file to write dialog box prompts you for the name of the file for saving
the random number data points. Type data.txt and click the Save
button.
Because the Mean VI is outside the While Loop, the VI does not
display the mean until you click the Stop button.
9. Use any text editor to open data.txt and view the data.
Instrument I/O
This section introduces you to the basic concepts on how to use LabVIEW
to acquire data from instruments controlled by GPIB, VXI, RS-232, and
other hardware standards. This section also shows you how to run the
Demo Scope VI if you do not have instrument I/O hardware installed.
Data Acquisition
This section teaches you how to use LabVIEW with general purpose data
acquisition (DAQ) hardware. If you use only stand-alone instruments and
control them with GPIB, VXI, or serial standards, refer to the
Instrument I/O section of this chapter.
Refer to Part II, DAQ Basics, of the LabVIEW Measurements Manual for
more information about data acquisition in LabVIEW.
Note Data acquisition and the DAQ wizards are available on Windows and
Macintosh only.
Note Refer to your hardware manual or the NI-DAQ Help file for data acquisition
hardware installation and configuration instructions.
On Windows, you access the DAQ Channel Wizard through the Data
Neighborhood in Measurement & Automation Explorer. On Macintosh
you can access the DAQ Channel Wizard by selecting Tools»Data
Acquisition»DAQ Channel Wizard. The DAQ Channel Wizard also
can be accessed from the DAQ Solution Wizard.
1. When you return to the DAQ Solution Wizard, select Use channel
names specified in DAQ Channel Wizard and click the Next button.
2. Select Solutions Gallery and click the Next button to open the
Solutions Gallery.
3. Choose a solution to generate for the analog input channel. For this
example, in the Gallery Categories list, select Data Logging.
4. In the Common Solutions list, select Simple Data Logger.
5. Click the Next button to continue.
6. Select a channel name as the input channel to use for the solution.
7. Click the Open Solution button to generate the solution.
8. Click the Run button to take data from the configured analog input
channel and log the data to a file. A file dialog box prompts you for a
file name. Type data.txt and click the Save button.
9. Click the STOP button in the lower-right corner of the front panel to
stop the VI. Use any text editor to view data.txt.
Tip You can customize the front panel and block diagram of the VI solution and save your
customized solutions.
10. Save any changes you want to keep and close this VI.
11. View the DAQ Solution Wizard window and click theBack button
to browse other gallery categories and common solution VIs.
12. Click the Cancel button to exit the DAQ Solution Wizard.
Note If you have not built the Random Number Example VI, you can find the solution VI
in LabVIEW\vi.lib\tutorial.llb\Random Number Example Solution.vi.
3. Use the Wiring tool to right-click the channel (0) input of the AI
Sample Channel VI and select Create Constant from the shortcut
menu to specify the name of the channel from which you will acquire
data.
4. Select the name of a channel from the pull-down menu on the constant.
5. View the front panel. Right-click the graph and select
Y Scale»AutoScale Y from the shortcut menu.
6. Click the Run button to acquire and display data on the chart.
7. Click the Stop button to stop the VI.
8. In the file dialog box, enter a name such as data.txt and click the
Save button to save the data to a spreadsheet file.
9. Save this VI as Acquire Data.vi in
labview\vi.lib\tutorial.llb.
2. Right-click the output wire of the Random Number function and select
Probe from the shortcut menu. A small number: window displays the
value of the data at that point.
3. Click the Step Into button on the toolbar. The While Loop now flashes
to indicate that the VI is running in single-step mode.
4. Click the Step Into button again. The Random Number function now
flashes.
5. Click the Step Over button to step over the Random Number function.
The Random Number function executes, so the output now appears in
the probe.
6. Using Step Into and Step Over buttons, single-step a few more times
through the loop to view each random number as the VI generates
them.
7. Click the Pause button to run the VI in normal mode.
8. View the front panel and click the Stop button to stop the VI. Save the
collected data to data.txt.
Note The LabVIEW documentation set is available in Portable Document Format (PDF)
on the LabVIEW CD in the manuals directory. You must have Adobe Acrobat Reader 3.0
or later installed to view these files.
Online Help
All built-in LabVIEW VIs and functions include a complete description of
the VI functionality and parameters. Access context-sensitive VI and
function help by selecting Help»Show Context Help or pressing
<Ctrl-H>.
When you place a VI on the block diagram and pass the mouse cursor over
it, the VI description displays in the Context Help window. Click the lock
button at the bottom of the Context Help window to lock the current
contents of the window.
Access the LabVIEW Help file to search for particular topics by selecting
Help»Contents and Index. You also can right-click any built-in VI or
function on the block diagram and select Help from the shortcut menu.
Customer Education
For additional training, National Instruments offers interactive CDs,
videos, books, and hands-on LabVIEW courses to help you master
LabVIEW quickly and develop successful applications.
Alliance Program
The Alliance Program is a network of third-party developers and
consultants who are experts in LabVIEW and other National Instruments
products. The National Instruments Alliance Solutions directory lists
additional libraries and utilities developed by our Alliance members to help
you use LabVIEW. In addition, the Alliance Solutions directory lists expert
LabVIEW consultants who can help you develop custom applications.
NI Developer Zone
The NI Developer Zone at ni.com/zone is the essential resource for
building measurement and automation systems. At the NI Developer Zone,
you can easily access the latest example programs, system configurators,
tutorials, technical news, as well as a community of developers ready to
share their own techniques.
Customer Education
National Instruments provides a number of alternatives to satisfy your
training needs, from self-paced tutorials, videos, and interactive CDs to
instructor-led hands-on courses at locations around the world. Visit the
Customer Education section of ni.com for online course schedules,
syllabi, training centers, and class registration.
System Integration
If you have time constraints, limited in-house technical resources, or other
dilemmas, you may prefer to employ consulting or system integration
services. You can rely on the expertise available through our worldwide
network of Alliance Program members. To find out more about our
Alliance system integration solutions, visit the System Integration section
of ni.com
Worldwide Support
National Instruments has offices located around the world to help address
your support needs. You can access our branch office Web sites from the
Worldwide Offices section of ni.com. Branch office Web sites provide
up-to-date contact information, support phone numbers, e-mail addresses,
and current events.
If you have searched the technical support resources on our Web site and
still cannot find the answers you need, contact your local office or National
Instruments corporate. Phone numbers for our worldwide offices are listed
at the front of this manual.
B
block diagram Pictorial description or representation of a program or algorithm. The block
diagram, consists of executable icons called nodes and wires that carry data
between the nodes. The block diagram is the source code for the VI. The
block diagram resides in the block diagram window of the VI.
C
conditional terminal Terminal of a While Loop that contains a Boolean value that determines if
the VI performs another iteration.
Controls palette Palette that contains front panel controls, indicators, and decorative objects.
D
DAQ Channel Wizard Utility that guides you through naming and configuring DAQ analog and
digital channels. Available in the Data Neighborhood of Measurement &
Automation Explorer (Windows) or DAQ Channel Wizard (Macintosh).
DAQ Solution Wizard Utility that guides you through specifying your DAQ application, and it
provides a custom DAQ solution.
data flow Programming system that consists of executable nodes that execute only
when they receive all required input data and produce output automatically
when they execute. LabVIEW is a dataflow system.
E
Enable Indexing Option that allows you to build a set of data to be released at the termination
of a While Loop. With indexing disabled, a While Loop releases only the
final data point generated within the loop.
execution highlighting Debugging technique that animates VI execution to illustrate the data flow
in the VI.
F
front panel Interactive user interface of a VI. Front panel appearance imitates physical
instruments, such as oscilloscopes and multimeters.
Functions palette Palette that contains VIs, functions, block diagram structures, and
constants.
G
General Purpose GPIB—synonymous with HP-IB. The standard bus used for controlling
Interface Bus electronic instruments with a computer. Also called IEEE 488 bus because
it is defined by ANSI/IEEE Standards 488-1978, 488.1-1987, and
488.2-1992.
I
IEEE 488.2 Institute of Electrical and Electronic Engineers Standard 488.2-1987,
which defines the GPIB.
indicator Front panel object that displays output, such as a graph or LED.
L
Labeling tool Tool to create labels and enter text into text windows.
M
MB Megabytes of memory. 1 MB is equal to 1,024 KB.
N
node Program execution element. Nodes are analogous to statements, operators,
functions, and subroutines in text-based programming languages.
On a block diagram, nodes include functions, structures, and subVIs.
O
Operating tool Tool to enter data into controls and operate them.
P
palette Display of icons that represent possible options.
R
RS-232 Recommended Standard 232, a serial interface bus standard.
S
Solutions Gallery Option within the DAQ Solution Wizard in which you can select from
numerous categories of common DAQ applications.
T
terminal Object or region on a node through which data pass.
tip strip Small yellow text banners that identify the terminal name and make it easier
to identify terminals for wiring.
Tools palette Palette that contains tools you can use to edit and debug front panel and
block diagram objects.
V
VI See virtual instrument.
virtual instrument Program in LabVIEW that models the appearance and function of a
physical instrument.
VISA Single interface library for controlling GPIB, VXI, RS-232, and other types
of instruments.
W
waveform chart Indicator that plots data points at a certain rate.
While Loop Loop structure that repeats a section of code until a condition is met.
wire branch Section of wire that contains all the wire segments from junction to
junction, terminal to junction, or terminal to terminal if there are no
junctions between.