You are on page 1of 375

Online LabVIEW Core 1

ni.com/training
What You Need To Get Started

• LabVIEW Core 1 Course Manual


• LabVIEW Core 1 Exercise Manual
• LabVIEW Core 1 Course CD
• Multifunction DAQ device
• GPIB interface
• DAQ Signal Accessory, wires, and cable
• NI Instrument Simulator and power supply
• Serial and GPIB cables
Computer running
LabVIEW 2009 or later
and Windows 2000 or later

ni.com/training
File Locations

The course installer places the course files in the following


location:

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

LabVIEW Core 1 LabVIEW Core 3


Managing Software
LabVIEW Core 2 Engineering in LabVIEW
Skills learned:
• Modular application LabVIEW OOP System Design
Skills learned:
• LabVIEW environment development Advanced Architectures in
navigation • Structured design and LabVIEW
• Dataflow programming development practices
Skills learned:
• Use of common design • Inter-application • Manage a LabVIEW project from
techniques communication and design to deployment
connectivity techniques • Object-oriented programming for
• Event driven programming LabVIEW
• Programmatic UI control • Develop scalable applications and
reusable code
Certifications • Advanced design patterns for LabVIEW

Certified LV Associate Certified LabVIEW Certified LabVIEW


Developer Exam Developer Exam Architect Exam
Skills tested: Skills tested: Skills tested:
• LabVIEW environment • LabVIEW application • LabVIEW application
knowledge development expertise development mastery

ni.com/training
Course Learning Map

ni.com/training
Course Goals

This course prepares you for the following:


• Solve problems using LabVIEW
• Use data acquisition and instrument control in LabVIEW
applications
• Use modular programming practices
• Develop, debug, and test LabVIEW VIs
• Effectively use a state machine architecture
• Parallelism and variables

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

• 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. Signal
2. Terminal Block
3. Cable
4. DAQ Device
5. Computer

ni.com/training
DAQ Hardware – Terminal Block & Cable

DAQ Signal Accessory—terminal block used in this course

ni.com/training
DAQ Hardware – DAQ Device

• Most DAQ devices have four standard elements: analog


input, analog output, digital I/O, and counters
• You can transfer the signal you measure with the DAQ
device to the computer through a variety of different bus
structures

ni.com/training
DAQ Hardware – Analog Input

The process of measuring an analog signal and transferring


the measurement to a computer for analysis, display, or
storage
• An analog signal is a signal that varies continuously
• Analog input most commonly measures voltage or current

ni.com/training
DAQ Hardware – Analog Output

The process of generating analog signals from your computer


• Performing digital-to-analog (D/A)
conversions generates analog output
• The available analog output types
are voltage and current
• To perform a voltage or current
output, a compatible device must be
installed that can generate that
type of signal

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

• A counter is a digital timing device typically used for event


counting, frequency measurement, period measurement,
position measurement, and pulse generation
• A counter has a fixed number it can count to as determined
by the resolution of the counter
• For example, a 24-bit counter
can count to:
2(Counter Resolution) – 1 = 224 – 1 = 16,777,215

ni.com/training
B. Using DAQ Software – Configuration

• Configure and test your DAQ device using the Measurement


& Automation Explorer (MAX)

ni.com/training
Simulating a DAQ Device

• Using NI-DAQmx simulated devices, you can try NI products


in your application without the hardware
• With NI-DAQmx simulated devices, you also can export a
physical device configuration onto a system that does not
have the physical device installed

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

• What is a possible real-world application using DAQ?

DISCUSSION
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
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

• Interface Drivers: Instrument interfaces such as GPIB


include a set of drivers for the interface
• Configuration: Use MAX to configure the interface

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

• What is a possible real-world application using instrument


control?

DISCUSSION
Summary—Quiz

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
Summary—Quiz 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
Summary—Quiz

2. Which of the following are benefits of instrument control?


a) Automate processes
b) Save time
c) One platform for multiple tasks
d) Limited to only one type of instrument

ni.com/training
Summary—Quiz Answers

2. Which of the following are benefits of instrument control?


a) Automate processes
b) Save time
c) One platform for multiple tasks
d) Limited to only one type of instrument

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)

The appearance and operation of VIs imitate physical instruments, such


as oscilloscopes and digital multimeters.

ni.com/training
B. Parts of a VI

LabVIEW VIs contain three main components:


1. Front Panel 2. Block Diagram 3. Icon/Connector Pane

ni.com/training
B. Parts of a VI – Front Panel

You build the front panel


with controls (inputs) and
indicators (outputs)

ni.com/training
B. Parts of a VI – Block Diagram

Front panel objects


appear as terminals on
the 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

Demonstrate using the Getting Started dialog box and the


New dialog box to start 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

Demonstrate creating a project, adding files, and removing


files.

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

The numeric data type can represent numbers of various


types, such as integer or real

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

• 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. 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

• Select multiple objects to simultaneously configure shared


properties

ni.com/training
F. Block Diagram

Block diagram objects include the


following:
• Terminals
• SubVIs
• Functions
• Constants
• Structures
• Wires

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

• Objects on the block diagram that have inputs and/or


outputs and perform operations when a VI runs
• Analogous to statements, operators, functions, and
subroutines in text-based programming languages
• Nodes can be functions, subVIs, or structures
Nodes

ni.com/training
F. Block Diagram – Function Nodes

• Fundamental operating elements of LabVIEW


• Do not have front panels or block diagrams, but do have
connector panes
• Double-clicking a function only selects the function – does
not open it like a VI
• Has a pale yellow background on its icon

ni.com/training
F. Block Diagram – SubVI Nodes

• SubVI: VIs that you build to use inside of another VI


• Any VI has the potential to be used as a subVI
• When you double-click a subVI on the block diagram, you
can view the front panel and block diagram of the subVI
− The upper right corner of the front panel and block diagram
displays the icon for the current VI
− This is the icon that appears when you place the VI on a block
diagram as a subVI

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

• Transfer data between block diagram objects through wires


• 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

DBL Numeric Integer Numeric String


Scalar
1D Array
2D Array

ni.com/training
F. Block Diagram – Wiring Tips

• Press <Ctrl>-B to delete all broken wires


• Right-click and select Clean Up Wire to reroute the wire

ni.com/training
F. Block Diagram – Wiring Tips

Use the Clean Up Diagram tool to reroute multiple wires and


objects to improve readability
1. Select a section of your block diagram
2. Click the Clean Up Diagram button on the block diagram
toolbar

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

• What are constants and when should you use them?


• What are free labels and when should you use them?

DISCUSSION
G. Searching for Controls, VIs & Functions

Find controls, functions, and VIs using the Search button on


the Controls and Functions palette.

ni.com/training
Exercise 2-2
Concept: Navigating Palettes

Learn to use the palettes and search for controls, functions


and VIs.
GOAL
Exercise 2-2
Concept: Navigating Palettes

• Why would you want to add a function to the Favorites


category in the Functions palette?

DISCUSSION
H. Selecting A Tool

• Create, modify, and debug VIs


using the tools provided by LabVIEW
• A tool is a special operating mode of the
mouse cursor
• The operating mode of the cursor corresponds to the icon of
the tool selected
• When using the Automatic Tool Selection, LabVIEW
chooses which tool to select based on the current location of
the mouse

ni.com/training
Exercise 2-3
Concept: Selecting A Tool

Gain experience using the Automatic Tool Selection to select


which tool to use.
GOAL
Exercise 2-3
Concept: Selecting A Tool

• How do you enable automatic tool selection?

DISCUSSION
I. Dataflow

LabVIEW follows a dataflow model for running VIs


• A node executes only when data are available at all of its
input terminals
• A node supplies data to the output terminals only when the
node finishes execution

ni.com/training
I. Dataflow – Quiz

Which node executes first?


a) Add
b) Subtract
c) Random Number
d) Divide
e) Sine

ni.com/training
I. Dataflow – Quiz Answers

NO CORRECT ANSWER

Which node executes first?


a) Add – possibly
b) Subtract – definitely not
c) Random Number – possibly
d) Divide – possibly
e) Sine – definitely not

ni.com/training
Exercise 2-4
Concept: Dataflow

Understand how dataflow determines the execution order in a


VI.
GOAL
Exercise 2-4
Concept: Dataflow

• Should a well-designed block diagram flow in a particular


direction?

DISCUSSION
J. Building a Simple VI

ni.com/training
J. Building a Simple VI – Acquire

Acquire Express VIs:

• DAQ Assistant Express VI

• Instrument I/O Assistant Express VI

• Simulate Signal Express VI

• Read from Measurement File Express VI

ni.com/training
J. Building a Simple VI – Analyze

Analyze Express VIs:

• Amplitude and Level Measurements Express VI

• Statistics Express VI

• Spectral Measurements Express VI

• Tone Measurements Express VI

• Filter Express VI

ni.com/training
J. Building a Simple VI – Present

• Present tasks are Express VIs that perform a function or


indicators that present data on the front panel of the VI
• Indicators include the Waveform Chart, the Waveform
Graph, and the XY Graph
• Express VIs include the Write to Measurement File Express
VI, Build Text Express VI, DAQ Assistant Express VI, and
the Instrument I/O Assistant Express VI

ni.com/training
J. Building A Simple VI – Running

1. Place Express VI on the block diagram


2. Configure the dialog box that opens
3. Wire Express VIs together
4. Save and run the VI

The Run button appears broken when the VI you


are creating or editing contains errors

ni.com/training
Exercise 2-5
Simple Acquire, Analyze, and Present VI

Create a simple VI that acquires data, analyzes data, and


presents the results.
GOAL
Exercise 2-5
Simple Acquire, Analyze, and Present VI

• How do you determine the file path of the generated text


file?

DISCUSSION
Summary—Quiz
1. Which function executes first:
Add or Subtract?
a) Add
b) Subtract
c) Unknown

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

5. What are the three parts of a VI?


a) Front Panel
b) Block Diagram
c) Project
d) Icon/Connector Pane

ni.com/training
Summary—Quiz 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 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

• Displays basic information about LabVIEW objects when


you move the cursor over each object
• Select Help»Show
Context Help, press
<Ctrl-H> or
click the Show Context
Help Window button
on the toolbar

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

• You are given a VI containing unfamiliar functions. How do


you determine the functionality in the block diagram?

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

Your VI isn’t broken, but you are getting unexpected data or


behavior
• Any unwired or hidden subVIs?
• Incorrect default data being used?
• Undefined data being passed?
• Numeric representation correct?
• Node execution order correct?

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

Single-step through the VI to view each action of the VI on the


block diagram
Suspend the execution of a subVI to edit values of controls
and indicators, to control the number of times it runs, or to go
back to the beginning of the execution of the subVI
• Open subVI and select Operate»Suspend When Called from
the shortcut menu

ni.com/training
C. Debugging Techniques – Probes

• Use the Probe tool to observe intermediate data


values and to check the error output of VIs
and functions, especially those performing I/O
• Retain the values in the wires so that you can
probe wires for data after execution has finished

ni.com/training
C. Debugging Techniques – 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
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

• No matter how confident you are in the VI you create, 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 checking tells you why and where errors occur
− Automatic error handling
− Manual 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

• 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
Exercise 3-2
Concept: Debugging

Use the debugging tools built into LabVIEW.


GOAL
Exercise 3-2
Concept: Debugging

• If you have a VI with a broken Run arrow, what should you


do first?
• After you fixed your broken Run arrow, your VI results show
unexpected data. What can you do next?

DISCUSSION
Summary—Quiz

1. How do you disable automatic error handling?


a) Enable execution highlighting
b) Wire the error out cluster of a subVI to the error in
cluster of another subVI
c) Place a checkmark in the Show Warnings checkbox of
the Error List dialog box

ni.com/training
Summary—Quiz Answer

1. How do you disable automatic error handling?


a) Enable execution highlighting
b) Wire the error out cluster of a subVI to the error in
cluster of another subVI
c) Place a checkmark in the Show Warnings checkbox of
the Error List dialog box

ni.com/training
Summary—Quiz

2. Which of the following are the contents of the error cluster?


a) Status: Boolean
b) Error: String
c) Code: 32-bit integer
d) Source: String

ni.com/training
Summary—Quiz Answer

2. Which of the following are the contents of the error cluster?


a) Status: Boolean
b) Error: String
c) Code: 32-bit integer
d) Source: String

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

• Labels – short descriptions


• Captions – long descriptions
• Captions do not appear on block diagram

ni.com/training
A. Front Panel Design – Color Tips

Start with a gray scheme


• Select one or two shades of gray
• Add highlight colors sparingly for important settings—on
plots, abort buttons, and the slider thumbs

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

Terminals visually communicate information about the data


type represented

ni.com/training
B. LabVIEW Data Types – Numerics

• The numeric data type represents


numbers of various types
• To change the representation
of a numeric, right-click the
control, indicator, or constant,
and select Representation
from the shortcut menu

ni.com/training
B. LabVIEW Data Types – Boolean

• Behavior of Boolean controls is specified by the mechanical


action
• In LabVIEW, the Boolean
data type is represented
with the color green

ni.com/training
Mechanical Action of Booleans

Use the Mechanical Action of Booleans VI located in the NI


Example Finder to learn about the different switch and latch
actions.

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

• Stores the information generated or acquired by an Express


VI
• Non-Express VIs do not accept the dynamic data type
− To use a built-in VI or function to analyze or process the
dynamic data type, you must convert the data type
− Numeric, waveform, or Boolean data indicators or inputs
automatically convert the dynamic data type when wired
• In LabVIEW, the dynamic data type is represented with the
color dark blue

ni.com/training
C. Documenting Code – Front Panels

• Tip Strips
• Descriptions
• VI Properties
• Good Design

ni.com/training
C. Documenting Code – Naming

Giving controls and indicators logical and descriptive names


adds usability to front panels

ni.com/training
C. Documenting Code – Block Diagram

• Use block diagram comments to:


− Describe algorithms
− Explain the data contents of wires
• Use the Labeling tool or place a
free label from the Functions
palette

ni.com/training
Configuring Your LabVIEW Environment

• Options Dialog Box


− Controls/Functions Palettes page
• Select Load palettes during launch to make Search Palettes
immediately usable after launch
• Set Palette to Category (Icons and Text)
− Block Diagram page
• Uncheck Place front panel terminals as icons to place control and
indicator terminals in a compact format
• Configure Block Diagram Cleanup to customize your block
diagram

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;

LabVIEW While Loop Flowchart Pseudo Code

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
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

Use an error cluster in a While Loop to stop the While Loop if


an error occurs

ni.com/training
Exercise 4-2
Auto Match VI

Use a While Loop and an iteration terminal and pass data


through a tunnel.
GOAL
Exercise 4-2
Auto Match VI

• How many times is the # of iterations indicator updated?


Why?

DISCUSSION
E. For Loops

N=100;
i=0;
Until i=N:
Repeat (code;i=i+1);
End;

LabVIEW For Loop 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
E. For Loops – Conditional Terminal

You can add a conditional terminal to configure a For Loop to


stop when a Boolean condition or an error occurs

ni.com/training
E. For Loops – Conditional Terminal

For Loops configured for a conditional exit have:


Red glyph next to the count terminal
Conditional terminal in the lower right corner

ni.com/training
E. For Loop/While Loop Comparison

For Loop While Loop

• 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

• Normally, when you wire different representation types to the


inputs of a function, the function returns an output in the larger
or wider format
Coercion Dot
• LabVIEW chooses the
representation that
uses more bits
• However, the For Loop
count terminal always
coerces to a 32-bit signed
integer

ni.com/training
E. For Loops – Numeric Conversion

• Avoid coercion for better performance


− Choose matching data type
− Programmatically convert to the matching data type

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

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
F. Timing a VI – 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
F. Timing a VI – Elapsed Time Express VI

• Determines how much time elapses after some point in your


VI
• Keep track of time while the VI continues to execute
• Does not provide the processor with
time to complete other tasks

ni.com/training
Wait Chart VI

Compare and contrast using a Wait function and the Elapsed


Time Express VI for software timing.

DEMONSTRATION
G. Iterative Data Transfer

• When programming with loops, you often need to know the


values of data from previous iterations of the loop
• Shift registers transfer values from one loop iteration to the
next

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

Block Diagram 1st run 2nd run


Initialized
Shift Output = 5 Output = 5
Register

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

• You calculated the average of the last 3 temperature


readings. How would you modify the VI to calculate the
average of the last 5 temperature readings?

DISCUSSION
H. Plotting Data – Waveform Chart

• Special type of numeric indicator that displays one or more


plots of data, typically acquired at a constant rate
• Displays single or multiple plots

ni.com/training
H. Plotting Data – Chart Update Modes

• Right-click the chart and select Advanced»Update Mode


from the shortcut menu
• Strip chart is the default update mode
• Scope chart and Sweep chart modes display plots
significantly faster than the strip chart mode

ni.com/training
H. Plotting Data

ni.com/training
H. Plotting Data – Waveform Graphs

Use the Context Help window to determine how to wire multi-


plot data to Waveform Graphs and XY Graphs

ni.com/training
Exercise 4-5
Temperature Multiplot VI

Plot multiple data sets on a single waveform chart and


customize the chart view.
GOAL
Exercise 4-5
Temperature Multiplot VI

• For this exercise, is it better to use a chart or a graph?

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

• Selector Terminal: Wire an input value, or selector, to


determine which case executes

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

You can create multiple input and output tunnels


• Inputs are available to all cases if needed
• You must define each output tunnel for each case

ni.com/training
I. Case Structures – Use Default if Unwired

Default values are: Data Type Default Value

Numeric 0

Boolean FALSE

String Empty

Avoid using the Use Default If Unwired option on Case


structure tunnels
• Adds a level of complexity to your code
• Complicates debugging your code

ni.com/training
I. Case Structures – Boolean

Boolean input creates two cases: True and False

ni.com/training
I. Case Structures – Integer

• Add a case for each integer as necessary


• Integers without a defined case use the default case

ni.com/training
I. Case Structures – String

• Add a case for each string as necessary


• Strings without a defined case use the default case

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

Modify a VI to use a Case structure to make a software


decision.
GOAL
Exercise 4-6
Determine Warnings VI

• What happens if all the values are 10? How could you fix
this?

DISCUSSION
Summary—Quiz

1. Which identifies the control or indicator on the block


diagram?
a) Caption
b) Location
c) Label
d) Value

ni.com/training
Summary—Quiz Answer

1. Which identifies the control or indicator on the block


diagram?
a) Caption
b) Location
c) Label
d) Value

ni.com/training
Summary—Quiz

2. Which structure must run at least one time?


a) While Loop
b) For Loop

ni.com/training
Summary—Quiz Answer

2. Which structure must run at least one time?


a) While Loop
b) For Loop

ni.com/training
Summary—Quiz

3. Which is only available on the block diagram?


a) Control
b) Constant
c) Indicator
d) Connector Pane

ni.com/training
Summary—Quiz Answer

3. Which is only available on the block diagram?


a) Control
b) Constant
c) Indicator
d) Connector Pane

ni.com/training
Summary—Quiz

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) Switch Until Released
b) Switch When Released
c) Latch Until Released
d) Latch When Released

ni.com/training
Summary—Quiz 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) Switch Until Released
b) Switch When Released
c) Latch Until Released
d) Latch When Released

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
• Consider using arrays when you work with
a collection of similar data and when you
perform repetitive computations

ni.com/training
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, right-
click 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 – Creating Constants

• To create an array constant:


− Select an array constant on the
Functions palette
− Place the array shell on the block diagram
− Place a constant in the array shell
• You can use an array constant to store
constant data or as a basis for comparison
with another array
• Array constants also are useful for passing data into a subVI

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
A. Arrays – Auto-indexing Input

For Loop executes


a number of times
equal to the number
of elements in the
array

ni.com/training
A. Arrays – 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
A. Arrays – Auto-indexing Output

• When you auto-index an array output tunnel, the output


array receives a new element from every iteration of the loop
• Auto-indexed output arrays are always equal in size to the
number of iterations

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

Manipulate arrays using various LabVIEW functions.


GOAL
Exercise 5-1
Concept: Manipulating Arrays

• How would you programmatically create a 3-dimensional


array?

DISCUSSION
B. Clusters

• Clusters group data elements of mixed types


• Similar to a record or a struct in text-based programming
languages

ni.com/training
B. Clusters – Array vs Cluster

• Clusters differ from arrays in that they are a fixed size


• Clusters can contain mixed data types; arrays contain only
one data type
• Like an array, a cluster is either a control or an indicator and
cannot contain a mixture of controls and indicators

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

• If you have a cluster control or indicator, right-click the


cluster on the block diagram and select Create»Constant
from the shortcut menu

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
B. Clusters – Assembling a Cluster

Use the Bundle function to assemble a new cluster

ni.com/training
B. Clusters – Modifying a Cluster

Use the Bundle By Name or the Bundle function to modify an


existing cluster

ni.com/training
B. Clusters – Disassembling a Cluster

Use the Unbundle By Name or Unbundle function to use


individual items in a cluster

ni.com/training
B. Clusters – Error Clusters

• LabVIEW uses error clusters to pass error information


• An error cluster contains the following elements:
− status: Boolean value that reports True if an error occurs
− code: 32-bit signed integer that identifies the error
− source: String that identifies where the error occurred

ni.com/training
Exercise 5-2
Concept: Clusters

Create clusters on the front panel, reorder clusters, and use


the cluster functions to assemble and disassemble clusters.
GOAL
Exercise 5-2
Concept: Clusters

• What would happen if Small Cluster was reordered where


the numeric was first and the Boolean was second?

DISCUSSION
C. Type Definitions – Custom Controls

Use custom controls and indicators to extend the available set


of front panel objects
1. Create and save a
custom control
or indicator
2. Use the custom control
or indicator on other
front panels

ni.com/training
C. Type Definitions – Control Editor

• Use the Control Editor window to customize controls and


indicators
• To display the Control Editor
window, right-click a control
or indicator and select
Advanced»Customize

ni.com/training
C. Type Definitions

You can save a custom control as:


• Control
• Type Definition
• Strict Type Definition

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

Strict Type Definition:


• Similar to a type definition, except a strict type definition
forces everything about an instance to be identical to the
strict type definition, except:
− label
− description
− default value

ni.com/training
Exercise 5-3
Concept: Type Definition

Create a type defined enumerated control and explore the


differences between a type definition and a strict type
definition.
GOAL
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

1. You can create an array of arrays.


a) True
b) False

ni.com/training
Summary—Quiz 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
Summary—Quiz

2. What is the value of the Iterations indicator


after running this VI?

ni.com/training
Summary—Quiz Answer

2. What is the value of the Iterations indicator


after running this VI? Value of Iterations = 4

ni.com/training
Summary—Quiz

3. You customize a control, select Control from the Type Def.


Status 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
Summary—Quiz Answer

3. You customize a control, select Control from the Type Def.


Status 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
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

• File I/O writes to or reads from a file


• A typical file I/O operation involves the following process:

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

LabVIEW can use or create the following file formats:


• Binary—Underlying file format of all other file formats
• ASCII—Specific type of binary file that is a standard used by
most programs
• LVM— The LabVIEW measurement data file (.lvm) is a tab-
delimited text file you can open with a spreadsheet
application or a text-editing application
• TDMS—Type of binary file created for NI products consisting
of two separate files: a binary file and a binary index file

ni.com/training
A. Understanding File I/O – File Formats

• In this course, you learn about creating text (ASCII) files


• Use text files in the following situations:
− You want to access the file from another application
− Disk space and file I/O speed are not crucial
− You must not perform random access reads or writes
− Numeric precision is not important

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

Use a high-level file I/O VI to write to a spreadsheet-readable


file.
GOAL
C. Understanding Low-Level File I/O VIs

ni.com/training
Exercise 6-2
Temperature Log VI

Modify a VI to create an ASCII file using disk streaming.


GOAL
Exercise 6-2
Temperature Log VI

• What would happen if you used the Write to Measurement


File Express VI inside the While loop?

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

• Measurement & Automation Explorer


− Configure and test DAQ device

• 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

• A basic DAQmx application involves the following process:

Acquire or
Create Configure Start Clear
Generate
Task Task Task Task
Data

ni.com/training
D. DAQ Programming – Create Task

• Create Virtual Channel VI


− Creates a virtual channel and adds it to a task
− Use pull-down menu to select the appropriate instance of this
VI

ni.com/training
D. DAQ Programming – Configure Task

• Configure timing if reading multiple samples


− Sample rate, timing source, etc
• Configure triggering if necessary for application
− Configures the task to start or stop on a rising or falling digital
edge, analog edge, or analog windows

ni.com/training
D. DAQ Programming – Start Task

• Starts the task after the task has been configured

ni.com/training
D. DAQ Programming – Acquire or Generate Data

• Acquire or generate data from the DAQ device


• Make sure pull-down menu selection is compatible with task
configuration

ni.com/training
D. DAQ Programming – Clear Task

• DAQmx Clear Task VI


− Stops the task
− Releases any resources the task reserved
− Clears the task

ni.com/training
D. DAQ Programming – Example

• Example acquisition with triggering

ni.com/training
E. Instrument Control Programming

• Virtual Instrument Software Architecture (VISA):


− High-level API that calls low-level drivers
− Can control VXI, GPIB, serial, or computer-based instruments
and makes the appropriate driver calls depending on the type
of instrument used

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

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

ni.com/training
VISA Open Function

• Establishes communication line to resource


• Generally used once per resource
• Returns VISA Resource Name

ni.com/training
VISA I/O Functions

VISA Write and VISA Read Functions

ni.com/training
VISA Close Function

• Sessions take up system resources


• Close sessions before program ends

ni.com/training
VISA Write and Read Example

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
F. Using Instrument Drivers

• Organized set of VIs that control a


programmable instrument
− Each VI performs multiple instructions
− Grouped by operation type
(configuration, data, etc)
• Reduce development time
− Simplify instrument control
− Reusable
− Common architecture and interface

ni.com/training
Using Instrument Drivers

• When you use an instrument driver, the driver contains the


code specific to the instrument
• If you change instruments, replace the instrument driver VIs
with the instrument driver VIs for the new instrument, which
greatly reduces your redevelopment time

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

Modules in LabVIEW are called subVIs

ni.com/training
A. Understanding Modularity – SubVIs

•SubVIs correspond to subroutines in text-based


programming languages
•The upper right corner of the front panel and block diagram
displays the icon for the VI
•This icon identifies the VI when you place the VI on the block
diagram

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)
} }

SubVI Block Diagram Calling VI Block Diagram

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

• Characteristics of a good VI icon


− Conveys the functionality of the VI using:
• Relevant graphics
• Descriptive text

ni.com/training
B. Icon and Connector Pane – Create Icon

• Create custom icons by right-clicking the icon in the upper


right corner of the front panel or block diagram and selecting
Edit Icon or by double-clicking the icon
• You also can drag a graphic from anywhere in your file
system and drop it on the icon

ni.com/training
B. Icon and Connector Pane – Create Icon

• Use the editing tools to modify an icon manually

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

• Use this connector pane layout as a standard

• Top terminals are usually reserved for references, such as a


file reference
• Bottom terminals are
usually reserved for
error clusters

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
• To place an open VI on the block diagram of another open
VI
− Click the icon of the VI you want to use as a subVI
− Drag the icon to the block diagram of the other VI

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

• Use a Case structure to handle errors passed into the subVI

ni.com/training
C. Using SubVIs – Handling Errors

• Avoid using LabVIEW error handler VIs inside subVIs

ni.com/training
C. Using SubVIs – Section to SubVI

To convert a section of a VI into a subVI:


• Use the Positioning tool to select the section of the block
diagram you want to reuse
• Select Edit»Create 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

• What would you do if this subVI needed 20 inputs and


outputs?

DISCUSSION
Summary—Quiz

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
Summary—Quiz 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
Summary—Quiz

2. You must create a custom icon to use a VI as a subVI.


a) True
b) False

ni.com/training
Summary—Quiz 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 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

Use error clusters to force order of execution

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

• Avoid overusing Sequence structures


• You cannot stop the execution part way through a sequence

ni.com/training
A. Using Sequential Programming

The best way to write this VI is to enclose the dialog boxes in


Case structures, wiring the error cluster to the case selectors

ni.com/training
B. Using State Programming

Although Sequence structures or sequentially wired subVIs


accomplish the purpose, it is not always the best choice:
• 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 the 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
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

• 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
C. State Machines – Infrastructure

• A state machine consists of a set of states and a transition


function that maps to the next state
• Each state can lead to one or multiple states or end the
process flow

While Loop

Shift Register Case Structure ni.com/training


C. State Machines – Default Transition

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

Demonstrate an implementation of a state machine.

<Exercises>\LabVIEW Core 1\Demonstrations\Course Project

DEMONSTRATION
Exercise 8-1
State Machine VI

Create a simple state machine using a type-defined


enumerated control and practice the skills learned throughout
this course.
GOAL
Exercise 8-1
State Machine VI

• If you want to add a Process 3 to the program, how would


you modify the 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

You cannot stop the execution part way through a sequence.

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

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 can be of the following types:


• Local - Stores data in front panel controls and indicators
• Global - Stores data in special repositories that can be
accessed from multiple VIs
• Functional Global - Stores data in While Loop shift
registers
• Shared - Transfers data between various distributed
targets connected together over a network
ni.com/training
B. Variables – Using in a Single VI

Use local variables to pass data within a single VI

ni.com/training
Creating Local Variables

Create and use local variables.

DEMONSTRATION
B. Variables

• Boolean controls with associated local variables must use


switch mechanical action
• Boolean latch action is incompatible with local variables

ni.com/training
Exercise 9-1
Local Variable VI

Use a local variable to write to and read from a control.


GOAL
Exercise 9-1
Local Variable VI

• What functionality does the local variable provide for this


application?

DISCUSSION
B. Variables – Using Between VIs

Use a global variable or a single process shared variable to


share data between multiple VIs
• Use a global variable to share data among VIs on the same
computer, especially if you do not use a project file
• Use a single process shared variable if you may need to
share the variable information among VIs on multiple
computers in the future

ni.com/training
Creating Global Variables

Create and use global variables.

DEMONSTRATION
B. Variables – Using Between VIs

Single Process Shared Variables

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

Set Variable Type to Single Process

ni.com/training
Creating Shared Variables

Create and use single process shared variables.

DEMONSTRATION
B. Variables – Using Carefully

ni.com/training
B. Variables – Using Carefully

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
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

Explore the Timer FGV functional global variable.


Observe how CallingVI.vi uses the functional global variable.

DEMONSTRATION
Exercise 9-2
Global Data Project

Create a project containing multiple VIs that share data using


a single process shared variable.
GOAL
Exercise 9-2
Global Data Project

• What is the purpose of the first Stop shared variable in the


Generate Data VI?

DISCUSSION
D. Race Conditions

Race conditions are a common problem for programs


that execute multiple tasks in parallel and share data
between the tasks

ni.com/training
Race Conditions

Watch a demonstration of race conditions.

<Exercises>\LabVIEW Core 1\Demonstrations\Race


Condition

DEMONSTRATION
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
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

Run the top VI first


Run the bottom VI second

ni.com/training
D. Race Conditions – Sequencing

What is the final value?


Four possible outcomes:
• Value = (Value * 5) +2
• Value = (Value + 2) * 5
• Value = Value * 5
• Value = Value +2

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

• What could you use instead of a semaphore to protect your


code?

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

You should use variables only when necessary. Use wires to


transfer data whenever possible.

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

• Instructor Led Training


− LabVIEW Core 2: Learn about multiple loop design patterns,
property nodes and building an executable
− Hardware courses such as Data Acquisition and Signal
Processing
− Online courses such as Machine Vision and LabVIEW Real-
Time
• Self-Paced: a variety of instructional packages and tools
designed to educate you at your own pace

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

LabVIEW Core 1 LabVIEW Core 3 Managing Software


Engineering in LabVIEW
LabVIEW Core 2 Skills learned:
• Modular application LabVIEW OOP System Design
Skills learned: development Advanced Architectures in
• LabVIEW environment • Structured design and
LabVIEW
navigation development practices
Skills learned:
• Basic application creation • Memory management and VI
• Quality application design
using LabVIEW performance improvement • Code reuse maximization
• Object-oriented programming in
LabVIEW
• LabVIEW engineering process
management
Certifications • Advanced design patterns used to build
LabVIEW architecture

Certified LV Associate Certified LabVIEW Certified LabVIEW


Developer Exam Developer Exam Architect Exam
Skills tested: Skills tested: Skills tested:
• LabVIEW environment • LabVIEW application • LabVIEW application
knowledge development expertise development mastery

ni.com/training
Please complete the course survey.
Thank you!

ni.com/training

You might also like