Professional Documents
Culture Documents
Core 1 - Combined Slides With Custom Slideshows
Core 1 - Combined Slides With Custom Slideshows
Core 1 - Combined Slides With Custom Slideshows
TOPICS
Lesson 1, Slide 1
What You Need to Get Started
Lesson 1, Slide 2
File Locations
Exercises LabVIEW
Root Directory <or>
Solutions Core 1
Lesson 1, Slide 3
Instructional Methods
Demonstrations
Concept
Quizzes
Exercise
Development
Lecture Topic Exercise
Lesson 1, Slide 4
Getting the Most out of this Course
• Ask questions!
• Experiment with hands-on exercises to understand the
methods used
• Explore solutions
• Implementations explore a possible solution—you may find
a better one
Lesson 1, Slide 5
New User Experienced User Advanced User
LabVIEW Performance
Certifications
Certified LV Associate Certified LabVIEW Certified LabVIEW
Developer Exam Developer Exam Architect Exam
Other Courses
Lesson 1, Slide 6
Course Learning Map
Lesson 1 Lesson 4 Lesson 7
Developing Modular Using Sequential and State
Navigating LabVIEW
Applications Machine Algorithms
Lesson 3 Lesson 6
Managing File and Hardware
Implementing a VI
Resources
Lesson 1, Slide 7
Course Goals
Lesson 1, Slide 8
Lesson 1
Navigating LabVIEW
TOPICS
A. What Is LabVIEW? F. Searching for Controls, VIs
B. Project Explorer and Functions
C. Parts of a VI G. Selecting a Tool
D. Front Panel H. Dataflow
E. Block Diagram I. Building a Simple VI
Lesson 1, Slide 9
A. What Is LabVIEW?
Lesson 1, Slide 10
What Is LabVIEW?
— A graphical programming environment used to develop
sophisticated measurement, test, and control systems.
LabVIEW:
• Interfaces with wide
variety of hardware
• Scales across
different targets and
OSs
• Provides built-in
analysis libraries
Lesson 1, Slide 11
LabVIEW Language Characteristics
Lesson 1, Slide 12
B. Project Explorer
Project Explorer Window
Files Types
Project Folders
Lesson 1, Slide 13
Project Explorer
Lesson 1, Slide 14
LabVIEW Files
Lesson 1, Slide 15
Adding Folders to a Project
• Virtual folder
− Organizes project items and
does not represent files on
disk
• Auto-populating folder
− Adds a directory on disk to the
project
− LabVIEW continuously
monitors and updates the
folder according to changes
made in the project and on
disk
Lesson 1, Slide 16
C. Parts of a VI
Front Panel
Block Diagram
Icon
Connector Pane
Lesson 1, Slide 17
Parts of a VI
VIs have 3 main components:
Icon/Connector pane
Block diagram
Front panel
Lesson 1, Slide 18
Parts of a VI – Front Panel
Lesson 1, Slide 19
Parts of a VI – Block Diagram
Block Diagram – Contains the
graphical source code
Lesson 1, Slide 20
Parts of a VI – Icon/Connector Pane
Icon – Graphical representation of a VI
Lesson 1, Slide 21
Using the Project Explorer and Starting a VI
DEMONSTRATION
D. Front Panel
Controls and Indicators
Object Styles
Object Types
Boolean
Numeric
String
Lesson 1, Slide 23
Front Panel
Lesson 1, Slide 24
Controls and Indicators
Controls Indicators
− Input devices − Output devices
− Knobs, buttons, slides − Graphs, LEDs
− Supply data to the block − Display data the block diagram
diagram acquires or generates
Lesson 1, Slide 25
Front Panel Object Styles
Lesson 1, Slide 26
Numeric Controls and Indicators
Numeric control
Increment/Decrement buttons
Numeric indicator
Lesson 1, Slide 27
Boolean Controls and Indicators
• The Boolean data type represents data that has only two
options, such as True/False or On/Off.
• Use Boolean controls and indicators to enter and display
Boolean (TRUE/FALSE) values.
• Boolean objects simulate switches, push buttons, and LEDs.
Boolean Boolean
control indicator
Lesson 1, Slide 28
Strings
• The string data type is a sequence of ASCII characters .
• Use string controls to receive text from the user, such as a
password or user name.
• Use string indicators to display text to the user.
Lesson 1, Slide 29
E. Block Diagram
Terminals
Nodes
Wires
Context Help
Lesson 1, Slide 30
Block Diagram
Lesson 1, Slide 31
Block Diagram
Lesson 1, Slide 32
Terminals
Lesson 1, Slide 33
Terminals for Front Panel Objects
• Terminals are:
– Entry and exit ports that exchange information between the
front panel and block diagram.
– Analogous to parameters in text-based programming
languages.
• Double-click a terminal to locate the corresponding front
panel object.
Lesson 1, Slide 34
View Terminals as Icons
Lesson 1, Slide 35
Nodes
Nodes are objects on the block diagram that have inputs
and/or outputs and perform operations when a VI runs.
Nodes
Lesson 1, Slide 36
Function Nodes
• Functions are:
− Fundamental operating elements of LabVIEW.
− Do not have front panels or block diagrams, but do have
connector panes.
− Has a pale yellow background on its icon.
• Double-clicking a function only selects the function.
• Functions do not open like VIs and subVIs.
Lesson 1, Slide 37
SubVI Nodes
• SubVIs :
− Are VIs that you use on the block diagram of another VI.
− Have front panels and block diagrams.
− Use the icon from the upper-right corner of the front panel as
the icon that appears when you place the subVI on a block
diagram.
• When you double-click a subVI, the front panel and block
diagram open.
• Any VI has the potential to be used as a subVI.
Lesson 1, Slide 38
Express VIs
• Express VIs:
− Are a special type of subVI.
− Require minimal wiring because you configure them
with dialog boxes.
− Save each configuration as a subVI.
• Icons for Express VIs appear on the block diagram
as icons surrounded by a blue field.
Lesson 1, Slide 39
Node View Options
Lesson 1, Slide 40
Wires
• Wires transfer data between block diagram objects.
• Wires are different colors, styles, and thicknesses,
depending on their data types.
• A broken wire appears as a dashed
black line with a red X in the middle.
Scalar
1-D Array
2-D Array
Lesson 1, Slide 41
Context Help
• Displays basic information
about wires and nodes when
you move the cursor over an
object.
• Can be shown or hidden in
the following ways.
− Select Help»Show Context
Help from the LabVIEW menu.
− Press <Ctrl-H>.
− Click the following button on the
toolbar:
Lesson 1, Slide 42
LabVIEW Help
• Contains detailed descriptions and instructions for most
palettes, menus, tools, VIs, and functions.
• Can be accessed by:
− Selecting Help»
LabVIEW Help from the
menu.
− Clicking the Detailed help
link in the
Context Help window.
− Right-clicking an object
and selecting Help from
the shortcut menu.
Lesson 1, Slide 43
Examples
• LabVIEW includes
hundreds of example
VIs.
• Use NI Example Finder
to browse and search
installed examples.
− Select Help»Find
Examples in the menu.
• Click the example buttons in LabVIEW Help topics.
Lesson 1, Slide 44
Group Exercise 1-1
Concept: Exploring a VI
DISCUSSION
F. Searching for Controls, VIs, and
Functions
Palettes
Quick Drop
NI Global Search
Lesson 1, Slide 47
Searching for Controls, VIs, and Functions
Lesson 1, Slide 48
Controls Palette
Lesson 1, Slide 49
Functions Palette
Lesson 1, Slide 50
Searching with Quick Drop
Lesson 1, Slide 51
Global Search
Use the Search bar in the top right of the front panel and block
diagram windows to search palettes, LabVIEW Help, and
ni.com.
Lesson 1, Slide 52
Search for Controls, VIs, and Functions
DEMONSTRATION
Exercise 1-2
Concept: Locating Controls, Functions, and VIs
DISCUSSION
G. Selecting a Tool
Selecting a Tool
Block Diagram Clean-Up
Lesson 1, Slide 56
Selecting a Tool
Lesson 1, Slide 57
Wiring Tips
• Press <Ctrl-B> to delete all broken wires.
• Right-click and select Clean Up Wire to reroute the wire.
Lesson 1, Slide 58
Wiring Tips – Clean Up Diagram
Use the Clean Up Diagram tool to reroute multiple wires and
objects and to improve readability.
1. Select a section of your block diagram.
2. Click the Clean Up Diagram button on the block diagram
toolbar.
Lesson 1, Slide 59
Cloning and Moving Items
• Clone an object in LabVIEW using the following steps:
1. Select the Positioning tool.
2. Press the <Ctrl> key while clicking an object.
3. Drag the copy to new location.
• Move an object using the following steps:
1. Select the Positioning tool.
2. Click and drag the object to new location.
Note: Avoid cutting and pasting objects as this can impact related items.
For example, cutting and pasting a block diagram terminal also moves the
front panel object.
Lesson 1, Slide 60
Selecting, Editing, Resizing and Wiring
DEMONSTRATION
Exercise 1-3
Concept: Selecting a Tool
DISCUSSION
H. Dataflow
Lesson 1, Slide 64
Dataflow
LabVIEW follows a dataflow model for running VIs.
• A node executes only when data are available at all of its
required input terminals.
• A node supplies data to the output terminals only when the
node finishes execution.
Lesson 1, Slide 65
Dataflow – Quiz
Lesson 1, Slide 66
Dataflow – Quiz Answers
Lesson 1, Slide 67
Group Exercise 1-4
Concept: Dataflow
GOAL
Group Exercise 1-4
Concept: Dataflow
DISCUSSION
Group Exercise 1-4
Concept: Dataflow
DISCUSSION
Group Exercise 1-4
Concept: Dataflow
DISCUSSION
Group Exercise 1-4
Concept: Dataflow
DISCUSSION
I. Building a Simple VI
Lesson 1, Slide 73
Building a Simple VI
Lesson 1, Slide 74
Acquire Express VIs
Lesson 1, Slide 75
Analyze Express VIs
• Statistics Express VI
• Filter Express VI
Lesson 1, Slide 76
Present Express VIs and Indicators
• Report Express VI
Lesson 1, Slide 77
Building and Running a VI
Lesson 1, Slide 78
Exercise 1-5, Part A – Group Exercise
Simple Acquire, Analyze, and Present Design
Scenario:
• Acquire a sine waveform 0.1 seconds.
• Determine the average value of the waveform.
• Log the data.
• Display the data to a graph.
GOAL
Exercise 1-5, Part A – Group Exercise
Simple Acquire, Analyze, and Present Design
DISCUSSION
Exercise 1-5, Part A – Group Exercise
Simple Acquire, Analyze, and Present Design
DISCUSSION
Exercise 1-5, Part B
Simple Acquire, Analyze, and Present VI
How do you determine the file path of the generated text file?
DISCUSSION
Summary—Quiz
1. Which function executes first:
Add or Subtract?
a) Add
b) Subtract
c) Unknown
Lesson 1, Slide 84
Summary—Quiz Answer
1. Which function executes first:
Add or Subtract?
a) Add
b) Subtract
c) Unknown
Lesson 1, Slide 85
Summary—Quiz
2. Which function executes first:
Sine or Divide?
a) Sine
b) Divide
c) Unknown
Lesson 1, Slide 86
Summary—Quiz Answer
2. Which function executes first:
Sine or Divide?
a) Sine
b) Divide
c) Unknown
Lesson 1, Slide 87
Summary—Quiz
3. Which of the following
functions executes first:
Random Number, Add or
Divide?
a) Random Number
b) Divide
c) Add
d) Unknown
Lesson 1, Slide 88
Summary—Quiz Answer
3. Which of the following
functions executes first:
Random Number, Add or
Divide?
a) Random Number
b) Divide
c) Add
d) Unknown
Lesson 1, Slide 89
Summary—Quiz
4. Which of the following
functions executes last:
Random Number, Subtract or
Add?
a) Random Number
b) Subtract
c) Add
d) Unknown
Lesson 1, Slide 90
Summary—Quiz Answer
4. Which of the following
functions executes last:
Random Number, Subtract or
Add?
a) Random Number
b) Subtract
c) Add
d) Unknown
Lesson 1, Slide 91
Summary—Quiz
Lesson 1, Slide 92
Summary—Quiz Answer
Lesson 1, Slide 93
Lesson 2
Troubleshooting and Debugging VIs
TOPICS
A. Correcting Broken VIs
B. Debugging Techniques
C. Undefined or Unexpected Data
D. Error Handling
Lesson 2, Slide 1
A. Correcting Broken VIs
Lesson 2, Slide 2
Correcting Broken VIs
Lesson 2, Slide 3
Common Causes of Broken VIs
Lesson 2, Slide 4
B. Debugging Techniques
Execution Highlighting
Single-Stepping
Probes
Breakpoints
Lesson 2, Slide 5
Debugging Techniques
Lesson 2, Slide 6
Execution Highlighting
• Use execution highlighting to watch the data flow through
the block diagram.
• If the VI runs more slowly than expected, confirm that you
turned off execution highlighting in subVIs.
Lesson 2, Slide 7
Single-Stepping
• Single-step through the VI to view each action of the VI on
the block diagram.
• Suspend the execution of a subVI to edit values of controls
and indicators, to control the number of times it runs, or to
go back to the beginning of the execution of the subVI.
− Open subVI and select Operate»Suspend When Called from
the shortcut menu.
Lesson 2, Slide 8
Probes
• Use the Probe tool to observe intermediate data
values and check the error output of VIs
and functions, especially those performing I/O.
• Specify to retain the values in the wires so that
you can probe wires for data after execution.
Lesson 2, Slide 9
Breakpoints
• When you reach a breakpoint during execution, the
VI pauses and the Pause button appears red.
• You can take the following actions at a breakpoint:
− Single-step through execution using the single-stepping buttons.
− Probe wires to check intermediate values.
− Change values of front panel controls.
− Click the Pause button to continue running to the next breakpoint
or until the VI finishes running.
Lesson 2, Slide 10
C. Undefined or Unexpected Data
Lesson 2, Slide 11
Undefined or Unexpected Data
Check for unexpected Inf values or NaN values in your
mathematical operations:
• ∞ (Inf)
− Infinity
− Produced by dividing a number by zero.
• NaN
− Not a number
− Produced by invalid operations, such as taking the square root
of a negative number.
Lesson 2, Slide 12
Exercise 2-1
Concept: Debugging
DISCUSSION
D. Error Handling
Automatic and Manual Error Handling
Merge Errors Function
Error Clusters
Warnings
Lesson 2, Slide 15
Error Handling
Error Handling – Anticipation, detection,
and resolution of warnings and errors
• You cannot predict every problem a user can encounter.
• Without a mechanism to check for errors, you know only that
the VI does not work properly.
• Error handling tells you why and where errors occur.
− Automatic error handling
− Manual error handling
Lesson 2, Slide 16
Automatic Error Handling
• By default, LabVIEW automatically handles any known error
when a VI runs by:
− Suspending execution.
− Highlighting the subVI or function where the error occurred.
− Displaying the Error list window.
• Automatic error handling is:
− Acceptable for quick prototypes.
− Not recommended for professional application development.
− Not included in LabVIEW-built executables.
Lesson 2, Slide 17
Manual Error Handling
• You control when dialog boxes appear.
• Propagate errors by wiring the error out cluster to error in
cluster of next node to execute.
• Terminate the error chain with a call to Simple Error Handler
VI.
Lesson 2, Slide 18
Automatic vs. Manual Error Handling
DEMONSTRATION
Disable Automatic Error Handling
• Options Dialog Box
− Block Diagram page
• Uncheck
− Enable automatic error handling in new VIs
− Enable automatic error handling dialogs
• Other suggested changes
− Front Panel page
• Set Control Style for New VIs to Silver style
− Block Diagram page
• Uncheck
− Place front panel terminals as icons
• Configure Block Diagram Cleanup to customize your block diagram
Lesson 2, Slide 20
Merge Errors
Lesson 2, Slide 21
Merge Errors Function
• Merge Errors function returns the first error found. If no error
is found, it returns the first warning.
• The Merge Errors function does not concatenate errors.
Lesson 2, Slide 22
Error Clusters
• Use the error cluster controls and indicators to create error
inputs and outputs in subVIs.
• The error in and error
out clusters include the
following components
of information:
− Status
− Code
− Source
Lesson 2, Slide 23
Errors and Warnings
Status = FALSE
Status = TRUE Code = Non-zero
Error Warning
Lesson 2, Slide 24
Errors and Warnings Recommendations
Lesson 2, Slide 25
Summary—Quiz
Lesson 2, Slide 26
Summary—Quiz Answer
Lesson 2, Slide 27
Summary—Quiz
Lesson 2, Slide 28
Summary—Quiz Answer
Lesson 2, Slide 29
Summary—Quiz
3. All errors have negative error codes and all warnings have
positive error codes.
a) True
b) False
Lesson 2, Slide 30
Summary—Quiz Answer
3. All errors have negative error codes and all warnings have
positive error codes.
a) True
b) False
Lesson 2, Slide 31
Summary—Quiz
Lesson 2, Slide 32
Summary—Quiz Answer
Lesson 2, Slide 33
Lesson 3
Implementing a VI
TOPICS
A. Front Panel Basics F. Timing a VI
B. LabVIEW Data Types G. Data Feedback in Loops
C. Documenting Code H. Plotting Data – Waveform Chart
D. While Loops I. Case Structures
E. For Loops
Lesson 3, Slide 1
A. Front Panel Basics
Lesson 3, Slide 2
Front Panel Basics
Lesson 3, Slide 3
B. LabVIEW Data Types
Shortcut Menu and Properties Dialog Box
Numeric Types
Boolean Types
String Types
Enums and Other Types
Lesson 3, Slide 4
LabVIEW Data Types
Lesson 3, Slide 5
Shortcut Menus
• All LabVIEW objects have
associated shortcut
menus.
• Use shortcut menu items
to change the look or
behavior of objects.
• To access the shortcut
menu, right-click the
object.
Lesson 3, Slide 6
Properties Dialog Box
• All LabVIEW objects have
properties.
• To access properties,
right-click the object and
select Properties.
• Property options are
similar to shortcut menu
options.
• Select multiple objects to
simultaneously configure
shared properties.
Lesson 3, Slide 7
Numerics
Various data type
representations:
• Floating-point
• Unsigned integers
• Signed integers
Lesson 3, Slide 8
Numeric Conversion Coercion Dot
Lesson 3, Slide 9
Booleans
• Behavior of Boolean
controls is specified by the
mechanical action.
• Boolean have only
TRUE/FALSE values.
Lesson 3, Slide 10
Mechanical Action of Booleans
Lesson 3, Slide 11
Mechanical Action of Booleans
DEMONSTRATION
Strings
• A string is a sequence
of ASCII characters.
• Strings have various
display styles.
− Backslash codes
− Password
− Hex
Lesson 3, Slide 13
Enums
• Enums give users a list of
items from which to
select.
• Each item represents a
pair of values.
− String
− 16-bit Integer
Lesson 3, Slide 14
Other Data Types
Refer to LabVIEW Help for complete list of terminal symbols
for different types of controls and indicators.
• Dynamic
− Stores the information generated or acquired by an Express VI.
• Path
− Stores the location of a file or directory using the standard
syntax for the platform you are using.
• Waveform
− Carries the data, start time, and dt of a waveform.
Lesson 3, Slide 15
Searching Help for Data Types
DEMONSTRATION
C. Documenting Code
VI Descriptions
Tip Strips
Labels
Free
Owned
Lesson 3, Slide 17
Documenting Code
Lesson 3, Slide 18
Creating Descriptions and Tip Strips
Lesson 3, Slide 19
Documenting Block Diagram Code
Free labels: Owned labels:
• Describe algorithms. • Explain data contents of wires
• Have pale yellow backgrounds. and objects.
• Double-click in any open space • Move with object.
to create. • Have transparent
backgrounds.
• Select Visible Items»Label
from the shortcut menu to
create.
Lesson 3, Slide 20
Exercise 3-1
Temperature Warnings VI
DISCUSSION
D. While Loops
Iteration and Conditional Terminals
Tunnels
Error Checking
Lesson 3, Slide 23
While Loops
Repeat (code);
Until Condition met;
End;
Lesson 3, Slide 24
While Loops
Iteration terminal Conditional terminal
• Returns number of times loop • Defines when the loop stops.
has executed. • Has two options.
• Is zero-indexed. − Stop if True
− Continue if True
Lesson 3, Slide 25
While Loops – Tunnels
• Tunnels transfer data into and out of structures.
• Data pass out of a loop after the loop terminates.
• When a tunnel passes
data into a loop, the loop
executes only after
data arrive at the tunnel.
Lesson 3, Slide 26
While Loops – Error Checking and Error Handling
Use an error cluster in a While Loop to stop the While Loop if
an error occurs.
Lesson 3, Slide 27
Exercise 3-2
Auto Match VI
DISCUSSION
E. For Loops
Conditional Terminal
Comparison with While Loops
Numeric Conversion for Count Terminal
Lesson 3, Slide 30
For Loops
N=100;
i=0;
Until i=N:
Repeat (code;i=i+1);
End;
Lesson 3, Slide 31
For Loops
• Create a For Loop the same way you create a While Loop.
• You can replace a While Loop with a For Loop by right-
clicking the border of the While Loop and selecting
Replace with For Loop from the shortcut menu.
• The value in the count terminal (an input terminal)
indicates how many times to repeat the subdiagram
in the For Loop.
Lesson 3, Slide 32
For Loops – Conditional Terminal
You can add a conditional terminal to configure a For Loop to
stop when a Boolean condition is true or an error occurs.
Lesson 3, Slide 33
For Loops – Conditional Terminal
For Loops configured with a conditional terminal have:
• A red glyph next to the count terminal.
• A conditional terminal in the lower right corner
Lesson 3, Slide 34
For Loop/While Loop Comparison
For Loop While Loop
• Executes a set number of times • Stops executing only if the value
unless a conditional terminal is at the conditional terminal meets
added. the condition.
• Can execute zero times. • Must execute at least once.
• Tunnels automatically output an • Tunnels automatically output the
array of data. last value.
Lesson 3, Slide 35
For Loops – Numeric Conversion
• The number of iterations a For Loop executes must be specified in
non-negative integers.
• If you wire a double-precision, floating-point numeric value to the
count terminal, LabVIEW converts the numeric value to a 32-bit
signed integer.
Lesson 3, Slide 36
Group Exercise 3-3
Concept: While Loops versus For Loops
Lesson 3, Slide 38
Timing a VI
Lesson 3, Slide 39
Wait Functions
A wait function inside a loop:
• Allows the VI to sleep for a set amount of time.
• Allows the processor to address other tasks during the wait
time.
• Uses the operating system millisecond clock.
Lesson 3, Slide 40
Elapsed Time Express VI
• Determines how much time elapses after some point in
your VI.
• Keeps track of time while the VI continues to execute.
• Does not provide the processor with
time to complete other tasks.
Lesson 3, Slide 41
Wait Chart VI
DEMONSTRATION
G. Data Feedback in Loops
Shift Registers
Initializing Shift Registers
Default for Unwired Values
Compound Shift Registers
Lesson 3, Slide 43
Data Feedback in Loops
• When programming with loops, you often need to know the
values of data from previous iterations of the loop.
• Shift registers transfer values from one loop iteration to the
next.
Lesson 3, Slide 44
Shift Registers
• Right-click the border and select Add Shift Register from
the shortcut menu.
• Right shift register stores data on completion of an iteration.
• Left shift register provides stored data at beginning of the
next iteration.
Lesson 3, Slide 45
Initializing Shift Registers
Run once VI finishes Run again
Not
Initialized Output = 4 Output = 8
Shift
Register
Lesson 3, Slide 46
Use Default if Unwired
Numeric 0
Boolean FALSE
String Empty
Lesson 3, Slide 47
Multiple Previous Iterations
• Stacked shift registers remember values from multiple
previous iterations and carry those values to the next
iterations.
• Right-click the left shift register and select Add Element
from the shortcut menu to stack a shift register.
Lesson 3, Slide 48
Exercise 3-4
Average Temperature VI
DISCUSSION
H. Plotting Data – Waveform Chart
Lesson 3, Slide 51
Plotting Data – Waveform Chart
• Waveform chart
is a special type
of numeric
indicator.
• Waveform charts
display single or
multiple plots.
Lesson 3, Slide 52
Waveform Chart Properties
Extensive plot
customization lets you:
• Show or hide legends.
• Change color and line
styles.
• Change interpolation
styles.
Lesson 3, Slide 53
Exercise 3-5
Temperature Monitor VI – Plot Multiple
Temperatures
In what ways do the following tools allow the user to interact with
the plot?
• Plot Legend
• Graph Palette
• Scale Legend
DISCUSSION
I. Case Structures
Parts of a Case Structure
Enum Case Structures
Error Case Structures
Input and Output Tunnels
Lesson 3, Slide 56
Case Structures
• Have two or more subdiagrams or cases.
• Use an input value to determine which case to execute.
• Execute and display only one case at a time.
• Are similar to case statements or if...then...else statements
in text-based programming languages.
Lesson 3, Slide 57
Case Structures
• Case Selector Label
− Contains the name of the current
case.
Case Selector Label
− Has decrement and increment
arrows.
• Selector Terminal
− Lets you wire an input value, or
selector, to determine which
case executes.
Selector Terminal
Lesson 3, Slide 58
Case Structures
Selector terminal data types:
• Boolean
− True case and False Case
• Error Cluster
− Error Case and No Error Case
• Integer, string, or enum
− Structure can have any
number of cases.
− Include a Default diagram to
avoid listing every possible
input value.
Lesson 3, Slide 59
Enum Case Structure
• Gives users a list of items from which to select
• The case selector displays a case for each item in the
enumerated type control
Lesson 3, Slide 60
Shortcut Menu
Use the shortcut menu of a
Case structure to:
− Customize the structure and
diagrams.
− Remove or replace the
structure.
− Add, duplicate, remove, or
rearrange cases.
− Specify the Default case.
− Switch cases.
Lesson 3, Slide 61
Error Case Structure
Use Case structures inside VIs to execute the code if there is
no error and skip the code if there is an error.
Lesson 3, Slide 62
Input and Output Tunnels
You can create multiple input and output tunnels.
• Inputs tunnels are available to all cases if needed.
• You must define each output tunnel for each case.
Lesson 3, Slide 63
Case Structures
DEMONSTRATION
Exercise 3-6
Temperature Warnings VI
• What happens if all the values are 10? How could you fix
this?
• Are all output tunnels defined? What happens if an output
is not defined?
DISCUSSION
Summary—Quiz
1. If an input to a function is marked with a red dot (known
as a coercion dot), what does the dot indicate?
a) Data was transferred into a structure.
b) A For Loop was configured with a conditional terminal.
c) A For Loop iteration terminal is unwired.
d) The value passed into a node was converted to a
different representation.
Lesson 3, Slide 67
Summary—Quiz Answer
1. If an input to a function is marked with a red dot (known
as a coercion dot), what does the dot indicate?
a) Data was transferred into a structure.
b) A For Loop was configured with a conditional terminal.
c) A For Loop iteration terminal is unwired.
d) The value passed into a node was converted to a
different representation.
Lesson 3, Slide 68
Summary—Quiz
Lesson 3, Slide 69
Summary—Quiz Answer
Lesson 3, Slide 70
Summary—Quiz
Lesson 3, Slide 71
Summary—Quiz Answer
Lesson 3, Slide 72
Summary—Quiz
Lesson 3, Slide 73
Summary—Quiz Answer
Lesson 3, Slide 74
Lesson 4
Developing Modular Applications
TOPICS
A. Understanding Modularity
B. Icon
C. Connector Pane
D. Using SubVIs
Lesson 4, Slide 1
A. Understanding Modularity
Lesson 4, Slide 2
Understanding Modularity
Lesson 4, Slide 3
Understanding Modularity – SubVIs
Lesson 4, Slide 4
Understanding Modularity – SubVIs
Lesson 4, Slide 5
Understanding Modularity – SubVIs
Lesson 4, Slide 6
Understanding Modularity – SubVIs
Function Code Calling Program Code
function average (in1, in2, main
out) {
{ average (point1, point2,
out = (in1 + in2)/2.0; pointavg)
} }
Lesson 4, Slide 7
B. Icon
Characteristics of a Good Icon
Using the Icon Editor
Lesson 4, Slide 8
Icon
Lesson 4, Slide 9
Characteristics of a Good Icon
Good icons convey the functionality of the VI using:
− Relevant graphics
− Descriptive text, if necessary
Lesson 4, Slide 10
Creating Icons - Icon Editor
Open the Icon Editor using one of these methods:
− Right-click the icon in the upper-right corner of the front panel
or block diagram and select Edit Icon.
− Double-click the icon.
Lesson 4, Slide 11
Icon Editor
Use the editing tools to modify an icon manually.
Lesson 4, Slide 12
Icon Editor
Use the Glyphs tab to display glyphs you can include in the icon.
Lesson 4, Slide 13
Icon Editor
Use the Icon Text tab to specify the text to display in the icon.
Lesson 4, Slide 14
Icon Editor
Use the Templates tab to display icon templates you can use as a
background for the icon.
Lesson 4, Slide 15
C. Connector Pane
Patterns
Standards
Lesson 4, Slide 16
Connector Pane
Lesson 4, Slide 17
Connector Pane – Standards
Lesson 4, Slide 18
D. Using SubVIs
Using on Block Diagram
Terminal Settings
Handling Errors
Creating from a Section of Block Diagram
Lesson 4, Slide 19
Using SubVIs
Lesson 4, Slide 20
Terminal Settings
• Bold
− Required terminal
• Plain
− Recommended
terminal
• Dimmed
− Optional terminal
Lesson 4, Slide 21
Handling Errors
Use a Case structure to handle errors passed into the subVI.
Lesson 4, Slide 22
Handling Errors
Avoid using LabVIEW error handler VIs inside subVIs.
Lesson 4, Slide 23
Convert a Section of a VI to SubVI
To convert a section of a VI into a subVI:
1. Use the Positioning tool to select the section of the block
diagram you want to reuse.
2. Select Edit»Create SubVI.
Lesson 4, Slide 24
Exercise 4-1
Temperature Warnings VI
Create the icon and connector pane for a VI so you can use
the VI as a subVI. Call the subVI from a test VI.
GOAL
Exercise 4-1
Temperature Warnings VI
DISCUSSION
Summary—Quiz
Lesson 4, Slide 27
Summary—Quiz Answer
Lesson 4, Slide 28
Summary—Quiz
Lesson 4, Slide 29
Summary—Quiz Answer
Lesson 4, Slide 30
Lesson 5
Creating and Leveraging Data Structures
TOPICS
A. Arrays
B. Common Array Functions
C. Polymorphism
D. Auto-Indexing
E. Clusters
F. Type Definitions
Lesson 5, Slide 1
A. Arrays
1D and 2D Arrays
Creating an Array Control and Constant
Initializing Arrays
Lesson 5, Slide 2
Arrays
An array:
• Is a collection of data elements
that are of same type.
• Has one or more dimensions.
• Contains up to (231)–1 elements
per dimension, memory
permitting.
• Accesses elements by its index.
Note: The first element is index 0.
Lesson 5, Slide 3
Arrays – 1D and 2D Examples
ID array
One row of 10-elements
0 1 2 3 4 5 6 7 8 9
1.2 3.2 8.2 8.0 4.8 5.1 6.0 1.0 2.5 1.7
Index
2D array
Five-row by seven-column table of 35 numbers
elements
0 1 2 3 4 5 6
0
1
2
3
4
Lesson 5, Slide 4
Why Use Arrays?
Use arrays when you work with a collection of similar data and
when you perform repetitive computations.
Lesson 5, Slide 5
Viewing Arrays on the Front Panel
The elements at First element
Second
index 0 are not at index 1 element at
shown because index 2
element 1 is selected
in the index display.
Lesson 5, Slide 6
Creating an Array Control
For a new array:
1. Select an Array control from the
Controls palette on the front panel.
2. Place a data object, such as a
numeric control, into the array
shell.
3. Add a second dimension, if necessary, by
resizing the index.
From a block diagram terminal or wire:
1. Right-click the object and select Create»Control
or Create»Indicator.
Lesson 5, Slide 7
Creating an Array Constant
For a new array:
1. Select Array Constant from the Functions
palette on the block diagram.
2. Place a constant, such as a numeric,
into the array shell.
3. Add a second dimension, if necessary, by
resizing the index.
From a block diagram terminal or wire:
1. Right-click and select Create»Constant.
Lesson 5, Slide 8
Initializing Arrays
• You can initialize an array or leave it uninitialized.
• For initialized arrays, you define the number of elements in
each dimension and the contents of each element.
• Uninitialized arrays have dimension but no elements.
Lesson 5, Slide 9
2D Arrays
• 2D arrays:
− Store elements in a grid.
− Require a column index and a row index to locate an element,
both of which are zero-based.
• Create a multidimensional array on the front panel by right-
clicking the index display and selecting Add Dimension
from the shortcut menu.
• Resize the index display until you have as many dimensions
as you want.
Lesson 5, Slide 10
B. Common Array Functions
Array Size
Initialize Array
Array Subset
Build Array
Index Array
Lesson 5, Slide 11
Common Array Functions
• Array Size
• Initialize Array
• Array Subset
• Build Array
• Index Array
Lesson 5, Slide 12
Array Size
Lesson 5, Slide 13
Initialize Array
Lesson 5, Slide 14
Array Subset
Lesson 5, Slide 15
Build Array
Lesson 5, Slide 16
Index Array
Lesson 5, Slide 17
C. Polymorphism
Lesson 5, Slide 18
Polymorphism
Polymorphism - The ability of VIs and functions to
automatically adapt to accept input data of different
data types
Lesson 5, Slide 19
Arithmetic Functions Are Polymorphic
Combination Result
Lesson 5, Slide 20
D. Auto-Indexing
Use in For Loops and While Loops
Waveform Graphs
Auto-Indexing with a Conditional Terminal
Creating 2D Arrays
Auto-Indexing Input to a Loop
Lesson 5, Slide 21
Auto-Indexing Auto-Indexing Enabled
Lesson 5, Slide 22
Waveform Graph
• Is a graphical display of data.
• Displays one or more plots of
evenly sampled measurements.
• Is used to plot pre-generated
arrays of data.
• Can display plots with any
number of data points.
Lesson 5, Slide 23
Charts vs. Graphs – Single-Plot
Lesson 5, Slide 24
Auto-Indexing with a Conditional Tunnel
Lesson 5, Slide 25
Creating 2D Arrays
1D Array 2D Array
0 1 2 3 4 5
Lesson 5, Slide 26
Auto-Indexing Input
If the iteration count terminal is wired and arrays of different
sizes are wired to auto-indexed tunnels, the actual number of
iterations becomes the smallest of the choices.
Lesson 5, Slide 27
Auto-Indexing Input
Use an auto-indexing input array to perform calculations
on each element in an array.
• Wire an array to an auto-indexing tunnel on a For Loop.
• You do not need to wire the count (N) terminal.
− The For Loop executes
the number of times
equal to the
number of
elements in the array.
− The Run button is not broken.
Lesson 5, Slide 28
Exercise 5-1
Concept: Manipulating Arrays
• In the All Data Channel case, how can you verify that the
two approaches yield the same results?
– Polymorphic Add of array + scalar
– Auto-indexed array elements added to scalar
DISCUSSION
E. Clusters
Reasons To Use Clusters
Cluster vs. Arrays
Creating a Cluster Control and Constant
Ordering Items and Resizing Clusters
Disassembling and Modifying Clusters
Plotting Data
Lesson 5, Slide 31
Clusters
• Clusters group data elements of mixed types.
• Clusters are similar to a record or a struct in text-based
programming languages.
Lesson 5, Slide 32
Why Use Clusters?
• Keep data organized.
− Logically group related data values together.
− Improve diagram readability by eliminating wire clutter.
• Reduce the number of connector pane terminals.
Lesson 5, Slide 33
Clusters vs. Arrays
• Clusters are a fixed size. • Arrays vary in size.
• Clusters can contain mixed • Arrays contain only one data
data types. type.
• Clusters can be a control, an • Arrays can be a control, an
indicator, or a constant. indicator, or a constant.
− All elements have to be controls,
indicators, or constants.
Lesson 5, Slide 34
Create a Cluster Control
For a new cluster:
1. On the front panel, select Cluster
from the Controls palette.
2. Place a data object into the
cluster shell.
3. Place additional data objects,
if necessary, into the shell.
From block diagram terminal or wire:
1. Right-click and select Create»Control or Create»Indicator.
Lesson 5, Slide 35
Create a Cluster Constant
For a new cluster:
1. On the block diagram, select Cluster
Constant from the Functions palette.
2. Place a constant into the cluster shell.
3. Place additional data objects, if
necessary, into the cluster shell.
From block diagram terminal or wire:
1. Right-click and select Create»Constant.
Lesson 5, Slide 36
Cluster Order
• Cluster elements have a logical
order unrelated to their position
in the shell.
• You can view and modify the
cluster order by right-clicking
the cluster border and
selecting Reorder Controls
In Cluster.
Lesson 5, Slide 37
Autosizing Clusters
• Autosizing helps you
arrange elements in
clusters.
• NI recommends the
following:
− Arrange cluster elements
vertically.
− Arrange elements compactly.
− Arranges elements in their
preferred order.
Lesson 5, Slide 38
Disassembling a Cluster
• Use the Unbundle By Name function whenever possible.
• Use Unbundle function when some or all cluster elements
are unnamed.
Lesson 5, Slide 39
Modifying a Cluster
• Use Bundle By Name whenever possible to access
elements in a cluster.
• Use Bundle when some or all cluster elements are
unnamed.
You must
wire the
input
cluster
terminal.
Lesson 5, Slide 40
Creating a Cluster on the Diagram
• Use the Bundle function to programmatically create a
cluster on a block diagram.
• If the elements that are bundled have labels, you can
access them using the Unbundle By Name function.
Otherwise use the Unbundle function.
Lesson 5, Slide 41
Charts vs. Graphs – Multi-plot and XY Graph
Lesson 5, Slide 42
Plotting Data
Use the Context Help window to determine how to wire
multi-plot data to Waveform Graphs, Charts and XY Graphs.
Lesson 5, Slide 43
Error Clusters
• LabVIEW uses error clusters to pass error information.
• An error cluster contains the following elements:
− status—Boolean value that reports True if an error occurs.
− code—32-bit signed integer that identifies the error.
− source—String that identifies where the error occurred.
Lesson 5, Slide 44
Exercise 5-2
Temperature Warnings – Clusters
DISCUSSION
F. Type Definitions
Type Definitions and Custom Data Types
Creating and Identifying Type Definitions
Controls
Strict Type Definitions
Lesson 5, Slide 47
Type Definitions (Type Def)
• A type definition is a master copy of a custom data type
(control, indicator, or constant).
− A custom data type is saved in a .ctl file.
− Instances of a type def are linked to the .ctl file.
• Instances can be controls, indicators, or constants.
• When the type def changes, instances automatically update.
− Changes include data type changes, elements added,
elements removed, and adding items to an enum.
Lesson 5, Slide 48
Creating Type Definitions (Type Def)
1. Right-click a control, indicator or constant and select
Make Typedef.
2. Right-click the object again and select Open Type Def.
3. Edit control, if needed.
4. Save control as a .ctl file.
Lesson 5, Slide
Identifying Type Definitions (Type Def)
• Look for a glyph marking the upper left corner of terminals
and constants.
• Hover cursor over glyph to view tip strip.
• View Context Help while hovering cursor over terminal or
constant.
Lesson 5, Slide
Other Control Options
You can save a custom control as:
• Control
• Type Definition
• Strict Type Definition
Lesson 5, Slide 51
Control
• Instances are not linked to a.ctl file.
• Each instance is an independent copy of the control.
• Used to create controls that behave like existing controls but
look different.
Lesson 5, Slide 52
Strict Type Definition
• Strict type definitions are similar to a type definition in that:
− All instances link to .ctl file.
− When attributes or data types change, all instances update.
• Examples: Changing a knob to a dial, a round LED to a square
LED, or a double to an integer.
• Strict type definitions enforce every aspect of a instance
except label, description, and default value.
• Use strict type definitions to ensure all front panel instances
have the same appearance.
Lesson 5, Slide 53
Exercise 5-3
Weather Warnings – Type Definition
DISCUSSION
Summary—Quiz
1. You can create an array of arrays.
a) True
b) False
Lesson 5, Slide 56
Summary—Quiz Answer
1. You can create an array of arrays.
a) True
b) False
Lesson 5, Slide 57
Summary—Quiz
2. What is the value of the Iterations indicator
after running this VI?
Lesson 5, Slide 58
Summary—Quiz Answer
2. What is the value of the Iterations indicator
after running this VI?
4
Lesson 5, Slide 59
Summary—Quiz
3. Which of the following custom control settings defines the
data type of all instances of a control but allows for
different colors and font styles?
a) Control
b) Type definition
c) Strict type definition
d) Cluster control
Lesson 5, Slide 60
Summary—Quiz Answer
3. Which of the following custom control settings defines the
data type of all instances of a control but allows for
different colors and font styles?
a) Control
b) Type definition
c) Strict type definition
d) Cluster control
Lesson 5, Slide 61
Summary—Quiz
4. You have input data representing a circle: X Position, Y Position,
and Radius. In the future, you might need to modify your data to
include the color of the circle.
What data structure should you use to represent the circle in your
application?
a) Three separate controls for the two positions and the radius
b) A cluster containing all of the data (X,Y)
c) A custom control containing a cluster
d) A type definition containing a cluster
e) An array with three elements R
Lesson 5, Slide
Summary—Quiz Answer
4. You have input data representing a circle: X Position, Y Position,
and Radius. In the future, you might need to modify your data to
include the color of the circle.
What data structure should you use to represent the circle in your
application?
a) Three separate controls for the two positions and the radius
b) A cluster containing all of the data (X,Y)
c) A custom control containing a cluster
d) A type definition containing a cluster
e) An array with three elements R
Lesson 5, Slide
Lesson 6
Managing File and Hardware Resources
TOPICS
A. Understanding File and Hardware Resources
B. File I/O
C. Acquiring Measurements with a DAQ System
D. Controlling Instruments
Lesson 6, Slide 1
A. Understanding File and Hardware
Resources
Definition of Resources
Accessing Resources in LabVIEW
Lesson 6, Slide 2
What are Resources?
Lesson 6, Slide 3
Accessing Resources in LabVIEW
A typical resource operation involves the following process:
Open, Read
Check for
Initialize or and/or Close
Errors
Create Write
Lesson 6, Slide 4
Accessing Resources in LabVIEW
Sample refnum wires:
Lesson 6, Slide 5
B. File I/O
Understanding File I/O
File Formats
High-Level and Low-Level I/O
Lesson 6, Slide 6
File I/O
Lesson 6, Slide 7
Understanding File I/O
Open/ Read
Close Check for
Create/ and/or
File Errors
Replace File Write to File
Lesson 6, Slide 8
File Formats
LabVIEW can use or create the following file formats:
• Binary—Efficient, compact, and allows random access
reading but not a human-readable file. Commonly used for
high-speed and multi-channel DAQ.
• ASCII—Human-readable text file where data is represented
as strings. Commonly used for low-speed DAQ.
• LVM—Format built on ASCII, the LabVIEW measurement
data file (.lvm) is a tab-delimited text file you can open with a
spreadsheet application or a text-editing application.
• TDMS—An NI-specific binary file format that contains data
and stores properties about the data.
Lesson 6, Slide 9
ASCII File Format
• In this course, you learn about creating text (ASCII) files.
• Use ASCII files in the following situations:
− You want to access the file from another application.
− Disk space and file I/O speed are not crucial.
− You do not need to perform random access reads or writes.
− Numeric precision is not important.
Lesson 6, Slide 10
High-Level File I/O
• High-level File I/O functions:
− Perform all three steps (open,
read/write, close) for common file I/O
operations.
− Might not be as efficient as the
functions configured or designed for
individual operations.
• Low-level File I/O functions:
− Provide individual functions for each
step.
− Are efficient for writing to a file in a
loop.
Lesson 6, Slide 11
High-Level File I/O
Write to Spreadsheet File
• Converts an array of double-precision numbers to a text string and
writes the string to an ASCII file.
Read From Spreadsheet File
• Reads a specified number of lines or rows
from a numeric text file and outputs a
2D array of double-precision numbers.
Write To/Read From Measurement File
• Express VIs that write data to or read data
from an LVM or TDMS file format.
Lesson 6, Slide 12
Understanding Low-Level File I/O VIs
Lesson 6, Slide 13
Exercise 6-1
Concept: Spreadsheet Example VI
DISCUSSION
C. Acquiring Measurements with a
DAQ System
DAQ Hardware
Analog I/O, Digital I/O, and Counters
Configuring and Simulating DAQ Hardware
Programming DAQ
Lesson 6, Slide 17
DAQ Hardware
1. Signal
2. Terminal Block
3. Cable
4. DAQ Device
5. Computer
Lesson 6, Slide 18
DAQ Terminal Block
BNC-2120 features:
• Quadrature encoder
• 8 LEDs for digital I/O
• Counter I/O
• Function generator
• Function generator frequency
and amplitude control
• Temperature sensor
• Analog input
• Analog output
Lesson 6, Slide 19
DAQ Hardware – DAQ Device
Lesson 6, Slide 20
Analog Input
The process of measuring an analog signal and transferring
the measurement to a computer for analysis, display, or
storage.
• An analog signal is a signal that varies continuously.
• Analog input most commonly measures voltage or current.
Lesson 6, Slide
Analog Output
Analog output is the process of generating analog signals
from your computer.
• Performing digital-to-analog (D/A)
conversions generates analog output.
• The available analog output types
are voltage and current.
• To perform a voltage or current
output, a compatible device must be
installed that can generate that
type of signal.
Lesson 6, Slide 22
Digital I/O
Digital signals are:
− Electrical signals that transfer digital data (on/off, high/low, 1/0)
using a wire.
− Used to control or measure digital or finite state devices, such
as switches and LEDs.
− Used to transfer data:
• To program devices.
• To communicate between devices.
− Used as clocks or triggers to control or
synchronize other measurements.
Lesson 6, Slide 23
Counters
• A counter is a digital timing device typically used for event
counting, frequency measurement, period measurement,
position measurement, and pulse generation.
• A counter can count to a fixed limit as determined by the
resolution of the counter.
For example, a 24-bit counter
can count to:
2(Counter Resolution) – 1 = 224 – 1 = 16,777,215
Lesson 6, Slide 24
Configuring DAQ Hardware
Configure and test hardware using the NI Measurement &
Automation Explorer (MAX).
Lesson 6, Slide 25
Simulating a DAQ Device
• Using NI-DAQmx simulated devices, you can try different NI
products in your application without the hardware.
• With NI-DAQmx simulated devices, you can export a
physical device configuration onto a system that does not
have the physical device installed.
Lesson 6, Slide 26
Exercise 6-3
Concept: Measurement & Automation Explorer
DISCUSSION
DAQ Programming – Software Overview
• NI-DAQmx
− Driver level software
− Detects DAQ devices
− Installs NI-DAQmx functions in LabVIEW
• DAQ Assistant
− Configurable Express VI used to create a DAQ
application.
• DAQmx API
− Provides a set of VIs to program DAQ applications.
Lesson 6, Slide 29
DAQ Programming – Basic Flow
A basic DAQmx application involves the following process:
Acquire or
Create Configure Start Clear Check for
Generate
Task Task Task Task Errors
Data
Lesson 6, Slide 30
Step 1 - Create Task
The Create Virtual Channel VI:
• Creates a virtual channel and adds it to a task.
• Uses a pull-down menu to select the appropriate instance of
this VI.
Lesson 6, Slide 31
Step 2 - Configure Task
• Configure the timing of a task if reading multiple samples.
− Sample rate, timing source, etc.
• Configure the triggering if necessary for application.
− Configures the task to start or stop on a rising or falling digital
edge, analog edge, or during analog windows.
Lesson 6, Slide 32
Step 3 - Start Task
The Start Task VI starts the task after the task has been
configured.
Lesson 6, Slide 33
Step 4 - Acquire or Generate Data
• The DAQmx Read or DAQmx Write VIs acquire or generate
data from the DAQ device.
• Make sure the pull-down menu selection is compatible with
the task configuration.
Lesson 6, Slide 34
Step 5 - Clear Task
The DAQmx Clear Task VI:
• Stops the task.
• Releases any resources the task reserved.
• Clears the task.
Lesson 6, Slide 35
DAQ Programming – Example
This is an example program of an acquisition with triggering.
Lesson 6, Slide 36
Exercise 6-4 Using DAQmx (DAQ)
What types of VIs did you use outside of the While Loop?
DISCUSSION
D. Controlling Instruments
Benefits
GPIB
Instrument Control Software
VISA
Instrument Drivers
Lesson 6, Slide 39
Instrument Control
• Use software on a PC to control an instrument over an
instrument control bus.
• Mix and match instruments from various categories.
• Understand the properties of the instrument, such as the
communication protocols to use.
Lesson 6, Slide 40
Benefits of Instrument Control
• Automates processes.
• Saves time.
• Uses one platform for multiple tasks.
• Is easy to use.
• Is compatible with many types of instruments.
Lesson 6, Slide 41
GPIB – General Purpose Interface Bus
GPIB is a standard
interface for
communication between a
controller and instruments
from various vendors.
Lesson 6, Slide 42
GPIB
• The bus supports one system controller, usually a computer,
and up to 14 additional instruments.
• The controller:
− Defines the communication links.
− Sends GPIB commands.
− Responds to devices that request service.
− Passes/receives control of the bus.
Lesson 6, Slide 43
Using Instrument Control Software
• Interface Drivers: Instrument interfaces such as GPIB
include a set of drivers for the interface.
• Configuration: Use MAX to configure the interface.
Lesson 6, Slide 44
Exercise 6-5
Concept: GPIB Configuration with MAX
DISCUSSION
Instrument Control Programming
Virtual Instrument Software Architecture (VISA):
− Is a high-level API that calls low-level drivers.
− Can control instruments over GPIB, USB, Ethernet, serial, and
other interfaces as it makes the appropriate driver calls
depending on the type of instrument used.
Lesson 6, Slide 47
VISA
VISA
Virtual Instrument System Architecture
Lesson 6, Slide 48
VISA – Programming Terminology
• Resource
Any instrument in the system, including serial and parallel ports.
• Session
You must open a VISA session to a resource to communicate
with it, similar to a communication channel. When you open a session
to a resource, LabVIEW returns a VISA session number, which is a
unique refnum to that instrument. You must use the session number in
all subsequent VISA functions.
• Instrument Descriptor
Specifies the interface type (GPIB, USB, TCP/IP, ASRL), the address of the
device, and the VISA session type (INSTR or Event).
Lesson 6, Slide 49
VISA Alias
Assign a user-defined name to a device or resource in place
of the instrument descriptor.
Lesson 6, Slide 50
VISA Programming
VISA functions operate similar to File I/O functions.
Lesson 6, Slide 51
VISA Open and Close Functions
• VISA Open Function
− Establishes a communication line to the resource.
− Is generally used once per resource.
− Returns a VISA Resource Name.
Lesson 6, Slide 52
VISA I/O Functions
VISA Write and VISA Read Functions
Lesson 6, Slide 53
VISA Write and Read Example
Lesson 6, Slide 54
Application Development
Instrument Drivers Environment (ADE)
Lesson 6, Slide 55
Using Instrument Drivers
• When you use an instrument driver, the driver contains the
code specific to the instrument.
• If you change instruments, replace the instrument driver VIs
with the instrument driver VIs for the new instrument, which
greatly reduces your redevelopment time.
Lesson 6, Slide 56
Using Instrument Drivers – Where are they?
• You can locate most LabVIEW Plug and Play instrument drivers in the
Instrument Driver Finder.
− Access within LabVIEW by selecting Tools» Instrumentation»Find
Instrument Drivers or Help»Find Instrument Drivers.
− Use it to connect with ni.com to find instrument drivers.
− You can also find instrument drivers at ni.com/idnet
• When you install an instrument driver, the installer:
− Adds an example program using the driver to the NI Example Finder.
− Adds instrument driver VIs to the Instrument I/O»Instrument Drivers
palette in the Functions palette.
− Extracts instrument driver VIs and supporting files to the
<LabVIEW>\instr.lib directory.
Lesson 6, Slide 57
Instrument Driver Example
Lesson 6, Slide 58
Exercise 6-6 NI Devsim VI (GPIB)
DISCUSSION
Summary—Quiz
1. After opening a file, which output does the Open/Create/Replace
File function return?
a) File path
b) File name
c) Refnum out
d) Task out
Lesson 6, Slide 61
Summary—Quiz Answer
1. After opening a file, which output does the Open/Create/Replace
File function return?
a) File path
b) File name
c) Refnum out
d) Task out
Lesson 6, Slide 62
Summary—Quiz
2. What is Measurement & Automation Explorer (MAX)?
a) A tool to configure and test DAQ devices
b) A tool to test instrument communication
c) A configurable Express VI
d) A window to view LabVIEW project files
Lesson 6, Slide 63
Summary—Quiz Answer
2. What is Measurement & Automation Explorer (MAX)?
a) A tool to configure and test DAQ devices
b) A tool to test instrument communication
c) A configurable Express VI
d) A window to view LabVIEW project files
Lesson 6, Slide 64
Summary—Quiz
3. Which of the following are benefits of instrument control?
a) Automate processes
b) Save time
c) One platform for multiple tasks
d) Limited to only one type of instrument
Lesson 6, Slide 65
Summary—Quiz Answers
3. Which of the following are benefits of instrument control?
a) Automate processes
b) Save time
c) One platform for multiple tasks
d) Limited to only one type of instrument
Lesson 6, Slide 66
Summary—Quiz
4. VISA is a high-level API that calls low-level drivers.
a) True
b) False
Lesson 6, Slide 67
Summary—Quiz Answer
4. VISA is a high-level API that calls low-level drivers.
a) True
b) False
Lesson 6, Slide 68
Lesson 7
Using Sequential and
State Machine Algorithms
TOPICS
A. Using Sequential Programming
B. Using State Programming
C. State Machines
Lesson 7, Slide 1
A. Using Sequential Programming
Flow-Through Parameters
Sequence Structures
Error Case Structures
Lesson 7, Slide 2
Using Sequential Programming
• Many of the VIs you write accomplish sequential tasks.
• By default, LabVIEW does not force sequential programming.
Lesson 7, Slide 4
Sequence Structures Force Execution Order
• Sequence structures are a structure with frames, where each frame
executes in order.
• The second frame cannot begin execution until everything in the first
frame completes execution.
Lesson 7, Slide 5
Avoid Overuse of Sequence Structures
You cannot stop the execution in the middle of a sequence.
Lesson 7, Slide 6
Better to Use Error Case Structures
The best way to write this VI is to enclose the dialog boxes in
Case structures, wiring the error cluster to the case selectors.
Lesson 7, Slide 7
B. Using State Programming
State Programming
State Transition Diagrams
Lesson 7, Slide 8
State Programming
State programming helps you solve the following issues that
sequential programming or flow-through parameters do not:
• What if you need to change the order of the sequence?
• What if you need to repeat one item in the sequence more
often than other items?
• What if some items in the sequence execute only when
certain conditions are met?
• What if you need to stop the program immediately, rather
than waiting until the end of the sequence?
Lesson 7, Slide 9
State Transition Diagram
A state transition diagram is a type of flowchart that indicates
the states of a program and transitions between states.
Lesson 7, Slide 10
State Transition Diagram
Furnace
Example:
Lesson 7, Slide 11
C. State Machines
Common Uses
Infrastructure
Transitions
Lesson 7, Slide 12
State Machines
• The state machine design pattern implements a state
diagram or flow chart.
• Common uses of state machines:
− To create user interfaces, where different user actions send the
user interface into different states.
− For process tests, where a state represents each segment of
the process.
Lesson 7, Slide 13
State Machines – Infrastructure
• A state machine consists of a set of states and a transition
function that maps to the next state.
• Each state can lead to one or multiple states or end the
process flow.
While Loop
Type-Defined
Enum
Case Structure
Shift Register
Lesson 7, Slide 14
State Machines – Default Transition
Lesson 7, Slide 15
State Machines – Transition Between Two
States
Lesson 7, Slide 16
State Machines – Case Structure Transition
Lesson 7, Slide 17
State Machines – Transition Array Transition
Lesson 7, Slide 18
Course Project Transition Diagram
Lesson 7, Slide 19
Course Project
DEMONSTRATION
Exercise 7-1
Weather Station Project
DISCUSSION
Summary—Quiz
1. When using a Sequence structure, you can stop the execution in
the middle of a sequence.
a) True
b) False
Lesson 7, Slide 23
Summary—Quiz Answer
1. When using a Sequence structure, you can stop the execution in
the middle of a sequence.
a) True
b) False
Lesson 7, Slide 24
Summary—Quiz
2. Which of the following are benefits of using a state machine
instead of a sequential structure?
a) You can change the order of the sequence.
b) You can repeat individual items in the sequence.
c) You can set conditions to determine when an item in the
sequence should execute.
d) You can stop the program at any point in the sequence.
Lesson 7, Slide 25
Summary—Quiz Answers
2. Which of the following are benefits of using a state machine
instead of a sequential structure?
a) You can change the order of the sequence.
b) You can repeat individual items in the sequence.
c) You can set conditions to determine when an item in the
sequence should execute.
d) You can stop the program at any point in the sequence.
Lesson 7, Slide 26
Lesson 8
Solving Dataflow Challenges with Variables
TOPICS
A. Communicating Between Parallel Loops
B. Writing to Controls & Reading from Indicators
C. Variables
D. Local Variables
E. Race Conditions
Lesson 8, Slide 1
A. Communicating Between Parallel
Loops
Lesson 8, Slide 2
Communicating Between Parallel Loops
Lesson 8, Slide 3
How do the loops stop in this example?
Lesson 8, Slide 4
How do the loops stop in this example?
Lesson 8, Slide 5
B. Writing to Controls & Reading from
Indicators
Lesson 8, Slide 6
Writing to Controls & Reading from Indicators
How would you handle the following dataflow challenges?
− Initialize front panel controls with values from a configuration file?
− Copy a “Ship To” address to a “Bill To” address?
− Initialize indicators that will be written to later in your code?
− Write to an indicator in two cases of a Case structure without
writing to it in all cases?
Lesson 8, Slide 7
C. Variables
Lesson 8, Slide 8
Variables
Lesson 8, Slide 9
D. Local Variables
When To Use Local Variables
Local Variables and Boolean Mechanical Actions
How To Create Local Variables
Lesson 8, Slide 10
Local Variables
Lesson 8, Slide 11
Local Variables
Lesson 8, Slide 12
Use Switch Mechanical Action
• Boolean controls with
associated local
variables must use
switch mechanical
action.
• Boolean latch action
is incompatible with
local variables.
Lesson 8, Slide 13
Creating Local Variables
DEMONSTRATION
Exercise 8-1
Weather Station UI with Local Variable VI
DISCUSSION
E. Race Conditions
Definition
How To Avoid Race Conditions
Controlling Shared Resources
Lesson 8, Slide 17
Race Conditions
Race Condition – A situation where the timing of
events or the scheduling of tasks may unintentionally
affect an output or data value
Lesson 8, Slide 18
What is the final value of the Value variable?
• Value = (Value * 5) +2
• Value = (Value + 2) * 5
• Value = Value * 5
• Value = Value +2
Lesson 8, Slide 19
Race Conditions
• Race conditions are very difficult to identify and debug.
• Often, code with a race condition can return the same result
thousands of times in testing, but still be capable of
returning a different result.
• Avoid race conditions by:
− Controlling shared resources.
• Use one writer, multiple readers.
− Properly sequencing instructions.
− Reducing use of variables.
Lesson 8, Slide 20
Controlling Shared Resources
Lesson 8, Slide 21
Summary—Quiz
1. You should use variables in your VI whenever possible.
a) True
b) False
Lesson 8, Slide 22
Summary—Quiz Answer
1. You should use variables in your VI whenever possible.
a) True
b) False
Lesson 8, Slide 23
Summary—Quiz
2. When controlling resources, which combination of writers and
readers reduces chance of race conditions?
a) One writer, one reader
b) One writer, multiple readers
c) Multiple writers, one reader
d) Multiple writers, multiple readers
Lesson 8, Slide 24
Summary—Quiz Answer
2. When controlling resources, which combination of writers and
readers reduces chance of race conditions?
a) One writer, one reader
b) One writer, multiple readers
c) Multiple writers, one reader
d) Multiple writers, multiple readers
Lesson 8, Slide 25
Continuing Your LabVIEW Education
• Instructor Led Training:
− LabVIEW Core 2: Learn about multiple loop design patterns, property
nodes and building an executable.
− LabVIEW Real-Time 1
− LabVIEW FPGA
− LabVIEW Instrument Control
− Data Acquisition and Signal Conditioning
• Self-Paced Online: Accessible 24 hours a day, prerecorded video
training modules, interactive quizzes, and challenging exercises with
solutions.
• Printed Course Materials: a variety of instructional packages and tools
designed to educate you at your own pace
Lesson 8, Slide 26
NI LabVIEW Skills Guide
ni.com/skills-guide
• Identify skills you need
• Find courses and learning resources to develop those skills
Lesson 8, Slide
Continue Your Learning
• ni.com/support
− Access product manuals, KnowledgeBase, example code, tutorials,
application notes, and discussion forums.
− Request technical support.
• NI Community: ni.com/community/
− Ask and answer questions in discussion forums.
− Exchange code and ideas.
• User Groups: ni.com/usergroups
• Alliance Program: ni.com/alliance
• Publications: ni.com/reference/books/
• Practice!
Lesson 8, Slide 28
New Users Experienced Users Advanced Users
Certifications
Certified LV Associate Certified LabVIEW Certified LabVIEW
Developer Exam Developer Exam Architect Exam
Lesson 8, Slide 29
Thank you!
Please complete the course survey
and retrieve your course CD.
Lesson 8, Slide 30