LabView Exems Answers PDF
LabView Exems Answers PDF
TOPICS
ni.com/training
Lesson 1
Navigating LabVIEW
TOPICS
A.
B.
C.
D.
E.
What Is LabVIEW?
Project Explorer
Parts of a VI
Front Panel
Block Diagram
ni.com/training
Graphical
Dataflow-oriented
Compiled
Multi-platform
Synchronous
LabVIEW Core 2
and Later Topics
Event-driven
Multi-threaded
Object-oriented
Multi-target
MemoryManaged
ni.com/training
Project Explorer
Find, access, and organize
project files
Prevent, detect, and resolve
incorrect links
Deploy or download files to
targets
Manage code for build options
Executables, installers, and zip files
ni.com/training
LabVIEW Files
Common LabVIEW file
extensions:
LabVIEW project .lvproj
Virtual instrument (VI) .vi
Custom control .ctl
ni.com/training
C. Parts of a VI
Front Panel
Block Diagram
Icon
Connector Pane
ni.com/training
Parts of a VI
VIs have 3 main components:
Icon/Connector pane
Block diagram
Front panel
ni.com/training
ni.com/training
ni.com/training
Front Panel
ni.com/training
Indicators
Output devices
Graphs, LEDs
Display data the block diagram
acquires or generates
ni.com/training
Numeric control
Increment/Decrement buttons
Numeric indicator
ni.com/training
Boolean
control
Boolean
indicator
ni.com/training
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.
ni.com/training
E. Block Diagram
Terminals
Nodes
Wires
Context Help
ni.com/training
Block Diagram
ni.com/training
Block Diagram
Block diagram items:
Terminals
Constants
Nodes
Functions
SubVIs
Structures
Wires
Free labels
ni.com/training
Terminals
ni.com/training
ni.com/training
ni.com/training
Nodes
Nodes are objects on the block diagram that have inputs
and/or outputs and perform operations when a VI runs.
Nodes
ni.com/training
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.
ni.com/training
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.
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.
ni.com/training
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.
Floating-point
Integer
String
Boolean
Scalar
1-D Array
2-D Array
ni.com/training
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 HelpShow Context
Help from the LabVIEW menu.
Press <Ctrl-H>.
Click the following button on the
toolbar:
ni.com/training
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.
ni.com/training
Examples
LabVIEW includes
hundreds of example
VIs.
Use NI Example Finder
to browse and search
installed examples.
Select HelpFind
Examples in the menu.
ni.com/training
ni.com/training
Controls Palette
Contains the controls and
indicators you use to create
the front panel.
Navigate the subpalettes or
use the Search button to
search the Controls palette.
ni.com/training
Functions Palette
Contains the VIs, functions,
and constants you use to
create the block diagram.
Navigate the subpalettes or
use the Search button to
search the Functions palette.
ni.com/training
ni.com/training
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.
ni.com/training
Selecting a Tool
A tool is a special operating mode of the
mouse cursor.
Create, modify, and debug VIs using the
tools provided by LabVIEW.
By default, LabVIEW automatically selects
tools based on the context of the cursor.
If you need more control, use the Tools
palette to select a specific tool.
Select ViewTools Palette to open the
Tools palette.
ni.com/training
Wiring Tips
Press <Ctrl-B> to delete all broken wires.
Right-click and select Clean Up Wire to reroute the wire.
ni.com/training
ni.com/training
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.
ni.com/training
ni.com/training
ni.com/training
Filter Express VI
ni.com/training
ni.com/training
ni.com/training
SummaryQuiz Answer
1. Which function executes first:
Add or Subtract?
a) Add
b) Subtract
c) Unknown
ni.com/training
SummaryQuiz Answer
2. Which function executes first:
Sine or Divide?
a) Sine
b) Divide
c) Unknown
ni.com/training
SummaryQuiz Answer
3. Which of the following
functions executes first:
Random Number, Add or
Divide?
a)
b)
c)
d)
Random Number
Divide
Add
Unknown
ni.com/training
SummaryQuiz Answer
4. Which of the following
functions executes last:
Random Number, Subtract or
Add?
a)
b)
c)
d)
Random Number
Subtract
Add
Unknown
ni.com/training
SummaryQuiz Answer
5. What are the three parts of a VI?
a) Front panel
b) Block diagram
c) Project
d) Icon/Connector pane
ni.com/training
Lesson 1
Setting Up Hardware
TOPICS
A.
B.
C.
D.
DAQ Hardware
Using DAQ Software
Instrument Control
GPIB
E. Serial Port
Communication
F. Using Instrument Control
Software
ni.com/training
Setting Up Hardware
LabVIEW is a graphical programming environment used by
millions of engineers and scientists to develop sophisticated
measurement, test, and control systems
LabVIEW can integrate with wide variety of hardware
devices
In this course, you will interact with DAQ, GPIB, and serial
hardware
ni.com/training
A. DAQ Hardware
1.
2.
3.
4.
5.
Signal
Terminal Block
Cable
DAQ Device
Computer
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
C. 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
ni.com/training
C. Instrument Control
Benefits of Instrument Control
Automate processes
Save time
One platform for multiple tasks
Ease of use
Many types of instruments available
ni.com/training
D. GPIB
GPIB (general purpose
interface bus) is a
standard interface for
communication between
instruments and controllers
from various vendors
ni.com/training
GPIB
The bus supports one system controller, usually a computer,
and up to 14 additional instruments
Controller:
Defines the communication links
Responds to devices that request service
Sends GPIB commands
Passes/receives control of the bus
ni.com/training
ni.com/training
ni.com/training
SummaryQuiz Answer
1. You can use the Measurement & Automation Explorer
(MAX) to examine, configure, and test your DAQ device
and GPIB instruments.
a) True
b) False
ni.com/training
SummaryQuiz Answers
2. Which of the following are benefits of instrument control?
a)
b)
c)
d)
Automate processes
Save time
One platform for multiple tasks
Limited to only one type of instrument
ni.com/training
Lesson 2
Troubleshooting and Debugging VIs
TOPICS
A.
B.
C.
D.
ni.com/training
ni.com/training
Debugging Techniques
What to look for if a VI produces unexpected data or behavior:
Are there any unwired or hidden subVIs?
Is the default data correct?
Does the VI pass undefined data?
Are numeric representations correct?
Are node executed in the correct order?
ni.com/training
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.
ni.com/training
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 OperateSuspend When Called from
the shortcut menu.
ni.com/training
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.
ni.com/training
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.
ni.com/training
NaN
Not a number
Produced by invalid operations, such as taking the square root
of a negative number.
ni.com/training
D. Error Handling
Automatic and Manual Error Handling
Merge Errors Function
Error Clusters
Warnings
ni.com/training
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
ni.com/training
ni.com/training
Uncheck
Enable automatic error handling in new VIs
Enable automatic error handling dialogs
Uncheck
Place front panel terminals as icons
Configure Block Diagram Cleanup to customize your block diagram
ni.com/training
Merge Errors
Propagate errors along wires.
Merge errors from different wire paths.
ni.com/training
ni.com/training
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
ni.com/training
Status = FALSE
Code = Non-zero
Error
Warning
ni.com/training
ni.com/training
SummaryQuiz Answer
1. Which of the following will result in a broken run arrow?
a) A subVI is broken.
b) The diagram includes a divide by zero.
c) A required subVI input is unwired.
d) A Boolean terminal is wired to a numeric indicator.
ni.com/training
SummaryQuiz Answer
2. Which of the following are the components and data types
of the error cluster?
a) Status: Boolean
b) Error: String
c) Code: 32-bit integer
d) Source: String
ni.com/training
SummaryQuiz Answer
3. All errors have negative error codes and all warnings have
positive error codes.
a) True
b) False
In an error cluster, a status of TRUE is always an error
regardless of the code value. A non-zero code with a
status of FALSE is considered a warning.
ni.com/training
SummaryQuiz Answer
4. Merge Errors function concatenates error information from
multiple sources.
a) True
b) False
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
ni.com/training
Lesson 4
Implementing a VI
TOPICS
A.
B.
C.
D.
E.
F.
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
Tip Strips
Descriptions
VI Properties
Good Design
ni.com/training
ni.com/training
ni.com/training
Controls Palette
Tack the Controls palette and select CustomizeChange
Visible Palettes then click Select All
ni.com/training
D. While Loops
Iteration terminal: returns number of times loop has
executed; zero indexed
Conditional terminal: defines when the loop stops
Iteration Terminal
Conditional Terminal
ni.com/training
ni.com/training
E. For Loops
N=100;
i=0;
Until i=N:
Repeat (code;i=i+1);
End;
Flowchart
Pseudo Code
ni.com/training
E. For Loops
Create a For Loop the same way you create a While Loop
If you need to replace an existing While Loop with a For
Loop, right-click the border of the While Loop, and select
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
ni.com/training
ni.com/training
ni.com/training
While Loop
ni.com/training
ni.com/training
ni.com/training
F. Timing a VI
Why do you need timing in a VI?
Control the frequency at which a loop executes
Provide the processor with time to complete other tasks,
such as processing the user interface
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
VI finishes
Block Diagram
Run again
1st run
2nd run
Initialized
Shift
Register
Output = 5
Output = 5
Not
Initialized
Shift
Register
Output = 4
Output = 8
ni.com/training
ni.com/training
ni.com/training
ni.com/training
H. Plotting Data
ni.com/training
ni.com/training
I. Case Structures
ni.com/training
I. Case Structures
Case Selector Label: contains the name of the current case
and decrement and increment buttons on each side
ni.com/training
ni.com/training
Data Type
Default Value
Numeric
Boolean
FALSE
String
Empty
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
SummaryQuiz Answer
1. Which identifies the control or indicator on the block
diagram?
a) Caption
b) Location
c) Label
d) Value
ni.com/training
SummaryQuiz Answer
2. Which structure must run at least one time?
a) While Loop
b) For Loop
ni.com/training
SummaryQuiz Answer
3. Which is only available on the block diagram?
a)
b)
c)
d)
Control
Constant
Indicator
Connector Pane
ni.com/training
SummaryQuiz Answer
4. Which mechanical action causes a Boolean in the False state to
change to True when you click it and stay True until you release
it and LabVIEW has read the value?
a)
b)
c)
d)
ni.com/training
Lesson 6
Managing Resources
TOPICS
A. Understanding File I/O
B. Understanding High-level
File I/O
C. Understanding Low-level
File I/O
D. DAQ Programming
E. Instrument Control
Programming
F. Using Instrument Drivers
ni.com/training
Open/
Create/
Replace File
Read
and/or
Write to File
Close
File
Check for
Errors
ni.com/training
ni.com/training
Low-level VIs
ni.com/training
ni.com/training
ni.com/training
D. DAQ Programming
1.
2.
3.
4.
5.
Signal
Terminal Block
Cable
DAQ Device
Computer
ni.com/training
DAQ Assistant
DAQmx API
ni.com/training
Configure
Task
Start
Task
Acquire or
Generate
Data
Clear
Task
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
VISA
VISA
Virtual Instrument System Architecture
Serial
GPIB
VXI
USB
ni.com/training
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,VXI, ASRL), the address of the device,
and the VISA session type (INSTR or Event)
ni.com/training
VISA Alias
Assign a user-defined name to a device or resource in place
of the instrument descriptor
ni.com/training
VISA Programming
VISA functions operate similar to File I/O functions
Open Session
to
Instrument(s)
Perform I/O
Operation(s)
Close
Session to
Instrument(s)
Check for
Errors
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
VISA Serial
The VISA Configure Serial Port VI initializes the port identified
by VISA resource name to the specified settings
ni.com/training
Application Development
Environment (ADE)
Instrument Commands
(*idn?, meas?)
Instrument
Driver
ni.com/training
ni.com/training
SummaryQuiz Answer
1. Your continuously running test program logs to a single file the
results of all tests that occur in one hour as they are calculated. If
you are concerned about the execution speed of your program,
should you use low-level or high-level File I/O VIs?
a) Low-level file I/O VIs
b) High-level file I/O VIs
ni.com/training
SummaryQuiz Answer
2. If you want to view data in a text editor like Notepad, what file
format should you use to save the data?
a) ASCII
b) TDMS
ni.com/training
SummaryQuiz Answer
3. Which of the following conveys the basic DAQmx programming
flow?
a) Create TaskConfigure TaskAcquire/Generate DataStart Task
b) Acquire/Generate DataStart TaskClear Task
c) Start TaskCreate TaskConfigure TaskAcquire/Generate
DataClear Task
d) Create TaskConfigure TaskStart TaskAcquire/Generate
DataClear Task
ni.com/training
SummaryQuiz Answer
4. VISA is a high-level API that calls low-level drivers.
a) True
b) False
ni.com/training
Lesson 7
Developing Modular Applications
TOPICS
A. Understanding Modularity
B. Icon and Connector Pane
C. Using SubVIs
ni.com/training
A. Understanding Modularity
Modularity - The degree to which a program is
composed of discrete modules such that a change to
one module has minimal impact on other modules
Modules in LabVIEW are called subVIs
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
C. Using SubVIs
To place a subVI on the block diagram
Click Select a VI on the Functions palette
Navigate to the VI you want to use as a subVI
Double-click to place it on the block diagram
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
SummaryQuiz Answer
1. On a subVI, which terminal setting causes an error if the
terminal is not wired?
a) Required
b) Recommended
c) Optional
ni.com/training
SummaryQuiz Answer
2. You must create a custom icon to use a VI as a subVI.
a) True
b) False
You do not need to create a custom icon to use a
VI as a subVI, but it is highly recommended to
increase the readability of your code.
ni.com/training
Lesson 7
Using Sequential and
State Machine Algorithms
TOPICS
A. Using Sequential Programming
B. Using State Programming
C. State Machines
ni.com/training
ni.com/training
The second frame cannot begin execution until everything in the first
frame completes execution.
ni.com/training
ni.com/training
ni.com/training
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?
ni.com/training
ni.com/training
ni.com/training
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.
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
SummaryQuiz Answer
1. When using a Sequence structure, you can stop the execution in
the middle of a sequence.
a) True
b) False
You cannot stop the execution in the middle of a
sequence.
ni.com/training
SummaryQuiz 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.
ni.com/training
Lesson 8
Solving Dataflow Challenges with Variables
TOPICS
A.
B.
C.
D.
E.
ni.com/training
Variables
Variables Block diagram elements that allow
you to access or store data in another location
Variables can be of the following types:
LocalStores data in front panel controls and indicators.
Global Stores data in special repositories that can be
accessed from multiple VIs.
Functional GlobalStores data in While Loop shift
registers.
SharedTransfers data between various distributed
targets connected together over a network.
ni.com/training
D. Local Variables
When To Use Local Variables
Local Variables and Boolean Mechanical Actions
How To Create Local Variables
ni.com/training
Local Variables
ni.com/training
Local Variables
ni.com/training
ni.com/training
Race Conditions
Race Condition A situation where the timing of
events or the scheduling of tasks may unintentionally
affect an output or data value
ni.com/training
Value = (Value * 5) +2
Value = (Value + 2) * 5
Value = Value * 5
Value = Value +2
ni.com/training
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.
ni.com/training
SummaryQuiz Answer
1. You should use variables in your VI whenever possible.
a) True
b) False
You should use variables only when necessary. Use
wires to transfer data whenever possible.
ni.com/training
SummaryQuiz 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
ni.com/training
Lesson 9
Using Variables
TOPICS
A.
B.
C.
D.
Parallelism
Variables
Functional Global Variables
Race Conditions
ni.com/training
A. Parallelism
Execute multiple tasks at the same time
ni.com/training
A. Parallelism
Passing data among parallel loops is a challenge
How do the loops stop in this example?
ni.com/training
A. Parallelism
How do the loops stop in this example?
ni.com/training
A. Parallelism
Read the Stop button from a file
Each loop independently accesses the file
However, reading and writing to files can consume much
processor time
ni.com/training
B. Variables
Cannot pass data between parallel loops with a wire
Variables allow you to circumvent normal dataflow by
passing data from one place to another without connecting
the two places with a wire
ni.com/training
B. Variables
Variables - Block diagram elements that allow
you to access or store data in another location
Variables can be of the following types:
LocalStores data in front panel controls and indicators
Global Stores data in special repositories that can be
accessed from multiple VIs
Functional GlobalStores data in While Loop shift
registers
SharedTransfers data between various distributed
targets connected together over a network
ni.com/training
ni.com/training
B. Variables
Boolean controls with associated local variables must use
switch mechanical action
Boolean latch action is incompatible with local variables
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
B. Variables Initializing
Verify that variables contain known data values before the VI
runs
If you do not initialize
the variable before the
VI reads it for the
first time, it contains the
default value of the
associated front
panel object
ni.com/training
B. Variables Initializing
ni.com/training
ni.com/training
ni.com/training
ni.com/training
D. Race Conditions
Race Condition - A situation where the timing of events
or the scheduling of tasks may unintentionally affect an
output or data value
Race conditions are a common problem for programs
that execute multiple tasks in parallel and share data
between the tasks
ni.com/training
D. 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
Properly sequencing instructions
Identifying and protecting critical sections within your code
Reducing use of variables
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
SummaryQuiz
1. You should use variables in your VI whenever possible.
a) True
b) False
ni.com/training
SummaryQuiz Answer
1. You should use variables in your VI whenever possible.
a) True
b) False
You should use variables only when necessary. Use
wires to transfer data whenever possible.
ni.com/training
SummaryQuiz
2. Which of the following cannot transfer data?
a) Semaphores
b) Functional global variables
c) Local variables
d) Single process shared variables
ni.com/training
SummaryQuiz Answer
2. Which of the following cannot transfer data?
a) Semaphores
b) Functional global variables
c) Local variables
d) Single process shared variables
ni.com/training
SummaryQuiz
3. Which of the following must be used within a project?
a) Local variable
b) Global variable
c) Functional global variable
d) Single-process shared variable
ni.com/training
SummaryQuiz Answer
3. Which of the following must be used within a project?
a) Local variable
b) Global variable
c) Functional global variable
d) Single-process shared variable
ni.com/training
SummaryQuiz
4. Which of the following cannot be used to pass data between
multiple VIs?
a) Local variable
b) Global variable
c) Functional global variable
d) Single-process shared variable
ni.com/training
SummaryQuiz Answer
4. Which of the following cannot be used to pass data between
multiple VIs?
a) Local variable
b) Global variable
c) Functional global variable
d) Single-process shared variable
ni.com/training
Asynchronous Communication
LabVIEW is a dataflow language.
Functions depend on other functions for data.
Dependent functions do not execute until their
dependencies have completed execution.
Wires transfer data between functions.
However, sometimes you need break dataflow and program
using asynchronous communication.
ni.com/training
Asynchronous Communication
Asynchronous Communication Transfer
information without using wires
Parallel loops
UI and Block Diagram
VIs
Application instances (LabVIEW projects, executables, etc.)
Data
Notification that something happened
ni.com/training
B. Queues
Queues
Queue Operations
Producer/Consumer (Data) Design Pattern
ni.com/training
Queues
Are used for communicating data between parallel loops.
Store multiple pieces of data (i.e. buffer data).
Work in a FIFO (first in, first out) manner by default.
Can hold data of any type.
ni.com/training
Drawbacks of Variables
Drawbacks of using variables to communicate between loops:
Its possible to read duplicate
data.
Its possible to miss data.
You can create read-modifywrite race conditions.
ni.com/training
Queue Operations
Use the Queue Operations functions to
create and use a queue for communicating data between:
Different sections of a VI.
Different VIs.
ni.com/training
ni.com/training
C. Event-Driven Programming
Events Definition
Event-Driven Programming Definition
Polling Versus Event Structures
Parts of an Event Structure
Configuring the Event Structure
Caveats and Recommendations
ni.com/training
Events
Event An asynchronous notification that something
has occurred
ni.com/training
Event-Driven Programming
Event-Driven Programming Method of
programming where the program waits for an event to
occur before executing one or more functions
User Action
on
Front Panel
Execution
Block Diagram
ni.com/training
Event Structures
Events in Event structures eliminate the need to poll the front panel.
Benefits of using Event structures:
Reduces the CPU requirements of the program.
Simplifies the block diagram code.
Guarantees that the block diagram can respond to all interactions
the user makes.
ni.com/training
ni.com/training
Timeout
ni.com/training
Event Data
Node
Event Filter
Node
ni.com/training
ni.com/training
ni.com/training
Configured
Events
Event Sources
Events
ni.com/training
ni.com/training
ni.com/training
SummaryQuiz Answer
1. Which of the following buffer data?
a) Queues
b) Events
c) Local Variables
4. Enqueue Element
ni.com/training
SummaryQuiz Answer
3. Which of the following are valid data types for queues?
a) String
b) Numeric
c) Enum
d) Array of Booleans
e) Cluster of a String and a Numeric
ni.com/training
SummaryQuiz Answer
4. The Event structure handles only one event each time it
executes.
a) True
b) False
ni.com/training
A. Design Patterns
Design Patterns Code implementations and
techniques that are solutions to specific
problems in software design.
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
Execution Timing
SummaryQuiz Answer
1. The state machine is an example of a design pattern.
a) True
b) False
ni.com/training
SummaryQuiz Answer
2. Which of the following are reasons for using a multiple
loop design pattern?
a)
b)
c)
d)
ni.com/training
SummaryQuiz Answer
3. Software control timing allows the processor time to
complete other tasks.
a) True
b) False
ni.com/training
Lesson 2
Implementing Design Patterns
TOPICS
A. Design Patterns
B. Simple Design Patterns
C. Multiple Loop Design
Patterns
D. Error Handlers
Simple VI Pattern
Single VI that takes a measurement, performs calculations,
and either displays the results or records them to disk.
Usually does not require a specific start or stop action from
the user.
ni.com/training
General VI Pattern
This pattern has three phases:
Start-up
Main application
Shut-down
ni.com/training
General VI Framework
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
D. Error Handlers
Examples
Producer/Consumer Error Handler
ni.com/training
ni.com/training
ni.com/training
Error Handler VI
ni.com/training
ni.com/training
ni.com/training
ni.com/training
Execution Timing
Execution Timing
Design patterns where the timing is based on the
occurrence of events do not need execution timing.
ni.com/training
ni.com/training
Synchronized Timeout
Even if no other events occur or the queue is empty, both the
producer and consumer loops continue to execute at regular
intervals.
Timeout in ms
ni.com/training
ni.com/training
ni.com/training
FGV
ni.com/training
ni.com/training
Up Down Counter VI
Action SelectionUses
an Enum to select the
counter operation:
Reset
Increment
Decrement
Get Current Value
Running TotalOutputs
the current value of the Up
Down Counter VI.
ni.com/training
ni.com/training
Functional
Global
Variable
Stores data.
Can be written to or read from like a variable.
ni.com/training
Functional Global
Variable Code
ni.com/training
ni.com/training
SummaryQuiz
1. Which of the following are reasons for using a multiple
loop design pattern?
a)
b)
c)
d)
ni.com/training
SummaryQuiz Answer
1. Which of the following are reasons for using a multiple
loop design pattern?
a)
b)
c)
d)
ni.com/training
SummaryQuiz
2. Which of the following are examples of error handling
code?
a)
b)
c)
d)
ni.com/training
SummaryQuiz Answer
2. Which of the following are examples of error handling
code?
a)
b)
c)
d)
ni.com/training
SummaryQuiz
3. What is the default timeout value of an Event structure?
a)
b)
c)
d)
0
100 ms
Never time out
The input value of the Wait (ms) function that exists in the
same loop as the Event structure
ni.com/training
SummaryQuiz Answer
3. What is the default timeout value of an Event structure?
a)
b)
c)
d)
0
100 ms
Never time out
The input value of the Wait (ms) function that exists in same
loop as the Event structure
ni.com/training
Lesson 3
Controlling the User Interface
TOPICS
A.
B.
C.
D.
VI Server Architecture
Property Nodes
Invoke Nodes
Control References
ni.com/training
A. VI Server Architecture
VI Server Architecture
Properties and Methods
VI Class Hierarchy
ni.com/training
VI Server Architecture
The VI Server provides programmatic access to LabVIEW.
Use the VI Server to:
Programmatically control front panel objects & VIs
Dynamically load and call VIs
Run VIs on a computer or remotely across a network
Programmatically access to the LabVIEW environment and
editor (Scripting)
ni.com/training
VI ServerClass Hierarchy
Class
Control
Property: Visible
Method:
Reinitialize to Default
Sub-Class
Boolean
Array
Numeric
Property:
Boolean Text
Object
Property Values
Label Text: Stop Button
Visible: Yes
Boolean Text: Stop
ni.com/training
VI ServerClass Hierarchy
Generic
GObject
VI
Application
Generic
Etc.
GObject
Control
Control
Boolean
GraphChart
Numeric
Cluster
Etc.
Boolean
ni.com/training
B. Property Nodes
Definition
Creating Property Nodes
Execution Order
ni.com/training
Property Nodes
Property Nodes read and write the properties of an object.
Property Nodes can:
Change the color of a chart plot.
Disable and enable controls.
Get the location of a control or indicator.
Execution Order
ni.com/training
C. Invoke Nodes
Definition
Control Methods
VI Methods
ni.com/training
Invoke Nodes
Invoke Nodes call methods or actions on objects.
Get VI Version
Print VI panel
Reinitialize All to Default
Control Methods
To create an implicitly linked Invoke Node:
1.
2.
ni.com/training
VI Methods
Use a VI Server Reference to associate an Invoke Node
with the current VI.
To create a VI method:
1. Place an Invoke Node on the block diagram.
2. Right-click and select Select Class to choose a class.
3. Right-click again and select Select Method to choose a
method.
Class Name
Method Name
Parameter
ni.com/training
D. Control References
Implicitly and Explicitly Linked Property Nodes
Create SubVIs
Use the Create SubVI Tool
Create Manually
Control References
Implicitly Linked Property Node
Main VI
VI
Main VI
VI
SubVI
ni.com/training
Control References
A control reference is a reference to a front panel object.
Wire control references to
generic Property Nodes.
Pass control references
to subVIs.
ni.com/training
Creating a SubVI
To create explicitly linked Property Nodes in a subVI:
1. Create your VI.
2. Select the portion of the block
diagram that will be in the subVI.
3. Select EditCreate SubVI.
LabVIEW automatically creates
the control references needed
for the subVI.
4. Customize and save the subVI.
ni.com/training
Creating a SubVI
ni.com/training
Ctl Refnum
ni.com/training
ni.com/training
SummaryQuiz Answer
1. For each of the following items, determine whether they
operate on a VI class or a Control class.
a.
b.
c.
d.
ni.com/training
SummaryQuiz Answer
2. You have a Numeric control refnum in a subVI.
Which control references could you wire to the
control refnum terminal of the subVI?
a.
b.
c.
d.
ni.com/training
Lesson 4
File I/O Techniques
TOPICS
A.
B.
C.
D.
E.
TDMS
ASCII
Binary
ni.com/training
Ideal Use
ASCII
TDMS
Direct Binary
Good
Best
Best
Best
(Any program easily)
Better
(NI Programs easily;
Excel)
Good
(only with detailed
format information)
Good
Best
Best
Store measurement
data and related
metadata. High-speed
streaming without loss
of precision.
ni.com/training
ni.com/training
Hard-coded paths
Useful for quick prototypes.
Not recommended for applications.
File Dialog
Allow user to specify the path to a file or directory.
Customize dialog options to limit options (*.txt).
Programmatic creation
Create consistent filenames and extensions.
Example: testdata_001.txt, testdata_002.txt, etc.
Specify a consistent location.
ni.com/training
ni.com/training
Creating Folders
Check if folder already exists before creating. Otherwise,
attempting to create an existing folder will result in an error.
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
Header Data
24.45
34.54
Operator Name
David
23.41
35.32
UUT S/N
A1234
22.97
35.98
Test Name
Pressure
21.56
36.76
Channel Name
Temperature
Pressure
Units
Kelvin
PSI
Max. Value
24.45
36.76
24.45
34.54
23.41
35.32
22.97
35.98
21.56
36.76
Tab
CR/LF
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
TDMS Functions
ni.com/training
ni.com/training
SummaryQuiz Answer
1. Consider the following code. The resulting Log File Path
contains a text file path in which folder?
a) Same folder as VI that executed the code
b) Same folder as the LabVIEW project
c) Current users AppData directory
d) Same folder as the Application Directory VI
ni.com/training
SummaryQuiz Answer
2. What index value is returned from Search 1D Array
function if Property Name is not found in the input array?
a) NaN (Not a Number)
b) 0
c) -1
d) Negative Infinity
ni.com/training
SummaryQuiz Answer
3. You need to store data that other engineers will later
analyze with Microsoft Excel. Which file storage format(s)
should you use?
a) Tab-delimited ASCII
b) Custom binary format
c) TDMS
ni.com/training
SummaryQuiz Answer
4. TDMS File store properties at which of the following
levels?
a) File
b) Channel Group
c) Channel
d) Value
ni.com/training
Lesson 5
Controlling the User Interface
TOPICS
A.
B.
C.
D.
Property Nodes
Invoke Nodes
VI Server Architecture
Control References
ni.com/training
A. Property Nodes
Property Nodes access the properties of an object
In some applications, you might want to modify the
appearance of front panel objects programmatically in
response to certain inputs
If a user enters an invalid password, you might want a red LED
to start blinking
If a data point is above a certain value, you might want to show
a red trace instead of a green one
ni.com/training
B. Invoke Nodes
Use the Invoke Node to perform actions, or methods, on
referenced items
Control
VI
ni.com/training
ni.com/training
Main VI
VI
Main VI
VI
SubVI
ni.com/training
ni.com/training
C. VI Server Architecture
VI Server performs many functions; however, this lesson
concentrates on using VI Server to control front panel objects
and edit the properties of a VI.
ni.com/training
VI Server Terminology
An object is a member of a class.
A class defines what an object is able to do, what operations
it can perform (methods), and what properties it has.
Methods perform an operation on an object.
Properties are the attributes of an object.
ni.com/training
Boolean
Stop
Boolean Sub-Class
Property: Boolean Text
Control Class
Property: Visible
Method: Reinitialize to Default
Array
Array Sub-Class
Property: Number of Rows
Stop Object
Properties:
Visible: Yes
Boolean Text: Stop
Method:
Reinitialize to Default
ni.com/training
VI Server Classes
Control Classes
LabVIEW front panel objects inherit properties and methods
from a specific control class
VI Class
Your VI belongs to the VI Class and has its own properties and
methods associated with it
ni.com/training
Class Hierarchy
Generic Object
GObject
Control
Boolean
ni.com/training
ni.com/training
D. Control References
A control reference is a reference to a front panel object
Wire control references to
generic Property Nodes
Pass control references
to subVIs
ni.com/training
ni.com/training
Ctl Refnum
ni.com/training
ni.com/training
ni.com/training
SummaryQuiz Answer
1. For each of the following items, determine whether they
operate on a VI class or a Control class.
a.
b.
c.
d.
ni.com/training
SummaryQuiz Answer
2. You have a GraphChart control refnum in a subVI.
Which control references could you wire to the
control refnum terminal of the subVI? (multiple answers)
a.
b.
c.
d.
ni.com/training
Lesson 5
Improving an Existing VI
TOPICS
A. Refactoring Inherited Code
B. Typical Refactoring Issues
ni.com/training
ni.com/training
ni.com/training
When to Refactor
When you are adding a feature to a VI or debugging it.
Good candidates for complete rewrites:
VIs that do not function.
VIs that satisfy only a small portion of your needs.
ni.com/training
Refactoring Process
When you refactor to improve
the block diagram, make small
cosmetic changes before
tackling larger issues.
ni.com/training
Disorganization
The block diagram is too disorganized, too big, or includes too
many nested structures
Solution:
Move objects within the block diagram.
Create subVIs to make it smaller and more organized.
Place comments to improve readability.
ni.com/training
Poor Naming
The block diagram uses incorrect object names and poor
icons.
Best
Better
Good
8
ni.com/training
Overly Complicated
The block diagram uses complicated or unnecessary logic.
ni.com/training
Duplicate Logic
The block diagram uses duplicate logic.
Solution:
Refactor the VI by creating a subVI for the duplicated logic.
ni.com/training
Breaks Dataflow
The block diagram does not use dataflow programming.
Solution:
Replace Sequence structures with state machines.
Delete local variables and wire directly to controls or
indicators.
ni.com/training
Outdated Practices
The VI was created in an earlier version of LabVIEW and has
outdated practices.
Solutions:
Replace polling-based design with event-based design.
Use new features that simplify code.
ni.com/training
SummaryRefactoring Checklist
Use the following refactoring checklist to help determine if
you should refactor a VI:
VI is too disorganized, too big, or includes too many
nested structures.
VI uses incorrect object names and poor icons.
VI uses unnecessary logic or has complicated
algorithms.
VI has duplicated logic.
VI does not use dataflow programming.
VI uses outdated development practices.
ni.com/training
Lesson 6
Creating and Distributing Applications
TOPICS
A.
B.
C.
D.
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
The VI returns:
ni.com/training
C:\Users\<user>\Documents
ni.com/training
ni.com/training
Build Specifications
A build specification contains all the settings for the build,
such as files to include, directories to create, and settings for
VIs.
ni.com/training
ni.com/training
ni.com/training
13
ni.com/training
ni.com/training
ni.com/training
2
ni.com/training
ni.com/training
ni.com/training
2
3
ni.com/training
ni.com/training
ni.com/training
D. Create an Installer
Why Create an Installer?
Configure the Installer Build Specifications
Deploy the Application to Another Machine
Debug the Executable
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
Summary
The Application Builder enables you to create stand-alone
applications and installers.
To create a professional, stand-alone application you must
understand:
The architecture of your application.
The programming issues particular to your application.
The application building process.
The installer building process.
Lesson 2
Synchronization Techniques
TOPICS
A. Notifiers
B. Queues
ni.com/training
ni.com/training
A. Notifiers
Use the Notifier Operations functions to suspend the
execution of a block diagram until you receive data from
another section of the block diagram or from another VI.
ni.com/training
ni.com/training
Notifiers Benefits
The following benefits result from using notifiers to transfer
data between parallel loops:
Both loops are synchronized to the master loopthe slave
loop only executes when the master loop sends a
notification
You can use notifiers to create globally available data,
making it possible to send data with a notification
Using notifiers creates efficient codethere is no need to
poll to determine when data is available from the master
loop
ni.com/training
Notifiers Disadvantages
Notifiers do not buffer data.
If the master loop sends another piece of data before the
first piece of data has been read by the slave loops, that
data is overwritten and lost.
ni.com/training
B. Queues
Queues are similar to notifiers, except that a queue can
store multiple pieces of data
By default, queues work in a FIFO (first in, first out) manner
Use a queue when you want to process all data placed in
the queue
Use a notifier if you only want to process the current data
ni.com/training
B. Queues
Use the Queue Operations functions to create a queue for
communicating data between sections of a block diagram or
from another VI.
ni.com/training
ni.com/training
SummaryQuiz Answer
1. Which of the following buffer data?
a) Notifiers
b) Queues
c) Global Variables
d) Local Variables
ni.com/training
SummaryQuiz Answer
3. Which of the following are valid data types for queues and
notifiers?
a) String
b) Numeric
c) Enum
d) Array of Booleans
e) Cluster of a String and a Numeric
ni.com/training
Lesson 3
Event Programming
TOPICS
A.
B.
C.
D.
Events
Event-Driven Programming
Caveats and Recommendations
Event-Based Design Patterns
ni.com/training
A. Events
Event An asynchronous notification that something
has occurred
ni.com/training
User Action
on
Front Panel
Execution
Block Diagram
ni.com/training
B. Event-Driven Programming
Parts of an Event structure
Notify and filter events
Configure and use the Event structure
Event Registration and Panel Locking
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
Configured
Events
Event Sources
Events
ni.com/training
ni.com/training
You must read the control terminal inside the event case for the
mechanical action to work correctly
ni.com/training
ni.com/training
ni.com/training
Producer/Consumer (Events)
Benefits
Efficiently
responds
asynchronously
to the user
interface
Queues can
transfer any
data type
ni.com/training
SummaryQuiz Answer
1. Using user interface events allows you to synchronize
user actions on the front panel with block diagram
execution.
a) True
b) False
ni.com/training
SummaryQuiz Answer
2. The Event structure handles only one event each time it
executes.
a) True
b) False
ni.com/training
SummaryQuiz Answer
3. Which of the following are examples of user interface
events?
a) Mouse click
b) Keystroke
c) Event Filter Node
d) Value change of a control
ni.com/training
SummaryQuiz Answer
4. Which of the following operations will generate a Value
Change event for a numeric control?
a) Click inside the digital display window and enter a
number from the keyboard
b) Click the increment or decrement arrow buttons
c) Place the cursor to the right of the digit you want to
change and press the up or down arrow keys
d) Update the numeric control using a local variable
ni.com/training
Lesson 3
Implementing a VI
TOPICS
A.
B.
C.
D.
E.
F.
G.
H.
I.
Timing a VI
Data Feedback in Loops
Plotting Data Waveform Chart
Case Structures
ni.com/training
ni.com/training
ni.com/training
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.
ni.com/training
Numerics
Various data type
representations:
Floating-point
Unsigned integers
Signed integers
ni.com/training
Numeric Conversion
Coercion Dot
ni.com/training
Booleans
Behavior of Boolean
controls is specified by the
mechanical action.
Boolean have only
TRUE/FALSE values.
ni.com/training
Strings
A string is a sequence
of ASCII characters.
Strings have various
display styles.
Backslash codes
Password
Hex
ni.com/training
Enums
Enums give users a list of
items from which to
select.
Each item represents a
pair of values.
String
16-bit Integer
ni.com/training
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.
ni.com/training
C. Documenting Code
VI Descriptions
Tip Strips
Labels
Free
Owned
ni.com/training
Documenting Code
VI
Name
Description
Front Panel
Block Diagram
Label Names
Tip Strips
Descriptions
Free Labels
Label Names
Free Labels
Owned
Labels
SubVI
Descriptions
ni.com/training
ni.com/training
Owned labels:
Describe algorithms.
Have pale yellow backgrounds.
Double-click in any open space
to create.
ni.com/training
D. While Loops
Iteration and Conditional Terminals
Tunnels
Error Checking
ni.com/training
While Loops
Repeat (code);
Until Condition met;
End;
Flowchart
Pseudo Code
ni.com/training
While Loops
Iteration terminal
Conditional terminal
Iteration Terminal
Conditional Terminal
ni.com/training
ni.com/training
ni.com/training
E. For Loops
Conditional Terminal
Comparison with While Loops
Numeric Conversion for Count Terminal
ni.com/training
For Loops
N=100;
i=0;
Until i=N:
Repeat (code;i=i+1);
End;
Flowchart
Pseudo Code
ni.com/training
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 rightclicking 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.
ni.com/training
ni.com/training
ni.com/training
While Loop
Stops executing only if the value
at the conditional terminal meets
the condition.
Must execute at least once.
Tunnels automatically output the
last value.
ni.com/training
ni.com/training
F. Timing a VI
Reasons To Use Timing
Wait Functions and Express VIs
ni.com/training
Timing a VI
Why do you need timing in a VI?
To control the frequency at which a loop executes.
To provide the processor with time to complete other tasks,
such as processing the user interface.
ni.com/training
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.
ni.com/training
ni.com/training
ni.com/training
ni.com/training
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.
ni.com/training
VI finishes
Block Diagram
Run again
1st run
2nd run
Initialized
Shift
Register
Output = 5
Output = 5
Not
Initialized
Shift
Register
Output = 4
Output = 8
ni.com/training
Default Value
Numeric
Boolean
FALSE
String
Empty
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
I. Case Structures
Parts of a Case Structure
Enum Case Structures
Error Case Structures
Input and Output Tunnels
ni.com/training
Case Structures
ni.com/training
Case Structures
Case Selector Label
Contains the name of the current
case.
Has decrement and increment
arrows.
Selector Terminal
Lets you wire an input value, or
selector, to determine which
case executes.
Selector Terminal
ni.com/training
Case Structures
Selector terminal data types:
Boolean
True case and False Case
Error Cluster
Error Case and No Error Case
ni.com/training
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.
ni.com/training
ni.com/training
ni.com/training
SummaryQuiz 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.
ni.com/training
SummaryQuiz Answer
2. Which structure must run at least one time?
a) While Loop
b) For Loop
ni.com/training
SummaryQuiz
3. Which is only available on the block diagram?
a)
b)
c)
d)
Control
Constant
Indicator
Connector Pane
ni.com/training
SummaryQuiz Answer
3. Which is only available on the block diagram?
a)
b)
c)
d)
Control
Constant
Indicator
Connector Pane
ni.com/training
SummaryQuiz
4. Which mechanical action causes a Boolean control in the
FALSE state to change to TRUE when you click it and stay
TRUE until LabVIEW has read the value?
a)
b)
c)
d)
ni.com/training
SummaryQuiz Answer
4. Which mechanical action causes a Boolean control in the
FALSE state to change to TRUE when you click it and stay
TRUE until LabVIEW has read the value?
a)
b)
c)
d)
ni.com/training
Lesson 4
Error Handling
TOPICS
A.
B.
C.
D.
E.
ni.com/training
ni.com/training
Merge Error VI
Merge Error VI returns the first error found. If no error is
found, it returns the first warning.
This VI does not concatenate errors.
ni.com/training
Warning
Status = False and Code is nonzero
ni.com/training
ni.com/training
ni.com/training
E. Error Handlers
Error Handler A VI or code that changes normal
flow of program execution when an error occurs.
Examples:
Simple Error Handler VI Optionally display a dialog box
with error information when an error occurs.
State machine error handler Transitions the state machine
to an error or shutdown state when an error occurs.
I/O error handler If an I/O operation times out, retry for a
certain period of time before reporting an error.
ni.com/training
SummaryQuiz Answer
1. Merge Errors VI concatenates error information from
multiple sources.
a) True
b) False
ni.com/training
10
SummaryQuiz Answer
2. All errors have negative error codes and all warnings have
positive error codes.
a) True
b) False
ni.com/training
11
Lesson 5
Creating and Leveraging Data Structures
TOPICS
A.
B.
C.
D.
E.
F.
Arrays
Common Array Functions
Polymorphism
Auto-Indexing
Clusters
Type Definitions
ni.com/training
A. Arrays
1D and 2D Arrays
Creating an Array Control and Constant
Initializing Arrays
ni.com/training
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.
ni.com/training
1.2 3.2 8.2 8.0 4.8 5.1 6.0 1.0 2.5 1.7
2D array
Five-row by seven-column table of 35
elements
0
Index
numbers
0
1
2
3
4
ni.com/training
ni.com/training
First element
at index 1
Second
element at
index 2
ni.com/training
3.
ni.com/training
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.
ni.com/training
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 rightclicking the index display and selecting Add Dimension
from the shortcut menu.
Resize the index display until you have as many dimensions
as you want.
ni.com/training
Array Size
Initialize Array
Array Subset
Build Array
Index Array
ni.com/training
Array Size
ni.com/training
Initialize Array
ni.com/training
Array Subset
ni.com/training
Build Array
ni.com/training
Index Array
ni.com/training
Polymorphism
Polymorphism - The ability of VIs and functions to
automatically adapt to accept input data of different
data types
Functions are polymorphic to varying degrees:
None, some, or all of their inputs can be polymorphic.
Some accept numeric or Boolean values.
Some accept numeric or strings.
Some accept scalars, numeric arrays, or clusters of
numerics.
ni.com/training
Result
ni.com/training
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
ni.com/training
Auto-Indexing
Auto-Indexing Enabled
Wire becomes thicker
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.
ni.com/training
ni.com/training
ni.com/training
Creating 2D Arrays
1D Array
0 1
3 4
2D Array
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.
ni.com/training
Auto-Indexing Input
Use an auto-indexing input array to perform calculations
on each element in an array.
ni.com/training
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
ni.com/training
Clusters
Clusters group data elements of mixed types.
Clusters are similar to a record or a struct in text-based
programming languages.
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
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.
ni.com/training
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.
ni.com/training
Disassembling a Cluster
Use the Unbundle By Name function whenever possible.
Use Unbundle function when some or all cluster elements
are unnamed.
ni.com/training
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.
ni.com/training
ni.com/training
ni.com/training
Plotting Data
Use the Context Help window to determine how to wire
multi-plot data to Waveform Graphs, Charts and XY Graphs.
ni.com/training
Error Clusters
LabVIEW uses error clusters to pass error information.
An error cluster contains the following elements:
statusBoolean value that reports True if an error occurs.
code32-bit signed integer that identifies the error.
sourceString that identifies where the error occurred.
ni.com/training
F. Type Definitions
Type Definitions and Custom Data Types
Creating and Identifying Type Definitions
Controls
Strict Type Definitions
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
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.
ni.com/training
ni.com/training
SummaryQuiz Answer
1. You can create an array of arrays.
a) True
b) False
ni.com/training
SummaryQuiz Answer
2. What is the value of the Iterations indicator
after running this VI?
4
ni.com/training
SummaryQuiz 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
ni.com/training
SummaryQuiz Answer
4.
ni.com/training
Lesson 5
Relating Data
TOPICS
A. Arrays
B. Clusters
C. Type Definitions
ni.com/training
A. Arrays
An array consists of elements and dimensions
Elements: data that make up the array
Dimension: the length, height, or depth of an array
An array can have one or more dimensions
and as many as (231)1 elements per
dimension, memory permitting
A. Arrays
The first element shown in the array (3.00) is at index 1 and
the second element (1.00) is at index 2
The element at index 0 is not shown in this image, because
element 1 is selected in the index display
The element selected in the index display always refers to
the element shown in the upper left corner of the element
display
ni.com/training
A. Arrays Creating
1. Place an array shell on the front panel
2. Drag a data object or element into the array shell
ni.com/training
A. Arrays 2D Array
Stores elements in a grid
Requires a column index and a row index to locate an
element, both of which are zero-based
To create a multidimensional array on the front panel, rightclick the index display and select Add Dimension from the
shortcut menu
You also can resize the index display until you have as
many dimensions as you want
ni.com/training
A. Arrays Initializing
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
ni.com/training
A. Arrays Auto-indexing
If you wire an array to or from a For Loop or While Loop, you
can link each iteration of the loop to an element in that array
by enabling auto-indexing on tunnel
The tunnel changes from a solid square to the image shown
above to indicate auto-indexing
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
Intensity Graph
GOAL
POLYMORPHIC - functions
GOAL
MODIFY this VI
Extract THIRD ROW
Extract SECOND COLUMN
Use:
GOAL
Exercise 5-1
Concept: Manipulating Arrays
B. Clusters
Clusters group data elements of mixed types
Similar to a record or a struct in text-based programming
languages
ni.com/training
ni.com/training
B. Clusters Creating
To create a cluster control or indicator on the front panel:
Place a cluster shell on the front panel
Drag a data object or element,
which can be a numeric, Boolean,
string, path, refnum, array, or
cluster control or indicator into
the cluster shell
ni.com/training
B. Clusters Constants
To create a cluster constant:
1. Select a cluster constant on the Functions palette
2. Place the cluster shell on the block diagram
3. Place a constant in the cluster shell
ni.com/training
B. Clusters 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 from
the shortcut menu
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
C. Type Definitions
You can save a custom control as:
Control
Type Definition
Strict Type Definition
ni.com/training
ni.com/training
ni.com/training
ni.com/training
SummaryQuiz
1. You can create an array of arrays.
a) True
b) False
ni.com/training
SummaryQuiz Answer
1. You can create an array of arrays.
a) True
b) False.
You cannot drag an array data type into an array
shell. However, you can create two-dimensional
arrays.
ni.com/training
SummaryQuiz
2. What is the value of the Iterations indicator
after running this VI?
ni.com/training
SummaryQuiz Answer
2. What is the value of the Iterations indicator
after running this VI? Value of Iterations = 4
ni.com/training
SummaryQuiz
3. You customize a control, select Control from the Control
Type pull-down menu, and save the control as a .ctl
file. You then use an instance of the custom control on
your front panel. If you open the .ctl file and modify the
control, does the control on the front panel change?
a) Yes
b) No
ni.com/training
SummaryQuiz Answer
3. You customize a control, select Control from the Control
Type pull-down menu, and save the control as a .ctl
file. You then use an instance of the custom control on
your front panel. If you open the .ctl file and modify the
control, does the control on the front panel change?
a) Yes
b) No
ni.com/training
SummaryQuiz
4.
You are inputting data that represents a circle. The circle data
includes three double precision numerics: x position, y position and
radius. In the future, you might need to expand all instances of the
circle data to include the color of the circle, represented as an
integer. How should you represent the circle on your front panel?
a) Three separate controls for the two positions and the radius
b) A cluster containing all of the data
c) A custom control containing a cluster
d) A type definition containing a cluster
e) An array with three elements
ni.com/training
SummaryQuiz Answer
4.
You are inputting data that represents a circle. The circle data
includes three double precision numerics: x position, y position and
radius. In the future, you might need to expand all instances of the
circle data to include the color of the circle, represented as an
integer. How should you represent the circle on your front panel?
a) Three separate controls for the two positions and the radius
b) A cluster containing all of the data
c) A custom control containing a cluster
d) A type definition containing a cluster
e) An array with three elements
ni.com/training
Lesson 8
Common Design Techniques and Patterns
TOPICS
A. Using Sequential Programming
B. State Programming
C. State Machines
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
C. State Machines
The state machine design pattern implements a state
diagram or flow chart
When to use state machines?
Commonly used to create user interfaces, where different user
actions send the user interface into different states
Commonly used for process tests, where a state represents
each segment of the process
ni.com/training
Shift Register
ni.com/training
ni.com/training
C. State Machines
Transition Between Two States
ni.com/training
C. State Machines
Case Structure Transition
ni.com/training
C. State Machines
Transition Array Transition
ni.com/training
SummaryQuiz Answer
1. When using a Sequence structure, you can stop the execution
part way through a sequence.
a) True
b) False
ni.com/training
SummaryQuiz 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
ni.com/training
Appendix A
Measurements Fundamentals
TOPICS
A. Computer-based Measurement Systems
B. Measurement Concepts
C. Increasing Measurement Quality
ni.com/training
ni.com/training
ni.com/training
B. Measurement Concepts
Grounded Signal Source
Voltage signals are referenced to a
system ground, such as the earth or
a building ground
Because such sources use the
system ground, they share a
common ground with the measurement device
Common examples are devices that plug into a building
ground through wall outlets, such as signal
generators and power supplies
ni.com/training
ni.com/training
B. Measurement Concepts
Floating Signal Source
In a floating signal source, the voltage
signal is not referenced to any
common ground, such as the earth
or a building ground
Some common examples of floating
signal sources are batteries, thermocouples, transformers,
and isolation amplifiers
Neither terminal of the source is connected to
the electrical outlet ground - each terminal is
independent of the system ground
ni.com/training
B. Measurement Concepts
Signal Conditioning
Many stand-alone instruments and DAQ devices have builtin signal conditioning
Signal conditioning also can be applied externally, by
designing a circuit to condition the signal or by using devices
specifically made for signal conditioning
To measure signals from transducers, you must convert
them into a form a measurement device can accept
Common types of signal conditioning include amplification,
linearization, transducer excitation, and isolation
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
B. Measurement Concepts
Measurement Systems
Differential
AIGND (analog input
ground) pin is the
measurement system
ground
Requires two channel
pins to measure a signal
ni.com/training
B. Measurement Concepts
Measurement Systems
Referenced SingleEnded (RSE)
AIGND is the
measurement system
ground
Need only one channel
to measure a signal
ni.com/training
B. Measurement Concepts
Measurement Systems
Non-referenced SingleEnded (NRSE)
AISENSE pin is the
measurement system
ground
Need one channel and
AISENSE to a measure
a signal
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
ni.com/training
C = code width
D = device input range (ADC range/amplification)
R = bits of resolution
The smaller the code width, the more accurately a device can
represent the signal
A 12-bit DAQ device with a 0 to 10 V ADC range and an
amplification of one detects a 2.4 mV change, while the same
device with a 10 to 10 V ADC range would detect a change of
4.8 mV
ni.com/training
C = code width
D = device input range (ADC range/amplification)
R = bits of resolution
ni.com/training
f sampling 2 f signal
The Nyquist Theorem states that you must sample a signal at
a rate greater than twice the highest frequency component of
interest in the signal to capture the highest frequency
component of interest
ni.com/training
Original Signal
Sampled Signal
ni.com/training
C. Decreasing Noise
To reduce noise take the following precautions:
Use shielded cables or a twisted pair of cables
Minimize wire length to minimize noise the lead wires pick up
Keep signal wires away from AC power cables and monitors to reduce
50 or 60 Hz noise
Increase the signal-to-noise (SNR) ratio by amplifying the signal close
to the signal source
Acquire data at a higher frequency than necessary, then average the
data to reduce the impact of the noise, as noise tends to average to
zero
ni.com/training
SummaryQuiz
1. Calculate the code-width for a signal acquired using a 16 bit data
acquisition board with a device input range of 5 volts.
1
CD R
2
ni.com/training
SummaryQuiz Answer
1. Calculate the code-width for a signal acquired using a 16 bit data
acquisition board with a device input range of 5 volts.
76.29 microvolts
C 5.
7 6.2 9 V
16
2
ni.com/training
SummaryQuiz
2. You are acquiring a triangle wave with a frequency of 1100 Hertz.
Which sampling frequency should you use for best shape
recovery of the signal?
a)
b)
c)
d)
1 kHz
10 kHz
100 kHz
1000 kHz
ni.com/training
SummaryQuiz Answer
2. You are acquiring a triangle wave with a frequency of 1100 Hertz.
Which sampling frequency should you use for best shape
recovery of the signal?
a)
b)
c)
d)
1 kHz
10 kHz
100 kHz
1000 kHz
ni.com/training
SummaryQuiz
3. You are acquiring a triangle wave with a frequency of 1100 Hertz.
You can sample the signal at the following rates. Which is the
minimum sampling frequency you should use to reliably acquire
the frequency of the signal?
a)
b)
c)
d)
1 kHz
10 kHz
100 kHz
1000 kHz
ni.com/training
SummaryQuiz Answer
3. You are acquiring a triangle wave with a frequency of 1100 Hertz.
You can sample the signal at the following rates. Which is the
minimum sampling frequency you should use to reliably acquire
the frequency of the signal?
a)
b)
c)
d)
1 kHz
10 kHz
100 kHz
1000 kHz
ni.com/training