Vous êtes sur la page 1sur 115

uti ts

uti ts
TM
LabVIEW Core 1

rib en

rib en
Course Manual

on

on
ist um

ist um
r D str

r D str
Course Software Version 2012
August 2012 Edition
Part Number 325290D-01
t fo l In

t fo l In
LabVIEW Core 1 Course Manual
Copyright
19932012 National Instruments.ts. All
ll rights reserved.
ublication
ation may not be reproduced
Under the copyright laws, this publication ced
ed or transmitted in
i aany form, electronic or mechanical, including
photocopying, recording, storing
ing in information retrieval system
n an information system, translating, in whole or in part, without the prior written
ystem,, or translating
No na

No na
ments Corporation.
consent of National Instruments orporation.
National Instruments respects
pects the intellectual property
p of others, and we ask our users to do the same. NI software is protected by
ellectual
tual property laws.
copyright and other intellectual la
law Where NI software
soft
oft mayay be uused to reproduce software or other materials belonging
se NI software
to others, you may use oftware only to t reproduce
ce materials
ateria ththat you may reproduce in accordance with the terms of any
applicable license or other
her legal restric
restrict
restriction.
tio

tio
ense Agreements a
End-User License Party Legal Notices
and Third-Party
You can find
d end-user
user license agreements
agr (EULAs)
EULAs) and third-party
third-p
third-pa legal notices in the following locations:
Noticess aree located in the <National
<
<N Instruments>
nstruments>
Instruments>\_Legal Information and <National Instruments>
directories.
tories.
EULAs
ULAs are located in theth <National nal Instruments>\Shared\MDF\Legal\License
onal I
In umen
men directory.
Review <National
<Nationa Instruments>\_Legal
ments>\_Leg
nts>\_ Information.txt for more information on including legal information
Na

in installers built with


Trademarks
CVI, LabVIEW, National
National
N
wi NI products.

Instruments Corporation.
ional Instru
In
trademarks.
arks.
ucts.

Instruments,
struments, NI, ni.com,
nstruments,

The mark LabWindows is used under a lli


ni.co the National Instruments corporate logo, and the Eagle logo are trademarks of
ni.co
poration. Refer to the Trademark Information at ni.com/trademarks for other National Instruments

license from Microsoft Corporation. Windows is a registered trademark of Microsoft


Na
Support
dwide T
Worldwide
ni.com
Te Produc Information
Produ
Technical Support and Product

Corporation in the United Statess and other


ot countries. Other product and company names mentioned herein are trademarks or trade
o Worldwide Offices
names of their respective companies. Visit ni.com/niglobal to access the branch office Web sites, which provide up-to-date contact information, support phone
Members of the National Instruments Alliance Partner Program are business entities independent from National Instruments and numbers, email addresses, and current events.
have no agency, partnership, or joint-venture relationship with National Instruments. National Instruments Corporate Headquarters
Patents 11500 North Mopac Expressway Austin, Texas 78759-3504 USA Tel: 512 683 0100
For patents covering National Instruments products/technology, refer to the appropriate location: HelpPatents in your software, For further support information, refer to the Additional Information and Resources appendix. To comment on National Instruments
the patents.txt file on your media, or the National Instruments Patent Notice at ni.com/patents. documentation, refer to the National Instruments Web site at ni.com/info and enter the Info Code feedback.
Contents

Contents
Lesson 4
Developing Modular Applications
Student Guide A. Understanding Modularity ....................................................................................4-2
.................
..........
B. Building the Icon and Connector Pane .................................................................4-3
.......................
..............

uti ts

uti ts
A. NI Certification .....................................................................................................v
.........................
.....................
B. Course Description ...............................................................................................vi
.........................
.................... C. Using SubVIs ........................................................................................................4-7
.........................
.....................
C. .........................
..................
What You Need to Get Started .............................................................................vii
D. ........................
................. ....
Installing the Course Software..............................................................................viii Lesson 5

rib en

rib en
E. Course Goals.........................................................................................................viii
.........................
................. ..........vii
....vii Creating and Leveraging Data Structures
F. .........................
................. ..............ix
.......ix
Course Conventions ..............................................................................................ix A. Arrays....................................................................................................................5-2
.........................
................. ..............5-2
........5-2

on

on
B. ........................
................... .................5-5
Common Array Functions ....................................................................................5-5 ...........5-5
Lesson 1 C. .........................
................ ....................5-6
.............5-6
Polymorphism .......................................................................................................5-6

ist um

ist um
Navigating LabVIEW D. .........................
................... ........................5
.......................5
Auto-Indexing .......................................................................................................5-8
A. What is LabVIEW ................................................................................................1-2
........................
................... .........................
.................... E. ........................
................... .........................
......................
Clusters .................................................................................................................5-13
B. .........................
................... .........................
...................
Project Explorer ....................................................................................................1-5 F. ........................
................ .........................
...................
Type Definitions ...................................................................................................5-18
C. .........................
.................. ..........................
...................
Parts of a VI ..........................................................................................................1-10
D. ........................
.................. .........................
.................
Front Panel ............................................................................................................1-14 Lesson 6
r D str

r D str
E. ........................
................... .........................
Block Diagram ......................................................................................................1-20 Managing File and Hardware Resources
sources
ources
F. Searching for Controls, VIs and Functions... ........................
..........................
Functions...........................................................1-31 A. Understanding Hardware and d Software
oftware Res Reso
Resources...............................................6-2
........................
..........................
G. .........................
.............. ..........................
......................
Selecting a Tool ....................................................................................................1-33 B. ........................
.............. .........................
....................
File I/O ..................................................................................................................6-4
H. ........................
................... .........................
.................
Dataflow................................................................................................................1-38 C. Acquiring Measurementss with ith a DAQ S ..........................
..................
System.....................................................6-7
I. ........................
......................... ..........................
.......................
Building a Simple VI ............................................................................................1-39 D. Controlling Instruments ts .....................
................. ..........................
................
.......................................................................................6-16
t fo l In

t fo l In
Lesson 2 Lesson 7
Troubleshooting and Debu
Debugging
gVVIs d Stat
Using Sequential and Stat Machine
State ch Algorithms
gorithms
A. Correcting Broken
roken VIs.....
VIs..........................................................................................2-2
..........................
....................... A. Using Sequential
ntial Programm
Programming ............................................................................7-2
..........................
.........................
B. Debuggingg Techni
chniques
ques .....
Techniques ..........................
.........................
.........................................................................................2-3 B. Using Statee Progr
ogramming
amming ......................................................................................7-4
Programming ..........................
.........................
No na

No na
C. ed orr Unexpected Data.............................................................................2-9
Undefined ........................
.................... chiness ..............
C. State Machines ............... ....................
.......................
......................................................................................................7-4
D. Error Handling
ling ............ .... .............
..............
......................................................................................................2-10
Lesson 8
Lesson 3 ataflow
low Cha
Solving Dataflow Challe
ll s with
Challenges ith Variab
Vari
Variables
nting a VI
Implementing
tio

tio
A. Communicating Between
Communicatin een Parallel Loop Loops .............................................................8-2
A.. Front
ont Panel BBasics ...............................................................................................3-2
.........................
....................... B. Writing to Co Controls and nd Reading
Reading fro from Indicators ................................................8-4
B. LabVIEW D Data Typess ...................
..........................................................................................3-3 C. Variables ..... .....................
...................
...............................................................................................................8-4
C. Documen
Documenting Code de ... ............
........
...............................................................................................3-14 D. Conditions ....................................................................................................8-13
Race Con ...... ............
........
D. While L ...............
........
Loops..........................................................................................................3-16
Na

E.
F.
G.
H
H.
II.
For L
Tim
D
........................
...................
Loops ..............................................................................................................3-19
Timing a VI.......................
VI......................
VI...........................................................................................................3-22
dback in Loops .......................................................................................3-23
Data Feedback
g Data Wavef
Plotting
tructures
tructur
Case Structures
Waveform
es .......
f Chart ..........................................................................3-26
.....................................................................................................3-28
Na
Appendix
ppendix A
Additional IInformation

Glossary
ssar
ation and R
Re
Resources

National Instruments | iii iv | ni.com


Student Guide

Student Guide
B. Course Description
Thank you for purchasing the LabVIEW Core 1 course kit. You can begin in developi
developing an The LabVIEW Core 1 course teaches you programming concepts, techniques, ques,
s, features,
ffea VIs, and
application soon after you complete this course. This course manual and functions you can use to create test and measurement, data acquisition, instrument
rument co ccontrol,
nd accompanying
d the accomp
accompa

uti ts

uti ts
software are used in the three-day, hands-on LabVIEW Core 1 course.e. ns.. This course assumes
datalogging, measurement analysis, and report generation applications. a that
you are familiar with Windows and that you have experience writingng algorithms
algorithms in the form of
responding
onding course
You can apply the full purchase of this course kit toward the corresponding cou registration
cours str fee re divided
flowcharts or block diagrams. The course and exercise manuals are ivided into lelessons, described

rib en

rib en
/training for online
if you register within 90 days of purchasing the kit. Visit ni.com/training
com/training line cou
course as follows.
schedules, syllabi, training centers, and class registration.
g:
In the course manual, each lesson consists of the following:

on

on
A. NI Certification son and what yo
An introduction that describes the purpose of the lesson you will learn
n

ist um

ist um
A description of the topics in the lesson
The LabVIEW Core 1 course is part of a series of courses
ourses
es designed to buildd your proficienc
proficiency with
rtant
nt concepts aand skills
A summary quiz that tests and reinforces important ls taught in the llesson
LabVIEW and help you prepare for the NI Certified ied LabVIEW A Associatete Developer exam.
exa
ex The
following illustration shows the courses that aree part
rt of the
the LabVIEW
Lab
La ning series. Refer
training R to In the exercise manual, each lesson consists off thee following:
ni.com/training for more information about out NI Certific
Certifica
Certification.
ics
cs
A set of exercises to reinforce those topics
r D str

r D str
hallenge
nge exercise
Some lessons include optional and challenge exercis sections
ns or a set of ad
add
additional exercises
New User U
Experienced User Advanced
Advanc User
to complete if time permits
Courses

LabVIEW Core 1* LabVIEW


L abVIE Core 3* Managing Software
Note For course and exercise
ercise
se manual uupdates and
nd corrections, refer to ni.com/info
t fo l In

t fo l In
LabVIEW Core 2*
En
Engineering in LabVIEW and enter the Info Codee Core1.
abVIE Connectivity
LabVIEW y Advanced Architectures
in LabVIEW
Object-Oriented
Obje dDDesign
gn Several exercises use one off th wing
wing N
the following Nationall Instruments h
ha
hardware products:
mming
and Programming
in LabVIEW A plug-in multifunction
ion data acq
acquisition (DAQ)
AQ) connected to a BNC-2120 containing
Q) device conn
LabVIEW
W Perform
Performance
ance or, function
a temperature sensor, unction gen
gene
generator, and
nd LEDs
Certifications
No na

No na
A GPIB interfacee connected
nected to an
a NI Instrument Simulator
trument Simu
Simula
Certified LabVIEW
VIEW Certified
dLLabVIEW
abVIEW Certified LabVIEW
loper Exam
Associate Developer Exam Developer Ex
Exam
am Architect Exam
If you do not have
ve this
his hardware,
hardware you still an ccomplete
till can lete the exercises. Alternate instructions are
ses
Other Courses provided for completing
pleting the exercises
ompleting ex
e s without
hout hardware.
hhard You also can substitute other hardware
for those previously
eviously mentioned.
mention Forr example,
ample, you can c use a GPIB instrument in place of the
tio

tio
LabVIEW
bVIEW In
Instrument
strument C
Control LabVIEW
bVIEW Real-Time
Re 1 LabVIEW Real-Time 2 ment
ent Simulator, or
NI Instrument o another
her National Instruments
Inst
Inst DAQ device connected to a signal
L abVIEW FPGA
LabVIEW LabVIEW DAQ and
LabVIEW an Signal Conditioning Modular Instruments Series uch as a function
source, such functio
functi generator.
ator.
tor.
*Core
Core co
courses
rses a
are
re strongly recommended to realize
lize m
maximum
a productivity gains when using LabVIEW.
Na

Na
National Instruments | v vi | ni.com
LabVIEW Core 1 Course Manual Student Guide

C. What You Need to Get Started NI Instrument Simulator Wizard installed from the NI Instrument Simulator software CD

LabVIEW Core 1 course CD, which installs the following folders:


Suggested Reading

uti ts

uti ts
The suggested reading material ensure that all students have a minimumm knowledge oof key theories Directory Description
and concepts related to the LabVIEW Core 1 course. To get the most ost out of this co
course, complete
all the suggested reading material.
Exercises Folder for saving VIs created during the course and for
f completing
ubVIs nece
certain course exercises; also includes subVIs necessary for some

rib en

rib en
To access each of the following suggested reading materials, refer
er to ni.com
ni.com/info and enter tthe exercises and zip file (NI Instrumentent Siumlator.zip
Siuml )
Info Code that corresponds to each topic: containing the LabVIEW instrumentt driver for the NI Instrument
rument

on

on
Simulator
LabVIEW Core 1 - The Software Development Method
hodd (Info Cod
Code: SoftDev
Dev)

ist um

ist um
Solutions Contains the solutions to all the
he course ex
exercises
Introduction to Data Acquisition (Info Code: DAQ
AQ)

GPIB Instrument Control Tutorial (Info Code:


de: GPIB)
D. Installing the Course Software
ware
re
Complete the following steps to install the course
ourse
se software.
Course Materials
r D str

r D str
1. Insert the course CD in your computer.
r. The LabVIEW Setup dialog box
LabVIE Coree 1 Course Setu
Before you begin this course, ensure you
ou have all the ffo
following
ng
g items: appears.
2. Click Install the course materials.
ls.
Computer running Windows 7/Vista/XP
Vista/XP
a/XP
3. Follow the onscreen instructions
ns too complete installation
i on and setup.
tion
t fo l In

t fo l In
Multifunction DAQ device configured
onfigured as D
Dev1 using
ing Measuremen
Measurement & Automation Explorer
Exercise files are located in the <Exercises>\LabVIEW
Exercises
Exercises> W Core 1\ folder.
VIEW
(MAX)

BNC-2120, wires, and


d cable
able Note Folder names
ames
mes in aangle brackets, such
uch as <Exerc
<Exercises>, refer to folders on the
compu
root directory of your computer.
GPIB interface
No na

No na
NI Instrumentt Simulator
mulator and ppower supp
supply
E. Course Goals
als
LabVIEW
W Full
ll or Professional
Profess
Professi Development
evelopment
opmen Sy
System 2012 or later
This course prepares
epares
es you to do the following:
lowing:
ing:
Understand
and front panels,
panels block diagrams, icons, and connector panes
grams, icon
tio

tio
DAQmx
mxx 9.5.5 or later hee programming structures
Use the ures
res and data ty
typ
types that exist in LabVIEW
NI-488.2
-488.2
8.2 3.0.2 or llater Usee various
arious editing and debugging
gging techniques
ging techni
techniq
Create
ate and save VIs so you
ou can
ca use them
he as subVIs
NI VISA 5.2 oor later
Na

A GPIB cable
cab
ca



Na Display and log
app
l data
applications
Create ap
Create applications
a
plug-in DAQ devices
ns that use plug
plug-i
ions that use serial
ser port and GPIB instruments
ser

This course does nott describe tthe following:


cti or object; refer to the LabVIEW Help for more information about
Every built-in VI, function,
LabVIEW features not described in this course
Analog-to-digital (A/D) theory

National Instruments | vii viii | ni.com


LabVIEW Core 1 Course Manual

Operation of the GPIB bus


Developing an instrument driver
he NI Example
Developing a complete application for any student in the class; refer to the Ex Finder,

uti ts

uti ts
available by selecting HelpFind Examples, for example VIs you can an us
usee and inc
inco
incorporate into
VIs you create

F. Course Conventions

rib en

rib en
The following conventions appear in this course manual:

on

on
The symbol leads you through nested sted menu it items and
ite d dialog
log box

ist um

ist um
options to a final action. The sequence
equence
ence Tools
ToolsInstrumentationFind
mentationFin
mentationFind
Instrument Drivers directs youu to drop dow down the Toolsools menu, sele
select the
Instrumentation item, and d finally
ally select tthe Find d Instrument
nstrument Drivers
D
option.

ip,
p, which al
This icon denotes a tip, alerts you to advisory
visory inform
information.
r D str

r D str
This icon denotess a note, which aalerts you
ou to important information.

This icon denotes


notess a caution, which
w advises
d ses you of precautions
ppr to take to
y, data loss, or a system
avoid injury, m crash.
t fo l In

t fo l In
bold notes items that you
Bold text denotes ou must select
select or click in the software, such as
menuu items
item and dialog
dialo box options. Bold text
te also denotes sections of dialog
xes and ha
boxes s.
hardware labels.

italic Italic
ic text denotes
deno
denot variables,
ables,
ab les, emphasis, a cross-reference, or an introduction
No na

No na
to a key conc ext also den
concept. Italic text deno
denotes text that is a placeholder for a word
or value tha
that you must supply. ly.

monospace Text in this font


nt denotes
notes te
text oor characters that you enter from the keyboard,
tio

tio
sect
sectio
sections of code,, programming
programm
programmi examples, and syntax examples. This font
also is usedd for the proper names
n of disk drives, paths, directories, programs,
ssubprograms,
ams,
ms, subroutines,
subroutine device names, functions, operations, variables,
mes and
filenames, d extensi
exten
extensions.
Na

monospace
onospace bold

Platform
orm
bol Text
xt in this font denotes
automatically
that are different

followin
differe
diffe

Text in this
d
omatically prints
pr
the messages and responses that the computer
to the screen. This font also emphasizes lines of code
from the other examples.

thi font denotes a specific platform and indicates that the text
th
following it applies only to that platform.
Na
National Instruments | ix
Lesson 1 Navigating LabVIEW

Navigating LabVIEW
1 A. What is LabVIEW
LabVIEW is a graphical programming environment you can use to quickly kly and efficiently
e create
applications with professional user interfaces. Millions of engineers andd scientists
ientists use
u LabVIEW
us

uti ts

uti ts
cations
ations using intuitive
to develop sophisticated measurement, test, and control system applications in icons
fferent
f ent targets and
and wires. In addition, the LabVIEW platform is scalable across different an OSs. In fact,
This lesson introduces how to navigate the LabVIEW environment. nt. This includes using the menus, LabVIEW offers unrivaled integration with thousands of hardware re devices
evices and pr
provides hundreds

rib en

rib en
bVIE
toolbars, palettes, tools, help, and common dialog boxes of LabVIEW. EW.
W. You also
als learn how to run n for you to cre
of built-in libraries for advanced analysis and data visualization crea ual
create virtual
ck diagram.
a VI and gain a general understanding of a front panel and block diagram. At tthe end of this
his lesso
lesson, instruments you can customize to your needs.

on

on
you create a simple VI that acquires, analyzes, and presentss data.
a.
Because LabVIEW programs imitate the appearance andd operation
eration of physical
ph ruments, such
instruments, su
suc
Topics as oscilloscopes and multimeters, LabVIEW programs aree called virtuvirt uments or, more
virtual instruments

ist um

ist um
grams.
commonly, VIs. VIs have front panels and block diagrams.ms. The fron
front panel iss the user inter
interf
interface.
A. What is LabVIEW The block diagram is the programming behind the user er interface. A ou
After you u build the fr
fron
front panel,
you add code using graphical representations of ffunctions
ctions to con
control thee front
ont panel obj
obje
objects. The
B. Project Explorer lso known as G code orr block
code on the block diagram is graphical code, also ck diagram code.
C. Parts of a VI
uages,
ages, like C+
In contrast to text-based programming languages, C++ and Visual
sual Basic, LabV
su LabVIEW uses icons
r D str

r D str
D. Front Panel
ons.. In text-base
instead of lines of text to create applications. text-bas gramming, inst
text-based programming, instru
instructions determine
E. Block Diagram the order of program execution. LabVIEW IEW
W uses graphi taflow
flow programming.
graphical dataflow pr
programm
ogramm In graphical
F. Searching for Controls, VIs and Functions
nctions dataflow programming, the flow of dataa throug
through h the nodes on the
he block diagram
dia
dia determines the
mming
execution order. Graphical programming ing and dataf xecution
cution are the ttwo major ways
dataflow execution
G. Selecting a Tool
t fo l In

t fo l In
LabVIEW is different from most ot other
her general-p
general-purposee programming
rogramming la languages.
H. Dataflow
I. Building a Simple VI In this course, you see how yoyou can use Lab
LabV
LabVIEW to effectively cre create simple data acquisition
applications using the threee steps:
steps: acquire, analyze,e,, and present. Although
A this course is taught on
VIEW
a Windows system, LabVIEW W is multi-
mul ti-
multi-platform. . You can develo
develop applications on a Windows, Mac
hermore, you can deploy
OS, or Linux system. Furthermore, eploy
ploy LabVIEW applications to a variety of real-time
No na

No na
and FPGA targets.

LabVIEW
W Characteristics
Characte cs
LabVIEW programs have th
the following
wingg characteris
characteri
characteristics:
tio

tio
A graphical
aphical compiled nature
hical and comp ature
ture
ataflow
ow and/or ev
Dataflow event-based programmin
rogrammin
programming
Multi-target
lti-target and platform
rm capabilities
m cap
capab es
Na



Na Object-oriented
Object-orient flexibility
Multi-thr
Multi-threa
Multi-threading
ibility
ity
ossibilities
possibilities

National Instruments | 1-1 1-2 | ni.com


LabVIEW Core 1 Course Manual Lesson 1 Navigating LabVIEW

In LabVIEW Core 1, you learn about the graphical and compiled nature of LabVIEW and dataflow Multithreading and Memory Management
programming. The following courses explore other characteristics:
LabVIEW enables your code to have automatic parallelism. In other languages
uages if you want to run
LabVIEW Core 2Learn about event-based programming. code in parallel, you have to manage multiple threads manually. The LabVIEW
VIEW environment, with
EW env
the compiler and execution system working together, automatically runs parallel whenever
ns code in paral
parall

uti ts

uti ts
Object-Oriented Design and Programming in LabVIEWLearn about
boutt object-ori
object-or
object-oriented
programming in LabVIEW. possible. Most of the time the details of the execution system are unimportant
impor
mportant you because the
tant to yo
system does the right thing without intervention. However, LabVIEW EWW also provid
provides you with
abVIEW'
IEW'ss multithreading
LabVIEW PerformanceLearn how to take advantage of LabVIEW's multit and options for improving performance.

rib en

rib en
memory management to improve program execution and memory
ory usage.

Launching the LabVIEW Environment


ent

on

on
Graphical and Compiled
While represented graphically, with icons and wires instead
teadd of with tex
text, G code
de onn the block When you launch LabVIEW, the Getting Started window
ow appears as sh
shown in
n Figure
gure 1-1.

ist um

ist um
diagram contains the same programming concepts found undd in most trad
traditional languages. For Figure 1-1. LabVIEW Getting
ting Started W
Win
Window
example, G code includes data types, loops, event handling,
dling, variab ursion,
rsion, and
variables, recursion,
object-oriented programming. LabVIEW compiles es G code direc
direct hine code so the
directly to machine t
computer processors can execute it. You do not have
ve to compil
compi
compile G code de in a separate step.
s

Dataflow and Event-Driven Programming


Programmin
ogrammi
r D str

r D str
LabVIEW programs execute according to dataflow pro programming
ing rules instea
instead of the procedural
ogrammi
mming
approach found in most text-based programming ng la
lang
languages suchh as C and CC++. Dataflow
pendent.
dent. The flo
execution is data-driven, or data-dependent. ata between no
flow of data nod
nodes in the G code
determines the execution order.
t fo l In

t fo l In
Event-driven programming featuress extend theth LabVIEWIEWW dataflow environment
en to allow the user's
direct interaction with the progr
rogr without
program hout the need
ed for polling.
polling. Ev
Event-based programming also
allows other asynchronous us activity
ctivity to
t influence the execution
xecution of G code on the block diagram.

Multi-Target and
nd Multi-Platform
Multi-Pl
Multi-Pla m
No na

No na
With LabVIEW applications,
pplications,
cations, you can target
get multicore
m cor coree pro
processors and other parallel hardware such
mmable
as field-programmablele gate arrays
arra (FPGAs).
GAs).
s). You
Y can automatically scale LabVIEW applications
to CPUs with two,
o, four, or m
mo es, often
more cores, ten wit
with no additional programming effort.
tio

tio
G code, with
th the exception of a few
ew platform-spe
platform-sp
platform-specific functions, is portable between the different
EW
LabVIEWW systems for ddifferent operating syste
systems. Therefore, you can often use the same code
her running
whether unning LabV
LabVIEW onn Windows,
W dows, M Ma
Mac OS X or Linux systems. Use the
he Getting Started
Start windowdow to create
reate new
n projects and VIs. You can create items from scratch
or from templates aand samples.
ples.
es. You
Y can al l open existing LabVIEW files and access LabVIEW
also
Na

Object-Oriented
Object-Orien
bject-Orie
Object-oriented programming
Object-oriente
programmin
programming languages.
classs of ob
amming is a p
ages.
pop
popular programming approach across a wide variety of
ges. It allows a variety of similar, yet different items, to be represented as a
objects in software. LabV
niques
niqu
programming techniques
La bV
LabVIEW
es in G ccode.
provides tools and functions so you can use object-oriented
Na
ommunity
mmunity resou
community resources and

The Getting S
appears when
reappears w
d help.
elp.

Started window disap


disapp
disappears when you open an existing file or create a new file, and
youu close all open front panels and block diagrams. You can display the window
tim by selecting
at any time ecting ViewG
ViewGetting Started Window.

National Instruments | 1-3 1-4 | ni.com


LabVIEW Core 1 Course Manual Lesson 1 Navigating LabVIEW

B. Project Explorer 2. Search for the template or sample project that supports the goal you want the project to
p projects:
accomplish. Use the following features to search for templates and sample
VIs are LabVIEW programs, and you can use multiple VIs together to makee a LabVIEW
La
L FiltersDisplays only results of a certain type, such as templatess orr sample
sampl
sam projects for a
application. To group these application-related VIs together, use a LabVIEW
VIEW project. When you
W projec specific target.

uti ts

uti ts
save a LabVIEW project from the Project Explorer window, LabVIEW IEW
W creates a ppr
project file
(.lvproj), that includes references to all the LabVIEW files and non-LabVIEW
-LabVIEW files
f in the criptions
tions of the fi
Additional SearchSearches the keywords, titles, and descriptions filtered results.
yment
ent information.
project, configuration information, build information, and deployment informati More InformationOpens the help file for the item. Reviewvieww the help fi
file to ensure that

rib en

rib en
antt the
the template or sample project supports the goal you want he project to
t accomplish.
mplish
Some LabVIEW applications, such as simple VIs, do not need ed too use a LabVIEW
LabV project.
ct.
3. Click the Next or Finish button to configure details of thee project,
oject, including
incl
includ
ud how w thee project is
ationss and share
However, you must use a project to build stand-alone applications sha ries. In addition,
shared libraries.

on

on
saved. After you finish configuring the project, LabVIEWEWW saves the project
p pens the
and opens
achine
you must use a project to work with non-development machine ine targets su such as real-time
-time (RT),
Project Explorer window and the top-level VI of the he project.
roject.
gital
field-programmable gate array (FPGA), or personal digitalal assistant (PDA)
((P argets. Refer to th
targets. the

ist um

ist um
specific module documentation for more information n about
out using propr
projects with
ith the LabVIE
LabVIEW 4. Use the Project Explorer window to modify the project.ject. Refer
Refer to the comments
mments on the bblock
Real-Time, FPGA, and PDA modules. ion about how to modify
diagrams of VIs in the project for more information fy the project. Al
Also refer
to the Project Documentation folder in the Project Explorer window
ect Explor
Explore ow for more inf
information
about how to modify the project.
Project Explorer Window
Projects in LabVIEW consist of VIs, files necessary
ecessary for tth
those VIss to run properly
properly, and
r D str

r D str
supplemental files such as documentationn or related links.
link Use the Project Ex Explorer window to
Exp
Project-Related Toolbars
manage projects in LabVIEW. Use the Standard, Project, Build, and Source Control toolbar
urce Contro arr buttons to perf
pe
perform
r operations in a
vailabl
blee at the tto
LabVIEW project. The toolbars are available top of thee Project Explorer window, as shown
oject Explor
cludes
es the follow
The Project Explorer window includes ms by default:
following items xpand
nd the Proje
in Figure 1-2. You might need to expand Project Explorerlorerr window to view all of the toolbars.
t fo l In

t fo l In
Project rootContains all other items in th the Project window. The label on the
ect Explorer wi
w Figure
gure 1-2. Proje
Pro
Project Explorer
plorerr Window
me for the pproject.
project root includes the filename
1 2 3 4
sents the local
esents
My ComputerRepresents al ccomputer
er as a target in tthe project.
cludes
es VIs and items that
DependenciesIncludes at VIs under a target
tar require.
ta
Includes build
Build SpecificationsIncludes
ionsIncludes b configurations
nfigurations for source distributions and other types
No na

No na
of builds available
able in LabVIEW toolkits andd modules. If you have the LabVIEW Professional
Developmentt System
stem or Appl
App
Applicationn Build
uild installed,
Builder stalle you can use Build Specifications to
tand-alone
d-alone applications,
configure stand-alone appli s, shared
ared libr
libraries, installers, and zip files.
tio

tio
Tip
ip A targett is any device
vice that can run a VI.

When you add another target to thee project


project, LLabVIEW creates an additional item in the Project
plorer
Explorer ent
nt the
er window to represent th target.
ett. Each
E target also includes Dependencies and Build
Specifications se
sec
pecifications sections. fi under each target.
You can add files
Na

Complete the ffollowing


Projects.
elect FileCreate
1. Select
ng steps to use th
the Project Explorer window to create and edit LabVIEW

reate Project tto display the Create Project dialog box. The Create Project
des a list of templates and sample projects you can use to ensure that the project
dialog box includes
Na
1
2
3
4
Standard Toolbar
Project Toolbar
Proje
Build
uild Toolbar
Source Control Toolbar
8 7

5
6
7
8
6 5

Project Root
Target
Dependencies
Build Specifications
ble ddesigns and programming practices.
you create uses reliable
Tip The Source Control toolbar is only available if you have source control configured
in LabVIEW.

National Instruments | 1-5 1-6 | ni.com


LabVIEW Core 1 Course Manual Lesson 1 Navigating LabVIEW

You can show or hide toolbars by selecting ViewToolbars and selecting the toolbars you want to Select the VI icon in the upper right corner of a front panel or block diagram window and drag
show or hide. You can also right-click an open area on the toolbar and select the toolbars you want the icon to the target.
to show or hide. Select an item or folder from the file system on your computer and dragg it to
t the
th target.

uti ts

uti ts
Creating a LabVIEW Project Removing Items from a Project
Complete the following steps to create a project. You can remove items from the Project Explorer window in thee following
llowing way
ways:

rib en

rib en
1. Choose one of the following actions to create a new LabVIEW
IEW
W project
project. Right-click the item you want to remove and select Remove Project from the shor
ove from Projec
Proj shortcut
In the Getting Started window, click Blank Project ct to open a blan ect orr click the
blank project menu.

on

on
emplate.
plate.
Create Project button to create a project from a template. e>.
Select the item you want to remove and press <Delete>.
In an open LabVIEW project or VI, select FileCreate
Create
reate Proje
Projec
Project.

ist um

ist um
Select the item you want to remove and click the Remove Project button on the
move From P
In any LabVIEW window, select FileNew. Then en select ProjectEmpty
Pr
Pro pty Project in the
Empty Standard toolbar.
New dialog box to display the Project Explorer
rer window.
plorer window
ct under
2. Add items you want to include in the project nder a target.
targe
target Note Removing an item from a project
ect does not delete
del the item
m on disk.
oject..
3. Select FileSave Project to save the project.
Organizing Items in a Project
oject
ect
r D str

r D str
Adding Existing Files To
o A Project
Projec The Project Explorer window includess two wo pages, the Items page and the File Files page. The Items
Fi
y exist
page displays the project items as they st in the project
pro
p e. The Files pag
tree. page displays the project
You can add existing files to a project.
ct. Use the My C Computer ter item
tem (or othe
other target) in the Project
items that have a corresponding file on disk. You ca nize filenames aan
can organize and folders on this page.
Explorer window to add files such h as VIs or text files, to
o a LabVIEW project.
pr
age both reflect aand update
Project operations on the Files page date
te the contents
conte on disk. You can switch
t fo l In

t fo l In
followin ways:
You can add items to a project in the following
ght-clicking a ffolder orr item
from one page to the other by right-clicking m under a ta
target and selecting Show in
Items View or Show in Files View from the shortcut ut menu.
enu
Right-click My Computer
uter ct AddFile
ter and select A e from the shor
shortc
shortcut menu to add a file. You also
can select ProjectAdd ProjectFile from
dd To Proj m thee Project E
Explorer menu to add a file. tems in the Project Explorer
Use folders to organize items orer window. Y
plorer You can add two types of folders
get and select Ad
Right-click the target A d der (Auto-populating)
AddFolder (Auto-popu from the shortcut menu to to a LabVIEW project, virtual ual folders and
a auto-populating
-populating folders.
fold Virtual folders organize project
arget in the Proj
items. Right-click a target Pro lorer window
plorer
Project Explorer ndow aand select NewVirtual Folder from
No na

No na
ulating
add an auto-populating g folder. Y
Yo
You also can
an sele
select Proje
Pro
ProjectAdd To ProjectAdd Folder
(Auto-populating) a pu
ting)) to add an auto-populatingg folder. L
LabVIEW continuously monitors and the shortcut menu too create
reate a new
new virtual
v r. Auto-populating
folder. Auto-pop folders update in real time to
updates the folderr according to changes
nges made
mad
m in the project and on disk. ts off folders on ddisk. Add
reflect the contents dd an aauto-populating
popu
popul folder to the project to view project
ppear
items as they appearar on disk.
Right-clickck the
he target or M mputer
My Computer er and sele
select AddFolder (Snapshot) from the shortcut
tio

tio
menu to add a virtual ffo ou also
folder. You lso can sele
selec
select ProjectAdd To ProjectAdd Folder lating
ating folders ar
Auto-populating are visiblee only on the Ite
te page of the Project Explorer window. You
IItems
ot) to add a vvirtual folder.
pshot)
(Snapshot) older. When yo you select a directory on disk, LabVIEW creates a can view thehe disk content
contents of ann auto-populating
auto-populatin folder but you cannot perform disk operations
w virtual
new irtual folder in the project
ject
ct with the same
sa name as the directory on disk. LabVIEW also such ass renaming,
naming, reorganizing,
reorg
reor nd removing project items. To perform disk operations of items
and
reates
es project items
creates ite that rep ent
nt the contents
represent cco of the entire directory, including files and n auto-populating
in an to-populatin folder, use tthe Files
iles pa
ppage of the Project Explorer window. The Files page
contents
tents of subdirectories.
subd ies.
s. Selecting
Sel
Select a folder on disk adds contents of the entire folder, plays the locati
displays locatio oject
ect fold
location of project folder
folders on disk. Project operations on the Files page both update
Na

including file

Note
No After
ter
ontents
ents of subfo
files and contents subfolders.

er you add a virtual


aautomatically
vir
vi folder on disk to a project, LabVIEW does not
ically update the folder in the project if you make changes to the folder on disk.
Na
nd
andd reflect the co
auto-populating
LabVIEW.

You can
contents of the

n aarrange items
he folder on disk. Likewise, LabVIEW automatically updates the
auto-populatin folderr in the projec
project if you make changes to the folder on disk outside of

tems in a folde
folder. Right-click a folder and select Arrange ByName from the
get and select NewVI from the shortcut menu to add a new, blank VI. You
Right-click the target nge item
shortcut menu to arrange items in alphabetical order. Right-click a folder and select Arrange By
also can select FileNew VI or ProjectAdd To ProjectNew VI to add a new, blank VI. Type from the shortcut menu en to arrange items by file type.

National Instruments | 1-7 1-8 | ni.com


LabVIEW Core 1 Course Manual Lesson 1 Navigating LabVIEW

Viewing Files in a Project C. Parts of a VI


When you add a file to a LabVIEW project, LabVIEW includes a reference ce to tthe file on disk.
LabVIEW VIs contain three main componentsthe front panel window, thee block
bloc
bl diagram, and
Right-click a file in the Project Explorer window and select Open from the shortcut menu to open
the icon/connector pane.
the file in its default editor.

uti ts

uti ts
Right-click the project and select ViewFull Paths from the shortcut
ut menu to view where files that Front Panel Window
a project references are saved on disk.

rib en

rib en
The front panel window is the user interface for the VI. Figure 1-3 shows an exeexample of a ffront
Use the Project File Information dialog box to view wheree fileses that a proj erences
nces are
project references panel window. You create the front panel window with controls ols and indicato ch are
indicators, which re the
ly.
interactive input and output terminals of the VI, respectively.

on

on
located on disk and in the Project Explorer window. Select
ct ProjectFile
rojectFile Information
mationn to display
ght-click
click the project
the Project File Information dialog box. You also can right-click pro andd select
lect ViewF
ViewFile Figure 1-3. VI Frontt Panel
anel

ist um

ist um
Information from the shortcut menu to display the Project
roject
ct File Info
Infor
Information n dialog box.

Saving a Project
You can save a LabVIEW project in the following
wing
g ways:
Select FileSave Project.
r D str

r D str
Select ProjectSave Project.
Right-click the project and select Save from the sshortcut menu.
nu.
Click the Save Project button on the
he Project ttoolbar.
t fo l In

t fo l In
You must save new, unsaved filess in a project before
b you can save the project. When you save a
project, LabVIEW does not save dependencies
pendenci
pende nci as part
art of the project file.

Note Make a backup


ckup copy of a project
ect when you pre
prepare to make major revisions to
the project.
No na

No na
tio

tio
Na

Na
National Instruments | 1-9 1-10 | ni.com
LabVIEW Core 1 Course Manual Lesson 1 Navigating LabVIEW

Block Diagram Window Opening an Existing VI


After you create the front panel window, you add code using graphical representations
esenta of functions Select Browse in the Open list in the Getting Started window to navigate to and oopen an existing VI.
ck diagram window. The
to control the front panel objects. Figure 1-4 shows an example of a block
block diagram window contains this graphical source code. Front panell objects appear
appea as terminals

uti ts

uti ts
Tip The VIs you edit in this course are located in the <Exercises>\LabVIEW
ercises>\Lab
rcises>\La
on the block diagram. Core 1 directory.

Figure 1-4. Block Diagram

rib en

rib en
ample
le might appear.
As the VI loads, a status dialog box similar to the following example ap
app

Figure 1-5. Dialog Box Indicating the Status


atus of Loading VIs

on

on
ist um

ist um
r D str

r D str
t fo l In

t fo l In
Icon and Connector
cto Pane
ane The Loading section lists the
he su
subVIs off the V
VI as they
hey load
ad into m
mem
memory and shows the number of
The Icon and Connector pane allows you to use and view a VI in another VI. A VI that is used in subVIs loaded into memoryry so far. Y el the load at any time by clicking the Stop button.
You can cancel
ubVI,
VI, wh
another VI is called a subVI, which
ich is ssimilar to
o a function in a text-based programming language.
mmediately
diately loca
If LabVIEW cannot immediately bVI, it begins se
locate a subVI, sea
searching through all directories
VI, it must have an icon and a connec
To use a VI as a subVI, connecto
connector pane.
No na

No na
specified by the VI search
rch path. You can edit the VI searc
search path by selecting ToolsOptions and
ys ann icon in the upper rightt corner
Every VI displays cco th front panel window and block diagram
of the om the Categor
selecting Paths from Category list.
xample
window. An exampleple of the default
def
de on iss sho
icon shown below. An icon is a graphical representation of
bVIEW igno
You can have LabVIEW ignor a subVI
ignore bVI byy clicking
click the Ignore Item button, or you can click the
on can
a VI. The icon n contain bo
both text andd images. If yyou use a VI as a subVI, the icon identifies the
ton to search ffor the missing
Browse button issing
ng subVI.
tio

tio
he block diagram of the VI. The default iicon contains a number that indicates how many
subVI on the
ou opened after
new VIs you afte launching
hing
ing LabVIEW
LabVIEW.
Na

To use a VI as a subVI,, youu needd to build


set of termina
rameter list
parameter l of a function call
yed next to the
displayed
bui a connector pane, shown below. The connector pane is a
terminals on thee icon that corresponds
corr
corre to the controls and indicators of that VI, similar to the
call in text-based programming languages. The connector pane is
he VI icon in th
tthe upper right corner of the front panel window. You cannot access
Na
the connector pane fromom the icicon in the block diagram window.

National Instruments | 1-11 1-12 | ni.com


LabVIEW Core 1 Course Manual Lesson 1 Navigating LabVIEW

Saving a VI D. Front Panel


To save a new VI, select FileSave. If you already saved your VI, select File
FileSave As to access
When you open a new or existing VI, the front panel window of the VI appears.
ppears.
ears TThe front panel
the Save As dialog box. From the Save As dialog box, you can create a copypy of the VI, or delete
window is the user interface for the VI. Figure 1-7 shows an example of a front panel
pane window.
the original VI and replace it with the new one.

uti ts

uti ts
Figure 1-7. Example of a Front Panel
el
Figure 1-6. Save As Dialog Box

rib en

rib en
1

on

on
2

ist um

ist um
r D str

r D str
t fo l In

t fo l In
1 Front Panel Window 2 Toolbar 3 Controls Palette

Controls and Indicators


dicators
No na

No na
Note fer to the Save A
Refer As Dialogg Box topic of th
the LabVIEW Help for detailed
tion about each option
information o n the Save
in ave As ddi
dialog box. You create the front
nt panel
anel with con
controls and
nd indicators,
cators, w
which are the interactive input and output
respectively Controls
terminals of the VI, respectively. ols are knobs,
kn pu buttons, dials, and other input devices.
push
Indicators are graphs,
phs, LEDs anaand other
er displays.
plays. Con
Controls simulate instrument input devices and
supply data to the block didiag
diagram off thee VI. Indicato
Indicat
Indicators simulate instrument output devices and
tio

tio
ataa the block diagram
display data diag cquires or gene
acquires genera
generates.

Figuree 1-7 has the following


foll ts: two cont
objects: co
controls: Number of Measurements and Delay(sec). It
raph
has one indicator: an XY graphph named
nam
n Tem
Temperature Graph.
Na

Na
he user can change
The

about
cha
ch
s the value generate
The user can see
thee input
put value for the Number of Measurements and Delay(sec) controls.
generated bby the VI on the Temperature Graph indicator. The VI
th valuess for the indicators
generates the indicato based on the code created on the block diagram. You learn
Control and Indicators section.
Contr
ut this in the Numeric Controls

tor has
Every control or indicator ha a data type associated with it. For example, the Delay(sec) horizontal
slide is a numeric data type. The most commonly used data types are numeric, Boolean value and
string. You learn about other data types in Lesson 3, Implementing a VI.

National Instruments | 1-13 1-14 | ni.com


LabVIEW Core 1 Course Manual Lesson 1 Navigating LabVIEW

Numeric Controls and Indicators String Controls and Indicators


The numeric data type can represent numbers of various types, such as integer
eger or real. The The string data type is a sequence of ASCII characters. Use string controls to re
receive text from the
two common numeric objects are the numeric control and the numeric indicator,
cator, aas shown in
ndicator, user such as a password or user name. Use string indicators to display text
ext to the user.
uus The most
Figure 1-8. Objects such as meters and dials also represent numeric data.
ata.
a. common string objects are tables and text entry boxes as shown in Figure
ure 1-10.
gure

uti ts

uti ts
Figure 1-8. Numeric Controls and Indicators
ators
rs Figure 1-10. String Controls and Indicators
ators
rs

rib en

rib en
1 2

on

on
ist um

ist um
3

1 Increment/Decrement Buttons 3 Numeric Indicator


Nu tor
2 Numeric Control

To enter or change values in a numeric control,


trol,
ol, click the increment
iinc and decrement bbuttons with the
r D str

r D str
er with
Operating tool or double-click the number ith either the Labeling
ng tool
tool or the Operating
Op
O tool, enter Controls Palette
a new number, and press the <Enter> key. The Controls palette contains the controls
trols and indicators
indicat
indica youu use to create th
the front panel. You
nt panel window
access the Controls palette from the front wind by selecting
win ecting View
ViewControls Palette. The
Boolean Controls and Indicators
ndicators
icators rious
us categories;
Controls palette is broken into various categories you canan
n expose some or all of these categories
t fo l In

t fo l In
hows a Control
to suit your needs. Figure 1-11 shows Controls palettee with all of the categories exposed and the
The Boolean data type representss data that only
onl has twoo possible
ossible states,
states such as TRUE and FALSE
Silver category expanded. During this course cises use controls
course, most exercises con
co from the Silver
or ON and OFF. Use Boolean controlss and indindicators to enter
nter and disp
display Boolean values. Boolean
category.
bu
objects simulate switches, push buttons, an LEDs.
and s.. The vertical toggle
t
to switch and the round LED
wn in Figure 1-9.
Boolean objects are shown
Figure 1-9.
1-9 Boolean
an Controls a
and Indicators
No na

No na
tio

tio
Na

Na
National Instruments | 1-15 1-16 | ni.com
LabVIEW Core 1 Course Manual Lesson 1 Navigating LabVIEW

Figure 1-11. Controls Palette While the VI runs, the Run button appears as shown below if the VI is a top-level VI, meaning it
has no callers and therefore is not a subVI.

uti ts

uti ts
wn below.
If the VI that is running is a subVI, the Run button appears as shown

rib en

rib en
on

on
The Run button appears broken when the VI you are creating tingg or editing co
contains errors.
ors. If the Ru
R
Run
lockk diagram,
button still appears broken after you finish wiring the block diagram, the
th VI iss broken and cannot
can

ist um

ist um
w, which lists aall errorss and warnings.
run. Click this button to display the Error list window,

Click the Run Continuously button to run the hee VI until you aabort orr pause
use execution
execution. You also can
r D str

r D str
us running.
click the button again to disable continuous
t fo l In

t fo l In
ecution button appears.
While the VI runs, the Abort Execution s. Click this
this bu
butt
button to stop the VI
ay to stop th
immediately if there is no other way the VI. If more
re than one rru
running top-level VI uses the
VI, the button is dimmed.
To view or hide categories (subpa
(subpalettes), select
se thee Customize but
bu
button on the palette, and select or
deselect in the Change Visible Palettes option.
ble Palett
No na

No na
Front Panel Window Toolbar
T ar Caution The
he Abort ExExecutionn bbutton
n stops th
the VI immediately, before the VI finishes
Each window has as a toolbar
oolbar associated
assoc
asso with it. Use
U the
he front
ffr panel window toolbar buttons to run rrent iteration. A
the current g a VI ttha
Aborting es external
that uses e resources, such as external
I.
and edit the VI. dware,
re, might leave
hardware, lea
leav the resources
rces in an unknown state by not resetting or releasing
em properly. Design
them Des
De Is with
VIs ith a stop but
bu
button to avoid this problem.
tio

tio
wing
ing toolbar appears
The following app
appe on the front panel w
window.
Click thee Pause
Paus button to pause a running VI. W When you click the Pause button, LabVIEW
ightss on the block
highlights bloc diagram
am the location where you paused execution, and the Pause button
ears red. Click th
appears the Pausee butto
button again
inn tto continue running the VI.
Na

lick
ick the Run but
Click
app
Run button appears
can use the VI
V as a subVI
un a VI. LabVIEW
button to run LabV
lid white arrow,
as a solid arr
ubVI if you create
compiles the VI, if necessary. You can run a VI if the
shown below. The solid white arrow also indicates you
cre a connector pane for the VI.
crea Naect the Text
Select T ettings pull-dow
Settings pull-down menu to change the font settings for the selected portions of
the VI, iincluding size, style, and color.

National Instruments | 1-17 1-18 | ni.com


LabVIEW Core 1 Course Manual Lesson 1 Navigating LabVIEW

Select the Align Objects pull-down menu to align objects along axes, including vertical, top edge, E. Block Diagram
left, and so on.
Block diagram objects include terminals, subVIs, functions, constants, structures,
uctures,
ures aand wires, which
transfer data among other block diagram objects.

uti ts

uti ts
Figure 1-12. Example of a Block Diagram and Corresponding
onding
ing Front Panel
Pa
Select the Distribute Objects pull-down menu to space objects evenly,
ly, including gaps,
venly,
compression, and so on.

rib en

rib en
on

on
ultiple
ple front pa
Select the Resize Objects pull-down menu to resize multiple pan cts to the same ssize.
panel objects

ist um

ist um
Select the Reorder pull-down menu when you u ha
haveve objects th rlap each other aand you want
that overlap
otther.
her. Select on
to define which one is in front or back of another. one of thee objects
ects with th
the Positioning
r D str

r D str
tool and then select from Move Forward, Move ove Backwa
Backwar Move
Backward, Front and Move To Back.
ve To Front,
t fo l In

t fo l In
Enter search terms to locate content LabV
LabVI
ent in the LabVIEW elp
p.
Help.
4 3 2 1

1 Indicator Terminals 2 Wires


s 3 Nodes 4 Control Terminals

Select the Show Context Windo buttonn to toggle the


xt Help Window the display
ddis of the Context Help window.
Terminals
No na

No na
Objects on the frontt panel
nel window aappear as term
terminals
inals on tthe block diagram. Terminals are entry
and exit ports that exchange
hange information
inform betw
between fron panel and block diagram. Terminals are
the front
rameters
analogous to parametersters and co
con
constants in text-b
ext- a
text-based programming languages. Types of terminals
pears
rs to remind you
Enter Text appears y thatt a new
ew value
v is available to replace an old value. The Enter ol orr indicator terminals
include control te s and node terminals.
tterm Control and indicator terminals belong
Text button disappears when you click
lick it, press the <Enter> key, or click the front panel or block
tio

to front panel

tio
nel controls and iindicators.
ors. Dataa you enter
en
ent into the front panel controls (a and b in the
orkspace.
diagram workspace. previous front
nt panel) enter the block
ock diagram through
thro
thr the control terminals. The data then enter the
Add and d Subtract functi
funct
functions. When en
n the Add and Subtract functions complete their calculations, they
uce new data values.
produce valu
val Thee data
da values
alues flow
fl
flo to the indicator terminals, where they update the
nt panel
front anel indicato
indicators (a+b and ndd ab he previous front panel).
a in the
Na

Tip

En
E
The <Enter>
T

ment
Environment
ter>
key aadds a new

ey option.
Enter key
> key on the numeric keypad ends a text entry, while the main <Enter>
ew line. To m
mod
modify this behavior, select ToolsOptions, select the
ent from the Ca
Category list, and place a checkmark in the End text entry with
C Na
The terminals in Figuree 1-12
represent the inputs
or exampl
For example
displayy the
i
12 belong to four front panel controls and indicators. Because terminals
nd outputs off your
and
onnector panes of
example, the connector
th terminals
als of the func
funct
y
you VI, subVIs and functions also have terminals shown below.
o the Add and Subtract functions have three node terminals. To
function on the block diagram, right-click the function node and select
minals from the shortcut menu.
Visible ItemsTerminals

National Instruments | 1-19 1-20 | ni.com


LabVIEW Core 1 Course Manual Lesson 1 Navigating LabVIEW

Controls, Indicators, and Constants You can view terminals with or without icon view. Figure 1-15 shows the same block diagram
without using the icon view of the terminals; however, the same distinguishing characteristics
Controls, indicators, and constants behave as inputs and outputs of the block
ck ddiagram algorithm.
between controls and indicators exist.
Consider the implementation of the algorithm for the area of a triangle:

tio s
Figure 1-15. Area of a Triangle Block Diagram without Icon

uti ts
on
n Terminal View
Vie
Area = .5 * Base * Height

ibu nt
In this algorithm, Base and Height are inputs and Area is an output,
put,, as shown in Figure 1-13.

rib en
Figure 1-13. Area of a Triangle Front
ont Panel

on
str me

ist um
Block Diagram Nodes
Nodes are objects on the block diagram that havee inputs
nputs and/or outputs
o andd perform operations
op

Di tru ents,, operators, ffunctions,


when a VI runs. They are analogous to statements,
text-based programming languages. Nodes can be functions
ns, and subroutines
subroutin in
Is, or structures. Structures are
functions, subVIs,

r D str
uctures,
tures, For Loops,
process control elements, such as Case structures, Loo
Lo Th Add and
or While Loops. The
Subtract functions in the Figure 1-12 aree function
nction nodes
nodes.
s
The user never changes or accessess thee constant .5
.5, so it does
es not appear oon the front panel unless Functions
l In

t fo l In
included as documentation of thee algorithm. Functions are the fundamental operating
perating
pe rating element
elements of LabVIEW.
bVIEW.
VIEW. Functio
F
Functions
uncti do not have front panel
windows or block diagram windows ws but do have
hav connector
ha ector
or panes. Double-clicking
Dou a function only
Figure 1-14 shows a possiblee implementation
i entation of this algorithm on a LabVIEW
L block diagram. This io has a pale y
selects the function. A function ye ackground on its icon.
yellow background
ferent
erent te
block diagram has four different terminals created by two controls
controls, one constant, and one indicator.
Figure 1-14.
14. Area of a Tr
Triangle Block Diagram w
with Icon Terminal View SubVIs
SubVIs are VIs that you create
reate to us
use inside of another VI or that you access on the Functions
No na

No na
palette.

Any VI has thee potential


tential to be uused as a subVI.
ubV When
W you double-click a subVI on the block
diagram, its front panel wind pears.
window appears. s. The front
fron panel
p includes controls and indicators. The
tio

tio
ram
block diagramam includes wires,
wi
wir icons,ns, functions, pos
possibly subVIs, and other LabVIEW objects. The
ghtt corner of the front panel
upper right anel
nel window and
an block diagram window displays the icon for the
is iss the icon that
VI. This tha appears whenhen you place
pla the VI on a block diagram as a subVI.

bVIs can also b


SubVIs be Express
ss VIs. Exp
E
Express V
VIs are nodes that require minimal wiring because you
Na

1 3 2

Na
configure
nfigure them with
w dialog og boxes.
boxes. Use EExpress VIs for common measurement tasks. You can save
t

configuration of an Express VI as a subVI. Refer to the Express VIs topic of the LabVIEW Help
the configuratio
1 Controls 2 Indicator 3 Constant
for more info
information n about creating a subVI from an Express VI configuration.
Notice
ce that
tha the Base
ase (cm) and He
Height (cm) block diagram terminals have a different appearance
H
from the Area (cm2) terminal. There
T are two distinguishing characteristics between a control and EW uses colored
LabVIEW olored icons to distinguish between Express VIs and other VIs on the block
ck diagram.
an indicator on the block diag
dia The first is an arrow on the terminal that indicates the direction xpress VIs
diagram. Icons for Express VI appear on the block diagram as icons surrounded by a blue field
V
of data flow. The controls have arrows showing the data leaving the terminal, whereas the indicator whereas subVI icons havee a yellow field.
has an arrow showing the data entering the terminal. The second distinguishing characteristic is the
border around the terminal. Controls have a thick border and indicators have a thin border.

National Instruments | 1-21 1-22 | ni.com


LabVIEW Core 1 Course Manual Lesson 1 Navigating LabVIEW

Expandable Nodes versus Icons Wires


You can display VIs and Express VIs as icons or as expandable nodes. Expandable
pand nodes appear You transfer data among block diagram objects through wires. In Figure 1-12,-12, w
wires connect the
as icons surrounded by a colored field. SubVIs appear with a yellow field,
d, and
nd Express
Expr VIs appear control and indicator terminals to the Add and Subtract function. Each wiree has a single
si data
with a blue field. Use icons if you want to conserve space on the block
k diagram. Use expandable source, but you can wire it to many VIs and functions that read the data.
a. Wires are different
dif
diff colors,

uti ts

uti ts
nodes to make wiring easier and to aid in documenting block diagrams.
ms. By de ult, ssubVIs appear
default, styles, and thicknesses, depending on their data types.
ble nodes. To di
as icons on the block diagram, and Express VIs appear as expandable dis
display a subVI or
ess VI and
Express VI as an expandable node, right-click the subVI or Express and rem
remo
remove the chcheckmark A broken wire appears as a dashed black line with a red X in the middle,
ddle, as show
sho ow Broken
shown below.

rib en

rib en
next to the View As Icon shortcut menu item. wires occur for a variety of reasons, such as when you try to wiree two objects with incompatible
ncompati
mpati
data types.

on

on
asier,
er, but it also takes a largee amount of
You can resize the expandable node to make wiring even easier,
ps too resize a no
space on the block diagram. Complete the following steps node on the block diagram
diagra
diagram:

ist um

ist um
1. Move the Positioning tool over the node. Resizingg handles
ndles appear at the top
op and bottom oof the Table 1-1 shows the most common wire types.
node.
ange
ge the cursor to the resizing
2. Move the cursor over a resizing handle to change zing cursor. Table 1-1. Common
mon
n Wire Types
Type

3. Use the resizing cursor to drag the border off the node dow isplaay additional terminals.
down to display Wire Type Scalar 1D Array 2D A
Array Color
Co
4. Release the mouse button.
r D str

r D str
Numeric Orange (fl
(floating-point),
Blue (i
(integer)
To cancel a resizing operation, drag thee node
de border past the block
border pa window before you
lock diagram w
release the mouse button.
Boolean Green
Gr
ction Generator
Figure 1-16 shows the Basic Function Generator VI as a resized
esized expand
expan
expandable node.
t fo l In

t fo l In
String Pink
Figure 1-16. Basic Function Generator
G or VII in Different Display Modes
In LabVIEW, you use wiress to connect
co mul
multiple rminals together
terminals togethe to pass data in a VI. You must
ts andd outpu
connect the wires to inputs ompatible
mpatible with th
outputs that are compatible the data that is transferred with the
wire. For example, you u cannot
nnot wire an
an array output
utput to a numer
numeric input. In addition the direction of
rrect. You must cconnect the
the wires must be correct. he wires to on
only one input and at least one output. For
No na

No na
not wire two indi
example, you cannot her. The com
indicators together. co
components that determine wiring
cludee the data type
compatibility include typ
ty of thee cont
ont and/or
control nd/or the indicator and the data type of the
terminal.
tio

tio
Data Types
pes
Data types
ypess indicate what
wha
wh objects,, inputs, and ooutputs you can wire together. For example, if a
switchh has
as a green bo ou ca
border, you ire
re a sw
can wire switch to any input with a green label on an Express VI.
If a knobb has an ora rder,
er, you
orange border, yo ccan wi
wire a knob to any input with an orange label. However,
Na

Note If youu display


the terminals
als
play a subVI
subV or Express VI as an expandable node, you cannot display
ls for that node and you cannot enable database access for that node. Na
youu cannot wire aan orange
as the terminal.
ge knob to an ininput with a green label. Notice the wires are the same color

National Instruments | 1-23 1-24 | ni.com


LabVIEW Core 1 Course Manual Lesson 1 Navigating LabVIEW

Automatically Wiring Objects Figure 1-17. Functions Palette


As you move a selected object close to other objects on the block diagram,, LabVIEW
Lab draws
temporary wires to show you valid connections. When you release the mouse button to place the
se butto
object on the block diagram, LabVIEW automatically connects the wires.res. ccan
es. You also ca

uti ts

uti ts
automatically wire objects already on the block diagram. LabVIEW connects
onnects the terminals
ter that
best match and does not connect the terminals that do not match.

rib en

rib en
Toggle automatic wiring by pressing the spacebar while you movee an object using
us thee Positioning
Positio
sitio
tool.

on

on
ons palette oor
By default, automatic wiring is enabled when you select an object from the Functions
nctions
when you copy an object already on the block diagram m byy pressing th
the <Ctrl>
> key and drag
draggi
dragging

ist um

ist um
the object. Automatic wiring is disabled by default whenn you use th ioning
ning tool to mo
the Positioning move an
object already on the block diagram.

You can adjust the automatic wiring settings byy selecting


electing Tool
Too ions and selectin
ToolsOptions selecting Block
Diagram from the Category list.
r D str

r D str
Manually Wiring Objects
When you pass the Wiring tool over a terminal,
rminal, a ti
tip strip appears
ppears
ars with the nname of the terminal.
In addition, the terminal blinks in thehe Context Help window ow and
nd on the ico
icon to help you verify that
t fo l In

t fo l In
minal. To wire o
you are wiring to the correct terminal. ob ogether,
ether, pass the
objects together, th Wiring tool over the first
terminal, click, pass the cursor overver the second
secon terminal,
nal, and click again.
ag
aga After wiring, you can
right-click the wire and selectct Clean Up W Wire from
Wi m the shortcut me
menu to have LabVIEW To view or hide categories, clic
click the Customize
usto
ustom button
utton on the pa
pale
palette, and select or deselect the
automatically choose a path thh for th
the wire. IIf you have
ave
ve broken wire
wires to remove, press <Ctrl-B> to Change Visible Palettes option.
tion.
res on the bloc
delete all the broken wires block diagram.m.

Block Diagram
am
m Toolbar
Toolba
No na

No na
Functions Palette
ette
When you run a VI, buttons appea
appear on thee blo
block diagram
agram toolbar that you can use to debug the VI.
The Functions palette te contains the
t VIs, s, functions
functio
ncti andd constants
c you use to create the block The following toolbar
ar appears oon the block
k dia
diagr
diagram.
diagram. You accessess the Func
Functions palette
Fun alettee from the block diagram by selecting ViewFunctions
pale is broken
Palette. The Functions palette roken n into various
variou
vario categories; you can show and hide categories
tio

tio
ur needs. Figure 1-17 shows
to suit your hows a Function
Functions palette with all of the categories exposed and
Functio
amming cat
the Programming
gramming categ anded.
nded. During tthis course, you work mostly in the Programming
category expanded.
ory, but you also use other
category, he categories,
tegories, or subpalettes. Click the Highlight EExecution buttontton to display
disp an animation of the block diagram execution
dis
whenn you
ou run the VI.
VI Noticee the flow
fflo off dat
data through the block diagram. Click the button again to
sable execution hhighlighting.
disable hting.
g.
Na

Na
National Instruments | 1-25 1-26 | ni.com
LabVIEW Core 1 Course Manual Lesson 1 Navigating LabVIEW

Click the Retain Wire Values button to save the wire values at each point in the flow of execution LabVIEW Help Utilities
so that when you place a probe on the wire you can immediately retain the most recent value of the
ast once
data that passed through the wire. You must successfully run the VI at least onc before you can Use the Context Help window, the LabVIEW Help, and the NI Example Finder
inder to help you create
retain the wire values. and edit VIs. Refer to the LabVIEW Help and manuals for more information
ationn about LabVIEW.

uti ts

tio s
Context Help Window

ibu nt
The Context Help window displays basic information about LabVIEW
bVIEW
EW objects when you
y move

rib en
Click the Step Into button to open a node and pause. When you ou click the Step Into button
on ag
again, p window se
the cursor over each object. To toggle display of the Context Help select HelpShow
elpSho
Sho
VI or structure.
it executes the first action and pauses at the next action of the subVI structu Youu alsoo can press Context Help, press the <Ctrl-H> keys, or click the Show Context
text Help Window
W button the
ton on th

on

n
str me
the <Ctrl> and down arrow keys. Single-stepping through a VI steps steps through
throu the VI node
ode by node.
node toolbar.
Each node blinks to denote when it is ready to execute.

ist um
When you move the cursor over front panel and blockock diagram ob he Context Help window
objects, the
nts, controls, an
displays the icon for subVIs, functions, constants, and indicators,
ators, with wires attached to

Di tru
Click the Step Over button to execute a node and pause at the next node.
ode. You also cacan press the
er the
<Ctrl> and right arrow keys. By stepping over he node, you execute
te thee node without
witho
with each terminal. When you move the cursor over er dialog box op
ooptions, the Context Hel
He window
Help
single-stepping through the node. displays descriptions of those options.
r D str
In the Context Help window, the labels of required term ppear bold, recommended
terminals appear recom
reco terminals
minals appear dimmed.
appear as plain text, and optional terminals dim
d laabels of optional
The labels opti
opt terminals do not

s
appear if you click the Hide Optionalnal Terminals and
a Full ath button iin the Context Help
ull Path
sh executing the
Click the Step Out button to finish th current
nt node and papause
pause. When the VI finishes window.
t fo l In

l In
executing, the Step Out button iss dimmed. Yo
You also can
an pre
ress
ss the <Ct
press <Ctrl> and up arrow keys. By
stepping out of a node, you completee single-s g through
single-stepping rough the nonode and navigate to the next
node.
Figure 1-18. Context
ontext
ntext Help Wind
Window
No na

No na
Click the Clean Up Diagram buttonbutt to automatically
auto cally
cally reroute
rer all existing wires and rearrange
lock diagram to ggenerate
objects on the block te a cleane
clea
cleaner layout. To configure the clean up options, select
ToolsOptions ns too display the Options
ns dialog
log box and
an select Block Diagram from the Category
n configure the ssettings in the
list. You can he Block Di
Dia
Diagram Cleanup section.
tio

tio
Thee Warning button
butt
but earss if a VI in
appears includes a warning and you placed a checkmark in the Show
Na

arning chec
Warnings check
checkbox in the Error List w window. A warning indicates there is a potential problem

Na
t
with the block diagram,
m, but it does no
not stop the VI from running.
Click
lick the
th Show
Sh Optional Termina and Full Path button located on the lower left corner of the
ptional Terminals
Termina
ext H
Context ndow to displa
Help window display the optional terminals of a connector pane and to display the full
al terminal
path to a VI. Optional terminals are shown by wire stubs, informing you that other connections
disp
exist. The detailed mode displays all terminals, as shown in Figure 1-19.

National Instruments | 1-27 1-28 | ni.com


LabVIEW Core 1 Course Manual Lesson 1 Navigating LabVIEW

Figure 1-19. Detailed Context Help Window NI Example Finder


Use the NI Example Finder to browse or search examples installed on yourr com
computer or on the NI
Developer Zone at ni.com/zone. These examples demonstrate how to use LabVIEWLabVIE to perform
a wide variety of test, measurement, control, and design tasks. Select HelpFind Examples
Exa
Ex or

uti ts

tio s
click the Find Examples link in the Examples section of the Getting Started wind
ng Starte window to launch
the NI Example Finder.

ibu nt
rib en
Examples can show you how to use specific VIs or functions. You can right-c
right-cli
l a VII or fun
right-click function
ples from the sho
on the block diagram or on a pinned palette and select Examples shortcut menuu to display

on

n
str me
a help topic with links to examples for that VI or function. You can
an modify
modif an example
mple VI to fit an
application, or you can copy and paste from one or moree examples
amples into a VI that
hat you
ou create.

ist um
Figure 1-20. NI Example
ample
ple Finder

Di tru
Click the Lock Context Help button to lock the
he current
urrent contents
conte of the Context Hel Help window.
ursor
rsor over anoth
When the contents are locked, moving the cursor ct does
another object oes nott chang
chan
change the contents
r D str ck the button ag
of the window. To unlock the window, click aga
again. Youu also
also can access this option from
the Help menu.

Ins
t fo l In

If a corresponding LabVIEW Help lp topic exist


exists for an object
ct the Conte
Context Help window describes,
p
a blue Detailed help link appears in the Con
Context Helpelp window. Als
Also, the More Help button is
he butt
enabled. Click the link or the isp the LabVIEW Help for more information about the
button to display
object.
No na

LabVIEW Help
elp
ss thee LabVIEW Help by clicking
You can access icking the M
More Help button in the Context Help window,
tio

elpLabVIEW Help, or clicking the bblue Detailed Help link in the Context Help
selecting HelpLabVIEW
window. You also can rig
ri k an object and select Help from the shortcut menu.
right-click

ti
VIEW Help contains
The LabVIEW c s deta
detailed descri
descr
descriptions of most palettes, menus, tools, VIs, and
ctions. The Lab
nctions.
functions. La
LabVIEW Help p also iinc
includes step-by-step instructions for using LabVIEW features.
Na

he LabVIEW H
The Help includes
ludes
es links to th
the following resources:

Na
t
No
entation Resou
LabVIEW Documentation Resour
Resources, which describes online and print documents to help new
and exp
expe d users and inclu
experienced includes PDF versions of all LabVIEW manuals.
Technical
chn support
port resources on the National Instruments Web site, such as the NI Developer
dgeBas and the Product Manuals Library.
dgeBase
Zone, the KnowledgeBase,

National Instruments | 1-29 1-30 | ni.com


LabVIEW Core 1 Course Manual Lesson 1 Navigating LabVIEW

F. Searching for Controls, VIs and Functions Double-click the search result to highlight its location on the palette. If the object is one you need
to use frequently, you can add it to your Favorites category. Right-click the object on the palette
When you select ViewControls or ViewFunctions to open the Controls
ols and Functions and select Add Item to Favorites, as shown in Figure 1-22.
palettes, two buttons appear at the top of the palette.

tio s

uti ts
Figure 1-22. Adding an Item to the Favorites Category
y of a Palette
SearchChanges the palette to search mode so you can perform text-based ext-based searches to locate
-based search

ibu nt
controls, VIs, or functions on the palettes. While a palette is in search
rch mode, click tthe Return button

en
to exit search mode and return to the palette.

on
str me
CustomizeProvides options for selecting a format for or the palette, showing
he current ppa hiding
howing and hidi

is um
ext and Tree formats
categories for all palettes, and sorting items in the Text for lphabetically.
phabetically. Se
alphabetically. Select
Options from the shortcut menu to display the Controls/Functions
ntrols/Function
ols/Function Palettes es page of the O
tes Options
dialog box, in which you can select a format for all palettes. This
Thi button n appears
pears only if you click

Di tru ette to pin the palette.


the thumbtack in the upper left corner of a palette pa

r D str
Until you are familiar with the locationn of VIs and
and fun
functions, search
earch for the fufunction or VI using
s
the Search button. For example, if you want to find the Random
andomm Number ffunction, click the
Search button on the Functions palettette toolbar an yping Random Number in the text box
and start typing
l In

t fo l In
W lists all matc
at the top of the palette. LabVIEW match ems that either sst
matching items start with or contain the text
you typed. You can click one of thee search results
res andd drag
rag it to the block
b diagram, as shown in
Figure 1-21.
Figure
e 1-21.
21. Search
Searching for an
n Object in the Functions
F Palette
No na

No na
Similar to the
he Search butto
button
button, you use thehe Quick DDrop dialog box to specify a palette object by
Dr
tio

tio
hen place the object
name and then o onn the
the block dia
diagr
diagram or front panel. In addition to palette objects,
you cann also
lso specify a project
p em
itemm by name in the Quick Drop dialog box.

lay the Quick Drop dialog bbox, pres


To display press <Ctrl-Space> or select ViewQuick Drop. Type the
Na

Na
ame
me of the objec
name ant to
object you want o add to tth
the block diagram or front panel. LabVIEW displays the
t

results in the Na atch


Name Match List. To att
h List. attach the object you select to the cursor, press the <Enter>
key, double-c
double-cl
double-click the name of the obobj
object in the list, or click the block diagram or front panel. Click
he location on the block diagram or
the o front panel where you want to add the object.

National Instruments | 1-31 1-32 | ni.com


LabVIEW Core 1 Course Manual Lesson 1 Navigating LabVIEW

Figure 1-23. Searching for an Object in the Quick Drop Dialog Box Operating Tool
When the mouse cursor changes to the icon shown below, the Operating tool ool is in operation. Use
re 1-25
the Operating tool to change the values of a control. For example, in Figure -25 the Operating
O tool
moves the pointer on the Horizontal Pointer Slide. When the mouse hovers vers over the pointer,
overs p the

uti ts

uti ts
cursor automatically accesses the Operating tool.

rib en

rib en
Figure 1-25. Using the Operating
ating Tool

on

on
ist um

ist um
r D str

r D str
G. Selecting a Tool
You can create, modify and debug VIss using the tools
to provided
ovided
vided by LabVIEW.
LabVI A tool is a special
t fo l In

t fo l In
rsor. The operating
operating mode of the mouse cursor. operati mode
operat de of the cursor corresponds to the icon of
ses which to
the tool selected. LabVIEW chooses too lect based on the current location of the
tool to select
mouse.
Figure 1-24.. Tools Palette
Fig
No na

No na
The Operating tool iss mostly used
us
use on the
he front
ront panel
pa window,
i but you also can use the Operating
ock diagram window
tool on the block win o change
to nge the val
value of a Boolean constant.
tio

tio
Positioning
ioning
oning Tool
Too
When n the mouse curs
curso
cursor changes
ges to the icon sh
shown below, the Positioning tool is in operation. Use
itioning tool to select
the Positioning ct orr resize
re
resiz bjec
je
objects. For example, in Figure 1-26 the Positioning tool
Na

Tip You can manually


Yo ually choo
choose
choos the tool you need by selecting it on the Tools palette.
ols Palette tto
Select ViewTools
Tools o display the Tools palette.
Na
elects
lects the Numb
selects
copy, or delete tthe object.
automatically accesses
urements numeric control. After selecting an object, you can move,
easurements
Number of Measurements
ect. When the mo
es the Position
Positionin
mouse hovers over the edge of an object, the cursor
Positioning tool.

National Instruments | 1-33 1-34 | ni.com


LabVIEW Core 1 Course Manual Lesson 1 Navigating LabVIEW

Figure 1-26. Using the Positioning Tool to Select an Object Labeling Tool
When the mouse cursor changes to the icon shown below, the Labeling tooll is in operation. Use the
bels.. For exa
Labeling tool to enter text in a control, to edit text, and to create free labels. example, in
Figure 1-28 the Labeling tool enters text in the Number of Measurements nts numeric cco
ents control. When

tio s

uti ts
tically
the mouse hovers over the interior of the control, the cursor automatically ally accesses the Labeling
click
tool. Click once to place a cursor inside the control. Then double-click k to select the
th current text.

ibu nt

rib en
n

on
str me
Figure 1-28. Using the Labeling
beling
ng Tool

ist um
Di tru

r D str
s
If the mouse hovers over a resizingg node
de of an obje
object, the cursor
ursor mode chchanges to show that you
l In

t fo l In
can resize the object, as shown inn Figure 1-27. N hatt the cursor is
Notice that i hovering over a corner of
the XY Graph at a resizing node, and the curso
cu rs modee changes
cursor anges to a double-sided
do arrow.
Figure 1-27.
-27. Using the
he Positioning
ning Tool to Re
Res
Resize an Object
na

No na
When you are not in a specific area
a of a frontnt panel
pa w window or block diagram window that accesses
use mode, the cursor
a certain mouse cu pears
rs as cross-hairs.
appears cross-ha
cross-h If automatic tool selection is enabled, you
tio

tio
e-click
-click any open space to access the Lab
can double-click Lab
Labeling tool and create a free label.

Wiring
ring
g Tool
When
hen the mouse cursor
ccu changes
hanges
nges to the icon shown below, the Wiring tool is in operation. Use the
Na

Na
Wiring
iring tool to wire

sses tth
accesses
ho
the mouse hovers
wi
w objects
tool wires the Number
N
ver
cts together on the
r of Measurements
er the exit or entry
over
ng tool.
the Wiring
Measure
Measurem
t block diagram. For example, in Figure 1-29 the Wiring
terminal to the count terminal of the For Loop. When
en point of a terminal or over a wire, the cursor automatically

You can use the Positioning tool on both the front panel window and the block diagram.

National Instruments | 1-35 1-36 | ni.com


LabVIEW Core 1 Course Manual Lesson 1 Navigating LabVIEW

Figure 1-29. Using the Wiring Tool Use the Object Shortcut Menu tool to access an object shortcut menu with the left mouse button.

uti ts

uti ts
ollbars.
ars.
Use the Scrolling tool to scroll through windows without using scrollbars.

rib en

rib en
on

on
ns, nodes,
Use the Breakpoint tool to set breakpoints on VIs, functions, des, wires,
wires and structures
ructures
res to pause
execution at that location.

ist um

ist um
Use the Probe tool to create probes on wires onn thee block diagram.
diag se thee Probe tool
Use too to check
estionable
onable or unexpected
intermediate values in a VI that produces questionable un ed results.
sults.
r D str

r D str
The Wiring tool works mainly with the block
lock
k diagram w
window and when you ccr
create a connector
pane on the front panel window.

olorss for pasting with the


Use the Color Copy tool to copy colors he Coloring
oloring tool.
tool
Other Tools Accessed
ed from the Palette
alette
ette
t fo l In

t fo l In
You can access the Operating, Positioning,
ositioning, Labeling,
La
Lab and Wiring tools
tool directly from the Tools
palette, rather than using the A tic tool selection
Automatic on mode.
ode. Select V
ViewTools Palette to access
the Tools palette.
Use the Coloring tool andd thee color picker to color
or an object. The Coloring tool also displays the
Figure 1-30. The Tools Pale
Figur Palette current foreground and background
ckground co ngs.
color settings.
No na

No na
an right-click
Select the Coloring tool and click
k an object
object o
or workspace to display the color picker.
tio

tio
H. Dataflow
ataflow
taflow
LabVIEW
bVIEW
EW follows a dataflow ow
w mo
model for ru
running VIs. A block diagram node executes when it
Na

The
he top item in the

automatic to
a
auto
t Toolss palette
LabVIEW automatically

are some additional


tion
alette is the Automatic Tool Selection button. When this is selected,
lly chooses a tool
on by deselect
tool selection
too based on the location of your cursor. You can turn off
deselecting the item, or by selecting another item in the palette. There
al tools on the ppalette, as described below:
Na
eceives
ceives all requir
receives uts. When a no
required inputs.
the next node in the dataflow
execution order
taflow
nod
node executes, it produces output data and passes the data to
ow path. The movement of data through the nodes determines the
ord of thee VIs and functions

Visuall Basic,
Ba
func
functi

+, JAVA, and most


C++,
on the block diagram.

mo other text-based programming languages follow a control flow


m
xecution. In control flow, the sequential order of program elements determines
model of program execution.
the execution order of a prog
program.

National Instruments | 1-37 1-38 | ni.com


LabVIEW Core 1 Course Manual Lesson 1 Navigating LabVIEW

For a dataflow programming example, consider a block diagram that adds two numbers and then Figure 1-33. Acquire, Analyze, and Present Example Front Panel Window and
subtracts 50.00 from the result of the addition, as shown in Figure 1-31. In this case, the block Block Diagram Window
diagram executes from left to right, not because the objects are placed in that order, but because the
hat ord
order
Subtract function cannot execute until the Add function finishes executing ting and passe
passes the data to

uti ts

tio s
the Subtract function. Remember that a node executes only when dataa are available aat all of its
input terminals and supplies data to the output terminals only when n thee node finishes
finish execution.

ibu nt
Figure 1-31. Dataflow Programming Example
mple

rib en
on

n
str me
ist um
In Figure 1-32, consider which code segment would ld execute
xecute first
firstthe Add, dd,
d, Random NumN
Number, or
Divide function. You cannot know because inputs ts to the Add and Dividee functions
func
nctions
tions are available
a at

u
the same time, and the Random Number functiontion has no inpu
input
inputs. In a situation
ation where one code
segment must execute before another, and noo data dependen
dependency exists sts between
tween the ffunctions, use
r D str

str
other programming methods, such as errorr clusters,
cluste
lusters,
rs, to force
for the order of execution.
fo executio Refer to
Lesson 5, Creating and Leveraging Datata Structures,
Structures, fofor more information ab abo
about error clusters.
Figure 1-32. Dataflow
aflow
w Example for
f Multiple
iple Code Segm
Segments
t fo l In

t fo l In
No na

No na
r
tio

tio
I. Building
lding
ding a Simple
Sim VI
V
On the Functions
unctions palett
pale
palette, the Express
xpress
press VIs are
are grouped
g together in the Express category. Express
Most LabVIEW
VIEW VIs have
hha three mainain tasksa
tasksacquiring some sort of data, analyzing the acquired
se the
VIs use he dynamic data
d typee to t pass
ass data b
be
between Express VIs.
data, andd presenting the result.
ult.
t. W
Wh ach oof these parts are simple, you can complete the entire
When each
VI using very few objects onn the block
bl diagram. Express VIs are designed specifically for
Na

completing
mpleting common,
comm frequently
that acquire, an
three tasks, as
equently
ently used operations.
analyze, and present d
a shownn in Figure 1-33
data
op In this section, you learn about some Express VIs
data. Then you learn to create a simple VI that uses these
1-33. Na
Acquire
cquire
Express VIs uused for the Acquire D
ssistant, S
Assistant, Simulatee Signal, and
Dat
Data task include the following: DAQ Assistant, Instrument I/O
and Rea
Read from Measurement File.

National Instruments | 1-39 1-40 | ni.com


LabVIEW Core 1 Course Manual Lesson 1 Navigating LabVIEW

DAQ Assistant Statistics


The DAQ Assistant acquires data through a data acquisition device.You mustt useu this Express VI The Statistics Express VI calculates statistical data from a waveform. Thiss inc
includes mean, sum,
frequently throughout this course. Until you learn more about data acquisition,
ion, you only use one
isition, standard deviation, and extreme values.
channel of the data acquisition device, CH0. This channel is connected to a temperature
temperatu sensor on

uti ts

uti ts
the BNC-2120. You can touch the temperature sensor to change the temperature
mperature the sensor reads.

rib en

rib en
Spectral Measurements

on

on
The Spectral Measurements Express VI performs spectral measurement
urement on
o a waveform,
veform,
m, such as
Instrument I/O Assistant magnitude and power spectral density.
The Instrument I/O Assistant acquires instrument control
rol data, usually
usuall from a GPIB or serial
seria

ist um

ist um
interface.

Tone Measurements
The Tone Measurements Express VI searches hes
es fo
forr a sing
single ttone with
th the highest fre
frequency or
r D str

r D str
Simulate Signal ency and amplitude
highest amplitude. It also finds the frequency amplit
amplitu of a single tone.
The Simulate Signal Express VI generates
ates simulated ddata suchh as a sine wave.
wave
t fo l In

t fo l In
Filter
Read From Measurement
re t File The Filter Express VI processes
essess a signall through
esse thr
th filters
ilters and windo
wind
windows. Filters used include the
The Read From Measurementmentt File EExpress VI reads
eads a file that w
was created using the Write To following: Highpass, Lowpass,
wpass, Bandpass, Bandstop,
s, Band stop, Smoothing. Windows used include
op, and Smooth
ress VI. It speci
Measurement File Express specifically read
eadss LVM or T
reads TD
TDM file formats. This Express VI Butterworth, Chebyshev,
ev, Inverse
nverse Chebyshev,
Ch
Cheb
eb Elliptical, and Bessel.
B
does not read ASCII files. Refer to LLesson 6,, Managing F File and Hardware Resources, for more
No na

No na
dingg data from a file.
information on reading

Present
nt
tio

tio
Analyze
yze
ze Present results
sults by using Express
E s VIs that perform
perfor a function, such as the Write to Measurement
xpress
ess VI, or ind
File Express indicators that present dat
data on the front panel window. The most commonly
Express
ess VIs used for the Analyze
alyze
y Data
ataa task
k include the followingAmplitude and Level icators for this
used indicators th task include
nclude
clud thee Wav
Waveform Chart, the Waveform Graph, and the XY Graph.
easurements,
asurements, Sta
Measurements, St
Statistics, and
d Ton
Tone M
Measurements. ommon Express VIs include
Common lude
de the Write
Wr
W it to Measurement File Express VI, the Build Text Express
Na

Amplitude and Level Measurements


The
he Amplitude
Amplit
These inc
Meas
Me
andd Level Measurements
Measure
C, rms, maximu
include DC,
rms measurements.
Express VI performs voltage measurements on a signal.
maximum peak, minimum peak, peak to peak, cycle average, and cycle
Na
VI,, the DAQ As
Instrument I/O
instrument.
Assistant, andd the In
I/ Assistant
Instrum
strum I/O Assistant. In this case, the DAQ Assistant and the
Instrument
ant provide output
outp data from the computer to the DAQ device or an external
ou

National Instruments | 1-41 1-42 | ni.com


LabVIEW Core 1 Course Manual

Write to Measurement File


The Write to Measurement File Express VI writes a file in LVM or TDMS file format. Refer to
Lesson 6, Managing File and Hardware Resources, for more information writing to
on on writin
measurement files.

uti ts

uti ts
rib en

rib en
Build Text

on

on
The Build Text Express VI creates text, usually for displaying
aying
ng on the front
fro panel
el window
indow or
anaging
ging File an
exporting to a file or instrument. Refer to Lesson 6, Managing dware Resource
and Hardware Resources
Resources, for

ist um

ist um
more information on creating strings.

r D str

r D str
Running a VI
After you configure the Express VIs and
nd wire them together,
tog you
ou can
can run the V
VI. When you finish
on on the toolb
creating your VI, click the Run button toolba ecutee the VI.
toolbar to execute
t fo l In

t fo l In
hee Run button ic
While the VI is running, the nges to the figu
icon changes figur
figure shown below. After the
execution completes, the Run button icon changes
ges back to its or
original state, and the front panel
indicators contain data..
No na

No na
Run Button
utton Errors
Error
tio

tio
If a VI does
oess not run, it is a broken,
n,, or nonexecuta
nonexecutable, VI. The Run button appears broken when the
VI youu aree creating or editing
e ntains
tains errors.
contains
Na

If the button still


nnot run.
cannot r
s appears
ears broken when
whe you finish wiring the block diagram, the VI is broken and
wh

ns that a required
Generally, this means re
req input is not wired, or a wire is broken. Press the broken run
Na
button to access the Error lis window. The Error list window lists each error and describes the
or list
li
problem. You can double-click an error to go directly to the error. Refer to Lesson 2,
Troubleshooting and Debugging VIs, for more information on debugging VIs.

National Instruments | 1-43


LabVIEW Core 1 Course Manual

Self-Review: Quiz
Refer to Figure 1-34 to answer the following quiz questions.

uti ts

uti ts
Figure 1-34. Dataflow Questions

rib en

rib en
on

on
ist um

ist um
1. Which function executes first: Add or Subtract?
btract?
ct?
a. Add
r D str

r D str
b. Subtract
c. Unknown
2. Which function executes first: Sinee or Divide?
t fo l In

t fo l In
a. Sine
b. Divide
c. Unknown
3. Which function executes
es first:
ecutes first Random
Ran
Ran Number,
umber, Divide or
o Add?
No na

No na
a. Random Number
mber
b. Divide
c. Add
d. Unknown
nown
tio

tio
4. Which
ch function executes
execu last: Number, Subtract or Add?
t: Random Num
a. Random Number
ndom Numb
b. Subtract
Na

c. Add
d. Unknown
Unkno
Unkn
5. What ar
are the three
hree parts of a V
a. Front panel window
VI?
Na
b. Block diagram window
windo
c. Project
d. Icon/connector pane

National Instruments | 1-45


LabVIEW Core 1 Course Manual Lesson 1 Navigating LabVIEW

Self-Review: Quiz Answers Notes

uti ts

uti ts
rib en

rib en
on

on
ist um

ist um
1. Which function executes first: Add or Subtract?
t?
a. Add
b. Subtract
r D str

r D str
c. Unknown
2. Which function executes first: Sine or Divide?
a. Sine
b. Divide
t fo l In

t fo l In
c. Unknown
3. Which function executess fir
first?
a. Random Number
b. Divide
No na

No na
c. Add
d. Unknown
n
4. Which function
on executes llast: Random,
nction andom, Subtract or Add?
m, Subtr
tio

tio
a. Random
ndom Number
b. Subtract
ubtract
c. Add
dd
d. Unknown
Na

5. What are th
a. Fron
b.. Bl
the three partss of a VI?
Front panel window
Block diagram
Blo
c. Project
gram window
Na
d. Icon/connector pane

National Instruments | 1-47 1-48 | ni.com


Lesson 2 Troubleshooting and Debugging VIs

Troubleshooting and Debugging VIs


Is
2 A. Correcting Broken VIs
If a VI does not run, it is a broken, or nonexecutable, VI. The Run button appears
ear bbroken when the
VI you are creating or editing contains errors.

uti ts

tio s
ibu nt
To run a VI, you must wire all the subVIs, functions, and structures
es with the corre
correct data types for

rib en
expe You can use
the terminals. Sometimes a VI produces data or runs in a way you do not expect. u lock
k diagram, the
If the button still appears broken when you finish wiring the block th VI iss broken
oken and
LabVIEW to configure how a VI runs and to identify problems ms with block ddiagram organizatio
anizatio
organization cannot run.

on

n
or with the data passing through the block diagram.

str me
Topics Finding Causes for Broken VIs

ist um
Warnings do not prevent you from running a VI. Theyey are designed to help
p you
ou avoid poten
potential
A. Correcting Broken VIs problems in VIs. Errors, however, can break a VI. You must resolv
resolve any errors
ors before yo
you can run
the VI.
B. Debugging Techniques

Di tru
C. Undefined or Unexpected Data Click the broken Run button or select ViewError
Erroror List to fin
find out why a VI is broke
brok
broken. The Error
list window lists all the errors. The Items withth errors sect
section listss thee names of aall items in
r D str
D. Error Handling memory, such as VIs and project librariess thatat have
have error
errors. If twoo or more
more items have the same
plication
cation inst
name, this section shows the specific application instanc
anc for each
instance ach item. The err
er
errors and warnings
section lists the errors and warnings for thee VI you select
se in the Items with errors section. The

s
Details section describes the errors and in some case mmends
cases recommendsends how to ccorrect the errors. Click
the Help button to display a topic in the LabVIEW
LabVIE Help that hat describes
describ th the error in detail and
t fo l In

l In
includes step-by-step instructionss for correcting the error.
ror.
Click the Show Error button n oor double-click
e-click the error
or description
description to highlight the area on the block
diagram or front panel thatt contain
contains the error.
Figure
gure 2-1. Example
E
Ex of the Error Lis
List Dialog Box
No na

No na
tio

tio
Na

Na
National Instruments | 2-1 2-2 | ni.com
LabVIEW Core 1 Course Manual Lesson 2 Troubleshooting and Debugging VIs

Common Causes of Broken VIs Suspend the execution of a subVI to edit values of controls and indicators, to control the
number of times it runs, or to go back to the beginning of the execution of the subVI.
The following list contains common reasons why a VI is broken while youu edit it:
Determine if the data that one function or subVI passes is undefined. This
his oofte
often happens with
The block diagram contains a broken wire because of a mismatch of data
ta types or
o a loose, numbers. For example, at one point in the VI an operation could havee divided a num
number by zero,

uti ts

uti ts
unconnected end. Refer to the Correcting Broken VIs topic of the LabVIEW Help for thus returning Inf (infinity), whereas subsequent functions or subVIs
ubVIs
VIs were expeexpecting
information about correcting broken wires. numbers.
A required block diagram terminal is unwired. Refer to the Using Link Block Diagram
singg Wires to Lin If the VI runs more slowly than expected, confirm that you turned
ned off execution
exec
execu highlighting
ghl

rib en

rib en
Objects topic of the LabVIEW Help for information about settingng required inputs andd outputs.
out amss when you aare not usingg them
in subVIs. Also, close subVI front panels and block diagrams
A subVI is broken or you edited its connector pane afterr you
u placed its icon on
n thee block because open windows can affect execution speed.

on

on
diagram of the VI. Refer to the Creating SubVIs topicc of the LabVIEW
LabVIE Help for information Check the representation of controls and indicators to see if you are receiving
rec erflow becaus
overflow becau
because
about subVIs. you converted a floating-point number to an integerer orr an integer tto a smaller
aller integer. For

ist um

ist um
nction
on that only acceptss 8-bit integers.
example, you might wire a 16-bit integer to a function
B. Debugging Techniques nteger
ger to an 8-b
This causes the function to convert the 16-bit integer esentation,
entation, pote
8-bit representation, potent
potentially
causing a loss of data.
If a VI is not broken, but you get unexpected data,
ta, you can use tthe following
owing
g techniques
technique to identify
and correct problems with the VI or the block k diagram
agram data fflow: execu
ecute
te zero iterations
Determine if any For Loops inadvertently execute ite andd produce empty
em arrays.
operly
erly unless
Verify you initialized shift registers properly unless you intend
d them to save ddata from one
r D str

r D str
Wire the error in and error out parameters
rs att the bottom
ters botto of most
ost built-in
built-in VIs and
a functions.
untered
ered in each node on
These parameters detect errors encountered n the block diagram
diagr and indicate if
diag execution of the loop to another.
and where an error occurred. You also can use tthe ameters
eters in the VI
these parameters VIs you build. Check the cluster element order at the source and destination
ation
on points. LabV
LabVIEW detects data
electt ViewErr
To eliminate all VI warnings, select ViewError List and d place a checkmark
che in the Show type and cluster size mismatches at edit time, bu
but it doess nott detect
de
detect mism
mismatches of elements of
Warnings checkbox to see allll warnings for tthe VI. Determine
etermine the ca
causes and correct them in the same type.
t fo l In

t fo l In
the VI. der.
Check the node execution order.
Use the Positioning tool to triple-click
lick a wire to highlight its entire
eent path and to ensure that the Check that the VI does not contain n hidd
hidde VIs. You inadvertently
hidden subVIs. inadver might have hidden a
roper
per term
wires connect to the proper terminals. subVI by placing one directly
irectly oon top of another
herr node or by decreasing
de the size of a structure
Use the Context Help c
elp window to check thee default values for each function and subVI on the without keeping the subVI
bVI in view
view.
block diagram. VIs and
d function
functions pass default
efault
fault values if rrecommended or optional inputs are ory off subVIs the
Check the inventory th VI usess agai
agains
againstt the resu
r
results of ViewBrowse Relationships
No na

No na
xample,
ple, a Boolean
unwired. For example, Boolea
Boole input mightght be set to TRUE if unwired. VIs and ViewB
This VIs SubVIs ationships
ationshipsU
ViewBrowse RelationshipsUnopened SubVIs to determine if any
extra subVIs exist.
st. Also open the VII Hiera
era
Hierarchy wind
window to see the subVIs for a VI. To help
d dialog
Use the Find log box to ssearch for subVI
ubV text,
subVIs, xt and other objects to correct throughout
rect results caused
avoid incorrect caus by hidden en V
VIs, sspecify that inputs to VIs are required.
the VI.
tio

tio
Hierarchy to find unwired sub
Select ViewVI Hiera
Hierar subVIs. Unlike unwired functions, unwired VIs do
ways generate errors
not always er nleess
ss you config
unless configu
configure an input to be required. If you mistakenly place Execution
ution
ion Highlighting
Highl
Highli ingng
an unwired
wired subVI oon the block
ck
k diagram, itt executes when the block diagram does. View ann animation of tthe execution
onn of the bloc
block diagram by clicking the Highlight Execution
Consequently,
equently, the
th VI might
ght pperform
orm
rm ext
extr
extra actions. button.
n.
Use execution highlighting
hting
ng to w
watc
watch the data move through the block diagram.
Na

Single-step through
Use the Probe
functi
functio
P
h thee VI to view each action of the VI on the block diagram.
oll to observe intermediate
tool
ecially those per
functions, especially
Click the Retain
int
performing I/O.
data values and to check the error output of VIs and

Values button on the block diagram toolbar to retain wire values for use
n Wire Valu
Na
Execution hhighlighting
her using
another uus
ting shows the
the m
movement of data on the block diagram from one node to
bles that move along the wires. Use execution highlighting in conjunction with
bubbles
ee how data values move from node to node through a VI.
single-stepping to see
ature allows
with probes. This feature a you to easily check values of data that last passed through any
wire.
Use breakpoints to pause execution, so you can single-step or insert probes.

National Instruments | 2-3 2-4 | ni.com


LabVIEW Core 1 Course Manual Lesson 2 Troubleshooting and Debugging VIs

(MathScript RT Module) In MathScript Nodes, execution highlighting shows the progression Probe Tools
from one line of script to another using a blue arrow that blinks next to the line that is executing
currently. Use the Probe tool to check intermediate values on a wire as a VI runs.

uti ts

uti ts
Note Execution highlighting greatly reduces the speed at which the VI ru
runs.

Figure 2-2. Example of Execution Highlighting


hting
g in Use eries of operations,
Use the Probe tool if you have a complicated block diagram with a series opera any one of

rib en

rib en
utionn highlighting,
which might return incorrect data. Use the Probe tool with execution hi
highlightin
ghlightin single-stepping,
gle-step
step
ata is available,
and breakpoints to determine if and where data is incorrect. If data availa
availab the probe be

on

on
immediately updates and displays the data in the Probe Watch Window dduring execution ution
akpoint.
oint. When eexecution
highlighting, single-stepping, or when you pause at a breakpoint. on pauses
auses at a nod
no
node
n probe
because of single-stepping or a breakpoint, you also can obe the wire that just
st executed to ssee the

ist um

ist um
value that flowed through that wire.

Tip If you want a probe to display thee data


ata that
that flowed
flowe through
flow ugh the wire during
dur
duri the last
alues button on the block
VI execution, click the Retain Wiree Values ck diagram ttoolbar.
r D str

r D str
Types of Probes
You can check intermediate values on a wire re when a VI
V runs by y using a generi
ge
generic
neri probe, by using an
indicator on the Controls palette to view
w the data,
data, by using a supplied
pplied probe
probe, by using a customized
ew probe.
supplied probe, or by creating a new
t fo l In

t fo l In
Single-Stepping
Single-step through a VI to view each
ch action of the VI on the block ddiagram as the VI runs. The Note (MathScript RT Module) Yo You can view
w the data in a script in a MathScript Node
own as
single-stepping buttons, shown a follows,
ws affect execution
xecution only in a VI or subVI in single-step sing a LabVIEW
as a VI runs by using IEW MathScript
Script probe.
mode.
Generic
No na

No na
Use the generic probe
be too view the
the data
da that passes
d asses through a wire. Right-click a wire and select
eric Probe fr
Generic
Custom ProbeGeneric from thee sh
shortcutt menu tto use the generic probe.
ep mode by click
Enter single-step clicking thee Step
ep IInto or Step Over button on the block diagram
The generic probe
robee displays the
th data. You cannot configure the generic probe to respond to the data.
annot con
toolbar. Movee thee cursor over the Step nto,, Step Ov
ep Into
Into, Over, or Step Out button to view a tip strip that
tio

tio
he next step if you
describes the yo clickk that button. You
y Yo can single-step through subVIs or run them LabVIEW W displays the generic
ge
gen probe
robe when you right-click
rri a wire and select Probe, unless you
y.
normally. already specified custom or supplied
pecified a custo
cus upplied for the data type.
pplied probe fo
Whenn you
ou single-step
single-ste through
gh a VI,
V nodes
odes blink
b to indicate they are ready to execute. If you You can custom probe
n debug a cus obe similarr to a V
be sim VI. However, a probe cannot probe its own block
gle-step through a VI with
single-step ithh execution
exec
executi hi
highlighting on, an execution glyph appears on the icons diagram,
agram, nor the block
b diagram
am of any of its subVIs. When debugging probes, use the generic
agram
Na

tha are currently


of the subVIs that rrently
ntly running.
running

Na
probe.
obe.

Using Ind
Indicators
You also
rs to View Da
Data
o can use an indicator to view the data that passes through a wire. For example, if you view
numeric data, you can n use a ch
chart within the probe to view the data. Right-click a wire, select
Custom ProbeControls fr from the shortcut menu, and select the indicator you want to use. You
also can click the Select a Control icon on the Controls palette and select any custom control or

National Instruments | 2-5 2-6 | ni.com


LabVIEW Core 1 Course Manual Lesson 2 Troubleshooting and Debugging VIs

type definition saved on the computer or in a shared directory on a server. LabVIEW treats type Breakpoints
definitions as custom controls when you use them to view probed data.
Use the Breakpoint tool to place a breakpoint on a VI, node, or wire and pause execution at that
he wire yyou
If the data type of the indicator you select does not match the data type of the location.

uti ts

uti ts
right-clicked, LabVIEW does not place the indicator on the wire.

Supplied

rib en

rib en
Supplied probes are VIs that display comprehensive information n about
bout the data that passes
assess thro
through ata passes
When you set a breakpoint on a wire, execution pauses after data asses through
throug
throu the wire aand the
a wire. For example, the VI Refnum Probe returns information on about
boutt the VI nname, the
he VI path, and iagram
am to pause execution
Pause button appears red. Place a breakpoint on the block diagram ion after all

on

on
the hex value of the reference. You also can use a suppliedd probe
obe to respond
respo
respon based d on the
he data tha
that order appears rre
nodes on the block diagram execute. The block diagram border red and blinkss to reflect
flows through the wire. For example, use an Error probee on an error cluster
clu ive the status,
to receive statu the placement of a breakpoint.

ist um

ist um
code, source, and description of the error and specify if you
u want to se ditional breakpoint
set a conditional breakp
breakpo if
an error or warning occurs. When a VI pauses at a breakpoint, LabVIEW brings thee block diagr diag
diagram to thehee front and use
uses a
pt that
marquee to highlight the node, wire, or line of script hat contains tthe breakpoint.
akpoint.
point. When yoyyou move
The supplied probes appear at the top of the Customm Probe shor
tom enu. Right-click a wire and
shortcut menu. ea of the Breakpoint
the cursor over an existing breakpoint, the black area Bre
Brea t tooll cursor appears
app
appe white.
select Custom Probe from the shortcut menu to select
elect a supp obe. Only probe
supplied probe. probes that match
pear
ear on the short
the data type of the wire you right-click appear nu.
shortcut menu. on, the VI pauses
When you reach a breakpoint during execution, pause and the Pause
ause button appears red.
You can take the following actions:
r D str

r D str
Refer to the Using Supplied Probes VI inn the
he labview\
labview\examples\general\probes.llb
labview ples\genera
ples\general for Single-step through execution using thee single-step
single-stepp uttons.
ttons.
single-stepping buttons.
an example of using supplied probes.
Probe wires to check intermediatee values.
ues.
nel controls.
Change the values of front panel
Custom
t fo l In

t fo l In
ntinue running to the nextt breakpoint or until the VI finishes
Click the Pause button to continue
Use the Create New Probe dialogg box to createcrea a probe
cre obe based on an existing probe or to create a
running.
new probe. Right-click a wirere and select
ect Cu robeNew from the shortcut menu to display
Custom ProbeNew
alog
the Create New Probe dialog og box. Create a probee when you wanwant to have more control over how
LabVIEW probes the dataata that
hat flows ththrough a wire
wire.. When yo
you create a new probe, the data type Suspending Execution
xecution
cution
ata type
of the probe matches the data type of the
t wiree you right-clicked.
right
right-clicke
-click If you want to edit the probe you
Suspend execution off a subVI
bVI to edit
edi values of controls anand indicators, to control the number of
No na

No na
pen it from the
created, you must open the ddirectory where you sa
sav
saved it.
ns before
times the subVI runs efore returning
returni to the caller,
ler, or to go back to the beginning of the execution
obe from the
After you select a probe th Custom Probe shortcut
om Pro
Prob rt menu, navigate to it using the Select a
rtc of the subVI. Youu cann cause all calls
c subV
bV to start with
to a subVI w execution suspended, or you can
Control palettete option,
ption, or create
cre
crea a new w probe
obe using
us the t Create New Probe dialog box, that probe ific call to a sub
suspend a specific subVI.
becomes thee default probe forfo that data type, and LabVIEW
La
L loads that probe when you right-click
tio

tio
To suspendd all calls to a subVI,
sub
su pen the subVI an
open and select OperateSuspend when Called. The
a wire andd select Probe from
fr menu LabVIEW only loads probes that exactly match
the shortcut menu.
utomatically
omatically suspends
subVI automatically susp hen another VI calls it. If you select this menu item when
when
the dataa type
ype of the wire
wi you right-click.
ht-click.
t-click. That is,
i a double precision floating-point numeric probe
stepping,
pping, the su
single-stepping, sub
subVI does not
ot suspend im
immediately. The subVI suspends when it is called.
ot probe
cannot obe a 32-bit unsigneded integer
ger wire eeven though LabVIEW can convert the data.
To suspend a specific
specif subVII call, right-click
right
rig ck the subVI node on the block diagram and select SubVI
Na

Note
the pr
I you want a custom pprobe to be the default probe for a particular data type, save
If
probe in the user.lib\
vi.lib\_probes
vi
vi.
up
user.lib\_probes\default directory. Do not save probes in the
probes directory
upgrade or reinstall.
direct
directo because LabVIEW overwrites those files when you Na
ode Setup from the shortcut
Node
suspend execut

he VI H
The
execution only

Hie
Hierarchy
ortcut
ut menu. Pla
y at that instanc
Pl
Place a checkmark in the Suspend when called checkbox to
instance of the subVI.

y window, which you display by selecting ViewVI Hierarchy, indicates


er a VI is paused
whether aused or suspe
suspen
suspended.

An arrow glyph indicatess a V


VI that is running regularly or single-stepping.

National Instruments | 2-7 2-8 | ni.com


LabVIEW Core 1 Course Manual Lesson 2 Troubleshooting and Debugging VIs

A pause glyph indicates a paused or suspended VI. Before you convert data to integer data types, use the Probe tool to check intermediate
floating-point values for validity. Check for NaN by wiring the Not A Number/Path/Refnum?
function to the value you suspect is invalid.
A green pause glyph, or a hollow glyph in black and white, indicates
cates a VI that ppauses when

uti ts

uti ts
called. termine
ermine if a VI pproduces
Do not rely on special values such as NaN, Inf, or empty arrays to determine
undefined data. Instead, confirm that the VI produces defined data byy making
aking the VI report an error
dicates
tes a VI that is currently
A red pause glyph, or a solid glyph in black and white, indicates a.
if it encounters a situation that is likely to produce undefined data.
paused.

rib en

rib en
For example, if you create a VI that uses an incoming array to o auto-index For Loop,
uto-index a F determine
p, determi
etermi
ended.
ed.
An exclamation point glyph indicates that the subVI is suspended. what you want the VI to do when the input array is empty. Either er produce aan output
ut error
rror code,

on

on
st
s
substitute defined data for the value that the loop creates, or use a Case structure thatt does not
execute the For Loop if the array is empty.

ist um

ist um
Note A VI can be suspended and paused
d at the same tim
time.
D. Error Handling
Determining the Current Instance
ce of a SubVI
SubV No matter how confident you are in the VI you create,
ate, you cann
cannot predict
ict ev
every
very
ery problem a user can
When you pause a subVI, the Call list pull-down own
wn menu on the toolbar ar listss the chain of
o callers from encounter. Without a mechanism to check forr errors,
rors, you kn
kno
know only y thatt the VI doe
do
does not work
d where errors oc
properly. Error checking tells you why and occur.
r D str

r D str
the top-level VI down to the subVI. This list istt is not the sa
sam
same list you see when you yo select View
Browse RelationshipsThis VIs Callers, ers, which lists aall calling
ng VIs regardles
re gardle of whether they
regardless
are currently running. Use the Call listt menunu to determ
determine thee current instanc
instance of the subVI if the ticipation,
pation, detection,
Error handling is the mechanism for anticipation, de
detec
tec ndd resolution off warnings
and w and errors.
block diagram contains more than onene instance.
innstance.
stance. Wh When you select
ect a VI from the Call list menu, its nentt in your LabVIEW
Error handling is an essential component Lab
La W application
plication development.
dev With error
block diagram opens and LabVIEW W highlights
highlights th the current
nt instance of the subVI. handling you quickly pinpoint the source
rce of pr
progra
ogra
programming g errors.
ors. Without it, you might observe
t fo l In

t fo l In
unexpected behavior but strugglee to find the source
sour of the
sou he problem.
unction to v
You also can use the Call Chain function vi
view the chain
in of callers
callers from the current VI to the
top-level VI. uable when
Error handling is also extremely valuable wh you test your application
applica to ensure that your error
reporting is meaningful andd that the
th error handling
ha stop your application when an error
code safely stops
ring stress
occurs. For example, during stress tes re setting values or conditions that are beyond the
testing you are
C. Undefined or Unexpected
Unexpe d Data pacity
normal operational capacityty of your ap
aapplication
p on which often rresult in errors. When such errors
No na

No na
nsure proper
occur, you want to ensure proper shu
shutdown off your applicat
applic
application.
Undefined data, which
hich are NaN
aN (not
(no a number)) or Inf
In (in
(infinity), invalidate all subsequent
(inf
ing-point
point operati
operations. Floating-point urn th
operations return lowing two symbolic values that indicate faulty
the following ontinues
nues to be important
Error handling continues iim nt after
ter an
a application
plica is deployed. Error handling can help
eaningless results:
computations or meaningless re detect system and environment
environmen differencessuch
ncessuch
ssu aas differences in file systems, memory, and disk
NaN (nott a number) represents
repre a floating-point
oating-point value
v that invalid operations produce, such as ational Instrume
resources. National ongly recomme
Instruments strongly recommen
recommends using error handling.
tio

tio
taking the
he square root of a negative
gative number.
number
Inf (infinity)
infinity) represents
repres
repr a floating-point
oati
ating-point
ng-point value
va that valid operations produce, such as dividing Automatic
omatic
matic Error
Erro
Err Handling
ndling
mber by zero
a number zero.
By default,
ult, LabVIEW automatically
matical
atica handles
handle
andle any error when a VI runs by suspending execution,
ghlighting the su
highlighting subVI or functi
nction
on w
function whe
where the error occurred, and displaying an error dialog box. In
Na

LabVIEW
abVIEW does nno
underflow for fl
Floating-Poi
Floating-Poin

ing-p
Floating-point
not check
k for overflow or underflow conditions on integer values. Overflow and

metic.
metic
Floating-Point Arithmetic.
nt numbers iis in accordance with IEEE 754, Standard for Binary
point
floating-point

erations propa
operations propag
propagate NaN and Inf reliably. When you explicitly or implicitly
convert NaN or Inf to integers or Boolean values, the values become meaningless. For example,
Na
thee error dialog bbox, each
the user.
to display to tth

To disable automatic
Execution from the
h error
rror has a num
numeric code to identify it and a corresponding error message

handling for the current VI, select FileVI Properties and select
atic error handli
handlin
he Category ppull-down menu. To disable automatic error handling for any new,
uces Inf. Converting Inf to a 16-bit integer produces the value 32,767,
dividing 1 by zero produces elect T
blank VIs you create, select ToolsOptions and select Block Diagram from the Category list. To
which appears to be a normal value. disable automatic error handling
d for a subVI or function within a VI, wire its error out parameter
to the error in parameter of another subVI or function or to an error out indicator.

National Instruments | 2-9 2-10 | ni.com


LabVIEW Core 1 Course Manual Lesson 2 Troubleshooting and Debugging VIs

Manual Error Handling Warnings


You may choose to handle errors without relying on automatic error handling.
ling. FFor example, if an A warning is defined as an error cluster with a nonzero code value and a FALSE
AL status value.
icatiion
on to sto
I/O VI on the block diagram times out, you might not want the entire application stop and display Although most errors have negative code values and warnings have positive values, this is not
ve code va
an error dialog box. You also might want the VI to retry for a certain period
eriod of time. universally true. Therefore you should rely on both the status value and
ndd the code valu
value to detect
va

uti ts

uti ts
errors and warnings.
In LabVIEW, you can make these manual error handling decisions on the block dia
diagram of the VI
di
using the following methods: Warnings are typically considered less severe than errors. Some APIs Is and functions,
funct
functi such as the

rib en

rib en
ver, other APIs, such ass thee VI
Match Regular Expression function, only report errors. However, VISA
Use the LabVIEW error handling VIs and functions on thee Dialog face palette to
Use Interface
ialog & User
arnings.
ngs.
API for controlling stand-alone instruments, often reports warnings.
notify and prompt users. For example, if LabVIEW encounters
counters error, you can
ers an error an display the

on

on
error message in different kinds of dialog boxes. Unlike when an error occurs, nodes execute normally when hen LabVIEW ddetects a warning.
arning. Even
Use error clusters and the error in and error out parameters
arameters most VIs and functions to
meters of mo though code executes normally, it is important that youu monitor
onitor warn
warni
warnings ring developm
during developmen
development to

ist um

ist um
cted you can fix the
manage errors. For example, when an error is detected t errorr programmatically
programmatical and ensure proper behavior of your application.
ction
n to the error in input
then wire the error out output of the VI or function ut of the Clear E
Er
Errors VI.
Explain Error Dialog Box
Tip Use error handling in conjunction
tion with the deb
debugging
g tools
ols to find and
an manage
When an error occurs, right-click within the cluster
ster border an
and
a select
ct Explain Error from the
xplain Erro
errors.
shortcut menu to open the Explain Error dialog
ialog box. Th
The Explain
in Error dialog box contains
r D str

r D str
nu includes an Explain
information about the error. The shortcut menu plain Warning ooption if the VI
Error Clusters contains warnings but no errors.
VIs and functions return errors in one
ne of two ways
wayswith numeric
meric error cco
codes or with an error rrorr dialog box from the
You also can access the Explain Error he HelpExplai
HelpExplain Error menu.
umeric
ric error code
cluster. Typically, functions use numeric cod
codes, and VIs
Is use an error ccluster, usually with error
t fo l In

t fo l In
inputs and outputs. Use the errorr cluster control
contro ndicators
ators to crea
controls and indicators create error inputs and outputs
in subVIs. Detect and Report Errors
rrors
Error handling in LabVIEW
W follows
follow the ddataflow model. Just as ddata values flow through a VI, so
Tip All error clusters
ers on a block diagram
gram
ram typically pr
provide the same standard error in can error information.
and standard error
or out functio
functi
functionality.
No na

No na
To implement good error handling,
handling, yyou must determine th the aactions to take when an error occurs at
The standard errorr in and error oout clusters
te include
clude the ffollowing components of information: any point in your applic
cation.
ation. To b
application. be ith you
begin with, u must
must uti
util
utilize the error terminals on functions and
status is a Boolean
an value th rts TRUE
that reports TRU if an error occurred. rror cluster is implemented
VIs. Since the error im nted as a flow-through
w-th
w-thr parameter, you should propagate
ng the
errors by wiring he error ou he first
out cluster of the fir node
no you want to execute to the error in cluster
code is a 32-bit
bit signed integer
in that
hat identifies the
th error numerically. A nonzero error code of the next node you want to execute.te. You mustt con
co
continue to do this for sequences of nodes.
tio

tio
coupledd with a status oof FALSE warning rather than a error.
SE signals a war
rcee is a string that
source ttha identifies
es where the error
fies e occurred. As the VI runs, LabVIEW tests fo orr errors at eac
for each node. If LabVIEW does not find any errors, the
xecutes
utes normall
node executes normally. If LabVIEWEW detects an error or warning, the node passes the error to the
de. Any subVIs
next node. subV that you create
ccr e should
shou also implement this flow-through behavior.
Errors
rorss
Na

Ann error is defin

he code.
of the code
cod
defined as an
n error
ror cluster w

If LabVIEW detects an error, the no


with a status value of TRUE, regardless of the code value.

node passes the error to the next node without executing that part
nod Na Tip
error
erro
ch
When you
W ou perform any kkind of input and output (I/O), consider the possibility that
errors mightt occur. Almos
Almost all I/O functions return error information. Include error
checking in VIs, especial
especiall
especially for I/O operations (file, serial, instrumentation, data
ion, and comm
acquisition,
tely.
appropriately.
commu
communication), and provide a mechanism to handle errors

National Instruments | 2-11 2-12 | ni.com


LabVIEW Core 1 Course Manual Lesson 2 Troubleshooting and Debugging VIs

Propagating Errors and Warnings OK message with warningsDisplays a dialog box with any warnings and a single OK
button. After the user acknowledges the dialog box, the VI returns control to the main VI.
To ensure that error and warning information is propagated correctly, it is important
impo to use
shift-registers for error cluster wires in loops so that the warning information propagated through
ion is propa
prop Continue/Stop + WarningsDisplays a dialog box with any warnings gs and but
buttons, which the
all iterations. Refer to Figure 2-3 for proper use of the shift-register to propagate err
errors and
erro user can use to either continue or stop. If the user selects Stop, the VII calls the Stop
Sto function to

uti ts

uti ts
warnings to successive loop iterations. halt execution.

Figure 2-3. Use Shift Registers to Propagate Errors


rors and Warnin
Warnings
Ranges of Error Codes

rib en

rib en
VIs and functions in LabVIEW can return numeric error codes. des. Each produc
produ
product or group
oup of VIs

on

on
IEW Error Cod
defines a range of error codes. Refer to the Ranges of LabVIEW Code
Codes topic of thee LabVIEW
Help for error code tables listing the numeric error codes andd descri
description
ption for each
descriptions ach product and VVI
grouping.

ist um

ist um
W reserves
In addition to defining error code ranges, LabVIEW serves some error code
ode
de ranges for y
yo
you to use
Merging Errors and Warnings des in the range
in your application. You can define custom error codes ran of 8999
89999 through 8000,
8 5000
through 9999, or 500,000 through 599,999.
Use the Merge Error function to merge the error
ror out cluster
luster values
v from parallel
parallel sequences.
seq Refer
rro
orr information
to Figure 2-4 for an example of merging error informatio from parallel
arallel node sequences.
sequ
seq
r D str

r D str
Some numeric error codes are used by more re thann one gro
grou Is and functions
group of VIs functions. For example,
ating
ng a serial po
error 65 is both a serial error code, indicating out, and a netw
port timeout, netwo
networking error code,
Figure 2-4. Merge
erge
e Errors From Multiple
ple Sources
indicating that a network connection iss already
eady establi
established.
t fo l In

t fo l In
No na

No na
At the end of yourr application
plication after
af
afte
fter
te all error
ror sources
ces are merged
m into one error cluster, you must
report errors to the user
ser using th
the Simplele Erro
rror H
Error ler VI or another error reporting mechanism.
Handler

Simple Error Handler


Handl VI
Hand
tio

tio
By default,
ult,
t, the Simple E
Error Handler
ndler
dler VI display
displays a dialog with a description of any errors that
occurred
ed and does not report warnings.
nings. However, the Simple Error Handler VI can be configured
ings. Howe
Howev
for otherr error handling
handl
handli behavior.
avior.
vior. Youu can select
s the type of dialog from the following options:
Na

dialogD
dialogD
No dialogDisplays
handlin errors.
over handling
mess
OK message
ackno
acknow
acknowledges
s.
no dialog box

efault)
fault)Display
(default)Displays
box. This is useful if you want to have programmatic control

Displa a dialog box with a single OK button. After the user


the dialog box, the VI returns control to the main VI.
Continue or stop messageDisplays a dialog box with buttons, which the user can use to
op message
Na
top. If the user selects Stop, the VI calls the Stop function to halt execution.
either continue or stop.

National Instruments | 2-13 2-14 | ni.com


LabVIEW Core 1 Course Manual

Self-Review: Quiz
1. Which of the following will result in a broken run arrow?

uti ts

uti ts
a. A subVI is broken
b. The diagram includes a divide by zero
c. A required subVI input is unwired

rib en

rib en
d. A Boolean terminal is wired to a numeric indicator

on

on
ist um

ist um
2. Which of the following are the components and data types of the error cluster?
luster?
uster?
a. Status: Boolean
b. Error: String
c. Code: 32-bit integer
r D str

r D str
d. Source: String

3. All errors have negative error codes


des and
and all w
wa
warnings have positive er
error codes.
t fo l In

t fo l In
a. True
b. False
No na

No na
4. Merge Errors function
nction concatenates errorr information from
on concatena fr multiple sources.
a. True
b. False
tio

tio
Na

Na
National Instruments | 2-15
LabVIEW Core 1 Course Manual Lesson 2 Troubleshooting and Debugging VIs

Self-Review: Quiz Answers Notes


1. Which of the following will result in a broken run arrow?

uti ts

uti ts
a. A subVI is broken
b. The diagram includes a divide by zero
c. A required subVI input is unwired

rib en

rib en
d. A Boolean terminal is wired to a numeric indicatorr

on

on
ist um

ist um
2. Which of the following are the contents of the error
or cluster?
a. Status: Boolean
b. Error: String
c. Code: 32-bit integer
r D str

r D str
d. Source: String

3. All errors have negative error codes


des and
and all w
wa
warnings have positive er
error codes.
t fo l In

t fo l In
a. True
b. False
No na

No na
4. Merge Errors function
nction concatenates errorr information from
on concatena fr multiple sources.
a. True
b. False
tio

tio
Na

Na
National Instruments | 2-17 2-18 | ni.com
Lesson 3 Implementing a VI

Implementing a VI
3 A. Front Panel Basics
In the design phase of the software development method, you identify the inputs
uts and
an outputs of the
problem. This identification leads directly to the design of the front panel
nel window.

uti ts

uti ts
Inputs for the design can come from the following actions:
This lesson teaches you how to implement code in LabVIEW. These se skills
sk
kills
ills include designing a user acquiring from a device such as a data acquisition device or a multimeter

rib en

rib en
interface, choosing a data type, documenting your code, using looping
ing structur h as W
structures such While
Loops and For Loops, adding software timing to your code, displaying
playing your data as a plot,
ot, and reading directly from a file
manipulating controls on the front panel

on

on
making decisions in your code using a Case structure.

You can display the inputs of the problem on the front panel controls, such
nel with con
contr ch as numeric
numeric,
Topics

ist um

ist um
boolean, or string controls, but not all input appears on the
he front panel.
pan
pane
A. Front Panel Basics
You can display the outputs of the problem with indicators,
ators, such as
ndicators, a graphs, LEDs, or log
hs, charts, or LE
LED
B. LabVIEW Data Types the outputs to a file. You also can output data too a device using
using signal generation.
eration.
C. Documenting Code
r D str

r D str
D. While Loops Designing Controls and Indicators
ndicators
dicators
E. For Loops When choosing controls and indicators,, make
ake sure that they are
ree appropriate fo
for the task you want
F. Timing a VI to perform. For example, when you wantt to determine
determin
determi the frequency
requenc
ency
y of a sine
sin wave, choose a dial
ay te
control, or when you want to display emperature,
mperature, choose a thermometer
temperature, ermometer iindicator.
G. Data Feedback in Loops
t fo l In

t fo l In
hart
H. Plotting Data Waveform Chart Labels
I. Case Structures Make sure to label controlss and iindicators
ors cclearly. These labels h
he
help
l users identify the purpose of
r. Also,
each control and indicator. so, clea
clear labeling helps
elps you docum
doc um your code on the block
document
ndicator
cator labels
diagram. Control and indicator laabels correspond
c ond
nd to the names
name of terminals on the block diagram,
-1.
as shown in Figure 3-1.
No na

No na
Figure
e 3-1.
1. Front Panel
Pan Controls
trols and Indicators
ndicat Appear on Block Diagram
tio

tio
Na

Na
1 Front Pa
Panel Window
w 2 Block Diagram

National Instruments | 3-1 3-2 | ni.com


LabVIEW Core 1 Course Manual Lesson 3 Implementing a VI

Control and Indicator Options Block Diagram Terminals and Data Types
You can set default values for controls and indicators. Figure 3-2 shows thee Up
Upper Temperature The block diagram terminals visually communicate to the user some informationmati about the data
control with a default value of 35 C. By setting a default value, you can assume reasonable value
me a re type the terminals represent. For example, in Figure 3-3, Height (cm) iss a double-p
double-precision,
for a VI if the user does not set another value during run-time. floating-point numeric. This is indicated by the color of the terminal, orange,
range, the text shown
ange, and by th

uti ts

tio s
on the terminal, DBL.
Complete the following steps to set the default value of a control orr indicator:
ndicator:

ibu nt
1. Enter the desired value. Figure 3-3. Terminal Data Type Example
ample
ple

rib en
2. Right-click the control or indicator and select Data OperationsMake
rationsMake
onsMake C
Currentt Value
lue
Default from the shortcut menu.

on

n
str me
Figure 3-2. Setting Default
faultt Values

ist um
Tip Terminal names correspond to thee labels
bels of the controls
cco and indicators on
o the front

Di tru
ect Find control or Find
panel. Right-click a terminal and select dicator from the shortcut
d indicator
cator
ator on the fron
menu to locate the control or indicator front panel.
r D str
Shortcut Menus

s
All LabVIEW objects have associateded shortcut
shortc
hortcut
ut men
menu
menus, also known
own as conte
context menus, pop-up
menus, and right-click menus. As youu create a VI, use thee shortcut menu items to change the
t fo l In

l In
appearance or behavior of front panel and block diagramm objects.
objects. To ac
aaccess the shortcut menu,
right-click the object.

utt menu
Figure 3-4 shows a shortcut menu for a control and
nd
d terminal.

Figure 3-4.
4. Shortcut Men
Menus for Front Panel and Block Diagram Objects
No na

na
Tip Youu can also re
reinitialize
ze values
alues to th
their default values.
tio

tio
Tip
p To initializ
initialize or re-initialize
initialize all
ll controls
con
co and indicators on the front panel at the same
time, select Ed
E
EditMake kee Current Values
Va
Val Default or EditReinitialize to Default
Values from the LabVIEW
bV W menu menu.
Na

B.. LabVIEW Data


Many differe
ata

dataa types in
dynamic
a Types
different data types
i Lesson
ypes exist for ddata. You already learned about numeric, Boolean, and string
on 1, Navigating LabVIEW. Other data types include the enumerated data type,
ic data, andd others. Even within numeric data types, there are different data types, such as
Na
ctional numbers.
whole numbers or fractional n

National Instruments | 3-3 3-4 | ni.com


LabVIEW Core 1 Course Manual Lesson 3 Implementing a VI

Property Dialog Boxes Numeric Data Types


Objects also have property dialog boxes that you can use to change the lookok oor behavior of the The numeric data type represents numbers of various types. To change the representation
repre type of a
objects. Right-click an object and select Properties from the shortcut menu
nu to access
acce the property tation,, aas shown in
number, right-click the control, indicator, or constant, and select Representation,
sentation
dialog box for an object. Figure 3-5 shows the property dialog box forr the Height (cm)
(cm terminal
(c Figure 3-6.

uti ts

bu nts
shown in Figure 3-4. The options available on the property dialog box
ox for an object are similar to
the options available on the shortcut menu for that object. Figure 3-6. Numeric Representation
n

rib en
Figure 3-5. Property Dialog Box for a Numeric
mericc Terminal

on

n
e
tio
ist um

um
r D str

str
tri
t fo l In

t fo l In
No na

No na
You can selectt multiple
ultiple objects
objec on thee frontnt pan
panel or the block diagram and edit any properties the

r
objects share.e. To select multiple
mult jects,
s, use the Positioning
objects, P
Po tool to drag a selection rectangle
tio

tio
around all of the objects yo
you wantt to edit
dit or hold down
d the <Shift> key while clicking each object.
ick
Right-clickck an object from
fr
fro the selection
election
lection and sel
select Properties from the shortcut menu to display When you ou wire two or mom
more numeric
mer
eric
ic inputs of d
di
different representations to a function, the function
rties dialog box. The Properties
the Properties
roperties operties didialog box only displays tabs and properties that the usuallyy returns
turns the dat
data in the larger,
ger,
er, or wider, representation. The functions coerce the smaller
ects you select sh
objects lect
ect sim
share. Select si
similar obje
objects to display more tabs and properties. If you select esentations
tations to the
representations th widestt repre
repr ntation
ation bbefore execution. LabVIEW places a coercion dot on
representation
bjects
jects that do not
objects no share any common pproperties, the Properties dialog box does not display any the terminal where
wher the conversion
version
rsion takes
ttake place.
l Refer to Numeric Conversion for more information.
Na

tabs or propertie
properties.
Na da type includes
The numeric data
sign integers,
sig
numbers, signed egers,
ludes the following
fo
fol
gers, unsigned integers,
i
subcategories of representationfloating-point
and complex numbers.

National Instruments | 3-5 3-6 | ni.com


LabVIEW Core 1 Course Manual Lesson 3 Implementing a VI

Floating-Point Numbers Integer word lengthThe number of integer bits in the bit string that LabVIEW uses to represent
all possible values of the fixed-point data, or, given an initial position to the left or right of the most
Floating-point numbers represent fractional numbers. In LabVIEW, floating-point
ng-po numbers are
significant bit, the number of bits to shift the binary point to reach the most ost sign
signi
significant bit. The
represented with the color orange.
integer word length can be larger than the word length, and can be positive tive or negative.
negat
negativ

uti ts

uti ts
Single-precision (SGL)Single-precision, floating-point numbers have ave 32-bit IEEE
IEE
ers when memo
single-precision format. Use single-precision, floating-point numbers mem
memory savings are Integers
important and you will not overflow the range of the numbers Integers represent whole numbers. Signed integers can be positive
ive or negative.
negative Use thee unsigned
un

rib en

rib en
ve. In LabVIEW,
integer data types when you know the integer is always positive. LabVIEW integers
gers are
Double-precision (DBL)Double-precision, floating-point numbers mbers have 64-bit
6 IEEE
EEE
represented with the color blue.

on

on
ormat for nume
double-precision format. Double-precision is the default format numer cts. For most
numeric objects.
situations, use double-precision, floating-point numbers gers,, the VI rounds
When LabVIEW converts floating-point numbers to integers, roun the inputut to the nearest
near

ist um

ist um
wo integers,
integer. If the value of the input is midway between two ntegers, the function
n returns the ne
nea
nearest
ded-precisi
-precision
Extended-precision (EXT)When you save extended-precision on nu
numbers to o disk, LabVIE
LabVIEW
even integer.
mat. In memory
stores them in a platform-independent 128-bit format. memory, y the sizee and precision vvary
ion, floating-poi
depending on the platform. Use extended-precision, berss only when nnecessary.
floating-point numbers Byte (I8)Byte integer numbers have 8 bits of storage
rage and a ra
range of 128
28 to 127.
meticc vary among platforms.
The performance of extended-precision arithmetic orms.
6 bits
Word (I16)Word integer numbers have 16 ts of storage and a rangee of 32,768
32,76 to 32,767.
r D str

r D str
Fixed-Point Data Type Long (I32)Long integer numbers havee 32 2 bits of stora
storage andd a range of 2
2,14
2,147,483,648 to
The fixed-point data type is a numeric dataa type that re representstss a set of rationa
ration
rational numbers using 2,147,483,647. In most cases, it is bestt to use a 32-bit integer.
ting-point
-point data type,
binary digits, or bits. Unlike the floating-point t hich allows the ttotal number of bits
which
LabVIEW uses to represent numbers rs too vary, you can
ca configure
figuree fixed-point
fixe
fixed-poin
poin numbers to always use rs have
Quad (I64)Quad integer numbers ave 64 bits oof storage
ge and
nd a range oof 1e19 to 1e19.
t fo l In

t fo l In
a specific number of bits. Hardwareare and targets tth
that onlyy can
an store and process
p data with a limited
or fixed number of bits then can store and procpro
process thee numbers.
mbers. You ccan specify the range and Byte (U8)Byte unsigned integer have 8 bits
ger numbers h
ha ts off storage and a range of 0 to 255.
mb
precision of fixed-point numbers.
ned in
Word (U16)Word unsigned integer numb ve 16 bits
numbers have bits of sto
stor
storage and a range of 0 to 65,535.
Note To represent
resent
nt a rational
rationa numberr using the fixed-point
fixed data type, the denominator Long (U32)Long unsigned
ed integer nnumbers have 32 bits
signed bits of sstorage and a range of 0 to
nal number
of the rational umber must be a power
ower
wer of 2, becau
because the binary number system is a 4,294,967,295.
No na

No na
mber
base-2 number er system.
Quad (U64)Quad integer numbers
uad unsigned inte umbe have
ave 64 bbits of storage and a range of 0 to 2e19.
oint data type w
Use the fixed-point u doo not nneed the dynamic functionality of floating-point
when you
representationn or when you want
w to workk with a target
targ
t that does not support floating-point Complexx Numbers
umbers
tio

tio
FPG target.
arithmetic, such as an FPGA t.
Complex numbers
umbers are concatenated
conc ed versions of flo
floa
floating-point numbers with a real and an imaginary
y the
Specify he encoding, w th,
h, and integer w
word length, word length of a fixed-point number when you want abVIEW, because
part. In LabVIEW, becau complex
plex
ex numbers are a type of floating-point number, complex numbers
umber
er to conform to a certain
the number ert bitt size. are alsoo represented
presented with
wi the color orange.
orange. There
The are three types of complex numbers.
T

Complex
omplex single-precision,
omplex Single (CSG)Complex
Complex (C sin floating-point numbers consist of real and
Na

The bbinary encoding


ncodingThe
ncoding
EncodingThe

lengt
Word lengthThe
ncoding
signe the sign
you select signed,

e total
ding of the fixed-point number. You can select signed or unsigned. If
ign bit is always the first bit in the bit string that represents the data.

otal number of
ble vvalues off the fixed-poin
possible
Certain targets might
o bits in the bit string that LabVIEW uses to represent all
fixed-point data. LabVIEW accepts a maximum word length of 64 bits.
ht limit data to smaller word lengths. If you open a VI on a target and the VI
Na
imaginary
maginary values

Complex Do
value in 32-bit
bit IEEE single

CDB)
DB)Comple
Double (CDB)Complex
single-
single-precision format.

Comple double-precision, floating-point numbers consist of real and


ginary values in 64-bitt IEEE double-precision
imaginary d format.

CXT)
CXT)
Complex Extended (CXT)Complex extended-precision, floating-point numbers consist of real
contains fixed-point dataa wit
with larger word lengths than the target can accept, the VI contains
EE extended-precision format. In memory, the size and precision of
and imaginary values in IEEE
broken wires. Refer to the documentation for a target to determine the maximum word length the
extended-precision numbers vary depending on the platform. In Windows, they have 128-bit IEEE
target accepts.
extended-precision format.

National Instruments | 3-7 3-8 | ni.com


LabVIEW Core 1 Course Manual Lesson 3 Implementing a VI

Numeric Conversion Latch when releasedChanges the control value only after you release the mouse button
within the graphical boundary of the control. When the VI reads it once,, the control reverts to
LabVIEW can represent numeric data types as signed or unsigned integers,, floating-point
float numeric ox but
its default value. This behavior works in the same manner as dialog box butto
buttons and system
epresentatio
esentatio types to the
values, or complex numeric values. Normally, when you wire different representation buttons. You cannot select this behavior for a radio buttons control.
inputs of a function, the function returns an output in the larger or widerr format. If you use a signed

uti ts

uti ts
integer with an unsigned integer, it will coerce to the unsigned integer.ger. If you use an unsigned Latch until releasedChanges the control value when you clickk itt and retains
retains the
th value until
integer with a floating point, it will coerce to the floating point. If you use a floatin
floating point number the VI reads it once or you release the mouse button, dependingg onn which one occurs
o last. You
with a complex number, it will coerce to the complex number. If you u use two nunum
numbers of the same cannot select this behavior for a radio buttons control.

rib en

rib en
type with different bit widths, LabVIEW will coerce to the larger rgerr of the two bbit widths.
hs.
To learn more about mechanical action, experiment with the Mechanical
chanical Act
Acti
Action of Booleans
eans VI in

on

on
gned
If the number of bits is the same, LabVIEW chooses unsigned d over signe
signed integers.
ers. For example
example, the NI Example Finder.
if you wire a DBL and an I32 to a Multiply function, thee result
ult is a DBL own
DBL, as shown n in Figure 33-
3-7. Figure 3-8. Boolean Mechanical
hanical
nical Action

ist um

ist um
LabVIEW coerces the 32-bit signed integer because itt useses fewer bits than the
he double-precision,
double-precis
double-preci
floating-point numeric value. The lower input of thee Multiply
ultiply func
funct ows
ws a red dot, ca
function shows called a
coercion dot, that indicates LabVIEW coerced thee data.
a.
r D str Figure 3-7. Numeric
ric Conversion Example
E e

r D str
1
t fo l In

t fo l In
1 Coercion Dot

Boolean Values
LabVIEW stores Booleanan data
ata as 8-
8-bit
bit values.
v Iff the 8-bit value is
i zero, the Boolean value is FALSE.
epresents
nts TRUE.
Any nonzero value represents TRUE In LabVIEW,
VIEW, thee colcolor green represents Boolean data.
No na

No na
Boolean values also mechanical action
lso have a mech on associated
ciated with them. The two major actions are
latch and switch. h. You
ou can selec
select from the follo
followin
following button behaviors:
Switch when pressedChanges
pressed
pressed es the
he control vavalue
v each time you click it with the Operating
Strings
tio

tio
tool. Thehe frequency with
w which
wi ch the VI reads tthe control does not affect this behavior. A string is a sequence of displayable
di
d ble or non-displa
non-displayable ASCII characters. Strings provide a
-independent
ndependent format
platform-independent for forr information
information and
an data. Some of the more common applications of
Switch h when releasedChanges
tch releas
relea nges the control
hanges contr value only after you release the mouse button
clude the following:
strings include follo
foll
uring
during g a mouse cl hin the graphical
click within graphic boundary of the control. The frequency with which
the VI reads the control does no fectt this behavior.
not affect ating simple text messages.
Creating essages.
sage
Na

Switch until releasedChanges

ope
op
re
until you release
to the operation
th behavior.
affect this
Latch when pressedChanges
Changes the
dChanges
he mouse button
the

Cha
ressedCha
ressed
buzze
th control value when you click it and retains the new value
button. At this time, the control reverts to its default value, similar
off a door buzzer.
buzzer The frequency with which the VI reads the control does not
avior. You cann
canno
cannot select this behavior for a radio buttons control.
the control value when you click it and retains the new value


Na Controlling instruments
in

Storing numeric
n
nts by sending ttext commands to the instrument and returning data values
er ASCII
in the form of either SCII or binary
bina strings which you then convert to numeric values.
data to disk. To store numeric data in an ASCII file, you must first convert
numer data to strings befo
numeric before writing the data to a disk file.
ompting th
Instructing or prompting the user with dialog boxes.
until the VI reads it once.
once At this point, the control reverts to its default value even if you keep
pressing the mouse button. This behavior is similar to a circuit breaker and is useful for
stopping a While Loop or for getting the VI to perform an action only once each time you set
the control. You cannot select this behavior for a radio buttons control.

National Instruments | 3-9 3-10 | ni.com


LabVIEW Core 1 Course Manual Lesson 3 Implementing a VI

On the front panel, strings appear as tables, text entry boxes, and labels. LabVIEW includes built-in Enums
VIs and functions you can use to manipulate strings, including formatting strings, parsing strings,
and other editing. An enum (enumerated control, constant or indicator) is a combination of data tytypes. An enum
represents a pair of values, a string and a numeric, where the enum can be one of a list of values.
For example, if you created an enum type called Month, the possible value
alue pairs for a Month

uti ts

uti ts
Refer to the ASCII Codes topic in the LabVIEW Help for more information
ation
ion about ASCII
ASC codes and
conversion functions. gure 3-9 shows
variable are January-0, February-1, and so on through December-11. Figure show an example
of these data pairs in the Properties dialog box for an enumeratedd control.
ntrol.
In LabVIEW, strings are represented with the color pink.

rib en

rib en
Figure 3-9. Properties for the Month Enumerated
merated
ated Contro
Control
Right-click a string control or indicator on the front panel too select
ect from the display
y types
pes shown

on

on
in the Table . The table also shows an example message in n each type.
ach display tty

ist um

ist um
Table 3-1. String Display
splay
y Types

Display Type Description Message


Normal Display Displays printable characters
ers Th
There are four disp
display
trol.
using the font of the control. types. \ is a ba
backslash.
racters
Non-displayable characters
r D str

r D str
oxes.
generally appear as boxes.
\ Codes Display Displays backslashh codes fo
for all There\sare\sfour\sdisplay\
re\sare\s
non-displayablee characters. stypes.\n\\\sis\sa\
types.\n\
sbackslash.
sbackslas
t fo l In

t fo In
Password Display Displays an asterisk (*) for each ******
**************************
ac including
character uding spaces. *******************
*****

Hex Display Displays


ays the AASCII valuee of each 546
5468 6572 6520 6172 6520
aracter in he
character d of the
hex instead 666F
6 7572 2064 6973 706C
aracter itse
character itself. 6179 2074 7970 6573 2E0A
No na

No na
5C20 6973 2061 2062 6163
6B73 6C61 7368 2E

ores strings as a pointerr to a structure that


LabVIEW stores th contains a 4-byte length value followed by
tio

tio
a 1D array of byte integers (8-bit characters).
Na

Na
National Instruments | 3-11 3-12 | ni.com
LabVIEW Core 1 Course Manual Lesson 3 Implementing a VI

Enums are useful because it is easier to manipulate numbers on the block diagram than strings. When you wire a dynamic data type to an array indicator, LabVIEW automatically adds the
Figure 3-10 shows the Month enumerated control, the selection of a data pair in the enumerated Convert from Dynamic Data Express VI to the block diagram. Double-click the Convert from
control, and the corresponding block diagram terminal. Dynamic Data Express VI to open the Configure Convert from Dynamic Data dialog box to
mic Dat
control how the data appears in the array.

uti ts

uti ts
Figure 3-10. Month Enumerated Control

1 2 3 C. Documenting Code

rib en

rib en
Professional developers who maintain and modify VIs know the he value
lue of good documentation.
mentati
Document the block diagram well to ease future modification n off the code
code.. In addition,
on, documen
document

on

on
the front panel window well to explain the purpose of the VI andd the fron
front panel objects.
cts.

signn to documen
Use tip strips, descriptions, VI Properties, and good design docume
document frontt panel windows
windows.

ist um

ist um
Tip Strips and Descriptions
Tip strips are brief descriptions that appear whenen you move the
th cursorr overr a control oro indicator
while a VI runs. For example, you might add a tipp strip to ind hat a temperature
indicate that temperatur is in degrees
Celsius or explain how an input works in an algor
lgorithm.
ithm. De
algorithm. Desc
Descriptionsns provide additio
additi
additional information
r D str

r D str
escriptions
iptions appe
about specific controls and indicators. Descriptions appea
appear in thee Context Help w window when you
move the cursor over the object. To addd tipp strips and descriptions
d tions
ons to controls
controls, right-click the
1 Front Panel Control 2 Selecting
ecting an Item 3 Block Di
Diagram Terminal control or indicator and select Description
ion and Tip from the
ription he shortcut
hortcut menu
menu.
t fo l In

t fo l In
Dynamic VI Properties
The dynamic data type stores es the
th information
matio generated
mati erated or acquired
acquir by an Express VI. The Use the Documentation component
mpo off the V erties dialog bo
VI Properties box to create VI descriptions and
dynamic data type appears rs ass a dark blue terminal,
al, shown below. Most Express VIs accept and/or to link from VIs to HTML L files or to compiled helpelpp files. To di
disp
sp VI Properties right-click the
display
return the dynamic dataa type.
pe. You can wire thee dynamic
dynamic data tytype to any indicator or input that nel orr block diagram
VI icon on the front panel dia andd select VI Pro
Properties from the shortcut menu or
Prop
veform,
accepts numeric, waveform, m, or Boolean
Bool
Boole data.. Wire the dynam
dynamic data type to an indicator that can rties.. Then select
select FileVI Properties. selec Documentation
mentation from the Categories drop-down menu.
No na

No na
a. Indicators
best present the data. ndicators inc
incl s, charts, or numeric indicators.
include graphs, his dialog
You cannot access this dialog box w while a VI runs.

des the
This page includes he following
followin components:
onents:
nts:
iptionContain the text
onContain
VI descriptionContains ext that
hat appears
appea in the Context Help window if you move the
tio

tio
Most other VIs and function
func tio in LabVIEW
functions abVIEW do nott accept the dynamic data type. To use a built-in icon Use <B>
cursor over the VI icon. B> and </B> tags
tag around any text in the description you want to
nction
tion to analyze or process
VI or function cess
ess the data the
the ddynamic data type includes, you must convert the at as bold. You also
format a can use the VI Description
Desc
Des property to edit the VI description
dynamicic data type. grammatically.
ammatically.
programmatically.
Help tagCont
p tagContains
tagCont HTM filename
the HTML enam
nam or index keyword of the topic you want to link to in
Usee the Convert fro amic
from Dynamicmic D
Da
Datata Express
pr VI to convert the dynamic data type to numeric,
hel file. You also can use
he
a compiled help u the Help:Document Tag property to set the help tag
Na

Boolean,
oolean, waveform,

Dynamic Da
wavefor and array
Convert from Dynamic
D

plays options
displays oop
c Data
ay data type
types for use with other VIs and functions. When you place the
ata Express
Expres VI
ogg box appears. The
Data dialog
hat let you specify
that
mic Data Express
Dynamic
V on the block diagram, the Configure Convert from
T Configure Convert from Dynamic Data dialog box
specif how you want to format the data that the Convert from
press VI retur
return
returns.
Na programmat
programmati
programmatically.
path
pat tains the path tto the HTML file or to the compiled help file you want to link
Help pathContains
ntext Help window.
to from the Context windo If this field is empty, the Detailed help link does not appear
window and the Detailed help button is dimmed.
in the Context Help window,
BrowseDisplayss a file dialog
d box to use to navigate to an HTML file or to a compiled help
file to use as the Help path.

National Instruments | 3-13 3-14 | ni.com


LabVIEW Core 1 Course Manual Lesson 3 Implementing a VI

Naming Controls and Indicators Label constants to specify the nature of the constant.
Giving controls and indicators logical and descriptive names adds usabilityy to front
f panels. For rams If you use an
Use free labels to document algorithms that you use on the block diagrams.
example, if you name a control Temperature, a user may not know which ich units to use.
u However, rmation.
ation
algorithm from a book or other reference, provide the reference information.
naming a control Temperature C adds more information to the front ont
nt panel. You nnow know to

uti ts

uti ts
enter temperatures in metric units. D. While Loops
Similar to a Do Loop or a Repeat-Until Loop in text-based programming
amming
ming languag
langua
languages, a Whi
While Loop,
Graphical Programming

rib en

rib en
shown in Figure 3-12, executes a subdiagram until a conditionn occurs.
ccurs.
While the graphical nature of LabVIEW aids in self-documentation
entation
tion of bloc
block diagrams,
ams,, extra

on

on
comments are helpful when modifying your VIs in the future.re. There are tw
two types of block
lock diagram The following illustration shows a While Loop in LabVIEW, flowchart eequivalent
EW, a flowchart lent off the While
eration
commentscomments that describe the function or operation ion of algori
algorithms andnd comments
omments thathat unctionality
onality of th
Loop functionality, and a pseudo code example of the functionality le Loop.
the While oop.

ist um

ist um
explain the purpose of data that passes through wires. Both
oth types of comments
c nts are shown in the
Figure 3-12. While
hile Loop
abelss with the L
following block diagram. You can insert standard labels La
Labeling tool,
ool, or by inserting
inser a
free label from the FunctionsProgrammingStructuresDecorations
ructuresDeco
turesDeco subpalette.
ubpalette. By default,
Code
e
free labels have a yellow background color.
No Repeat (co
(code);
Figure 3-11. Documenting
cumenting
umenting a Blo
Block Diagram
gram
Condition
r D str

r D str
Until Co
Condition met;
Code
met?
me
End;
Ye
Yess

End
En
t fo l In

t fo l In
1 2 3

1 LabVIEW While Loop 2 Flowchart 3 Pseudo Code

The While Loop is locateded on the Str


Structures palette.
alette.
ette. Select the While Loop from the palette then
use the cursor to drag a select
lection
ion rectangle
selection rectan around
recta ound the section of the block diagram you want to
No na

No na
lease the mouse button, a While Loop boundary
repeat. When you release b encloses the section you
Use the following
g guidelines
idelines for ccommenting
ntin your
ur VIs: selected.

Use comments
mentss on the block
bloc diagram explain what the code is doing.
am to ex
explai gram
m objects to the
Add block diagram t While
ile Loop by ddragging and dropping them inside the While
While LabVIEW can be self-documenting
abVIEW code cca documentin because it is graphical, use labels to describe
elf-documenting Loop.
tio

tio
how the
hee block diagram functions.
ons
ons.
Tip The Whi
While Loop always executes
execute at least once.
Usee labels
abels to identify
identif objectss on the front ppanel and block diagram. LabVIEW includes two
ident
ifferent
rent types of labelsowned
different l ow abels and
labels aan free labels. Owned labels belong to and move with
a particular object and annotate
rticular obje notat ththat obj
object
bj only. Free labels are not attached to any object, and hile Loop executes
The While exe he subdiagram
the subdia
subd m until
un the conditional terminal, an input terminal, receives
Na

you can creat


create, move,
Do not sho

Conte Help window.


Contex
Context
e, rotate
show labelss on function an
develope looking
developer
delete them independently.
tate orr dele
and subVI calls because they tend to be large and unwieldy. A
ngg at the block diagram
d can find the name of a function or subVI by using the

ls with long wires to identify their use. Labeling wires is useful for wires
Use owned labels
Na
a specific Boolean value. However,

Iff a conditional
c

conditio terminal
Whilee Loop,
minal
on never occurs.
infinitely if the condition
wever, the While Loop does not include a set iteration count and runs

nal is Stop if True,


Loo and the control is FALSE
Lo FA
F
ample. You also
in the following example.
T you place the terminal of a Boolean control outside a
when the loop starts, you cause an infinite loop, as shown
a cause an infinite loop if the conditional terminal is Continue
giste and for long wires that span the entire block diagram.Refer to the
coming from shift registers outsi the loop is set to TRUE, as shown in Figure 3-13.
outsid
if True and the control outside
Case Structures section of this lesson for more information about shift registers.
Label structures to specify the main functionality of the structure.

National Instruments | 3-15 3-16 | ni.com


LabVIEW Core 1 Course Manual Lesson 3 Implementing a VI

Figure 3-13. An Infinite Loop Tunnels through Structures


Tunnels feed data into and out of structures like While Loops. The tunnel appea
appears as a solid block
on the border of the While Loop. The block is the color of the data type wired red to th
the tunnel. Data
pass out of a loop after the loop terminates. When a tunnel passes data into
to a loop, the lo
nto lloop executes

uti ts

uti ts
only after data arrive at the tunnel.

In the following block diagram, the iteration terminal is connecteded to a tunnel. T u in the
The value

rib en

rib en
tunnel does not get passed to the Iterations indicator until thee While
hile Loop fin
finishes executing
uting
executing.

on

on
Figure 3-15. While Loop Tunnel
el

Changing the value of the control does not stop the infinite
initee loop because
beca
becau the value is only read
rea

ist um

ist um
once, before the loop starts. To stop an infinite loop, youu must abort the VI byy clicking the A
Abort
Execution button on the toolbar.

You also can perform basic error handling using ng the


he conditional
condition
conditiona terminal inal off a While Loop.
L When
rminal,
inal, only th
you wire an error cluster to the conditional terminal, the True or False
alse value oof the status
parameter of the error cluster passes to the terminal.
erminal. Also
Also, tthe Stopp if True and Co C
Continue if True
r D str

r D str
shortcut menu items change to Stop if Errorrror and Contin
Conti
Continue while ile Error.
Error
Only the last value of the iteration terminal
minall displays in the Iterations
rations indicato
erations indicator.
rminal
nal that
The iteration terminal is an output terminal that contains
cont
con thee number
mber of completed
com iterations.

Using While Loops for Error C


Checking
king
ing and Error
E Handling
t fo l In

t fo l In
You can wire an error cluster to the
he condition
conditiona
conditional terminalnal of a While L
Loop or a For Loop with a
oop alway
The iteration count for the While Loop always startss at zero. on of the
conditional terminal to stop the iteration tth loop.. If
I you
ou wire the error cluster to the conditional
terminal, only the TRUE or FALS atus parameter of the error cluster passes to the
FALSE value of the status
tatus
agram,
In the following block diagram,m, the W
While Loop executes until ththe Random Number function
urs, the loop st
terminal. If an error occurs, stops.
qual to 0.9 aand the Enable control iis True. The And function returns
output is greater than or equal
True only if both inputs
puts are
re True. O
Otherwise,e, it returns Fal
False.
F
No na

No na
ter to the conditional
If you wire an error cluster co l terminal, the shortcut
s menu items Stop if True and
ange to Stop on Error
Continue if True change ror and Continue
Continu while Error.
In the following example,
mple, there is
i an increased
se probability
crease babili of an infinite loop. Generally, the
desired behavior
or is too have one ccondition
on met to
t stop
sto the loop, rather than requiring both conditions In Figure 3-16,, thee error cluster
cluste
clust and a stop
p button
butto are
ar used together to determine when to stop the
to be met. loop. This iss the recommended
recommend method hodd for stopping
stoppin most loops.
tio

tio
Figure
igure
gure 3-14. Possible
Po
Pos Infinite Loop Figure
igure
gure 3-16. Stopping
Sto a While Loop
Na

Na
National Instruments | 3-17 3-18 | ni.com
LabVIEW Core 1 Course Manual Lesson 3 Implementing a VI

E. For Loops Adding a Conditional Terminal to a For Loop


If necessary, you can add a conditional terminal to configure a For Loop too stop when a Boolean
A For Loop, shown as follows, executes a subdiagram a set number of times.
mes.. Figure
Figu
Fig 3-17 shows a
condition or an error occurs. A For Loop with a conditional terminal executesecutes
tes until the condition
For Loop in LabVIEW, a flowchart equivalent of the For Loop functionality,
nality, ppseudo code
y, and a ps
occurs or until all iterations are complete, whichever happens first. Forr Loops you con configure for a
co

uti ts

tio s
example of the functionality of the For Loop.
nditional
tional termin
conditional exit have a red glyph in the count terminal as well as a conditional terminal in the lower
right corner. After you configure the For Loop to exit conditionally,ly, the
he lloop
oop appe
appears similar to

ibu nt
Figure 3-17. For Loop
Figure 3-19. The following For Loop generates a random number er every
very second
second until 100
00 seconds

rib en
N=100 has passed or the user clicks the stop button.

on

n
str me
Figure 3-19. For Loop Configured forr a Conditional Exit
i=0
N=100;
N=
i=i+1

ist um
i=0;
Code
No Until i=N:
i=N? Code
de
epeat (code; i=i+1);
Repeat
Yes

Di tru
End;
End
r D str 1 2 3

1 LabVIEW For Loop 2 Flowchart


owchart 3 Pseudo Code
C
To add a conditional terminal to a Forr Loop,
p, right-click
right-c
right-cli on the For Loop border
bor and select

s
The For Loop is located on the Structures
ures palette. You also
uctures so can
an ppl
place
ace
ce a W
While Loop on the block rtcutt menu. Then
Conditional Terminal from the shortcut The wire the conditional tterminal and the count
diagram, right-click the border off the While Loo
Loop elect
lect Replace w
Loop, and select with For Loop from the terminal.
t fo l In

l In
shortcut menu to change a Whilee Loop to a For Loop. The count terminal
termi is an input terminal
whose value indicates how many times mes to repeat
rep the subdiagram.
diagram. Figure 3-20. Adding
dding a Conditional
Co
C nal Terminal to a For Loop

al is ann output terminal


The iteration terminal ter
te hat
hat contains the
that t number of completed iterations.
No na

No na
The iteration count
nt for the Fo p always
For Loop ways starts at zero.
tio

tio
The For Loop
oop in Figure 33-18 generates
nerates
erates a ra
random
ndom number every second for 100 seconds and
displayss the
he random nu
numbers in a numeric indindicator.
Figure 3-18.
F
Fig 3-1 For Loop Example
Na

Na
National Instruments | 3-19 3-20 | ni.com
LabVIEW Core 1 Course Manual Lesson 3 Implementing a VI

Using For Loops for Error Checking and Error Handling Comparing For Loops and While Loops
In a For Loop with a conditional terminal, you also must wire a value to thehe co
count terminal or For Loops and While Loops differ in several distinct ways. Refer to Table 3-3 ffor a list of
auto-index an input array to set a maximum number of iterations. The For or Loop exe
executes until an differences between For Loops and While Loops.
error occurs or until the number of set iterations completes. Refer to Using Loops for Error
ing While Lo
Loop

uti ts

uti ts
Checking and Error Handling for more information. Table 3-2. Comparing For Loops and While Loops
oops

For Loop While Loop


Numeric Conversion in For Loops

rib en

rib en
Executes a set number of times unless a Stops executing
ng only if th
the value at thee
As noted in Numeric Conversion, when you wire different data ata type
types
ypess to the iinput off a function,
unction, the conditional terminal is added rminal meets
conditional terminal mee the conditionition

on

on
oweve
function generally returns the larger or wider data type. However,ever,
r, if you w
wire a double-precision
ble-precision
double-precision,
floating-point numeric value to the 32-bit count terminal al onn a For Loop
Loop, LabVIEWVIEWW coerces the Can execute zero times Must execute
cute at least once

ist um

ist um
larger numeric value to a smaller 32-bit signed integer.r. Although the conversion sion is contrary tto
Tunnels automatically output an array of data Tunnels
els automatically
automatic output
put the last value
valu
normal conversion standards, it is necessary, becausese a For Loop cca can only execute
xecute an integ
integer
number of times.
F. Timing a VI
Figure 3-21. Coercion
oercion
cion on a For
Fo Loop
When a loop finishes executing an iteration,, it immediately beginss executing
ecuting the nnext iteration,
r D str

r D str
ten,, you need to control th
unless it reaches a stop condition. Most often, thee iteration freq
frequency or timing.
For example, if you are acquiring data, and d you want
want to acquire
ree the data once every 10 seconds,
tions so they occur
you need a way to time the loop iterations oocc oncee every
very 10 seconds.
seco
secon
1
ution to occur aat a certain
Even if you do not need the execution ainn frequency,
frequency yoyou need to provide the
t fo l In

t fo l In
processor with time to complete other tasks, suc sponding
nding to the user interface. This section
such as responding
introduces some methods for timingg your loops.
loo

1 Coercion Dot
Wait Functionss
For better performance,
ce, avoid
void coercio
coercion by using
ing matching da
data types or programmatically Place a wait function insidee a loop to aallow a VI to sleep fo
for a set amount of time. This allows your
No na

No na
hingg data types, aas shown in
converting to matching n Figure 3-2
3-22
3-22. ss other
processor to address her tasks during
du
dur the waitt time. Wai
Wait functions use the millisecond clock of
tem.
the operating system.
Figure
ure 3-22. A
Avoiding
g Coercion
Coercio
erc By Using
U
Us Matching Data Types
The Wait Until til Next
ext ms Multiple
Mult nction
on monitors
function monit a millisecond counter and waits until the
tio

tio
millisecondd counter reaches
reache a multiple
tiple of the amou
amount you specify. Use this function to synchronize
activities.. Place this function
func in a loop to control
contro the loop execution rate. For this function to be
ve, your code execution
effective, ex mee must be less
time le than the time specified for this function. The
ution
executionn rate for th eratio off the loo
the first iteration lo
loop is indeterminate.
Na

Na
he Wait (m
The ction waits until
(ms) function
eci This function guara
you specify.
until the millisecond counter counts to an amount equal to the input
guaran
guarantees that the loop execution rate is at least the amount of the input
you specify.

National Instruments | 3-21 3-22 | ni.com


LabVIEW Core 1 Course Manual Lesson 3 Implementing a VI

Note The Time Delay Express VI behaves similarly to the Wait (ms) function with the You can add more than one shift register to a loop. If you have multiple operations that use previous
addition of built-in error clusters. Refer to Lesson 2, Troubleshooting and Debugging iteration values within your loop, use multiple shift registers to store the data values from those
VIs, for more information about error clusters. different processes in the structure, as shown in the following figure.

uti ts
Figure 3-23. Using Multiple Shift Registers

uti ts
s
Elapsed Time
In some cases, it is useful to determine how much time elapses afterfter some point iin your VI. The

rib en

rib en
pses after the specified
Elapsed Time Express VI indicates the amount of time that elapses sp start time.
This Express VI keeps track of time while the VI continues to o execute.
xecute. This Expresss VI does nnot
provide the processor with time to complete other tasks. Youu willl use the E
Ela
Elapsed Time Express VI

on

on
in the Weather Station course project.

ist um

ist um
G. Data Feedback in Loops Initializing Shift Registers
Initializing a shift register resets the value thee shift
hift register ppasses to
o the first iterati
iteratio
iteration of the loop
When programming with loops, you often must when the VI runs. Initialize a shift register byy wiring a conco
control or constantt to the shift
s register
r D str ust access ddata from previous iteration
itera
iterations
tio of the loop in

r D str
ring
LabVIEW. For example, if you are acquiring g one piece oof data in
n each iteration
iteration oof a loop and must hown
terminal on the left side of the loop, as shownwn in Figure 3-24.
st retain the data from
average every five pieces of data, you must om
m previous iterations
itera of the loop.
Figure 3-24.
4. Initialized
Initialize Shift Register
ister
Note Feedback Nodes are another me
met
method forr retaining
retaining inform
information from a previous
t fo l In

t fo l In
iteration. Refer to the Feedback Node topic of the H for more information
he LabVIEW Help
about Feedback Nodes.

Shift Registers
No na

No na
Shift registers are similar
milar
ar to static va
variables in
n text-based pr
programming languages.
In Figure 3-24, the For Loop execut
executes five times,, increment
in
incrementing
cremen the value the shift register carries by
Use shift registersrs when
hen you want
wan to pass
wa ass values
alu from
value m pprevious iterations through the loop to the fter five iteration
one each time. After teratio of the Forr L
iterations Loop, the sh
shift register passes the final value, 5, to the
next iteration. A shift
hift register appearss as a pair of te
terminals directly opposite each other on the he VI quits. Each time you
indicator and the ou run
un the
th VIVI, the shift register begins with a value of 0.
vertical sidess of the loop border.
bor
tio

tio
If you do not
ot initialize the shift
s register,
gister, the loop uses
u the value written to the shift register when
the loop last
st executed or, if the loop
oop has never exeexecuted, the default value for the data type.

minal on the rright side


The terminal dee of
o tthe loop
oop
op co
contains an up arrow and stores data on the completion Use an uninitialized
ninitialized shift
s register
ister to preserve
reserv state information between subsequent executions of
Lab
La
of an iteration. LabVIEW ansfers th
transfers the data connected to the right side of the register to the next a VI. Figure shows an
gure 3-25 ssh uninitialized
n uninitiali
uni niti shift
shh register.
Na

teration.
ration. After the
iteration.
stored in the sh

eate a ssh
Create
th loop executes,
ecutes, the te

ster by right-clic
shift register
ster.
shift register.
terminal on the right side of the loop returns the last value

right-clicking the left or right border of a loop and selecting Add Shift
er from thee shortcut menu
Register menu.
Na Figure 3-2
3-25. Uninitialized Shift Register

ny data type and automatically changes to the data type of the first object
A shift register transfers any
wired to the shift register. The data you wire to the terminals of each shift register must be the same
type.

National Instruments | 3-23 3-24 | ni.com


LabVIEW Core 1 Course Manual Lesson 3 Implementing a VI

In Figure 3-25, the For Loop executes five times, incrementing the value the shift register carries H. Plotting Data Waveform Chart
by one each time. The first time you run the VI, the shift register begins with a value of 0, which
is the default value for a 32-bit integer. After five iterations of the For Loop,p, thee shift
shi register passes
sh The waveform chart is a special type of numeric indicator that displays one or m mo
more plots of data
the final value, 5, to the indicator, and the VI quits. The next time you run un thehe VI
VI,, the shift register typically acquired at a constant rate. Waveform charts can display single
le or multiple pplots.

uti ts

uti ts
begins with a value of 5, which was the last value from the previous execution.
ecution.
cution. After
After five
ffi iterations lots
Figure 3-27 shows the elements of a multiplot waveform chart. Two plotsots are displayed:
displaye
display Raw Data
of the For Loop, the shift register passes the final value, 10, to the indicator.
dicator.
ator. If you runru the VI again, and Running Avg.
the shift register begins with a value of 10, and so on. Uninitialized ed shift
shifft registers retain the value
Figure 3-27. Elements of a Waveform
m Charts
harts

rib en

rib en
of the previous iteration until you close the VI.

on

on
Stacked Shift Registers 1
6

Stacked shift registers let you access data from previous us loop
oop iter
iterations
iterations.
ation Stackedked shift register
registers

ist um

ist um
remember values from multiple previous iterations andd car arry
ry those va
carry values to the
he next iteration
iteratio
iterations. To
rminal
nal and selec
create a stacked shift register, right-click the left terminal sele lement from th
select Add Element the
shortcut menu. 2

eft side
Stacked shift registers can occur only on the left ide of the loo use the
loop because he right term
terminal transfers
eration
ation to the next
the data generated from only the current iteration nex iteration,
tion, as shown ini Figure 3-26.
r D str

r D str
3
Figure 3-26. Using
sing Stacked Shift Registers
5
t fo l In

t fo l In
4

1 Label 3 X-scale
X 5 Graph Palette
2 Y-scale 4 Scale Legend 6 Plot Legend

Configure how the chart


hart updates
pdates tto
oddi
display new
ew data. Right-
Right-click the chart and select Advanced
No na

No na
Update Mode from m thee shortcut m
me he chart update
menu to set the upda mode. The chart uses the following
upd
If you add anotherer element
ement to the left terminal
minal in thehe previous
prev block diagram, values from the last a:
modes to display data:
arry
two iterations carry y over to the nnext iteration,
eration,
on, with
w the most recent iteration value stored in the top Shows running
rtShows
Strip ChartShows runn
run ta continuously
data ntinuo scrolling from left to right across the chart
shift register. Thee bottom term toress the data
terminal stores daata passed
pa to it from the previous iteration. a new
with old data on the left and w data
ata on the right.
ri
righ A strip chart is similar to a paper tape strip
tio

tio
ecorder.
corder. Strip C
chart recorder. Chart iss the default upd
upda
update mode.
ChartSh
pee ChartShows
Scope ChartShow tem
one itemm of data, such
suc as a pulse or wave, scrolling partway across the
hart from left to rright. For
chart or eeach new vavalu
value, the chart plots the value to the right of the last
ue. When the plot reaches
value. aches
hes the
th right
ht border
b of the plotting area, LabVIEW erases the plot and
Na

Na begins plottin

C
plotting again from
oscillosc
an oscilloscope.
Sweep ChartWorks
m the left bborder. The retracing display of a scope chart is similar to

Works similarly to a scope chart except it shows the old data on the right and
ne data onn the left separated
the new separat by a vertical line. LabVIEW does not erase the plot in a sweep
separa
t right border of the plotting area. A sweep chart is similar to an
chart when the plot reaches the
EKG display.

National Instruments | 3-25 3-26 | ni.com


LabVIEW Core 1 Course Manual Lesson 3 Implementing a VI

Figure 3-28 shows an example of each chart update mode. The scope chart and sweep chart have I. Case Structures
retracing displays similar to an oscilloscope. Because retracing a plot requires less overhead, the
scope chart and the sweep chart display plots significantly faster than the strip
ip cch
chart. A Case structure has two or more subdiagrams, or cases.

uti ts

uti ts
Figure 3-28. Chart Update Modes

rib en

rib en
xecutes
utes only one
Only one subdiagram is visible at a time, and the structure executes on case at a time. An

on

on
input value determines which subdiagram executes. The Case ase structure
tructure is similar to switch
witch
gramming
mming langu
statements or if...then...else statements in text-based programming languages.

ist um

ist um
The case selector label at the top of the Case structuree contains
ntains the name
nna of the
he selector valu
value that
Wiring Charts corresponds to the case in the center and decrementt and nd increment arrowss on each side.
side
You can wire a scalar output directly to a waveform
rm chart. The waveform
w m chart
hart terminal
termina shown in
Figure 3-29 matches the input data type.
Figure 3-29. Wiring a Single Plot to
t a Waveform
eform Chart Click the decrement and increment arrows too scroll through
throu the available
vailable
ailable cases. You
Yo also can click
r D str

r D str
the down arrow next to the case name andd select
elect a case from
f thee pull-down menu.
men
m

he selector
Wire an input value, or selector, to the elector term
termi
terminal to determine
rmine which case executes.
t fo l In

t fo l In
alue, stri
You must wire an integer, Boolean value, string, or enumerated type value to the selector terminal.
orr terminal
You can position the selector term yw
anywhere onn the left border of the Case structure. If the data
inal is Boolean,
type of the selector terminal Boolea the structureucture
cture has a TrTrue
rue case and a False case. If the
Waveform charts can display
lay multiple plots together
ogether using the
th Bundle function located on the ger, string, oor enumerated
selector terminal is an integer, erated type value
value, the structure can have any number
No na

No na
ant palette. IIn Figure 3-30, the Bundle
ariant
Cluster, Class & Variant Bund function bundles the outputs of the
Bun of cases.
he waveform chart.
three VIs to plot on the
Note By default, string
stri valuesues you wire
w too the tth selector terminal are case sensitive. To
Figure 3-3
3-30.
3 Wiring
ring Multi
Multiple P
Plots to a Waveform Chart w case-insensitiv
allow ase-insensiti matches,
case-insensitive hes, wire a sstrin
string value to the selector terminal, right-click the
order of the Ca
border Case structure,
ure, and select Ca
Case Insensitive Match from the shortcut menu.
C
tio

tio
d
If you do not specify a default ase
se for the Case structure to handle out-of-range values, you must
case
citly
explicitlyy list every po
possible inpu alue.
ue. For
input value. Fo example, if the selector is an integer and you specify
es for
cases or 1, 2, and 3, you mustst specify
spe
specif a default
d
de case to execute if the input value is 4 or any other
Na

The waveform
wave chart
art terminal ch
cha
changes to match the output of the Bundle function. To add more
oning tool to
plots, use the Positioning t resize the Bundle function.
Na
nspecified
specified integer
unspecified integ
intege value.

Note
No
Not
e.

Youu cannot specify a default case if you wire a Boolean control to the selector.
If you right-click
ght-click the cas
hortcut menu. M
in the shortcut
case selector label, Make This The Default Case does not appear
Make the Boolean control TRUE or FALSE to determine which
ute.
case to execute.

To convert a Case structure to a Stacked Sequence structure, right-click the Case structure and
select Replace with Stacked Sequence from the shortcut menu.

National Instruments | 3-27 3-28 | ni.com


LabVIEW Core 1 Course Manual Lesson 3 Implementing a VI

Right-click the Case structure border to add, duplicate, remove, or rearrange cases, and to select a Input and Output Tunnels on Case Structures
default case.
You can create multiple input and output tunnels for a Case structure. Inputs are av
available to all cases,
but cases do not need to use each input. However, you must define an output put tunnel fo
for each case.
Selecting a Case

uti ts

uti ts
Figure 3-31 shows a VI that uses a Case structure to execute different nt code depende
dependent on whether Consider the following example: a Case structure on the block diagram ram
m has an outpu
output tunnel, but
a user selects C or F for temperature units. The top block diagram am shows the True
Tr case in the unnel.
el. If you run this case,
in at least one of the cases, there is no output value wired to the tunnel.
LabVIEW does not know what value to return for the output. LabVIEW abVIEW
VIEW indicates
indicat
indica this error
er by

rib en

rib en
ed. To select a ca
foreground. In the middle block diagram, the False case is selected. ccase, enter
er th
the value
Aft you select
in the case selector identifier or use the Labeling tool to edit the values. After electt anothe
another leaving the center of the tunnel white. The unwired case mightt not ot be the case that iss currentl
rrentl
currently
case, that case displays on the block diagram, as shown in thee bottom
tom block diagram
d m of Figure 3-31.
3-31 visible on the block diagram.

on

on
Figure 3-31. Changing the Case View
ew of a Case St
S
Structure
e he unwired
To correct this error, display the case(s) that contain(s) the nwired outp nel and wire an
output tunnel

ist um

ist um
output to the tunnel. You also can right-click the outputt tunnel
nnel and select
sele
sel Use Default If Unw Unwired
unnel data type
from the shortcut menu to use the default value for the tunnel t for alll unwired tunnels.
tunn
unnel
When the output is wired in all cases, the output tunnel el is a solid ccolor.

Avoid using the Use Default If Unwired option. n. Using this opt
op
option does es not
ot document tthe block
diagram well, and can confuse other programmers mers using your code. The Use se Default If Unwired
r D str

r D str
option also makes debugging code difficult. If you use this o op
option, bee aware thatt the ddefault value used
red to the tunnel.
is the default value for the data type that is wired tun Forr example, if the
th tunnel is a Boolean
data type, the default value is FALSE. Refer to Table 3-3 for a list ist off default values
valu for data types.

Table
le 3-3.
-3. Data Type
Ty Default
ault
ult Values
t fo l In

t fo l In
Data Type Default Value
Def
Numeric 0

Boolean FALSE
No na

No na
String empty ("")

Examples
es
In the following
wing examples,
examples the
t numeric
mericc values pass
pas through tunnels to the Case structure and are
tio

tio
If you enterr a selector value
valu that iss not the same tyttype
y as the object wired to the selector terminal,
the valuee appears red. Thi ates
tes that the VI w
This indicates will not run until you delete or edit the value. Also, ed
either addedd or subtracted
subtracted depending
subtracted, nding
ding on the valu
va
value wired to the selector terminal.
becausee off the possible round-offf error inheren
inherent in floating-point arithmetic, you cannot use
ing-point
-point numbers
floating-point numbe as caseasee selector
se orr values.
valu If you wire a floating-point value to the case,
bVIEW rounds tthe valuee to the nnearest
LabVIEW ea integer. If you type a floating-point value in the case
Na

selector
lector label, the
th value appears
structure can eexecute.
pears red to indicate
i that you must delete or edit the value before the

Na
National Instruments | 3-29 3-30 | ni.com
LabVIEW Core 1 Course Manual Lesson 3 Implementing a VI

Boolean Case Structure String Case Structure


Figure 3-32 shows a Boolean Case structure. The cases overlap each other to simp
simplify the illustration. Figure 3-34 shows a string Case structure.

Figure 3-32. Boolean Case Structure Figure 3-34. String Case Structure

uti ts

uti ts
rib en

rib en
on

on
ist um

ist um
If the Boolean control wired to the selector terminal
rminal
nal is True, tthe VI adds the numeric values. If String is add, the VI adds the numeric values.
ues. If String is subtract
act, the VI subt
subtracts the
ues.
es.
Otherwise, the VI subtracts the numeric values. numeric values.
r D str

r D str
In situations where you are simply choosing
singg between two
tw valuess based
based on a boolean
boo
bo input, a Select Enumerated Case Structure
e
oolean
an Case structure.
statement can be used rather than a Boolean sstru
Figure 3-35 shows an enumerated Case
ase structure.
t fo l In

t fo l In
Figure
re 3-35. Enumerated
Enume
nume Case
se Structure

Integer Case Structure


cture
Figure 3-33 shows an integer
teger
er Case structure.
stru

Figure 3-33. Integer


nteger Case Structure
St
No na

No na
tio

tio
An enumerated
numerated
rated type ccontrol giv
gives users a list
l of items from which to select. The data type of an
merated
ated type con
enumerated cludes
udes iinformation
control includes mati about the numeric values and string labels in the
Na

er is
Integer i a text ring
ing control located
loca on the Text Controls palette that associates numeric values
loc
with text items. If thee Integer wired
w to the selector terminal is 0 (add), the VI adds the numeric
Na
ontrol.
ntrol. The case selectorr displays
control.

ype control.
plays the string
s label for each item in the enumerated type control
when you select Add Casee For Every Value from the Case structure shortcut menu. The Case
structure executes
type
exec
exe the appropriate ccas
case subdiagram based on the current item in the enumerated
control In the previous block diagram, if Enum is add, the VI adds the numeric values. If
Enum is subtract ct, the VI sub
subtracts the numeric values.
subt

values. If the value is 1 (sub


subtract), the VI subtracts the numeric values. If Integer is any other
value than 0 (add) or 1 (subtract), the VI adds the numeric values, because that is the default
case.

National Instruments | 3-31 3-32 | ni.com


LabVIEW Core 1 Course Manual

Using Case Structures for Error Handling


The following example shows a Case structure where an error cluster defines
nes the cases.

Figure 3-36. No Error Case

uti ts

uti ts
rib en

rib en
on

on
ist um

ist um
Figure 3-37.
-37.. Error Cas
Case
r D str

r D str
t fo l In

t fo l In
No na

No na
When you wire an error
rror cluster
uster to the
th selectorr terminal of a Case structure, the case selector label
sError
displays two cases rror and N No Erroro and nd the border
bor of the Case structure changes
colorred for Error
rrorr and green for No Errorror. If ann er
err
error occurs, the Case structure executes the
Error subdiagram.
gram.
m.
tio

tio
When you wire an error cl
cluster to
clu tterminal, the Case structure recognizes only the
o the selection ter
status Boolean
olean element of the cluster.
oolean luster.
uster.
Na

Na
National Instruments | 3-33
LabVIEW Core 1 Course Manual

Self-Review: Quiz
1. If an input to a function is marked with a red dot (known as a coercion
on dot), what
wh does the dot
indicate?

uti ts

uti ts
a. Data was transferred into a structure.
b. A For Loop was configured with a conditional terminal.

rib en

rib en
c. A For Loop iteration terminal is unwired.
d. The value passed into a node was converted to a different
fferent representation.
nt represent
represe

on

on
ist um

ist um
2. Which structure must run at least one time?
a. While Loop
b. For Loop
r D str

r D str
3. Which is only available on the block
ock diagram?
iagram?
a. Control
t fo l In

t fo l In
b. Constant
c. Indicator
d. Connector pane
No na

No na
nical action caus
4. Which mechanical ool
causes a Boolean ontrol in the FALSE state to change to TRUE
control
ick itt and stay T
when you click ntil Lab
TRUE until LabVIEWW hhas read the value?
a. Switch
h until
ntil released
tio

tio
b. Switch
tch when released
itch releas
relea
atch until released
c. Latch relea
rele
d.. Latch
atch when rreleased
re
Na

Na
National Instruments | 3-35
LabVIEW Core 1 Course Manual Lesson 3 Implementing a VI

Self-Review: Quiz Answers Notes


1. If an input to a function is marked with a red dot (known as a coercion
on dot), what
wh does the dot
indicate?

uti ts

uti ts
a. Data was transferred into a structure.
b. A For Loop was configured with a conditional terminal.

rib en

rib en
c. A For Loop iteration terminal is unwired.
d. The value passed into a node was converted to a different representation.
erent rep
repre ion.

on

on
ist um

ist um
2. Which structure must run at least one time?
a. While Loop
b. For Loop
r D str

r D str
3. Which is only available on the block
ock diagram?
iagram?
a. Control
t fo l In

t fo l In
b. Constant
c. Indicator
d. Connector pane
No na

No na
nical action caus
4. Which mechanical ool
causes a Boolean ontrol in the FALSE state to change to TRUE
control
ick itt and stay TRUE
when you click T ntil you release
until r se iit and LabVIEW has read the value?
a. Switch
h until
ntil released
tio

tio
b. Switch
tch when released
itch releas
relea
atch until released
c. Latch relea
rele
d.. Latch
atch when released
r d
Na

Na
National Instruments | 3-37 3-38 | ni.com
Lesson 4 Developing Modular Applications

Developing Modular Applicationss


4 A. Understanding Modularity
Modularity defines the degree to which a program is composed of discrete
te modul
mod
modules such that a
change to one module has minimal impact on other modules. Modules in LabVIEW
abVIEW are called

uti ts

uti ts
subVIs.

This lesson describes how to develop modular applications. The power wer of LabVI
LabVIEW lies in the A VI within another VI is called a subVI. A subVI corresponds to o a ssubroutine
ubroutine in text-based

rib en

rib en
hierarchical nature of the VI. After you create a VI, you can usee it on
n the block diagram
m of an
another programming languages. When you double-click a subVI, a front nt panel
anel and bloc
blo
block diagramram aappear,
y. Using
VI. There is no limit on the number of layers in the hierarchy. sing modular
modula programming
amming
ming help
helps rather than a dialog box in which you can configure options. The front panel iincludess controls
ntrols an
and
cons, functions,
indicators. The block diagram includes wires, front panel icons, function possibly ly subVIs,
ubVIs, and

on

on
you manage changes and debug the block diagram quickly.
other LabVIEW objects that also might look familiar.
Topics

ist um

ist um
ock diagram
The upper right corner of the front panel window and block diagram w w displays the ic
window ico
icon for
A. Understanding Modularity rs when
the VI. This icon is the same as the icon that appears hen you place
plac
plac the VI on the block di
ddiagram.

B. Building the Icon and Connector Pane form


As you create VIs, you might find that you performm a certain operation
oop n frequently.
quently. Consider
Con using
C. Using SubVIs petitively.
tively. For ex
subVIs or loops to perform that operation repetitively. example, the following bblock diagram
contains two identical operations.
r D str

r D str
Figure 4-1. Block Diagram
gram with Tw
Two Identical
tical
ical Operations
t fo l In

t fo l In
No na

No na
Figure 4-2. Block Diagram
ram with SubVIs
Su for Identical Operations
tio

tio
Na

Na
The example calls the Temperature
Temp
Temper VI as a subVI twice on its block diagram and functions the
k ddiagram. You also can reuse the subVI in other VIs.
same as the previous block

National Instruments | 4-1 4-2 | ni.com


LabVIEW Core 1 Course Manual Lesson 4 Developing Modular Applications

The following pseudo-code and block diagrams demonstrate the analogy between subVIs and Creating an Icon
subroutines.
Icons are graphical representations of VIs.
Function Code Calling Program
rogram Cod
Code Every VI displays an icon in the upper right corner of the front panel and
ndd bloc
block diagram windows.
k diagr
diagra

uti ts

uti ts
function average (in1, in2, out) main
{ {
out = (in1 + in2)/2.0; average (point1,
nt1, point2,
poin pointavg)

rib en

rib en
} }
any new VIs, up to nine VIs,
The default VI icon contains a number that indicates how many s, you have
hav

on

on
SubVI Block Diagram Calling
ing VI Block
Bl Diagram
m opened since launching LabVIEW. To disable this numbering,ng, select
lect Tools
Tool onsFront
Front Panel
ToolsOptionsFront
and remove the checkmark from the Use numbers in icons ons of new VIs (1 throughh 9) checkbo
ough checkbox.

ist um

ist um
An icon can contain text or images. If you use a VI ass a subVI, the ic
iicon identifies
tifies
fies the subVI on the
ette,, th
block diagram of the VI. If you add the VI to a palette, thee VI icon also appears
ppears
ears on the Fu
F
Functions
palette.

n. Double-click
Use the Icon Editor dialog box to edit a VI icon. Double-cl the icon in the uppe
upper right corner
B. Building the Icon and Connector
onnecto Pane
ne
r D str

r D str
w to display the
of the front panel or block diagram window th Icon Editor
ditor dialog bo
box
box.

After you build a VI front panel and block


ock diagram, build
bu the icon
iccon
on and the con
connector pane so you tom control
Create an icon to represent a VI or custom control grap y. Use the Icon E
graphically. Editor dialog box to
can use the VI as a subVI. The icon and connector
connector ppane correspond
rrespond ffunction prototype in
pond to the fu create or edit icons.
text-based programming languages. Every
s. Ev
very displays an icon
ery VI displ pper right corner of the front
on in the upper
t fo l In

t fo l In
panel and block diagram windows.ws. elated VIs. Natio
You can use banners to identify related trument
umentss recom
National Instruments recomm
recommends creating and saving
a banner as a template. You then can use this te
templatee forr a related VI
V icon and modify the body
fo
of the VI icon to provide information t specific
about the cific VI.

A VI icon is a graphicall representation


presentation of a VI.. It can contain
contain ttext, images, or a combination of Saving a Banner
er as a Template
Tem
both. If you use a VI as a subVI, the iicon identifies
ntifies
ntifi es the subV
subVI on the block diagram of the VI. If Complete the following
ing steps
eps to save a banner
er as an icon tem
template for a VI.
No na

No na
you add the VI to a palette,
ette, the
the VI ic ears on the F
icon also appears Functions palette. You can double-click
ont panel window or block
the icon in the front ock diagram
d
di m window
win to customize or edit it. 1. Double-click the icon upper right
con in the up ght corner
err of the front panel window or block diagram
window, or right-click icon and select
click the ic
ico ct Ed
Edit Icon
E n ffrom the shortcut menu, to display the Icon
alog box.
Editor dialog
Note
te Customizin the icon
Customizing on iss recomme
recommend
recommended, but optional. Using the default LabVIEW
tio

tio
con
on does not affe
icon aff ctionality.
affect functionality. 2. Press the key to select
hee <Ctrl-A> keys ctt alll user layers of the icon, and press the <Delete> key to delete
lection.
on. The default
the selection. def on
n is a single us
icon use
user layer called VI Icon.
so need to build a connector pane to us
You also use the VI as a subVI. 3. Onn the Templates page, selectt the _blan
_blank.png icon template from the VIFrameworks
_bl
gory. You can
category. ca browse
see templates
temp
tem es by category or by keyword.
Na

connecto pane iss a set of termi


The connector
milar to the
similar
pane defin
th parameter
termin
terminals that correspond to the controls and indicators of that VI,
meter list off a function
nputs and outpu
defines the inputs
fun call in text-based programming languages. The connector
outputs you can wire to the VI so you can use it as a subVI. A connector
pane receives data at its input tterminals and passes the data to the block diagram code through the
Na
4.. Use the Fill tool
with a color.

the text
color
to on the

tex by pressing
he right
ight side of the Icon Editor dialog box to fill the banner of the icon

T tooll to enter text in the banner of the icon. While the text is active, you can move
5. Use the Text
ssing the arrow keys.
6. Select FileSavee AsTemplate
AsTemp to display the Save Icon As dialog box and save the icon as a
ece
front panel controls and receives the results at its output terminals from the front panel indicators. template for later use. LabVIEW saves icon templates as 256-color .png files.
e. La
Lab

National Instruments | 4-3 4-4 | ni.com


LabVIEW Core 1 Course Manual Lesson 4 Developing Modular Applications

Creating a VI Icon from a Template Setting up the Connector Pane


Complete the following steps to create a VI icon that uses the template you
u cre
created. Define connections by assigning a front panel control or indicator to each of ththe connector pane
1. Press the <Ctrl-A> keys to select all user layers of the icon, and press the <Delete> key to delete terminals. The connector pane is located to the left of the VI icon in the upper
per right corner of the
front panel window. When you open LabVIEW, you see a default connector ector pattern.
nector

uti ts

uti ts
the selection.
n browse
2. On the Templates page, select the template you created. You can rowse templa
templates by category Each rectangle on the connector pane represents a terminal. Use thee rectangles aassign inputs and
ctangles to as
or by keyword. outputs. The default connector pane pattern is 4 2 2 4. Youu can
an select a di
ddifferent pattern
pa by

rib en

rib en
3. On the Icon Text page, enter up to four lines of icon text for the body of tthe icon. n. You
ou ca
can he shortcut men
right-clicking the connector pane and selecting Patterns from the me
menu. If you ou antici
anticipate
configure the font, alignment, size, and color of the text. Iff youu place a che
checkmarkk in the Center eep the default cconnector
changes to the VI that would require a new input or output, keep or pane