Академический Документы
Профессиональный Документы
Культура Документы
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
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
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.
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
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
Lesson 6
r D str
Lesson 7
No na
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
t fo l In
Courses
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
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
An introduction that describes the purpose of the lesson and what you will learn
ist um
A summary quiz that tests and reinforces important concepts and skills taught lesson
ght in the lesso
r D str
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
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)
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
GPIB interface
A serial cable
A GPIB cable
uti ts
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
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
r D str
Create applications that use plug-in DAQ devices
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
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
F. Course Conventions
uti ts
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
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
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
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.
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
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.
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.
m r functi
7. Get detailed help and view examples for the Quotient & Remainder function.
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
2
rib en
o
ist um
1
r D str
3
5
t fo In
4
No n
tio
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
r D str
Delay less than 1 hour
t fo l In
10. Save and close the VI and the LabVIEW Project.
Goal
Learn to use the palettes and search for controls, functions, and VIs.
rib en
Description
on
Click the Create Project button in the LabVIEW Getting Started window andd then click Blank Project.
nk Project.
Click Finish.
r D str
rols palett
palet
palette and click
lick the
th OK
K bbutton. Do not deselect any palettes.
Silver
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.
t fo l In
Locate trigonometric functions.
Click the Search button.
No na
In the search results, double-click Cosine <<Trigonometric
<<Trigonomet
Trigonome ons>> to display
Functions>> d the function on the palette.
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
Double-click the function in the search results and place the function on the block
ock diagram.
ist um
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
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
on.
HelpBrings up the help topic for this function.
No na
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.
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
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.
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.
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.
6. Rename the Numeric control to Number of Measurements using the Labeling tool.
uti ts
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
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
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.
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 right of the terminal, stopping when the cursor changes to a wiring
rib en
ring spool.
on
ist um
Move the cursor to the count (N) terminal of the For Loop.
r D str
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
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.
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
18. Close the VI and click the Dont Save - All button. You do not need to save the VI.
I.
tio s
Goal
ibu nt
Understand how dataflow determines the execution order in a VI.
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.
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?
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
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
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
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
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.
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
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
2. Analyze: Circle the Express VI that is best suited to determining the average va
value of the acquired ddata.
t fo l In
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
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.
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-
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
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
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.
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
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
10. Enter 1000 in Rate (Hz). 10.. In the Timing section, select the Simulate acquisition timing option.
No na
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.
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.
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.
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.
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.
uti ts
1. Switch to the front panel window of the VI.
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.
r D str
4. Run the VI.
t fo l In
implementation steps.
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
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.
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.
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
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
Click the broken Run button to display the Errorr list window,
No na
window, w
which lists
ists all the eerr
errors.
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
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
uti ts
Identify and correct errors that cause the VI to behave unexpectedly and return incorrect responses.
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
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.
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?.
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.
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.
Right-click the output of the Square Root function and select BreakpointSet Breakpoint as shown
own in Figure
F 2-4.
uti ts
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.
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
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.
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.
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
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.
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
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.
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
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.
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
1 4 6
on
ist um
r D str
2 3 5
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
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.
r D str
5. Document the block diagram using owned labels and free labels.
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
5
rib en
2
4
on
ist um
1
r D str
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.
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
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.
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
Flowchart
uti ts
The flowchart in Figure 3-5 illustrates the data flow for this design.
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.
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
1
ist um
r D str
ts
en
ist um
r D str
r
t fo l In
No na
1 2
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
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.
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.
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
Change the Number to Match value to a number that is out of the data
ta range, 0 1000.
0.
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
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
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?
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
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
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.
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
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
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
Implementation
1. Test the VI.
tio
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
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
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 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.
Implementation
1. Open the Temperature Monitor VI you created in Exercise
rcisee 3-4.
No na
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
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
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.
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
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
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
Implementation
1. Open Weather Warnings.lvproj in the <Exercises>\LabVIEW
s> VIEW Core 1\Weathe Warnings directory.
e 1\Weather
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
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
n
e
tio
um
2
str
3
tri
t fo l In
No na
r
tio
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
Test
uti ts
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.
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
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
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
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:
r D str
Inputs Outputs
t fo l In
Min Temperature
Error In No na Error
ror Out
Implementation
1. Open Weather Warnings.lvproj in thee <Exercise Cor 1\Weather Warnings directory.
tio
<Exercises>\LabVIEW
<Exercis abVIEW
VIEW Core
3. Connect the inputs and outputs to the connector pane as shown in Figure 4-1.
uti ts
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.
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
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 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.
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
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.
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
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
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
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
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
7. Complete the Add/Subtract Channels case as shown in Figure 5-3 and Figure 5-4.
uti ts
1 2
No na
uti ts
rib en
1
on
ist um
1 When the value of the Subtract? Boolean control is False, the array elements are added.
r D str
8. Switch to the front panel and test the Add/Subtract Channels case.
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.
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
12. Switch to the front panel and test the Select Channel case.
ect a Chann
Channe
Na
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.
Change the value of the Offset control and notice the square wave move on the Waveform Data
ata chart.
uti ts
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
1
r D str
t fo l In
5
No na
tio
2 3 4
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.
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
2 1
rib en
on
ist um
4
r D str
t fo l In
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.
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.
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
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
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
3
n
str me
2
l
Di
No na
tio
Na
t
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.
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
2
r D str
t fo l In
No na
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
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
r D str
What should happen to the copies of the custom data types used in VIss that are aal
already saved?
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:
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.
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
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.
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.
he type definition.
5. Tie the Weather Data Out indicator to the defi
Na
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.
Right-click the border of the Weather Data In control and select Open Type Deff from the shortcut
sh menu.
nu.
ist um
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.
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
uti ts
1. Use the SubVI Tester VI to test the modified Temperature Warnings VI as subVIs.
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.
t fo l In
No na
tio
Na
1 3 2
rib en
on
ist um
r D str
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
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
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
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.
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
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
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
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.
specifies the phase of the sine pattern which generates the cosine pattern.
pattern
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.
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
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
1 3 2 4 5 6 7
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.
Challenge
uti ts
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.
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
t fo l In
Hint:
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
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.
1
l In
No na
tio
Na
t
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
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
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.
t fo l In
channel 0.
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
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
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
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,
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.
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.
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.
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
2. Modify the front panel and set the default settings as shown in Figure 6-14.
uti ts
2 3 4 1
on
ist um
r D str
t fo l In
No na
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.
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.
Click Next.
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
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
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.
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.
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
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
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
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
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
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
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.
r D str
12. Select a different function from the Waveform Function control.
t fo l In
14. Explore the block diagram of the VI.
15. Close the VIs and project when you are finished. save changes.
ed. Do not sav nges.
tio
End of Exercise 6-6
Na
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
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
Flow Chart
uti ts
The flowchart in Figure 7-1 illustrates the data flow for this design.
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
Check
Warning = FAL
FALSE
SE
Stop = TRUE
Na
State Transitions
uti ts
The following table describes the states in this state machine.
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
r D str
t fo l In
No na
tio
Na
Implementation
uti ts
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
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.
Right-click the constant and select Editt Items from the shortcut
ortcut
tcut menu.
Na
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
1 2 3 4
rib en
on
ist um
r D str
t fo l In
No na
5
tio
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
1 2 3 4
rib en
on
ist um
r D str
t fo l In
5 6
No na
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
Test
uti ts
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
4. Notice the changes in the upper and lower limit values and the placement off tabs
abs and line breaks.
s.
r D str
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
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.
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.
Before determining which option to use, review the content of the Acquisition and Analysis states:
uti ts
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.
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
t fo l In
Time Check if no warning occurs
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
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
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.
Acquisition 0
Range Check 1
t fo l In
Analysis 2
Data Log 3
Time Check 4
No na
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
1
en
n
um
2
str
t fo l In
No na
r
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
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
uti ts
1. Run the VI.
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.
r D str
t fo l In
No na
tio
Na