LVCore3 2009 ExerciseManual Eng PDF
LVCore3 2009 ExerciseManual Eng PDF
LabVIEW Core 3 TM
rib en
Exercises
on
ist um
Course Software Version 2009
r D str
April 2010 Edition
Part Number 325511A-01
LabVIEW Core 3 Exercises
Copyright
t fo l In
20042010 National Instruments Corporation. All rights reserved.
Under the copyright laws, this publication may not be reproduced or transmitted in any form, electronic or mechanical, including
photocopying, recording, storing in an information retrieval system, or translating, in whole or in part, without the prior written consent
of National Instruments Corporation.
National Instruments respects the intellectual property of others, and we ask our users to do the same. NI software is protected by
copyright and other intellectual property laws. Where NI software may be used to reproduce software or other materials belonging to
others, you may use NI software only to reproduce materials that you may reproduce in accordance with the terms of any applicable
No na
ICU. Copyright 19952009 International Business Machines Corporation and others. All rights reserved.
HDF5. NCSA HDF5 (Hierarchical Data Format 5) Software Library and Utilities
Copyright 1998, 1999, 2000, 2001, 2003 by the Board of Trustees of the University of Illinois. All rights reserved.
b64. Copyright 20042006, Matthew Wilson and Synesis Software. All Rights Reserved.
Stingray. This software includes Stingray software developed by the Rogue Wave Software division of Quovadx, Inc.
Na
Worldwide Offices
Australia 1800 300 800, Austria 43 662 457990-0, Belgium 32 (0) 2 757 0020, Brazil 55 11 3262 3599, Canada 800 433 3488,
China 86 21 5050 9800, Czech Republic 420 224 235 774, Denmark 45 45 76 26 00, Finland 358 (0) 9 725 72511,
France 01 57 66 24 24, Germany 49 89 7413130, India 91 80 41190000, Israel 972 3 6393737, Italy 39 02 41309277,
Japan 0120-527196, Korea 82 02 3451 3400, Lebanon 961 (0) 1 33 28 28, Malaysia 1800 887710, Mexico 01 800 010 0793,
Netherlands 31 (0) 348 433 466, New Zealand 0800 553 322, Norway 47 (0) 66 90 76 60, Poland 48 22 328 90 10,
Portugal 351 210 311 210, Russia 7 495 783 6851, Singapore 1800 226 5886, Slovenia 386 3 425 42 00,
South Africa 27 0 11 805 8197, Spain 34 91 640 0085, Sweden 46 (0) 8 587 895 00, Switzerland 41 56 2005151,
Taiwan 886 02 2377 2222, Thailand 662 278 6777, Turkey 90 212 279 3031, United Kingdom 44 (0) 1635 523545
For further support information, refer to the Additional Information and Resources appendix. To comment on National Instruments
documentation, refer to the National Instruments Web site at ni.com/info and enter the info code feedback.
Contents
Student Guide
uti ts
A. NI Certification .....................................................................................................v
B. Course Description ...............................................................................................vi
C. What You Need to Get Started .............................................................................vi
D. Installing the Course Software..............................................................................vii
rib en
E. Course Goals.........................................................................................................vii
F. Course Conventions ..............................................................................................viii
on
Lesson 2
ist um
Analyzing the Project
Exercise 2-1 Analyze a Requirements Document .................................................2-1
Lesson 3
Designing the User Interface
r D str
Exercise 3-1 User-Interface Design Techniques ...................................................3-1
Lesson 4
Designing the Project
t fo l In
Exercise 4-1 User Event Techniques.....................................................................4-1
Exercise 4-2 Using the LabVIEW Project.............................................................4-7
Exercise 4-3 Using Project Explorer Tools ...........................................................4-8
Exercise 4-4 Choose Data Types...........................................................................4-14
Exercise 4-5 Information Hiding...........................................................................4-17
Exercise 4-6 Design an Error Handling Strategy ..................................................4-25
No na
Lesson 5
Implementing the User Interface
Exercise 5-1 Implement User Interface-Based Data Types...................................5-1
tio
Lesson 6
Na
Implementing Code
Exercise 6-1 Implement the Design Pattern ..........................................................6-1
Exercise 6-2 Timing ..............................................................................................6-14
Exercise 6-3 Implement Code ...............................................................................6-18
Exercise 6-4 Implement Error Handling Strategy .................................................6-27
Lesson 7
Implementing a Test Plan
Exercise 7-1 Integrate Initialize and Shutdown Functions....................................7-1
Exercise 7-2 Integrate Display Module .................................................................7-6
uti ts
Exercise 7-3 Integrate Record Function ................................................................7-12
Exercise 7-4 Integrate Play Function.....................................................................7-17
Exercise 7-5 Integrate Error Module .....................................................................7-24
rib en
Exercise 7-6 Stress and Load Testing....................................................................7-29
Exercise 7-7 Self Study: Integrate Save and Load Functions ...............................7-31
on
Exercise 7-8 Self Study: Integrate Stop Function .................................................7-37
ist um
Lesson 8
Evaluating VI Performance
Exercise 8-1 Identify VI Issues with VI Metrics...................................................8-1
Exercise 8-2 Methods of Updating Indicators.......................................................8-2
Lesson 9
r D str
Implementing Documentation
Exercise 9-1 Document User Interface..................................................................9-1
Exercise 9-2 Implement Documentation ...............................................................9-3
t fo l In
Lesson 10
Deploying the Application
Exercise 10-1 Implementing Code for Stand-Alone Applications..........................10-1
Exercise 10-2 Create a Stand-Alone Application....................................................10-6
Exercise 10-3 Self-Study: Create an Installer..........................................................10-8
No na
Appendix A
Additional Information and Resources
tio
Course Evaluation
Na
Thank you for purchasing the LabVIEW Core 3 course kit. This course
manual and the accompanying software are used in the three-day, hands-on
uti ts
LabVIEW Core 3 course.
You can apply the full purchase price of this course kit toward the
rib en
corresponding course registration fee if you register within 90 days of
purchasing the kit. Visit ni.com/training to register for a course and to
on
access course schedules, syllabi, and training center location information.
ist um
Note For course and exercise manual updates and corrections, refer to ni.com/info
and enter the info code core3.
A. NI Certification
The LabVIEW Core 3 course is part of a series of courses designed to build
r D str your proficiency with LabVIEW and help you prepare for exams to become
an NI Certified LabVIEW Developer and NI Certified LabVIEW Architect.
The following illustration shows the courses that are part of the LabVIEW
training series. Refer to ni.com/training for more information about
t fo l In
NI Certification.
Engineering in LabVIEW
LabVIEW Core 2*
LabVIEW OOP System Design
Advanced Architectures
in LabVIEW
Certifications
tio
Other Courses
Na
LabVIEW Real-Time
*Core courses are strongly recommended to realize maximum productivity gains when using LabVIEW.
B. Course Description
The LabVIEW Core 3 course teaches you four fundamental areas of
software development in LabVIEWdesign, implement, test, and deploy.
uti ts
By the end of the LabVIEW Core 3 course, you will be able to produce a
LabVIEW application that uses good programming practices and is easy to
scale, easy to read, and easy to maintain. As a result, you should be able to
rib en
more effectively develop software with LabVIEW.
This course assumes that you have taken the LabVIEW Core 1 and
on
LabVIEW Core 2 courses or have equivalent experience.
ist um
This course kit is designed to be completed in sequence. The course and
exercise manuals are divided into lessons, described as follows.
Note The exercises in this course are cumulative and lead toward developing a final
application at the end of the course. If you skip an exercise, use the solution VI for that
exercise, available in the <Solutions>\LabVIEW Core 3 directory, in later exercises.
tio
Filename Description
uti ts
Exercises Folder containing VIs and other files used in
the course
Solutions Folder containing completed course exercises
rib en
D. Installing the Course Software
on
Complete the following steps to install the course software.
ist um
1. Insert the course CD in your computer.
2. Follow the prompts to install the course material.
The installer places the Exercises and Solutions folders at the top level
of the root directory. Exercise files are located in the <Exercises>\
r D str LabVIEW Core 3 directory.
Tip Folder names in angle brackets, such as <Exercises>, refer to folders in the root
directory of your computer.
t fo l In
E. Course Goals
This course prepares you to:
Establish a software lifecycle for future project development
No na
F. Course Conventions
The following conventions are used in this course manual:
uti ts
The symbol leads you through nested menu items and dialog box options
to a final action. The sequence FilePage SetupOptions directs you to pull
down the File menu, select the Page Setup item, and select Options from
rib en
the last dialog box.
on
This icon denotes a note, which alerts you to important information.
ist um
bold Bold text denotes items that you must select or click in the software, such as
menu items and dialog box options. Bold text also denotes parameter names,
controls and buttons on the front panel, dialog boxes, sections of dialog
boxes, menu names, and palette names.
italic
r D str Italic text denotes variables, emphasis, a cross-reference, or an introduction
to a key concept. Italic text also denotes text that is a placeholder for a word
or value that you must supply.
monospace Text in this font denotes text or characters that you enter from the keyboard,
t fo l In
sections of code, programming examples, and syntax examples. This font
also is used for the proper names of disk drives, paths, directories, programs,
subprograms, subroutines, device names, functions, operations, variables,
filenames, and extensions.
No na
tio
Na
uti ts
Exercise 2-1 Analyze a Requirements Document
rib en
Goal
on
Assess a requirements document that is based on a software requirements
document specification.
ist um
Scenario
You work with a Certified LabVIEW Architect to develop a requirements
document. You develop the requirements document after researching
r D str commercially available theatre light control software and analyzing the
specifications document. You must analyze the requirements document to
ensure that it is complete and accurate.
Implementation
Analyze the requirements document for the Theatre Light Control Software.
t fo l In
document, you can use this requirements document as a basis for other
requirements documents. Refer to the IEEE Requirements Documents
section of Appendix A of the LabVIEW Core 3 Course Manual for another
version of this requirements document.
tio
Requirements Document
Na
Document NumberLV100975
uti ts
The application should do the following:
Function as specified in Section II: Application Requirements of this
document.
rib en
Conform to LabVIEW coding style and documentation standards. Refer
to the Development Guidelines topic of the LabVIEW Help for more
on
information about the LabVIEW style checklist and creating
documentation.
ist um
Be hierarchical in nature. All major functions should be performed in
subVIs.
Use a state machine that manages states with a type-defined enumerated
type control, a queue, or an Event structure.
Be easily scalable, enabling the addition of more states and/or features
r D str without having to manually update the hierarchy.
Minimize the excessive use of structures, local and/or global variables,
and Property Nodes.
Respond to front panel controls within 100 ms and not utilize 100% of
t fo l In
CPU time.
Close all opened references and handles.
Be well documented and include the following:
Labels on appropriate wires within the main VI and subVIs.
No na
ABC Theatre Lighting Inc. is the largest provider of theatre lighting systems
for major metropolitan theatres worldwide. Theatre light systems must be
scalable for as many lights as a particular production might require. A
software-based theatre light control system allows theatres to scale the
lighting for each production. The control system controls each light
individually. Each light contains its own dimmer and color mixing system.
The color mixing system can mix an appropriate amount of red, green, and
blue to define each color. The control software sends signals to a hardware
uti ts
control system that controls the intensity and color of the lights. The user
interface for the control software should look similar to the following front
panel.
rib en
on
ist um
r D str
t fo l In
Definitions
This section defines the terminology for the project.
ChannelThe most basic element of the Theatre Light Control
Application. Each channel corresponds to a physical light.
IntensityAttribute of the channel that defines the intensity of the
No na
physical light.
ColorAttribute of the channel that defines the color of the channel as
a combination of red, green, and blue.
tio
Fade timeA cue timing attribute that defines the time it takes, in
multiples of one second, before a channel reaches its particular intensity
and color.
Follow timeA cue timing attribute that defines the amount of time to
wait, in multiples of one second, before the cue finishes.
Task
uti ts
Design, implement, test, and deploy a theatre light control system that
allows a theatre lighting engineer to easily control and program the theatre
lights for any production.
rib en
General Operation
Front panel controls determine the operation of the theatre light control
on
software. Front panel indicators display the current status of the theatre light
control software.
ist um
The controller will store the channel intensity, channel color, channel wait
time, channel fade time, channel follow time, and name for the cue when the
user clicks the Record button. When the user clicks the Play button, the
controller services each cue in the Cue Control by cycling through the
recorded cues starting with the first cue in the Cue Control. A cue that is
r D str playing will wait for the specified wait time, then fade the channels to the
desired color and intensity within the specified fade time, and then wait for
the specified follow time. The next cue in the Cue Control loads and the
process repeats, until all of the Cues play. The user can stop a currently
t fo l In
playing cue by clicking the Stop button. The controller exits when the user
selects FileExit.
Sequence of Operation
Application Run
When the application starts, all the front panel controls must initialize to
No na
their default states. The Cue Control must be cleared to remove all the
recorded Cues. The channels must be initialized with their corresponding
channel number, zero intensity, and the color black.
tio
Record
Click the Record button to activate the cue recording functionality. A
custom panel must open that allows the lighting engineer to set the channel
intensity and color for the channels. The panel must provide for the
capability to name the cue, and specify the wait time, fade time, and the
Na
follow time. The minimum time for the wait time and follow time is zero
seconds. The minimum time for the fade time is one second. The minimum
increment for the wait time, fade time, and follow time is one second.
After a cue is recorded, the cue name is placed into the Cue Control.
Play
Click the Play button to play the recorded cues. When the play begins, the
uti ts
controller should disable the Record button and the Cue List. The values of
the first cue in the cue list are loaded into memory. The controller waits
based on the number of seconds specified for the wait time for the current
rib en
cue. The controller then fades the channel up or down based on the current
channel intensity and the desired channel intensity. The software writes the
on
color and intensity to the theatre lighting hardware control system, and
updates the front panel channels. The controller must finish fading within
ist um
the specified fade time. The controller will finish processing the cue by
waiting for the number of seconds specified for the follow time of the
current cue. When the play is complete, the controller should enable the
Record button and the Cue List.
r D str Stop
Click the Stop button to stop a currently playing cue. The operation is
ignored if a cue is not playing.
Save
Select FileSave to save all of the recorded cues in a file for later playback.
t fo l In
The user specifies the filename.
Open
Select FileOpen to open a file that contains recorded cues. The user
specifies the filename.
No na
Exit
Select FileExit to exit the application. If an error has occurred in the
application, the application reports the errors.
tio
uti ts
Cue Name StringDisplays the name of the current cue
Wait Time NumericDisplays the number of seconds of the
rib en
recorded cue wait time
Fade Time NumericDisplays the number of seconds of the
on
recorded cue fade time
ist um
Follow Time NumericDisplays the number of seconds of the
recorded cue follow time
Channel ClusterRecord that contains the channel
number, channel intensity, and channel color
r D str Scalability
Many of the newer theatre lights systems provide motor control to move the
light around the stage. The Theatre Light Control Software should provide
for the ability to easily implement channel pan and tilt. The software should
t fo l In
be easily scalable to control any number of channels.
Documentation
The application documentation should address the needs of the end user and
a programmer who might modify the application in the future.
No na
Deliverables
The project includes the following deliverables:
Documented source code
tio
Timeline
The project has the following timeline for completion:
Na
uti ts
Each requirement has a single, clear, unambiguous meaning.
rib en
system.
on
The requirements do not contradict each other.
ist um
Each requirement is testable.
Notes
uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
uti ts
Exercise 3-1 User-Interface Design Techniques
rib en
Goal
on
Learn techniques you can use to create professional user interfaces in
LabVIEW.
ist um
Description
LabVIEW includes features that allow you to create professional user
interfaces. Learn techniques to remove borders from clusters, create custom
r D str cursors, create custom toolbars, and use the transparency property to
enhance the users experience with your application.
Implementation
Creating Transparent Cluster Borders
t fo l In
Clusters group data elements of mixed types. However, sometimes you do
not want the user to know that you have organized the data into a cluster. The
clusters from the Modern palette visually indicate that the data is stored in
a container, however, you can modify a cluster from the Classic palette to
conceal the fact that data is organized in a cluster.
No na
2. Create a cluster from the Classic palette and make the borders of the
cluster transparent.
tio
Tip If the Controls palette is not visible, select ViewControls Palette to display the
palette.
Tip You can use the Search button to find controls, VIs, or functions. On the Controls
Na
or Functions palette, click the Search button on the palette toolbar. In the text field at the
top of the search dialog, start typing the name of the control, VI, or function you want to
find. As you type, the listbox shows all possible matches. When you find the control, VI,
or function you are looking for, double-click its name. This opens the palette where the
control, VI, or function is located and flashes the icon whose name you just
double-clicked.
Tip Select ToolsOptions, select Block Diagram from the Category list, and remove
the checkmark from the Place front panels terminals as icons checkbox to match the
examples in the manual.
uti ts
Click a blank area of the front panel with the Get Color tool to copy
the color of the front panel to the foreground and background colors
the Coloring tool uses.
rib en
Tip If the Tools palette is not visible, select ViewTools Palette to display the palette.
on
Select the Coloring tool. In the Coloring tool section of the Tools
ist um
palette, click the top left (foreground) color block to open the color
picker.
Click T in the upper right corner of the color picker to change the
foreground color to transparent.
Click the border of the cluster with the Coloring tool as shown in
r D str Figure 3-1 to make the cluster border transparent.
t fo l In
No na
You can use this technique with other controls from the Classic
palette. The controls from the Classic palette are easier to modify
tio
uti ts
provides visual cues to the user on the status of the application. For example,
if your application is busy processing data you can programmatically set the
cursor to busy while the processing occurs to let the user know that the
rib en
application is processing. Create a simple VI to test the cursor functionality.
on
1. Create a VI that contains a While Loop and the Set Cursor VI to change
the appearance of the cursor as shown in Figure 3-2.
ist um
r D str
Figure 3-2. VI to Change the Cursor
t fo l In
Control from the shortcut menu to create a stop button for the VI.
Add a Wait (ms) function inside the While Loop, and set the wait to
a reasonable amount, such as 100 ms.
tio
Add the Set Cursor VI from the Cursor palette to the While Loop.
Right-click the icon input of the Set Cursor VI and select Create
Control from the shortcut menu.
Na
uti ts
To create a toolbar at the top of your VI, add a Horizontal Splitter Bar to the
front panel and add a set of controls to the upper pane. Right-click the
rib en
splitter bar and select the following items from the shortcut menu to
configure the splitter bar as a toolbar:
on
Select Locked and Splitter SizingSplitter Sticks Top to lock the
splitter bar in position.
ist um
Select Upper PaneHorizontal ScrollbarAlways Off and Upper
PaneVertical ScrollbarAlways Off to hide the upper scrollbars of
the pane.
You also can paint the pane and resize the splitter so that it blends seamlessly
r D str with the menu bar. You can scroll the scrollbars of the lower pane or split the
lower pane further without affecting the toolbar controls. Figure 3-3 shows
examples of custom toolbars.
t fo l In
2. Add a Horizontal Splitter Bar from the Containers palette to the front
panel. Position the splitter bar near the top of the VI. Leave enough
space above the bar to add the menu controls.
3. To turn off the scrollbars, right-click the splitter bar and select Upper
PaneHorizontal ScrollbarAlways Off and Upper PaneVertical
ScrollbarAlways Off from the shortcut menu.
4. To change the style of the splitter bar to system, right-click the splitter
bar and select Splitter StyleSystem from the shortcut menu.
uti ts
User Interface Design Techniques\Toolbar Controls
directory to the upper pane created by the splitter bar.
6. Rearrange the controls and color the splitter bar to look like a toolbar.
rib en
Hide the labels for the controls.
on
Use the Align Objects and Distribute Objects buttons on the
ist um
toolbar to align and distribute the controls.
Color the background of the pane to blend the controls into the
panel.
r D str Click the background color block of the Coloring tool to open
the color picker.
Click the More Colors button in the bottom right corner of the
color picker to open the Color dialog box.
t fo l In
Enter the following values and click OK to set the background
color:
Red: 231
Green: 223
No na
Blue: 231
Click the background of the splitter bar pane to change the color.
7. To lock the splitter bar so that the user cannot move it, right-click the
tio
splitter bar and make sure Locked is checked in the shortcut menu.
uti ts
Add a Flat Square button from the Classic palette and position it on
top of the Tank. Resize the control to completely cover the Tank and
hide the label of the control.
rib en
2. Modify the button to make it transparent.
on
Use the Coloring tool to change the True and False color of the
ist um
button to transparent.
Click the button with the Operating tool to verify that the button is
transparent whether it is True or False.
r D str 3. Add code to cause Tank Value to update only when the transparent
button is True, as shown in Figure 3-5.
t fo l In
No na
Add a Case structure inside the While Loop to enclose the Tank
tio
Value indicator.
5. Run the VI and test the behavior of the VI when you click the Tank
indicator.
Notes
uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
Notes
uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
uti ts
Exercise 4-1 User Event Techniques
rib en
Goal
on
Complete a VI that contains a static user interface event and a user event.
ist um
Scenario
This VI contains the Fire Event Boolean control that causes an LED to light
when the user clicks the control. In addition, the block diagram contains a
countdown that displays on the slider. When the countdown reaches zero,
r D str it generates a programmatic event that lights the LED.
Design
1. Modify the block diagram to create and generate a user event for the
LED.
t fo l In
2. Configure the Fire Event event case to handle both the Value Change
event on the Fire Event Boolean control and the User event.
Note Event-driven programming features are available only in the LabVIEW Full and
Professional Development Systems. You can run a VI built with these features in the
No na
LabVIEW Base Package, but you cannot reconfigure the event-handling components.
Implementation
1. Open User Event.vi from the <Exercises>\LabVIEW Core 3\
tio
User Event Techniques directory. Figure 4-1 and Figure 4-2 show
the front panel and block diagram.
Na
uti ts
rib en
on
ist um
r D str
Figure 4-2. User Event VI Block Diagram
t fo l In
Create and Generate User Event
2. Modify the block diagram to create and generate a user event for the
LED as shown in Figure 4-3. You will add the True state as shown in
Figure 4-3. Wire the user event through the False state.
No na
tio
Na
Add a Create User Event function from the Events palette to the
block diagram. This function returns a reference to a user event
when Programmatic Count Down to Event reaches zero.
Add a False constant from the Boolean palette to the block diagram.
uti ts
Label it LED. Wire the False constant to the user event data type
input of the Create User Event function.
rib en
Add a Register For Events node from the Events palette to the block
diagram. Wire the node as shown in Figure 4-3.
on
Generate the event within the True case of the programmatic loop.
ist um
Add a Generate User Event function from the Events palette to
the block diagram.
Add a True constant to the block diagram and wire it to the event
r D str data input of the Generate User Event function.
Wire the user event reference through the False case of the Case
t fo l In
structure.
Configure Events
3. Create and configure an event case to handle the value change event on
the Fire Event Boolean control and handle the user event.
No na
Wire the Event Registration Refnum from the Register For Events
tio
Tip If the dynamic event terminal is not visible, right-click the border of the Event
structure and select Show Dynamic Event Terminals from the shortcut menu.
Na
Wire the error and Event Count shift registers from the left border of
the User Interface Loop to the left border of the Event structure.
4. Configure a Fire Event case to handle both the Value Change event on
the Fire Event Boolean control and the user event, as shown in
Figure 4-4.
uti ts
rib en
on
ist um
Figure 4-4. Fire Event Case
Wire the Event Fired! reference to the Bool Refnum input of the
Flash LED subVI.
t fo l In
Move the Fire Event Boolean control into the event case so the VI
reads the value of the control when the event executes.
Select Fire Event from the Event Sources list and select Value
Change from the Events list.
5. Create and configure the Stop event case to handle the Value Change
event on the Stop Boolean control as shown in Figure 4-5.
uti ts
rib en
on
Figure 4-5. Stop Event Case
ist um
Right-click the Event structure and select Add Event Case from the
shortcut menu to open the Edit Events dialog box.
Select Stop from the Event Sources list and Value Change from
the Events list and click OK.
r D str Move the Stop Boolean control into the Stop event case and wire the
control to the right border of the Event structure.
Wire the error and Event Count data through the Stop event case.
t fo l In
6. Complete the block diagram as shown in Figure 4-6 to stop the User
Interface Loop, release the user event resources, and handle any errors
that have occurred. Use the following items:
from the error cluster. If an error has occurred or the user clicks
Stop, then stop the User Interface Loop.
Merge Errors VICombines the error outputs from both loops into
a single error output.
Na
uti ts
rib en
on
ist um
Figure 4-6. Completed User Event VI Block Diagram
uti ts
Create a LabVIEW project for the application.
Scenario
rib en
Every large LabVIEW development needs to use a project to control naming
and project hierarchy. Using the LabVIEW Project simplifies the
on
development of larger applications.
Design
ist um
Create a LabVIEW project that includes folders for modules and controls.
Save the project as TLC.lvproj in the <Exercises>\LabVIEW
Core 3\Course Project directory.
Implementation
r D str 1. Create a new project.
uti ts
Use the Project Explorer tools to resolve conflicts and manage files in a
LabVIEW project.
Scenario
rib en
Conflicts can arise within a LabVIEW project if top-level VIs are calling
on
incorrect versions of nested code. Applications that are saved in multiple
locations as a result of archiving, backup, or division of work can lead to the
use of incorrect code and broken applications.
ist um
In this exercise, you examine a LabVIEW project that contains conflicts and
use the tools in the Project Explorer to resolve the conflicts and manage
the project.
Design
r D str The project in this exercise contains the following conflicts:
Two VIs within the project have the same name, Generate
Signal.vi.
t fo l In
A VI in the project calls a subVI outside the project that has the same
name, Log to File.vi, as a VI within the project.
Implementation
No na
uti ts
rib en
on
ist um
r D str Figure 4-7. LabVIEW Project with Conflicts
Tip The best way to determine if cross-linking exists is to view the full path to the item.
Viewing filepaths is often the first step when attempting to resolve conflicts that are
Na
caused by cross-linking. You can attempt to rename or move files as needed, but first you
must determine which file is the correct file. Enabling Show Item Paths displays the file
locations in a second column in the Project Explorer window.
You can resolve project conflicts from the Resolve Project Conflicts dialog
box, but in this exercise you practice additional techniques to resolve
conflicts.
uti ts
LabVIEW highlights the Create and Save Signal VI because it calls
this VI as a subVI.
rib en
and select FindCallers from the shortcut menu. Notice that this VI
has no callers in the project. However, it is inadvisable to delete this
on
VI because it performs a unique function. Renaming one or both
files is a more appropriate action.
ist um
4. Manually rename the conflicting files.
LabVIEW prompts you to save the changes made to the calling VI,
Create and Save Signal.vi, to preserve the links. Click Save.
t fo l In
Note You also can rename files from the Files page view of the project.
uti ts
rib en
on
ist um
r D str
t fo l In
In the Resolve Load Conflict dialog box, select the Log to File VI
No na
The Load Summary Warning dialog box informs you that the Log
to File subVI was loaded from a different location. Click Show
Details.
tio
Examine the Load and Save Warning List dialog box. Click Close.
All conflicts in the project should now be resolved.
The Create and Save Signal VI has unlinked subVIs after resolving
Na
Right-click the Sine Wave virtual folder in the project tree and
uti ts
select Convert to Auto-populating Folder from the shortcut menu.
rib en
Explorer Tools\Working Directory\Sine Wave directory
and click Current Folder. Notice in the project tree that the Sine
Wave folder icon changes to indicate that the folder is now set to
on
auto-populate.
ist um
Note In auto-populate mode, the contents of the project folder reflect the hierarchy of
the specified folder on disk, as well as any changes that are made outside the development
environment.
r D str Click the Windows Start button and select All Programs
AccessoriesNotepad to launch Notepad.
Close Notepad.
Notice that Data File.txt has been added to the Sine Wave
auto-populating folder on the Items page of the Project Explorer
window.
No na
In the Find Project Items dialog box, enter sine in the textbox,
as shown in Figure 4-9, and click Find.
Na
uti ts
rib en
on
ist um
r D str
Figure 4-9. Find Project Items Dialog Box
t fo l In
Select Sine Wave - Generate Signal.vi and click Go To. This item
should now be highlighted in the Project Explorer window.
uti ts
Design and create the data types that you need for this application.
Scenario
rib en
When you develop a VI, you must identify and design the data types that you
need to use in the application.
on
Design
ist um
Design a cluster called Cue for the cue information that contains the
following data elements:
The final cluster should resemble Figure 4-10. Use controls from the
System palette where appropriate, so your application will look like the
native operating system when moved to different locations.
No na
tio
Na
Implementation
1. Open the TLC project.
uti ts
the TLC project.
Right-click the Controls virtual folder in the TLC project tree and
rib en
select AddFile from the shortcut menu.
on
Course Project\Controls directory, select
tlc_Cue_Information.ctl and click Add File to add the file.
ist um
3. Open tlc_Cue_Information.ctl and verify that the Control Type
pull-down menu is set to Type Def.
4. Create the Cue Name, Wait Time, Fade Time, and Follow Time controls.
Use the System palette to create the controls. Add the controls to the
r D str cluster.
Add a String control to the cluster and label the control Cue Name.
Add a Numeric control to the cluster and label the numeric Wait
t fo l In
Time (s).
Create two copies of the Wait Time (s) control in the cluster. Name
No na
one Fade Time (s) and name one Follow Time (s).
5. Create the Channels 2D array shell. Turn off index display for the array.
Add an array from the Modern palette to the cluster. Change the
tio
Right-click the array shell and select Add Dimension from the
shortcut menu to make the array 2D.
Na
uti ts
9. Save the project.
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
uti ts
Design a VI that provides an interface to the data.
Scenario
rib en
Build a VI that uses a functional global variable to provide an interface to
the Cue data type you created in Exercise 4-4. The functional global variable
on
provides a safe way to access the data that the application needs.
Design
ist um
To provide an interface to the data in the Cue data type, you need to create
a VI that can access the Cue data type. Create a functional global variable to
access the data.
r D str The functional global variable implements the following functions:
Initialize
Add Cue
t fo l In
Get Cue Values
Implementation
1. Open the TLC project if it is not already open.
tio
Right-click the Fade Time (s) control and select Data Operations
uti ts
Make Current Value Default from the shortcut menu.
rib en
executes when the Theatre Light Control software starts.
on
ist um
r D str
t fo l In
the Rows and Columns elements from the Number of Cues cluster.
Right-click the Row output tunnel on the Case structure and select
Linked Input TunnelCreate and Wire Unwired Cases from the
shortcut menu. Click the corresponding input tunnel to link it to the
output tunnel. LabVIEW automatically wires the linked tunnels in
uti ts
all existing cases. If you add a case, LabVIEW wires the tunnels in
the new case.
rib en
Note The True constant wired to the loop conditional terminal causes the loop to iterate
on
only once each time it is called.
ist um
6. Complete the Add Cue case as shown in Figure 4-12 using the following
items. This case adds a new cue to the Cue List.
7. Use the Index Array function to complete the Get Cue Values case,
as shown in Figure 4-13. This case loads the next cue from the Cue List.
uti ts
rib en
on
ist um
r D str Figure 4-13. Get Cue Values Case
8. Use the Replace Array Subset function to complete the Set Cue Values
case as shown in Figure 4-14. This case is modifies an existing cue.
t fo l In
No na
tio
Na
9. Use the Array Size function to complete the Get Number of Cues case,
as shown in Figure 4-15. This case retrieves the recorded cues and
updates the Cue List.
uti ts
rib en
on
ist um
r D str
Figure 4-15. Get Number of Cues Case
10. Complete the Get Empty Cue case, as shown in Figure 4-16.
t fo l In
This case creates a blank cue, for example, to initialize the front panel
or record a new cue. A blank cue has an intensity of zero, the color black,
and the appropriate channel number.
No na
tio
Na
Add two For Loops to the Get Empty Cue case. Connect the Rows
data wire to the outer For Loop count terminal. Connect the
Columns data wire to the inner For Loop count terminal.
uti ts
Tip Create more working space for the front panel or block diagram by pressing the
<Ctrl> key and using the Positioning tool to drag out a rectangle where you want more
space.
rib en
Add channel.ctl constant from the Controls virtual folder of the
on
TLC project.
ist um
Tip Arrange a cluster horizontally or vertically by right-clicking the cluster border
and selecting AutosizingArrange Horizontally or AutosizingArrange Vertically.
Use this technique to decrease the size of the cluster.
in the inner For Loop to the Channels input of the second Bundle
By Name function, the tunnels on the For Loops have indexing
enabled by default. This creates a 2D array of Channels, where the
outer loop determines the number of rows and the inner loop
determines the number of columns.
Na
Switch to the front panel, right-click the outside border of the Cue
Output indicator, and select CreateLocal Variable to create the
local variable for the Cue Output.
This VI provides controlled access to the data stored in the cue. With this
type of VI, the data is protected.
Testing
Test the VI to verify its operation.
uti ts
Command = Initialize
Rows = 4
rib en
Columns = 8
on
2. Run the VI.
ist um
3. Set the following values for the front panel controls:
Verify that there are 4 rows by increasing the Row Index from 0 to
3. Verify that there are 8 rows by increasing the Column Index from
No na
Cue Input = Enter dummy data in the Wait Time (s), Fade
Na
uti ts
11. Set the following values for the front panel controls:
rib en
Cue Index = 0
on
12. Run the VI.
13. Verify that Cue Output matches the values you entered in step 6.
ist um
14. Save and close the VI and save the project.
uti ts
Develop a strategy to handle errors in the application.
Scenario
rib en
Creating a custom error code for your application is easy in the LabVIEW
environment. Use the custom error code in the application to provide a
on
detailed description of the error that occurred. You can use this information
to diagnose the error and the location where the error occurred. Every
application that contains multiple states must provide a method and strategy
ist um
for handling errors.
Design
Use the LabVIEW Error Code File Editor to create the following error code,
based on a possible error that can occur in the application.
r D str
Error Code Description
5000 Cue Data Error
t fo l In
Implementation
Part I: Edit the Error Code File
1. Open the TLC project if it is not already open.
No na
Click Add to open the Add Error Code dialog box. Create the error
code as specified in the Design section.
Note LabVIEW automatically sets the New Code value to 5000 and increments it each
time you click Add.
Na
Enter the description from the table in the Design section in the
New Description text box. Click OK to add the error code.
uti ts
the invalid index and generate error 5000.
rib en
Open the block diagram and add a Case structure around the While
Loop.
on
Wire error in to the case selector terminal.
ist um
Wire the error clusters through all the structures. Right-click each
unwired error output tunnel and select Linked Input Tunnel
Create and Wire Unwired Cases to automatically wire unwired
r D str cases.
2. Modify the Get Cue Values case to determine if the desired cue exists
before attempting to obtain its value. Figure 4-17 shows the True and
False cases for the Get Cue Values case. To build the Get Cue Values
case, use the following items:
t fo l In
Array Size functionThis function determines the number of
elements in the cue array. The minimum number of cues in the array
is zero.
indicates whether the specified Cue Index is valid for the existing
cue array. If it is not within range, error 5000 generates.
Case structure
Error Cluster From Error Code VIAdd this VI to the False case of
the Get Cue Values Case structure.
Na
Note The Error Cluster From Error Code VI converts an error or warning code to an
error cluster. This VI is useful when you receive a return value from a DLL call or when
you return user-defined error codes.
uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
3. Modify the Set Cue Values case to determine if the desired cue exists
before attempting to change its value. Figure 4-18 shows the True and
False cases for the Set Cue Values case. To build this case, use the same
items that you used for the Get Cue Values case in step 2.
uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Testing
1. Restart LabVIEW to load the error code file. Changes to error code text
files take effect the next time you start LabVIEW.
uti ts
2. Generate an error with the Cue Module VI.
rib en
Open tlc_Cue Module.vi from the project tree.
on
Enter an invalid Cue Index with Command set to Get Cue Values.
ist um
Run the VI.
3. Verify that the error explanation matches what you specified when you
created the error code file.
r D str Verify that error out indicates an error occurred.
Right-click the error cluster and select Explain Error from the
shortcut menu.
Verify that the Explanation text box displays the custom error
t fo l In
description in the Possible reason(s): section.
4. Verify that the same error generates if you enter an invalid Cue Index
with Command set to Set Cue Values.
Notes
uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
uti ts
Exercise 5-1 Implement User Interface-Based Data Types
rib en
Goal
on
Implement user interface-based data types.
ist um
Scenario
Implement the user interface for the application. The specification from the
customer and the requirements document define the user interface for the
project.
Design
r D str Figure 5-1 shows the user interface from the requirements document.
t fo l In
No na
tio
Inputs
Play buttonInput by the user
Record buttonInput by the user
Stop buttonInput by the user
Outputs
Cue List listboxDisplays a list of all of the recorded cues
Cue Name stringDisplays the name of the currently playing cue
uti ts
Wait Time (s) numericDisplays the wait time for the currently
playing cue
Fade Time (s) numericDisplays the fade time for the currently
rib en
playing cue
Follow Time (s) numericDisplays the follow time for the currently
on
playing cue
Channel clusterDisplays the channel number, channel intensity, and
ist um
channel color for each channel
Implementation
r D str Create a front panel similar to the user interface shown in Figure 5-1.
checkbox.
3. Delete the Queue Event and STOP buttons from the front panel.
Add a System Listbox from the System palette to the front panel.
uti ts
hide Cue List.
rib en
Add a System button to the front panel.
on
Tip Press the <Ctrl-space> keys to display the Quick Drop dialog box. Use this dialog
box to specify a palette object or project item by name and then place the object on the
ist um
block diagram or front panel. Press the <Enter> key, double-click the name of the object
in the search results text box, or click the block diagram or front panel to attach the object
to the cursor. Then click the location on the block diagram or front panel where you want
to add the object.
r D str Right-click the button and select AdvancedCustomize from the
shortcut menu to open the Control Editor.
Close the Control Editor. When prompted, click Yes to replace the
original control with the custom control.
Na
Select Play Button.ctl in the project tree and drag the file to the
Controls virtual folder to add the control in the project hierarchy.
uti ts
Click and drag the custom controls from the project tree to the front
panel.
rib en
Arrange the controls.
on
Hide the control labels.
ist um
7. Add the typedef that contains the Cue Name, Wait Time, Fade Time,
Follow Time, and array of Channels to the front panel.
9. Add error in and error out clusters to the front panel to pass error data
through the VI.
Na
Note The Run button is broken because you deleted the Queue Event and Stop buttons.
You resolve the broken Run button in a later exercise.
uti ts
Implement a meaningful icon for the VI.
Scenario
rib en
Follow the suggestions for creating an icon to develop an icon that describes
the purpose of TLC Main VI.
on
Design
ist um
Create an icon for the TLC Main VI that resembles the icon shown at left.
Implementation
r D str 1. Add shared files and the Shared virtual folder to the project.
4. Right-click the VI icon in the upper right corner of the front panel and
select Edit Icon from the shortcut menu to open the Icon Editor.
Na
6. From the Templates tab, select All Templates and click the template
shown at left.
7. Use the Fill tool to apply a different color to the top region of the icon.
Tip Use a light color to help keep the icon text readable.
uti ts
8. Use the Text tool to add text to the top section of the icon.
rib en
Tip Double-click the Text tool to modify the font.
on
9. Add the light bulb to the bottom section of the icon.
ist um
10. Click OK to close the Icon Editor. Save the VI.
uti ts
Implement an appropriate connector pane for the VI.
Scenario
rib en
Build every VI with the 4 2 2 4 connector pane. This connector pane
pattern provides for scalability, maintainability, and readability. The
4 2 2 4 connector pane is very easy to wire.
on
Design
ist um
Modify the TLC Main VI by following the connector pane guidelines in this
lesson to create a 4 2 2 4 connector pane, as shown at left. Connect the
error in and error out clusters to the connector pane terminals.
Implementation
r D str 1. Open the front panel of TLC Main VI.
2. Right-click the VI icon in the upper right corner of the front panel and
select Show Connector from the shortcut menu.
t fo l In
3. Verify that the connector pane uses the 4 2 2 4 pattern.
4. Use the Wiring tool to connect the error in and error out clusters to the
connector pane.
Click the connector pane terminal you want to connect to the error
No na
Click the error in cluster to assign the control to the connector pane
terminal.
tio
Click the connector pane terminal you want to connect to the error
out cluster.
Click the error out cluster to assign the indicator to the connector
Na
pane terminal.
5. Right-click the connector pane and select Show Icon from the shortcut
menu to display the icon for the VI.
Notes
uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
uti ts
Exercise 6-1 Implement the Design Pattern
rib en
Goal
on
Use LabVIEW to implement a design pattern as the basis for the application
architecture.
ist um
Scenario
Using a design pattern for the architecture makes the application readable,
scalable, and maintainable. Implementing the producer/consumer (events)
r D str design pattern makes the user interface more responsive. Using a variant
data type makes the architecture scalable for future needs.
Design
Modify the design pattern as follows to create an architecture that meets the
project requirements.
t fo l In
Create a type definition for the functions that the application performs.
Use the type definition as the data type to pass data from the producer to
the consumer.
Initialize the design pattern.
No na
In the consumer loop of the design pattern, verify that a case exists to
process each function in the enumerated data type.
Enqueue an element into the producer/consumer with (events) queue
when the producer receives an event.
tio
Create a custom run-time menu to perform the Load, Save, and Exit
functions.
Add a case to the Event structure in the producer loop to respond to
menu selections.
Na
Create user events that allow the consumer loop to send error data to the
producer loop to stop the producer
Implementation
Implement the architecture for the Producer/Consumer (Events) design
pattern, as shown in Figure 6-1.
uti ts
rib en
on
ist um
r D str
Figure 6-1. Theatre Light Controller Architecture
t fo l In
1. Open the TLC project.
Initialize
Record
Load
tio
Save
Play
Na
Stop
Exit
3. Create a scalable data type to pass data from the producer loop to the
consumer loop. This data type is a cluster that includes the
tlc_Functions.ctl control and a variant.
uti ts
Select Other FilesCustom Control from the Create New tree.
rib en
Verify Add to project is selected.
on
Click OK to open the Control Editor.
ist um
Change the label of the cluster to tlc_Consumer Control.ctl,
to correspond to the name of the file. Using the filename of the
control as a label helps you keep track of the block diagram controls.
Change the label of the variant to Data. Figure 6-2 shows the
t fo l In
resulting cluster.
No na
tio
Drag the control from the Project Window to the block diagram to
add it as a constant.
uti ts
Position the constant outside the producer and consumer loops.
Set the value of the enumerated type constant within the constant to
rib en
Initialize.
on
6. Initialize the producer/consumer design pattern.
Delete the empty string constant wired to the Obtain Queue function.
ist um
Wire the tlc_Consumer Control constant to the element data type
input of the Obtain Queue function.
r D str Add the Enqueue Element function to the block diagram. Wire the
cluster constant to the Enqueue Element function to initialize the
design pattern.
Delete the error cluster wires connected to the case selector terminal
and the loop conditional terminal for the consumer loop.
tio
Note You are deleting the initial error handling wiring in preparation for more complex
structures in later exercises. In Exercise 6-4 you build a functional global variable to
handle errors in the application and in Exercise 7-5, Integrate Error Module, you
integrate the error module in the main application.
Na
Right-click the border of the Case structure and select Add Case
For Every Value from the shortcut menu to populate the Case
structure with the items in the enumerated type control.
Right-click the error cluster tunnel on the consumer loop and select
uti ts
Replace with Shift Register from the shortcut menu. Add the other
side of the shift register to the right side of the consumer loop.
rib en
Wire the queue reference and error cluster through each case of the
consumer loop.
on
8. Modify an event case in the producer loop to respond to the Value
ist um
Change event for the Play button.
Click OK.
t fo l In
9. Modify the Play event case to send a message to the consumer loop to
execute Play, as shown in Figure 6-3. Delete the Unbundle By Name and
Or functions that are connected to the loop conditional terminal. Add the
following items:
tlc_Consumer Control.ctl
No na
Tip Right-click the Command element of the Bundle By Name function and select
CreateConstant from the shortcut menu to create tlc_functions.ctl.
False constant
uti ts
rib en
on
ist um
Figure 6-3. Producer Play Event
10. Create a Value Change event case for the following controls: Record
and Stop.
Right-click the Play event case, and select Duplicate Event Case
r D str from the shortcut menu.
Tip If you duplicate an event case with the terminal in the event case, you also duplicate
the terminal. Placing a terminal in the corresponding event case is good programming
t fo l In
style because it ensures that LabVIEW reads the terminal when the event occurs.
Select Record and the Value Change event and click OK.
Repeat the previous step for the Stop control, changing the
command the producer sends to the consumer to correspond to the
appropriate function.
tio
Table 6-1 shows the appropriate enumerated type control item to add in
the queue when each control receives a value change event.
11. Move the Record, Play and Stop control terminals to the corresponding
event cases to ensure that each control is read when it generates an event.
12. Create a custom run-time menu to perform the Load, Save, and Exit
uti ts
functions. Figure 6-4 shows the completed menu.
rib en
on
Figure 6-4. LabVIEW Run-Time Menu
ist um
Right-click My Computer in the project tree, select NewVirtual
Folder, and create the Menu virtual folder in the project tree.
Tip In the Item Name textbox, enter an underscore ( _ ) before the letter you want to
t fo l In
associate with the <Alt> key for that menu. This creates a shortcut so the user can press
the <Alt> key and the associated key to access the menu.
Click the blue + button on the Menu Editor toolbar to add a new item
under the File item.
tio
Click the right arrow button on the toolbar to make the new item a
subitem of the File menu.
for Open.
Note The Item Tag is passed to LabVIEW so that you can create decision making code
to respond to the selected menu item.
Click the blue + button on the Menu Editor toolbar to add a new item
under the File item.
uti ts
for Save.
rib en
Place your cursor in Shortcut and press <Ctrl-S> to record the
keyboard shortcut.
on
Click the blue + button on the Menu Editor toolbar to add a new item
ist um
under the FileSave item.
r D str Click the blue + button on the Menu Editor toolbar to add a new item
under the File item.
Enter E_xit in the Item Name textbox to create a menu item for
Exit.
Select File in the Preview section to preview the menu and verify
that it matches Figure 6-4.
Close the Menu Editor. When prompted, click Yes to change the
run-time menu to the custom menu.
tio
13. Add a case to the Event structure in the producer loop to respond to
menu selections.
Right-click the Event structure border and select Add Event Case
from the shortcut menu to open the Edit Events dialog box.
Select <This VI> from the Event Sources list and Menu Selection
(User) from the Events list to create the Menu Selection (User)
event case. Click OK.
Add a Case structure to the Menu Selection (User) event case. Wire
the ItemTag event data node to the case selector terminal.
Modify the Case structure in the Menu Selection (User) event case
uti ts
to have four cases. A Default case and a case for each ItemTag
string"Open", "Save", and "Exit". Be sure the spelling for the
case selector matches the spelling of the Item Tags in the Menu
Editor.
rib en
Delete any unused cases in the Case structure.
on
Modify the Exit case to stop the VI when the user selects FileExit,
ist um
as shown in Figure 6-5. Use the same items that you used for step 9.
r D str
t fo l In
Wire a True constant to the conditional terminal in the Exit case and
No na
Na
tio
No na
t fo l In
6-10
r D str
ist um
rib en
uti ts
on
Figure 6-6. Theatre Light Controller Architecture with User Events
ni.com
Lesson 6 Implementing Code
14. Complete the block diagram as shown in Figure 6-6 to create user events
that allow the consumer loop to send error data to the producer loop to
stop the producer.
uti ts
and select Show Dynamic Event Terminals from the shortcut
menu.
rib en
Add the Create User Event function to the block diagram. LabVIEW
uses the user event data type you wire to determine the event name
on
and data type of the event.
ist um
Right-click the error in input of the Create User Event function and
select CreateConstant to create the error constant. Label the error
constant error and wire it to user event data type.
Add the Register for Events node to the block diagram. This function
r D str dynamically registers the user event. Wire the event registration
refnum output of the Register for Events node to the dynamic
terminal of the Event structure.
Wire the Create User Event function to the Register for Events node.
t fo l In
Add the Dynamic Event case to the Event structure.
Wire the queue reference and error cluster through each case of
the Event structure.
tio
Note The name of the dynamic event is the same as the owned label for the data
structure wired to the Create User Event function.
Wire the status output from the event data node to the loop
Na
conditional terminal.
Wire the Release Queue, Unregister for Events, and Destroy User
uti ts
Events functions and the Merge Error VI as shown in Figure 6-6.
15. Delete any unused Event structure cases from the design pattern.
rib en
16. Connect the error in and error out clusters to the design pattern as
shown in Figure 6-6.
on
17. Save the VI.
ist um
Testing
1. Add the Format Into String and One Button Dialog functions to each
case of the consumer loop.
Wire the resulting string output to the message input of the One
Button Dialog function to open a dialog box indicating that the case
executes when the front panel receives events.
t fo l In
No na
tio
3. Run the VI to verify that all the functions listed in step 2 of the
Implementation section work correctly.
You can test the functionality by clicking a front panel button to execute
the Event structure. When the Event structure executes, it places a
message in the queue to execute the consumer.
The only cases that are not functional at this time are Load and Save.
You implement this functionality in a later exercise.
4. Verify that you can exit the application from the run-time menu.
uti ts
5. Close the TLC Main VI.
rib en
End of Exercise 6-1
on
ist um
r D str
t fo l In
No na
tio
Na
uti ts
Create a functional global variable that uses the Get Date/Time In Seconds
function to provide accurate software controlled timing.
Scenario
rib en
The Theatre Light Controller requires accurate timing to control the cue
on
wait time, fade time, and follow time. The Theatre Light Controller must
respond within 100 ms when any operation is running. The timing method
you choose for the Theatre Light Controller cannot interfere with the
ist um
application response. You will develop a functional global variable that will
be used in a later exercise to implement software control timing.
Design
Build a functional global variable that you can use to control the timing of
r D str the Theatre Light Controller. You will use the functional global variable to
control the timing for the wait, fade, and follow times of the Theatre Light
Controller. Use the Get Date/Time In Seconds function to control the
timing.
t fo l In
This application requires a structure that has precise timing characteristics
and does not use the processor. However, the structure also must respond
within 100 ms to meet the application requirements. Therefore, you will use
the Get Date/Time In Seconds function in a functional global variable to
implement software control timing.
No na
StartStarts a new time from zero, which resets the elapsed time.
Implementation
Na
1. Add the timing module files and Timing virtual folder to the Modules
virtual folder.
uti ts
tlc_Timing Command Control.ctl
rib en
tlc_Timing Module Unit Test.vi
on
tlc_Timing Module.vi
ist um
2. Open the tlc_Timing Module.vi.
Right-click the border of the While Loop and select Add Shift
Register.
Move the Timer Command control to the No Error case and wire it
to the case selector input of the Case structure inside the While
Loop. The Case structure should now have a Check Time case and a
Start case.
uti ts
4. Modify the Start case to store the start time of the VI, as shown in
Figure 6-9. Use the following items:
rib en
Get Date/Time In Seconds function
on
To Double Precision Float function
ist um
False constant
r D str
t fo l In
No na
5. Modify the Check Time case to output the elapsed time after a Start
command has been sent to the tlc_Timing Module VI, as shown in
Figure 6-10. Use the following items:
Na
Subtract function
uti ts
rib en
on
ist um
r D str Figure 6-10. Timing Module Check Time Case
Testing
A unit test VI is provided to verify the functionality of the Timing module.
t fo l In
The unit test VI repetitively calls the Timing module and displays the
elapsed time for the execution of the Timing module.
1. Use the unit test VI to test if the Timing module returns the values you
specify in the Cue control.
No na
Examine the block diagram and observe the functionality of the unit
test VI.
tio
Specify a value for the wait time, fade time, and follow time in the
Cue Input control.
Run the VI and verify that the times returned in Measured Test
Na
uti ts
Observe and implement the VIs that you identified as modules for the
application.
Scenario
rib en
When you carefully plan and design an application, your implementation of
on
the system creates scalable, readable, and maintainable VIs. Implement the
display, file, and hardware modules. These are the major modules that you
identified for the Theatre Light Control Software application. You have
ist um
already implemented the cue and timing modules.
Design
The functional global variable approach you used to implement the cue and
timing modules provides for a very scalable, readable, and maintainable
r D str method to build VIs. Continue to use a functional global variable to
implement the remaining modules for the application.
Display Module
t fo l In
The tight coupling that exists between the front panel and block diagram in
a VI requires that you update the front panel using block diagram terminals
or references from a subVI. Each of these methods has advantages and
disadvantages. Updating front panel controls and indicators using terminals
is very fast and efficient. However, you must have a way to get subVI data
to the top-level VI to update the front panel. You can loosen the tight
No na
coupling that exists between the front panel and the block diagram by
sending a message from subVIs to the top-level VI that contains the control
or indicator you want to update. An ideal implementation for this is a
functional global variable.
tio
The display module uses a functional global variable to store the reference
for the display queue. This allows the module to be called from anywhere in
the application to control the display loop.
File Module
The file module calls the File I/O VIs. The file module provides the
functionality to initialize, load cues from a file, save cues to a file, and
shutdown. Implement the file module using the functional global variable
uti ts
architecture.
Hardware Module
rib en
The hardware module calls the Theatre Light Control API. The hardware
module provides the functionality to initialize, write to, and shutdown the
on
hardware.
ist um
Implementation
Display Module
The Display module provides a method to update the front panel controls
and indicators from anywhere in the application. This module populates a
queue that contains the commands the display module performs and the data
r D str needed to perform these tasks. The display module performs the Initialize
Front Panel, Update Front Panel Channels, Select Cue in Cue List,
Enable/Disable Front Panel Controls, and Update Cue List functions.
To build a system that can perform these functions, first modify the design
t fo l In
pattern in TLC Main VI to have a display loop, then create the display
module with a functional global variable that sends messages to the display
loop.
Create a queue that specifically controls the display loop. The display loop
only updates the user interface in the top-level VI.
No na
uti ts
rib en
on
ist um
uti ts
the project tree, select AddFile and navigate to <Exercises>\
LabVIEW Core 3\Course Project\Controls. Add
tlc_User Interface Command.ctl and tlc_User
Interface Data Type.ctl to the project.
rib en
tlc_User Interface Data Type.ctl is used as part of
on
tlc_User Interface Command.ctl.
ist um
Add tlc_User Interface Command.ctl as a block diagram
constant. This constant uses a cluster of an enum and a variant to
provide a scalable data type for the display loop. Set the enum value
to Initialize.
r D str Obtain Queue function
Right-click the Case structure and select Add Case for Every Value
from the shortcut menu.
No na
Boolean constants
queue references.
4. Wire the queue reference and error cluster through each case of the Case
structure.
uti ts
LabVIEW Core 3\Course Project\Controls to the Controls
virtual folder. This control enqueues items to this queue from subVIs.
rib en
Display Module
on
Create a module that stores which function the display should perform. As
the application runs, update the display. Complete the following steps to
ist um
create the display module.
1. Add the display module files and Display virtual folder to the Modules
virtual folder.
tlc_Display Module.vi
tlc_Display_Command Control.ctl.
No na
uti ts
rib en
on
ist um
r D str
Figure 6-12. Display Module Initialize Case
t fo l In
4. Modify the Update UI case to call the Enqueue Element function to pass
No na
the command and data to the display loop in the top-level VI, as shown
in Figure 6-13. Use the following items to complete this case:
uti ts
rib en
on
ist um
r D str Figure 6-13. Display Module Update UI Case
File Module
tio
The file module saves and loads a file from the application. The file module
accepts an array of cues, a file path, and a command, and returns an array of
cues. The file module performs the Save Cues and Load Cues functions.
1. Add the file module files and File virtual folder to the Modules virtual
Na
folder.
uti ts
tlc_File Module.vi
tlc_File_Command Control.ctl
rib en
2. Save the project.
on
3. Open tlc_File Module.vi and observe the architecture and design
ist um
of the module. The module uses standard File I/O VIs to read and write
data.
Testing
r D str Test the functionality of the file module with simple hand tests.
2. Click the Browse button and set a name and save location for a new file.
The Path control has been set to browse for new or existing files.
t fo l In
3. Enter dummy data in the Cue Array Input.
7. Verify that Cue Array Output matches the data you entered in
Cue Array Input.
tio
Hardware Module
The hardware module interacts with the Theatre Light Control API. The
Na
1. Add the hardware module files and Hardware virtual folder to the
Modules virtual folder.
uti ts
tlc_Hardware Module.vi
tlc_Hardware_Command Control.ctl
rib en
2. Open tlc_Hardware Module.vi.
on
3. Observe the architecture and design of the hardware module. Notice that
ist um
the VI calls the Theatre Light Control API.
uti ts
Develop a module that handles the errors in the application.
Scenario
rib en
Handling errors is an important part of developing applications in
LabVIEW. When you are developing the application, you can use error
on
handling to help find bugs in the applications.
A good error handling strategy is to call a module that stores the error
ist um
information and safely stops the application if an error occurs.
Design
Using a functional global variable, store the error information in an
r D str uninitialized shift register. If an error occurs, the VI sends a stop message to
the producer to shut the program down.
Implementation
1. Add tlc_User Event Reference.ctl and tlc_Consumer
t fo l In
Queue Reference.ctl to the project. These custom controls are
references to the user event created by Create User Event and the queue
created by Obtain Queue in the TLC Main VI. These custom controls
stop execution of the producer and consumer loops of the TLC Main VI
if an error occurs.
2. Add the error module files and Error virtual folder to the Modules
virtual folder.
uti ts
tlc_Error Module.vi
rib en
3. Open tlc_Error Module.vi.
on
4. Modify the block diagram to stop the producer, consumer, and display
ist um
loops if an error occurs. Use the following items to complete the case
where the structures are set to Handle Errors, Error, and True, as shown
in Figure 6-15.
Create constants for the element input of each instance. For the
consumer queue, set the first enum to Stop and set the second enum
to Exit. For the display queue, set the enum to Stop.
No na
uti ts
rib en
on
ist um
Figure 6-15. Error Handler Error Case
5. Complete all structures by wiring the User Event reference and queue
r D str references through all remaining cases.
Notes
uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
uti ts
Exercise 7-1 Integrate Initialize and Shutdown Functions
rib en
Goal
on
Initialize and shut down a set of code modules.
ist um
Scenario
The Initialize function places the application into a stable mode by
initializing all of the modules and clearing the user interface.
r D str When the user selects the FileExit menu, the application should safely shut
down. Safely shutting down an application requires closing all open
memory references.
Design
The Initialize function outlined in the requirements document performs the
t fo l In
following actions:
Initialize Error Module
Initialize Cue Module
Initialize File Module
No na
Each module is designed to close any open memory references when the
shutdown function is called. The Shutdown VI accesses the shutdown
Na
function for each module. The Shutdown VI also sends a Stop message to
the display loop to finish execution of the loop. The display, hardware, and
file modules need to shut down. You can re-initialize the Cue module to
delete any Cues that are stored in the persistent shift register.
Implementation
The implementation of the Initialize VI involves calling the modules that
you built and wiring the correct data type to them. There is not a specific
order in which you must call the VIs. Follow the order in the Design section
to be complete.
Initialize
uti ts
1. Add the integration files and Integration virtual folder to the project.
rib en
Folder (Snapshot) from the shortcut menu.
on
Project\Integration directory and click Current Folder to
add the folder and its contents to the project tree.
ist um
2. Open tlc_Initialize.vi.
Note In later instances, the Data input of the tlc_Display Module VI is set to 2, which
disables the controls.
tlc_Hardware Module VI
tlc_Display Module VI
uti ts
rib en
on
ist um
uti ts
rib en
Figure 7-2. Initialize Function Icon and Connector Pane
on
5. Save and close the VI and save the project.
ist um
6. Open the TLC Main VI.
Note As you integrate each function into the application, delete the Format Into String
and One Button Dialog functions in the corresponding case of the Case structure.
Note The labels for the cluster constants in Figure 7-3 have been made visible to
differentiate between the parameters in each cluster.
tio
Na
Wire the user event out output of the Create User Event function
outside the While Loops to the tlc_User Event Reference.ctl input
uti ts
of the tlc_Initialize VI.
Wire the queue out output of the Obtain Queue function outside the
display loop to tlc_Display Queue Reference.ctl input of the
rib en
tlc_Initialize VI.
on
Wire the queue out output of the Dequeue Element function inside
the consumer loop to the tlc_Consumer Queue Reference.ctl input
ist um
of the tlc_Initialize VI.
Shutdown
1. Open tlc_Shutdown.vi from the Integration virtual folder.
r D str 2. Complete the block diagram as shown in Figure 7-4.
t fo l In
4. Open the TLC Main VI and add the tlc_Shutdown VI to the Exit case of
the consumer loop. Run the error wire through the tlc_Shutdown VI.
Testing
1. Run the TLC Main VI and select FileExit. Verify that the shutdown
function causes the application to end. After you integrate the display
functionality, you also can verify that the initialize function executes.
uti ts
Update the front panel controls.
Scenario
rib en
The application architecture splits the functionality into three separate
loops. The producer loop uses an Event structure to monitor changes to the
on
front panel. The consumer loop handles all the processing for the
application. The display loop updates the user interface. The advantage of
this architecture is that functionality is contained within individual parallel
ist um
processes. This improves the performance and stability of the application.
The three loop architecture also improves the maintainability and scalability
of the application.
r D str Implement the code in the display loop to update the user interface.
Design
In order to perform the functions specified in the requirements document,
you need to have the following display functions:
t fo l In
Initialize Front Panel
Implement these functions in the display loop of the top-level VI. The
tio
Implementation
Na
Edit the following cases in the display loop Case structure of the TLC
Main VI.
1. Modify the Initialize Front Panel case as shown in Figure 7-5 using the
following items.
uti ts
Cue Information.
rib en
return an empty cue with an intensity of zero, a color of black, and
configured channel numbers.
on
Cue Information local variableRight-click the Cue Information
ist um
terminal and select CreateLocal Variable from the shortcut menu.
r D str
t fo l In
1. Modify the Select Cue in Cue List case of the display loop as shown in
Figure 7-6. Use the following items:
uti ts
rib en
on
ist um
Figure 7-6. Select Cue in Cue List Case
uti ts
rib en
on
ist um
Figure 7-7. Enable/Disable Front Panel Controls Case
Note Coercion dots appear where you wire data to the Property Nodes because the
Property Nodes expect an enum instead of a numeric value.
r D str 2. Save the VI.
1. Modify the Update Cue List case of the display loop as shown in
Figure 7-8. Use the following items:
For Loop
No na
Add the VI inside the Case structure and outside the For Loop.
tio
For Loop to execute the loop once for each cue in the list.
cluster containing the cue name, wait time, fade time, follow
time, and the 2D array of channels associated with the cue.
uti ts
to the input cluster to retrieve the Cue Name element.
Wire the error clusters of the Cue Module VIs through the For Loop.
Create shift registers on the For Loop error tunnels.
rib en
Cue List Property NodeCreate a Property Node to modify the
on
Item Names property of the Cue List indicator.
ist um
Right-click the Property Node and select Change All To Write
from the shortcut menu.
This case updates the value of the 2D array of channels. The VI calls this
case every time the channel data changes, such as when a cue is playing and
the channel intensities and colors change. The VI also calls this case when
the user selects a cue from the Cue List to display the information for the
selected cue.
1. Modify the block diagram for the Update Front Panel Channels case of
the display loop as shown in Figure 7-9. Use the following items:
uti ts
tlc_Cue_Information.ctlAdd this control to the block
diagram as a constant and wire it to the type input of the Variant to
Data function. This converts the Variant input of Variant to Data to
rib en
a cue in order to display the cue information.
on
Cue Information terminalMove this terminal into the Update
Front Panel Channels case of the display loop.
ist um
r D str
t fo l In
Testing
1. Run the VI.
2. The VI calls the Initialize function. The function initializes the front
panel. All the front panel channels should initialize with the correct
tio
uti ts
Pass data from the user interface to the rest of the application. Use an Event
structure to create a dialog box where the user enters cue information to
record a cue.
rib en
Scenario
on
The record function must prompt the user for the Cue Name, Wait Time,
Fade Time, Follow Time, and settings for the channels. Prompt the user with
a dialog box where the user can enter values. The values are passed to the
ist um
Cue module and the user interface updates.
Design
A Record dialog box has been created using the Dialog Based Events
framework. This framework uses an Event structure to monitor user
r D str interface events. Complete the functionality to retrieve the inputs from the
user. Pass a Cue Data type from the producer loop into the consumer loop to
store the recorded cue in the application. Use a variant for the design pattern
makes it easier to perform this functionality.
t fo l In
Implementation
1. Open the tlc_Record Dialog Box VI from the Integration virtual folder.
When this dialog box displays, the user enters values for Cue Name,
Wait Time (s), Fade Time (s), and Follow Time (s) and sets cue
intensities and colors in the channel array.
No na
2. Set the minimum value for Fade Time (s) to one second.
Remove the checkmark from Use Default Limits and enter 1 as the
Minimum value.
Click OK.
Na
3. Open the block diagram and create a constant from the command input
of the tlc_Cue Module VI. Set the command to Get Empty Cue,
as shown in Figure 7-10.
uti ts
rib en
on
ist um
r D str Figure 7-10. Record Function Dialog Box
4. Modify the connector pane to pass the Output Cue parameter, as shown
in Figure 7-11.
t fo l In
Modify the front panel of the VI to expand the input cluster, align the
objects, and hide the error clusters.
tio
Resize the front panel to show only the buttons and the input cluster.
Dialog. Change the Window Title to Cue Record and click OK.
uti ts
rib en
on
ist um
Figure 7-12. Front Panel of Record Dialog Box
r D str 6. Save and close the VI.
Wire the queue refnum and error wires through the True case.
Na
uti ts
rib en
on
ist um
Figure 7-13. Record Event Case
r D str 9. Test the TLC Main VI. Verify that the Cue Record dialog box appears
when you click Record. After clicking OK in the Cue Record dialog
box, a One Button Dialog should appear indicating that you are in the
Record case of the consumer loop. Click OK.
11. Open the tlc_Record VI from the Integration virtual folder and
examine the block diagram. The VI first uses the display module to
update the 2D array of channels. Next, it calls the cue module to add the
new cue to the functional global variable cue array. Finally, it calls the
display module again to update the Cue List.
No na
13. Modify the consumer loop to call the Record VI and convert the variant
data into data that the Record VI can accept. Figure 7-14 shows the
tio
completed Record case in the consumer loop. Use the following items:
tlc_Cue_Information.ctl constant
Na
tlc_Record.vi
uti ts
rib en
on
Figure 7-14. Record Case in Consumer Loop
ist um
14. Save the VI.
Testing
r D str 1. Run the TLC Main VI.
3. If the application is running correctly, the front panel displays the cue
you recorded, and the Cue List updates with the name of the cue that you
t fo l In
entered in the Cue Record dialog box.
Note If time permits, proceed to Exercise 7-7. Alternately, you can copy the save and
load functionality into your project at the beginning of Exercise 7-5.
No na
uti ts
Execute a state machine design pattern in a producer/consumer (events)
design pattern.
Scenario
rib en
The Play functionality for the Theatre Light Controller is best implemented
on
as a state machine. Figure 7-15 shows the states of the Play function.
ist um
Start
Cue
Exists
Initialize Begin Play Load Cue Wait Time
r D str Cue Does Not Exist Cue Exists
Cue
Does Not
Exist Check for
End Follow Time Fade Time
t fo l In
Next Cue
design pattern operates. As you have seen in previous exercises, the design
pattern receives an event in the producer loop and sends a message to the
consumer loop to do some computation on the event. The consumer loop is
designed to compute a single message from the producer. Implementing a
state machine requires a looping mechanism that is not native to the
tio
application. Add messages in the consumer queue to stay in the Play case in
the consumer loop until the Play function completes. This method of
implementing a state machine inside the producer/consumer (events) design
pattern introduces some complexities when you implement the capability to
stop a play.
Design
The Play function uses a state machine and the timing module to implement
the wait, fade, and follow timing requirements.
uti ts
After you develop the play module, integrate the play function into the TLC
Main VI.
rib en
Implementation
Build the play functionality to add in the consumer loop. Start by examining
on
the play VIs.
ist um
1. Open tlc_Play_Update Cue.vi from the Integration virtual folder
and examine how the VI operates.
The VI calls the Light Color Controller VI, which calculates a color
based on desired color, desired intensity, elapsed time, and target time.
r D str The VI sends a command to the hardware module and display module.
The VI uses the state machine design pattern with a True constant wired
to the loop conditional terminal. This VI is designed to be called
repeatedly in order to move from one state to the next. To control the VI,
No na
the state machine returns a Boolean value to indicate whether the cue list
has completed execution. Examine how the Initialize, Begin Play, and
Load Cue states operate.
3. Modify the Wait Time state in the tlc_Play VI to use the tlc_Timing
tio
tlc_Timing Module.vi
Add two tlc_Timing Module VIs inside the Wait Time state.
uti ts
rib en
on
ist um
r D str
t fo l In
Case structure
structure output tunnel. This tunnel is wired to the While Loop shift
register. When the tlc_Timing Module VI outputs True from the
Done? output, the Select function transitions the state machine to the
Fade Time state.
Wait (ms) functionAdd a Wait (ms) function to the case and wire
a numeric constant of 25 to the Wait function.
4. Modify the Fade Time state in the tlc_Play VI to use the tlc_Timing
Module functional global variable to control the timing as shown in
Figure 7-17. Use the following items:
uti ts
and set the cluster element to Fade Time (s).
tlc_Timing Module.vi
rib en
Add two copies of this VI inside the Fade Time state.
on
Right-click each tlc_Timing Module VI and select Create
Constant. Set each constant as shown in Figure 7-17.
ist um
r D str
t fo l In
No na
tio
Case structure
uti ts
Wire the Done? terminal of the tlc_Timing Module VI to the
case selector terminal. If the tlc_Timing Module VI outputs True
from the Done? output, the Case structure sends the tlc_Timing
rib en
module a Start command to set a new start time.
on
Wire the error cluster through the False case.
ist um
structure output tunnel. This tunnel is wired to the While Loop shift
register. When the tlc_Timing Module VI outputs True from the
Done? output, the Select function transitions the state machine to the
Follow Time state.
r D str Wait (ms) function with a 25 ms wait.
5. Modify the Follow Time state in the tlc_Play VI to use the tlc_Timing
Module functional global variable to control the timing as shown in
Figure 7-18. Use the following items:
t fo l In
uti ts
rib en
on
ist um
r D str
t fo l In
Figure 7-18. Play Module Follow Time Case
7. Open TLC Main VI and modify the Play state in the consumer loop to
call the tlc_Play VI. Add the functionality to repeatedly call the tlc_Play
VI, as shown in Figure 7-19. Use the following items:
selector terminal.
uti ts
rib en
on
Figure 7-19. Play Case in Consumer Loop
ist um
8. Save the VI.
Testing
r D str At this point, you can run the VI, record a cue, and play back the cue.
2. Record a cue with a single channel that contains a color other than black,
and an intensity of 100. Set the Wait time to 0, Fade time to 10, and
t fo l In
Follow time to 0. Click OK.
3. Click Play.
4. The channel that you recorded should fade from 0% to 100% intensity
within 10 seconds.
No na
5. Try recording another cue and observe the response of the system.
Note If time permits, proceed to Exercise 7-8. Alternately, you can copy the stop
functionality into your project at the beginning of Exercise 7-5.
uti ts
Integrate an error handling module into the design pattern.
Scenario
rib en
When working on large applications, it is often helpful to distribute the
development effort for the project among several developers. Another
on
developer received a copy of your code after you integrated the Play
functionality. That developer has integrated the Save, Load, and Stop
functions into TLC Main.vi. Before you can integrate your error handling
ist um
module into the design pattern, you must overwrite your working copy of
the TLC project with their files.
Note Refer to Exercise 7-7 and Exercise 7-8 for more information about the changes the
r D strdeveloper made. If you want to make these changes yourself, complete Exercise 7-7 and
Exercise 7-8 before you begin Exercise 7-5.
The Error module that you built is designed to safely shutdown the
application if an error occurs. Shutting down the producer loop requires
sending a user event to the producer loop. Shutting down the consumer loop
t fo l In
requires placing an Exit message in the queue. Shutting down the display
loop requires placing a Stop message in the queue.
executing the cases in each of the application loops that cause the loops to
stop.
Design
tio
Update the TLC project to the current version and modify the TLC Main VI
to call the Error module after each computation in the producer, consumer,
and display loop.
Na
Implementation
1. Copy the updated version of the TLC project and overwrite your
working copy of the code.
Note If you have completed self-study Exercises 7-7 and 7-8, skip to step 3 of this
exercise.
uti ts
Project\ and paste TLC.lvproj and TLC Main.vi. When
prompted, overwrite the existing files.
rib en
Open the TLC project and the TLC Main VI.
on
2. Test the new code.
ist um
Record a cue and play it. Verify the stop functionality by clicking the
Stop button during play.
r D str Select FileSave and save the data file as File Test.dat in the
<Exercises>\LabVIEW Core 3 directory.
Play the loaded cue list and verify that the cues match the saved cues.
3. Modify the TLC Main VI to call the Error module after each
computation in the producer, consumer, and display loop, as shown in
Figure 7-20. Use the following items:
tio
Na
tio
No na
t fo l In
7-26
r D str
ist um
rib en
uti ts
on
Figure 7-20. Producer/Consumer Design Pattern with Error Module
ni.com
Lesson 7 Implementing a Test Plan
Testing
1. Test the error handling capability by placing a Diagram Disable
structure over the Clear Specific Error VI in the producer loop.
uti ts
You can use the Diagram Disable structure to comment out code when
you want to test functionality or isolate problem areas.
In the producer loop, navigate to the False case in the Open case of
rib en
the Menu Selection User Event structure, as shown in Figure 7-21.
on
ist um
r D str
t fo l In
Figure 7-21. Producer Loop with Diagram Disable Structure
wire the error cluster through the case as shown in Figure 7-22.
tio
Na
Figure 7-22. Enabled Case of Producer Loop with Diagram Disable Structure
uti ts
If the error module works correctly, the Simple Error Handler VI
displays a dialog box indicating that Error 43 occurred, and the
rib en
application stops because the error module stops each loop in the
application.
on
4. Enable the case of the Diagram Disable structure that contains the Clear
ist um
Specific Error VI.
Switch to the block diagram and navigate to the Disabled case of the
Diagram Disable structure.
r D str Right-click the border of the Diagram Disable structure and select
Enable This Subdiagram.
Challenge
t fo l In
Integrate the Select Cue function to update the user interface with the values
in a selected recorded cue. There are two primary tasks that must be
implemented to build the Select Cue functionality. The Select Cue function
must acquire the cue values for the selected cue and update the front panel
with the cue values.
No na
4. Modify the producer loop to pass the index of the selected cue to the
consumer loop.
Na
5. Modify the consumer loop to get the selected cue value and update the
front panel.
6. To test your changes, record several cues. Click each row in the cue list.
The Cue Information cluster should update with the information for
each cue that you select.
uti ts
Perform stress and load testing on the application.
Scenario
rib en
Before releasing an application, you must perform a set of system level tests.
These tests can consist of usability testing, performance testing, stress, and
on
load testing.
Design
ist um
Create a large set of cues stored in a file that contain random wait times, fade
times, follow times, channel colors, and intensities. The VI that creates the
large set of cues requests maximum values to use for the wait, fade, and
follow times so that it is easier to analyze the functionality of the
application.
r D str
Implementation
1. Open System Testing Driver.vi from the <Exercises>\
LabVIEW Core 3\Course Project\System Testing directory.
t fo l In
2. Open the block diagram and examine how this VI uses the modules that
you implemented to create a large set of Cues.
8. Click Play.
9. Open the Windows Task Manager and monitor the memory usage and
performance of the Theatre Light Controller. Running TLC Main VI
uti ts
with a large number of cues can indicate if there is a memory or
performance issue with the application.
rib en
11. Select FileExit to stop the VI.
on
End of Exercise 7-6
ist um
r D str
t fo l In
No na
tio
Na
uti ts
Use a scalable data type to pass data from the consumer to the producer.
Scenario
rib en
The file save and load functionality are important for the lighting designers
who use the software. Most theatres orchestrate the lighting for a production
on
during dress rehearsals and the lighting designer uses the same lighting cues
from dress rehearsal for opening night and beyond. Save and load
functionality is important for any large scale application.
ist um
Design
Modify the producer loop in the TLC Main VI to prompt the user for the file
name. Several checks need to occur to determine if the user cancels the file
operation or tries to open a file that does not exist.
r D str Modify the Save case in the consumer loop to get the values stored in the
cue module and pass the recorded Cues to the file module.
Modify the Load case in the consumer loop to open the file and extract the
t fo l In
saved cues, while populating the cue module with the saved cues.
Implementation
Note The code changes described in this exercise are integrated into the TLC Main VI
as step 1 of Exercise 7-5. The purpose of this exercise is to describe the changes that were
No na
made to integrate the save and load functions into the application. If you are working
through all the Lesson 7 exercises, you should complete this exercise after Exercise 7-3.
Modify the Save case in the consumer loop to get the values stored in the
tio
cue module and pass the recorded Cues to the file module.
Save
1. Add the shared files and Shared virtual folder to the project.
Na
3. Modify the Save case in the Menu Selection event of the producer loop,
as shown in Figure 7-23. Use the following items:
uti ts
Launches a dialog box to select a file to load. Verify that
Limit selection to single item is selected. Select File and New.
Click OK.
rib en
If the user selects an existing file, the File Dialog Express VI
on
prompts the user to replace the file. The File Dialog Express VI
returns True for the exists output if the user replaced the file. If
ist um
the user cancels a save operation, the cancelled output returns
True.
Case structure
uti ts
rib en
on
ist um
Figure 7-23. Producer Save Case True Case
5. Modify the Save Consumer case to perform the Save function as shown
in Figure 7-25. Use the following items:
For LoopThis loop iterates through the cues in the Cue List.
tlc_Cue Module.vi
Add the first instance of this VI outside the For Loop and set the
uti ts
command input to Get Number of Cues.
Wire the Number of cues output to the count terminal of the For
rib en
Loop to determine the number of iterations needed to save the
Cue List data.
on
tlc_Cue Module.vi
ist um
Add the second instance inside the For Loop and set the
command input to Get Cue Values.
Wire the iteration terminal to the Cue Index input of the cue
r D str module to retrieve each cue in the list.
Wire the Cue Output output of the cue module to the Cue Array
t fo l In
Input of the file module. Verify that indexing is enabled on the For
Loop tunnel.
No na
tio
Load
Modify the Load case in the consumer loop to open the file, extract the saved
cues, and populate the cue module with the saved cues.
1. Create the Open case in the Menu Selection (User) event case of the
producer loop, as shown in Figure 7-26. It is easiest to create the Open
case by duplicating the Save case and modifying the File Dialog
Express VI.
Delete the existing Open case of the Case structure inside the Menu
uti ts
Selection (User) event case.
Right-click the Save case and select Duplicate Case from the
shortcut menu.
rib en
Enter Open in the case selector label.
on
Double-click the File Dialog2 Express VI to configure it. Select File
ist um
and Existing. Click OK.
r D str
t fo l In
No na
3. Complete the Load case of the consumer loop in the TLC Main VI,
as shown in Figure 7-27. Use the following items:
Wire the data output of the Variant to Data function to the Path
input of the tlc_Load VI.
Right-click the type input of the Variant to Data function and select
uti ts
CreateConstant to create the path constant.
rib en
on
ist um
Figure 7-27. Load Function
r D str 4. Save the VI.
Testing
t fo l In
1. Run the TLC Main VI.
Note If you are working through all the Lesson 7 exercises, proceed to Exercise 7-4.
uti ts
Flush a queue to guarantee when a command is sent.
Scenario
rib en
The requirements for the application state that the user can stop a playing
cue by clicking the Stop button. This exercise implements that capability.
on
Design
ist um
When the user clicks the Stop button, the Event structure generates an event
to process the Stop button. To guarantee that the application responds to the
Stop button, flush the queue that controls the consumer loop to remove any
messages stored in the queue.
r D str Make the following modifications to the TLC Main VI:
In the producer loop, modify the Stop event case to flush the queue and
call the tlc_Timing Stop Module VIs.
In the consumer loop, modify the Stop case to enable the front panel
t fo l In
controls.
Implementation
Note The code changes described in this exercise are integrated into the TLC Main VI
as step 1 of Exercise 7-5. This exercise describes the changes that were made to integrate
No na
the stop function into the application. If you are working through all the Lesson 7
exercises, you should complete this exercise after Exercise 7-4.
2. In the producer loop, add the Flush Queue function to the Stop event
case to flush the queue, as shown in Figure 7-28.
Na
uti ts
rib en
on
ist um
Figure 7-28. Producer Stop Event Case
Because the consumer loop runs in parallel with the producer loop,
it is possible that the Play case of the consumer loop could enqueue
t fo l In
a play command after the user clicks Stop and the queue is flushed
in the producer loop.
4. In the consumer loop of the TLC Main VI, modify the Stop case as
shown in Figure 7-29. This case should stop execution of the cue list and
tio
uti ts
rib en
on
ist um
Figure 7-29. Consumer Stop Case
Testing
1. Run the TLC Main VI.
r D str 2. Record a cue, and play the cue. Verify that the stop functionality works
by clicking the Stop button during play.
Note If you are working through all the Lesson 7 exercises, proceed to Exercise 7-5.
Notes
uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
uti ts
Exercise 8-1 Identify VI Issues with VI Metrics
rib en
Goal
on
Determine the complexity of the VI.
ist um
Scenario
Use VI Metrics to determine the complexity of a VI and identify issues with
the application.
Designr D str Run the VI Metrics tool to determine the complexity of the VI.
Implementation
1. Open the TLC Main VI.
t fo l In
2. Select ToolsProfileVI Metrics.
Globals/locals
CINs/shared lib calls
SubVI interface
tio
Notice the number of global and local variables that this application
uses.
uti ts
Compare the performance of different methods for updating indicators.
Description
rib en
There are three primary methods for updating user interface values:
Wire data directly to an indicatorFastest and preferred method of
on
passing data to the user interface.
Wire data to a local variableGood method for initializing data that is
ist um
in a control.
Wire data to a Value Property Node of the indicatorUse this method
to update the control or indicator directly on the block diagram or in a
subVI through a control reference.
r D str Each of these methods has performance differences. This exercise
demonstrates the performance of each of these methods.
Implementation
1. Open Methods of Updating Indicators.vi from the
t fo l In
<Exercises>\LabVIEW Core 3\Methods of Updating
Indicators directory.
3. Run the VI for each of the methods by setting the Method enum, and
No na
running the VI. Observe how long the VI takes to run for each method.
Notes
uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
Notes
uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
uti ts
Exercise 9-1 Document User Interface
rib en
Goal
on
Document the user interface.
ist um
Scenario
Document the user interface. You must document the front panel of every
VI that you create.
Designr D str Document the TLC Main VI. Good documentation includes a description of
the VI, and a meaningful description and tip for each control and indicator.
Implementation
t fo l In
1. Open the TLC Main VI.
Functionality
Data type
uti ts
You also can list the default value in parentheses as part of the
control or indicator label.
Behavior for special values (0, empty array, empty string, and so on)
rib en
4. Save the VI.
on
End of Exercise 9-1
ist um
r D str
t fo l In
No na
tio
Na
uti ts
Use features in LabVIEW to create professional documentation for the
application.
Scenario
rib en
Documentation is an important part of developing applications that are
on
scalable, readable, and maintainable. Also, the end user of the application
requires documentation in order to use the system. LabVIEW assists in
developing documentation. LabVIEW can automatically generate HTML or
ist um
RTF documents that document the functionality of the application. After
LabVIEW generates the documentation, the developer can edit and expand
the documentation for other developers who maintain the application, and
for the end user.
Design
r D str Use the Print dialog box to generate an HTML document that you can link
to the VI Properties of the TLC Main VI.
Implementation
t fo l In
7. Click Save.
uti ts
Testing
1. Open the Context Help window.
rib en
2. Idle your mouse over the icon/connector pane of the TLC Main VI.
3. Click the Detailed help link in the Context Help window to load the
on
documentation for the application.
ist um
End of Exercise 9-2
r D str
t fo l In
No na
tio
Na
Notes
uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
Notes
uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
uti ts
Exercise 10-1 Implementing Code for Stand-Alone
rib en
Applications
on
Goal
Create an About dialog box that you can use in your own applications.
ist um
Scenario
Most applications have an About dialog box that displays general
information about the application and the user or company that designed it.
You can create a VI that LabVIEW runs when a user selects HelpAbout to
r D str display information about the stand-alone application you create.
You can use a Case structure and the Application:Kind property to execute
different code based on the LabVIEW instance the VI is running in,
including invalid application types. In this case, you want to call the Quit
LabVIEW function if the application is running in the LabVIEW Run-Time
tio
Engine.
Design
1. Implement a dialog box VI that uses an Event structure to create an
About dialog box.
Create a dialog box VI that closes when the user clicks the mouse
anywhere on the VI.
2. Add a Case structure around the Quit LabVIEW function and use an
App.Kind Property Node to quit LabVIEW when the code is running in
the Run-Time Engine.
uti ts
3. Modify the properties of the VI to prepare for building a stand-alone
application.
Implementation
rib en
About Dialog Box
on
1. Create a dialog box VI that closes when the user clicks the mouse button
anywhere on the VI.
ist um
Create a new VI within the TLC project.
Note The front panel window must include a National Instruments copyright notice.
Refer to the National Instruments Software License Agreement located on the LabVIEW
DVD or CD for more information about the requirements for any About dialog box you
t fo l In
create for a LabVIEW application.
Add any free text or images you want to the front panel.
3. Switch to the block diagram and add code to close the dialog box when
the user clicks the mouse button anywhere on the VI, as shown in
Figure 10-1.
tio
Na
Add an Event structure to the block diagram and edit an Event case
for the Mouse Down event for the <Pane> event source.
Note You must save the About VI at the same level of the file hierarchy as the top-level
uti ts
VI for the About dialog box to display when the user selects HelpAbout.
rib en
6. Open the TLC project. Verify that the About VI displays in the project
on
hierarchy at the same level as the TLC Main VI.
ist um
8. Modify the TLC Main VI so the run-time menu contains HelpAbout
LabVIEW. When the user selects HelpAbout in the stand-alone
application, the About dialog box displays. Figure 10-2 shows the
r D str completed Run-Time Menu Editor.
t fo l In
No na
tio
Open the TLC Main VI. Select EditRun-Time Menu to open the
Menu Editor.
Na
Add the Help menu item by adding a User Item for Help, with the
Item Name set to _Help and the Item Tag set to Help. Use the
arrow buttons to move the entry below the other entries and in line
with File, as shown in Figure 10-2.
Add the About LabVIEW item below the Help menu item by
selecting EditInsert Application ItemHelpAbout LabVIEW.
uti ts
application runs in the Run-Time Engine, for example, when it runs as a
stand-alone application. Implement this functionality as shown in
Figure 10-3.
rib en
on
ist um
r D str Figure 10-3. Quit LabVIEW
Add a Property Node to the block diagram of the TLC Main VI.
Wire the App.Kind output of the Property Node to the case selector
terminal of the Case structure.
tio
Right-click the Case structure and select Add Case for Every
Value. Each case represents a different LabVIEW execution
environment.
Na
2. Wire the diagram as shown in Figure 10-3. The Quit LabVIEW function
must be the last function that executes.
Window Appearance
1. Select FileVI Properties and select Window Appearance from the
Category list.
uti ts
2. Select Top-level application window and click OK.
rib en
checkmark in the Same as VI name checkbox.
on
End of Exercise 10-1
ist um
r D str
t fo l In
No na
tio
Na
uti ts
Create a build specification and build a stand-alone application (EXE) in
LabVIEW.
Scenario
rib en
Creating a stand-alone application is important for distributing and
on
deploying your application. It is also a step in the creation of a professional
installer.
ist um
Design
Use the Application (EXE) Build Specifications to create a stand-alone
application for the Theatre Light Controller.
Implementation
r D str 1. Create a stand-alone application of the Theatre Light Controller.
Select the Source Files page and select TLC Main.vi in the
tio
Project Files listbox. Click the right arrow to add the VI to the
Startup VIs listbox.
Select About.vi in the project hierarchy and click the right arrow
to add the VI to the Always Included listbox.
Na
Select the Icon page and use the Icon Editor to create a color icon
for both the 32 32 and 16 16 icons. Save the new icon in the
<Exercises>\LabVIEW Core 3\Course Project\Icons
directory.
Deselect Use the default LabVIEW Icon file and browse to the
.ico file you created.
Select the Preview page and click Generate Preview to preview the
output of the Build Specification.
Select the Advanced page and add a checkmark to the Copy error
uti ts
code files checkbox to include the custom error code that you
developed.
Click OK.
rib en
2. Save the project.
on
3. Right-click the build specification in the project tree and select Build
ist um
from the shortcut menu.
Testing
Navigate to the directory you specified for the destination directory and run
r D str the executable.
uti ts
Create a professional installer for your application.
Scenario
rib en
A professional application should always have an installer to deploy the
application. Providing an installer improves the end user experience with the
on
application.
Design
ist um
Create an installer build specification for the executable you created.
Implementation
r D str Create an installer for the Theatre Light Controller.
5. Select the Source Files page and verify that a folder that matches your
project name exists under ProgramFilesFolder in Destination View. If
no folder exists for your project, add a folder and provide a meaningful
name for the folder.
tio
7. Select the Shortcuts page to edit the shortcut the installer creates in the
ProgramMenuFolder in Windows. Change the Name to Theatre
Light Controller. This places the item in the StartPrograms
menu.
9. Click OK.
11. Right-click the installer build specification and select Build from the
shortcut menu.
uti ts
Testing
Navigate to the installer destination directory you specified and run the
rib en
installer. After the installer runs, verify the installation of the Theatre Light
Controller.
on
Note These are the ideal conditions for testing an installer. For a more accurate test,
ist um
try your installer on a computer that does not have LabVIEW installed.
r D str
t fo l In
No na
tio
Na
Notes
uti ts
rib en
on
ist um
r D str
t fo l In
No na
tio
Na
uti ts
This appendix contains additional information about National Instruments
rib en
technical support options and LabVIEW resources.
on
Visit the following sections of the award-winning National Instruments
ist um
Web site at ni.com for technical support and professional services:
SupportTechnical support at ni.com/support includes the
following resources:
Self-Help Technical ResourcesFor answers and solutions,
visit ni.com/support for software drivers and updates,
r D str a searchable KnowledgeBase, product manuals, step-by-step
troubleshooting wizards, thousands of example programs, tutorials,
application notes, instrument drivers, and so on. Registered
users also receive access to the NI Discussion Forums at
t fo l In
ni.com/forums. NI Applications Engineers make sure every
question submitted online receives an answer.
Standard Service Program MembershipThis program entitles
members to direct access to NI Applications Engineers via phone
and email for one-to-one technical support as well as exclusive
access to on demand training modules via the Services Resource
No na
ni.com/contact.
System IntegrationIf you have time constraints, limited in-house
technical resources, or other project challenges, National Instruments
Alliance Partner members can help. The NI Alliance Partners joins
Na
If you searched ni.com and could not find the answers you need, contact
your local office or NI corporate headquarters. Phone numbers for our
worldwide offices are listed at the front of this manual. You also can visit the
uti ts
Other National Instruments Training Courses
National Instruments offers several training courses for LabVIEW users.
rib en
These courses continue the training you received here and expand it to other
areas. Visit ni.com/training to purchase course materials or sign up for
on
instructor-led, hands-on courses at locations around the world.
ist um
Earning an NI certification acknowledges your expertise in working with
NI products and technologies. The measurement and automation industry,
your employer, clients, and peers recognize your NI certification credential
r D str as a symbol of the skills and knowledge you have gained through
experience. Visit ni.com/training for more information about the
NI certification program.
LabVIEW Resources
t fo l In
This section describes how you can receive more information regarding
LabVIEW.
LabVIEW Publications
Many books have been written about LabVIEW programming and
No na
applications. The National Instruments Web site contains a list of all the
LabVIEW books and links to places to purchase these books. Visit
zone.ni.com/devzone/cda/tut/p/id/5072 for more information.
tio
Na
uti ts
Instructor _________________________________________ Date ____________________________________
rib en
Company _________________________________________ Phone ___________________________________
on
Instructor
Please evaluate the instructor by checking the appropriate circle. Unsatisfactory Poor Satisfactory Good Excellent
ist um
Instructors ability to communicate course concepts
Instructors knowledge of the subject matter
Instructors presentation skills
Instructors sensitivity to class needs
Instructors preparation for the class
Course
r D str
Training facility quality
Training equipment quality
Was the hardware set up correctly? Yes No
The course length was Too long Just right Too short
t fo l In
The detail of topics covered in the course was Too much Just right Not enough
The course material was clear and easy to follow. Yes No Sometimes
Did the course cover material as advertised? Yes No
I had the skills or knowledge I needed to attend this course. Yes No If no, how could you have been
better prepared for the course? ____________________________________________________________________
No na
_____________________________________________________________________________________________
What were the strong points of the course? __________________________________________________________
_____________________________________________________________________________________________
What topics would you add to the course? ___________________________________________________________
tio
_____________________________________________________________________________________________
What part(s) of the course need to be condensed or removed? ____________________________________________
_____________________________________________________________________________________________
What needs to be added to the course to make it better? ________________________________________________
Na
_____________________________________________________________________________________________
How did you benefit from taking this course? ________________________________________________________
_____________________________________________________________________________________________
Are there others at your company who have training needs? Please list. ____________________________________
_____________________________________________________________________________________________
_____________________________________________________________________________________________
Do you have other training needs that we could assist you with? _________________________________________
_____________________________________________________________________________________________
How did you hear about this course? NI Web site NI Sales Representative Mailing Co-worker
Other ______________________________________________________________________________________
Na
tio
No na
t fo l In
r D str
ist um
rib en
uti ts
on