Вы находитесь на странице: 1из 99

uti ts

TM
LabVIEW Core 1

rib en
Exercises

on
ist um
r D str
Course Software Version 2012
August 2012 Edition
Part Number 325291D-01

t fo l In
LabVIEW Core 1 Exercises

Copyright
19932012 National Instruments. All rights reserved.
nsmitted
Under the copyright laws, this publication may not be reproduced or transmitteditted in any form,
fo ctronic
tronic or mechanical,
electronic mechan including photocopying, recording, storing in an information retrieval system, or
translating, in whole or in part, without the prior written consent of National Instruments Corporation.
ationall Instrumen ration.
No na
National Instruments respects the intellectual property of others, and users to do the same.
nd wee ask our user software is protected by copyright and other intellectual property laws. Where NI software may
e. NI softw
be used to reproduce software or other materials belonging to others,
ers, you may use NI
N software
ware only
onl to reproduce
prod materials that you may reproduce in accordance with the terms of any applicable license
or other legal restriction.
tio
End-User License Agreements and Third-Party
Party
arty Legal Notices
No
You can find end-user license agreements (EULAs) and third-party
hird-party legal notices
n in
n the following llo
locations:
Notices are located in the <National Instruments>\_Legal or tion and
s>\_Lega Information
ments>\_Lega an <National
< Instruments> directories.
EULAs are located in the <National Instruments>\Shared\MDF\Legal\license
ruments>\Shar
ents>\Shar F\Lega
\Leg ice
c directory.
Na

Review <National Instruments>\_Legal txt for more information


egal Information.txt
Informa in on including legal information in installers built with NI products.

Trademarks
LabVIEW, National Instruments, NI, ni.com, thee National IIn
Instruments logo, and the Eagle logo are trademarks of National Instruments Corporation. Refer to the Trademark Information at
nts corporate logo
ni.com/trademarks for other National Instruments ments trademarks.
t ks.
na
Other product and company names mentioned herein are trademarks or trade names of their respective companies.

Patents
For patents covering National Instruments products/technology, refer to the appropriate location: HelpPatents in your software, the patents.txt file on your media, or the National Instruments
Patent Notice at ni.com/patents.
uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio

Worldwide Technical Support and Product


duct
ct Informat
Information
Na

ni.com

Worldwide Offices
Visit ni.com/niglobal to access the branch office W
Web sites, which provide up-
up-to-date contact information, support phone numbers, email addresses, and current events.

National Instruments Corporate Headquarters


11500 North Mopac Expressway Austin, Texas 78759-3504 USA Tel: 512
5 683 0100

To comment on National Instruments documentation, refer to the National Instruments Web site at ni.com/info and enter the Info Code feedback.
uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
uti ts
Student Guide

rib en
A. NI Certification........................................................................................................................................................................................vii
.....................
................ ..........
.....
B. Course Description ..................................................................................................................................................................................viii
.....................
............... ....................
..............

on
C. What You Need to Get Started ................................................................................................................................................................ix
.....................
................ .....................
.................
D. Installing the Course Software ................................................................................................................................................................x
....................
............... ...................
.....................

ist um
E. Course Goals ...........................................................................................................................................................................................xi
.....................
.............. .....................
..................
F. .....................
.............. .......
..................
.............
Course Conventions.................................................................................................................................................................................xii

Lesson 1

r D str
Navigating LabVIEW
Exercise 1-1 Concept: Exploring a VI ............................................................................................................................................1-3
......................
............... ......................
...................
Exercise 1-2 Concept: Locating Controls, Functions, tions,
ns, and VIs VI ......................
................
VIs.......................................................................................................1-8
Exercise 1-3 ....................
..................... ......................
...................
Concept: Using Tool Selection ..................................................................................................................................1-11

t fo l In
Exercise 1-4 .................
................... ......................
.................
Concept: Dataflow .....................................................................................................................................................1-19
Exercise 1-5 .. ......... .....................
Simple AAP VI ..........................................................................................................................................................1-24

Lesson 2 No na
Troubleshooting and Debugging VIs
Exercise 2-1 Concept: Debugging
ng ..................
..................................................................................................................................................2-2
................. ....... .........
........

Lesson 3
tio
Implementing a VI
Exercise 3-1 Temperature
ure Warnings VI .........................................................................................................................................3-2
................
...............
Exercise 3-2 atchh VI ...........................................................................................................................................................3-11
Auto Match ..........
......... .........
...... ......
Na

Exercise 3-3 ept:


pt: While Loo
Concept: Loops versus ersusus For Loo Lo
Loops ..................................................................................................................3-21
Exercise 3-4 mperature Monitor
Temperature Mon VIAverage Temperature.....................................................................................................3-25
Exercise 3-5 perature Monitor
Temperature M r VIPlot
VIPlot M Mu
Multiple Temperatures ...........................................................................................3-29
Exercise 3-6 ature Warnings
Temperature ngs VIWith
VIW Error Handling ....................................................................................................3-35
VIWit

LabVIEW Core 1 Exercises National Instruments | v

Contents ni.com | vi

Lesson 4
uti ts
Developing Modular Applications
Exercise 4-1 Temperature Warnings VIAs SubVI .....................................................................................................................4-3
.....................
...............
rib en

Lesson 5
on

Creating and Leveraging Structures


Exercise 5-1 Concept: Manipulating Arrays...................................................................................................................................5-3
......................
............... ......................
ist um

Exercise 5-2 .....................


.............. .....................
..................
Concept: Clusters .......................................................................................................................................................5-15
Exercise 5-3 .....................
.............. ......................
.................
Concept: Type Definition ..........................................................................................................................................5-23

Lesson 6
r D str

Managing File and Hardware Resources


Exercise 6-1 Concept: Spreadsheet Example VI ............................................................................................................................6-3
.....................
................ ......................
...................
Exercise 6-2 Temperature Monitor VILoggingg Data..................................................................................................................6-7
Data.........
Data.......... ......................
.................
Exercise 6-3 Concept: NI Measurement & Automation utomation Exp Explorer (MAX).........
MAX)........
(MAX).....................................................................................6-13
t fo l In

Exercise 6-4 ................... ......................


................
Using DAQmx ...........................................................................................................................................................6-19
Exercise 6-5 Concept: GPIB Configuration on with MAX .................................................................................................................6-23
......................
Exercise 6-6 ............
.......... ......................
...................
Concept: NI Devsim VI .............................................................................................................................................6-27

Lesson 7
No na

Using Sequential and State Machine Algorithms


orithms
Exercise 7-1 State Machine VII .......................................................................................................................................................7-3
....................
................ ...............
......
tio

Lesson 8
sing
ng Varia
Solving Dataflow Challenges Using Variab
Variables
Exercise 8-1 Weather Station
ation UI VI
V with Local
Loc Variables.............................................................................................................8-3
Loca Variab
ariab
Na
Student Guide

uti ts
Thank you for purchasing the LabVIEW Core 1 course kit. You can begin developing an application

rib en
ion soon after
after you
y complete
mple the exercises in this manual. This exercise
manual and the accompanying course manual and software are used in the three-day, hands-onon LabVIEW C Core 1 course.
rse.

on
ration
on fee if you
You can apply the full purchase of this course kit toward the corresponding course registration yo register
sterr within 90 days
d of purchasing the kit. Visit
ni.com/training for online course schedules, syllabi, training centers, and class registration.
gistration.
tration.

ist um
A. NI Certification
The LabVIEW Core 1 course is part of a series of courses designed to build your
ur proficiency
roficiency wwith LabVIEW
abVIEW
VIEW and hhelp you prepare for the NI Certified LabVIEW
Associate Developer exam. The following illustration shows the courses that are part of the LabVIEWW training series.
IEW s Refer to ni.com/training for more

r D str
information about NI Certification.
LabVIEW
VIEW
W Training
Traini Courses
rsess

New User Experienced


Experien User Advanced User

t fo l In
Courses

LabVIEW Core 1* LabVIEW


Lab Cor
Core 3** Managing Software
Engineering in LabVIEW
LabVIEW Core 2*
W Connectivity
LabVIEW Advanced Architectures
in LabVIEW
No na Oriented Design
Object-Oriented Desig
and Programming
gramming
n LabVIEW
in EW

LabVIEW
VIEW Performance
Certifications
tio
Certified
ed LabVIEW
LabVIEW Certified LabVIEW Certified LabVIEW
Associate
e Developer Exam
Ex Developer Exam
Develo Architect Exam

Other Courses
ourses
Na

LabVIEW
bVIEW In
Instrument
stru Control L
LabVIEW Real-Time 1 LabVIEW Real-Time 2
LabVIEW
L abVIE FPGA LabVIEW
L bV DAQ and Signal Conditioning Modular Instruments Series

*Core courses are strongly


gly recommended to realize maximum productivity gains when using LabVIEW.

LabVIEW Core 1 Exercises National Instruments | vii

Student Guide ni.com | viii

B. Course Description
uti ts

The LabVIEW Core 1 course teaches you programming concepts, techniques, features, VIs, and functions
ctions
ns you ccan
an uuse to create test and measurement, data acquisition,
instrument control, datalogging, measurement analysis, and report generation applications. This course
rse assumes that you are familiar with Windows and that you have
ourse
rib en

ercisee manuals are divided


experience writing algorithms in the form of flowcharts or block diagrams. The course and exercise vided into lessons, described as follows.

In the course manual, each lesson consists of the following:


on

An introduction that describes the purpose of the lesson and what you will learn
ist um

A description of the topics in the lesson

A summary quiz that tests and reinforces important concepts and skills taught lesson
ght in the lesso
r D str

In the exercise manual, each lesson consists of the following:

A set of exercises to reinforce those topics

addit
add
Some lessons include optional and challenge exercise sections or a set of additional xercises to complete
exercises co if time permits
t fo l In

Note For course and exercise manual updates and corrections,


rrr s, refer to ni.com/info
.com/info an
and enter the Info Code core1.

Several exercises use one of the following National Instruments


ts hardware
ments hardwar products:
ucts:
cts:
No na

A plug-in multifunction data acquisition (DAQ) device


vicee connected to a BNC-2120
C-2120
C-2120 containing
cont
con a temperature sensor, function generator, and LEDs

A GPIB interface connected to an NI Instrumentt Simulator


mulator
tio

If you do not have this hardware, you still can complete


mplete the exercises.
exer
exe Alternate
Alternate instructions
instr are provided for completing the exercises without hardware.You also can
substitute other hardware for those previously mentioned. Fo For example,
mple, youu can uuse a GPIB instrument in place of the NI Instrument Simulator, or another National
ple, yo
Instruments DAQ device connected to a signal such as a function
nal source, suc tion generator.
ction gener
Na
C. What You Need to Get Started

uti ts
Suggested Reading
The suggested reading materials ensure that all students have a minimum knowledge of key theories
eories
es and conc
concepts
con elat to the LabVIEW Core 1 course. To get the
related

rib en
most out of this course, complete all the suggested reading material.

on
To access each of the following suggested reading materials, refer to ni.com/info and enter
ter the Info Code thatt correspond
correspon
corresponds to each topic:

ist um
LabVIEW Core 1 - The Software Development Method (Info Code: SoftDev)

Introduction to Data Acquisition (Info Code: DAQ)

GPIB Instrument Control Tutorial (Info Code: GPIB)

r D str
Serial Communication Overview (Info Code: Serial)

Course Materials
Before you begin this course, ensure you have all the following items:
ms:

t fo l In
Computer running Windows 7/Vista/XP

Multifunction DAQ device configured as Dev1 using Measurement


No na surement & Automation
mation Explor
Explore
Explorer (MAX)

DAQ Signal Accessory or BNC-2120, wires, and cable


able

GPIB interface

NI Instrument Simulator and power supply


tio

LabVIEW Full or Professional Development


ment
nt System 22012 or later
ater
er

DAQmx 9.5.5 or later


Na

NI-488.2 3.0.2 or later

NI VISA 5.2 or later

A serial cable

LabVIEW Core 1 Exercises National Instruments | ix

Student Guide ni.com | x

A GPIB cable
uti ts

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


rib en

Directory Description
escription
on

Exercises Folder for saving VIs created during the course and forr completing
completin certain course exercises;
exer also includes subVIs necessary
for some exercises and zip file (NI Instrument Simulator.zip
imulator ) containing
ntaining the LabVIEW instrument driver for the NI
ist um

Instrument Simulator

Solutions Contains the solutions to all the course exercisess

D. Installing the Course Software


r D str

Complete the following steps to install the course software.

1. Insert the course CD in your computer. The LabVIEW Core 1 Course


rse Setup ddialog box appears.
ourse
t fo l In

2. Click Install the course materials.

3. Follow the onscreen instructions to complete installation and setup.


nd set

Exercise files are located in the <Exercises>\LabVIEW ore 1\ fo


W Core folder.
No na

Note Folder names in angle brackets, such as <Exercise


Exercise , refer
<Exercises> fe to folders on
o the root directory of your computer.
tio
Na
E. Course Goals

uti ts
This course prepares you to do the following:

rib en
Understand front panels, block diagrams, icons, and connector panes

Use the programming structures and data types that exist in LabVIEW

on
Use various editing and debugging techniques

ist um
Create and save VIs so you can use them as subVIs

Display and log data

r D str
Create applications that use plug-in DAQ devices

Create applications that use serial port and GPIB instruments

This course does not describe the following:

t fo l In
Every built-in VI, function, or object; refer to the LabVIEW Help for more information
mation
on about
about L
LabVIEW features not described in this course

Analog-to-digital (A/D) theory No na


Operation of the serial port

Operation of the GPIB bus

Developing an instrument driver


tio

ny student in the
Developing a complete application for any tth class; refer to the NI
N Example Finder, available by selecting HelpFind Examples, for example VIs
you can use and incorporate into VIs you create
Na

LabVIEW Core 1 Exercises National Instruments | xi

Student Guide ni.com | xii

F. Course Conventions
uti ts

The following conventions appear in this course manual:


rib en

g box
The symbol leads you through nested menu items and dialog x options to a final
al act
action. The sequence ToolsInstrumentation
ols menu, selec
Find Instrument Drivers directs you to drop down the Tools sele
select the Instrumentation
Instrumen
rumen item, and finally select the Find
on

Instrument Drivers option.

This icon denotes a tip, which alerts you to advisory information.


nformation.
rmation.
ist um

This icon denotes a note, which alerts you to important


ortant information.
nt informa
informat

bold Bold text denotes items that you must select orr click
ick in the software,
s re, such as menu
men items and dialog box options. Bold text also
denotes sections of dialog boxes and hardwarere labels.
are
r D str

italic Italic text denotes variables, emphasis, a cross-referenc


cross-reference,
oss-referenc or ann introduction to a key concept. Italic text also denotes text that is a
placeholder for a word or value that you
ou must supply.
suppl
supply
t fo l In

monospace Text in this font denotes text or characters


aracters that you
y enterer from the keyboard,
ke
key sections of code, programming examples, and syntax
examples. This font also is used for the proper namess of disk drives
drives, paths, directories, programs, subprograms, subroutines, device
varia
names, functions, operations, variables, filen
filenames, extension
extensio
and extensions.

monospace bold Bold text in this font denotes


otes the messages
messag andd responses thattha the computer automatically prints to the screen. This font also
emphasizes lines of codee thatt are diffe
different from
m the other examples.
om ex
No na
tio
Na
1

uti ts
Navigating LabVIEW

rib en
on
ist um
Complete the exercises in this lesson to reinforce the concepts you learn in Lesson 1 off LabVIEW
abVIEW Core
C 1.

Exercises
Exercise 1-1 Concept: Exploring a VI

r D str
Exercise 1-2 Concept: Locating Controls, Functions, and
nd VIs
Exercise 1-3 Concept: Using Tool Selection
Exercise 1-4 Concept: Dataflow

t fo l In
Exercise 1-5 Simple AAP VI

No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 1-1


uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
Exercise 1-1 Concept: Exploring a VI

uti ts
Goal
As a class, identify the parts of an existing VI.

rib en
Description

on
You received a VI from an employee that takes the seconds until a plane arrives at an airport
portt and converts
conve the timeme into a combination
cco of hours/minutes/seconds.
You must evaluate this VI to see if it works as expected and can display the remaining time
me until the plane arrives.

ist um
1. Open Flight Delay.lvproj in the <Exercises>\LabVIEW Core 1\Exploring
ploring A VI directory.
Exploring irectory.

2. Open Seconds Breakdown.vi from the Project Explorer window.

r D str
nd of each item?
3. On the front panel, identify the following items. How many can you find item

Controls

Indicators

t fo l In
Free labels
Run button No na
Icon

Connector pane
tio
4. Press <Ctrl-T> to view the front panel and block
lock diagram aat the same time or se
select WindowTile Up and Down or WindowTile Left and Right.

Tip To switch between the front panell window aand the block
k diagram without tiling the windows, press <Ctrl-E>.
Na

LabVIEW Core 1 Exercises National Instruments | 1-3

Lesson 1 Navigating LabVIEW ni.com | 1-4

5. On the block diagram, identify the following items. How many can you find of each item?
uti ts

Controls

Indicators
rib en

Constants
on

Free labels
ist um

6. Use the Context Help to learn more about the items on the block diagram.

Press <Ctrl-H> to open the Context Help window or select HelpShow


w Context Help.
He
r D str

Move the Context Help window to a convenient area where the window
indow
dow does not
no hide part of the bloc
block diagram.

Place your cursor over each of the different color wires to see whichh data type
typ they represent.
resent.

The Context Help window content changes to show information


mation about the
th object
ct that your mouse
m
mo is over.
t fo l In

m r functi
7. Get detailed help and view examples for the Quotient & Remainder function.

Place your cursor over the Quotient & Remainder function.


tion. Read the Context
ntext Help window
ontext wi and click the Detailed Help link to launch the LabVIEW Help
and learn more about this function.
No na

Click the Example link in the Quotient & Remainder


nder topic oof the LabV
mainder LabVIEW
W Help.
Help

Click the Open Example button in the bottom


ottom
m of the he
hel
help window
dow
w to launch
launc an example that uses the Quotient & Remainder function.
tio

Examine the example and then close itt when you are finished.
hed.
ed.
Na
8. Refer to Figures 1-1 and 1-2 to verify that you identified all items correctly.

tio s
Figure 1-1. Front Panel Items

t
en
3 4 5

n
ist um
st
ri
2

t fo l In
No na
r
tio
Na

1 Indicators 2 Control
ontrol 3 Run Button
R 4 Connector Pane 5 Icon

LabVIEW Core 1 Exercises National Instruments | 1-5

Lesson 1 Navigating LabVIEW ni.com | 1-6

Figure 1-2. Block Diagram Items


uti ts

2
rib en
o
ist um

1
r D str

3
5
t fo In

4
No n
tio

1 Free Labels 2 Control 3 Indicators 4 String Constants 5 Numeric Constants


Na
9. Test the Seconds Breakdown VI using the values given in Table 1-1.

uti ts
Enter an input value in the Total Time in Seconds control.
Click the Run button.

rib en
For each input, compare the given outputs to the outputs listed in Table 1-1. If the VI works cor
corr
correctly, they should m
match.

on
Table 1-1. Testing Values for Seconds
onds Brea
Breakdown.vi
n.v
n.vi

ist um
Input Numeric Indicators LED Indicator
or String Indicator

0 seconds 0 hours, 0 minutes, 0 seconds Off Delay less than 1 hour

60 seconds 0 hours, 1 minute, 0 seconds Off

r D str
Delay less than 1 hour

3600 seconds 1 hour, 0 minutes, 0 seconds On Delay 1 hour or longer

3665 seconds 1 hour, 1 minute, 5 seconds On Delay 1 hour or longer

t fo l In
10. Save and close the VI and the LabVIEW Project.

End of Exercise 1-1 No na


tio
Na

LabVIEW Core 1 Exercises National Instruments | 1-7

Lesson 1 Navigating LabVIEW ni.com | 1-8

Exercise 1-2 Concept: Locating Controls, Functions, and VIs


uti ts

Goal
Learn to use the palettes and search for controls, functions, and VIs.
rib en

Description
on

1. Open a blank LabVIEW project.


ist um

Click the Create Project button in the LabVIEW Getting Started window andd then click Blank Project.
nk Project.

Click Finish.
r D str

2. Create a blank VI and add it to the project.

Right-click My Computer in the Project Explorer window andd select


lect NewV
NewVI from
New m the shortcut menu.

3. Select ViewControls Palette from the menu of the VI front panel


nel window.
t fo l In

4. Customize the Controls palette.

Click the Customize button and select Change Visible


ible Palettes.
Palette

Select the following palettes to add them to the Controls


No na

rols palett
palet
palette and click
lick the
th OK
K bbutton. Do not deselect any palettes.

Silver

Control Design & Simulation


tio

Signal Processing

Notice that the three palettes youu justt selected nnow appear
pear
ear in th
the Controls
Co window.
Na
5. Explore the Controls palette.

uti ts
Use palettes to locate controls and functions when you want to explore the options available to you or when yo
you are not sure of the name of the control or function
you need.

rib en
Click the Search button.

on
Type string control in the search text box.

ist um
Click String Control (Silver) in the search results and drag it to the front panel
nel window to place the
he object.

6. Open the block diagram and right-click anywhere on the block diagram to display
play Functions palette.
ay the Func ette.

Click the pin in the upper left-hand corner to keep the palette open.

r D str
Tip You can customize the Functions palette just like you customized
mized
zed the Controls
Con palette.

7. Explore the Functions palette.

t fo l In
Locate trigonometric functions.
Click the Search button.

Search for the term cosine.


No na
In the search results, double-click Cosine <<Trigonometric
<<Trigonomet
Trigonome ons>> to display
Functions>> d the function on the palette.

Locate file I/O functions.


tio
Search for the term file i/o.

Double-click File I/O in the search


archh results to ddisplay the File I/O palette.
p

Drag the Write To Text Filee function from the palette


alette the block diagram.
tte to th
Na

8. Practice using the Quick Drop feature.


ature.

Use the Quick Drop feature when you


u know the name function or VI you want to use.
ame of the fun
fu

Press <Ctrl-Space> to open the Quick Drop dialogg box.


box

LabVIEW Core 1 Exercises National Instruments | 1-9

Lesson 1 Navigating LabVIEW ni.com | 1-10

Type Bundle By Name and double-click Bundle By Name in the search results. The cursorr changes
anges to a hand with the Bundle By Name function.
uti ts

Click on the block diagram to place the Bundle By Name function.


Open the Quick Drop dialog box again.
rib en

Search for the Wait Until Next ms Multiple.


on

Double-click the function in the search results and place the function on the block
ock diagram.
ist um

9. Practice using the global search feature.

Type Random in the Search bar in the upper right hand corner of the block
ockk diagram.

es in the Lab
Note As you type, the global search automatically looks for matches
hes La
LabVIEW Help and LabV
LabVIEW palettes. It also searches for online material
r D str

related to your query.

Hover the mouse over the first result in the Palette section, Random
andom
dom Numb 1). You now see
Number (0-1). sse the following three options:
t fo l In

DropAllows you to place this function immediately on the block ddiagram


m

FindLocates the function on the Functions palette


ette
tte

on.
HelpBrings up the help topic for this function.
No na

Click each of these options to observe the different


erentt behaviors
behaviors.

10. Practice accessing similar functions.


tio

Place an Add function on the block diagram.


gram.
ram.

Right-click the Add function and notice


oticee that Numeric
Num
Nume tee is available
palette availa
availab from the shortcut menu.

Practice placing functions from the Numeric palette


p on the bloc
block diagram.
Na

11. Close the VI and LabVIEW project.


ect. You do no
not need save the files.
file

End of Exercise 1-2


Exercise 1-3 Concept: Using Tool Selection

uti ts
Goal
Become familiar with automatic tool selection and the Tools palette in LabVIEW.

rib en
Description

on
During this exercise, you complete tasks in a partially built front panel and block diagram.
m. These tasks give you experience using the automatic tool selection.

ist um
1. Open Using Temperature.lvproj in the <Exercises>\LabVIEW Core ature direc
e 1\Using Temperature
T erature directory.

2. Open Using Temperature.vi from the Project Explorer window.

3. Select ViewTools Palette from the menu to display the Tools window.

r D str
Tip Press <Shift> and right-click the front panel to open the Tools
ools palette temporarily.
tem rily.
ly.

By default, LabVIEW selects tools for you based on the context of your cursor
cursor. You can
an disable aut
automatic tool selection by clicking the Automatic Tool

t fo l In
Selection button in the Tools window.

No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 1-11

Lesson 1 Navigating LabVIEW ni.com | 1-12

Figure 1-3 shows an example of the front panel as it appears after your modifications. In steps 48 you
u increase
crease th
the size of the waveform chart, rename the numeric
uti ts
control, change the value of the numeric control, and move the knob.

Figure 1-3. Using Temperature VI Front


rontt Panel
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
4. Expand the waveform graph horizontally using the Positioning tool.

uti ts
Move the cursor to the right edge of the Chart waveform chart until you see the resizing nodes
des appear around
a the chart.

Move the cursor to the middle right resizing node until the cursor changes to a double arrow,

rib en
w, as shown
show in Figure
Figur 1-4.

Figure 1-4. Resize Waveform


orm Char
Chart

on
ist um
r D str
t fo l In
Drag the repositioning node until the waveform chart is the size you want.
No na
5. Rename the waveform chart using the Labeling tool.
ool.

Double-click the word Chart. LabVIEW


W highlights
ghlights the word andd automatic
automat
automatically selects the Labeling tool in the Tools window.
tio
Enter the text Temperature Chart
t.

Complete the entry by clicking outside


utside
de the control
contr labell or clicking
cl
c ing
ng the
th Enter Text button on the toolbar.
Na

Notice that LabVIEW automatically


lly retu
re
returns to the Positioni
Positionin
Positioning tool in the Tools window. The Positioning tool is the default tool. If LabVIEW does not switch
back to the Positioning tool, click the Automatic Selection button in the Tools window to enable automatic tool selection.
ic Tool Se
Sel

LabVIEW Core 1 Exercises National Instruments | 1-13

Lesson 1 Navigating LabVIEW ni.com | 1-14

6. Rename the Numeric control to Number of Measurements using the Labeling tool.
uti ts

Double click the word Numeric.

Enter the text Number of Measurements.


rib en

Complete the entry by clicking outside the control or clicking the Enter Text button
on onn the too
toolb
toolbar.
on

7. Change the value of the Number of Measurements control to 100 using the Labeling
eling
g tool.
ist um

Move the cursor to the interior of the Number of Measurements control.


When the cursor changes to the Labeling tool icon, click the mouse button.
ton..
r D str

Enter the text 100.

Complete the entry by pressing the <Enter> key on the numericc keypad,
pad, click
clic
clicking thee Enter
nter Text button
b on the toolbar, or clicking outside the control.

ating tool.
8. Change the value of the Delay Multiplier knob using the Operating
t fo l In

Move the cursor to the knob.

When the cursor changes to the Operating tool icon,


n, press
ress the mouse
mo button
tto
tonn and drag to
t the value you want.
No na

Set the value to 1.


tio

nob using the Coloring


9. Change the color of the Delay Multiplier knob ring
ing tool.

Click the background square in thee Set


et Color button
bu
but and
nd
d se
sel
selectt a colo
col
color from the color picker.
Na

When the cursor changes to a paintbrush,


bru clickk the Delay Multiplier
M knob.
Click the Automatic Tool Selection button again to turn on automatic tool selection.

uti ts
table
le with usin
10. Try changing the value of objects, resizing objects, and renaming objects until you are comfortable using these tools.

rib en
11. Open the block diagram of the VI.

ns. Steps
Figure 1-5 shows an example of the block diagram as it appears after your modifications. teps 1213
12 instruct
uct you on how to update the block diagram to move

on
the Number of Measurements terminal and wire the terminal to the count terminal of the he For Loop.
Loo

ist um
Figure 1-5. Using Temperature
ature
e VI Block Diagram
am
m

r D str
t fo l In
No na
12. Move the Number of Measurements terminal using
sing the Positioning
Positio tool.
ool.

Move the cursor to the Number of Measurements


ments terminal.
urements term
tio
Move the cursor over the terminal until
til the cursor changes
ch to an arrow.
Na

Click and drag the terminal too the


the new location
locat as shown in Figure
Figu 1-5.

LabVIEW Core 1 Exercises National Instruments | 1-15

Lesson 1 Navigating LabVIEW ni.com | 1-16

13. Wire the Number of Measurements terminal to the count terminal of the For Loop using the Wiring
ring tool.
uti ts

Move the cursor to the Number of Measurements terminal.

Move the cursor to the right of the terminal, stopping when the cursor changes to a wiring
rib en

ring spool.
on
ist um

Click to start the wire.

Move the cursor to the count (N) terminal of the For Loop.
r D str

Click the count terminal to end the wire.

14. Try moving other objects, deleting wires and rewiring them, and wiring
ring objects and wires
ires together until
u you are comfortable with using these tools.
t fo l In

15. Automatically clean up the entire block diagram.

Click the Clean Up Diagram button on the LabVIEW


W toolbar.
toolbar
No na

Press <Ctrl-Z> to undo the clean-up.


tio

Tip You can also select specific objects


tss to clean up, ssuch ass wires or indiv
individual nodes. <Shift>-click to select multiple objects and then click the Clean Up
button. LabVIEW cleans up only the objects
bjects that you
y select and not the en entire block diagram. Configure how LabVIEW cleans up objects by selecting Tools
Options from the menu, clicking the Diagram category,
he Block Diagr ate y, and changing
ch
c the options in the Block Diagram Cleanup section.
Na
16. Change the Boolean text of the Stop button.

uti ts
Note Boolean controls and indicators have Boolean text labels in addition to their controll labels.
abels. Boole
Boolean text labels change depending on the value of the
n thee value of th
control or indicator. The label for the control or indicator does not change depending on the control or indicator.

rib en
Right-click the Stop Button terminal and select Properties from the shortcut menu.
u. Set
et the properties
prope as shown
hown in Figure
F 1-6.

on
Figure 1-6. Changing the Boolean Textt for the St
Stop Control
ontrol
ol

ist um
1

r D str
t fo l In 2
No na
1 Control labelThis text identifies the terminal of the Boolean control for pro
programming purposes. This text does not appear on the front panel unless you select
Visible.
tio
2 Boolean textThis text appears only on the and by default, appea
e front panel, a appears in the center of the Boolean control.

Click the OK button to close the dialog


alogg box.

Right-click the Stop Button terminal


minal and select
selec Find Control
sele Contro from
f the shortcut menu. Notice the control label is Stop Button and the button text is End.
Na

Tip You can also double-click


ick the Stop Button
B terminal to fin
find
f the button control on the front panel.

LabVIEW Core 1 Exercises National Instruments | 1-17

Lesson 1 Navigating LabVIEW ni.com | 1-18

17. Click the Run button to run the VI.


uti ts
rib en

The time required to execute this VI is equivalent to Number of Measurements times Delay
ay Multiplier.
Multipl n the VI is finished executing, the Temperature
When
on

Chart displays the data.


ist um

18. Close the VI and click the Dont Save - All button. You do not need to save the VI.
I.

End of Exercise 1-3


r D str
t fo l In
No na
tio
Na
Exercise 1-4 Concept: Dataflow

tio s
Goal

ibu nt
Understand how dataflow determines the execution order in a VI.

Dataflow DiscussionGroup Activity

n
str me
As a class, discuss how data flow determines execution order. You can find answers to the uestions in the Dataflow
he questions ataflow
flow Discu
Discus
DiscussionAnswers section.

Note Nodes are objects on the block diagram that have inputs and/or outputs
uts and perfor
perform operations
rations
tions when a V
VI runs.

Using Figure 1-7, answer questions 1 through 5.

Di tru
1. Which node executes first? Is there any dependency between the File Dialog
alog function aand thee Simulate Sign
log functio Signal Express VI?

2. Which node executes last?

s
3. Because a green wire connects the File Dialog function to the TDMS
DMS Viewer VI, can the TDMS File Viewer VI execute before the TDMS Close function?
S File View

l In
n can execu
4. How many nodes must execute before the TDMS Write function execute?

ar directio
5. Should a well-designed block diagram flow in a particular direction?
Figure 1
1-7. Block
1- ock Diagram E
Example
No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 1-19

Lesson 1 Navigating LabVIEW ni.com | 1-20

6. In Figure 1-8, which Express VI executes last?


uti ts

Figure 1-8. Block DiagramSimple Acquire, Analyze,, and


nd Present Example
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
7. In Figure 1-9 an error wire (shown in yellow) connects the Express VIs. Which Express VI executes
tes last?

uti ts
Figure 1-9. Block DiagramSimple AAP Example
ple with Error W
Wire

rib en
on
ist um
r D str
t fo l In
No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 1-21

Lesson 1 Navigating LabVIEW ni.com | 1-22

8. In Figure 1-10, which Tone Measurements Express VI executes last?


uti ts

Figure 1-10. Block DiagramFilter Example


xample
mple
rib en
on
ist um
r D str
t fo l In

Dataflow DiscussionAnswers
1. Either the File Dialog function or the Simulate Signal Express
xpress
ess VI can execute
tee first. There iis no data dependency between the two nodes so either of them can
execute first or they can execute simultaneously.
No na

dler VI.
2. The last node to execute is the Simple Error Handler

Note Terminals are not considered nodes.


es.
tio

3. No. The TDMS File Viewer VI cannot execute


cute before the
ecute th TDMS MSS Close function
func because the yellow error wire connecting the TDMS Close function and the
TDMS File Viewer VI forces data dependency.
ncy. Remember,
endency. Reme
Remem the
th data to all
al inputs
i of a node must be available before a node can execute. Therefore, the
TDMS File Viewer VI must receive data from both the greenen Boolean
een Boo
Bo n wire
w and the yellow error wire before the VI can execute.
Na

he TDMS Write
4. Three nodes must execute before the Wri function tion
n can execu
ex ecu File Dialog, TDMS Open, and Simulate Signal. The TDMS Write function also depends
execute:
onstant, but tthat input
on the Simulated Signal string constant, put
ut is instantan
instantaneous.

ic
ica
5. Yes. A well-designed block diagram typically ws from left to right. This makes it easier to see the flow of data on the block diagram. However, do not assume
flows
depen
depend
left-to-right or top-to-bottom execution when no data dependency exists.
6. Either the Statistics Express VI or the Write to Measurement File Express VI executes last or they
y execute
ecute in parallel. The DAQ Assistant Express VI cannot

uti ts
execute last because both the Statistics Express VI and the Write to Measurement File Express VII are depend
dependent on the data signal from the output of the DAQ
depende
Assistant Express VI.

rib en
Note In LabVIEW, the flow of data, rather than the sequential order of commands, determines
ermines the execution
utionn order
or of block diagram elements. Therefore,
it is possible to have simultaneous operations.

on
7. The Write to Measurement File Express VI executes last. It has a data dependency on both the DAQ
DA Assistant
sistant Express VI and the Statistics Express VI.

ist um
8. Either one of the Tone Measurement Express VIs can execute last. Even thoughh thee Tone Mea
Measurements
men ts 2 Express VI has an extra dependency on the Filter
ents
Express VI, the Filter Express VI might execute before the Tone Measurements
nts 1 Express VVI allowing
ng the Tone Measurements 2 Express VI to execute before
wing
the Tone Measurements 1 Express VI. Although it seems as if the Tone Measurements
rements 1 Express
asurements E ss VI would
would execute
exe first, without an explicit data dependency
there is no way to know definitely it would execute first.

r D str
End of Exercise 1-4

t fo l In
No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 1-23

Lesson 1 Navigating LabVIEW ni.com | 1-24

Exercise 1-5 Simple AAP VI


uti ts

Goal
Create a simple VI that acquires, analyzes, and presents data.
rib en

Scenario
on

You need to acquire a sine wave for 0.1 seconds, determine and display the average value,
e, log
og th
thee data, and display
lay the sine wave on a graph.
ist um

Design
The input for this problem is an analog channel of sine wave data. The outputs include
ude a graph of
o the sine
ne data, a file that
th
t logs the data, and an indicator that displays
the average data value.
r D str
t fo l In
No na
tio
Na
Flowchart

uti ts
The flowchart in Figure 1-11 illustrates the data flow for this design.

Figure 1-11. Simple AAP VI Flowchart


wchart
hart

rib en
ACQUIRE ANALYZE PRE
PRESENT

on
ist um
Acquire Data Display
play D
Data
ata

r D str
t fo l In
Log Data

No na Determine
rmine Display Average
Average Value
alue Value
tio
Na

LabVIEW Core 1 Exercises National Instruments | 1-25

Lesson 1 Navigating LabVIEW ni.com | 1-26

Program ArchitectureQuiz
uti ts

1. Acquire: Circle the Express VI that is best suited to acquire a sine wave from a data acquisition
on device.
rib en

DAQ Assistant The DAQ Assistant acquires data through


h a data acq
acquisition devic
device.
on

Instrument I/O Assistant The Instrument I/O Assistant acquires


ires instrum
instrument control
ontrol data, uusually from a GPIB or serial interface.
ist um

Simulate Signal The Simulate Signal Express


ess VI gene
generates simulated
ulated data,
data such as a sine wave.
r D str

2. Analyze: Circle the Express VI that is best suited to determining the average va
value of the acquired ddata.
t fo l In

Tone Measurements The Tone Measurements


asurement Expresss VI finds the
th frequency and amplitude of a single tone.
No na

Statistics The Statistics E


Express VI calculate
calculates statistical data from a waveform.

Amplitude and Level Measurements The Amplitude


Amp and
nd Level Measurements
M Express VI performs voltage measurements on a signal.
tio

Filter The Filter


T er Ex
Express VI processes a signal through filters and windows.
Na
3. Present: Circle the Express VIs and/or indicators that are best suited to displaying the data on a graph
raphh and log
logging the data to file.

uti ts
DAQ Assistant The DAQ Assistant acquires data through a data acquisition
acquis device.

rib en
on
Write to Measurement File The Write to Measurement File Express
ess VI writes
writ a file in LVM or TDM
TD file format.

ist um
Build Text The Build Text Express VI creates
eates text, usually forr displaying on the front panel window or exporting to a
file or instrument.

r D str
Waveform Graph The waveform graphh displays
display one or more
ore plots of evenly sampled measurements.

t fo l In
Refer to the next page for answers to this quiz.
No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 1-27

Lesson 1 Navigating LabVIEW ni.com | 1-28

Program ArchitectureQuiz Answers


uti ts

1. Acquire: Use the DAQ Assistant to acquire the sine wave from the data acquisition device.

2. Analyze: Use the Statistics Express VI to determine the average value of the sine wave. Because
ecaususee this signal
sign is cycli
sig cyclical, you could also use the Cycle Average
rib en

option in the Amplitude and Level Measurements Express VI to determine the average valuealuee of the sin e.
sine wave.
on

veform Graph
3. Present: Use the Write to Measurement File Express VI to log the data and use the Waveform Grap
Gra to display
play the data
da on the front panel window.
ist um

Implementation
1. Prepare your hardware to generate a sine wave. If you are not using hardware, skipp to step 2.
2

Find the BNC-2120 and visually confirm that it is connected to the DAQ
AQ device in your
y computer.
mputer.
uter
r D str

Using a BNC cable, connect the Analog In Channel 1 to the Sine Function
ction Generator,
Gener as shown in Figure
Fig 1-12.

Set the Frequency Selection switch and the Frequency Adjust


st knob
nob to their
the lowest
st levels.
vels.
t fo l In
No na
tio
Na
Figure 1-12. Connections for the BNC-2120
120

uti ts
ANALOG INPUTS NATIONAL
+
_ Floating
Source (FS)
Ground Ref.
Source (GS)
+
_ INSTRUMENTS
AI 3 PWR
! BNC-2120

rib en
1 RES BNC
TIMING I/O
2

3
PFI 0 / P1.0

on
4

1. RES+
2. AI GND
3. AI SENSE

ist um
4. RES-

Temp. Thermo Quadrature


ratu
BNC BNC couple E
Encoder
Ref.
96 Pulses/Rev
Pul

PULSES

UP/DN
AI 0 AI 1
PFI 1 / P1.1
FS GS FS GS
PFI 2 / P1.2

r D str
PFI 3 / P1.3

PFI
FI 4 / P1.4

PFI 5 / P1.5

AI 2 AI 3
PFI 6 / P1.6
FS GS FS GS
7
PFI 7 / P1.7

PFI 8 / P2.0
P

t fo l In
PFI 9 / P2.1

PFI 12 / P2
P2.4

AI 4 AI 5 PFI 13 / P2.5

FS GS FS GS
PFI 14 / P2.6

+5 V

D GND

AI 6 AI 7 USER-DEFINED
No na S
FS GS FS GS
SIGNALS*

ANALOG OUTPUTS

USER 1

USER 2
AO

O0
AO AO 1
tio
FUNCTION
TION GENERATOR *For BNC connections, wire
anyTiming I/O or Digital I/O
Frequency
equency Selection screw terminals here.

DIGITAL I/O

kH
0.1-10 kHz 1-100 kHz 13-1000 kHz P0.7

P0.6

P0.5
Na

P0.4

P0.3
S ine /Triangle
Sine TTL Square Wave

P0.2

P0.1

P0.0

D GND
LO HI LO HI
Amplitude Adjust Frequency Adjust

LabVIEW Core 1 Exercises National Instruments | 1-29

Lesson 1 Navigating LabVIEW ni.com | 1-30

2. Open LabVIEW.
uti ts

3. Create a blank project. Save the project as Simple AAP.lvproj in the <Exercises>\LabVIEW
IEW Core 1\Simple AAP directory.
bVIEW
rib en

AP.vi in th
4. Add a new VI to the project from the Project Explorer window and save the VI as Simple AAP.vi the <Exercises>\LabVIEW
xerc Core 1\Simple AAP
directory.
on

In steps 56 you will build a front panel similar to the one in Figure 1-13.
ist um

Figure 1-13. Acquire, Analyze, and Present


resent Front
Fron Panel
ell Window
r D str
t fo l In
No na

5. Add a waveform graph to the front panel window


w to display the acquired
red ddata.

Press <Ctrl-Space> to open the Quick Drop


rop dialog box.
box
tio

Type Waveform in the text box and double-click


uble-click Waveform
W rm
m Graph (Si
(Silver)
(Sil in the search results list.

Place the graph in the front panel window.


ndow.
Na

6. Add a numeric indicator to the front


nt panel window to display
panel windo lay the aver
isplay average value.

Press <Ctrl-Space> to open the Quick Drop


D dialog
alog box.

Type Numeric Indicator in the text box and


nd double-click
double- Numeric Indicator (Silver) in the search results list.
Place the indicator in the front panel window.

uti ts
Change the numeric indicator label to Average Value.
In the steps 714 you build a block diagram similar to the one in Figure 1-14.

rib en
Figure 1-14. Acquire, Analyze, and Present
resent
nt Block D
Diagram
m

on
ist um
r D str
t fo l In
7. Open the block diagram of the VI.
No na
Select WindowShow Block Diagram.
tio
Note The terminals corresponding to the front panel
pane window
ow objects app
appear on the block diagram.

8. Acquire a sine wave for 0.1 seconds by following instructions in Table 11-2. If you have hardware installed, follow the instructions in the Hardware Installed
owing the in
column to acquire the data using the DAQQ Assistant.
Assistant If youu do not
n haveve hardware
ave h installed, follow the instructions in the No Hardware Installed column to
Na

imulate
mulate Signal Express
simulate the acquisition using the Simulate ss VI.

LabVIEW Core 1 Exercises National Instruments | 1-31

Lesson 1 Navigating LabVIEW ni.com | 1-32

Table 1-2. Instructions for Acquiring or Simulating


ting Data
uti ts

Hardware Installed No
N o Hardware Installed

1. Press <Ctrl-Space> to open the Quick Drop dialog box. 1. Press <Ctrl-Space>
rl-Space> to open the Quick Drop dialog box.
rib en

2. Type DAQ Assistant in the text box and double-click DAQ Assistant 2. Type Simulate
imulate Signal in the text tex box and double-click Simulate
on

in the search results list. nal in the search


Signal s results
ults list.
ist um

3. Place the DAQ Assistant on the block diagram. 3. Place the Simulate
S e Signal Express
Expre VI on the block diagram.
4. Wait for the DAQ Assistant dialog box to open. 4. Wait for
fo the Simulate
ulate Signal dialog box to open.

5. Select Acquire SignalsAnalog InputVoltage for the measurement 5. Select Sine forr the signal
Sele signa type.
type.
r D str

6. Select ai1 (analog input channel 1) for the physical channel. 6. Set thee signal frequency
frequ to 100.
7. Click the Finish button. 7. In thee Timing section,
s set the Samples per second (Hz) to 1000.
t fo l In

8. In the Timing Settings section, select N Samples as the Acquisition


quisition 8. In the Timing
Timin section, deselect Automatic for the Number of samples.
Mode.
9. In the Timing Settings section enter 100 in Samples To Read.
Read. 9. In the Timing
T section, set the Number of samples to 100.

10. Enter 1000 in Rate (Hz). 10.. In the Timing section, select the Simulate acquisition timing option.
No na

11. Click the OK button. 11. Click the OK button.


tio

Tip Reading 100 samples at a rate of 1,000


,000 Hz retri
retriev
retrieves 0.1 seconds
conds wort
worth of data.

9. Use the Statistic Express VI to determinee the


he average value
v of the acquired.
hee data acqu

Press <Ctrl-Space> to open the Quick Drop dialog


di
d box.
ox.
Na

Type statistics in the text


xt box and dou
do
double-click
ic Statistics
ick Statistic [NI_ExpressFull.lvlib] in the search results list.

Place the Statistics Express VI on the block


b diagram
iagram to the right of the DAQ Assistant (or Simulate Signal Express VI).

Wait for the Statistics Express VI dialog box to open.


n
Place a checkmark in the Arithmetic mean checkbox.

uti ts
Click the OK button.
10. Log the generated sine data to a LabVIEW Measurement File.

rib en
Press <Ctrl-Space> to open the Quick Drop dialog box.

on
Type write to measurement in the text box and double-click Write to Measurement
easurement F in the search results
surement File resu list.

ist um
Place the Write to Measurement File Express VI on the block diagram below
low
w the Statistics
Statist Express
xpress
ress VI.

Wait for the Write to Measurement File Express VI dialog box to open.
Leave all configuration settings in the Write to Measurement File dialog

r D str
ialog
log box as de
ddefault.

Click the OK button.

Note Future exercises do not detail the directions for finding


ing specific fun
fu
functionss or contro
controls
ls in the palettes. Use Quick Drop, the palette search feature, or

t fo l In
the global search to locate functions and controls.

11. Wire the data from the DAQ Assistant (or Simulate Signal Express VI)) to
al Expre t the Statistics
tatistics Express
Expre VI.
Expr

Place the mouse cursor over the data output of thee DAQ
AQ Assistant
Assista (or the Sine outpu
output of the Simulate Signal Express VI) at the location where the cursor
No na
changes to the Wiring tool.

Click the mouse button to start the wire.


Place the mouse cursor over the Signals input of the Statistics
St
S s Express VI and
a click the mouse button to end the wire.
tio

12. Wire the data to the graph indicator.

Place the mouse cursor over the data


ata output wire
wir of thee DAQ Assistant
As ta (or the Sine output of the Simulate Signal Express VI) at the location where the cursor
Na

changes to the Wiring tool.

Click the mouse button to start


rt the wire.

Place the mouse cursor over the Waveform Graph indicat


indica
indicator and click the mouse button to end the wire.

LabVIEW Core 1 Exercises National Instruments | 1-33

Lesson 1 Navigating LabVIEW ni.com | 1-34

13. Wire the Arithmetic Mean output of the Statistics Express VI to the Average Value numeric indicator.
icator.
or.
uti ts

Place the mouse cursor over the Arithmetic Mean output of the Statistics Express VI at the
he location
loca
ocation
tion where
wh the cursor changes to the Wiring tool.

Click the mouse button to start the wire.


rib en

Place the mouse cursor over the Average Value numeric indicator and click the mouse
ouse button to
t end the
he wire.
ire.
on

14. Wire the data output to the Signals input of the Write Measurement File Express VI.
ist um

Place the mouse cursor over the data output wire of the DAQ Assistant (or the
he Sine output of the Simulate
imulate Sig
Signal
Sign Express VI) at the location where the cursor
changes to the Wiring tool.

Click the mouse button to start the wire.


r D str

Place the mouse cursor over the Signals input of the Write Measurement
urement
ment File Express
E s VI and click the
t mouse button to end the wire.

Note Future exercises do not detail the directions for wiring


g between
etween obje
objects.
t fo l In

15. Save the VI.


No na
tio
Na
Test

uti ts
1. Switch to the front panel window of the VI.

2. Set the graph properties to be able to view the sine wave.

rib en
Right-click the waveform graph and select X ScaleAutoscale X to remove the checkmark
eckmark
mark and ddisablee autoscaling.
oscaling.

on
Right-click the waveform graph and select Visible ItemsX Scrollbar to enable
le the
he X scale
scale.

ist um
Use the labeling tool to change the last number on the Time scale of the waveform
aveform
form graph to .1.

3. Save the VI.

r D str
4. Run the VI.

Click the Run button on the front panel toolbar.


The graph indicator should display a sine wave and the Average Value
ue sshould display
u indicator sh splay a number
numb around zero. If the VI does not run as expected, review the
num

t fo l In
implementation steps.

5. Close the VI.

End of Exercise 1-5


No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 1-35


uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
2

uti ts
Troubleshooting and Debugging VIs

rib en
on
ist um
Complete the exercise in this lesson to reinforce the concepts you learn in Lesson 2 of LabVIEW
bVIEW Co
Core 1.

Exercises
Exercise 2-1 Concept: Debugging

r D str
t fo l In
No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 2-1

Lesson 2 Troubleshooting and Debugging VIs ni.com | 2-2

Exercise 2-1 Concept: Debugging


uti ts

Goal
Use the debugging tools built into LabVIEW.
rib en

Description
on

The VIs in this exercise check the validity of a triangle and then calculate the area. For a triangle
angle to be valid, all three sides must have a length that is greater than
zero. The subVI in this exercise uses Herons formula to calculate the area of a triangle.
e. You can use this method when you yyo know the lengths of all three sides of a
ist um

triangle.

Herons formula

A = s ( s a ) ((ss b ) ( s c )
r D str

where

a+b+c
---
----
s = --------------------
-
t fo l In

I, are
The default values, which you will use to debug and test this VI, ar Sidee A = 6, Side
de B = 8, Side C = 10. Therefore the correct values are as follows:

6 + 8 + 10
s = ------------------------
-----------------
---------------- = 12
2
No na

A = 2 6 4 2 = 24
12
tio

u debug the VI
You might want to refer to this calculation as you V
VI.

Complete the following sections to identify andd fix edit-time


edit-tim and run-time
n-time issues.
un-time ssues Use single-stepping and execution highlighting to step through the VI. Use
iissues
breakpoints and probes to determine if the calculations
culations are
ar correct
ect aand figure oout where an error originates.
Na
Edit-Time Errors

tio s
Locate and correct errors that prevent the VI from running.

ibu nt
1. Open and examine the area and validity of a triangle VI.

Open Debug.lvproj in the <Exercises>\LabVIEW Core 1\Debugging directory.


irectory.
tory.

n
str me
Open Area and Validity of a Triangle VI from the Project Explorer window.
Figure 2-1. Area and Validity of Triangle VI
V Front Panel
anel

Di tru
s
t fo l In
No na
tio

Notice the Run button on the toolbar


Na

olbar appears broken,


b , indicating
dicating tth
that the VI is broken and cannot run.

LabVIEW Core 1 Exercises National Instruments | 2-3

Lesson 2 Troubleshooting and Debugging VIs ni.com | 2-4

2. Display and examine the block diagram of Area and Validity of a Triangle VI shown in Figure 2-2.
2.
uti ts
This VI takes input values for each of the three sides of a triangle, passes the values into a subVII that determines
determin the area, and checks that the values entered are
valid for a triangle.
rib en

Figure 2-2. Area and Validity of a Triangle


e VI Block Diagram
Dia
on
ist um
r D str
t fo l In

3. Find and fix each error.

Click the broken Run button to display the Errorr list window,
No na

window, w
which lists
ists all the eerr
errors.

Select an error description in the Error list window.


indow.
ow. The Details
D
De section
ection
on describes
rib the error and in some cases recommends how to correct the error.
ribe

Click the Help button to display a topic inn the LabVIEW Helpp that
at describe
describes the error in detail and includes step-by-step instructions for correcting the error.
tio

Click the Show Error button or double-click


ble-click
e-click the error
er
e description
crription
iption to highlight
hig the area on the block diagram that contains the error.

Use the Error list window to fix each error.


Na

Note Double-click the Areaa of a Triangle subVI to open it. In thet Area of Triangle VI, notice that the formula for calculating the area of a triangle requires
the sum of the sides be dividedd by 2. Right-click
Righ o the Divide function and select CreateConstant and enter a value of 2.
k the y input of

4. Save both VIs.


Run-Time Errors

uti ts
Identify and correct errors that cause the VI to behave unexpectedly and return incorrect responses.

1. Test the VI.

rib en
Display the front panel by clicking it or by selecting WindowShow Front Panel.

on
Use the default values for each side. These values are valid measurements for a triangle.
ngle.

ist um
Run the VI.
Notice that although the numbers you entered are valid, the LED is not illuminated
luminated
minated and the Area
rea of a Triangle
Triang indicator displays NaN.
Trian

2. Animate the flow of data through the block diagram.

r D str
Display the block diagram.
Click the Highlight Execution button on the toolbar to enable
le execution
xecution highlighting.
hi hting.
ing.

t fo l In
Click the Retain Wire Values button on the toolbar
No na ar soo you can ssee the last value passe
passed
pas on a wire.

Run the VI.


tio
Notice that you can see how data flowss through
hrough the wires.
w At the output of
o each node, you can see the data value displays momentarily. Because you have
enabled the Retain Wire Values button,
on,, yo
you probe the last
u can pr
pro ast the wire.
st value in th
Na

LabVIEW Core 1 Exercises National Instruments | 2-5

Lesson 2 Troubleshooting and Debugging VIs ni.com | 2-6

3. Probe the wire values.


tio s
Right-click each of the inputs to the Compound Arithmetic Function and select Probe. This
his displays the Probe Watch Window.
ibu nt

Notice that one of the wire values is False as shown in Figure 2-3.
Figure 2-3. Probe Wires
ires
n
str me
Di tru
forIns
No
N
Because you are checking to see that all three sides of the triangle have positive lengths, eitherr thee input vvalue is invalid or the logic is incorrect. The input

uti ts
values were all positive numbers, so that means the logic is incorrect.

Notice that the node returning a value of False is a Less than Zero? function, but this section
ection
ion of code should be checking to see if the value is greater

rib en
than zero.

Right-click the Less than Zero? function and select ReplaceComparison PaletteGreater

on
teGreater
reater th
tthan Zero?.
ro?.

4. Test the VI.

ist um
Run the VI.
Notice that all the probe values are all True.

r D str
Display the front panel. Notice that the Valid Triangle? LED is illuminated,
uminated,
nated, but the
t Area
ea of Triangle indicator
i is still returning NaN.

The area of the triangle is calculated in the subVI, so you must continue
ntinue debugging
debu
deb in the Area of a Triangle subVI.

t fo l In
5. Continue debugging the subVI.

Display the block diagram of the Area and Validity of a T


Trianglee VI.

Click the Step Into button to start single-stepping through


ough the VI.
V Execution
ution highlighting
highlight
highligh shows the flow of data on the block diagram from one node to
another. Nodes blink to indicate they are ready to
o execute.
cute.
No na
tio
Click the Start Single Stepping button after each nod
node to step
ep through the entire block diagram. Each time you click the Step Over button, the current node
executes and pauses at the next node.
Na

When you get to the subVI, click the Step Into button
utton to open th
the block diagram of the Area of Triangle subVI. The subVI is paused.

Turn on Execution Highlighting andd R


Retain Wire Values in the subVI.

LabVIEW Core 1 Exercises National Instruments | 2-7

Lesson 2 Troubleshooting and Debugging VIs ni.com | 2-8

Right-click the output of the Square Root function and select BreakpointSet Breakpoint as shown
own in Figure
F 2-4.
uti ts

Figure 2-4. Set Breakpoint


rib en
on
ist um

1
r D str

1 The breakpoint stops the VI after the Square Root node executes and before the value is output
outp to the
e Area of Triangle
Triang indicator.

6. Click the red pause button to resume the execution of the VI.

The VI continues executing until the breakpoint and then pauses


auses again.
t fo l In

7. Examine the values on the wires

Move the cursor to hover over the input wire of the Square
uare Root ffunction.
n.. You should ssee a tip strip with a value of 576. You cannot take the square root of
anglee indicator returnss NaN.
a negative number, which is why the Area of Triangle
No na

Tip If you cannot see the tip strip, you can clickk the wire to
t openn thee Probe
P e WaWatch window to see the value.

Hover over other wires or use the Probe Watch window to examine
amine
ne othe
otherr intermediate
int
in values.
tio

Notice that the value on the (S-B) wire


re is also a ne
neg
negative number.
umb
mber.
er. If you look more closely, you notice that the inputs for the subtract function are reversed.

Click the Abort button to stop thee VI..


Na

Switch the inputs for the (S-B)


B)) Subtract
Subtract function
func and
nd save the VI
VI.

Tip Press <Ctrl> and click one of the inputs to switch them.
them When you press <Ctrl> and hover over an input, you see the cursor change.

8. Save the VI.


9. Test the Area of Triangle VI.

uti ts
Run the VI again.
Check the intermediate values as the VI runs or hover over the wires after it pauses at thee breakpoint

rib en
eakpoint and
an verify
fy tha
that the values returned are correct. The square
root function should return a value of 24.

on
Right-click the breakpoint and select BreakpointClear Breakpoint.

ist um
Turn off execution highlighting in the Area of Triangle VI and the Area and Validity
lidity of a T
Triangle
le VI.

Save both VIs.

Test

r D str
1. Test the Area and Validity of a Triangle VI using the values for Side A, Side
ide B, and
and Side
S C in Table 2-1. For
F each set of test values, the VI should return the value
shown in the Area column.

t fo l In
Table 2-1. Area and Validity
Valid of a Triangle Test
Tes Values

Side A Side B Side C Area

24 No na 30 18 216
12 122 12 62.35

15 20 25 150
tio
2. Save and close the VI when you are finishedd testing.

End of Exercise 2-1


Na

LabVIEW Core 1 Exercises National Instruments | 2-9


uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
3

uti ts
Implementing a VI

rib en
on
ist um
Complete the exercises in this lesson to reinforce the concepts you learn in Lesson 3 off LabVIEW
abVIEW Core
C 1.

Exercises
Exercise 3-1 Temperature Warnings VI

r D str
Exercise 3-2 Auto Match VI
Exercise 3-3 Concept: While Loops versus For Loops
ps
Exercise 3-4 Temperature Monitor VIAverage Temperature
mperature

t fo l In
Exercise 3-5 Temperature Monitor VIPlot Multiple Temperaturess
ultiple Tempe
Exercise 3-6 Temperature Warnings VIWith
With Errorr Han
Handling
Hand

No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 3-1

Lesson 3 Implementing a VI ni.com | 3-2

Exercise 3-1 Temperature Warnings VI


uti ts

Goal
Create and document a simple VI.
rib en

Scenario
on

You must create a portion of a larger project. The lead developer gives you the inputs of the VI, the alg
algorithm,
m, and
nd the expe
expected outputs. Your task is to create and
document a VI based on the given design.
ist um

Design
Use the following flowchart and input/output list to create a VI that displays temperature
peratur
raturee warnings.
warni
warn This
his VI is part oof the temperature weather station project studied
throughout the course.
r D str
t fo l In
No na
tio
Na
Flowchart

uti ts
The flowchart in Figure 3-1 illustrates the data flow for this design.

Figure 3-1. Temperature Warnings VII Flowchart


owchart

rib en
on
ist um
Current Temp
>= Max Temp? No

Yes

Warning Text =

r D str
Warning Text =
Warning
Heatstroke
No
o Warning
Warning
Warning

t fo l In
rrent Temp
Current
No
<= Min Temp?

No na Yess
Ye

W arni Text =
Warning ass current value
Pass
Freeze Warning
Free of Warning Text
tio
W
Warning
Tex
Text = No No
W
Warning?

Yes
Na

Warning ? = False Warning ? = True

LabVIEW Core 1 Exercises National Instruments | 3-3

Lesson 3 Implementing a VI ni.com | 3-4

Inputs and Outputs


uti ts
The following table describes the inputs and outputs for this exercise.

Table 3-1. Temperature Warnings VI Inputs


uts and Outpu
Outputs
rib en

Type Name Properties


operties
on

Numeric control Current Temperature Double-precision,, floating-point


floating-p
ist um

Numeric control Max Temperature Double-precision,


sion, floating-point
floatin

Numeric control Min Temperature Double-precision,


ecision, floating-point
flo nt

String indicator Warning Text Three potential values:


va Heatstroke
stroke Warning,
Wa No Warning, and Freeze Warning
r D str

Round LED indicator Warning?

Implementation
Complete the following steps to create a front panel similar to Figure 3-2. The user enters the
he current tem
te
temperature, maximum temperature, and minimum temperature.
t fo l In

Then, the front panel displays the warning string and the warning Boolean
oolean LED.
LED

roject.
1. Create a new LabVIEW Project and add a new VI to the project.

Select FileNew from the LabVIEW menu and then


hen select ProjectEmpty
Proj mpty Project ffrom the Create New tree.
No na

Save the new project as <Exercises>\LabVIEW


VIEW
EW Core 1\Weather
ath Warnings\Weather
Warni Warnings.lvproj.

Right-click My Computer in the Project Explorer


plorer win
window and
nd select
lect New
NewVI to open a blank VI.
N
tio

Save the VI as Temperature Warnings.vi


ngs.vi in th
ings.vi the <Exercises>\LabVIEW
xercises>\L
ercises>\ Core 1\Weather Warnings directory.

2. Create the front panel shown in Figuree 3-2.


2.
Na

Note Use controls and indicators


ators
ors from the Silver palette.
lette.
Figure 3-2. Temperature Warnings VI Front Panel
nel

uti ts
rib en
1

on
4

ist um
2
3

r D str
1 Numeric ControlRight-click and select RepresentationDBL to confirm
onfirm that this numeric
ric control is double precision.
2 Create copies of the Current Temperature numeric control by holding down the <Ctrl>
rl> key and dr
dragging the Current Temperature control.

t fo l In
3 String IndicatorResize the indicator to accommodate longerr strings.
4 Round LED

Tip You can use this VI for Fahrenheit, Kelvin, or any


y other tem
temp
temperature
ree scale, as lon
long as all inputs to the VI use the same scale. Therefore, it is not necessary
to add scale units to the labels.
No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 3-5

Lesson 3 Implementing a VI ni.com | 3-6

3. Create the block diagram as shown in Figure 3-3.


uti ts

Figure 3-3. Temperature Warnings VI Block


ck Diagram
rib en

1 4 6
on
ist um
r D str

2 3 5

1 Greater or Equal?Compares input values and returns a TRUE value


alue if Curre
Current Temperature
mperature is greater
g than or equal to Max Temperature.
t fo l In

2 Less or Equal?Compares input values and returns a TRUE value if Current


Curre Temperature
erature is less
le than or equal to Min Temperature.
3 String ConstantCreate string constants for Heatstroke Warning
rning, Freeze Warning, and No Warning.
4 SelectReturns the Heatstroke Warning string if Current
rrent Temperature
T is
s greater than or equal to Max Temperature; otherwise returns the No Warning
string.
5 SelectReturns the Freeze Warning string if Currentt Temper
Temperature is less than o
or equal to Min Temperature; otherwise returns the No Warning string.
No na

6 ? indicator if the value Warning Text is something other than No Warning.


Not Equal?Returns a TRUE value to the Warning?

4. Modify the description and tip associated with the Warning Text indicator
ndicator
ator to ch
change the content shown in the Context Help window.
tio

Press <Ctrl-H> to display the Context Help window,


window if necessary.
cessary.
essary.

Select WindowShow Front Panel


el to
o open the ffront panel
anel off the VI.
VI
Na

Move your mouse over the Warning


rning Text indicator.
arning in
ind .

Read the contents of the Context


text Help window.
w
wi
Right-click the Warning Text indicator and select Description and Tip.

uti ts
Enter Displays text string indicating Heatstroke Warning, Freeze Warning,
rning, or
o No Warning depending on weather
conditions in the Warning Text Description text box.

rib en
Note Text you enter in the Warning Text Tip text box displays in a tip strip. Tip
p strips
rips are brief
brie descriptions
criptions
tions that appear when you move the cursor over

on
a front panel object while a VI runs.

ist um
Click the OK button.

Move your mouse over the Warning Text indicator.


Notice that the contents of the Context Help window changed to match
ch the
he text you typed
d in the
he descript
descrip
description field of the Description and Tip dialog box.

r D str
5. Document the block diagram using owned labels and free labels.

Press <Ctrl-E> to switch to the block diagram.

t fo l In
Add owned labels and free labels on the diagram as shown in Figure 3-4
3-4.
Owned labels are owned by a specific object. You can hid
hide owned labels and
ned labe
lab d move them, but
b you cannot copy or delete them independently of their owners.

No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 3-7

Lesson 3 Implementing a VI ni.com | 3-8

Figure 3-4. Temperature Warnings VI Block Diagram


gram
uti ts

5
rib en

2
4
on
ist um

1
r D str

1 Owned labelsRight-click a function and select Visible ItemsLabel from


rom the shortcut
sh menu
enu to display
displa the owned label for that function.
2 Po
Move labelClick the owned label of the Greater or Equal? function with the Positioning tool an
anddm
move it beneath the function.
t fo l In

3 Move functionUse the positioning tool to move the function. Notice that the owned label
abel moves with the function.
4 el from th
Owned labelRight-click the wire and select Visible ItemsLabel the shortcutt menu. Mo
Move the label with the Positioning tool.
5 Free labelDouble-click a blank area of the block diagram
m and use the Labeling
ng tool to crea
create comments for the code.

6. Document the VI Properties, giving a general description


tion of the VI, a list off inputs and ou
outputs, your name, and the date the VI was created. To access the VI
No na

Properties dialog box, select FileVI Properties and


nd select
elec Documentation
Docu ion from the Category pull-down menu.

7. Save the VI.


tio
Na
Test

uti ts
1. Test the VI by entering a value for Current Temperature, Max Temperature, and Min Temperature,
rature,, and rrunning the VI for each set.
perature

va
Table 3-2 shows the expected Warning Text string and Warning? Boolean value for each set of input values.

rib en
Note The temperature range in the table is only an example of temperatures selected
ted to indicate freezee or heatstroke
heatstrok warnings.

on
ist um
Table 3-2. Testing Values for Temperature
emperature
perature Warnings
W gs VI

Current Temperature Max Temperature Min Temperature


e Warning Text Warning?

30 30 10 Heatstroke
roke Warning
Wa True

r D str
25 30 100 No
o Warning False

10 30 10 Freeze
reeze Warning
Wa True

t fo l In
What happens if you input a maximum temperature value that iss less than the minimum
m temperature
mum temperatu value? What would you expect to happen? You learn to
temperat
handle issues like this one in Exercise 3-6.

2. Save and close the VI and the project.

End of Exercise 3-1


No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 3-9


uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
Exercise 3-2 Auto Match VI

uti ts
Goal
Use a While Loop and an iteration terminal and pass data through a tunnel.

rib en
Scenario

on
Create a VI that continuously generates random numbers between 0 and 1000 until it generates
erates
es a nu
numbe
number
mbe that matches
ches a num
number selected by the user. Determine how
many random numbers the VI generated before generating the matching number.

ist um
Design
Use the following flowchart and input/output list to create the VI for this exercise.
e.

r D str
t fo l In
No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 3-11

Lesson 3 Implementing a VI ni.com | 3-12

Flowchart
uti ts
The flowchart in Figure 3-5 illustrates the data flow for this design.

Figure 3-5. Auto Match Flowchart


hart
rib en
on
ist um

Generate a
Random Number No
Between 0 and 1
r D str

Multiply by 1000
t fo l In

Add 1 to
Round to Nearest Display
Di Value
splay Value =NNumber
Yes Iteration
Integer Value to User
User
No na

to Match?
Terminal
tio

Display Number
of Iterations
Na
Inputs and Outputs

uti ts
The following table describes the inputs and outputs for this exercise.

Table 3-3. Auto Match VI Inputs and


d Outputs

rib en
Type Name Properties
ropertie

on
Numeric control Number to Match Double-precision,
ion, floatin
floating-point between
etween 0 and
a 1000, coerce to nearest whole
fault value = 50
number, default

ist um
Numeric indicator Current Number Double-precision,
precision, ffloating-point
poin
Numeric indicator Number of Iterations Integer
ger

r D str
Implementation
1. Create a blank project and save it as Auto Match.lvproj in the <Exercises EW Core 1\Auto Match directory.
<Exercises>LabVIEW
xercise VIEW

2. Create a new VI in the project and save it as Auto Match.vi in the same directory
ddi y as the project.
proje
project

t fo l In
No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 3-13

Lesson 3 Implementing a VI ni.com | 3-14

3. Build the front panel shown in Figure 3-6.


uti ts

Figure 3-6. Auto Match VI Front Panel


anel
el
rib en
on

1
ist um
r D str

1 Set the default value of the Number to Match control to 50Enter 50


0 in the Number
Nu to
o Matc
Match control
on and then right-click the control and select Data
t fo l In

OperationsMake Current Value Default.


2 rRight-
Set Number of Iterations indicator to output a signed, long integerRight-click ndicator an
the indicator and select RepresentationI32.

4. Set the properties for the Number to Match control so that


hat the dat
data type is a 32-bit
-bit unsigned integer, the data range is from 0 to 1000, the increment value is 1,
and the digits of precision is 0.
No na

Right-click the Number to Match control and select


ect RepresentationU32
Repres U32 from the
t shortcut menu.

Right-click the Number to Match control and select Data ry from


Da Entry om the
t shortcut
s menu. Set the properties on the Data Entry and Display Format tabs as
shown in Figure 3-7.
tio
Na
Figure 3-7. Number to Match Numeric Properties
perties
ies

ts
en
ist um
r D str
r
t fo l In
No na
1 2

1 Number to MatchData Entry Properties 2 Number to MatchDisplay Format Properties


tio
Na

LabVIEW Core 1 Exercises National Instruments | 3-15

Lesson 3 Implementing a VI ni.com | 3-16

5. Set the data type of the Current Number indicator to an unsigned, 32-bit integer and set the digitss off precision
precisio for the Current Number output to 0.
tio s
Right-click the Current Number indicator and select RepresentationU32 from the shortcut
tcutt menu.
menu
ibu nt

Right-click the Current Number indicator and select Display Format. Set the properties
rties as shown in Figure
ure 3-7.
3
Figure 3-8. Current Number Indicator Display
splayy Format Properties
ertiess
n
str me
Di tru
s
t fo In
No n
tio
Na
6. Create the block diagram shown in Figure 3-9.

uti ts
Figure 3-9. Auto Match VI Block Diagram
agram
am

rib en
1 2 9

on
ist um
r D str
3 4 5 6 7 8

t fo l In
1 Random Number (01)Generates a random number between
en 0 and 1.
2 MultiplyMultiplies the random number by the y input to pro
produce a ran
random number
umber between 0 and y.
3 unction and select CreateCon
Numeric ConstantRight-click the y input of the Multiply function CreateConstant. Enter a value of 1000. Because the Random Number (0-1)
function generates a double-precision, floating point number between 0 and
ber betwee d 1, multiplyin
multiplying the number by 1000 produces a range of numbers between 0 and
1000.
4
No na
Round To NearestRounds the random number to the
he nearest integer.
5 Equal?Compares the random number with Number
er to Match
Matc and returns
urns FALSE
SE if the numbers are not equal. Otherwise, it returns TRUE.
6 While LoopRepeats the algorithm until the Equal?
al? function
functio returns TRUE be
because the Equal? function is wired to the conditional terminal, which is set to Stop
tio
if True.
7 Iteration terminalEach time the loop executes,
cutes, the iteration
ite terminal
rminal increments
increm by one.
8 IncrementAdds 1 to the While Loop count because the iteration
unt becaus n starts at 0.
9 Coercion dotsRed coercion dots appear block diagram
ppear on bloc nodes when you connect a wire of one numeric type to a terminal of a different numeric type. In this
m node
Na

case, the output from Round To Nearest double-precision,


arest is a dou floating point but Current Number is an integer.
ion, floatin

Tip Coercion dots can cause a VI to us


use moree memory and increase its run time, so try to keep data types consistent in the VIs you create.

LabVIEW Core 1 Exercises National Instruments | 3-17

Lesson 3 Implementing a VI ni.com | 3-18

7. Update the VI to remove the coercion dots.


tio s
Right-click the wire coming from the Round To Nearest function and select InsertNumeric
ric PaletteConversionTo
PaletteCo Unsigned Long Integer as shown in
ibu nt

Figure 3-10. This inserts the To Unsigned Long Integer function on the wire.
Figure 3-10. Inserting the To Unsigned Long Integer
nteger
eger Function
Funct
Functio on a Wire
n
str me
Di tru
Ins
ti
Na
t
No
8. Notice that converting the output from the Round To Nearest function removes all the coercion dots
ots on the block
bl diagram, as shown in Figure 3-11.

uti ts
Figure 3-11. Completed Auto Match
h VI

rib en
on
ist um
r D str
9. Display the front panel.

10. Right-click the Current Number indicator and select AdvancedSynchronous lay..
dSynchrono Display.
dSynchronou play

t fo l In
Note If synchronous display is enabled, then every time the block diagram di m sends
nds a value to the Current Number indicator, the block diagram stops
executing until the front panel has updated the value off the
he indicator.
ind In
I this exercise,
xercise, you enable
een the synchronous display, so you can see the Current Number
pically, the synchronous
indicator get updated repeatedly on the front panel. Typically, onous display is
i disabled to increase execution speed since you usually do not need
to see every single updated value of an indicator on thehe front panel.
pan
No na
11. Save the VI.

Test
tio
1. Change the number in the Number to Match
ch control to a number
atch ber
er that is in th
tthe data range, which is 0 to 1000 with an increment of 1.

2. Run the VI.


Na

3. Change the Number to Match valueue and run the V VI again. Number updates at every iteration of the loop because it is inside the loop. Number of Iterations
in. Current Num
updates upon completion becausee it is outside tthe loop.
op.

LabVIEW Core 1 Exercises National Instruments | 3-19

Lesson 3 Implementing a VI ni.com | 3-20

4. To see how the VI updates the indicators, enable execution highlighting.


uti ts

On the block diagram toolbar, click the Highlight Execution button to enable execution highlighting.
ighlighting.
hlighting. Execution
Ex highlighting shows the movement of data
on the block diagram from one node to another so you can see each number as the VI generates
rates it.
enerates
rib en
on

5. Run the VI and observe the data flow.


ist um

6. Turn off execution highlighting to quickly finish executing the VI.

7. Try to match a number that is outside the data range.


r D str

Change the Number to Match value to a number that is out of the data
ta range, 0 1000.
0.

Run the VI.

Notice LabVIEW coerces the out-of-range value to the nearest


t fo l In

rest value in the


th dataa range
ange you
you specified
spe
sp in step 4 of the Implementation section.

8. Close the VI.

End of Exercise 3-2


No na
tio
Na
Exercise 3-3 Concept: While Loops versus For Loops

uti ts
Goal
Understand when to use a While Loop and when to use a For Loop.

rib en
Description

on
For the following scenarios, decide whether to use a While Loop or a For Loop.

ist um
Scenario 1
Acquire pressure data in a loop that executes once per second for one minute.

op?
1. If you use a While Loop, what is the condition that you need to stop the loop?

r D str
2. If you use a For Loop, how many iterations does the loop need to run?
n?

t fo l In
3. Is it easier to implement a For Loop or a While Loop?

Scenario 2
Acquire pressure data until the pressure is greater than or equal
al to 1400 psi.
p
No na
1. If you use a While Loop, what is the condition thatt youu need to st
stop thee loop?
l ?

2. If you use a For Loop, how many iterations does the loop need
n n?
to run?
tio

3. Is it easier to implement a For Loop or a While Loop?


Loop
Na

LabVIEW Core 1 Exercises National Instruments | 3-21

Lesson 3 Implementing a VI ni.com | 3-22

Scenario 3
uti ts
Acquire pressure and temperature data until both values are stable for two minutes.

1. If you use a While Loop, what is the condition that you need to stop the loop?
rib en
on

2. If you use a For Loop, how many iterations does the loop need to run?
ist um

3. Is it easier to implement a For Loop or a While Loop?

Scenario 4
Output a voltage ramp starting at zero, increasing incrementally by 0.5 V every
ry second, until
ery un
u the output voltage is equal to 5 V.
r D str

1. If you use a While Loop, what is the condition that you need to stop the loop?
t fo l In

2. If you use a For Loop, how many iterations does the loop need to run?

3. Is it easier to implement a For Loop or a While Loop?


No na
tio
Na
Answers

uti ts
Scenario 1
Acquire pressure data every second for one minute.

rib en
1. While Loop: Time = 1 minute

on
2. For Loop: 60 iterations
3. Both are possible.

ist um
Scenario 2
Acquire pressure data until the pressure is 1400 psi.
1. While Loop: Pressure = 1400 psi
2. For Loop: unknown

r D str
oop,
p, you still nneed to wire a value to the count terminal. Without more information, you
3. A While Loop. Although you can add a conditional terminal to a For Loop,
do not know the appropriate value to wire to the count terminal.

t fo l In
No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 3-23

Lesson 3 Implementing a VI ni.com | 3-24

Scenario 3
uti ts
Acquire pressure and temperature data until both values are stable for two minutes.

1. While Loop: [(Last Temperature = Previous Temperature) for 2 minutes or more] and [(Lastt Pressure
Pressu re = Previous
ressure Pr Pressure) for 2 minutes or more]
rib en

2. For Loop: unknown


3. A While Loop. Although you can add a conditional terminal to a For Loop, you still need value to the count ter
ed too wire a va terminal. Without more information, you
on

do not know the appropriate value to wire to the count terminal.


ist um

Scenario 4
ond,
d, until the output
Output a voltage ramp starting at zero, increasing incrementally by 0.5 V every second, o oltage is equal
voltage equa to 5 V.

1. While Loop: Voltage = 5 V


or each value 0, 0.5,
2. For Loop: 11 iterations (Including the two end points, count the iteration for 5, 1.0,
0, 1.5, ... 4.5,
4 5.0.)
r D str

3. Both are possible.

End of Exercise 3-3


t fo l In
No na
tio
Na
Exercise 3-4 Temperature Monitor VIAverage Temperature
re

tio s
Goal

ibu nt
Use a While Loop and shift registers to average data.

Scenario

n
str me
The Temperature Monitor VI acquires and displays temperature. Modify the VI to average
ge the
he last five temperature
erature
ure measurements
measure
measur and display the running average
on the waveform chart.

Design
Figure 3-12 and Figure 3-13 show the Temperature Monitor VI front panel and block
ck diagram.
diagram

Di tru
Figure 3-12. Temperature
erature
rature Mo
Monito
Monitor VI Front Panel

Ins
ti
Na
t
No

LabVIEW Core 1 Exercises National Instruments | 3-25

Lesson 3 Implementing a VI ni.com | 3-26

Figure 3-13. Temperature Monitor VI Block Diagram


gram
uti ts
rib en
on
ist um
r D str

To modify this VI, you need to retain the temperature values from thee previous
revious four iterations
tions
ons of the Wh
While Loop and average the values. To accomplish this, you
t fo l In

modify this VI as follows:

revi
revio
Use a shift register with additional elements to retain data from the previous ur iterations.
four

ulated
ed thermom
Initialize the shift register with a reading from the simulated thermometer.
No na

Calculate and chart only the average temperature.

Implementation
1. Test the VI.
tio

Open Temperature Monitor.lvproj


proj in the <
vproj <Exercises>\LabVIEW
ises>\LabV
ses>\LabV Core 1\Temperature Monitor directory.

Open Temperature Monitor VI from


m the Project lorer window.
Proj Explorer
xplorer w dow
Na

Run the VI. Notice the variation


ion
on in the simu
simulated temperature
emperature
perature rea
reading.

2. Stop the VI by clicking the Stop button


on on the
t front
nt panel.
3. Modify the VI to reduce the number of temperature spikes.

uti ts
Display the block diagram.
Modify the block diagram as shown in Figure 3-14.

rib en
Figure 3-14. Temperature Monitor VI Block DiagramAverage
agramAvera
mAvera Temperature
emperature
erature

on
1 3 4

ist um
r D str
2

t fo l In
1
No na
Shift RegistersMultiple shift registers collect multiple temperature
emperatu readings.
lower resizing handle of the shift register to display a four shift registers.
re
ngs. Right-c
Right-click the border of the While Loop and select Add Shift Register. Drag the

2 Create a copy of the Thermometer (Demo) VIPress ss <Ctrl> w gin the su


while dragging subVI outside the While Loop to create a copy. The Thermometer (Demo) VI
returns one temperature measurement and initializes
zes the left
lef shift registers
ters before
b the loop starts.
tio
3 Compound ArithmeticReturns the sum of the current temperature
rature and the four previous temperature readings. Resize the function to have five terminals.
4 ve temperature
DivideReturns the average of the last five temperatu readings.
ngs.

4. Save the VI.


Na

LabVIEW Core 1 Exercises National Instruments | 3-27

Lesson 3 Implementing a VI ni.com | 3-28

Test
uti ts
1. Run the VI.

During each iteration of the While Loop, the Thermometer VI takes one temperature measurement. rem ent. The VI
ment. V adds this value to the last four measurements stored
rib en

me ments
nts
in the left terminals of the shift register. The VI divides the result by five to find the average of the five measurementsthe current measurement plus the previous
four. The VI displays the average on the waveform chart. Notice that the VI initializes the he shift registe h a temperatur
register with emperatur measurement.
temperature
on

2. Stop the VI by clicking the Stop button on the front panel and save the VI.
ist um

3. Save and close the VI and the project.

End of Exercise 3-4


r D str
t fo l In
No na
tio
Na
Exercise 3-5 Temperature Monitor VIPlot Multiple Temperatures
eratures
tures

uti ts
Goal
Plot multiple data sets on a single waveform chart and customize the chart view.

rib en
Scenario

on
Modify the VI from Exercise 3-4 to plot both the current temperature and the running average
erage
ge on th
thee sa
same chart.
hart. In additio
addition
addition, allow the user to examine a portion of
the plot while the data is being acquired.

ist um
Design
Figure 3-15 shows the front panel for the existing Temperature Monitor VI and Figure
ure 3-16 sh
shows the
he block
ock diagra
diagram.
Figure 3-15. Temperature
erature
rature Mo
Monito
Monitor VI Front Panel

r D str
t fo l In
No na
tio

To allow the user to examine a portion of the plot while th


the dataa iss being
bei acquired,
cqui
qui display the scale legend and the graph palette for the waveform chart. Also, expand
Na

the legend to show additional plots.

LabVIEW Core 1 Exercises National Instruments | 3-29

Lesson 3 Implementing a VI ni.com | 3-30

To modify the block diagram in Figure 3-16, you must modify the chart terminal to accept multiple pieces
ecess of data.
data Use a Bundle function to combine the average
uti ts
temperature and the current temperature into a cluster to pass to the Temperature History terminal.

Figure 3-16. Original Temperature Monitor VI Block Diagram


Diagr
rib en
on
ist um
r D str
t fo l In

Implementation
1. Open the Temperature Monitor VI you created in Exercise
rcisee 3-4.
No na

Open Temperature Monitor.lvproj in the <Exercis


<Exercises>\LabVIEW
VIEW Core
Co 1\Temperature Monitor directory.

Open Temperature Monitor.vi from the Project


ject Explorer
Explor
Explo window.
ndow.
w.
tio
Na
2. Modify the block diagram so that it resembles Figure 3-17.

uti ts
Figure 3-17. Temperature Monitor VI Block DiagramPlotting
tting
ng Multiple T
Temperatures

rib en
on
ist um
r D str
t fo l In
1 BundlePasses the current temperature and average temperature
re to the Temperature
ture History chart.

No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 3-31

Lesson 3 Implementing a VI ni.com | 3-32

3. Modify the front panel so that it resembles Figure 3-18.


uti ts

Figure 3-18. Temperature Monitor VI Front PanelPlotting


ng Multiple Te
Temperatures
rib en

1
on
ist um

2
r D str
t fo l In

4
No na

1 Show both plots in the plot legendUse the positioning ng tool to resize the plo
plot legend
end to show two objects. Double-click the label to edit the plot names. The order
of the plots listed in the plot legend is the same ass the order of
o the itemss wired
wi to the Bundle function on the block diagram.
2 eUse the O
Change the plot type of Current TemperatureUse ool to selec
Operating tool select the plot in the plot legend. Click the plot icon, select Common Plots from the
tio

menu, and choose the plot you want.


3 Display Graph PaletteRight-click the Temperature
mperature History chart select Visible ItemsGraph Palette.
hart and sel
4 Display Scale LegendRight-click the Temperature
emperatur History
ry cchart and select
s Visible itemsScale Legend.
Na

4. Save the VI.


Test

uti ts
1. Run the VI. Use the tools in the scale legend and the graph palette to examine the data as it generates.
nerates.
ates.

2. Click the Stop button to stop the VI.

rib en
3. Close the VI and project when you are finished.

on
End of Exercise 3-5

ist um
r D str
t fo l In
No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 3-33


uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
Exercise 3-6 Temperature Warnings VIWith Error Handling
ng

uti ts
Goal
Modify a VI to use a Case structure to make a software decision.

rib en
Scenario

on
You created a VI where a user inputs a temperature, a maximum temperature, and a minimummum m temperatu
temperature. A warning
rning string generates depending on the relationship
ectly.
y. For example,
of the given inputs. However, a situation could occur that causes the VI to work incorrectly. exam he user could enter
the e a maximum temperature that is less

ist um
he user to the eerror: Upper
than the minimum temperature. Modify the VI to generate a different string to alert the per Limit < Lower Limit. Set the Warning?
indicator to TRUE to indicate the error.

Design
Modify the flowchart created for the original Temperature Warnings VI as shown
hown
own in Figure
Figu 3-19.

r D str
Figure 3-19. Modified
fied Temperat
Temperature Warnings
arnings
rnings Flowchart
Flowc

t fo l In
Output
MinTemp
Min Temp>= No CMin
Current
urreTemp
Temp
>= No Current Temp No No Warning
Max Temp Max
MaxTemp
Max Temp
Te Min Temp and
FALSE
No na Yes Yes Yes

Output Output
Heatstroke Freeze Warning
Create Error
Warning and
and and
tio
TRUE TRUE

Output
Upperr Limit
Na

er Limit
< Lower Lim
and
nd TRUE

LabVIEW Core 1 Exercises National Instruments | 3-35

Lesson 3 Implementing a VI ni.com | 3-36

The original block diagram for the Temperature Warnings VI appears in Figure 3-20. You must add a Casee structu
structure to the Temperature Warnings VI to execute the
uti ts
code if the maximum temperature is less than or equal to the minimum temperature. Otherwise, the VI does not execute
eex the code. Instead, the VI generates a new
string and the Warning? indicator is set to TRUE.
rib en

Figure 3-20. Original Temperature Warnings


gs VII Block D
Diagram
Di m
on
ist um
r D str
t fo l In

Implementation
1. Open Weather Warnings.lvproj in the <Exercises>\LabVIEW
s> VIEW Core 1\Weathe Warnings directory.
e 1\Weather

2. Open Temperature Warnings.vi from the Project Explorer


rer window.
plorer windo Youu created the Temperature
T
Te Warnings VI in Exercise 3-1.
No na
tio
Na
3. Place an Error In and Error Out cluster on the front panel as shown in Figure 3-21.

tio s
Figure 3-21. Temperature Warnings VI Front Panel with Error Clusters
Cl

ibu ent
n
um
str
t fo l In
No na
r
4. Open the block diagram and create space to add the Case structure.
str
st e.
tio

Select the Current Temperature, Maxx Temperatu


Temperature,
Tempera Min
in Temperatu and Error In control terminals.
n Temperature,

Tip To select more than one item


m press
ress the <Shift>
<S keyy while
wh youu select the items.
Na

While the terminals are still selected, use


use the
th left arrow key on the
t keyboard to move the controls to the left.

Tip Press and hold the <Shift> key


ey to move the objects in five pixel increments.

LabVIEW Core 1 Exercises National Instruments | 3-37

Lesson 3 Implementing a VI ni.com | 3-38

Tip Press the <Ctrl> key and use the Positioning tool to drag out a region of the size you want
ant
nt to insert.
uti ts

Select the Warning?, Warning Text, and Error Out indicator terminals.
rib en

Align the terminals by clicking the Align ObjectsLeft Edges button in the LabVIEW
W toolbar.
on

While the terminals are still selected, use the right arrow key on the keyboard to move
ve th
thee indic
indicators to the
he right.
ist um

5. Modify the block diagram similar to that shown in Figure 3-22, Figure 3-23, and Figure This VII is part of the ttemperature weather station project.
gure 3-24. T
r D str
t fo l In
No na
tio
Na
Figure 3-22. Temperature Warnings VI Block DiagramNo
No Error, False
Fa Case

ts
2

en
um
str
1

t fo l In
No na
4

r 3
tio

1 Less?Compares the Max Temperature and Min Temperature.


Te e. Make sure the Less? function is outside the Case structure.
2 Case StructureDo not include the Current
rent Temperature,
Tempe Max Temperature,
empe Min Temperature, Error In, Warning?, Warning Text, or Error Out terminals
in the Case structure because these controls
trols and in
indicators
s are used b
by both cases.
Na

3 Set True and False casesWith the


e True case visible,
v right-click
ht-click the border of the Case structure and select Make this Case False.
4 Case StructureWire the Error In terminal to the selector
lector terminal
termina to create No Error and Error cases. By default, the Case structure has True and False cases.
These cases change to Error and No Error ccases only after you wire
w Error In to the selector terminal.

LabVIEW Core 1 Exercises National Instruments | 3-39

Lesson 3 Implementing a VI ni.com | 3-40

Figure 3-23. Temperature Warnings VINo Error,


r, True
rue Cas
Case
bu nts

1
n
e
tio
um

2
str

3
tri
t fo l In
No na
r
tio

1 True caseIf the Max Temperature is set lower


ower than the Min Temperature,
mperature, the True case executes. Click the case selector label to choose the True case.
2 cutes, the Wa
True ConstantWhen the True case executes, Warning? LED illumina
illuminates.
3 String ConstantIf the Max Temperature e is set lower
lowe than the Min Tem
Temperature, the warning Upper Limit < Lower Limit displays on the front panel.
Enter the text in the String Constant.
Na
6. Create the Error case in the outer Case structure so this VI can be used as a subVI.

ts
Figure 3-24. Temperature Warnings VIError
Error
ror Case

en
um
str
t fo In
No na
r
tio
7. Save the VI.
Na

LabVIEW Core 1 Exercises National Instruments | 3-41

Lesson 3 Implementing a VI ni.com | 3-42

Test
uti ts

1. Switch to the front panel of the VI.

2. Resize the Warning Text indicator to a length to accommodate the new string.
rib en

3. Test the VI by entering values from Table 3-4 in the Current Temperature, Max Temperature,
rature,, and
mperature aan Min mperatur controls and running the VI for each
n Temperature
Temperatur
on

set of data.
ist um

Table 3-4 shows the expected Warning Text and Warning? Boolean value for each
ch set of data
data.

Table 3-4. Testing Valuess forr Determine


Determin Warnings
rnings
gs VI

Current Temperature Max Temperature Min Temperature Warning


ning Text Warning?
r D str

30 30 10 Heatstroke Warning
Heatst True

25 30 10 No W
Warning False
t fo l In

10 30 10 Freeze Warning
F True
25 20 30
3 Upper
er Limit < Lower Limit True

4. Test the Error case. To use this VI as a subVI, the VI mustt be able to handlee an error comi
coming into the VI. Test the Error case to make sure that this VI can output
comin
No na

the error information it receives.

On the front panel, use the Operating tool to clickk the status
statu Boolean
leann indicator
ind
in or inside
i the Error In cluster so that the indicator turns red and enter 7 in the
code control.
tio

Run the VI. The error information you entered


ntered passes through
ugh
gh the Error case
cca in the VI and is output in the Error Out cluster.

Display the block diagram, select the


he No Error
Error case,
ca highlight
ghlig execution,
execut
executio and then run the VI again to see the error pass through the Error case.
Na

On the front panel, right-click the


he border of th
the Error
or Out cluster
cluste and select Explain Error to display information about the error that was returned.

5. Save and close the VI.

End of Exercise 3-6


4

uti ts
Developing Modular Applications

rib en
on
ist um
Complete the exercise in this lesson to reinforce the concepts you learn in Lesson 4 of LabVIEW
bVIEW Co
Core 1.

Exercises
Exercise 4-1 Temperature Warnings VIAs SubVI

r D str
t fo l In
No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 4-1


uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
Exercise 4-1 Temperature Warnings VIAs SubVI

uti ts
Goal
Create the icon and connector pane for a VI so that you can use the VI as a subVI.

rib en
Scenario

on
You have created a VI that determines a warning string based on the inputs given. Createe an icon and a connector
ectorr pane so that
tth you can use this VI as a subVI.

ist um
Design
The Temperature Warnings VI contains the following inputs and outputs:

Table 4-1. Temperature Warnings


arnings VI IInputs and
d Outputs

r D str
Inputs Outputs

Current Temperature Warning Text


W xt

Max Temperature Warning?


ng?

t fo l In
Min Temperature

Error In No na Error
ror Out

Use the standard connector pane terminal pattern to assure


ure room for future
fu expansion.
pansion
pansion.

Implementation
1. Open Weather Warnings.lvproj in thee <Exercise Cor 1\Weather Warnings directory.
tio
<Exercises>\LabVIEW
<Exercis abVIEW
VIEW Core

2. Open Temperature Warnings VI from thee Project Explorer


Ex
E window. You created the Temperature Warnings VI in Exercise 3-1 and modified it in
Exercise 3-6.
Na

LabVIEW Core 1 Exercises National Instruments | 4-3

Lesson 4 Developing Modular Applications ni.com | 4-4

3. Connect the inputs and outputs to the connector pane as shown in Figure 4-1.
uti ts

Figure 4-1. Connector Pane Connections for Temperature


erature
ature Warnings
Warni VI
rib en
on
ist um

1 2

1 Connector PaneLocated in the upper right corner of the VI window, the connector tor pane displays
dis potential
ential termi
terminals for the VI. The connector pane shown here
ane and se
displays the standard pattern of terminals. You can right-click the connector pane ns to choose
select Patterns choo different terminal designs.
2 ConnectionsThe Context Help window displays the connections for the
e VI.
r D str

Using the Wiring tool, click the upper-left terminal of the connector
tor pane.

Click the corresponding front panel control, Current Temperature.


ure..
rature
t fo l In

Notice that the connector pane terminal fills in with a color to match the ddata type control connected to it.
ype off the cont
contr

Click the connector pane terminal below the Current Temperature


emp re ter
terminal.

Click the corresponding front panel control, Max Temperature.


Temperature
mperature
No na

Continue wiring the connector pane until all controls


ontrols
ols and
and indicators
indi are wired, and the Context Help window matches that shown in Figure 4-1.
tio
Na
4. Create an icon.

uti nts
Right-click the icon and select Edit Icon.
Use the tools in the Icon Editor dialog box to create an icon. Make the icon as simple or as complex as
a you want
want, however, it should be representative of the
function of the VI. Figure 4-2 shows a simple example of an icon for this VI.

on
me
Figure 4-2. Sample Warning
arning
ng Icon

s tru
t fo l In
No na
tio
Na

Tip Double-click the Selection onn tool to select


selec the existing
xisting
ting graphic.
graphi Press the <Delete> key to delete the graphic. Then, double-click the rectangle tool to
automatically create a borderr for the icon.

Tip Double-click the Text tool to mod


mo
modify fonts.
nts. You can se
select Small Fonts to choose fonts smaller than 9 points in size.

LabVIEW Core 1 Exercises National Instruments | 4-5

Lesson 4 Developing Modular Applications ni.com | 4-6

Tip Select the Glyphs tab and filter the glyphs by the keyword warning. Then drag a warning
rning
ning glyph onto
oon your icon.
tio s
ibu nt

5. Click OK when you are finished to close the Icon Editor dialog box.

6. Save and close the VI.


n
str ume

Test
Test the Temperature Warnings VI as a SubVI.

1. Add files to the Weather Warnings LabVIEW project as shown in Figure 4-3.
Figure 4-3. Weather
ather
er Warnings
Warning Project
ect
str
t fo l In
No na
r

Add an auto-populating folder to the Weather


tio

eather
ather Warning
Warnin
Warnings LabVIEW
VIEW project. LabVIEW continuously monitors auto-populating folders and updates the folder
ording
ding to chang
in the Project Explorer window according dee in the project
changes made proje
projec and on disk.

Right-click My Computer in thee Weather W gss pro


Warnings projectt and select AddFolder (Auto-populating) from the shortcut menu.
Na

Navigate to <Exercises>\LabVIEW
s>\LabVIEW
\LabVIEW Core 1\Shared
\Shared Files
F and click the Select Folder button.
The Shared Files folder contains shared
shar filess that
tha you use in this and future exercises.
Add SubVI Tester.vi to the project.

uti ts
Right-click My Computer and select AddFile from the shortcut menu.

rib en
Navigate to <Exercises>\LabVIEW Core 1\Weather Warnings\Test VIs\SubVI er.v and click Add File.
s\SubVI Tester.vi

2. Open the SubVI Tester VI and complete the block diagram as shown in Figure 4-4.

on
Figure 4-4. Test SubVI Block
ock Diagra
Diagram

ist um
1 2

r D str
3

t fo l In
4

No na
1 Thermometer (Demo)Locate this VI in the Shared
d Files
Files fold
folder in the Project
ct Explorer
Exp window, drag it to the block diagram and wire it as shown. This VI
generates sample temperature values.
2 Temperature WarningsBecause of the modifications
cations you made to Temperature
Tempera Warnings VI, you can use it as a subVI. Wire the Temperature Warnings VI
tio
using the connections you just created.
3 Enum ConstantRight-click the Units (0:Celsius) input of the
:Celsius) inp Thermometer (Demo) VI and select CreateConstant. Creating the enum constant from the
e Thermomet
Thermometer (Demo) VI automatically populates
pulates the enum with the approp
appropriate choices. Use the Operating tool to select Celsius.
4 OrUse the Or function to stop the VI if the user clicks
cl the Sto
Stop button
on or if the Temperature Warnings VI outputs an error in the Error Out cluster.
Na

3. On the front panel of the SubVI Tester


ester VI, enter test values
alues
es for the Max
M Temperature and Min Temperature controls.

4. Run the VI.

The Thermometer (Demo) VI generates sample temperatures,


peratures
peratures which the SubVI Tester VI displays on the Thermometer indicator.
tures,

LabVIEW Core 1 Exercises National Instruments | 4-7

Lesson 4 Developing Modular Applications ni.com | 4-8

5. Notice how the string in the Warning Text indicator change as the temperature rises and falls.
uti ts

6. After you have finished testing, save and close the VI.
rib en

End of Exercise 4-1


on
ist um
r D str
t fo l In
No na
tio
Na
5

uti ts
Creating and Leveraging Structures

rib en
on
ist um
Complete the exercises in this lesson to reinforce the concepts you learn in Lesson 5 off LabVIEW
abVIEW Core
C 1.

Exercises
Exercise 5-1 Concept: Manipulating Arrays

r D str
Exercise 5-2 Concept: Clusters
Exercise 5-3 Concept: Type Definition

t fo l In
No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 5-1


uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
Exercise 5-1 Concept: Manipulating Arrays

uti ts
Goal
Manipulate arrays using various LabVIEW functions.

rib en
Description

on
You are given a VI and asked to enhance it for a variety of purposes. The front panel of this
his VI is built. You complete
omplete
plete the block
blo
bl diagram to practice several different
techniques to manipulate arrays.

ist um
Implementation
1. Open Manipulating Arrays.lvproj in the <Exercises>\LabVIEW
EW Core 1\Manipulating
1\ pulating
ating Arrays
Ar directory.

r D str
2. Open Array Manipulation VI from the Project Explorer window. The
he front panel, shown
n in Figure 5-1, is already built for you.

t fo l In
No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 5-3

Lesson 5 Creating and Leveraging Structures ni.com | 5-4

Figure 5-1. Array Manipulation VI Front Panel


anel
el
ts
en
is um
r D str
t fo l In
No na
tio
Na
3. Open the block diagram and complete each of the cases that correspond to the tabs on the front panel
nel as shown
show in Figures 5-2 through 5-8.

uti ts
Figure 5-2. Array Manipulation VIConcatenate
e Channels Case
Ca

rib en
on
ist um
r D str
t fo l In
2 1

1 Build ArrayExpand this node to accept two inputs, and


d then right-click
righ and select Co
Concatenate inputs from the shortcut menu.
2
No na
Wire the sine wave and square wave outputs to the Build
uild Array ffunction to create 1D array with both waveforms.
reate a 1

4. Switch to the front panel and test the Concatenate


ate Channels case.
cca
tio
On the front panel, click the Concatenate
te Channels tab.
ate t

Run the VI and notice that the sine wavee is concatenated


concat d with
w h a squar
square wave.
Na

5. Stop the VI.

6. Switch to the block diagram and sel


select Add/Subtract
ect the Ad
Add ract Channels case.

LabVIEW Core 1 Exercises National Instruments | 5-5

Lesson 5 Creating and Leveraging Structures ni.com | 5-6

7. Complete the Add/Subtract Channels case as shown in Figure 5-3 and Figure 5-4.
uti ts

Figure 5-3. Array Manipulation VIAdd/Subtract Channels


annels True Case
rib en
on
ist um
r D str
t fo l In

1 2
No na

1 Subtract?Wire this to the case selector terminal so that


at the cor
correct case
e executes when you click the Subtract? button on the front panel.
2 Case StructurePlace a Subtract function in the True
ue case, so that the VI subtracts
btracts the elements of the array when the Subtract? button on the front panel is
pressed.
tio
Na
Figure 5-4. Array Manipulation VIAdd/Subtract Channels
nnels
ls False Case

uti ts
rib en
1

on
ist um
1 When the value of the Subtract? Boolean control is False, the array elements are added.

Note This case demonstrates polymorphic functionality by adding and


nd subtracting elements
ents of the array
arra
array.

r D str
8. Switch to the front panel and test the Add/Subtract Channels case.

On the front panel, click the Add/Subtract Channels tab.

t fo l In
Run the VI.

Click the Subtract? button and observe the behavior off sub
subtracting
ng tthe square
uare
are wave from the sine wave.

9. Stop the VI.


No na
10. Switch to the block diagram and select the Select a Channel
annel case
case.
tio
Na

LabVIEW Core 1 Exercises National Instruments | 5-7

Lesson 5 Creating and Leveraging Structures ni.com | 5-8

11. Complete the Select a Channel case as shown in Figure 5-5.


uti ts

Figure 5-5. Array Manipulation VISelect a Channel

1 2
rib en
on
ist um

4
r D str
t fo l In

1 Build ArrayCombines the sine and square waves into one 2D arr
array.
2 Index ArrayExtracts row 0 or 1 from the 2D array. The output fro
from this function
unction is a 1D array and is the waveform you select with the Select Channel control.
No na

The waveform is displayed on the Single Channel of Data Wave


Waveform Graph ph and the Single Channel of Data Array indicator.
3 Select ChannelWire to the row input of the Index Array function.
fun
4 Array SizeBecause you are using a 1D array, this function
functio outputs a scala
scalar value.
tio

Note The Select a Channel case usess a property node


no to change color of the graph plot. You learn about Property Nodes LabVIEW Core 2.
hange the col
colo

12. Switch to the front panel and test the Select Channel case.
ect a Chann
Channe
Na

On the front panel, click the Select


elect Chann tab.
ect a Channel

Run the VI.


Switch between Channel 0 and Channel 1 and notice the ddifferent values shown in the Single Channel of Data Array indicator.
13. Stop the VI.

uti ts
14. Switch to the block diagram and select the Waveform Data case.

rib en
15. Complete the Waveform Data case block diagram as shown in Figure 5-6.

The waveform datatype is a special kind of cluster that contains additional timing information
rmation about the waveform.
ion abou aveform.
orm.

on
Figure 5-6. Array Manipulation
n VIWavefor
VIWaveform
IWavefo Data
ta

ist um
r D str
t fo l In
1
No na
1 AddUses the value from the Offset control to modify the value of the
e wav
waveform in the waveform datatype. Notice the value from the Offset control must be
coerced to be used with the waveform datatype.
y
tio
Note Polymorphism is the ability off VIs and functions
func
funct too automatically
automatically adapt to accept input data of different data types, including arrays, scalars, and
waveforms. VIs and functions are polymoprhic
moprhic to varying
ng degrees.
grees.
Na

16. Switch to the front panel and test the Data case.
hee Waveform D se.

On the front panel, click the Waveform Data


D tab.
b.

Run the VI.

LabVIEW Core 1 Exercises National Instruments | 5-9

Lesson 5 Creating and Leveraging Structures ni.com | 5-10

Change the value of the Offset control and notice the square wave move on the Waveform Data
ata chart.
uti ts

17. Stop the VI.


rib en

18. Switch to the block diagram and select the All Data Channel case.

19. Complete the All Data Channel case as shown in Figure 5-7.
on

Figure 5-7. Array Manipulation


ation
on VIAll Data
D
ist um

1
r D str
t fo l In

5
No na
tio

2 3 4

1 AddModify the same data in one array byy adding the


th value of the Channel
Cha 1 Offset to each element of the array.
2 For LoopExtracts each element of the
e array using
usin auto indexing
ndex so that
t the Add function in the For Loop can add the scalar value.
Na

3 Build ArrayTakes the two 1D arrays


ays and builds
buil a 2D array.
rray. Each 1D array becomes a row in the 2D array.
4 Array SizeOutputs a 1D array where each element
nt shows the size of each dimension. In this exercise, you have 2 elements of data for the number of rows
and columns.
5 All Data Channel and Data Channel Array
rr indicators
ators display the same data.
Note The polymorphic functionality of LabVIEW functions allows you to perform the samee operation
eration oon each element without extracting the array

uti ts
elements, as you do with the two Add functions in the All Data Channel case.

20. Switch to the front panel and test the All Data Channel case.

rib en
On the front panel, click the All Data Channel tab.

on
Run the VI.

ist um
Change the value of the Channel 1 Offset control and observe the behavior.

21. Stop the VI.

22. Switch to the block diagram and select the Waveform Subset case.

r D str
23. Complete the Waveform Subset case as shown in Figure 5-8.

t fo l In
No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 5-11

Lesson 5 Creating and Leveraging Structures ni.com | 5-12

Figure 5-8. Array Manipulation VIWaveform


m Subset
ubset
uti ts

2 1
rib en
on
ist um

4
r D str
t fo l In

1 Array SubsetExtracts a subset of an existing array. In this


his exe
exercise, you use
e this function to zoom in on a subset of the waveform you generated.
2 Numeric ConstantThese constants specify that the function extract
nction extra the first
irst two rows starting at element 0.
No na

3 Start ValueSets the start index. The default value is set


et to start at element 0.
ent 0
4 LengthSets the number of elements to extract. The value is set to output
e default va 1000 elements.
utput 1

24. Switch to the front panel and test the Waveform


m Subset case.
case
tio

On the front panel, click the Waveform


m Subset tab.

Run the VI.


Na

Change value of the Start Value


uee and Length sliderss and
nd notice that
th the Subset Data waveform graph x-axis starts at zero and finishes at the number of
elements in the new array. The start at zero
he x-axis starts o because the
th VVI creates a brand new array and the graph does not know where the data was located in the
original array.

25. Stop the VI.


Using the NI Example Finder to Learn More about Arrays

uti ts
Use the NI Example Finder to browse or search examples installed on your computer or on the NI Developer Zon at ni.com/zone. Example VIs can show you
eveloper Zone
how to use specific functions and programming concepts such as arrays and polymorphism.

rib en
nstrate
ate different
Complete the following steps to use the NI Example finder to locate example VIs that demonstrate differe wayss to use the
th Array function.

on
1. Select HelpFind Examples to start the NI Example Finder.

ist um
2. Click the Search tab and enter the keyword array.

3. Click the Search button to find VIs using that keyword.

ption.
tion.
4. Click one of the example VIs in the search results list and read the description.

r D str
5. Double-click an example VI to open it.

6. Read through the comments on the front panel and block diagram to learn more about what
at this
this exam
example VI demonstrates.

t fo l In
7. Run the example, examine the different cases, and click the Stop eex
op button to exit.

nished
8. Close the VIs and the NI Example Finder when you are finished.

End of Exercise 5-1


No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 5-13


uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
Exercise 5-2 Concept: Clusters

tio s
Goal

ibu nt
Create a cluster datatype containing the data to be passed around an application and, in the process,
cess,
s, create scalable,
sca
sc readable
rea code.

Description

n
str me
You create a cluster which contains the data used by the Temperature Warnings VI you created
eated
ed in Lesson 3. You
ou modify the Temperature
T Warnings VI to receive and
orkss in a more
return data in the form of that same cluster as shown in Figure 5-9. The modified VI works mor modular
ular fashion
ula ashion wit
w
with other subVIs in the overall application.
Figure 5-9. Temperature Warnings
gs VI with Clusters
Clu Front
ront Panel

Di tru
Ins
No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 5-15

Lesson 5 Creating and Leveraging Structures ni.com | 5-16

1. Open Weather Warnings.lvproj in the <Exercises>\LabVIEW Core 1\Weather Warnings


nings d
arnings directory.
uti ts

2. Open Temperature Warnings VI from the Project Explorer window.


rib en

3. Place existing controls and indicators in a cluster named Weather Data as shown in Figure
gure 5-10.
Figure 5-10. Create Cluster
luster
er
on
ist um

1 3
r D str

2
t fo l In
No na
tio

1 ClusterUse the Cluster control from the Silve


Silver palette and change
ange the label to Weather Data.
2 Select controls and indicators to include in the cluster
cluster. <Shift>-click select multiple objects.
click to selec
3 D
Drag the controls and indicators into the Weather Data cluster.
Na
4. Resize the cluster so that all the elements are visible and arranged vertically as shown in Figure 5-11.
11.

tio s
Figure 5-11. Resize Cluster Control
rol

ibu nt
n
str ume
1

t fo l
No na
r
tio
1 Autosize clusterLabVIEW can rearrange
e and resize the cluster
er for you. Ri
Right-click the border of the Weather Data cluster and select AutoSizingArrange
Vertically.
Na

LabVIEW Core 1 Exercises National Instruments | 5-17

Lesson 5 Creating and Leveraging Structures ni.com | 5-18

5. Reorder the items in the cluster as shown in Figure 5-12


tio s
Figure 5-12. Reorder Cluster
ibu nt

3
n
str me

2
l
Di
No na
tio
Na
t

1 Right-click the edge of the clusterr and select Reorder


er Controls
Controls in
i Cluster.
2 Click the black numbers to toggle the orde
order of the items in the cluster.
3 Click the Confirm button to save the changes.
6. Modify the VI to receive and return cluster data.

tio s
Figure 5-13. Temperature WarningsWeather Data In and Weather Dat
Data Out Clusters

ibu nt
n
str me
3

Di tru
2

s
l In
No na
tio
Na
t
1 Weather Data<Ctrl>-click the Weather
ather Data cluster and
d drag it to create a copy. Rename the copy Weather Data In.
2 Weather DataRight-click the original cluste elec Change to Indicator. Rename the indicator Weather Data Out.
cluster and select
3 Wire connector paneWire the Weather
ther Data In control to the
th top left corner of the connector. Wire Weather Data Out to the top right corner.

LabVIEW Core 1 Exercises National Instruments | 5-19

Lesson 5 Creating and Leveraging Structures ni.com | 5-20

7. Modify the block diagram as shown in Figure 5-14 to extract data from the input cluster.
uti ts

Move the Weather Data In cluster to the left, outside the Case structures.

Move the Weather Data Out cluster to the right outside the Case structures.
rib en

Figure 5-14. Temperature Warnings with Clusters


sters Block
Bloc Diagram
gram
m
on
ist um

2
r D str
t fo l In
No na

1 Unbundle By NameWire the Weather Data In control and expand the he U


Unbundle By Name function to display three items. Wire the outputs of the Unbundle
By Name function to the broken wires in the order shown. Be
Because youu moved iindividual controls and indicators into a single cluster, you must use the Unbundle
tio

By Name function to wire the internal controls


ols and indicators
indicat independently
ependently of each other.
2 Bundle By NameWire the Weather Data a In cluster around
a the
he Case structure
struc to the input cluster of the Bundle by Name function. Display two elements and
use the Operating tool to select Warning? and Warni
Warning Text elements.
ements. Connect
C the broken wires to the Unbundle By Name inputs as shown.

Note If the order of the elements


nts in the
the Unbu
Unbundle By Name and the Bundle By Name functions is different than what you want, can use the Operating tool
Na

to change the order.

8. Save and close the Temperature Warnings


rnings VI.
V
Test

uti ts
1. Use the SubVI Tester VI to test the modified Temperature Warnings VI as a subVI.

On the block diagram, delete the Thermometer, Warning?, and Warning Text indicators
tors and any br
broken wires
wires. Press <Ctrl-B> to clean up all broken wires.

rib en
Modify the SubVI Tester VI to work with the Temperature Warnings VI that now uses clusters as
a shown
wn inn Figure 5-15.
5-

on
Figure 5-15. SubVI Tester VI Block Diagram Modified to Work with M
Modified
d Temperature Warnings VI

ist um
1

r D str
2

t fo l In
No na
3

1 Weather DataRight-click the Weather Data Outt output of the Temperatureature Warnings VI and select CreateIndicator. Wire the output to the edge of the While
S
Loop, right-click the tunnel, and then select Replace with Shift ster from the shortcut menu. The shift register stores the cluster data from one iteration to
Register
tio
the next.
2 ConstantRight-click the left shift register and select Create constant initialize weather data to values. Rename the constant Initialize Weather.
onstant to in
3 Bundle By NameWire the shift registerr from the Initialize
In Weather constant
We con to the input cluster of the Bundle By Name function. Expand the Bundle By Name
function to display three elements.
Na

LabVIEW Core 1 Exercises National Instruments | 5-21

Lesson 5 Creating and Leveraging Structures ni.com | 5-22

Arrange the front panel as shown in Figure 5-16.


uti ts

Figure 5-16. SubVI Tester VI Front Panel Modified


ed
d with Clusters
Clust
rib en
on
ist um
r D str
t fo l In

Enter values in the Max Temperature and Min Temperature


er contr
contro
controls.

Run the VI and verify that the Weather Data indicator


atorr displays correct values.
No na

2. Save and close the VI

End of Exercise 5-2


tio
Na
Exercise 5-3 Concept: Type Definition

uti ts
Goal
To improve the scalability of your application by using type definitions made from custom cluster
ter controls
controls,, iin
indicators,
ors, and constants of a particular data type.

rib en
Scenario

on
As a LabVIEW developer, you can encounter situations where you need to define your own wn custom dat data types
es inn the form oof clusters and enums. A challenge
velopmen
opment.
associated with using custom data types is that you may need to change them later in development. t. In addition,
on, you may nneneed to change them after they have already

ist um
been used in VIs. For example, you create copies of a custom data type and use themm as controls,
controls, indicators,
iin ors,
rs, or constants
constant in one or more VIs. Then you realize that
the custom data type needs to change. You need to add, remove, or change items in n thee cluster dda
data typee or the enum.
enum

As a developer you must ask yourself the following questions:

r D str
What should happen to the copies of the custom data types used in VIss that are aal
already saved?

Should the copies remain unchanged or should they update themselves


mselves reflect changes
elves to refl
re anges original?
es to the or

Usually, you want all the copies of the custom data type to update iff you update the
th original
inal
al custom
custom ddat
data type. To achieve this you need copies of the custom data

t fo l In
types to be tied to a type definition, which is defined as follows:

Type definitionA master copy of a custom data type that multiple


ltiple VIs can
ultiple an use.

Implementation
No na
In this exercise, you modify the Temperature Warnings VI that you
you revised
rev in Exercise 5-2 in such a way that the changes to the Weather Data custom data type
propagate through the application.

tors temperature
When complete, the Weather Station application monitors temper information. This exercise modifies the Temperature Warnings VI. In the Challenge
andd wind inf
infor
tio
exercise, you modify the Windspeed Warnings VI.

1. Open Weather Warnings.lvproj in


n the
he <Exerc
<Exercises>\LabVIEW
abVIEW Core
C 1\Weather Warnings directory.

rom the Project


2. Open Temperature Warnings VI from Proje Explorer
Projec lorer win
wind
rer window.
Na

LabVIEW Core 1 Exercises National Instruments | 5-23

Lesson 5 Creating and Leveraging Structures ni.com | 5-24

3. Experiment with changing an existing cluster.


uti ts

Place a File Path Control (Silver) in the Weather Data In cluster control.

Notice that the Temperature Warnings VI is broken. This is because the Weather Dataa In and Weather
rib en

Weat
Weath Data O clusters are no longer the same data type.
ata Out

Open the block diagram and notice the broken wire connected to the Weather Dataa Out
ut terminal.
termin
termina
on

Press <Ctrl-Z> to undo the addition of the File Path Control.


ist um

4. Make a type definition.

Right-click the border of the Weather Data In control and select Make f.
ke Type Def
Def.
r D str

On the block diagram the Weather Data In terminal now has a black
ack
k triangle on the corner
orner
rner indicating that it is connected to a type definition.

Right-click the border of the Weather Data In control and select


ct Open Typ Def too display
pen Type isplay the Custom
C Control Editor window as shown in Figure 5-17.
The window looks like the front panel of a VI but it does nott have
ave a block diagram.
am.
m.
t fo l In
No na
tio
Na
Figure 5-17. Custom Control Editor Window
ow

uti ts
rib en
on
1

ist m
1

t fo l
The control type is Type Def, which maintains the link between
tween this file and
d the custom ccontrol copies used in VIs.
No na
rD
Save the custom control as Weather Data.ctl
l in the <Ex
ctl <Exercises>\LabVIEW
ises LabVI Core 1\Weather Warnings directory and close the control editor
window.

On the block diagram of the Temperature


tio
ree Warnings
Warnings VI,
VI noticee the coercion ddot on the Weather Data Out indicator terminal. This indicates that the indicator
V
is not tied to the type definition.

he type definition.
5. Tie the Weather Data Out indicator to the defi
Na

Right-click the border of the Weather


ather Data Out indicator
ndicator
cator on the front panel and select ReplaceSelect a Control from the shortcut menu.

Browse to and select the Weather l file you just ccreated.


her Data.ctl
Dat

LabVIEW Core 1 Exercises National Instruments | 5-25

Lesson 5 Creating and Leveraging Structures ni.com | 5-26

Note You can no longer add or remove elements to or from the cluster control and indicator on the fron
front panel. You must open the type definition and add
uti ts
or remove the element from the control editor window.

Save the Temperature Warnings VI.


rib en

6. Edit the Weather Data type definition to include unit information.


on

Right-click the border of the Weather Data In control and select Open Type Deff from the shortcut
sh menu.
nu.
ist um

Modify the front panel as shown in Figure 5-18.


r D str
t fo l In
No na
tio
Na
Figure 5-18. Weather Data Type Definition with Temperature
perature
rature Units
U

bu nts
n
e
tio
um
str
tri
t fo l In
No na 1

r
tio
1 Enum (Silver)Place an enum in the cluster
er and rename it Units
t . Right-click the enum and select Edit items. Create an item for Celsius and Fahrenheit.

Save the Weather Data type definition


on and close the
th controll editor window.
wind
Na

LabVIEW Core 1 Exercises National Instruments | 5-27

Lesson 5 Creating and Leveraging Structures ni.com | 5-28

Notice that the Weather Data In control and Weather Data Out indicator on the Temperaturee Warnings VI have been updated with the changes you made
tio s
to the Weather Data type definition. Arrange the front panel of the VI as shown in Figure 5-19.
19.
9.
ibu ent

Figure 5-19. Temperature Warnings VI with Type Def


ef Controls
ontrols an
and Indicators
n
um
str
t fo In
No n
tio
Na

7. Save the Temperature Warnings VI.


Test

uti ts
1. Use the SubVI Tester VI to test the modified Temperature Warnings VI as subVIs.

Open the SubVI Tester VI from the Project Explorer window.

rib en
On the front panel, right-click the Weather Data Out cluster and select ReplaceSelect
Select Contr from
ct a Con
Control m the
he shortcut menu.

on
Navigate to the Weather Data.ctl file in the <Exercises>\LabVIEW Core
re 1\Weather
1\Wea Warnings di
directory and select it.

ist um
On the block diagram of SubVI Tester VI, delete the following items:
Initialize Weather constant wired to the left shift register

r D str
Any broken wires. Press <Ctrl-B> to clean up all broken wires.

Modify the SubVI Tester VI to work with the Temperature Warnings


rnings
gs VI wh
whic
which now
w uses
ses type defi
definitions as shown in Figure 5-20.

t fo l In
No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 5-29

Lesson 5 Creating and Leveraging Structures ni.com | 5-30

Figure 5-20. SubVI Tester VI Block Diagram Modified to Test Temperature


mperature
erature W
Warnings SubVI
uti ts

1 3 2
rib en
on
ist um
r D str

1 Initialize shift registerRight-click the left shift register and select


ct CreateConstant
reateCo to
o initialize th
the shift register. Right-click the cluster and select View Cluster
t fo l In

as Icon.
2 Bundle By NameExpand the node to display four elements.
ent Use the O
Operating select Units.
ng tool to se
3 Wire the Units (0:Celsius) constant to the Units element off the Bu
Bundle By Name
ame function.
No na
tio
Na
Arrange the front panel as shown in Figure 5-16.

uti ts
Figure 5-21. SubVI Tester VI Front Panel Modified
ed with Type Def

rib en
on
ist um
r D str
t fo l In
Enter values in the Max Temperature and Min Temperature
mperature controls.
c ls.
s.
No na
2. Run the VI and verify that correct values are displayed
ed in the Weather
layed W Da Out indicator.
r Data ind
3. Save and close the VI.
tio
Challenge
In this challenge exercise, you modify the Windspeed
dspeed Warn
Warnings VI to
o au
augment
gment tthe Weather Station application. You then modify test the Windspeed Warnings VI as
a subVI.
Na

1. Add the Windspeed Warning VI too the Weather Stationn project.


roject.

In the Project Explorer window,


w, right cli
click My Computer and
an select AddFile from the shortcut menu.

Navigate to <Exercises>\LabVIEW Core 1\Weather


1\Weath Warnings\Support VIs and select Windspeed Warnings.vi.

LabVIEW Core 1 Exercises National Instruments | 5-31

Lesson 5 Creating and Leveraging Structures ni.com | 5-32

2. Open the Windspeed Warnings VI.


tio s
3. Copy the Weather Data In cluster from the Temperature Warnings VI to the Windspeed Warnings
ngs VI.
rnings
ibu nt

4. Right-click the Weather Data In cluster and select Open Type Def from the shortcut menu.
nu.

5. Modify the Weather Data type definition with windspeed controls as shown in Figure 5-22.
n
str me

Figure 5-22. Windspeed Warnings VI Type Definition


efinition C
Co
Controls and Indicators
Di tru
s
t fo l In
No na
tio
Na
6. Modify the block diagram of the Windspeed Warnings VI to use the new Weather Data type definition
itionn instead of individual controls and indicators, as shown in

uti ts
Figure 5-23.
Figure 5-23. Windspeed Warnings VI Using Type
pe Definitions
Definitio

rib en
on
ist um
r D str
t fo l In
No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 5-33

Lesson 5 Creating and Leveraging Structures ni.com | 5-34

7. Modify the SubVI Tester VI to work with the Windspeed Warnings VI, as shown in Figure 5-24.
uti ts

Figure 5-24. SubVI Tester VI Block Diagram Modified to Testt Windspeed Warnings
W SubVI
rib en
on
ist um
r D str
t fo l In

8. Run the SubVI Tester VI and verify that correct values are displayed
layed in the Weather
W er Data Out indicator.
i
in
9. Save and close the VI and the project.

End of Exercise 5-3


No na
tio
Na
6

uti ts
Managing File and Hardware Resources
es
s

rib en
on
ist um
Complete the exercises in this lesson to reinforce the concepts you learn in Lesson 6 off LabVIEW
abVIEW Core
C 1.

Exercises
Exercise 6-1 Concept: Spreadsheet Example VI

r D str
Exercise 6-2 Temperature Monitor VILogging Data
Exercise 6-3 Concept: NI Measurement & Automation
ion Explorer (MAX)
(M
Exercise 6-4 Using DAQmx

t fo l In
Exercise 6-5 Concept: GPIB Configuration withh MAX
Exercise 6-6 Concept: NI Devsim VI

No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 6-1


uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
Exercise 6-1 Concept: Spreadsheet Example VI

tio s
Goal

ibu nt
Save a 2D array in a text file so a spreadsheet application can access the file and to explore how
w to display numeric
nu
n data
dat in a table.

Description

n
str me
Complete the following steps to examine a VI that saves numeric arrays to a file in a format
mat you can access
ac withh a spreadsheet.
spreadsh

1. Open Spreadsheet Example.lvproj in the <Exercises>\LabVIEW Core


ore t Example directory.
e 1\Spreadsheet
1\Spre eet

2. Open Spreadsheet Example.vi from the Project Explorer window.

Di tru
The Spreadsheet Example VI generates sine, noise, and cosine data for 128 8 points.
oints. Then the VII stores
ores this da
data in a 2D array that is 128 rows 3 columns. The
e, Noise, and C
Table indicator in Figure 6-1 displays the data from three columns (Sine, Cosine)) for the first 14 rows of the array. The Waveform Graph indicator
es the data in
displays the plots each column. Finally, the Spreadsheet Example VI saves i a logg file.

Ins
Figure 6-1. Spreadsheet
preadsheet
eadsheet Example
E le VI Front Pan
Panel
Na
t
No

3. Run the VI.

LabVIEW Core 1 Exercises National Instruments | 6-3

Lesson 6 Managing File and Hardware Resources ni.com | 6-4

4. Save the file, when prompted, as wave.txt in the <Exercises>\LabVIEW Core 1\Spreadsheet
dsheet
heet Example
E
Ex directory and click the OK button. You
uti ts
examine this file later.

5. Display and examine the block diagram for this VI.


rib en

Figure 6-2. Spreadsheet Example VI Block Diagram


Diag
Diagra
on
ist um
r D str

Sine Pattern VIReturns a numeric array of 128 elements containing


ontaining
aining a sine
sin pattern.
ern.
rn. The constant
consta 90.0, in the second instance of the Sine Pattern VI,
t fo l In

specifies the phase of the sine pattern which generates the cosine pattern.
pattern

Uniform White Noise VIReturns a numeric array off 128 elements


ents containing ppattern.
ning a noise pa

ray from
Build Array functionBuilds the following 2D array from the sine
ssi array,
ay, noise array,
array and cosine array.
No na

Sine Arra
Array

Noise Array
Nois
tio

Cosine Array
C
Na
Transpose 2D Array functionRearranges the elements of the 2D array so element [i,j] becomes
comes
mes element
elem [j,i], as follows.

uti ts
S N C

rib en
on
ist um

r D str
sheet
Write To Spreadsheet File VIFormats the 2D array into a spreadsheet et string an tes the string to a file. The string has the following format, where an
and writes
arrow () indicates a tab, and a paragraph symbol () indicates an end of line character.
cter.
er.

S N C

t fo l In


No na


tio
Number To Fractional String functionConverts
nConverts aan array of numeric va
Converts values to an array of strings that the table displays.

6. Close the VI. Do not save changes.


Na

Note This example stores only


nly three ar
array
arrays
ray in thee file.
le. To inclu
include more arrays, increase the number of inputs to the Build Array function.

LabVIEW Core 1 Exercises National Instruments | 6-5

Lesson 6 Managing File and Hardware Resources ni.com | 6-6

7. Open the wave.txt file using a word processor, spreadsheet application, or text editor and view its contents.
contents
uti ts

Open a word processor, spreadsheet application, or text editor, such as Notepad or WordPad.
ad.

Open wave.txt. The sine waveform data appear in the first column, the random (noise)
rib en

ise) waveform data appear in the second column, and the cosine
waveform data appear in the third column.
on

8. Exit the word processor or spreadsheet application and return to LabVIEW.


ist um

End of Exercise 6-1


r D str
t fo l In
No na
tio
Na
Exercise 6-2 Temperature Monitor VILogging Data

uti ts
Goal
Modify a VI to create an ASCII file using disk streaming.

rib en
Description

on
You have been given a VI that plots the current temperature and the average of the last three
ree temperatur
temperatures. Modify
odify
fy the VI to log the current temperature to an ASCII
file.

ist um
Implementation
1. Open Temperature Monitor.lvproj in the <Exercises>\LabVIEW
EW Core 1\Temperature
1\ erature
ature Monitor
Mon directory.

r D str
2. Open Temperature Monitor.vi from the Project Explorer window. You this VI inn Exercise 3-5
u created th
thi

t fo l In
No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 6-7

Lesson 6 Managing File and Hardware Resources ni.com | 6-8

3. Modify the block diagram as shown in Figure 6-3.


uti ts

Figure 6-3. Temperature Monitor VI with Logging


g Block Diagram
Diagr
rib en
on
ist um
r D str
t fo l In

1 3 2 4 5 6 7

1 Open/Create/Replace FileCreates or replaces an existing


ting file for the data
ta log. Right-click
Right-c the operation input and select CreateConstant.
Set the constant to replace or create.
No na

2 Format Into StringFormats temperature data into a string. Ex de to ac


Expand the node accept two inputs.
3 End of Line ConstantAdds an end-of-line constant
ant after ea
each piece of d
data so that data values are separated by line breaks.
4 Write to Text FileWrites the data to a file.
tio

5 OrStops the VI when an error occurs or when


hen the Stop Button
on is clicked.
6 Close FileCloses the data log file created
ed or replaced
replac when the
he VI started
starte running.
7 Simple Error HandlerIndicates whether
er an error occurred.
ed. If an error
ror occurred, this VI returns a description of the error and optionally displays a dialog box.
Na
4. Configure the Format Into String function as shown in Figure 6-4.

uti ts
Figure 6-4. Configuring the Format Into String
ing
g Function

rib en
on
1
2

ist um
r D str
3

t fo l In
1 Format Into StringDouble-click the Format Into String function
n to open th
the Edit Format
rmat String dialog box.
2 Use specified precisionPlace a checkmark in this checkbox enter 3 in the text box tto specify that data have a floating point precision of three digits.
ckbo and ente
3 Corresponding format stringThis text box automaticallyy updates based on the configur
configuration you specify. After you click the OK button in the dialog box, the
block diagram updates to display the format string.
4
No na
Help buttonClick the Help button for more information format specifier
on about for elements, such as %3f, and configuration options for the Format Into String
cifier eleme
function.

5. Test the VI.


tio
Run the VI.
Give the text file a name and a location.
ation.
n.
Na

Click the Stop button after the VI has been running


ru forr a few sam
samples.

Navigate to the text file created


ed and explore
explo it.

6. Close the VI and text file when you have finished.


f

LabVIEW Core 1 Exercises National Instruments | 6-9

Lesson 6 Managing File and Hardware Resources ni.com | 6-10

Challenge
uti ts

Objective 1: Create Log File with Single Header


To improve the usability of the log file, you are asked to include a header at the top of the log filee ass shown in Figure 6-5.
rib en

Figure 6-5. Temperature Monitor VI Log


og File with H
Header
He
on
ist um
r D str

Modify the Temperature Monitor VI to include the header Current Temperature


mperatur .
Temperatur
t fo l In

Hints:

Because you write the header to the text file only once,, you shouldd write
w to header outside
o the header out
ou the While Loop.

Use the functions on the Strings palette to manipulate format a string


ulatee and forma ng for use in a word processing or spreadsheet application.
ing
No na
tio
Na
Objective 2: Create Log File with Two Columns and Headers

uti ts
arate
ate the colum
Modify the VI to write both the current temperature and the average temperature to the log file. Separate columns of data with a tab character and place a header
at the top of each column as shown in Figure 6-6.

rib en
Figure 6-6. Temperature Monitor VI Log File with Two Columns and Headers
Heade

on
ist um
r D str
1 2

1 Tabbed columns in a text editor. 2 Tabbed


bbed columns
colum in a spreadsheet application.

t fo l In
Hint:

vert and format


Use an expanded Format Into String function to convert fo ata
ta into a strings.
the data string

End of Exercise 6-2


No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 6-11


uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
Exercise 6-3 Concept: NI Measurement & Automation Explorer
lorer
er (MAX)
(M
(MA

uti ts
Goal
Use MAX to examine, configure, and test a device.

rib en
Description

on
Complete the following steps to examine the configuration for the DAQ device in the computer
mputer
uter using MAX.
M Usee the test routines
ro
r in MAX to confirm operation of
uctions
ions in step 3.
the device. If you do not have a DAQ device, you can simulate a device using the instructions

ist um
Note Portions of this exercise can only be completed with the use of a real
al device and a BNC-2120.
C-2120.
2120. Some oof these steps have alternative instructions for
simulated devices.

1. Launch MAX by selecting StartProgramsNational InstrumentsMeasurement omation or by double-clicking the NI MAX icon on your desktop.
asurement & Automation
easurement

r D str
MAX searches the computer for installed National Instruments hardware displays the information.
are and display

mining
ing the DAQ
2. If you have a DAQ device installed, skip step 3 and go to the Examining DA Device
ice Settings section.
sec

t fo l In
te the exercis
3. Create an NI-DAQmx simulated device to allow you to complete exer i without
exercises houtt hardware.
hardware

Right-click Devices and Interfaces and select Createe New


NewSimulated
ula
ulat NI-DAQmx
I-DAQmx Dev or Modular Instrument from the list.
-DAQmx Device
De

Click the Finish button.


No na
In the Create Simulated NI-DAQmx Device dialog
og box, sel
select M Series
S es DAQN
DAQ
DAQNI PCI 6225.

Click the OK button.


tio
Na

LabVIEW Core 1 Exercises National Instruments | 6-13

Lesson 6 Managing File and Hardware Resources ni.com | 6-14

Examining the DAQ Device Settings


tio s
1. Expand the Devices and Interfaces section.
ibu nt

2. Select the device that is connected to your machine. Green icons represent real devices and yellow rrepresent
ow icons re nt simulated devices. You might have a different
device installed, and some of the options shown might be different.
n
str me

MAX displays the National Instruments hardware and software in the computer. The device
device alias appears
ap in quotes following the device type. The Data
otes follow
Acquisition VIs use this device alias to determine which device performs DAQ operations.
ns. MAX also displays
rations. ays the attributes
isplays attri
attr of the device such as the system
resources that the device uses. Figure 6-7 shows the PCI-6225 device.

Figure 6-7. MAX with Device


ce and
nd Interfac
Interfa
Interfaces Expanded
xpanded
anded
Di trus

1
l In
No na
tio
Na
t

1 Make sure the device you use is named


ed D
Dev 1. To rename a device, right-click the device and select Rename from the shortcut menu. You use Dev 1 in
Exercise 6-4.
Tip The Show Help/Hide Help button in the top right corner of MAX is available for certain items.
ms. Click
Clic the Show Help/Hide Help button to hide online

tio s
help or show the DAQ device information.

ibu nt
ternal
3. Select the Device Routes tab at the bottom of MAX to see detailed information about the internal nal signals that can be routed to other destinations on the device,
as shown in Figure 6-8. This is a powerful resource that gives you a visual representation of the signals tthat aree availa
vaila to provide timing and synchronization
available
with components that are on the device and other external devices.

n
str me
Figure 6-8. Device Routes
utes

Di tru
Ins
No
N

LabVIEW Core 1 Exercises National Instruments | 6-15

Lesson 6 Managing File and Hardware Resources ni.com | 6-16

4. Select the Calibration tab, as shown in Figure 6-9, to see information about the last time the device
ce was calibrated
ca
calib
lib both internally and externally.
ts

Figure 6-9. Calibration


en
um
str
t fo l In
No na
r
tio

5. If you are using a physical device, right-click


lick
ck the NI-DAQmx
NI-DA device
evice
vice in the co
configuration tree and select Self-Calibrate to update the built-in calibration constants
and calibrate the DAQ device using a precision voltage reference
cision volta erenc source.
urce. Complete the steps in the dialog that appears. When the device has been calibrated,
ource.
update
updat Skipp this
information in the Self-Calibration section updates. his step if you are using a simulated device.
Na
Testing the DAQ Device Components

uti ts
1. Click the Self-Test button in MAX to test the device. The actions in the Test Panels dialog boxx test
est the system
syste resources assigned to the device. The device
should pass the test because it is already configured.

rib en
alog input and
2. Click the Test Panels button to test the individual functions of the DAQ device, such as analog a output.
tput. The Test
T Panels dialog box appears.

on
Use the Analog Input tab to test the various analog input channels on the DAQ device.
ice. Click the
t Analog
g Input tab
alog ta
tab. Click the Start button to acquire data
men
nting
ting with the
from analog input channel 0 and click the Stop button when you finish experimenting tth settings
ings on the tab.
tab
ta

ist um
If you are using the BNC-2120, make sure the switch over the AI 0 connector
ctor is in the
nnector mp.. Ref. position
th Temp. posit
positio to connect the temperature sensor to ai0.
Place your finger on the sensor to see the voltage rise.

If you are using a simulated device, a sine wave is shown on all input channels.
nput channels

r D str
Use the Analog Output tab to set up a single voltage or sine wave
ve on one of th
the DAQ
Q device analo
analog output channels. Click the Analog Output tab.

Select Sinewave Generation in the Mode drop-down menu


enu and click the rt button. MA
t Start MAX generates a continuous sine wave on analog output

t fo l In
channel 0.

ne wave that channel


If you have hardware installed, you can read the sine ch
c 0 outputs. On the BNC-2120, wire Analog Out Ch0 to Analog In Ch1. Click
the Analog Input tab in the Test Panels dialog box x and sselect Dev1/ai1
ai11 from the Channel
C Name drop-down menu. Click the Start button to acquire
data from analog input channel 1. MAX displays
No na wave from
ys the sine wa m analog output
outpu channel 0.
outp

Use the Digital I/O tab to test the digital lines on the DAQ dde
device. Click
k the Digital
Digi I/O tab.
Digit

In the Select Direction section, set lines


es 0 through 3 as
a output
put as shown
sh in Figure 6-10.
tio
Figure
F e 6-10. Digital I/O Line Direction
Na

LabVIEW Core 1 Exercises National Instruments | 6-17

Lesson 6 Managing File and Hardware Resources ni.com | 6-18

Click Start to begin the digital output test, then toggle the switches in the Select State section
tion
n shown in Figure 6-11. If you have a BNC-2120, toggling
uti ts
the switches turns the LEDs on or off. Notice that the LEDs use negative logic.
Figure 6-11. Digital I/O Switches
hes
rib en
on
ist um

Click Stop to stop the digital output test.

Use the Counter I/O tab to determine if the DAQ device counter/timerss aree functioning
functionin
functioni properly.
perly.
y. Click the
th Counter I/O tab.

erify
ify counter
If you have hardware installed, click the Counter I/O tab. To verify counter/ti peration, selec
counter/timer operation, select Edge Counting from the Mode drop-down menu
r D str

ements
ents rapidly.
and click the Start button. The Counter Value indicator increments rapidly Click
k Stop to stop the
t counter test.

Click the Close button to close the Test Panel dialog box and return
urn to MAX.
MAX
t fo l In

End of Exercise 6-3


No na
tio
Na
Exercise 6-4 Using DAQmx

uti ts
Goal
Explore a DAQmx example program that continuously acquires data, and modify it to wait on a digital
gital trigge
trigg
trigger.

rib en
Scenario

on
Explore a DAQmx example program that continuously acquires a voltage signal on channel nel analog input
inp 1 (AI1)
AI1)) of a DAQ device. Modify the VI to use a digital
trigger. The VI begins measuring when the user sends a digital trigger to the device. In thiss exercise, the user
er sends a trig
trigg
trigger by turning the Quadrature Encoder

ist um
knob on the BNC-2120. The VI stops measuring when the user clicks the Stop button n onn the front panel off the VI.

Implementation
External Connections

r D str
1. If you are using the BNC-2120, connect the Sine/Triangle output on the he function generator
ge or to channel AI
A 1 with a BNC cable, and make sure the switch on the
function generator is set to the sine wave. Also, ensure that there is a wire
re connecti
connect
connecting the UP/DN screw terminal to the PFI 1 screw terminal in the Timing I/O
section.

t fo l In
Note The UP/DN terminal on the BNC-2120 outputs a high igh or a low signal
s indicating
icating the rotation direction of the Quadrature Encoder knob. When
you rotate the Quadrature Encoder knob clockwise, the
he UP/DN DN terminal
term outputs a high ssignal. When you rotate the Quadrature Encoder knob
counterclockwise, the UP/DN terminal outputs a low signal.
ignal. IIn this exercise,
e, this signal ttriggers the VI to start acquiring data.
ise,

Open and Run a DAQmx Example


No na
rt the
1. In LabVIEW, select HelpFind Examples to start he NI Examp nder.
Example Finder.

Note If you cannot locate this DAQmx example


exammple
mple in the NI Example
xample
mple Finder,
Finder
Finde you
yo can also open the VI from the <Exercises>\LabVIEW Core 1\
tio
Using DAQmx directory and skip to step
epp 5.

2. Confirm that you are browsing according


ng to
o task.
Na

3. Navigate to Hardware Input and OutputDAQmxAnalog


OutputDAQ
OutputDAQm Input.
og Input.
nalog

4. Double-click Voltage-Continuous
us Input.vi to open the
he example program.
pr
p This VI demonstrates how to acquire a continuous amount of data from a DAQ device.

5. Select FileSave As to save the VI as <Exercises>\LabVIEW


Ex es>\LabVI
es>\LabVIE Core 1\Triggered Analog Input\Trigger AI Acquisition.vi. When
prompted, select Copy - Substitute copy for original.
l

LabVIEW Core 1 Exercises National Instruments | 6-19

Lesson 6 Managing File and Hardware Resources ni.com | 6-20

6. Open and explore the block diagram as shown in Figure 6-12.


uti ts

Figure 6-12. Block Diagram of Original Voltage - Continuous


ntinuous Input
Inp VI
rib en

3
on
ist um

1
r D str

1 DAQmx Create Channel VIClick the pull-down menu and notice it is set to Analog InputVoltage.
InputVolta
t fo l In

2 Press <Ctrl-H> to open the Context Help window. Hover over each of the DAQmx functions
ctions to llearn about each function.
3 Property NodeGets or sets properties for a reference. You will learn
earn about
a Property Nodes later.

7. Set the default values and settings on the front panel.


No na

Select Dev1\ai1 from the Physical Channel control.


ntrol.
ol.

Set Max Voltage to 1.

Set Min Voltage to -1.


tio

8. Run the VI. The VI should begin acquiring


ing continuously.
g data contin

Use the Frequency Selection switch


witch and the F
Frequency Adju knob on the BNC-2120 to change the frequency of the generated and acquired signal.
ncyy Adjust
Na

9. Click the Stop button to stop the VI.


Add Triggering to the Example Program

uti ts
1. Modify the block diagram as shown in Figure 6-13 to add trigger functionality. After you modify
ify this VI, the VI waits for a trigger before acquiring data.

Figure 6-13. Trigger AI Acquisition VI Block


ck Diagram
Diagra

rib en
on
3

ist um
r D str
2 1

t fo l In
1 DAQmx Trigger VIPlace to the right of the DAQmx Configurere Logging VI.
VI Delete the
he ta
task
sk out and error out wires from the DAQmx Configure Logging VI
and then wire them through the DAQmx Trigger VI to the DAQmxx Start Task
Ta VI.
2 Configure the triggerClick the DAQmx Trigger VI pull-down menu and
wn m nd select StartDigita
StartDigital Edge.
3 Create controlsRight-click the source input and the edge
ge input of the DAQmx VI and select CreateControl.
Qmx Trigger V
4 Free labelCreate a label and enter Trigger Settings
s.
No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 6-21

Lesson 6 Managing File and Hardware Resources ni.com | 6-22

2. Modify the front panel and set the default settings as shown in Figure 6-14.
uti ts

Figure 6-14. Trigger AI Acquisition VI Front


ont Panel
rib en

2 3 4 1
on
ist um
r D str
t fo l In
No na

1 Move the Acquired Data groupSelect all the items


ms in the Acquired
A Data group and shift them to the right. <Shift>-click to select multiple items and press
<Shift-arrow key> to move them.
tio

2 Create Trigger Settings groupCopy a container


tainer from another
an group, label the copy Trigger Settings, and place the edge and source controls in it.
3 Select Rising in the edge control.
4 Select Dev1/PFI1 in the source control.
Na

3. Save the VI.


ree Encoder kn
4. Run the VI. Turn the Quadrature kknob on the BNC-212
BNC-2120 counterclockwise then clockwise to begin the acquisition.
5. Stop and close the VI.

End of Exercise 6-4


Exercise 6-5 Concept: GPIB Configuration with MAX

uti ts
Goal
Learn to configure the NI Instrument Simulator and use MAX to examine the GPIB interface settings,
ettings,
ngs, detect instruments,
men and communicate with an instrument.

rib en
Description

on
1. Configure the NI Instrument Simulator.

ist um
Power off the NI Instrument Simulator.
Set the configuration switch on the rear panel to CFG, as shown in Figure
ure 6-15.

Figure 6-15. NI Instrume


Instrumen
Instrument Simulator
ulator

r D str
t fo l In
Power on the NI Instrument Simulator using the power
No na ower
er switch
switch on the front
ont of the unit.
unit

Verify that the PWR LED is lit and the RDY LED
D is flashing
flashing.

Launch the NI Instrument Simulator Wizardd from


om StartAll
StartA ProgramsNational
ogramsNa
ams InstrumentsInstrument SimulatorInstrument Simulator Wizard.
tio
Click Next.

Click Next.

On the Select Interface page, select


Na

elect GPIB Int


Interfacee and
In d click Next.
N

Select Change GPIB Settings


gs and click Next.
N

Select Single Instrument Mode and


nd click
c xt..
Next.
xt

LabVIEW Core 1 Exercises National Instruments | 6-23

Lesson 6 Managing File and Hardware Resources ni.com | 6-24

Set GPIB Primary Address to 1.


uti ts

Set GPIB Secondary Address to 0(disabled).

Click Next.
rib en

Click Update.
on

Click OK when you get the message that the update was successful.
ist um

Power off the NI Instrument Simulator using the power switch on the frontt of the unit.
Set the configuration switch on the rear panel to NORM.
r D str

Power on the NI Instrument Simulator using the power switch on the


he front of the unit.

Verify that both the PWR and RDY LEDs are lit.

selectin ToolsMeasurement
2. Launch MAX by either double-clicking the icon on the desktop or by selecting lsMeasureme
Measurem & Automation Explorer in LabVIEW.
t fo l In

3. View the settings for the GPIB interface.

Expand the Devices and Interfaces section to display


lay the installed
install interfaces.
faces. If a GPI
GPIB interface is listed, the NI-488.2 software is correctly loaded on the
computer.
No na

Select the GPIB interface.

Examine but do not change the settings for


or thee GPIB interface.
int
tio

4. Communicate with the GPIB instrument.

Make sure the GPIB interface is still


till selected in the
t Devices
vices
ice and
d Interfaces
Inte
Int section.
Na

Click the Scan for Instruments


ts button on the
th toolbar.
bar.

Expand the GPIB interface selected


ected in th
the Devices
ces
es and Interfaces
Interf section. An instrument named Instrument Simulator appears.
Click Instrument Simulator to display information about it in the right pane of MAX. Clickk the Attributes
A tab. Notice the NI Instrument Simulator

uti ts
has a GPIB primary address.

Click the Communicate with Instrument button on the toolbar. An interactive window
w appears.
ppears. You can use it to query, write to, and read from that

rib en
instrument.

Enter *IDN? in the Send String text box and click the Query button. The instrument

on
ment returns
eturns it
its make and model num
number in the String Received indicator
ument
nt problems
as shown in Figure 6-16. You can use this communicator window to debug instrument problem or to verify
ify that spe
specific commands work as described in the

ist um
instrument documentation.

Figure 6-16. Communication


n with
ith the GPIB
GP
G instrument
trument
umen

r D str
t fo l In
No na
tio
Enter MEASURE:VOLTAGE:DC? in thee Send String text box
ox and click the
t Query button. The NI Instrument Simulator returns a simulated voltage
measurement.

Click the Query button again to return


rn a different
differe value.
ue.
Na

Click the Exit button when done.


one.

LabVIEW Core 1 Exercises National Instruments | 6-25

Lesson 6 Managing File and Hardware Resources ni.com | 6-26

5. Set a VISA alias of devsim for the NI Instrument Simulator so you can use the alias instead of having
aving
ng to remember
rem the primary address.
uti ts

While Instrument Simulator is selected in MAX, click the VISA Properties tab.

Enter devsim in the VISA Alias on My System field. You use this alias later in the course.
rib en

rse.

Click Save.
on

6. Select FileExit to exit MAX.


ist um

7. Click Yes if prompted to save the instrument.

End of Exercise 6-5


r D str
t fo l In
No na
tio
Na
Exercise 6-6 Concept: NI Devsim VI

uti ts
Goal
Install an instrument driver and explore the example programs that accompany the instrument driver.
er.

rib en
Description

on
Install the instrument driver for the NI Instrument Simulator. After installation, explore thee VIs
Is that the instrument
i mentt driver provides
pprov
ro and the example programs that are
added to the NI Example Finder.

ist um
Figure 6-17. NI Instrument
trument
ment Simu
Simulator

r D str
t fo l In
Install Instrument Driver and Open ProjectDownload from Internet nternet
ro
If you have internet access and have, or want to create, a user profile on ni.c
ni.com, complete
omplete the following
foll steps. Otherwise, install the driver from the course CD
following the instructions in the Install Instrument Driver andd Open ProjectExtract
P act from Diskk section.
ract

1. Select HelpFind Instrument Drivers.


No na
2. Click the Login button.

3. If you have an ni.com profile, log in with your


our ID.
D.
tio
4. If you do not have an ni.com profile, follow
low
w the onscreen
onscree instructions
ructions
uctions to create
crea one at this time. Be sure to make a note of the user ID and password you create.
cre

5. After you log in, click the Scan for Instruments


uments button.
struments bu
but If you hhave instrument connected, clicking this button detects the instrument and finds the correct
vee an iin
driver. In this case, it detects the Instrument
rument Simulator.
trument Simula
Simu
Na

6. Double-click Instrument Simulator


ator in the lis
list and click
ick the Search
Sear button.

7. Select Version 2.0 of the instrument driver


river from the
he Driver list.
lis

LabVIEW Core 1 Exercises National Instruments | 6-27

Lesson 6 Managing File and Hardware Resources ni.com | 6-28

8. Click the Install button.


uti ts

9. Click the Start using this driver button.


rib en

10. Click the Open Project button.

11. Expand the Examples folder in the LabVIEW Project window.


on

12. Close the NI Instrument Driver Finder window and go to the Explore Instrument Driver
verr section to
t continue
inue this exercise.
exerc
exe
ist um

Install Instrument Driver and Open ProjectExtract from Disk


If you do not have Internet access or do not want to create a user profile, complete
te the
he following
followin stepss to install the instrument driver.
followin

iver directory.
1. Navigate to the <Exercises>\LabVIEW Core 1\Instrument Driver
river directo This
director is folder contains
contai a zip file with the LabVIEW Plug and Play
r D str

instrument drivers for the Instrument Simulator.

he <Program
2. Right-click the zip file and follow the wizard to extract all files to the <Progra Files>\National
es>\Nation
>\Nation Instruments\LabVIEW 2012\instr.lib
directory.
t fo l In

.lvproj in the <Program


3. Open National Instruments Instrument Simulator.lvproj rogram F
Files>\National Instruments\LabVIEW 2012\
Si tor directory.
instr.lib\National Instruments Instrument Simulator tor
tory.

4. Expand the Examples folder in the LabVIEW Projectt window.


indow.
No na

5. Go to the Explore Instrument Driver section to continue


tinue exercise.
ue this exerc
exer

Explore Instrument Driver


tio

1. Open National Instruments Instrument Simulator


imula
mul tor Acquire
Acqu Single
Acq ingle Measurement(DMM).vi
Measure from the Examples folder in the Project Explorer window of
ulator
ator project.
the National Instruments Instrument Simulator
om the Instrum
This VI reads a single measurement from mula
Instrument Simulator.
Na

2. Verify that the PWR and RDY LEDs


Ds are lit on the
th Instrument
ment Simulator.
ument Simul
Simula

3. Select devsim from the VISA Resource


source Nam trol
Name control fron panel. You specified the VISA alias for this GPIB instrument as devsim in step 5 of
ol on the front
ratio with MAX
ration
Exercise 6-5, Concept: GPIB Configuration MAX.
X.

4. Run the VI.


5. Open the block diagram of the VI.

uti ts
6. Open the Functions palette and navigate to the Instrument I/OInstrument DriversNational nstrumen Instrument Simulator palette.
al Instruments
Instrumen

rib en
7. Explore the palette and subpalettes using the Context Help window to familiarize yourselff with
th the func ity of functions on the palette.
functionality

8. Stop and close the VI. Do not save changes.

on
vi from the pro
9. Open National Instruments Instrument Simulator Acquire Waveform(Scope).vi pr
project. This VI reads a single waveform from the Instrument

ist um
Simulator.

10. Select the same VISA resource name you selected in step 3.

11. Run the VI.

r D str
12. Select a different function from the Waveform Function control.

13. Run the VI again.

t fo l In
14. Explore the block diagram of the VI.

To familiarize yourself with the VIs functionality, explore


xplore
plore the
th blockk diagram
ram
am using the Context
C Help window.

Double-click the Read Waveform VI to open it.


No na
Open to the block diagram of the Read Waveform
form
m VI. Notice
Notic that it uses
us VISA functions
ffu to communicate with the instrument.

15. Close the VIs and project when you are finished. save changes.
ed. Do not sav nges.
tio
End of Exercise 6-6
Na

LabVIEW Core 1 Exercises National Instruments | 6-29


uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
7

uti ts
Using Sequential and State Machine Algorithms
Algorithm
gorith s

rib en
on
ist um
Complete the exercise in this lesson to reinforce the concepts you learn in Lesson 7 of LabVIEW
bVIEW Co
Core 1.

Exercises
Exercise 7-1 State Machine VI

r D str
t fo l In
No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 7-1


uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
Exercise 7-1 State Machine VI

uti ts
Goal
Create a VI that implements a state machine using a type-defined enum.

rib en
Scenario

on
You must design a VI for a user interface state machine. The VI acquires a temperature every very
y half second,
secon analyzes
alyzeses each tem
temperature to determine if the temperature
is too high or too low, and alerts the user if there is a danger of heatstroke or freeze. Thee program
ogram logs the data
ata if a warning
warnin occurs. If the user has not clicked the stop

ist um
button, the entire process repeats. The state machine must also allow for expansion, because ause processes
proces
proce ay
mayy be added in the future.

Design
Use the following flowchart and states list to create the VI in this exercise.

r D str
t fo l In
No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 7-3

Lesson 7 Using Sequential and State Machine Algorithms ni.com | 7-4

Flow Chart
uti ts
The flowchart in Figure 7-1 illustrates the data flow for this design.

Figure 7-1. Temperature Warnings VII Flowchart


owchart
rib en
on
ist um

Initialize

Acquistion
r D str

Time Elapsed
psed = TRUE
and
and
t fo l In

S top = FALSE
Stop FALS

Warning
g = TRUE
Analysis

Data
a log
No na

Time Elapsed = FALSE


and
Stop = FALSE
tio

Time
Check
Warning = FAL
FALSE
SE

Stop = TRUE
Na
State Transitions

uti ts
The following table describes the states in this state machine.

State Description Next State

rib en
Acquisition Set time to zero, acquire data from the temperature sensor
or Analysis
A

on
Analysis Read front panel controls and determine warning level
vel Data Log
og if a warning
war occurs

ist um
ime Check if no warning occurs
Time

Data Log Log the data in a tab-delimited ASCII file Time Check

Time Check Check whether time is greater than or equall to .5 seconds


seco Acquisi
Acquisition if time has elapsed
Check if time has not elapsed
Time C

r D str
t fo l In
No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 7-5

Lesson 7 Using Sequential and State Machine Algorithms ni.com | 7-6

Implementation
uti ts

1. Open Weather Station.lvproj in the <Exercises>\LabVIEW Core 1\Weather Station


ation dire
directory.
dire

2. Open Weather Station UI.vi from the Project Explorer window.


rib en

Figure 7-2 shows the front panel of the Weather Station UI VI that has been provided for you. modify the block diag
ou. You m diagram to create a state machine for the
on

Weather Station.
ist um

Figure 7-2. Weather Station UII VII Front Pan


Panel Window
ndow
dow
r D str
t fo In
tio
Na
No
Figure 7-3 shows the starting point of the block diagram for the Weather Station UI VI. You edit this
is block
lock diag
diagram to implement a state machine for the Weather

uti ts
Station application.
Figure 7-3. Weather Station UI VI Block Diagram
iagram
ram Starting
Startin

rib en
on
1

ist um
r D str
t fo l In
1 You use these controls and indicators to program differentt cases.
No na
3. Create a new type definition to control the Weather Station
ation applica
application.

Open the block diagram and create an Enum


m constant
nstant to th
the left of the
he W
While
Wh L Loop.

Type Acquisition in the constant.


tio

Right-click the constant and select Editt Items from the shortcut
ortcut
tcut menu.
Na

LabVIEW Core 1 Exercises National Instruments | 7-7

Lesson 7 Using Sequential and State Machine Algorithms ni.com | 7-8

Add the items shown in Figure 7-4 and click OK.


bu nts

Figure 7-4. Weather Station States Type


ype
e Def
n
e
tio
um
str
t fo l In
No na
r
tio

Right-click the enum constant on the block


ck diagram and
a select
lect
ect Make Type
Typ Def.
Ty

4. Modify the new type definition and add Weather Station


d it to the Wea
Weat atio project.
oject.
Na

Right-click the enum constant and


nd select Open f.
Ope Typee Def
Def.

Change the label on the Enum


m control to States
s.
es

Save the type definition as Weather Station


on States.ctl
States in the <Exercises>\LabVIEW Core 1\Weather Station\Supporting Files
directory.
Close the control editor window.

uti ts
In the Project Explorer window, notice that Weather Station States.ctl has been added to your Supporting
Suppo Files folder because that folder is an
auto-populating folder.

rib en
wn in Figure 7-5.
5. Control the state machine with the type-defined enum and update the framework as shown 77-

on
Figure 7-5. Weather Station UII VI Block Diagram
Diag

ist um
5

r D str
1 3

t fo l In
1
No na
Shift RegisterRight-click the While Loop and select Add Shift Register.
2 Enum type definition constantRight-click and select Visible
ct V ible ItemsLabel.
bel Change
ange the label to Beginning State. Wire the Beginning State constant to the
quisition state.
shift register to initialize the shift register to the Acquisition sta Wire the
he shift
s register to the case selector of the Case Structure.
3 ture and selec
Add more casesRight-click the Case structure se For Eve
select Add Case Every Value to create different cases for each value in the enum.
tio
4 Weather Data InDrag Weather Data.ctl from
m the Project
Pro Explorer window to the block diagram to create a type definition cluster constant. Right-click the
xplorer windo
cluster and select View Cluster As Icon.
5 Shift RegisterPlace a shift register on the While Loop and
dw eW
wire the Weather Data In constant to it.
Na

Note After you finish wiring


g the Acquisiti
Acquisitio
Acquisition casee inn step 6, som
ssome
om tunnels are empty because not all cases are wired yet.

LabVIEW Core 1 Exercises National Instruments | 7-9

Lesson 7 Using Sequential and State Machine Algorithms ni.com | 7-10

6. Complete the Acquisition state shown in Figure 7-6.


uti ts

Figure 7-6. Weather Station UI VI Acquisition


ition
on State
Stat

1 2 3 4
rib en
on
ist um
r D str
t fo l In
No na

5
tio

1 Thermometer or Thermometer (Demo)Drag Drag one of th


these VIs
Is from the S
Shared Files folder in the Project Explorer window to the block diagram. Drag the
Thermometer VI if you have hardware and drag the T ter (Demo) VI
Thermometer V if you do not have hardware.
2 Temperature HistoryMove this indictorr into the Acquisition
A th Case structure.
state of the
3 erature Value output of the Ther
Bundle By NameWire the Temperature Thermometer VI to the Current Temperature input.
Na

4 e Beginning S
Next State enum<Ctrl>-click the m and drag a copy into the Acquisition case. Rename this copy of the Weather Station States type
State enum
definition Next State. Set the enum to Analysis
An and wire it through
thr a tunnel on the Case structure to the shift register on the While Loop.
5 True ConstantCreate a True constantstant and
a wire e it through the Case structure to the Elapsed Time shift register. The True constant resets the Elapsed Time
counter every time the VI executes the Ac n case.
Acquisition
7. Complete the Analysis case as shown in Figure 7-7.

uti ts
Figure 7-7. Weather Station UI VIAnalysis
ysis
s Case

1 2 3 4 7 5

rib en
on
ist um
r D str
6

t fo l In
No na
1 Upper Limit and Lower LimitMove these controlss from outside
out the Whil
While Loop.
2 Bundle By NameReplaces the Max Temperature erature and M rature item
Min Temperature items with the values from the Upper Limit and Lower Limit controls. The Bundle
tio
By Name function makes it possible to wire the Upper Limit
Lim and Lower Limit va
values to the Weather Data In input of the Temperature Warnings VI.
3 Temperature WarningsDrag the Temperature
erature Warnings
Wa VI from the Supporting
Sup Files folder in the Project Explorer window.
4 Unbundle By NameReturns the value of specific items from the cluster.
cluste
5 SelectDetermines which state to execute next depending
g on whether
whe or not a warning occurs.
Na

6 Weather Station StatesWire two


o copies of the Weather Station States
Sta type definition to the Select function. You can create these copies from the Beginning
State enum.
6 WarningMove this indicator from outsid
outside the While
hile Loop.

LabVIEW Core 1 Exercises National Instruments | 7-11

Lesson 7 Using Sequential and State Machine Algorithms ni.com | 7-12

8. Complete the Data Log case as shown in Figure 7-8.


uti ts

Figure 7-8. Weather Station UI VIData Log


og Case
Cas

1 2 3 4
rib en
on
ist um
r D str
t fo l In

5 6
No na

1 Unbundle By NameReturns the value of specific items


ems from the
t cluster.
2 Tab ConstantInserts a tab in the string. The log file
le you create
cre contains
ns tabs between
et values.
3 End of Line ConstantInserts a platform-specific end-of-line value at the end of the string. The log file you create uses the End of Line constant to insert line
fic end-of-l
tio

breaks between data.


4 Format Into StringExpand the node to accept eight inputs.
5 Write to Text FileWrites the text that you
ou formatted
formatte into a log file.
e
6 Next StateCreate a copy of the Weather
eather Station States enum,
num, llabel it Next State, and set the next state to Time Check.
Na
9. Complete the Time Check case as shown in Figure 7-9.

uti ts
Figure 7-9. Weather Station UI VITime Check
eck Case

1 2 4

rib en
on
um
str
t fo l In
No na
r
tio
3 5

1 Next StateWire two copies of the Weather


er Station States
St type
e definition to the Select function.
2 SelectDetermines which state to execute
te next depending
dep on whether
ether or not time has elapsed.
3 Stop ButtonMove the Stop Button
on terminal from outside
erminal fro While Loop. Wire the Stop Button terminal to the Or function outside of the Case structure.
e the W
Na

4 Next State wireWire the tunnel for the Next S


State wire to
o the shift register.
r
5 Use default if unwiredRight-click
ck these tunn
tunnels and Use
d select U se Default If Unwired.

10. Save and test the VI.

LabVIEW Core 1 Exercises National Instruments | 7-13

Lesson 7 Using Sequential and State Machine Algorithms ni.com | 7-14

Test
uti ts

1. Run the VI.

Name the log file when prompted.


rib en

Enter values for the Upper Limit and Lower Limit controls and observe the behavior
vior of the VI.
V Does it behave
ehave as ex
eexpected?
on

2. Stop the VI.


ist um

3. Navigate to the Weather Warning Log.txt file and open it.

4. Notice the changes in the upper and lower limit values and the placement off tabs
abs and line breaks.
s.
r D str

5. Close the log file.

6. Save and close the VI and the project.

End of Exercise 7-1


t fo l In
No na
tio
Na
8

uti ts
Solving Dataflow Challenges Using Variables
riables
ables

rib en
on
ist um
Complete the exercise in this lesson to reinforce the concepts you learn in Lesson 8 of LabVIEW
bVIEW Co
Core 1.

Exercises
Exercise 8-1 Weather Station UI VI with Local Variables

r D str
t fo l In
No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 8-1


uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
Exercise 8-1 Weather Station UI VI with Local Variables

uti ts
Goal
Use a local variable to write to and read from a control.

rib en
Scenario

on
You have a LabVIEW project that implements a temperature weather station. The weather er station
tation acqu
acquires a temperature
mperature ev
eevery half a second, analyzes each
temperature to determine if the temperature is too high or too low, then alerts the user iff there
ere is a dan
danger of a heat stroke or
o freeze. The VI logs the data if a warning

ist um
occurs.

nd the
Two front panel controls determine the setpointsthe temperature upper limit and he temperat werr limit. How
temperature lower However, nothing prevents the user from setting a
lower limit that is higher than the upper limit.

r D str
Use a local variable to set the lower limit less than the upper limit if the userr sets
ets a lower limit
l hat is higher th
that than the upper limit.

Design
Your task is to modify the VI you created in Exercise 7-1 so that the lower
ower
er limit is sset less than the uppe
upper limit when necessary.

t fo l In
State Definitions
The following table describes the states in the state machine.

State Description Next State


No na
Acquisition Set time to zero, acquire data from the temper
temperature sensor Analysis

Analysis Read front panel controls and determine w


warning level
el Data Log if a warning occurs, Time Check if no warning occurs
tio
Data Log Log the data in a tab-delimited
mited ASCII file Time Check
Time Check Check whether time is greater
reater than or equal to .5 seconds
secon Acquisition if time has elapsed, Time Check if time has not elapsed
Na

rature
ature limit con
Changing the value of the lower temperature hould
control shouldld happen after the user has entered the value but before the value determines the warning level.
Therefore, make the modifications to the VI in the A itionn or Analys
Acquisition Analysis state, or place a new state between the two.

LabVIEW Core 1 Exercises National Instruments | 8-3

Lesson 8 Solving Dataflow Challenges Using Variables ni.com | 8-4

Before determining which option to use, review the content of the Acquisition and Analysis states:
uti ts

Open Weather Station.lvproj in the <Exercises>\LabVIEW Core 1\Weather


er Station directory.

Open Weather Station UI.vi from the Project Explorer window.


rib en

Review the contents of the Acquisition and Analysis states, which correspond to the
he Acquisition
cquisitio and Analysis
ysis cases oof the Case structure.
on

Design Options
ist um

You have three different design options for modifying this project.

Option Description Benefits/Drawbacks


r D str

1 Insert a Case structure in the Acquisition state to reset


set the Poor design: the ac
acquisition state has another task added, rather than
controls before a local variable writes the values to the cluster.
cluster focusing
cusing only on acquisition.

2 Insert a new state in the state machine that checks


ks the controls
cont Ability
bility to control
con when the state occurs.
and resets them if necessary.
t fo l In

3 Modify the Determine Warnings subVI to reset


eset the co
controls. Easy to implement because functionality is already partially in place.
How
However, if current functionality is used, one set of data always is lost
when resetting the lower limit control.
whe
No na

This exercise implements Option 2 as a solution.


tio
Na
New State Definitions for Option 2

uti ts
le 8-1 describes
Read the upper and lower limit controls in the Range Check state, instead of the Analysis state. Table describe the states in the new state machine. You have
already implemented the Acquisition, Analysis, Data Log, and Time Check states. In this exercise, e, you
ou add the Range
R Check state. The VI reads the Upper Limit
and Lower Limit controls in the Range Check state, instead of the Analysis state. The Range Checkheck
ck state also resets the Lower Limit control lower than the upper

rib en
limit if the Upper Limit control is less than the lower limit.

on
Table 8-1. State Descriptions
ns for Option 2
State Description Next State

ist um
Acquisition Acquire data from the temperature sensor on
n channel A
AI0 Range Check
and read front panel controls

Range Check Read front panel controls and set the lower
ower limit to 1 less Analysis

r D str
than the upper limit if the upper limit
mit is less than
th the lower
ower
limit

Analysis Determine warning level Data Log if a warning occurs

t fo l In
Time Check if no warning occurs

Data Log Log the data in a tab-delimited


b-de ed ASCII
AS file
le Time Check

Time Check No na Check whether timee is greater than orr equal to .5 seconds
se Acquisition if time has elapsed
Time Check if time has not elapsed
tio
Na

LabVIEW Core 1 Exercises National Instruments | 8-5

Lesson 8 Solving Dataflow Challenges Using Variables ni.com | 8-6

Implementation
uti ts

1. If the Weather Station.lvproj is not already open, open it from the <Exercises>\LabVIEW
VIEW Core 1\Weather Station directory.
abVIEW

2. Add the Range Check state to the state machine.


rib en

Open Weather Station States.ctl from the Project Explorer window.


on

Right-click the States control and select Edit Items from the shortcut menu.
ist um

Insert an item and modify the item to match Table 8-2. Be careful not to add
dd ann empty lis
listing.

Table 8-2. States


s Enumerated
numerated Control
rol
r D str

Item Digital Display

Acquisition 0
Range Check 1
t fo l In

Analysis 2

Data Log 3
Time Check 4
No na

Save and close the control.

Open Weather Station UI.vi from the Project Explore window.


roject Explorer dow.
w.
tio

On the block diagram of the Weather Station UI VI,


VI right-click
click
lick the state machine Case structure and select Add Case for Every Value from the shortcut
menu. Because the enumerated control
trol has a new value, a new aappears in the Case structure.
w case app
Na
3. Set the Next State enum in the Acquisition case to Range Check as shown in Figure 8-1.

ts
Figure 8-1. Weather Station UI VI with Local VariablesCompleted
Completed
mpleted Acquisition
Acq State

en
um
str
t fo l In
No na
r
tio
Na

LabVIEW Core 1 Exercises National Instruments | 8-7

Lesson 8 Solving Dataflow Challenges Using Variables ni.com | 8-8

4. Modify the Analysis case as shown in Figure 8-2.


tio s
Figure 8-2. Weather Station UI VI with Local VariablesCompleted
Completed
ompleted Analysis
An State
t

1
en
n
um

2
str
t fo l In
No na
r

1 Delete the Bundle By Name function and wire


re the Weath
Weather Data wire
e directly to the Temperature Warnings VI. Press <Ctrl-B> to delete the broken wires from
tio

the Upper Limit and Lower Limit controls.


2 Move the Upper Limit and Lower Limit controls outside the While
ontrols outs hile Loop.
Na
5. Complete the Range Check True state as shown in Figure 8-3.

uti ts
When the Upper Limit control value is less than or equal to the Lower Limit control value, use a local variab
variable to write the value, upper limit - 1, to the Lower
Limit control.
Figure 8-3. Weather Station UI VI with Local VariablesRange
esRange
Range Ch
C
Check True Case

rib en
1

on
ist um
r D str
2

t fo l In 3 4 5 6 7
No na
tio
1 Case StructurePlace a Case structure inside
nside the Ran
Range Check
eck case.
2 ontrols into the Range Check case.
Move the Upper Limit and Lower Limit controls ca
3 Less or Equal?Compares upper limit and lo wer limit values.
lower ues. Because
se the Less or Equal? function is wired to the case selector of the inner Case structure,
Na

when the upper limit is less than or equal to the lower


lo limit, the True case executes.
4 DecrementSubtracts 1 from the
e value of the Upperr Limit control
contro so the True case writes a lower value to the Lower Limit control.
5 -click the L
Lower Limit local variableRight-click mit control and
Lower Limit a select CreateLocal Variable. Place the local variable in the True case.
6 wo elements
Bundle by NameExpand to display two nts and use the
t Operating tool to select the correct cluster elements.
7 Next StateCreate a copy of the Weather Station States
ates type
t def control and set the next state to Analysis.

LabVIEW Core 1 Exercises National Instruments | 8-9

Lesson 8 Solving Dataflow Challenges Using Variables ni.com | 8-10

6. Create the Range Check False state as shown in Figure 8-4.


uti ts

If the Upper Limit control value is not less than or equal to the Lower Limit control value, the False executes and the values are passed, unchanged, through
se case exec
to the temperature cluster.
rib en

Figure 8-4. Weather Station UI VI with Local VariablesRange


blesRange
sRange Check
C False
se State
Sta
on
ist um
r D str
t fo l In
No na

7. Save the VI and the project.


tio
Na
Test

uti ts
1. Run the VI.

Enter a name for the log file when prompted.

rib en
Enter a value in the Upper Limit control that is less than the value in the Lower Limit
imitt control
control. D
Does the
he VI behave aas expected?

on
2. Stop the VI when you are finished.

ist um
3. Close the VI and the project.

End of Exercise 8-1

r D str
t fo l In
No na
tio
Na

LabVIEW Core 1 Exercises National Instruments | 8-11


uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na

Вам также может понравиться