Professional Documents
Culture Documents
ni.com/training
What You Need To Get Started
ni.com/training
File Locations
ni.com/training
Instructional Methods
ni.com/training
Getting The Most Out Of This Course
• Ask questions!
• Complete the homework exercises each evening and be
prepared to ask questions about them
• Experiment with hands-on exercises to understand the
methods used
• Explore solutions
• Implementations explore a possible solution—you may find
a better one
ni.com/training
Courses
New User Experienced User
ni.com/training
Course Learning Map
ni.com/training
Course Goals
ni.com/training
Lesson 1
Setting Up Hardware
TOPICS
A. DAQ Hardware E. Serial Port
B. Using DAQ Software Communication
C. Instrument Control F. Using Instrument Control
D. GPIB Software
ni.com/training
Setting Up Hardware
ni.com/training
A. DAQ Hardware
1. Signal
2. Terminal Block
3. Cable
4. DAQ Device
5. Computer
ni.com/training
DAQ Hardware – Terminal Block & Cable
ni.com/training
DAQ Hardware – DAQ Device
ni.com/training
DAQ Hardware – Analog Input
ni.com/training
DAQ Hardware – Analog Output
ni.com/training
DAQ Hardware – Digital I/O
• Digital signals:
− 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
• program devices
• communicate between devices
− Use digital signals as clocks or triggers to
control or synchronize other measurements
ni.com/training
DAQ Hardware – Counters
ni.com/training
B. Using DAQ Software – Configuration
ni.com/training
Simulating a DAQ Device
ni.com/training
Exercise 1-1
Concept: Measurement and Automation Explorer
HOMEWORK
Use MAX to examine, configure, and test a DAQ device.
GOAL
Exercise 1-1
Concept: Measurement and Automation Explorer
DISCUSSION
C. Instrument Control
ni.com/training
C. Instrument Control
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
ni.com/training
E. Serial Port Communication
Serial communication
• Transmits data between a computer and a peripheral
device, such as a programmable instrument or another
computer
• Uses a transmitter to send data one bit at a time over a
single communication line to a receiver
• Best method when data transfer rates are low, or you must
transfer data over long distances
• Most computers have one or more serial ports, so you do
not need any extra hardware other than a cable
ni.com/training
F. Using Instrument Control Software
ni.com/training
Exercise 1-2
Concept: GPIB Configuration with MAX
HOMEWORK
Learn to configure the NI Instrument Simulator and use MAX
to examine the GPIB interface settings, detect instruments,
and communicate with an instrument.
GOAL
Exercise 1-2
Concept: GPIB Configuration with MAX
DISCUSSION
Summary—Quiz
ni.com/training
Summary—Quiz Answer
ni.com/training
Summary—Quiz
ni.com/training
Summary—Quiz Answers
ni.com/training
Lesson 2
Navigating LabVIEW
TOPICS
A. Virtual Instruments (VIs) G. Searching for Controls, VIs
B. Parts of a VI and Functions
C. Starting a VI H. Selecting a Tool
D. Project Explorer I. Dataflow
E. Front Panel J. Building a Simple VI
F. Block Diagram
ni.com/training
A. Virtual Instruments (VIs)
ni.com/training
B. Parts of a VI
ni.com/training
B. Parts of a VI – Front Panel
ni.com/training
B. Parts of a VI – Block Diagram
ni.com/training
B. Parts of a VI – Icon/Connector Pane
• Icon: graphical representation of a VI
• Connector Pane: map of the inputs and outputs of a VI
• Icons and connector panes are necessary to use a VI as
a subVI
− A subVI is a VI that is inside of another VI
− Similar to a function in a text-based programming
language
Icon Connector Pane
ni.com/training
C. Starting a VI
DEMONSTRATION
D. Project Explorer
Use LabVIEW Projects to:
• Group LabVIEW files and non-LabVIEW files
• Create build specifications
• Deploy or download files to targets
ni.com/training
Using the Project Explorer
DEMONSTRATION
E. Front Panel – Controls Palette
• Contains the controls and indicators you use to
create the front panel
• Access from the front panel by selecting
View»Controls Palette
ni.com/training
E. Front Panel – Front Panel Toolbar
ni.com/training
E. Front Panel – Controls & Indicators
• Controls
− Knobs, push buttons, dials, and other input devices
− Simulate instrument input devices and supply data to the block
diagram of the VI
• Indicators
− Graphs, LEDs, and other displays
− Simulate instrument output devices and display data the block
diagram acquires or generates
ni.com/training
E. Front Panel – Numeric Controls/Indicators
Numeric Control
Increment/Decrement Buttons
Numeric Indicator
ni.com/training
E. Front Panel – Boolean Controls/Indicators
• The Boolean data type represents data that only has two
parts, such as True and False or On and Off
• Use Boolean controls and indicators to enter and display
Boolean (True or False) values
• Boolean objects simulate switches, push buttons, and LEDs
Boolean Boolean
Control Indicator
ni.com/training
E. Front Panel – Strings
ni.com/training
E. Front Panel – Shortcut Menus
• All LabVIEW objects have
associated shortcut menus
• As you create a VI, use the
shortcut menu items to change
the look or behavior of front
panel and block diagram
objects
• To access the shortcut menu,
right-click the object
ni.com/training
E. Front Panel – Property Dialog Box
• Right-click a front panel
object and select
Properties to display
• The options available on
the property dialog box
are similar to the options
available on the shortcut
menu for that object
ni.com/training
E. Front Panel – Configure Multiple Objects
ni.com/training
F. Block Diagram
ni.com/training
F. Block Diagram – Functions Palette
Contains the VIs, functions, and constants
you use to create the block diagram
ni.com/training
F. Block Diagram – Block Diagram Toolbar
ni.com/training
F. Block Diagram – Terminals
• Terminals are:
− Block diagram appearance of front panel objects
− Entry and exit ports that exchange information between the
front panel and block diagram
− Analogous to parameters and constants in text-based
programming languages
• Change the view type of a terminal by toggling the View as
Icon selection from the context menu
ni.com/training
F. Block Diagram Terminals
ni.com/training
F. Block Diagram – Nodes
ni.com/training
F. Block Diagram – Function Nodes
ni.com/training
F. Block Diagram – SubVI Nodes
ni.com/training
F. Block Diagram – SubVI Nodes
• Express VIs are a special type of subVI
− Require minimal wiring because you configure them
with dialog boxes
− Save the configuration of an Express VI as a subVI
• Icons for Express VIs appear on the block diagram
as icons surrounded by a blue field
ni.com/training
F. Block Diagram – Icons/Expandable Nodes
ni.com/training
F. Block Diagram – Wires
ni.com/training
F. Block Diagram – Wiring Tips
ni.com/training
F. Block Diagram – Wiring Tips
ni.com/training
Exercise 2-1
Concept: Exploring a VI
HOMEWORK
Identify the parts of an existing VI.
GOAL
Exercise 2-1
Concept: Exploring a VI
DISCUSSION
G. Searching for Controls, VIs & Functions
ni.com/training
Exercise 2-2
Concept: Navigating Palettes
DISCUSSION
H. Selecting A Tool
ni.com/training
Exercise 2-3
Concept: Selecting A Tool
DISCUSSION
I. Dataflow
ni.com/training
I. Dataflow – Quiz
ni.com/training
I. Dataflow – Quiz Answers
NO CORRECT ANSWER
ni.com/training
Exercise 2-4
Concept: Dataflow
DISCUSSION
J. Building a Simple VI
ni.com/training
J. Building a Simple VI – Acquire
ni.com/training
J. Building a Simple VI – Analyze
• Statistics Express VI
• Filter Express VI
ni.com/training
J. Building a Simple VI – Present
ni.com/training
J. Building A Simple VI – Running
ni.com/training
Exercise 2-5
Simple Acquire, Analyze, and Present VI
DISCUSSION
Summary—Quiz
1. Which function executes first:
Add or Subtract?
a) Add
b) Subtract
c) Unknown
ni.com/training
Summary—Quiz Answer
1. Which function executes first:
Add or Subtract?
a) Add
b) Subtract
c) Unknown
ni.com/training
Summary—Quiz
2. Which function executes first:
Sine or Divide?
a) Sine
b) Divide
c) Unknown
ni.com/training
Summary—Quiz Answer
2. Which function executes first:
Sine or Divide?
a) Sine
b) Divide
c) Unknown
ni.com/training
Summary—Quiz
3. Which of the following
functions executes first:
Random Number, Add or
Divide?
a) Random Number
b) Divide
c) Add
d) Unknown
ni.com/training
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
ni.com/training
Summary—Quiz
4. Which of the following
functions execute last:
Random Number, Subtract or
Add?
a) Random Number
b) Subtract
c) Add
d) Unknown
ni.com/training
Summary—Quiz Answer
4. Which of the following
functions execute last:
Random Number, Subtract or
Add?
a) Random Number
b) Subtract
c) Add
d) Unknown
ni.com/training
Summary—Quiz
ni.com/training
Summary—Quiz Answer
ni.com/training
Lesson 3
Troubleshooting and Debugging VIs
TOPICS
A. LabVIEW Help Utilities
B. Correcting Broken VIs
C. Debugging Techniques
D. Undefined or Unexpected Data
E. Error Checking and Error Handling
ni.com/training
A. LabVIEW Help Utilities – Context Help
ni.com/training
A. LabVIEW Help Utilities – LabVIEW Help
• Detailed descriptions of most palettes, menus, tools, VIs,
and functions and instructions for using LabVIEW features
• Accessing the LabVIEW Help:
− Select Help»Search the LabVIEW Help
− Use the Detailed help
link or button in the
Context Help window
− Right-click an object
and select Help from
the shortcut menu
ni.com/training
A. LabVIEW Help Utilities – NI Example Finder
ni.com/training
Exercise 3-1
Concept: Using Help
HOMEWORK
Become familiar with using the Context Help window, the
LabVIEW Help, and the NI Example Finder.
GOAL
Exercise 3-1
Concept: Using Help
DISCUSSION
B. Correcting Broken VIs
ni.com/training
B. Correcting Broken VIs
Common Issues
• Broken wire
− You wired a Boolean control
to a String indicator
− You wired a Numeric control
to a Numeric control
• A required block diagram terminal is unwired
• A subVI is broken or you edited its connector pane after you
placed its icon on the block diagram of the VI
ni.com/training
C. Debugging Techniques
ni.com/training
C. Debugging Techniques –
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
C. Debugging Techniques – Single Stepping
ni.com/training
C. Debugging Techniques – Probes
ni.com/training
C. Debugging Techniques – Breakpoints
ni.com/training
D. Undefined or Unexpected Data
• ∞ (Inf)
− Infinity
− Divided a number by zero?
• NaN
− Not a number
− Produced by invalid operations, such as taking the square root
of a negative number
• Check for unexpected Inf values or NaN values in your
mathematical operations
ni.com/training
E. Error Checking and Error Handling
ni.com/training
E. Error Checking and Error Handling – Automatic
Error Handling
• LabVIEW automatically handles any known error when a VI
runs by:
− suspending execution,
− highlighting the subVI or function where the error occurred,
− and displaying the Error dialog box
• Select File»VI Properties and select Execution from the
Category pull-down menu to disable automatic error
handling for a specific VI
ni.com/training
E. Error Checking and Error Handling – Manual Error
Handling
• To disable automatic error handling for a subVI or function,
wire its error out cluster to the error in cluster of another
subVI or function or to an error out indicator
• Use the LabVIEW error handling VIs,
functions, and parameters
to manage errors
ni.com/training
E. Error Checking and Error Handling – Error Clusters
ni.com/training
Exercise 3-2
Concept: Debugging
DISCUSSION
Summary—Quiz
ni.com/training
Summary—Quiz Answer
ni.com/training
Summary—Quiz
ni.com/training
Summary—Quiz Answer
ni.com/training
Lesson 4
Implementing a VI
TOPICS
A. Front Panel Design G. Iterative Data Transfer
B. LabVIEW Data Types H. Plotting Data
C. Documenting Code I. Case Structures
D. While Loops
E. For Loops
F. Timing a VI
ni.com/training
A. Front Panel Design
• Inputs and outputs lead to front panel design
• Retrieve the inputs by the following methods:
− Acquiring from a device
− Reading directly from a file
− Manipulating controls
• Output data by the following methods:
− Displaying with indicators
− Logging to a file
− Outputting to a device
ni.com/training
A. Front Panel Design – Labels/Captions
ni.com/training
A. Front Panel Design – Color Tips
ni.com/training
A. Front Panel Design – Spacing
ni.com/training
A. Front Panel Design – Text & Fonts
Bad Example
ni.com/training
A. Front Panel Design – Tab Controls
Use tab controls to
overlap front panel
controls and indicators
in a smaller area
ni.com/training
A. Front Panel Design – Decorations
• Use decorations to visually
group or separate objects on
a front panel with boxes, lines,
or arrows
• These objects are for
decoration only
ni.com/training
B. LabVIEW Data Types – Terminals
ni.com/training
B. LabVIEW Data Types – Numerics
ni.com/training
B. LabVIEW Data Types – Boolean
ni.com/training
Mechanical Action of Booleans
DEMONSTRATION
B. Data Types – String
• A sequence of displayable or non-displayable
ASCII characters
• On the front panel, strings appear as tables,
text entry boxes, and labels
• Change the display type from the short-cut
menu: Normal, ‘\’ Codes, Password and Hex
• Edit and manipulate strings with the String functions on the
block diagram
• In LabVIEW, the string data type is represented with the
color pink
ni.com/training
B. Data Types – Enum
An enum
represents a
pair of values,
a string and a
numeric, where the
enum can be one
of a defined list of
values
ni.com/training
B. Data Types – Enum
• Enum: enumerated
control, constant, or
indicator
• Enums are useful because it is easier
to manipulate numbers than strings
on the block diagram
ni.com/training
B. Data Types – Dynamic
ni.com/training
C. Documenting Code – Front Panels
• Tip Strips
• Descriptions
• VI Properties
• Good Design
ni.com/training
C. Documenting Code – Naming
ni.com/training
C. Documenting Code – Block Diagram
ni.com/training
Configuring Your LabVIEW Environment
ni.com/training
Configuring Your LabVIEW Environment
• Functions Palette
− Tack the Functions palette and select View»Change Visible
Categories then click Select All
• Controls Palette
− Tack the Controls palette and select View»Change Visible
Categories then click Select All
ni.com/training
Exercise 4-1
Determine Warnings VI
HOMEWORK
Create and document a VI.
GOAL
Exercise 4-1
Determine Warnings VI
• What happens if the Max. Temp value is lower than the Min.
Temp value?
DISCUSSION
D. While Loops
Repeat (code);
Until Condition met;
End;
ni.com/training
D. While Loops
ni.com/training
D. While Loops – Tunnels
• Tunnels transfer data into and out of structures
• The tunnel adopts the color of the data type wired to the
tunnel
• 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
ni.com/training
D. While Loops - Error Checking and Error Handling
ni.com/training
Exercise 4-2
Auto Match VI
DISCUSSION
E. For Loops
N=100;
i=0;
Until i=N:
Repeat (code;i=i+1);
End;
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
E. For Loops – Conditional Terminal
ni.com/training
E. For Loops – Conditional Terminal
ni.com/training
E. For Loop/While Loop Comparison
• Executes a set number of times unless • Stops executing only if the value at the
a conditional terminal is added conditional terminal meets the
• Can execute zero times condition
• Tunnels automatically output an array • Must execute at least once
of data • Tunnels automatically output the last
value
ni.com/training
E. For Loops – Numeric Conversion
• The number of iterations a For Loop executes must be specified in
nonnegative integers
• If you wire a double-precision, floating-point numeric value to the
count terminal, LabVIEW converts the larger numeric value to a 32-bit
signed integer
ni.com/training
E. For Loops – Numeric Conversion
ni.com/training
E. For Loops – Numeric Conversion
ni.com/training
Exercise 4-3
Concept: While Loops versus For Loops
HOMEWORK
Understand when to use a While Loop and when to use a For
Loop.
GOAL
F. Timing a VI
ni.com/training
F. Timing a VI – Wait Functions
ni.com/training
F. Timing a VI – Elapsed Time Express VI
ni.com/training
Wait Chart VI
DEMONSTRATION
G. Iterative Data Transfer
ni.com/training
G. Iterative Data Transfer – 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
G. Iterative Data Transfer – Initializing
Run once VI finishes Run again
Not
Initialized Output = 4 Output = 8
Shift
Register
ni.com/training
G. Iterative Data Transfer –
Stacked Shift Registers
• 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
ni.com/training
Exercise 4-4
Average Temperature VI
HOMEWORK
Use a For Loop and shift registers to average data.
GOAL
Exercise 4-4
Average Temperature VI
DISCUSSION
H. Plotting Data – Waveform Chart
ni.com/training
H. Plotting Data – Chart Update Modes
ni.com/training
H. Plotting Data
ni.com/training
H. Plotting Data – Waveform Graphs
ni.com/training
Exercise 4-5
Temperature Multiplot VI
DISCUSSION
I. Case Structures
• Have two or more subdiagrams or cases
• Execute and displays only one case at a time
• An input value determines which subdiagram to execute
• Similar to case statements or if...then...else
statements in text-based programming languages
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
I. Case Structures – Default Case
• You can specify a default case
for the Case structure
− If you specified cases for 1, 2,
and 3, but you get an input of
4, the Case structure executes
the default case
• Right-click the Case structure
border to add, duplicate,
remove, or rearrange cases
and to select a default case
ni.com/training
I. Case Structures – Input & Output Tunnels
ni.com/training
I. Case Structures – Use Default if Unwired
Numeric 0
Boolean FALSE
String Empty
ni.com/training
I. Case Structures – Boolean
ni.com/training
I. Case Structures – Integer
ni.com/training
I. Case Structures – String
ni.com/training
I. Case Structures – Enum
• Gives users a list of items from which to select
• The case selector displays a case for each item in the
enumerated type control
ni.com/training
I. Case Structures - Error Checking and Error
Handling
Use Case Structures inside VIs to execute the code if there
is no error and skip the code if there is an error
ni.com/training
Exercise 4-6
Determine Warnings VI
• What happens if all the values are 10? How could you fix
this?
DISCUSSION
Summary—Quiz
ni.com/training
Summary—Quiz Answer
ni.com/training
Summary—Quiz
ni.com/training
Summary—Quiz Answer
ni.com/training
Summary—Quiz
ni.com/training
Summary—Quiz Answer
ni.com/training
Summary—Quiz
ni.com/training
Summary—Quiz Answer
ni.com/training
Lesson 5
Relating Data
TOPICS
A. Arrays
B. Clusters
C. Type Definitions
ni.com/training
A. Arrays
ni.com/training
A. Arrays
ni.com/training
A. Arrays – Creating
ni.com/training
A. Arrays – 2D Array
ni.com/training
A. Arrays – Initializing
ni.com/training
A. Arrays – Creating Constants
ni.com/training
A. Arrays – Auto-indexing
ni.com/training
A. Arrays – Auto-indexing Input
ni.com/training
A. Arrays – Auto-indexing Input
ni.com/training
A. Arrays – Auto-indexing Output
ni.com/training
A. Arrays – Creating 2D Arrays
You can use two For Loops, one inside the other, to create a
2D array
ni.com/training
Exercise 5-1
Concept: Manipulating Arrays
DISCUSSION
B. Clusters
ni.com/training
B. Clusters – Array vs Cluster
ni.com/training
B. Clusters – Creating
ni.com/training
B. Clusters – Constants
ni.com/training
B. Clusters – Order
ni.com/training
B. Clusters – Assembling a Cluster
ni.com/training
B. Clusters – Modifying a Cluster
ni.com/training
B. Clusters – Disassembling a Cluster
ni.com/training
B. Clusters – Error Clusters
ni.com/training
Exercise 5-2
Concept: Clusters
DISCUSSION
C. Type Definitions – Custom Controls
ni.com/training
C. Type Definitions – Control Editor
ni.com/training
C. Type Definitions
ni.com/training
C. Type Definitions – Control Type
Control
• No connection between the custom control or indicator you
saved and the instance of the custom control or indicator in
the VI
• Update the file, but the
instances are not updated
ni.com/training
C. Type Definitions – Type Definition
Type Definition (type def):
• Edit the saved file, and have all instances update with the
changes made
• Forces the data type of each instance to be identical
• Example:
− Add an item to the type definition of an
enum, the instances of the enum
update with the new item
− If you resize the enum front panel
control type definition, the instances
of the enum do not resize
ni.com/training
C. Type Definitions – Strict Type Definition
ni.com/training
Exercise 5-3
Concept: Type Definition
• If you only edit the color of Strict Type Def Numeric.ctl in the
Control Editor, would all the instances of the control change
color?
• If you only edit the color of Type Def Numeric.ctl in the Control
Editor, would all the instances of the control change color?
DISCUSSION
Summary—Quiz
ni.com/training
Summary—Quiz Answer
ni.com/training
Summary—Quiz
ni.com/training
Summary—Quiz Answer
ni.com/training
Summary—Quiz
ni.com/training
Summary—Quiz Answer
ni.com/training
Summary—Quiz
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
Summary—Quiz 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 6
Managing Resources
TOPICS
A. Understanding File I/O D. DAQ Programming
B. Understanding High-level E. Instrument Control
File I/O Programming
C. Understanding Low-level F. Using Instrument Drivers
File I/O
ni.com/training
A. Understanding File I/O
Open/ Read
Close Check for
Create/ and/or
File Errors
Replace File Write to File
ni.com/training
A. Understanding File I/O – File Formats
ni.com/training
A. Understanding File I/O – File Formats
ni.com/training
B. Understanding High-level File I/O
• High-level VIs
− 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 VIs
− Individual VI for each step
− If you are writing to a file in a loop, use
low-level file I/O functions
ni.com/training
B. Understanding 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
ni.com/training
Exercise 6-1
Spreadsheet Example VI
ni.com/training
Exercise 6-2
Temperature Log VI
DISCUSSION
D. DAQ Programming
1. Signal
2. Terminal Block
3. Cable
4. DAQ Device
5. Computer
ni.com/training
D. 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
ni.com/training
D. DAQ Programming – Basic Flow
Acquire or
Create Configure Start Clear
Generate
Task Task Task Task
Data
ni.com/training
D. DAQ Programming – Create Task
ni.com/training
D. DAQ Programming – Configure Task
ni.com/training
D. DAQ Programming – Start Task
ni.com/training
D. DAQ Programming – Acquire or Generate Data
ni.com/training
D. DAQ Programming – Clear Task
ni.com/training
D. DAQ Programming – Example
ni.com/training
E. Instrument Control Programming
ni.com/training
VISA
ni.com/training
VISA – Programming Terminology
• Resource
Any instrument in the system, including serial and parallel ports
• Session
When you open a session to a resource, LabVIEW returns a VISA
session number, which is a unique refnum to that instrument
• 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
ni.com/training
VISA Programming
ni.com/training
VISA Open Function
ni.com/training
VISA I/O Functions
ni.com/training
VISA Close Function
ni.com/training
VISA Write and Read Example
ni.com/training
VISA – Serial
ni.com/training
F. Using Instrument Drivers
ni.com/training
Using Instrument Drivers
ni.com/training
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
− Connects you with ni.com to find instrument drivers
• When you install an instrument driver
− An example program using the driver is added to the NI Example
Finder
− Instrument driver VIs are added to the Instrument I/O»Instrument
Drivers palette in the Functions palette
ni.com/training
Using Instrument Drivers – Example
ni.com/training
Exercise 6-3
Using DAQmx (DAQ)
or
Exercise 6-4
NI Devsim VI(GPIB/serial)
HOMEWORK
6-3: Explore a DAQmx example program that continuously
acquires data, and modify it to wait on a digital trigger
6-4: Install an instrument driver and explore the example programs
that accompany the instrument driver
GOAL
Exercise 6-3
Using DAQmx (DAQ)
or
Exercise 6-4
NI Devsim VI(GPIB/serial)
• In Exercise 6-3, what types of VIs did you use outside of the
While Loop?
• In Exercise 6-4, how would modify the example programs if
you wanted to continuously acquire data?
DISCUSSION
Summary—Quiz
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
Summary—Quiz 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
Summary—Quiz
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
Summary—Quiz 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
Summary—Quiz
3. Which of the following conveys the basic DAQmx programming
flow?
a) Create Task»Configure Task»Acquire/Generate Data»Start Task
b) Acquire/Generate Data»Start Task»Clear Task
c) Start Task»Create Task»Configure Task»Acquire/Generate
Data»Clear Task
d) Create Task»Configure Task»Start Task»Acquire/Generate
Data»Clear Task
ni.com/training
Summary—Quiz Answer
3. Which of the following conveys the basic DAQmx programming
flow?
a) Create Task»Configure Task»Acquire/Generate Data»Start Task
b) Acquire/Generate Data»Start Task»Clear Task
c) Start Task»Create Task»Configure Task»Acquire/Generate
Data»Clear Task
d) Create Task»Configure Task»Start Task»Acquire/Generate
Data»Clear Task
ni.com/training
Summary—Quiz
4. VISA is a high-level API that calls low-level drivers.
a) True
b) False
ni.com/training
Summary—Quiz 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
ni.com/training
A. Understanding Modularity – SubVIs
ni.com/training
A. Understanding Modularity – SubVIs
ni.com/training
A. Understanding Modularity – SubVIs
ni.com/training
A. Understanding Modularity – SubVIs
Function Code Calling Program Code
function average (in1, in2, main
out) {
{ average (point1, point2,
out = (in1 + in2)/2.0; pointavg)
} }
ni.com/training
B. Icon and Connector Pane
• After you build a VI, build the icon and the connector pane
so you can use the VI as a subVI
• The icon and connector pane correspond to the function
prototype in text-based programming languages
• Every VI displays an icon in the upper-right corner of the
front panel and block diagram windows
• An icon is a graphical representation of a VI
• If you use a VI as a subVI, the icon identifies the subVI on
the block diagram of the VI
ni.com/training
B. Icon and Connector Pane – Good VI Icon
ni.com/training
B. Icon and Connector Pane – Create Icon
ni.com/training
B. Icon and Connector Pane – Create Icon
ni.com/training
B. Icon and Connector Pane – Create Icon
• Use the Glyphs tab to display glyphs you can include in the icon
• Select Tools»Synchronize with ni.com Icon Library to update
ni.com/training
B. Icon and Connector Pane – Create Icon
• Use the Icon Text tab to specify the text to display in the icon
ni.com/training
B. Icon and Connector Pane – Create Icon
• Use the Templates tab to display icon templates you can use as
a background for the icon
ni.com/training
B. Icon and Connector Pane – Setting up the
Connector Pane
• Right-click the icon in the upper
right corner of the front panel
and select Show Connector
− Each rectangle on the connector
pane represents a terminal
− Use the terminals to assign inputs
and outputs
• Select a different pattern by
right-clicking the connector pane
and selecting Patterns from the
shortcut menu
ni.com/training
B. Icon and Connector Pane – Standards
ni.com/training
C. Using SubVIs
ni.com/training
C. Using SubVIs – Terminal Setting
• Bold: Required terminal
• Plain: Recommended
terminals
• Dimmed: Optional terminals
ni.com/training
C. Using SubVIs – Handling Errors
ni.com/training
C. Using SubVIs – Handling Errors
ni.com/training
C. Using SubVIs – Section to SubVI
ni.com/training
Exercise 7-1
Determine Warnings VI
Create the icon and connector pane for a VI so you can use
the VI as a subVI.
GOAL
Exercise 7-1
Determine Warnings VI
DISCUSSION
Summary—Quiz
ni.com/training
Summary—Quiz Answer
ni.com/training
Summary—Quiz
ni.com/training
Summary—Quiz Answer
ni.com/training
Lesson 8
Common Design Techniques and Patterns
TOPICS
A. Using Sequential Programming
B. State Programming
C. State Machines
ni.com/training
A. Using Sequential Programming
• Many of the VIs you write accomplish sequential tasks
• There is nothing in this block diagram to force the
execution order of these tasks - any one of these tasks
could happen first
ni.com/training
A. Using Sequential Programming
ni.com/training
A. Using Sequential Programming
To force execution order, use a Sequence structure
• A structure with frames, where each frame executes in order
• The second frame cannot begin execution until everything in the first
frame completes execution
ni.com/training
A. Using Sequential Programming
ni.com/training
A. Using Sequential Programming
ni.com/training
B. Using State Programming
ni.com/training
B. Using State Programming –
State Transition Diagram
Type of flowchart that indicates the states of a program and
transitions between states
ni.com/training
B. Using State Programming –
State Transition Diagram
Furnace
Example:
ni.com/training
C. State Machines
ni.com/training
C. State Machines – Infrastructure
While Loop
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
Course Project
DEMONSTRATION
Exercise 8-1
State Machine VI
DISCUSSION
Summary—Quiz
1. When using a Sequence structure, you can stop the execution
part way through a sequence.
a) True
b) False
ni.com/training
Summary—Quiz Answer
1. When using a Sequence structure, you can stop the execution
part way through a sequence.
a) True
b) False
ni.com/training
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
ni.com/training
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
ni.com/training
Lesson 9
Using Variables
TOPICS
A. Parallelism
B. Variables
C. Functional Global Variables
D. Race Conditions
ni.com/training
A. Parallelism
ni.com/training
A. Parallelism
ni.com/training
A. Parallelism
ni.com/training
A. Parallelism
ni.com/training
B. Variables
ni.com/training
B. Variables
ni.com/training
Creating Local Variables
DEMONSTRATION
B. Variables
ni.com/training
Exercise 9-1
Local Variable VI
DISCUSSION
B. Variables – Using Between VIs
ni.com/training
Creating Global Variables
DEMONSTRATION
B. Variables – Using Between VIs
ni.com/training
B. Variables – Creating Shared Variables
• You must have a project open to
create a shared variable
• Variable configuration data is
stored in Project Libraries
• LabVIEW will automatically
create a library if the variable
was not created from an existing
library
ni.com/training
Shared Variables – Configuration Options
ni.com/training
Creating Shared Variables
DEMONSTRATION
B. Variables – Using Carefully
ni.com/training
B. Variables – Using Carefully
ni.com/training
B. Variables – Initializing
ni.com/training
B. Variables – Initializing
ni.com/training
C. Functional Global Variables
The general form of a functional global variable includes
an uninitialized shift register (1) with a single iteration For
or While Loop
ni.com/training
C. Functional Global Variables
• A functional global variable usually has an action input
parameter that specifies which task the VI performs
• The VI uses an uninitialized shift register in a While
Loop to hold the result of the operation
ni.com/training
C. Functional Global Variables – Timing
Very useful for performing customized elapsed time
measurements
ni.com/training
Functional Global Variables
DEMONSTRATION
Exercise 9-2
Global Data Project
DISCUSSION
D. Race Conditions
ni.com/training
Race Conditions
DEMONSTRATION
D. Race Conditions
ni.com/training
D. Race Conditions – Shared Resources
ni.com/training
D. Race Conditions – Critical Code
• A critical section of code is code that may behave
inconsistently if some shared resource is altered while it is
running
• If one loop interrupts another loop while it is executing
critical code, then a race condition can occur
• Eliminate race conditions by identifying and protecting
critical code with:
− Functional Global Variables
− Semaphores
ni.com/training
D. Race Conditions – Critical Code
ni.com/training
D. Race Conditions – Critical Code
Functional Global Variable used
to protect critical code:
ni.com/training
D. Race Conditions – Critical Code
ni.com/training
D. Race Conditions – Sequencing
ni.com/training
Exercise 9-3
Bank VI
HOMEWORK
Eliminate a race condition by protecting a critical section of
code.
GOAL
Exercise 9-3
Bank VI
DISCUSSION
Summary—Quiz
1. You should use variables in your VI whenever possible.
a) True
b) False
ni.com/training
Summary—Quiz Answer
1. You should use variables in your VI whenever possible.
a) True
b) False
ni.com/training
Summary—Quiz
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
Summary—Quiz 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
Summary—Quiz
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
Summary—Quiz 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
Summary—Quiz
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
Summary—Quiz 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
Continuing Your LabVIEW Education
ni.com/training
Continue Your Learning
• ni.com/support
− Access product manuals, KnowledgeBase, example code,
tutorials, application notes, and discussion forums
− Request technical support
• Info-LabVIEW: www.info-labview.org
• Alliance Program: ni.com/alliance
• Publications: ni.com/reference/books/
• Practice!
ni.com/training
Courses
New User Experienced User Advanced User
ni.com/training
Please complete the course survey.
Thank you!
ni.com/training