Labview Core 2 Instructor Guide: November 2014
Labview Core 2 Instructor Guide: November 2014
Instructor Guide
November 2014
Table of Contents
LabVIEW Core 2 Course Overview ............................................................... 1
COURSE OBJECTIVES ........................................................................................................ 1
TARGET AUDIENCE ............................................................................................................ 1
ABOUT THIS GUIDE............................................................................................................ 1
Instructor Notes ............................................................................................. 2
LESSON OVERVIEW ........................................................................................................... 2
COURSE TIMING ................................................................................................................ 3
Welcome and Housekeeping ......................................................................... 5
Lesson 1. Using Variables ........................................................................... 6
A. VARIABLES ................................................................................................................... 6
B. USING VARIABLES APPROPRIATELY ................................................................................ 7
C. RACE CONDITIONS ........................................................................................................ 8
Lesson 2. Communicating Data Between Parallel Loops........................... 10
A. INTRODUCTION ............................................................................................................ 10
B. QUEUES ..................................................................................................................... 11
C. NOTIFIERS .................................................................................................................. 12
D. SUMMARY .................................................................................................................. 13
Lesson 3. Implementing Design Patterns .................................................. 14
A. W HY USE DESIGN PATTERNS? ..................................................................................... 14
B. SIMPLE DESIGN PATTERNS ......................................................................................... 14
C. MULTIPLE LOOP DESIGN PATTERN ............................................................................... 15
D. FUNCTIONAL GLOBAL VARIABLE DESIGN PATTERN ........................................................ 17
E. ERROR HANDLERS ...................................................................................................... 19
F. GENERATING ERROR CODES AND MESSAGES ................................................................ 20
G. TIMING A DESIGN PATTERN.......................................................................................... 21
Lesson 4. Controlling the User Interface .................................................... 25
A. VI SERVER ARCHITECTURE .......................................................................................... 25
B. PROPERTY NODES ...................................................................................................... 27
C. INVOKE NODES ........................................................................................................ 28
D. CONTROL REFERENCES .............................................................................................. 29
Lesson 5. File I/O Techniques ................................................................... 32
A. FILE FORMATS ............................................................................................................ 32
B. CREATING FILE AND FOLDER PATHS ............................................................................. 33
C. W RITE AND READ BINARY FILES ................................................................................... 34
D. W ORK WITH MULTICHANNEL TEXT FILES WITH HEADERS ................................................ 35
E. ACCESS TDMS FILES IN LABVIEW AND EXCEL ............................................................. 37
Lesson 6. Refactoring Code ...................................................................... 39
A. REFACTORING INHERITED CODE ................................................................................... 39
B. TYPICAL REFACTORING ISSUES .................................................................................... 40
Lesson 7. Creating and Distributing Applications ....................................... 42
A. PREPARING THE FILES ................................................................................................. 42
B. BUILD SPECIFICATIONS ................................................................................................ 43
C. CREATE AND DEBUG AN APPLICATION ........................................................................... 44
D. CREATE AN INSTALLER ................................................................................................ 47
Next Steps… ............................................................................................... 50
LabVIEW Core 2 Course Overview
Course Objectives
The LabVIEW Core 2 course is an extension of the LabVIEW Core 1 course and teaches common
design patterns to successfully implement and distribute LabVIEW applications.
Target Audience
• New LabVIEW users • Might be interested in certification
• Engineers and scientists • Interested more in practice than
• Widely varied disciplines and applications assessment
• Computer literate • Both US and International
• Very little past experience with LabVIEW
About This Guide
This Instructor Guide is your primary tool to plan, prepare for, and conduct the course. It is
important for you to review this guide thoroughly, well in advance of the course. The following
icons are included in this guide.
Lesson Overview
The following table contains a breakdown of the overall lesson and non-lecture activity duration.
Welcome and
housekeeping
Timing
Day Activity Name Estimates
(h:m)
Content/Narrative Materials/
Duration
Slide 1 National Instruments
Title slide
Slide 2 LabVIEW Core 2
Title slide
Slide 3 What You Need to Get Started
Review the hardware and software requirements to get the most out of
the course.
Slide 4 File Locations
Tell the students where to find the exercise and multimedia files on disk.
Slide 5 Instructional Methods
Go over the instruction methods for the course.
Slide 6 Getting the Most out of this Course
Reassure everyone that mistakes are okay and that they will not break
anything. When a student makes a mistake, use it as a learning
opportunity.
Our goal is to teach a student to be self-sufficient when the instructor is
no longer available.
Slide 7 LabVIEW Certification
Slide 8 Course Learning Map
Slide 9 This course prepares you to:
Go over some of the objectives of the course.
Content/Narrative Duration
Slide 1 State the lesson objective.
Briefly outline the topics covered in this lesson.
Slide 2 15 min
A. Variables
Objective: Identify the differences between local and global variables.
Slide 3 Definition: Variables—Block diagram elements that access or store data from
another location.
Point out that variables can be written to or read from multiple places.
Slide 4 Local versus Global Variables
Briefly highlight the differences. Students will learn more in the multimedia
module coming up.
Point out difference in icons.
Local Global
Stores data in front panel controls Stores data in special repositories in the
and indicators. project.
Accessible only within a VI. Can be accessed from multiple VIs.
Content/Narrative Duration
Slide 1 State the lesson objective.
Briefly outline the topics covered in this lesson.
Slide 2 5 min
A. Introduction
Objective: Review using local variables to communicate between parallel
loops.
Slide 3 Communicating Data Between Parallel Loops – Local Variables
Review potential reasons to use parallel loops
• Execute tasks simultaneously
• Execute tasks at different rates
Common use case of local variables and parallel loops is the Stop button
(shown on slide). The bottom loop only needs to know the latest value of the
stop button.
The key point is “latest data”.
o The reading loop only needs the latest value of the stop button.
o The reading loop only needs to act on the current setpoint and doesn’t
care about previous setpoints.
Slide 4 If you need to transfer every point of data between parallel loops, should
you use a local variable?
Let students answer this question.
Answer: No, you should not use a local variable for this scenario because of
the following:
• It is possible to read duplicate data in the bottom loop.
• It is possible to miss data in the bottom loop.
This is due to local variables only being able to share the latest data. The next
topic, queues, will provide the solution to this scenario.
Lesson 2 Communicating Data Between Parallel Loops
10 A. Introduction
Slide 5 35 min
B. Queues
Objective: Transfer every point of data between parallel loops using queues
Content/Narrative Duration
Slide 1 State the lesson objective.
Briefly outline the topics covered in this lesson.
Slide 2 5 min
A. Why Use Design Patterns?
Objective: Describe the benefits of design patterns.
Slide 3 Benefits of Design Patterns
• Design patterns represent techniques that have proven themselves useful
time and time again.
• Pattern recognition helps other developers (and you!) to read and make
changes to your code.
Slide 4 5 min
B. Simple Design Patterns
Objective: Describe and use simple VI design patterns
Content/Narrative Duration
Slide 1 State the lesson objective.
Briefly outline the topics covered in this lesson.
Slide 2 10 min
A. VI Server Architecture
Objective: Describe the purpose of the VI Server and the class hierarchy of
properties and methods.
Slide 3 VI Server Purpose and Use
• The VI Server provides programmatic access to LabVIEW.
• Use the VI Server to:
o Programmatically control front panel objects & VIs
o Dynamically load and call VIs
o Run VIs on a computer or remotely across a network
o Programmatically access to the LabVIEW environment and editor
(Scripting)
The VI Server uses a referenced-based architecture, which is consistent with
other common LabVIEW architectures such as file I/O, DAQ, and VISA.
VI Server has an object-oriented architecture that is platform-independent.
In this class, we cover calling properties and methods to control the user
interface. In the LabVIEW Connectivity course, we cover other VI Server
features such as dynamically running VIs on both local and remote systems.
Slide 4 Properties and Methods
Definition: Properties─Single-valued attributes of the object, such as
read/write, read only, and write only.
Examples: Color, position, size, visibility, label text, and label font
Definition: Methods─Functions that operate on the object.
Examples: reinitializing values to default, exporting graph images
Content/Narrative Duration
Slide 1 State the lesson objective
Briefly outline the topics covered in this lesson.
Slide 2 5 min
A. File Formats
Objective: The learner will be able to recognize appropriate use cases and
the pros and cons of each file type.
Slide 3 Files store data as a series of bits.
• At their lowest level, all files written to your computer’s hard drive are a
series of bits.
• Briefly describe the three common file types in LabVIEW:
o ASCII file format
o TDMS file format
o Direct binary data storage
Lesson 5 File I/O Techniques 35 D. Work with Multichannel Text Files with Headers
Slide 21 Discussion: Exercise 5-2: Creating File and Folder Paths
Question: When reading the data back into LabVIEW, what function did
you use to skip over the header information?
Answer: Array Subset. This function returns a portion of an array. For a
2D array, the function displays the index inputs for a row and a column. We
used a row index of 4 to skip over the first 4 rows of header information
(date, time, operator, and UUT serial)..
Slide 22 Activity 5-1: Read Data and Extract Information 10 min
• Review/discuss questions on slide as a group.
• Have students write answers in space provided in Participant Guide
Lesson 5 File I/O Techniques 36 D. Work with Multichannel Text Files with Headers
Slide 25 40 min
E. Access TDMS Files in LabVIEW and Excel
Objective: Identify TDMS file I/O VIs and functions from the File I/O
palette and identify the pros and cons of using them.
Slide 26 TDMS File Format
• Contains two types of data:
o Metadata
o Raw data
• Binary file (.tdms) - Contains data and stores properties
• Binary index file (*.tdms_index) - Provides info on attributes and
pointers in the TDMS file
o Speeds access to data
o Automatically regenerated if lost
Slide 27 TDMS Files - Data Hierarchy and Properties
• Discuss overall TDMS data structure/hierarchy
o Dataset
o Channel Group
o Channel(s)
• Customization of properties
Slide 28 TDMS Functions
• Review TDMS API
• Point out that the Write to Measurement File and Read From
Measurement File Express VIs have the ability to work with TDMS files.
Slide 29 TDMS Files - File Viewer
Discuss opening and presenting TDMS file data in the TDMS File Viewer
dialog box.
Slide 30 Exercise 5-3: Creating File and Folder Paths 25 min
Goal: In this exercise, students use what they have learned log data to a
TDMS file and read the same TDMS data file to access information about a
specific channel.
Encourage students to complete the optional steps at the end of the exercise
regarding the TDM Excel Add-in.
Lesson 5 File I/O Techniques 37 E. Access TDMS Files in LabVIEW and Excel
Slide 31 Discussion: Exercise 5-3: Creating File and Folder Paths
Question: What is the purpose of the Time Stamp constant and the Empty
String constant in the TDMS Reader.vi?
Answer: These constants define the data type of the properties being read
from the TDMS file. Wire these inputs before wiring the property value
output.
Question: Did the TDMS Read function read all the data in the TDMS file?
Answer: No. We read a subset of the data based on the Data Set value
(Time Data or Power Spectrum) and Serial Number. In the last text file
example, we read in all the data and then used array functions to extract
subsets of the data. With TDMS, this is handled automatically as part of the
TDMS Read operation.
Question: Why would it be difficult to implement the logger and reader
using ASCII files? Custom Binary files?
Answer: To implement this in ASCII or Binary would require considerable
amount of organization, either within one file or split into separate files. For
example, one approach would be to separate the data into separate files with
UUT and other property information embedded into the filename. E.g.,
“JohnSmith_Jun25_2009_UUT_A001” This would make your disk
organization more complex but simplify the data reader and writer.
Slides 32 Activity 5-2: Lesson Review 5 min
to 40 Have students complete the review at the end of the lesson in their
Participant Guides. Then come together as a class to review and discuss.
1. The answer is unknown, because we don’t know if the VI has been
loaded as part of a project or not. If so, then B. If not, then A.
2. The Search 1D Array function returns -1 when it cannot find the
specified value.
3. Excel can easily load tab-delimited ASCII and TDMS files. Custom
binary files require that you provide additional information on how to
read the file.
4. TDMS files store properties at the File, Channel Group, and Channel
levels.
Lesson 5 File I/O Techniques 38 E. Access TDMS Files in LabVIEW and Excel
Lesson 6. Refactoring Code
Objective: Recognize a VI that can be improved and practice techniques to improve existing VIs.
This lesson contains the following topics:
A. Refactoring Inherited Code
B. Typical Refactoring Issues
Duration: 1 hour, 10 minutes
Content/Narrative Duration
Slide 1 State the lesson objective.
Briefly outline the topics covered in this lesson.
Slide 2 10 min
A. Refactoring Inherited Code
Objective: Explain the refactoring process and identify VIs that would benefit
from refactoring.
Slide 3 Definition
Refactoring — Process of redesigning code such that:
• Code is easier to read, scale, and maintain.
• Cost of future changes does not increase over time.
• Observable behavior of software is unchanged.
Inherited VIs may be poorly designed, making it difficult to add features later
in the life of the VI.
Slide 4 When to Refactor
• When you are adding a feature to a VI or debugging it.
• Good candidates for complete rewrites:
o VIs that do not function.
o VIs that satisfy only a small portion of your needs.
Slide 5 Refactoring Process
Before you begin refactoring, Develop a test sequence to verify its
functionality.
For each improvement that you make, use that test sequence to ensure that
your modifications did not affect the core functionality of the code.
Repeat that process until you have made all of the desired improvements.
For more information on developing functionality tests for your code, consider
attending the Managing Software Engineering in LabVIEW course.
Content/Narrative Duration
Slide 1 State the lesson objective.
Objective: Make necessary code modifications, then select and build the
appropriate deployment option for a LabVIEW application.
Slide 2 35 min
A. Preparing the Files
Objective: Identify tasks to complete when preparing project files for
distribution.
Slide 3 First, prepare your files.
These are important steps to create professional, stand-alone applications.
Point out to students that, even though we are just covering these concepts
now, they should develop their VIs with these steps in mind from the very
beginning.
Slide 4 VI Properties
• VI Properties dialog box for window appearance.
• Programmatically setting VI properties using VI Server property nodes.
Slide 5 Paths
• Recommend: Set paths relative to Application Directory VI path
• Review table on slide
Slide 6 System Paths
• Use the Get System Directory VI to get system directory paths.
• Paths differ based on the operating system and user.
o Windows XP User Documents:
C:\Documents and Settings\<user>\My Documents
o Windows 7 User Documents:
C:\Users\<user>\Documents
• Architecture issues:
Static vs. dynamic files. You must explicitly include dynamically linked
files in your build specification.
• Programming issues:
File and folder paths. You must ensure that your file and folder paths are
valid on other systems.
• Build process:
The configuration settings of your build specification can impact your
application. For example, if you enable debugging, the size of the
executable will be larger compared to the same executable without
debugging enabled.
• Installer process:
The configuration settings of your build specification can impact your
deployed application. Be sure to include required driver installers. If the
target system already has the LabVIEW Run-Time Engine installed, you
don’t need to include.
Slide 40 Building Applications Checklist─Job Aid
Direct students to their participant guide for some helpful tips on distributing
builds.
Slide 41- Activity 7-1: Lesson Review 5 min
45 Have students complete the review at the end of the lesson in their Participant
Guides. Then come together as a class to review and discuss.
1. Installers, ZIP files, and Executables use LabVIEW build specifications.
2. True, False, True, False
Content/Narrative Duration
Slide 1-2 Continuing Your LabVIEW Education:
LabVIEW Core 3
Go over the goals of the LabVIEW Core 3 course.
Slide 3 Continuing Your LabVIEW Education:
Other training
Go over the other available courses.
Slide 4 NI LabVIEW Skills Guide
Slide 5-6 Continue Your Learning
Slide 7 LabVIEW Certification
Go over the learning path.
Slide 8 Thank You!
Ask students to fill out the survey.