Labview Tutorial


001Title Page 1 Thursday, August 24, 2000 9:59 AM
®
LabVIEW
Tutorial
Manual
January 1996 Edition
Part Number 320998A-01
© Copyright 1993, 1996 National Instruments Corporation. All Rights Reserved.
001Title Page 2 Thursday, August 24, 2000 9:59 AM
Internet Support
GPIB: gpib.support@natinst.com
DAQ: daq.support@natinst.com
VXI: vxi.support@natinst.com
LabVIEW: lv.support@natinst.com
LabWindows: lw.support@natinst.com
HiQ: hiq.support@natinst.com
E-mail: info@natinst.com
FTP Site: ftp.natinst.com
Web Address: http://www.natinst.com
Bulletin Board Support
BBS United States: (512) 794-5422 or (800) 327-3077
BBS United Kingdom: 01635 551422
BBS France: 1 48 65 15 59
FaxBack Support
(512) 418-1111 or (800) 329-7177
Telephone Support (U.S.)
Tel: (512) 795-8248
Fax: (512) 794-5678 or (800) 328-2203
International Offices
Australia 03 9 879 9422, Austria 0662 45 79 90 0, Belgium 02 757 00 20,
Canada (Ontario) 519 622 9310, Canada (Québec) 514 694 8521, Denmark 45 76 26 00,
Finland 90 527 2321, France 1 48 14 24 24, Germany 089 741 31 30, Hong Kong 2645 3186,
Italy 02 48301892, Japan 03 5472 2970, Korea 02 596 7456, Mexico 95 800 010 0793,
Netherlands 0348 433466, Norway 32 84 84 00, Singapore 2265886, Spain 91 640 0085,
Sweden 08 730 49 70, Switzerland 056 200 51 51, Taiwan 02 377 1200, U.K. 01635 523545
National Instruments Corporate Headquarters
6504 Bridge Point Parkway Austin, TX 78730-5039 Tel: (512) 794-0100
Important Information
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 manual 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®and NI-488M"! are trademarks of National Instruments Corporation.
Product and company names listed are trademarks or trade names of their respective companies.
WARNING REGARDING MEDICAL AND CLINICAL USE OF NATIONAL INSTRUMENTS PRODUCTS
National Instruments products are not designed with components and testing intended to ensure a level of reliability
suitable for use in treatment and diagnosis of humans. Applications of National Instruments products involving
medical or clinical treatment can create a potential for accidental injury caused by product failure, or by errors on the
part of the user or application designer. Any use or application of National Instruments products for or involving
medical or clinical treatment must be performed by properly trained and qualified medical personnel, and all
traditional medical safeguards, equipment, and procedures that are appropriate in the particular situation to prevent
serious injury or death should always continue to be used when National Instruments products are being used.
National Instruments products are NOT intended to be a substitute for any form of established process, procedure, or
equipment used to monitor or safeguard human health and safety in medical or clinical treatment.
005 IXTOC Page i Thursday, August 24, 2000 10:02 AM
Table
of
Contents
About This Manual
Organization of This Manual ........................................................................................ix
Conventions Used in This Manual ................................................................................xi
Related Documentation .................................................................................................xii
Customer Communication ............................................................................................xiii
Customer Education ......................................................................................................xiii
Chapter 1
Introduction to LabVIEW
Chapter Information ......................................................................................................1-2
What Is LabVIEW? .......................................................................................................1-2
How Does LabVIEW Work? ........................................................................................1-3
Installing LabVIEW ......................................................................................................1-4
LabVIEW Files ...............................................................................................1-4
Virtual Instruments .......................................................................................................1-4
Front Panel ......................................................................................................1-5
Front Panel Toolbar ..........................................................................1-7
Block Diagram ................................................................................................1-9
Hierarchy ........................................................................................................1-11
Icon/Connector Pane .......................................................................................1-12
Tools Palette ..................................................................................................................1-14
Editing Techniques .......................................................................................................1-15
Controls Palette .............................................................................................................1-18
Controls and Indicators .................................................................................................1-19
Numeric Controls and Indicators ....................................................................1-19
Boolean Controls and Indicators ....................................................................1-20
Configuring Controls and Indicators ..............................................................1-20
Functions Palette ...........................................................................................................1-21
Building a VI .................................................................................................................1-21
Front Panel ......................................................................................................1-23
Block Diagram ................................................................................................1-24
Wiring Techniques ...........................................................................1-27
Tip Strips ..........................................................................................1-28
Showing Terminals ..........................................................................1-28
Wire Stretching ................................................................................1-29
© National Instruments Corporation i LabVIEW Tutorial Manual
005 IXTOC Page ii Thursday, August 24, 2000 10:02 AM
Table of Contents
Selecting and Deleting Wires .......................................................... 1-29
Bad Wires ........................................................................................ 1-30
Create & Wire Controls, Constants, and Indicators ....................................... 1-30
Run the VI ...................................................................................................... 1-31
Documenting the VI ....................................................................................... 1-32
Saving and Loading VIs ................................................................................. 1-34
Summary ....................................................................................................................... 1-36
Chapter 2
Creating a SubVI
Understanding Hierarchy............................................................................................... 2-1
Creating the SubVI ....................................................................................................... 2-1
Icon ................................................................................................................. 2-2
Icon Editor Tools and Buttons ......................................................... 2-2
Connector ....................................................................................................... 2-4
Using a VI as a SubVI .................................................................................................. 2-6
Front Panel ..................................................................................................... 2-6
Block Diagram ............................................................................................... 2-7
Block Diagram Toolbar ................................................................... 2-8
Some Debugging Techniques .......................................................... 2-9
Opening, Operating, and Changing SubVIs ................................................... 2-12
Hierarchy Window ......................................................................................... 2-13
Search Hierarchy ............................................................................. 2-14
Online Help for SubVI Nodes ........................................................................ 2-15
Simple/Complex Help View ............................................................ 2-15
Links to Online Help Files ............................................................... 2-16
Summary ....................................................................................................................... 2-17
Chapter 3
Loops and Charts
Using While Loops and Charts ..................................................................................... 3-1
Front Panel .................................................................................................... 3-2
Block Diagram .............................................................................................. 3-3
Mechanical Action of Boolean Switches ........................................ 3-6
Adding Timing ................................................................................ 3-7
For Loop ...................................................................................................................... 3-9
Numeric Conversion ..................................................................................... 3-10
Using a For Loop ......................................................................................................... 3-12
Front Panel .................................................................................................... 3-12
Block Diagram .............................................................................................. 3-13
Shift Registers ............................................................................................................. 3-14
Using Shift Registers ................................................................................................... 3-16
LabVIEW Tutorial Manual ii © National Instruments Corporation
005 IXTOC Page iii Thursday, August 24, 2000 10:02 AM
Table of Contents
Front Panel .................................................................................................... 3-16
Block Diagram .............................................................................................. 3-17
Multiplot Charts .............................................................................. 3-19
Customizing Charts ........................................................................ 3-20
Different Chart Modes .................................................................... 3-22
Summary ..................................................................................................................... 3-23
Additional Topics ........................................................................................................ 3-24
Customizing Charts ....................................................................................... 3-24
Faster Chart Updates ...................................................................... 3-24
Stacked Versus Overlaid Plots ....................................................... 3-24
Using Loops ................................................................................................................ 3-24
Testing a While Loop before Execution ....................................................... 3-24
Using Uninitialized Shift Registers .............................................................. 3-26
Chapter 4
Arrays, Clusters, and Graphs
Arrays ........................................................................................................................... 4-1
Array Controls, Constants, and Indicators ..................................................... 4-1
Graphs ............................................................................................................ 4-2
Creating an Array with Auto-Indexing ........................................................................ 4-2
Front Panel ..................................................................................................... 4-2
Block Diagram ............................................................................................... 4-4
Multiplot Graphs ............................................................................. 4-7
Polymorphism .................................................................................. 4-8
Using Auto-Indexing on Input Arrays .......................................................................... 4-9
Using Auto-Indexing to Set the For Loop Count ........................................... 4-10
Using the Initialize Array Function ............................................................... 4-11
Using the Graph and Analysis VIs ............................................................................... 4-12
Front Panel ..................................................................................................... 4-13
Block Diagram ............................................................................................... 4-13
Using Arrays ................................................................................................................ 4-15
Creating and Initializing Arrays ..................................................................... 4-15
Using the Build Array Function ..................................................................... 4-16
Finding the Size of an Array .......................................................................... 4-18
Using the Array Subset Function ................................................................... 4-18
Using the Index Array Function .................................................................... 4-19
Summary ...................................................................................................................... 4-22
Additional Topics ......................................................................................................... 4-23
More About Arrays ........................................................................................ 4-23
Efficient Memory Usage: Minimizing Data Copies ...................................... 4-23
Customizing Graphs ....................................................................................... 4-23
Graph Cursors .................................................................................. 4-24
© National Instruments Corporation iii LabVIEW Tutorial Manual
005 IXTOC Page iv Thursday, August 24, 2000 10:02 AM
Table of Contents
Intensity Plots ................................................................................................. 4-25
Data Acquisition Arrays (Windows, Macintosh, and Sun) ............................ 4-25
Graph Examples ............................................................................................. 4-25
Chapter 5
Case and Sequence Structures and the Formula Node
Using the Case Structure .............................................................................................. 5-1
Front Panel ..................................................................................................... 5-1
Block Diagram ............................................................................................... 5-2
VI Logic ......................................................................................................... 5-4
Using the Sequence Structure ....................................................................................... 5-5
Front Panel ..................................................................................................... 5-5
Modifying the Numeric Format ....................................................... 5-5
Setting the Data Range .................................................................... 5-7
Block Diagram ............................................................................................... 5-8
Formula Node ............................................................................................................... 5-11
Using the Formula Node .............................................................................................. 5-13
Front Panel ..................................................................................................... 5-14
Block Diagram ............................................................................................... 5-15
Summary ....................................................................................................................... 5-16
Additional Topics ......................................................................................................... 5-17
More Information on Case and Sequence Structures ..................................... 5-17
Timing with Sequence Structures .................................................................. 5-17
More Information on Formula Nodes ............................................................ 5-17
Artificial Data Dependency ............................................................................ 5-17
Chapter 6
Strings and File I/O
Strings ........................................................................................................................... 6-1
Creating String Controls and Indicators ......................................................... 6-1
Strings and File I/O ........................................................................................ 6-2
Using String Functions ................................................................................................. 6-2
Front Panel ..................................................................................................... 6-2
Block Diagram ............................................................................................... 6-3
Using Format Strings .................................................................................................... 6-4
Front Panel ..................................................................................................... 6-4
Block Diagram ............................................................................................... 6-5
More String Functions .................................................................................................. 6-7
Front Panel ..................................................................................................... 6-7
Block Diagram ............................................................................................... 6-8
File I/O .......................................................................................................................... 6-9
File I/O Functions ......................................................................................................... 6-10
LabVIEW Tutorial Manual iv © National Instruments Corporation
005 IXTOC Page v Thursday, August 24, 2000 10:02 AM
Table of Contents
Writing to a Spreadsheet File ....................................................................................... 6-11
Front Panel ..................................................................................................... 6-12
Block Diagram ............................................................................................... 6-12
Appending Data to a File .............................................................................................. 6-14
Front Panel ..................................................................................................... 6-14
Block Diagram ............................................................................................... 6-15
Reading Data from a File ............................................................................................. 6-16
Front Panel ..................................................................................................... 6-17
Block Diagram ............................................................................................... 6-17
Using the File I/O Functions ........................................................................................ 6-18
Specifying a File ............................................................................................ 6-18
Paths and Refnums ......................................................................................... 6-19
File I/O Examples .......................................................................................... 6-20
Summary ...................................................................................................................... 6-20
Additional Topics ......................................................................................................... 6-21
Datalog Files .................................................................................................. 6-21
Binary Byte Stream Files ............................................................................... 6-22
Error I/O in File I/O Functions ...................................................................... 6-22
Chapter 7
Customizing VIs
VI Setup ........................................................................................................................ 7-1
Setting Window Options ................................................................................ 7-2
SubVI Node Setup ........................................................................................................ 7-3
Using Setup Options for a SubVI ................................................................................. 7-3
Front Panel ..................................................................................................... 7-4
Block Diagram ............................................................................................... 7-4
Front Panel ....................................................................................... 7-7
Block Diagram ................................................................................. 7-8
Custom Controls and Indicators ................................................................................... 7-10
Summary ...................................................................................................................... 7-13
Additional Topics ......................................................................................................... 7-13
Simulating a Control/Indicator ...................................................................... 7-13
Using the Control Editor ................................................................................ 7-14
Chapter 8
Data Acquisition and Instrument Control
Using LabVIEW to Acquire Data ................................................................................ 8-1
About Plug-in Data Acquisition Boards (Windows, Macintosh, and Sun) .................. 8-2
About VISA .................................................................................................................. 8-2
About GPIB .................................................................................................................. 8-3
About Serial Ports ........................................................................................................ 8-4
© National Instruments Corporation v LabVIEW Tutorial Manual
005 IXTOC Page vi Thursday, August 24, 2000 10:02 AM
Table of Contents
Using Serial Ports ......................................................................................................... 8-5
Front Panel ..................................................................................................... 8-5
Block Diagram ............................................................................................... 8-6
About VXI for Windows, Macintosh, and Sun ............................................................ 8-7
About Instrument Drivers ............................................................................................. 8-8
Using Instrument Drivers ............................................................................................. 8-9
Front Panel ..................................................................................................... 8-9
Block Diagram ............................................................................................... 8-10
Using a Frequency Response Test VI .......................................................................... 8-13
Front Panel ..................................................................................................... 8-14
Block Diagram ............................................................................................... 8-15
Writing a Test Sequencer ............................................................................................. 8-17
Front Panel ..................................................................................................... 8-17
Block Diagram ............................................................................................... 8-18
Summary ....................................................................................................................... 8-19
Additional Topics ......................................................................................................... 8-20
Error Handling ............................................................................................... 8-20
Waveform Transfers ....................................................................................... 8-21
ASCII Waveforms ........................................................................... 8-21
Binary Waveforms ........................................................................... 8-22
Chapter 9
Programming Tips and Debugging Techniques
Programming Tips ........................................................................................................ 9-1
Debugging Techniques ................................................................................................. 9-5
Finding Errors ................................................................................................ 9-5
Single Stepping Through a VI ........................................................................ 9-5
Execution Highlighting .................................................................................. 9-6
Debugging a VI ............................................................................................................ 9-6
Front Panel ..................................................................................................... 9-6
Block Diagram ............................................................................................... 9-7
Opening the Front Panels of SubVIs ............................................................................ 9-9
Summary ....................................................................................................................... 9-10
Chapter 10
Program Design
Use Top-Down Design ................................................................................................. 10-1
Make a List of User Requirements ................................................................. 10-1
Design the VI hierarchy ................................................................................. 10-2
Write the Program .......................................................................................... 10-3
Plan Ahead with Connector Patterns ............................................................................ 10-3
SubVIs with Required Inputs ......................................................................... 10-5
LabVIEW Tutorial Manual vi © National Instruments Corporation
005 IXTOC Page vii Thursday, August 24, 2000 10:02 AM
Table of Contents
Good Diagram Style ..................................................................................................... 10-5
Avoid Oversized Diagrams ............................................................................ 10-5
Watch for Common Operations ..................................................................... 10-6
Use Left-to-Right Layouts ............................................................................. 10-7
Check for Errors ............................................................................................. 10-7
Watch Out for Missing Dependencies ........................................................... 10-9
Avoid Overuse of Sequence Structures ......................................................... 10-10
Study the Examples ........................................................................................ 10-10
Chapter 11
Where to Go from Here
Other Useful Documentation ........................................................................................ 11-1
For Information on Advanced Topics .......................................................................... 11-2
Appendix A
Customer Communication
Glossary
Index
© National Instruments Corporation vii LabVIEW Tutorial Manual
005 ATM Page ix Thursday, August 24, 2000 10:01 AM
About
This
Manual
The LabVIEW Tutorial contains the information you need to get started
with the Laboratory Virtual Instrument Engineering Workbench
(LabVIEW) software package. LabVIEW simplifies scientific
computation, process control, and test and measurement applications,
and you can also use it for a wide variety of other programming
applications.
This manual gives you an overview of the fundamental concepts of
LabVIEW, and includes lessons to teach you what you need to know to
build your own virtual instruments (VIs) as quickly as possible. This
manual does not explain every LabVIEW feature. Its goal is to
introduce the most important LabVIEW features in the context of
addressing programming tasks.
This manual presumes that you know how to operate your computer
and that you are familiar with its operating system.
Organization of This Manual
Each chapter discusses a different LabVIEW concept, although you
can design a VI that may incorporate several of these basic concepts.
Therefore, we encourage you to work through the entire tutorial before
you begin building your application.
Some of the chapters in this tutorial include an Additional Topics
section, which gives an overview of advanced LabVIEW features and
refers you to other documentation and example VIs.
This manual is organized as follows:
" Chapter 1, Introduction to LabVIEW, describes what LabVIEW is,
what a Virtual Instrument (VI) is, how to use the LabVIEW
environment (windows, menus, palettes, and tools), how to
operate VIs, how to edit VIs, and how to create VIs.
© National Instruments Corporation ix LabVIEW Tutorial Manual
005 ATM Page x Thursday, August 24, 2000 10:01 AM
About This Manual
" Chapter 2, Creating a SubVI, describes what a subVI is, teaches you
how to create the icon and connector, and teaches you how to use a VI
as a subVI.
" Chapter 3, Loops and Charts, introduces While Loops, teaches you
how to display data in a chart, teaches you about shift registers and
how to use them, and teaches you how to use For Loops.
" Chapter 4, Arrays, Clusters, and Graphs, discusses how to create
arrays, use basic array functions, clusters, and graphs. You also learn
what polymorphism is, and how to use graphs to display data.
" Chapter 5, Case and Sequence Structures and the Formula Node,
describes how to use the Case structure and Sequence structure,
sequence locals and Formula Nodes.
" Chapter 6, Strings and File I/O, teaches you how to create string
controls and indicators and teaches you how to use string functions,
file input and output operations, save data to files in spreadsheets, and
write data to and read data from text files.
" Chapter 7, Customizing VIs, shows you how to use the VI and subVI
setup options and how to make custom controls and indicators.
" Chapter 8, Data Acquisition (for Windows, Macintosh, and Sun) and
Instrument Control, discusses how to acquire data from a plug-in data
acquisition board, teaches you about VISA, teaches you about GPIB,
shows you how to control a serial port interface from LabVIEW,
discusses VXI (for Windows, Macintosh, and Sun), teaches you about
instrument drivers and how to use them, and teaches you about using
a Frequency Response Test VI.
" Chapter 9, Programming Tips and Debugging Techniques, gives you
tips for programming and debugging VIs and teaches you editing
techniques.
" Chapter 10, Program Design, offers some techniques to use when
creating programs and offers programming style suggestions.
" Chapter 11, Where to Go From Here, contains information on other
useful resources to examine as you build your LabVIEW
applications.
" The Appendix, Customer Communication, contains forms you can
use to request help from National Instruments or to comment on our
products and manuals.
LabVIEW Tutorial Manual x © National Instruments Corporation
005 ATM Page xi Thursday, August 24, 2000 10:01 AM
About This Manual
" The Glossary contains an alphabetical list of terms used in this
manual, including abbreviations, acronyms, metric prefixes,
mnemonics, and symbols.
" The Index contains an alphabetical list of key terms and topics in this
tutorial, including the page where you can find each one.
Conventions Used in This Manual
The following conventions are used in this manual:
bold Bold text denotes menus, menu items, or dialog box buttons or options. In
addition, bold text denotes VI input and output parameters.
italic Italic text denotes emphasis, a cross reference, or an introduction to a key
concept.
bold italic Bold italic text denotes a note, caution, or warning.
monospace Monospace font denotes text or characters that you enter using the
keyboard. Sections of code, programming examples, syntax examples,
and messages and responses that the computer automatically prints to the
screen also appear in this font.
italic Italic text in this font denotes that you must supply the appropriate words
monospace or values in the place of these items.
<> Angle brackets enclose the name of a key on the keyboard for example,
.
- A hyphen between two or more key names enclosed in angle brackets
denotes that you should simultaneously press the named keys for
example, .
The symbol leads you through nested menu items and dialog box
options to a final action. The sequence
FilePage SetupOptionsSubstitute Fonts
directs you to pull down the File menu, select the Page Setup item, select
Options, and finally select the Substitute Fonts option from the last
dialog box.
paths Paths in this manual are denoted using backslashes (\) to separate drive
names, directories, and files, as in drivename\dir1name\
dir2name\myfile.
© National Instruments Corporation xi LabVIEW Tutorial Manual
005 ATM Page xii Thursday, August 24, 2000 10:01 AM
About This Manual
IEEE 488.1 and IEEE 488.1 and IEEE 488.2 refer to the ANSI/IEEE Standard 488.1-1987
IEEE 488.2 and the ANSI/IEEE Standard 488.2-1987, respectively, which define
the GPIB.
Warning: This icon to the left of bold italicized text denotes a warning, which alerts
you to the possibility of damage to you or your equipment.
Caution: This icon to the left of bold italicized text denotes a caution, which alerts
you to the possibility of data loss or a system crash.
Note: This icon to the left of bold italicized text denotes a note, which alerts you
to important information.
Abbreviations, acronyms, metric prefixes, mnemonics, symbols, and
terms are listed in the Glossary.
Related Documentation
The following documents contain information that you may find
helpful as you read this manual:
" LabVIEW Analysis VI Reference Manual
" LabVIEW Code Interface Reference Manual
" LabVIEW Communication VI Reference Manual
" LabVIEW Data Acquisition Basics Manual (Windows, Macintosh,
and Sun)
" LabVIEW Data Acquisition VI Reference Manual (Windows,
Macintosh, and Sun)
" LabVIEW Instrument I/O VI Reference Manual
" LabVIEW User Manual
" ANSI/IEEE Standard 488.1-1987, IEEE Standard Digital Interface
for Programmable Instrumentation
" ANSI/IEEE Standard 488.2-1987, IEEE Standard Codes, Formats,
Protocols, and Common Commands
" LabVIEW Function Reference Manual available online; printed
version available by request.
LabVIEW Tutorial Manual xii © National Instruments Corporation
005 ATM Page xiii Thursday, August 24, 2000 10:01 AM
About This Manual
Customer Communication
National Instruments wants to receive your comments on our products
and manuals. We are interested in the applications you develop with
our products, and we want to help if you have problems with them. To
make it easy for you to contact us, this manual contains comment and
configuration forms for you to complete. These forms are in the
Appendix, Customer Communication, at the end of this manual.
Customer Education
National Instruments offers hands-on LabVIEW Basics and Advanced
courses to help you quickly master LabVIEW and develop successful
applications. The comprehensive Basics course not only teaches you
LabVIEW fundamentals, but also gives you hands-on experience
developing data acquisition and instrument control applications. The
follow-up Advanced course teaches you how to maximize the
performance and efficiency of LabVIEW applications. Contact
National Instruments for a detailed course catalog and for course fees
and dates.
© National Instruments Corporation xiii LabVIEW Tutorial Manual
01Intro Page 1 Thursday, August 24, 2000 10:04 AM
Chapter
1
Introduction to LabVIEW
This chapter describes what LabVIEW is, what a Virtual
Instrument (VI) is, how to use the LabVIEW environment (windows,
menus, palettes, and tools), how to operate VIs, how to edit VIs, and
how to create VIs.
Because LabVIEW is such a feature-rich program development
system, this tutorial cannot practically show you how to solve every
possible programming problem. Instead, this tutorial explains the
theory behind LabVIEW, contains exercises to teach you to use the
LabVIEW programming tools, and guides you through practical uses of
LabVIEW features as applied to actual programming tasks.
If you would like more training after using this manual, National
Instruments offers hands-on LabVIEW courses to help you quickly
master LabVIEW and develop successful applications.
The comprehensive LabVIEW Basics course not only teaches you
LabVIEW fundamentals, but also gives you hands-on experience
developing data acquisition (for Windows, Macintosh, and Sun) and
instrument control applications. The follow-up LabVIEW Advanced
course teaches you how to maximize the performance and efficiency of
LabVIEW applications in addition to teaching you the advanced
features of LabVIEW.
For a detailed course catalog and for course fees and dates, refer to the
address page on the inside front cover of this manual for information
about contacting National Instruments.
© National Instruments Corporation 1-1 LabVIEW Tutorial Manual
01Intro Page 2 Thursday, August 24, 2000 10:04 AM
Chapter 1 Introduction to LabVIEW
Chapter Information
Each chapter begins with a section like the one that follows, listing the
learning objectives for that chapter.
You Will Learn:
" What LabVIEW is.
" What a Virtual Instrument (VI) is.
" How to use the LabVIEW environment (windows and palettes).
" How to operate VIs.
" How to edit VIs.
" How to create VIs.
What Is LabVIEW?
LabVIEW is a program development application, much like various
commercial C or BASIC development systems, or National
Instruments LabWindows. However, LabVIEW is different from those
applications in one important respect. Other programming systems use
text-based languages to create lines of code, while LabVIEW uses a
graphical programming language, G, to create programs in block
diagram form.
You can use LabVIEW with little programming experience. LabVIEW
uses terminology, icons, and ideas familiar to scientists and engineers
and relies on graphical symbols rather than textual language to describe
programming actions.
LabVIEW has extensive libraries of functions and subroutines for most
programming tasks. For Windows, Macintosh, and Sun, LabVIEW
contains application specific libraries for data acquisition and VXI
instrument control. LabVIEW also contains application-specific
libraries for GPIB and serial instrument control, data analysis, data
presentation, and data storage. LabVIEW includes conventional
program development tools, so you can set breakpoints, animate
program execution to see how data passes through the program, and
single-step through the program to make debugging and program
development easier.
LabVIEW Tutorial Manual 1-2 © National Instruments Corporation
01Intro Page 3 Thursday, August 24, 2000 10:04 AM
Chapter 1 Introduction to LabVIEW
How Does LabVIEW Work?
LabVIEW includes libraries of functions and development tools
designed specifically for instrument control. For Windows, Macintosh,
and Sun, LabVIEW also contains libraries of functions and
development tools for data acquisition. LabVIEW programs are called
virtual instruments (VIs) because their appearance and operation
imitate actual instruments. However, they are analogous to functions
from conventional language programs. VIs have both an interactive
user interface and a source code equivalent, and accept parameters
from higher-level VIs. The following are descriptions of these three VI
features.
" VIs contain an interactive user interface, which is called the front
panel, because it simulates the panel of a physical instrument. The
front panel can contain knobs, push buttons, graphs, and other
controls and indicators. You input data using a keyboard and
mouse, and then view the results on the computer screen.
" VIs receive instructions from a block diagram, which you
construct in G. The block diagram supplies a pictorial solution to
a programming problem. The block diagram contains the source
code for the VI.
" VIs use a hierarchical and modular structure. You can use them as
top-level programs, or as subprograms within other programs or
subprograms. A VI within another VI is called a subVI. The icon
and connector pane of a VI work like a graphical parameter list so
that other VIs can pass data to it as a subVI.
With these features, LabVIEW promotes and adheres to the concept of
modular programming. You divide an application into a series of tasks,
which you can divide again until a complicated application becomes a
series of simple subtasks. You build a VI to accomplish each subtask
and then combine those VIs on another block diagram to accomplish
the larger task. Finally, your top-level VI contains a collection of
subVIs that represent application functions.
Because you can execute each subVI by itself, apart from the rest of the
application, debugging is much easier. Furthermore, many low-level
subVIs often perform tasks common to several applications, so that you
can develop a specialized set of subVIs suited to applications you can
construct.
© National Instruments Corporation 1-3 LabVIEW Tutorial Manual
01Intro Page 4 Thursday, August 24, 2000 10:04 AM
Chapter 1 Introduction to LabVIEW
Installing LabVIEW
For instructions on how to install LabVIEW, see your LabVIEW
release notes.
After installing LabVIEW, the default configuration setting is correct
for the purposes of this tutorial. If you would like to explore LabVIEW
configuration options, see the Preferences Dialog Boxes section of
Chapter 8, Customizing Your LabVIEW Environment, in the LabVIEW
User Manual.
LabVIEW Files
The LabVIEW system consists of the LabVIEW application and a
number of associated files.
LabVIEW uses several directories and files from the hard drive to store
information necessary to create your VIs. These directories and files
include, among others:
" The vi.lib directory. This directory contains libraries of VIs,
such as analysis VIs.
" The examples directory. This directory contains many sample
VIs that demonstrate LabVIEW s program functionality.
" The tutorial.llb library. This file, located in the vi.lib
directory, contains a library of VIs that this tutorial uses.
You can access the contents of these files and directories from within
the LabVIEW environment.
Virtual Instruments
LabVIEW programs are called virtual instruments (VIs). VIs have
three main parts: the front panel, the block diagram, and the
icon/connector.
OBJECTIVE To open, examine, and operate a VI, and to familiarize yourself with
the basic concepts of a virtual instrument.
LabVIEW Tutorial Manual 1-4 © National Instruments Corporation
01Intro Page 5 Thursday, August 24, 2000 10:04 AM
Chapter 1 Introduction to LabVIEW
Front Panel
1. (Windows) Open LabVIEW by double-clicking with the mouse
button on the LabVIEW icon in the LabVIEW group. If this is the
first time you have opened LabVIEW, the program prompts you to
enter your name, the name of your company, and your LabVIEW
serial number.
(Macintosh) Launch LabVIEW by double-clicking on the
LabVIEW icon in the LabVIEW folder. If this is the first time you
have launched LabVIEW, the program prompts you to enter your
name, the name of your company, and your LabVIEW serial
number.
(UNIX) Launch LabVIEW by typing labview in a
shell window. If LabVIEW is not in your executable path, you
must type in the path to the LabVIEW executable followed by
labview, as shown in the following example.
/usr/lib/labview/labview
(All Platforms) After a few moments, a blank, untitled front panel
appears.
© National Instruments Corporation 1-5 LabVIEW Tutorial Manual
01Intro Page 6 Thursday, August 24, 2000 10:04 AM
Chapter 1 Introduction to LabVIEW
2. Open the Temperature System Demo VI by following these steps.
a. Select FileOpen.
b. Double-click on examples. Double-click on apps.
Double-click on tempsys.llb.
c. Double-click on Temperature System Demo.vi.
While the VI loads, a dialog box appears, which describes the name of
the VI currently loading, the name of the hard drive that the VI is
located on, the directories and paths being searched, and the number of
the VI in the loading process. The following illustration shows the
dialog box that appears when you load the Temperature System Demo
VI.
After a few moments, the Temperature System Demo VI front panel
appears, as the following illustration shows. The front panel contains
LabVIEW Tutorial Manual 1-6 © National Instruments Corporation
01Intro Page 7 Thursday, August 24, 2000 10:04 AM
Chapter 1 Introduction to LabVIEW
several numeric controls, Boolean switches, slide controls, knob
controls, charts, graphs, and a thermometer indicator.
Front Panel Toolbar
The front panel contains a toolbar of command buttons and status
indicators that you use for running and debugging VIs. It also contains
font options and alignment and distribution options for editing VIs.
Front Panel Toolbar:
Run button Runs the VI
Continuous run button Runs the VI over and over; useful for
debugging
Stop button Aborts VI execution
© National Instruments Corporation 1-7 LabVIEW Tutorial Manual
01Intro Page 8 Thursday, August 24, 2000 10:04 AM
Chapter 1 Introduction to LabVIEW
Pause/Continue button Pauses VI execution/Continues VI execution
Font ring Sets font options, including font type, size, style, and color
Alignment ring Sets alignment options, including vertical, top edge,
left, and so on, for two or more objects
Distribution ring Sets distribution options, including gaps,
compression, and so on, for two or more objects
1. On the front panel, run the VI by clicking on the run button in the
toolbar.
The button changes appearance to indicate that the VI is running.
The Temperature System Demo VI simulates a temperature monitoring
application. The VI takes temperature readings and displays them in
the thermometer indicator and on the chart. The Update Period slide
controls how fast the VI acquires the new temperature readings.
LabVIEW also plots high and low temperature limits on the chart,
which you can change using the Temperature Range knobs in the
middle left border. If the current temperature reading is out of the set
range, LEDs light up next to the thermometer.
This VI continues to run until you click the Acquisition switch to Off.
You can also turn the data analysis on and off. The analysis consists of
a running calculation of the mean and standard deviation of the
temperature values and a histogram of the temperature values.
2. Use the Operating tool to change the values of the high and low
limits. First, highlight the old value, either by double-clicking on
the value you want to change, or by clicking and dragging across
the value with the Labeling tool. When the initial value is
highlighted, type a new value and press (Windows);
(Macintosh); (Sun); or (HP-UX).
You can also click on the enter button in the toolbar, or click the
mouse in an open area of the window to enter the new value.
3. Change the Update Period slide control, shown in the following
illustration, by placing the Operating tool on the slider and
dragging it to a new location.
LabVIEW Tutorial Manual 1-8 © National Instruments Corporation
01Intro Page 9 Thursday, August 24, 2000 10:04 AM
Chapter 1 Introduction to LabVIEW
Label
Digital Display
Scroll Button
Slider
Housing
4. Practice adjusting the other controls.
5. Stop the VI by clicking on the Acquisition switch. The VI may not
stop immediately because the VI has to wait for the last equation
or analysis set to complete operation.
Note: You should always wait for a VI to complete execution or you should
design a method to stop it, such as placing a switch on the front panel. In
this case, the VI collects the last set of temperature values, performs the
analysis, and comes to a completion when you click the Acquisition
switch.
Although the VI stops if you click on the stop button in the toolbar, this is
not the best way to stop VIs because the stop button halts the program
immediately. This may interrupt critical I/O functions, and so it is
probably not desirable.
Block Diagram
The following block diagram represents a complete LabVIEW
application, and is an example of how intricate LabVIEW
programming can be. Subsequent chapters in this tutorial detail
structures and elements mentioned in this section. It is not necessary to
understand all of these block diagram elements at this time to
appreciate the nature of a block diagram.
© National Instruments Corporation 1-9 LabVIEW Tutorial Manual
01Intro Page 10 Thursday, August 24, 2000 10:04 AM
Chapter 1 Introduction to LabVIEW
For Loop While Loop
Shift Registers Case Structure
1. Open the block diagram of the Temperature System Demo VI by
choosing WindowsShow Diagram.
2. Examine the different objects in the block diagram.
Each front panel has an accompanying block diagram, which is the VI
equivalent of a program. You build the block diagram using the
graphical programming language, G. You can think of the block
diagram as source code. The components of the block diagram
represent program nodes such as For Loops, Case structures, and
multiplication functions. The components are wired together to show
the flow of data within the block diagram.
The outermost structure is a While Loop. It continues to run what is
inside of it until the Acquisition switch is set to Off. The arrow
terminals on the border of the While Loop are called Shift Registers and
store values from one iteration of the loop to the next. The values that
the shift registers store here are the histogram, analysis iteration value,
mean, and standard deviation, in that order.
LabVIEW Tutorial Manual 1-10 © National Instruments Corporation
01Intro Page 11 Thursday, August 24, 2000 10:04 AM
Chapter 1 Introduction to LabVIEW
The two main structures inside the While Loop are a For Loop and a
Case structure. The acquisition of the data takes place inside the For
Loop. The For Loop takes 10 temperature readings at the rate specified
by Update Period and plots each reading on the thermometer and the
chart. The VI also compares the temperature to the high and low limits.
The Case structure controls the temperature analysis. If the Analysis
switch is off, the VI performs no analysis. You can see this by clicking
on one of the arrows next to the word True. In the False case, no
analysis takes place, and the histogram and analysis iteration value are
reset to zero. Change back to the True case using the same method you
used to change to the False case. Here, two subVIs analyze the
data one keeps a running mean and standard deviation of the
temperatures, and the other keeps a running histogram of the acquired
temperatures.
You do not need to fully understand all of the structures at this point.
The subsequent chapters in this tutorial discuss in greater detail each
element that appears in this VI.
Hierarchy
The power of LabVIEW lies in the hierarchical nature of VIs. After
you create a VI, you can use it as a subVI in the block diagram of a
higher level VI. You can have an essentially unlimited number of
layers in the hierarchy.
As an example, look at a VI that the Temperature System Demo VI
uses as a subVI in its block diagram.
© National Instruments Corporation 1-11 LabVIEW Tutorial Manual
01Intro Page 12 Thursday, August 24, 2000 10:04 AM
Chapter 1 Introduction to LabVIEW
1. Open the Temperature Status subVI by double-clicking on the
subVI icon. The following front panel appears.
Icon/Connector Pane
You use the icon/connector pane to turn a VI into an object that you
can use in the block diagrams of other VIs as a subroutine or function.
The icon and connector are located in the upper right corner of the VI
front panel. The icon graphically represents the VI in the block diagram
Icon
of other VIs. The connector terminals determine where you must wire
the inputs and outputs on the icon. The terminals are analogous to
parameters of a subroutine or function. They correspond to the controls
and indicators on the front panel of the VI. The icon hides the
Connector
connector until you choose to view it.
2. Put the Operating tool on the icon pane in the upper right corner of
the front panel and pop up. A pop-up menu appears.
3. Select Show Connector from the pop-up menu. The cursor
changes to the Wiring tool, shown on the left.
The squares on the connector are terminals that correspond to the
controls and indicators on the front panel.
4. Click on a terminal. It turns black. Notice that a control or
indicator becomes highlighted on the front panel. When you
wire the control or indicator (terminal), the data in it passes
to (or is received from) the other end of the wire.
LabVIEW Tutorial Manual 1-12 © National Instruments Corporation
01Intro Page 13 Thursday, August 24, 2000 10:04 AM
Chapter 1 Introduction to LabVIEW
5. Place the Wiring tool on the connector in the front panel and pop
up. A pop-up menu appears.
6. Select Show Icon. The Wiring tool changes back to the Operating
tool.
7. Switch to the block diagram by selecting WindowsShow
Diagram. At this time, you do not need to understand what all the
parts of the block diagram do. It is enough to notice that a subVI
can be complex or simple in itself.
By creating subVIs, you can make your block diagrams modular. This
modularity makes VIs easy to debug, understand, and maintain.
8. Switch to the front panel (WindowsShow Panel).
9. Select FileClose and do not save any changes you have made.
© National Instruments Corporation 1-13 LabVIEW Tutorial Manual
01Intro Page 14 Thursday, August 24, 2000 10:04 AM
Chapter 1 Introduction to LabVIEW
Tools Palette
LabVIEW uses a floating Tools palette, which you can use to edit and
debug VIs. You use the key to tab through the commonly used
tools on the palette. If you have closed the Tools palette, select
WindowsShow Tools Palette to display the palette.The following
Illustration displays the Tools palette.
Operating tool Places Controls and Functions palette items on the
front panel and block diagram
Positioning tool Positions, resizes, and selects objects
Labeling tool Edits text and creates free labels
Wiring tool Wires objects together in the block diagram
Object pop-up menu tool Brings up on a pop-up menu for an object
Scroll tool Scrolls through the window without using the scrollbars
Breakpoint tool Sets breakpoints on VIs, functions, loops, sequences,
and cases
Probe tool Creates probes on wires
Color copy tool Copies colors for pasting with the Color tool
Color tool Sets foreground and background colors
LabVIEW Tutorial Manual 1-14 © National Instruments Corporation
01Intro Page 15 Thursday, August 24, 2000 10:04 AM
Chapter 1 Introduction to LabVIEW
Editing Techniques
OBJECTIVE To learn LabVIEW editing techniques.
To work on the Editing Exercise VI, select FileOpen. The Editing
Exercise VI is located in examples\general\controls\
smplctls.llb.
The front panel of the Editing Exercise VI contains a number of
LabVIEW objects. Your objective is to change the front panel of the VI
as the following illustration shows.
1. If the Tools palette is not visible, select WindowsShow Tools
Palette to display it.
2. Reposition the digital control.
a. Choose the Positioning tool from the Tools palette.
b. Click on the digital control and drag it to another location.
Notice that the label follows the control. The control owns the label.
3. Click on a blank space on the front panel to deselect the control,
and then click on the label and drag it to another location.
© National Instruments Corporation 1-15 LabVIEW Tutorial Manual
01Intro Page 16 Thursday, August 24, 2000 10:04 AM
Chapter 1 Introduction to LabVIEW
Notice that the control does not follow the label. You can position an
owned label anywhere relative to the control, but when the control
moves, the label follows.
4. Switch to the block diagram by selecting WindowsShow
Diagram.
5. Move the block diagram so that you can see both windows.
6. Click on the front panel to make it active.
7. Copy the digital control to the block diagram to create a
corresponding constant.
a. Choose the Positioning tool from the Tools palette.
b. Click on the digital control. While holding the mouse button
down, drag the digital control to the block diagram. The
digital control now appears as a corresponding constant on the
block diagram. You can also use the Copy and Paste options
from the Edit menu to copy the control and then paste it to the
block diagram.
Note: You can use this same process to drag or copy a constant from the block
diagram to the front panel to create a corresponding control.
8. Reposition the four slide switches as a group.
a. Using the Positioning tool, click in an open area near the four
switches, hold down the mouse button, and drag until all the
switches lie within the selection rectangle.
b. Click on the selected switches and drag them to a different
location.
9. Duplicate the free label. Using the Positioning tool, hold down
(Windows);