AAL Exercise Manual
AAL Exercise Manual
LabVIEW Exercises TM
Copyright
© 2009–2012 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
license or other legal restriction.
For components used in USI (Xerces C++, ICU, HDF5, b64, Stingray, and STLport), the following copyright stipulations apply. For a
listing of the conditions and disclaimers, refer to either the USICopyrights.chm or the Copyrights topic in your software.
Xerces C++. This product includes software that was developed by the Apache Software Foundation (http://www.apache.org/).
Copyright 1999 The Apache Software Foundation. All rights reserved.
ICU. Copyright 1995–2009 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 © 2004–2006, Matthew Wilson and Synesis Software. All Rights Reserved.
Stingray. This software includes Stingray software developed by the Rogue Wave Software division of Quovadx, Inc.
Copyright 1995–2006, Quovadx, Inc. All Rights Reserved.
STLport. Copyright 1999–2003 Boris Fomitchev
Trademarks
LabVIEW, National Instruments, NI, ni.com, the National Instruments corporate logo, and the Eagle logo are trademarks of National
Instruments Corporation. Refer to the Trademark Information at ni.com/trademarks for other National Instruments trademarks.
Other product and company names mentioned herein are trademarks or trade names of their respective companies.
Members of the National Instruments Alliance Partner Program are business entities independent from National Instruments and have
no agency, partnership, or joint-venture relationship with National Instruments.
Patents
For patents covering National Instruments products/technology, refer to the appropriate location: Help»Patents in your software,
the patents.txt file on your media, or the National Instruments Patent Notice at ni.com/patents.
Worldwide Technical Support and Product Information
ni.com
Worldwide Offices
Visit ni.com/niglobal to access the branch office Web sites, which provide up-to-date contact information, support phone
numbers, email addresses, and current events.
National Instruments Corporate Headquarters
11500 North Mopac Expressway Austin, Texas 78759-3504 USA Tel: 512 683 0100
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
A. NI Certification .....................................................................................................v
B. Course Description ...............................................................................................vi
C. What You Need to Get Started .............................................................................vii
D. Installing the Course Software..............................................................................vii
E. Course Goals.........................................................................................................viii
F. Course Conventions ..............................................................................................viii
Lesson 1
Software Architecture – Introduction
Exercise 1-1 Design a Wind Farm.........................................................................1-1
Exercise 1-2 Analyzing a Design Pattern ..............................................................1-10
Exercise 1-3 Identifying Design Challenges .........................................................1-13
Lesson 2
Designing an API
Exercise 2-1 Evaluating an API Design ................................................................2-1
Lesson 3
Multiple Processes and Inter-Process Communication
Exercise 3-1 Queue-Driven Message Handler ......................................................3-1
Exercise 3-2 JKI State Machine (Optional)...........................................................3-3
Exercise 3-3 Spawning Multiple Instances of an Asynchronous Independent VI...3-5
Exercise 3-4 Fixing the Run VI Method ...............................................................3-9
Exercise 3-5 Using Single Element Queues (SEQ)...............................................3-10
Exercise 3-6 Using Data Value References...........................................................3-19
Exercise 3-7 Functional Global Variables (Optional) ...........................................3-21
Lesson 4
Advanced User Interface Techniques
Exercise 4-1 Creating an XControl (Optional)......................................................4-1
Exercise 4-2 Modifying X Listbox Abilities (Optional) .......................................4-3
Exercise 4-3 Creating X Listbox Properties and Methods (Optional)...................4-6
Exercise 4-4 Creating the X Listbox Facade VI (Optional) ..................................4-12
Lesson 5
Introduction to Object-Oriented Programming in LabVIEW
Exercise 5-1 LVOOP.............................................................................................5-1
Lesson 6
Plug-In Architectures
Exercise 6-1 Using Plug Ins with VI Server..........................................................6-1
Exercise 6-2 Using LVOOP Plug Ins ....................................................................6-6
Lesson 7
Tips, Tricks, & Other Techniques
Exercise 7-1 Using Drop Ins .................................................................................7-1
Lesson 8
Error Handling
Exercise 8-1 Designing an Error Handling System...............................................8-1
Appendix A
Course Slides
Topics..........................................................................................................................A-1
Appendix B
Additional Information and Resources
You can apply the full purchase price of this course kit toward the
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
access course schedules, syllabi, and training center location information.
A. NI Certification
The Advanced Architectures in LabVIEW course is part of a series of
courses designed to build 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 NI Certification.
LabVIEW Performance
Certifications
Other Courses
*Core courses are strongly recommended to realize maximum productivity gains when using LabVIEW.
B. Course Description
In the Advanced Architectures in LabVIEW course you participate in
discussions and work independently and collaboratively to learn how to
architect an application and then design the components to support the
architecture.
This course assumes you have taken the LabVIEW Core 3 course or have
equivalent experience.
The course is divided into lessons, each covering a topic or a set of topics.
Each lesson consists of the following parts:
• An introduction that describes what you will learn.
• A discussion of the topics.
• A set of exercises that reinforces the topics presented in the discussion.
Some lessons include optional exercises or challenge steps to complete
if time permits.
• A summary that outlines important concepts and skills taught in the
lesson.
Note For course manual updates and corrections, refer to ni.com/info and enter the
Info Code aalerrata.
❑ NI LabVIEW 2011
Directory Description
Exercises Folder for saving VIs created during
the course and for completing certain
course exercises
Solutions Folder containing the solutions to all
the course exercises
Advanced Architectures Advanced Architectures in LabVIEW
in LabVIEW 2011 - Course manual.
Course Manual.pdf
Tip Folder names in angle brackets, such as <Exercises>, refer to folders on the root
directory of your computer.
E. Course Goals
After completing this course you will be able to:
• Design a software architecture to be implemented in LabVIEW
• Design a consistent, organized, and usable API
• Analyze and evaluate several solutions to a problem
• Use advanced design patterns and techniques to build the components or
subsystems of an architecture
• Understand the design trade-offs when selecting an advanced design
pattern or technique
• Analyze, critique, and improve the architecture of a LabVIEW
application
F. Course Conventions
The following conventions are used in this course manual:
» The » symbol leads you through nested menu items and dialog box options
to a final action. The sequence Options»Settings»General directs you to
pull down the Options menu, select the Settings item, and select General
from the last dialog box.
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.
monospace Text in this font denotes text or characters that you enter from the keyboard,
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.
Scenario
LabVIEW is a programming language that facilitates the rapid prototyping
and development of code. As such many users of LabVIEW have developed
a “code and fix” model for constructing software. The proper process, for
smaller as well as larger projects, is to first design a software architecture.
The developer should specify the major components of the project and how
those components communicate with one another. Data structures should
also be defined.
Implementation
Refer to the next section, Wind Farm Course Project Requirements
Document, to begin designing the software architecture for the Wind Farm
course project.
Your design may include diagrams and text. You should first consider the
architecture, regardless of the programming language of the
implementation. The architecture should be clear to C, Java, and LabVIEW
developers. Use your remaining time to consider the LabVIEW
implementation. Which design patterns will you use? Which
communication components might be more difficult to implement?
1. Introduction
1.1.Purpose
The purpose of the Systems Requirements Specification (SyRS) is to
enumerate the functions of the system and define in detail how the system
interfaces to both surrounding systems and its users. This document is
intended for both the customer and the developers implementing the system.
1.2.Definitions of Terms
This section provides the definitions of specific terms used to construct this
SyRS.
• The word SHALL denotes a mandatory requirement. Departure from
such a requirement is not permissible without formal agreement.
• The word SHOULD denotes a recommendation or advice on
implementing such a requirement of the document.
• The word WILL denotes a provision or service, or an intention in
connection with a requirement.
• The word MAY denotes a permissible practice or action. It does not
express a requirement.
1.3.Product Description
The course project has been designed to give students the opportunity to
design and evaluate several potential architectures for a larger LabVIEW
application. Students will begin an initial design of the Wind Farm at the
beginning of the course and then consider the implementation, utilizing
programming techniques that they currently understand. Then several
advanced design patterns will be taught and discussed. The merits of each
will be analyzed as they apply to the overall course project.
1.4.Assumptions
1.4.1.Simplifying a Complex System
Each module or system that will be coded or used in the course project may
appear to be quite simple. Students should assume that each of these systems
actually represents a complex process that might take weeks or months to
develop. For the purposes of this course, a very complex system was
significantly simplified.
1.4.3.Additional Requirements
A typical requirements specification would include much more information
than is noted below. The wind farm requirements constitute a subset that
might be classified as interface requirements, functional requirements and
design constraints. A well researched and carefully crafted requirements
specification would include many additional categories such as: hardware
interfaces, communication interfaces, networking with other systems, safety
issues, constraints, documentation, and much more. Additionally, each
requirement should have a unique ID, a priority, and an identified user. For
the purpose of this exercise, you may assume that all requirements must be
implemented and the user is the operator. For more information on writing
requirements refer to the following:
• IEEE Std 1233, 1998 and 1233-1996 aIEEE Guide for Developing
System Requirements Specifications -Description
• Managing Software Engineering in LabVIEW
• Large LabVIEW Application Development Community Page on
ni.com
• Writing Better Requirements by Alexander and Stevens
1.5.Product Description
A wind farm is comprised of many wind turbines. Each wind turbine is a
sophisticated system that measures wind speed, wind direction and many
operational parameters related to rotating machinery. The optimum energy
production occurs when the turbine rotates at a specified speed. The angle
of attack and the direction of the turbine are adjusted by the control system
to take advantage of the current wind conditions. This course project does
not include an actual simulation or the complexities of a typical control
system. Additionally, the course project runs on one target. An actual wind
farm is a sophisticated, networked system.
2. Product Requirements
10-0000 Interface Requirements
11-0000 Operator Interfaces
11-1000 General
11-1001 The user interface shall include a simple display of the operation
of the wind turbines.
11-1002 The user interface will be intuitive and require minimal training.
11-1003 The user interface shall not contain tabs.
11-2000 Wind Turbine Control and Data Visualization
11-2001 The user interface shall provide the capability for an operator to
add a wind turbine to the display.
11-2002 The user interface shall provide the capability for an operator to
display the turbine rotation speed from each wind turbine.
11-2003 The user interface may provide the capability for an operator to
stop a wind turbine.
11-2004 The user interface may provide the capability for an operator to
restart a wind turbine.
11-2005 The user interface may provide the capability for an operator to
remove a wind turbine from the display.
11-2006 The user interface may provide the capability for an operator to
stop all displayed wind turbines.
11-3001 The user interface shall provide the capability for an operator to
shut the system down.
11-3002 The user interface may display a message on successful
shutdown.
20-0000 Functional Requirements
21-0000 Main Software
21-1001 The system shall acquire each wind turbine’s rotational speed in
RPM.
21-1002 The system may acquire each wind turbine's blade angle of
attack in degrees relative to the support shaft.
21-1003 The system may acquire each wind turbine’s generated power in
Watts.
21-1004 The system may acquire each wind turbine’s energy generation.
21-2000 Data Logging
21-2001 The test software shall create a data log for each running wind
turbine.
21-2002 The data logs shall contain the name of the wind turbine tested.
21-2003 The data logs shall contain the time and date when each turbine
was started.
21-2004 The data logs shall contain the rotation speed of each wind
turbine at 250 msec intervals.
21-2005 The data logs shall be saved to disk in one of the following
user-specified formats:
•XML
•Tab-Delimited ASCII Text
21-2006 The data logs may also need to be saved to disk in additional
formats, such as TDMS, in the future.
21-3000 Wind Turbine Simulation
31-1000 General
31-1001 The test system software shall be limited to one physical screen.
31-1002 The user interface shall be of a maximum resolution of
1280 x 1024.
Scenario
The Producer/Consumer Design Pattern (Events) is a foundational starting
point for many subcomponents for any software architecture. However,
several changes should be made to the template before it becomes a robust
starting point for component development. National Instruments provides a
basic pattern that is generic to any application or use case. Further
customization of the template to handle unique requirements for each
programming team saves considerable time and effort during software
development. The architect, with assistance from a larger team when
available, must determine the needed changes.
Discussion Questions
Open the Producer/Consumer Design Pattern (Events) from the template
browser and answer the following questions:
Discussion Answers
❑ When might you use this design pattern?
You might use this design pattern when you need a producer loop to
handle events and maintain a responsive user interface and a
parallel consumer loop to asynchronously handle the processing of
the event and its data.
Scenario
In this course, you learn several advanced programming techniques as well
as some tips and tricks. In order to facilitate integrating the ideas into your
applications, you must first consider key challenges and periodically return
to this list to determine how the technique could apply.
Implementation
Take a moment to think about your current application or a recent project.
Consider data structures, modules, processes, and behavior. Determine
which aspects pose the greatest challenge when designing an architecture.
What were or are the greatest coding challenges? Identify and document the
top three issues in that application.
Note Common challenges include deciding what will run synchronously and what will
be asynchronous, designing the asynchronous communication mechanism, or crafting
cohesive modules such that changes have limited affects on the rest of the code and
minimal coding is needed to make those changes.
1.
2.
3.
Notes
Implementation
The installer for the Simple Messaging Reference Library (STM) is
included on your course CD. The installer places the VIs in a subpalette
under user.lib.
❑ Run the STM Basic Server Example VI. You must run the server
first.
Note To run this example on two computers, you must determine the IP address of the
computer running STM Basic Server Example.vi. From the Windows Start menu,
open a Windows Command Prompt and enter ipconfig. Press <Enter> to run the
command which displays the IP address.
❑ Open the block diagram for both VIs and notice the design decisions
that were made.
Discussion Questions
1. In what ways are the icons clear and meaningful?
2. How has connector pane selection facilitated the use of this API?
3. How does the choice in label names make the VIs easy to use?
4. How has the use of polymorphic VIs made this library easy to use?
Discussion Answers
1. In what ways are the icons clear and meaningful?
The VI icons have a common STM banner to show that they are
part of the same API.
The icons have meaningful graphics, such as arrows to indicate the
direction of the communication. The text in the icons indicates
whether the polymorphic VI is using the TCP, UDP, or Serial
instance.
2. How has connector pane selection facilitated the use of this API?
The connector panes consistently use the lower terminals for error
wires and the upper terminals for the connection information
3. How does the choice in label names make the VIs easy to use?
The label names all have a common STM or TCP prefix. The label
names also very clearly describe the VI’s functionality (i.e. STM
Read Message, STM Read Meta Data).
4. How has the use of polymorphic VIs made this library easy to use?
You can use the same polymorphic VIs to implement TCP, UDP, or
serial communication. The polymorphic VIs automatically adapt
based on whether you wire a TCP connection ID, UDP connection
ID, VISA resource, or an existing Connection Info cluster to the
top-left input terminal.
Notes
Notes
Scenario
Some type of queue driven message handler (QDMH) or state machine is a
fundamental starting point for successful LabVIEW teams and individual
programmers. In existence for over a decade, this advanced design pattern
is well-established and widely-used.
The QDMH used in this course is not intended to be the solution for every
student. Rather, it is an example of what a development team could build
from the Producer/Consumer design pattern. It does include key features
commonly found in many development teams’ applications. Consider this
as a starting point and continue to expand or modify as needed. As is, the
QDMH is sufficient for use in any of your applications.
Implementation
1. Create a new VI from a template.
Tip Because this is an advanced course, some exercises do not specify the details for
every step.
Note Because the main VI includes a sub VI that is also a template, you must also save
the sub VI in order to save the main VI.
3. Modify the QDMH so that the message display updates when the control
value changes.
Scenario
Members of JKI Software have been extraordinarily involved in the
LabVIEW community and in the development and promotion of open
source tools. Additionally they engage in LabVIEW integration projects and
work with teams that need assistance in software architecture and the
deployment and maintenance of LabVIEW tools across an enterprise.
LabVIEW architects should become informed about the tools that this team
provides (www.jkisoft.com).
JKI Software provides a very flexible and well thought-out state machine to
the LabVIEW community at no cost. JKI made several design decision that
are different from what most students have seen in previous LabVIEW
courses and in the broader LabVIEW community. First, the goal was to craft
a very thin template with minimal support VIs. Secondly, JKI has defined a
scripting methodology that allows for the rapid development state
definitions and transitions. However, you may notice that a certain
component is missing from the template. JKI purposefully left this feature
out, thus allowing the user of the template to determine the preferred
mechanism for peer to peer communication between parallel loops.
Implementation
Install and use the JKI State Machine.
❑ Place the JKI State Machine on the block diagram. You can now
find it in the Functions palette.
❑ On the front panel, add two Boolean controls and rename them as
Test 1 and Test 2.
❑ Modify the block diagram so that the label of the control appears in
the message indicator when either of the Boolean controls is pressed.
Challenge
A mechanism must be included to move data into and out of the state
machine from other places in the application. What are the various ways to
implement this? Why would you choose one over the other?
Scenario
In this exercise, you begin with a reentrant VI. You must create a subVI to
asynchronously launch the VI to run independently. You must then use this
subVI in a main VI to launch multiple instances of the asynchronous
independent VI.
Implementation
Scenario
As the architect, you must understand and be able to explain to your team
how LabVIEW handles VI references. In this exercise, the goal is to
understand how references work using the Run VI method to launch an
asynchronous VI with no open front panel.
Note Opening the front panel for the spawned VI is not the solution for the exercise.
Implementation
1. Open <Exercises>\Advanced Architectures in LabVIEW\
Fixing Run VI Method\Run VI Method.lvproj.
Scenario
In order to pass critical information from the Wind Farm UI to the individual
Wind Turbine code, you create a Wind Turbine Object. This is an object that
you can instantiate an infinite number of times at runtime. Additionally, the
data is protected so that while one VI modifies the data, other VIs are
blocked. This class includes a subset of methods from the original
requirements specification. Though this class is unique to a Wind Turbine
object, you can use the templates and the process immediately in your
application.
Design
Because the process for creating the class is somewhat unique and a portion
of it uses scripting, follow the detailed directions in the Implementation
section.
Implementation
Using Single Element Queue templates, a replicate hierarchy tool, and VI
scripting, create a by Reference Wind Turbine Object. The purpose of the
object is not to run the wind turbine process, but to communicate between a
host and multiple wind turbines.
Note This is a generic tool you can use to duplicate any template hierarchy and replace
keywords that are in the template with new keywords.
❑ The root path should point to the templates directory. The remaining
controls should resemble Figure 3-4.
❑ Run the VI and click OK after you have confirmed that all inputs are
correct. The VI may take several seconds to run.
2. Modify controls and the Wind Turbine Create VI, Wind Turbine Destroy
VI, and the Wind Turbine Object Snooper VI.
❑ Add five numeric controls to the cluster. Each should remain double
precision. Use the following labels:
Note Do not open Wind Turbine Get.vi or Wind Turbine Set.vi that are
located in the Not Used subfolder. You will use the new VI Scripting to create the get and
set methods for the class.
❑ You may need to clean up the front panels. Your VIs should resemble
Figure 3-6, Figure 3-7, and Figure 3-8.
4. Add the following VIs to the SEQ Wind Turbine Object virtual folder in
the Project Explorer.
Note VI Scripting allows the programmer to use LabVIEW to create and modify
LabVIEW code. Refer to Lesson 7, Tips, Tricks, & Other Techniques, for more
information about VI Scripting.
Before running the VI, you must select the path to the Queue reference.
The scripting VI then extracts the cluster elements from the reference
and allows the user to specify which one will be get or set. Additionally
the template VIs have been modified to include the icon for this exercise.
❑ Move the VI so you can see the entire front panel of the
newly-created VI.
❑ Additionally you should add the text Wind Speed to the VI icon.
❑ Repeat the process and use the Set/Get Boolean control and Object
Data Elements listbox control to create the following VIs:
❑ Using the icon banner for the VIs that you created, modify the icons
for the Create, Destroy, and Object Snooper that you previously
created.
6. Add the following VIs to the SEQ Wind Turbine Object virtual folder in
the Project Explorer.
Testing
Now, you will test the Wind Turbine Class that you created. You will run two
separate VIs that have been set up to run three Wind Turbines. This is a very
simple test VI.
1. Open the block diagram for TEST Set Wind Speeds.vi. The test
code is written for you. Add the following VIs in the appropriate
locations and wire inputs and outputs.
2. Open the block diagram for TEST Get Wind Speeds.vi. The test
code is written for you. Add the following VIs in the appropriate
locations and wire inputs and outputs.
5. Set the Wind Speeds in the TEST Set Wind Speeds VI.
6. Confirm that the TEST Get Wind Speeds VI reads the Wind Speeds
correctly.
7. Debug as needed.
Challenge
Review the list of challenges you created in Exercise 1-3. Determine how
you might integrate this into your current application.
What features from the scripting VI are missing that you might want to
incorporate?
Scenario
You will inevitably encounter a scenario in which you need to instantiate
more than one instance of an object. Additionally, you might need a fast and
efficient way to access data from more than one location in your block
diagram. One way to design the component is using Single Element Queues.
Another option is to use the DVR feature.
Implementation
1. Explore the DVR Timer class that was demonstrated during the
Functional Global Variables section of the course.
Note The Demonstrations folder contains valuable instructor demos you may find
useful in developing your applications.
Challenge
Review the challenges you listed in Exercise 1-3. Determine which
challenge might be solved with the DVR. Code a simple prototype. The
screenshots in the slides and the block diagram of the DVR Timer
demonstrate the basics for creating a DVR class.
Using the DVR, create a simple wind turbine object that gets and sets wind
speed.
Scenario
As the architect, you must determine the extent to which your team uses
FGVs in your application. A name-value pair FGV is useful for storing and
retrieving data items across an application. If you plan to use FGVs like this,
you should construct a template for your developers. In this exercise, you
use a name-value template to build a User Event Reference manager. You
can use this template as-is for your development team or you can customize
it further.
User Events are a very powerful tool for moving data from one block
diagram location to another. Subsequently, any block of code can cause an
event to be fired that would be handled by the event structure. Even though
complex architectures can be developed without User Events, they still
serve as a very powerful tool for the architect. However, the architect must
determine the method for getting the User Event Reference from one part of
the block diagram to another. A name-value FGV is one way to solve that
problem, and in a way that it scales to an unlimited number of User Events.
Moreover, you can use this VI in any application.
Design
You create a new FGV from FGV Resource Template.vit, located in
the templates directory.
• The user event data type is cluster with a string and variant.
Note You must label the string and variant before creating the User Event Reference.
Otherwise, the event structure can not retrieve the information that is passed via the User
Event.
• Delete the Modify case as the User Event References is never modified.
Implementation
First, you create a new functional global variable from the template. You
modify some control labels and redefine two type definitions.
Note Explore the properties of the build specifications. This source distribution places
the FGV templates in the appropriate directory so that they are available in the template
browser.
❑ Click OK.
Note The order for saving may be different from the order shown here. Carefully
observe what you are saving at this step.
– Click OK.
❑ Navigate to the Add User Event Ref case and place the Create
User Event function on the block diagram (you use this later in the
exercise as well as here).
❑ Create a cluster constant with a string and variant constant. Label the
string as String, label the variant Data, and label the cluster User
Event, as shown in Figure 3-12.
Tip In order to access the elements within an event structure, you must include labels
for cluster elements.
You must create the variant constant from an existing variant function.
❑ Create an indicator from the user event out output terminal of the
Create User Event function. Select the indicator on the front panel
and press <CTRL-X>.
In a later step, you will paste it into the TYPE FGV User Event
Ref type definition.
❑ On the front panel, open the TYPE FGV User Event Ref type
definition by right-clicking the DataSet Out indicator and selecting
Open Type Def.
❑ Select <CTRL-V> to paste the user event out indicator and rename
it as User Event.
You do not need to rename the DataSet control because you will
delete it later.
❑ Wire the user event out terminal from the Create User Event
function to the build array, as shown in Figure 3-13.
Figure 3-13. Add User Event Ref case of FGV User Event Reference Manager VI
Tip One of the benefits of this advanced design pattern is that error checking code can
be integrated into the functional global. The template already includes the check to
ensure that the dataset or User Event Ref is indeed valid.
❑ Inside the internal case structure labeled Valid Data Set?, add
the Destroy User Event function to the True case to destroy the
reference returned at the deleted portion terminal of the Delete
From Array function.
❑ Create a constant from the tunnel to pass out an invalid user event.
You will modify two VIs. One VI allows you to add user event
references and generate (or fire) user events to those references. The
other VI handles, or responds to the user events. You now have a tool to
globally create and manage user events.
– Initialize
– Exit
Choose the correct selection for the Method input of the FGVs and
wire the correct output of the FGVs to the Register for Events
function.
❑ Navigate to the event case that handles the user event and examine it.
❑ Fire various user events from TEST FGV User Event Reference
Manager.vi.
Ensure the user events are handled in TEST Handle FGV User
Event Reference Manager.vi.
Tip If you need help, see the corresponding cases in TEST FGV User Event
Reference Manager.vi and TEST Handle FGV User Event Reference
Manager.vi in the <Solutions>\Exercise 3-7 directory.
Challenge
Add instructions to the .vit so your development team can use it for other
use cases.
List potential uses for this advanced design pattern. Review your answers on
Exercise 1-3 to see if the functional global variable solves a challenge that
you listed.
If you are already familiar with VI scripting, you may consider further
automating this process.
Notes
Notes
Scenario
One benefit of XControls is that the architect can blend the functionality of
several controls into one. In this exercise, you modify a Listbox control to
have the look and feel of a radio button. Unlike the static radio button, this
XControl scales dynamically while the program runs. The benefit is that the
operator can see all of the items that are available (unlike a ring control) and
which item is currently selected (unlike a plain Listbox). Moreover, this is a
control that you can utilize in any application.
Design
Create and save the XControl with the names X Listbox.xctl, X
Listbox State.ctl, X Listbox Facade.vi, and X Listbox
Init.vi.
Implementation
1. Create the XControl and save the control and the abilities.
Note You can also create an XControl from the template browser.
❑ When prompted, click Yes to save the new unsaved files of the
XControl.
Note An XControl is a special kind of project library. If you must rename or move
folders, do so within the XControl project. Renaming or moving files in Windows
Explorer breaks the XControl.
Design
Modify X Listbox Data.ctl
• This component specifies the data type of the XControl, in this case, the
string data type.
Implementation
Modify the Data, State, and Init abilities of the XControl.
1. Modify the Data ability. This component specifies the data type of the
XControl, in this case, the string data type.
❑ Label it Names.
3. Modify the Init ability. LabVIEW calls the Init ability when the
XControl is first placed on a front panel or when a VI that contains the
XControl is loaded into memory.
❑ Scroll down the front panel until you find the Default Indicator State
and the Default Control State.
Tip Some controls on the front panel window are locked to prevent accidental deletion,
which would destroy the VI. You can unlock and move the controls if you want.
❑ Move the controls and resize the front panel to display only the items
shown in Figure 4-3.
Figure 4-3.
Scenario
You can create properties for an XControl in which one attribute or element
of the display state is modified. In such cases, the property you create has
one parameter associated with it. You use methods in cases when no
parameters are needed (as in the Delete All method) or when more than one
parameter is needed. Additionally, invoking a method implies that an action
is taken, such as adding an item and deleting an item.
Design
• Create the Delete All Items method.
Implementation
In this exercise, the data type of the X Listbox control is a string, specifically
the item name of the active row. Users of the XControl must be able to add
an item, delete an item, and delete all items. When complete, the front panel
for the test VI resembles Figure 4-4.
Remember that the X Listbox State contains the elements that you modify
with the methods you create. When the parent VI that holds the XControl
calls a method or property, the corresponding Facade VI executes the
Display State Change event. After you create these methods, proceed to
Exercise 4-4 to modify the Display State Change event case to handle the
data modified by the methods.
❑ View the settings. No changes must be made for this method because
it does not have any inputs or outputs.
❑ Save X Listbox.xctl.
Figure 4-6. Delete Item From Listbox VI Block Diagram - False Case
Figure 4-7. Delete Item From Listbox VI Block Diagram - True Case
❑ Add and configure the parameters for the input and each output, as
shown in Figure 4-8.
Figure 4-8. Configure Method Dialog for Delete Item From Listbox VI
Note If you did not define connector pane terminals, the above items will not be
available. Each item added in the Configure method is a parameter for the XControl
method.
❑ Save X Listbox.xctl.
❑ Save X Listbox.xctl.
Design
Create the front panel window
• The front panel window should include a Listbox that is sized to include
many items. The Fit Control to Pane option should be enabled.
• This section should update the properties of the X Listbox so that new
items are added and others are deleted. The X Listbox Update for
Add and Delete.vi can be used here.
• The number of rows and the item names of the listbox should be updated
based on the display state data.
• The item symbols should be updated depending upon the active listbox
item. The X Listbox Update Symbols for Select.vi can be
used here.
Test the VI using the TEST X Listbox VI that has been provided.
Implementation
1. Modify the Facade front panel.
Note The XControl has its own label when you drop it onto a front panel.
❑ Size the Listbox control and the front panel window so that the
listbox control takes up the entire window and exactly matches the
window borders, as shown in Figure 4-11.
Note The Display State Change event is generated on the Facade VI when the display
state of the XControl changes. This can be in response to a property or method call, or
from the Init ability. This event is not generated when other Facade events set the State
Changed? element of action. At any given time, the appearance and behavior of the
XControl should depend only on the display state, and therefore the Display State
Change event must apply any changes in the state to the appearance or behavior of the
XControl.
Note The X Listbox Update for Add and Delete.vi is located in the SubVIs
directory of the X Listbox Control Project.
The number of the event case does not relate to the functionality of the event structure;
it specifies the order of the event case when you view it.
Note The Exec State Change event is generated on the Facade VI when a VI containing
the XControl changes from edit mode to run mode, or vice versa. You can use this event
to modify the control for any differences between its edit-time and run-time behavior.
Remember that you can add any event for the controls on the Facade of
your XControl.
The XControl template adds only four new event cases to those that are
already available for controls and VIs.
Note The X Listbox Update Symbols for Select.vi is located in the SubVIs
folder in the X Listbox Control.lvproj.
❑ Drag the X Listbox.xctl from the project onto the front panel.
❑ Wire the X Listbox control to the X Control Output control and edit
the event handled by this case, as shown in Figure 4-16.
Note Wires on the block diagram appear broken until you wire the “Delete Item”:
Value Change case.
Note In order for state data to be saved with a parent VI, a Convert for Save ability must
be added to the XControl. No modifications need to be made.
Challenges
❑ As it is currently coded, the X Listbox operates in the following manner.
When a user adds or deletes an item, the last item becomes the active
item. This may not be the cleanest solution when the user deletes an item
in the middle of the list. Modify the X Listbox so that upon deleting an
item, the active row remains the same as the row that was just deleted.
You must modify the X Listbox State.ctl as well as the
X Listbox Facade.ctl.
Notes
Notes
Scenario
You are given an existing hierarchy of LVOOP of classes. The parent class
is the report class. The existing child classes are the XML class and the TXT
class. These are sibling classes. From the TXT class, you create a TDMS
class and test its functionality.
Code is already written to interface with the parent and existing sibling
classes. Adding a new class with the same interface as the other classes is
very simple task. You do not need to fully understand native LabVIEW
classes (LVOOP) to complete this exercise, but you see how classes add
flexibility and needed structure in an architecture. Use this as a starting point
for creating reports in any application.
Design
• From the LVOOP Report project, you create a new sibling class from the
TXT Report.lvclass.
• Modify the Write to File to generate the TDMS file. The Write TDMS
File VI is provided for you.
• Add the TDMS Report Init.vi to the TEST Report Class VI to test your
code.
Implementation
1. Observe the class hierarchy.
❑ Click Continue.
❑ Click OK.
❑ In the Apply Icon Changes to Member VIs? dialog box, click Yes.
❑ Change the label on the object out to TDMS Report out from TXT
Report out.
❑ Go to the No Error case and change the string constant text from txt
to TDMS.
❑ On the front panel, change the names of the objects to reflect the
TDMS report type.
Testing
1. Test the changes.
❑ On the block diagram, replace the existing Init.vi with the TDMS
Report_Init.vi. Notice the automatic selection of the Write
TDMS.
❑ Run and confirm that the TDMS file has been created.
Note To view the contents of the TDMS file, run the Read TDMS_Report.vi located
in the SubVIs directory of this exercise.
Challenge
Review the challenges you listed in Exercise 1-3. Look for potential
modules in your application in which a parent-child relationship exists.
Draft an initial class diagram.
Notes
Notes
Scenario
Though the architect cannot foresee all potential changes to an application,
some changes can easily be identified and the architect can plan in advance
to adapt. Often, the change entails adding a component that is of a similar
type to another component. For instance, the structure for saving data to a
file can change. Data may initially be saved in a binary file and then later the
application will save data to a TDMS file.
The interface for saving the file, regardless of its type, can be defined early
the design stage. The application calls the interface, which in turn calls
specific binary writer code. Then, any additional file format writers can be
added by dropping the new plug in VI into a specified directory. The
interface will recognize the plug in and as such make it available to the main
application.
This example was designed with plug ins that are different waveform
generation VIs. Though waveform generation may not be a feature of your
application, the structure for finding and calling the plug ins can
immediately be used in your application.
Implementation
Add features to a running VI without stopping the VI.
❑ Open Plug Ins Main.vi from the Plug Ins with VI Server
project.
❑ Run the VI and observe the two waveform options from the
Waveform Selector.
– Initialize case
Note The control terminals are used in the event structure and, as such, the local
variables must be used here. Because this is a VI in which the User Interface is visible,
this is an acceptable use of local variables.
Open the Create WFG Plug In List subVI. Observe how the list
is created. The VIs that have the same connector pane as the
strictly typed VI will be opened and not have an error. For those
VIs, name value pairs are created from the window title and the
VI path.
Open the Call WFG Plug In subVI. Notice that the connector
pane must remain the same for any plug in that will be called by
this VI.
Tip When designing plug ins, you may want consider using extra terminals of the string
or variant data type to facilitate modifications to the code.
❑ In the project explorer, explore the Plug Ins directory where the
plug in VIs are stored. In the remainder of this exercise, you create
a plug in and then save it to this directory while Plug Ins
Main.vi is running.
Move and size the front panel so that you can view the running VI and
the project at the same time.
❑ From the Plug Ins with VI Server project, expand the SubVIs folder.
Note The new VI must be saved in the Plug Ins folder for the example to work correctly.
❑ Close the VI. The VI flashes because it is already linked into the
main application.
❑ Return to the still running Plug Ins main and notice that the user now
has the option to create a Square Waveform.
Challenge
Create a build specification and stand-alone EXE that will have the same
plug-in functionality as seen earlier in this exercise.
❑ Move the Square Plug In.vi to a location other than the Plug
Ins directory.
❑ Copy the Square Plug In.vi to the Plug Ins directory to confirm
that it gets linked into the code while the stand-alone EXE is
running.
What other considerations could come into play with this advanced
design pattern?
Scenario
This is an advanced feature that will likely take time to fully grasp. It is
included because it could be useful for you now or at a later date.
Additionally, the details for the implementation were published in the
LabVIEW community at www.expressionflow.com.
Implementation
This exercise illustrates the ease of extending an application using native
LabVIEW classes. You are given the stub VI and a list of the VIs that you
need to add to the application. You must decipher how to put the VIs
together and where to find them on the palettes.
❑ Open the TEST LVOOP Plug Ins.vi from the Plug Ins folder
of the project explorer.
❑ Observe the block diagram and the use of the following VIs.
– Set Extensions
– Write to File
These general steps help you complete the block diagram. Arrows and notes
on the block diagram assist you in the placement of the VIs.
• Extract all files from the Plug Ins folder that have the .lvclass
extension.
• Add all objects from the Plug Ins folder that are also in the report class
hierarchy to the array of report objects.
• To screen for objects that are in the report class hierarchy, you can try to
convert the object to the more specific class of report. If no error occurs,
then the object is part of the hierarchy.
Note Objects that are in the same object class hierarchy can be bundled into arrays and
can be wired to any terminal whose data type is in the same hierarchy. Thus, objects
facilitate the design of flexible and scalable software architectures.
Testing
1. Run and test the VI.
Challenge
Create the build application for the project.
Notes
Scenario
As the project architect, part of your job is identifying coding tasks that you
repeat over and over again. Additionally, you may identify a feature that you
want to include with a type of control in LabVIEW. By extracting the
references of controls of a certain type for a VI, you can add features that
are not currently available. You will use a drop-in architecture to implement
a Boolean value change logger, which is a drop-in VI that you can use in any
application and expand to add functionality.
Design
• Open Drop Ins.lvproj
Implementation
1. Open the project and drop-in VI.
2. Enable the VI Scripting palette to access the Traverse For GObjects VI.
❑ Click OK.
3. Modify the DropIn Get Button Clicks - Stub VI block diagram to write
to file each time a value change event occurs for any boolean control on
the referenced VI, as shown in Figure 7-1, using the following items.
Testing
Test the drop-in VI by placing it in a calling VI.
❑ Add the DropIn Get Button Clicks - Stub VI to the TEST Drop In VI
block diagram.
4. On the front panel, click the Test 1, Test 2, and Test 3 buttons a few
times. Click Exit.
5. Navigate to the location you specified in the file (use dialog) constant
and open the log file. You should see a list of the buttons that you pressed
and when you pressed them.
Challenge
Modify the drop-in VI to capture all interaction with the front panel and
classify the type of control in which the value change event occurred.
Notes
Scenario
Apply the skills that you learned in the course and to improve code that you
are currently designing. Follow the requirements generally, as specifics can
be added to or deleted from what is listed. Your main consideration is the
broader structure.
Design
Assume that the overall architecture of a project that uses the error handling
system may include Queue Driven Message Handlers, or a design similar to
the JKI State Machine for controlling all main processes.
The error system might be a separate process that runs concurrently with the
main application. However, the error system does not have to be centralized.
You could implement a central definition that is utilized in a distributed error
handling system.
General Requirements
Note These are not specific requirements. They include broad categories and
information to help you define requirements for your application.
Classification
The error handling system classifies all errors. The architect must determine
the classification. For example, you can classify errors as warnings,
non-critical errors, or critical errors. The classification also implies the
action to be taken. Classification and action could be synonymous or
differentiated. For instance, an application could flag a data acquisition error
that is critical or non-critical. Additionally, a non-critical error could be
appropriately handled by a user prompt or an email. Therefore, you should
consider the types of actions that may need to occur. Thus you must first
determine an appropriate error classification system.
Data Structure
Determine the appropriate data that is required to process various errors. For
instance, in a process environment, if a fatal error occurs, information about
the lot and the process parameters may be required. If the error is a transient
instrumentation error, the pertinent information may be the instrument IDs
and a command to reset the instrument. Regardless, the information needed
to adequately process an error will exceed the capabilities of the standard
error cluster. Moreover, isolating the cause may require retaining historical
operational information. Therefore, you should carefully analyze all of the
data that might be needed to process errors and consider the types of errors
that might be added in the future.
Actions
Basic error logging may entail simply documenting the errors that occur and
when they occur in a simple .txt file. Actions could include prompting the
operator or shutting down the system. Additionally, error notification could
extend beyond operator notification and include email, web, or text
messages.
Implementation
Refine the general requirements to better suit your application needs.
Considering Classification, Data Structures, and Actions helps you further
clarify how the system should respond to various errors that could occur.
After you sketch the requirements, draft a software architecture and
prototype a system.
1. Clarify Requirements.
❑ Classification
❑ Actions
❑ Data Structures
❑ Share the ideas with someone else in the class and refine.
4. Prototype
Notes
Lesson 1
Software Architecture – Introduction
TOPICS
A. Software Architecture – Quality
B. Documenting a Software Architecture
C. Design Patterns and Scalability
ni.com/training
ni.com/training
ni.com/training
Scalable
Consider Plug Ins or Objects
ni.com/training
DISCUSSION
ni.com/training
ni.com/training
ni.com/training
Disadvantages
• May be in a cluttered
Okay diagram with many other
clusters
• Requires remembering the
functionality of the code
• Changing functionality may
require changes throughout
the application
ni.com/training
ni.com/training
ni.com/training
ni.com/training
In LabVIEW
Software Processes
Components SubVIs/Libraries
ni.com/training
Producer
Process
Engine
Process
Display
Process
ni.com/training
Identifying a Process
Characteristics
• Executes a sequence of steps or actions Process
• Continuously runs those steps or actions
• Has a specific and singular responsibility
Action 1
A ti 2
Action
Implementation Handle Error
Action 2
• Typically based on Producer/Consumer or
Queued Message Handler
• Can include one loop or two.
Producer/Consumer may comprise one
process
ni.com/training
Control Alarm
Module Processing
Main Process
Data Analysis Display(s)
Engine
IO
Data Logging Error Handling
Engine
ni.com/training
ni.com/training
Log Data
You explore various data
communication techniques in
Lesson 3, Multiple Processes Data
Logger
and Inter-Process
Communication.
ni.com/training
ni.com/training
• The course material includes three solutions to the Wind Farm Course
Project
• You will learn about the underlying design choices and the trade offs
of the different implementation choices
• You will not build the course project
• Exercises are not unique to wind turbine operation
• For every exercise, you will be able to use the solutions or process in
your application at your workplace
DISCUSSION
• Requires:
− An unlimited number of processes
− Communication between those processes
• Reflects common design challenges
• Can be implemented many ways
• Simulated application
ni.com/training
Process
Data
Communication
Libraries
ni.com/training
ni.com/training
ni.com/training
• Diagrams
• Documents
• Prototypes
• Test Cases
• Other
ni.com/training
ni.com/training
Get Turbine
Speed
Add Yes
Turbine?
Yes
Error? Handle Errors
Continue?
ni.com/training
ni.com/training
ni.com/training
Test Alarm
Alarm
Control Setup
IO
Engine Alarms Display 1 Display 2
Process/
Logging ni.com/training
Simple
p Commands
Display Temporary process with GUI
Chanel Class hierarchy for channel and alarm classes Object Messaging
ni.com/training
ni.com/training
Prototype
Prototype–A early sample or model built to
test a concept.
Advantages of Prototyping:
• Risk mitigation
• Evaluation of requirements
• Rapid development (minimal software engineering process)
• Communication to stakeholders
• Evaluation of design alternatives
ni.com/training
Test Cases
Test Case–For some components in your architecture,
consider writing the test code for the component before
developing the component itself.
ni.com/training
ni.com/training
DISCUSSION
ni.com/training
Set Wind
Speed
Get Turbine
Speed
Add Yes
Turbine?
Yes
Error? Handle Errors
Continue? ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
DISCUSSION
ni.com/training
Hallmarks of Scalability
N 1
N+1 F il
Family Lib
Library
ni.com/training
ni.com/training
DISCUSSION
Design Well!
• Take the time to thoughtfully design a scalable, readable,
maintainable software architecture
− Prevents last-minute changes
− Mitigates the cost of any necessary changes in the future
• LLast-minute
t i t changes
h are expensive
i
Software Engineering Process Phase Cost Ratio For Making a Change
Requirements 1
Design 3-6x
Development 10x
Development – testing 15-40x
Validation 30-70x
Post-release 40-1000x ni.com/training
Lesson 2
Designing an API
TOPICS
A. APIs
B. API Design Techniques
C. Polymorphic VIs for an API
D. Project Libraries
E. Passing Data in an API
ni.com/training
ni.com/training
APIs
ni.com/training
APIs
ni.com/training
Designing an API
ni.com/training
• Documentation
Usability • Naming
• Icons
of APIs • Place VI Contents
ni.com/training
Good Layout
Needs Improvement
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
Add a Trigger
ni.com/training
Documentation
ni.com/training
Naming Conventions
Good Better
Mode Handshaking mode
Ch Channel
Level Trigger level, Trigger voltage level
Ti
Time Ti
Time ((sec))
Action Action (Get Data)
Don’t forget to include the units and default value.
ni.com/training
• Keep it simple
• Avoid ambiguity
− Unclear: Polarity (T)
− Clear: Positive Polarity (T)
• Avoid reverse logic
− Reverse logic: Don’t Convert EOL (F)
− Clear: “Convert EOL (T)”
ni.com/training
ni.com/training
Icons
v
Library o
e
• Unifying Theme Verb
r bj
− Use a common element or b Objecte
ct
theme to group your API.
• Text
− Avoid using culturally-specific images or words.
− Use fonts consistently.
ni.com/training
Icon Templates
• Use the Icon Editor to design custom icon templates for your team
• Distribute icon templates to the LabVIEW Data\Icon Templates
directory
Drag VI contents
onto block diagram
• The API must be a functioning and debugged black box for the user
• Designate an API owner who performs updates as needed
• The developer chooses to deploy code snippets or code generation
tools as needed
ni.com/training
ni.com/training
ni.com/training
1 Compute
2 Compute Number
3 Compute Array
4 Compute Waveform
ni.com/training
1 Compute
2 Compute Number
3 Compute Array
4 Compute Waveform
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
D. Project Libraries
• Tool to facilitate the creation of an API
• Set of related VIs and other LabVIEW files
• Information on library is stored in a text file (.lvlib)
ni.com/training
ni.com/training
ni.com/training
ni.com/training
Project Libraries
<Exercises>\…\Demonstrations\Project Library\Wind
Turbine.lvproj
DEMONSTRATION
Pass Data
By Value Pass Data By
Reference
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
DISCUSSION
Lesson 3
Multiple Processes and Inter-Process
Communication
TOPICS
A IIntroduction
A. t d ti – Processes
P F B
F. By Reference
R f IInter-Process
t P
Foundational APIs Data Storage
B. Foundational APIs G. Inter-Target Communication
C. Foundational Design Patterns H. Analysis of LabVIEW
D. Scaling Foundational Design Communication APIs
Patterns I. Communication Reference
E. What is an Asynchronous Architectures
Dynamic Process?
ni.com/training
A. Introduction – Processes
User Alarm
interface IO Engine
Engine
Control Data
Model Logger
ni.com/training
ni.com/training
ni.com/training
Store Data
Headless Headless
UI Process 1
Process 1 Process N
Use Cases
Configuration data
Slowly changing data
Non-critical messages
“Global Data”
ni.com/training
Stream Data
Headless
Process 1 Use Cases
Waveforms
Large sets of data
High Speed
Data
Acquisition
ni.com/training
Send Message
Use Cases
UI Process 1 State machines
Event processing
Headless Test sequencing
Process 2 Alarm notification
Message system
Headless
Process 1
ni.com/training
Courier
Receiver(s)
Message
Route
Sender (s) Receiver(s)
ni.com/training
ni.com/training
DISCUSSION
ni.com/training
ni.com/training
Application1.exe
Application2.exe
VI in Project1.lvproj
VI in Project2.lvproj
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
B. Foundational APIs
Design patterns and scalable reference architectures
are dependent on APIs that are native to LabVIEW
Messaging
System
ni.com/training
ni.com/training
• Native LabVIEW
− Any File I/O
− Global and local variables
− Shared Variables
− Data Value References (DVR)
• Common Design Patterns
We will cover
− FGVs (Foundational)
these in detail
• Reference Architectures
− CVT
ni.com/training
• Native LabVIEW
− Queues We will cover
− Network Streams these in detail
− TCP
ni.com/training
ni.com/training
DVRs Notifiers
• Pointer to Data • 1:1, 1:N
• 1:1, 1:N, N:1, N;N • Full API
• Full API • Lossy
• Named
ni.com/training
ni.com/training
Queues – Benefits
• Secure
• Globally accessible by name within an application instance
• Flexible, element can be any data type
• Fast!
• Optimizes memory with limited data copies
• Full API for various queue operations
• Foundational API that must be mastered
ni.com/training
Secure Messaging
ni.com/training
Reference #1
1. 3.
My VI2.vi
Reference #2
2. 4.
ni.com/training
ni.com/training
ni.com/training
ni.com/training
Consumer
A common use case for user events is sending messages from the
consumer loop back to the event structure in the producer loop
ni.com/training
ni.com/training
• Limited API
• No way to preview events
• No way to flush buffered events that have not been handled
• Cannot be named like queues and notifiers
ni.com/training
ni.com/training
ni.com/training
When using many different user events, the Edit Events dialog
can become cluttered and difficult to manage
ni.com/training
ni.com/training
Process 1
Process 2
ni.com/training
Process 2
ni.com/training
<Exercises>\...\Demonstrations\Event Registration
DEMONSTRATION
DVRs Notifiers
• Pointer to Data • 1:1, 1:N
• 1:1,1:N,N:1,N;N • Full API
• Full API • Lossy
• Named
DISCUSSION
ni.com/training
ni.com/training
48
ni.com/training
SubVI Encapsulation
ni.com/training
ni.com/training
Modify
Data
VI-2.vi
Modify
Data
What happens if two VIs both call the Get method, then both
modify the data, and then both call the Set method?
ni.com/training
ni.com/training
ni.com/training
Pros Cons
• Can create custom events • Can be confusing to a novice user
• Can pass data with the event • Cannot be named like queues
• Can move data across the block • Must have a mechanism to pass
di
diagram th
the reference
f tto multiple
lti l llocations
ti
• User events are buffered
• User events are ideal for
shutdown and other high priority or
global actions
DEMONSTRATION
Private
ni.com/training
<Exercises>\...\Demonstrations\FGV vs DVR\Functional
Global Variable\FGV Timer.lvproj
DEMONSTRATION
ni.com/training
ni.com/training
• Efficiently responds to
the user interface
ni.com/training
Enum or String ?
ni.com/training
ni.com/training
• Enum • Variant
• String • String
• Cluster
• Object (LV Class)
ni.com/training
ni.com/training
DEMONSTRATION
DISCUSSION
DEMONSTRATION
GOAL
DISCUSSION
DEMONSTRATION
DEMONSTRATION
TCP Init
Send TCP Msg
Initialize
Handle Error
Get TCP Msg
Handle Error
Action 2
ni.com/training
ni.com/training
Command/State
Data
ni.com/training
ni.com/training
ni.com/training
ni.com/training
<Exercises>\...\Demonstrations\QDMH Client-
Server\Client-Server.lvproj
DEMONSTRATION
What happens?
ni.com/training
DEMONSTRATION
External.vi Main.vi
ni.com/training
AMC combines
the QDMH with a
messaging
system
ni.com/training
ni.com/training
DEMONSTRATION
<Exercises>\...\Demonstrations\Scaling Components
with User Events
DEMONSTRATION
ni.com/training
DISCUSSION
Further Considerations
• What about the scenario in which you don’t want to load all
of the code at run time?
• What about running a background process that handles
archivingg of data and runs independently
p y of the main VI?
• What about dynamically determining at run time how many
UUT user interfaces to launch?
ni.com/training
ni.com/training
Main.vi
Launcher.vi VI 2.vi
VI 3.vi
ni.com/training
Wind Farm #1
DEMONSTRATION
ni.com/training
• Asynchronous Subroutines
ni.com/training
Asynchronous Independent VI
Calling VI
ni.com/training
ni.com/training
? ?
Backup Files
?
Main VI
ni.com/training
DEMONSTRATION
Asynchronous Subroutines
ni.com/training
ni.com/training
Asynchronous
Subroutine
?
Calling VI
?
ni.com/training
ni.com/training
4
2
3
1. VI path of asynchronous VI
2. Include the 0x80 flag as part of the options input to open a call-and-
forget VI reference
3. Starts an asynchronous call to the VI indicated by the reference
input
ni.com/training
4
2
3
4. Close the VI reference when the calling VI no longer needs the reference
When you close a call-and-forget VI Reference, LabVIEW does not abort
instances of the VI that are already running.
The asynchronous VI manages its own lifetime.
The asynchronous VI will leave memory when it has stopped running and
has a closed front panel
ni.com/training
Daemon VI
3
2
1. VI path of background daemon
2. Starts daemon asynchronously
3. Closes the VI reference. The daemon to manages its own
lifetime
ni.com/training
C ll th
Call the code
d n times
ti tto spawn n VI instances
i t
2
3
1
ni.com/training
1 2 4
6
5
1. Include the 0x100 flag as part of the options input to open a call-
and-collect VI reference
2. Wait On Asynchronous Call node is associated with a Start
Asynchronous Call node that uses the same VI reference
3. Starts an asynchronous call to the VI indicated by the reference
input
ni.com/training
1 2 4
6
1 2 4
6
5
6. When you close a call-and-collect VI reference, LabVIEW
aborts all running instances of the VI.
Note: When the VI that opened the call-and-collect VI reference
finishes executing, LabVIEW automatically closes the
reference and aborts all running instances of the VI.
ni.com/training
Launch time-consuming
code asynchronously
ni.com/training
<Exercises>\...\Demonstrations\Async Subroutine
– Multiple Instances\Async Subroutine –
Multiple Instances.lvproj
DEMONSTRATION
GOAL
DISCUSSION
ni.com/training
ni.com/training
• Caveats
− Asynchronous Call nodes are only available in LabVIEW 2011
or later
− Asynchronous Call nodes require a strictly typed VI reference,
so you must know the connector pane of the asynchronous VI
at edit-time
• If you are using a prior version of LabVIEW or unable to not
determine the connector pane of the asynchronous VI at
edit-time, use the Run VI method instead
ni.com/training
?
? ni.com/training
ni.com/training
GOAL
DISCUSSION
Run VI method
Asynchronous
Call nodes
ni.com/training
Add/Start
Error
Handler
Logger
DISCUSSION
Wind Farm #1
Wind Farm #1
Data Communication
Between UI and VI Server (Set/Get Ctrl Value)
Turbines
DISCUSSION
ni.com/training
Headless Headless
UI Process 1
Process 1 Process N
ni.com/training
ni.com/training
ni.com/training
<Exercises>\...\Demonstrations\FGV vs DVR\Functional
Global Variable\DVR Object.lvproj
DEMONSTRATION
Pass Data
By Value Pass Data By
Reference
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
GOAL
• Could you follow the process, or did you find yourself lost at some
point?
• Why did a specific order exist for the creating of the element data and
then the creation of the queue reference?
• How would you change the templates?
• What other aspect of the process would you automate?
DISCUSSION
ni.com/training
ni.com/training
ni.com/training
To examine the design of a Timer class that was created with the Data
Value Reference (DVR) feature in LabVIEW.
GOAL
DISCUSSION
Process 1 or VI 1 Process 2 or VI 2
Pass Catch
ni.com/training
DISCUSSION
Wind Farm #3
DISCUSSION
Wind Farm #3
Data
Communication
VI Server (Set/Get Ctrl Value) Single Element Queue
Between UI and
Turbines
Shutdown
Poll FGV User events
Turbines
DISCUSSION
G. Inter-Target Communication
• Crosses the application instance and network boundary
• Can be used for local communication
• Good for design applications that must scale later
− VI Server
− Network Steams
Note: TCP is not covered in this course but falls under this category. You can use TCP
to facilitate communication with non-LabVIEW systems across the network.
ni.com/training
Use case
• Stream buffered data between two processes in different
applications or on different targets on a network
• High throughput
Caveat
• Both processes must be in a LabVIEW application
ni.com/training
Network Streams
Network Streams Characteristics
• Lossless
− Each network stream writes to and reads from FIFOs
• Unidirectional
− Transfers data in only one direction for each network stream
• One-to-one communication channel
− Each network stream consists of one writer and one reader
Computer 1 Computer 2
FIFO FIFO
Writer Network Streams Engine Reader
Endpoint Endpoint
ni.com/training
Network Streams
For more information, refer to the following topics of the
LabVIEW Help:
• Streaming Data and Sending Commands between
Applications
• Network Streams Functions
Computer 1 Computer 2
FIFO FIFO
Writer Network Streams Engine Reader
Endpoint Endpoint
ni.com/training
Standard Protocols
Use case
• Communicate with hardware and software that does not
support LabVIEW
− May already have a completed application that uses a
standard
t d d protocol
t l
• Standard protocol may be easiest solution
− Implement a broadcast model using UDP protocol
ni.com/training
ni.com/training
Courier
Message
Route
Sender (s) Receiver(s)
Scope:
Scalability:.
Performance:
Ease of implementation
ni.com/training
Queues
Courier – Lossless or lossy & buffered
Sender (s)
Message – Anything
ni.com/training
User Events
Courier – Lossless & Buffered
Sender (s) Receiver(s)
Message – Anything
ni.com/training
Notifiers
Courier – Lossy/Not Buffered
Receiver(s)
Message – Anything
Sender Receiver(s)
ni.com/training
DVRs
Courier – Current value
Sender (s) Receiver(s)
Message – Anything
ni.com/training
Network Streams
Courier – Lossless/buffered
Sender Receiver(s)
Route – 1:1 only
Scope: Different application instances, different network targets
Scalability: Not as easy, but essential for streaming across instances and the network
Performance: Very Fast
Ease of implementation: Not too difficult. Trickier for connects that are not continuous.
ni.com/training
ni.com/training
ni.com/training
AMC
Courier – Queue/UDP
Scope: Same application instance, different application instances, different network targets
Scalability: Easy to add processes. Message format is defined and scalable. Bi-directional by
design.
Performance: Good for messages, not streaming
Ease of implementation: Will require training, but does leverage foundational concepts.
ni.com/training
ni.com/training
ni.com/training
DEMONSTRATION
ni.com/training
ni.com/training
ni.com/training
Messages – CVT/CCC
Courier – FGV/TCP
Scope: Same application instance, different application instances, different network targets.
Scalability: Can call from any module.
Performance: Reasonable. Not for streaming.
Ease of implementation: Uses FGVs and STM reference library. Not very difficult.
ni.com/training
ni.com/training
DEMONSTRATION
DEMONSTRATION
DEMONSTRATION
Lesson 4
Advanced User Interface Techniques
TOPICS
A. Subpanels – Examples
B. XControls Overview – Review of Controls
C. XControl Abilities
D. XControl Properties and Methods
E. XControl Development – Editing XControls in Use
ni.com/training
ni.com/training
ni.com/training
A. Subpanels – Example
ni.com/training
S
Subb P
Panell MyVI vi
MyVI.vi
ni.com/training
ni.com/training
Wind Farm #2
DISCUSSION
Subpanels – Scalable
ni.com/training
Subpanels – Extensible
ni.com/training
ni.com/training
ni.com/training
Subpanel References
Explicitly linked
p y linked
Implicitly
Considerations
• Create a control reference to access more properties and
methods
• Consider sizing the subpanel to the front panel of the
inserted VI
ni.com/training
ni.com/training
<Exercises>\…\Demonstrations\Subpanels – Dock
Undock\Main_CP_example.vi
DEMONSTRATION
ni.com/training
ni.com/training
What is an XControl?
Front Panel of Main.vi
• XControls allow the architect Container
to create controls with
custom appearance and edit-
time and run-time
functionality
• For the user, the XControl
has the same functionality as
other controls
A single XControl
ni.com/training
XControl
Simple Xgraph
<Exercises>\…\Demonstrations\XControl\Simple
XGraph\Test X Graph Simple XControl.vi
DEMONSTRATION
Designing an XControl
• What is an XControl?
• What aspects of an XControl need to be defined?
DISCUSSION
Advantages of XControls
ni.com/training
ni.com/training
ni.com/training
ni.com/training
DISCUSSION
DEMONSTRATION
Using XControls
ni.com/training
ni.com/training
Structure of an XControl
Abilities
(Required)
Properties
XControl (Optional)
Methods
(Optional)
ni.com/training
C. XControl Abilities
ni.com/training
Data.ctl
State.ctl
• Specifies information other than data type that affect the appearance of the
XControl
• What information is necessary for describing the XControl?
• What methods and properties do you need for your XControl?
ni.com/training
Init.vi
ni.com/training
ni.com/training
Facade.vi
ni.com/training
ni.com/training
ni.com/training
ni.com/training
• Event Generation
− Generated when the value of the XControl changes as a result
of writing to its terminal, local variable, or Value property
− Not generated when other events set the Data Changed?
element of Action
• Purpose
− Performs any formatting or modification of the data
− Updates the state and control values as necessary
ni.com/training
ni.com/training
ni.com/training
ni.com/training
• Event generation
− Generated when an instance of the XControl changes from a
control to an indicator or vice versa
• Purpose
− Updates the appearance and properties of the control
• Modifies the properties of controls
<OR>
• Puts both a control and an indicator on the front panel and makes
the correct object visible
ni.com/training
ni.com/training
• Event generation
− Generated when a VI containing the XControl changes from
edit mode to run mode or vice versa
• Purpose
p
− Makes modifications to the appearance or properties of the
control if necessary
− Use the Run Mode? element of Container State to determine
the execution state (also works in other events)
ni.com/training
ni.com/training
ni.com/training
Abilities
(Mandatory)
Properties
XControl (Optional)
Methods
(Optional)
ni.com/training
XControl Properties
• Allow the user to configure the XControl programmatically
via Property Node
Main VI containing the XControl
XControl
XControl
Property Node
ni.com/training
Property Read VI
Property Write VI
ni.com/training
XControl Methods
• Allow the user to engage functionality of the XControl
programmatically via Invoke Node
Main VI containing the XControl XControl
XControl
Invoke Node
ni.com/training
XControl Methods
• Create by right-clicking the XControl library and selecting
New»Method
• Configure by right-clicking the Method and selecting Configure
Method
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
Set Wind
UI Parameters Wind Turbine
Speed
Call Get Turbine
Parameters
Error
Handler
a de Logger/
? Speed
Reporter
DISCUSSION
Wind Farm #2
Shutdown
Poll FGV Queues User events
Turbines
DISCUSSION
Lesson 5
Introduction to Object-Oriented
Programming in LabVIEW
TOPICS
A. What is Object Oriented Programming?
B. Recommended Resources
C. Class Diagrams and Design (Optional Section)
ni.com/training
OO emphasizes:
p
• Encapsulation– Only the methods grouped with the data
can access it so the data is protected
• Inheritance–Methods are dynamically called at run time
without the need to create a special framework
ni.com/training
ni.com/training
LVOOP
DEMONSTRATION
OOP Terminology
ni.com/training
OOP Terminology
ni.com/training
ni.com/training
OOP Terminology
ni.com/training
Class
Data + Methods = Data
Methods
ni.com/training
ni.com/training
OOP Terminology
ni.com/training
Data
ni.com/training
ni.com/training
Block diagram of VI
that is not a member
of the Report class
ni.com/training
Migrating to OOP
For those who choose object designs, wire and node should morph
naturally into class and method
R
Report Class
Cl
Object
Methods
ni.com/training
?
?
?
?
? ?
How many VIs access the cluster? Only the method VIs touch the data. The
How long could it take to find the developer’s search for the source of the
source of the bug? error narrows significantly.
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
GOAL
DISCUSSION
ni.com/training
B. Recommended Resources
• Applying Common OO Design Patterns to LabVIEW on NI
Community – information and examples for several OO
design patterns
Design Pattern Usage
Channeling Pattern Guarantee pre-processing/post-processing around some
dynamic central functionality
Factory Pattern Provide a way to initialize the value on a parent wire with data
from many different child classes based on some input value,
such as an enum or string input
Command Pattern Uses child classes to represent messages (command and
data) that need to be sent to a consumer loop, which executes
the functionality associated with the message
Hierarchy Composition Pattern Develop a single object as a tree of smaller instances of that
same object type
And more…
ni.com/training
Recommended Resources
Actor Framework
• Software library containing classes that supports the writing of
applications in which multiple VIs run independently while
communicating with each other
• <Exercises>\Advanced Architectures in LabVIEW\Adv Design
Patterns and Tools\Actor Framework
ni.com/training
Recommended Resources
• Object-Oriented Design and Programming in LabVIEW course – covers the
fundamental concepts of object-oriented design and programming and then
discusses how to implement those concepts in LabVIEW
• LabVIEW Object-Oriented Programming topic of LabVIEW Help – detailed
conceptual and procedural information for LVOOP
• LabVIEW Object Oriented Programming FAQ on ni.com – answers many
questions
ti andd provides
id useful
f l related
l t d lilinks,
k suchh as whitepapers,
hit
presentations, videos, and exercises
• LabVIEW Object Oriented Programming: The Decisions Behind the Design
on ni.com/zone – covers the design issues behind the LVOOP
implementation of object-oriented programming
• Refer to www.expressionflow.com for several good articles, including
one on plug-ins
• Explore the many threads on www.lavag.org
ni.com/training
Wind Farm #3
DISCUSSION
Data/Attributes
Methods (Verbs)
ni.com/training
Lesson 6
Plug-In Architectures
TOPICS
A. Using Plug-In Architecture with VI Server
B. Using Plug-In Architecture with LVOOP
ni.com/training
Waveform
Function Triangle.vi
Square.vi
ni.com/training
Advantages of Plug-Ins
ni.com/training
ni.com/training
ni.com/training
DEMONSTRATION
Design Considerations
DISCUSSION
ni.com/training
DISCUSSION
ni.com/training
ni.com/training
ni.com/training
GOAL
DISCUSSION
Lesson 7
Tips, Tricks, & Other Techniques
TOPICS
A. Variant Attributes
B. Callback VIs
C. VI Scripting
D. What is a Drop In VI?
E. Other
ni.com/training
A. Variant Attributes
• Very flexible mechanism for storing data
• Accepts any data type
• Lookup mechanism is a hash table
• Can replace the core of an FGV for implementations that
store a large number of elements
ni.com/training
Variant Attribute
<Exercises>\…\Demonstrations\Variant Attribute\Name
Value Lookup.vi
DEMONSTRATION
B. Callback VIs
A callback VI runs when a specified event occurs
1. Wire the reference of the event source.
2. Select the event.
3. Create and edit the callback VI from the VI Ref input.
3
ni.com/training
Callback VI
ni.com/training
Callback VI
DEMONSTRATION
C. VI Scripting
ni.com/training
VI Scripting
ni.com/training
ni.com/training
Calling VI code
Drop In VI
ni.com/training
ni.com/training
ni.com/training
ni.com/training
Edit Event
Add Button Add Case
Structure
ni.com/training
What if we used
control references,
thus eliminating the
step of editing the
event structure?
ni.com/training
A Better Solution…
ni.com/training
Drop In VI Example
Right-click Drop In VI
<Exercises>\…\Demonstrations\Drop In - Right
Click\Drop In – Right Click.lvproj
DEMONSTRATION
ni.com/training
• Single-shot Drop In VI
− Performs functionality on calling VI and finishes execution
− Examples
• Resize the front panel
p of callingg VI to the largest
g decoration
• Continuous Drop In VI
− Performs functionality on calling VI continuously
− Examples
• Right-click to show description of any Boolean control
• Allow user to move the VI by clicking and dragging the front panel
ni.com/training
ni.com/training
• Single-shot Drop In VI
• Continuous Drop In VI
<Exercises>\…\Demonstrations\Drop In – Single-shot
and Continuous\Drop In – Single-shot and
Continuous.lvproj
DEMONSTRATION
DISCUSSION
E. Other
ni.com/training
Lesson 8
Error Handling
TOPICS
A. Basic Error Handling Strategies
B. Comprehensive Error Handling Strategies
C. LabVIEW Implementation Example – SEH
ni.com/training
ni.com/training
C d
Code Error
E
handling
code
Code
ni.com/training
DEMONSTRATION
ni.com/training
ni.com/training
Possible actions
• Ignore
• Retry
• Correct
ni.com/training
ni.com/training
ni.com/training
Function
ni.com/training
ni.com/training
Error Communication
Priority
Queue
ni.com/training
ni.com/training
Priority
Queue Central
Handler
ni.com/training
Error Reporting
ni.com/training
Error Logging
ni.com/training
Throwing Errors
Error to
generate
ni.com/training
ni.com/training
Get
Process Take Action
& Filter
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
Get next error based on priority Handle error (log, report, etc)
ni.com/training
ni.com/training
DISCUSSION
Lesson 9
Additional Resources
TOPICS
A. Now What?
ni.com/training
A. Now What?
Which
What am I
techniques
missing?
should I use?
Wow… what
else can I
create?
ni.com/training
Wind Farm
DISCUSSION
DEMONSTRATION
Local
NI Idea
User
Exchange
Group
Communities
Large
LV
App
APIs
Dev
NI Labs
DEMONSTRATION
ni.com/training
In Conclusion…
ni.com/training
Appendix A
Additional XControl Programming
Techniques
TOPICS
A. Refresh Section
B. Shortcut Menus
C. Resizing the XControl
D. Defining Custom Events
ni.com/training
A. Refresh Section
ni.com/training
ni.com/training
B. Shortcut Menus
• Define right-click commands for
XControls like any other control
• Different controls on the
Facade can each have their
own right-click menus
• Handle
H dl the Shortcut
th Sh t tMMenu
Activation? event and alter the
menu
• Use to provide quick access to
properties or display a
configuration dialog box
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
Generate events from any XControl VI with access to the display state
ni.com/training
ni.com/training
ni.com/training