You are on page 1of 57

LabVIEW Basics I: Introduction What You Need To Get Started

• LabVIEW Basics I Course Manual


• LabVIEW Basics I 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
11500 North Mopac Expressway LabVIEW 8.6 or later
and Windows 2000 or later
Austin, Texas 78759
ni.com/training ni.com/training

File Locations Instructional Methods Demonstrations

Concept
Quizzes
Exercise
The course installer places the course files in the following • Lecture gives a foundation
location: in the topic
• Instructor reinforces Lecture Topic Development
Exercise

Exercises foundation through


LabVIEW demonstrations and quizzes
Root Directory <or>
Basics I
Solutions • Use concept exercises to further explore a topic
− Watch a simulation, experiment with example VIs
• Use development exercises to gain hands-on experience
− Demonstration of a finished development exercise further
reinforces the learning process
ni.com/training ni.com/training

Courses
New User Experienced User Advanced User
Getting The Most Out Of This Course
LabVIEW Basics I LabVIEW Intermediate I LabVIEW Advanced I
LabVIEW Basics II LabVIEW Intermediate II
• Experiment with hands-on exercises to understand the
Skills learned: Skills learned: Skills learned:
methods used • LabVIEW environment • Modular application • Large application design
navigation development
• Implementations explore a possible solution—you may find • Basics application creation • Structured design and
• Advanced development
techniques
a better one using LabVIEW development practices • Implementing multideveloper
• Basics of data acquisition and • Inter-application projects
• Do not come to class prepared to develop an outside instrument control communication and
connectivity techniques
application; concentrate on the exercises given to build a Certifications
good foundation 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 ni.com/training
6

1
Course Learning Map Lesson 7
Course Goals
Developing Modular Applications
Lesson 1 Lesson 4 This course prepares you for the following:
Implementing a VI
Problem Solving
Lesson 8 • Solve problems using LabVIEW
Data Acquisition • Use data acquisition and instrument control in LabVIEW
Lesson 2 Lesson 5
applications
pp
Navigating LabVIEW Relating Data
Lesson 9 • Use modular programming practices
Instrument Control • Develop, debug, and test LabVIEW VIs
Lesson 3 Lesson 6
Troubleshooting & Debugging VIs Storing Measurement Data
• Effectively use a state machine architecture
Lesson 10
Common Design Techniques

ni.com/training ni.com/training
8

Lesson 1 A. Software Development Method


Problem Solving
• Problem solving skills are essential to creating software
solutions
• Computer programmers use a software development
TOPICS method
A. Software Development E. Testing • Using the software development method, code is more
Method F. Maintenance likely to be successful, readable, scalable, and
B. Scenario maintainable
G. Project
C. Design
D. Implementation

ni.com/training ni.com/training
10

Software Development Method Software Development Method

1. Define the problem (Scenario) • Used in all hands-on development exercises in this course
2. Design an algorithm or flowchart • Scenario and Design are usually given; you implement the
3. Implement the design design and test the implementation
4. Test and verify the implementation
5. Maintain and update the implementation

ni.com/training ni.com/training
11 12

2
B. Scenario C. Design

Define the problem Design a solution by analyzing the problem:


• Identify the software inputs
Furnace Example: • Identify the software outputs
Cure a material at a certain temperature for a set amount of • Identify additional requirements
time in a furnace. You must know: • Design an algorithm or flowchart
• Cure time
• Cure temperature
• Method for adjusting the temperature

ni.com/training ni.com/training
13 14

Design—Software Inputs Design—Software Outputs

Raw data you want to process, such as information received Results of calculations, processing, or other implemented
from the user, data acquisition, instrument control and so on conditions such as information displayed to the user, data
written to file, signal generation, and so on
Furnace Example:
p
Cure Time (seconds) Furnace Example:
Desired Cure Temperature (degrees Kelvin) On/Off switch to control coil voltage
Current Furnace Temperature (degrees Kelvin)

ni.com/training ni.com/training
15 16

Design – Additional Requirements Design – Algorithm

Factors that influence solving the problem


Steps that process your inputs and create outputs

Furnace Example:
Assume the furnace cannot start until the interior Furnace Example:
temperature is the same as the exterior temperature. This 1. Read exterior temp 5. If current temp ≥ desired temp,
requirement adds an additional input: Exterior Temperature 2. Read interior temp turn off voltage to coil
(degrees Kelvin). 3. If interior temp ≠ 6. If current temp < desired temp,
exterior temp, go to turn on voltage to coil
step 1 7. If time < cure time, go to step 4
4. Read interior temp 8. Turn off voltage to coil
ni.com/training ni.com/training
17 18

3
Design –
Design – State Transition Diagram
Flowchart
Visual design Type of flowchart that indicates the states of a program and
of an algorithm transitions between states
Furnace Example: • State—part of a program that satisfies a condition,
performs an action or waits for an event
• Transition—condition, action, or event that causes the
program to move to the next state

ni.com/training ni.com/training
19 20

Design – State Transition Diagram D. Implementation

Furnace • Create code for the algorithm or flowchart


Example: • Course goal— to successfully create implementations in
LabVIEW

ni.com/training ni.com/training
21 22

E. Testing F. Maintenance

Test implementation with logical and illogical data • Ongoing process of resolving programming errors
• Does logical data produce expected result? • Implement changes to the original solution
• Does illogical data produce expected error?
• How does illogical data affect the results?
• Is error handling strategy sufficient?

ni.com/training ni.com/training
23 24

4
Exercise 1-1: Software Development Method G. Project – Temperature Weather Station

1. Acquires a temperature every half second


2. Analyzes each temperature to determine if the
temperature is too high or too low
3. Alerts the user if there is a danger
g of a heat stroke or a
freeze
Solve a non-programming problem using the software 4. Displays the data to the user
development method described in this course.
GOAL

5. Logs the data if a warning occurs


6. If the user does not stop the program, the entire process
repeats

ni.com/training ni.com/training
26

G. Project G. Project

Many possible solutions


Example of
an alternate solution:

ni.com/training ni.com/training
27 28

Summary—Matching Quiz Summary—Matching Quiz Answers

1. Scenario A. Apply an algorithm or 1. Scenario C. Define the problem


2. Design flowchart 2. Design E. Identify the inputs and
3. Implementation B. Verify the code 3. Implementation outputs
4. Testing C. Define the pproblem 4. Testing pp y an algorithm
A. Apply g or
5. Maintenance D. Update the code 5. Maintenance flowchart
E. Identify the inputs and B. Verify the code
outputs D. Update the code

ni.com/training ni.com/training
29 30

5
Lesson 2 A. Virtual Instruments (VIs)
Navigating LabVIEW
• LabVIEW programs are called virtual instruments, or VIs
• Appearance and operation imitate physical instruments,
such as oscilloscopes and digital multimeters
TOPICS
A. Virtual Instruments G. Searching Palettes
B. Parts of a VI H. Selecting a Tool
C. Starting a VI I. Dataflow
D. Project Explorer J. Building a Simple VI
E. Front Panel
F. Block Diagram
ni.com/training ni.com/training
1 2

B. Parts of a VI B. Parts of a VI – Front Panel

LabVIEW VIs contain three main components: • User interface for


1. Front Panel 2. Block Diagram 3. Icon/Connector Pane the VI
• You build the
front panel with
controls (inputs)
and indicators
(outputs)

ni.com/training ni.com/training
3 4

B. Parts of a VI – Block Diagram B. Parts of a VI – Icon/Connector Pane

• Contains the • Icon: graphical representation of a VI


graphical source • Connector Pane: map of the inputs and outputs of a VI
code • Icons and connector panes are necessary to use a VI as
• Front panel objects a subVI
appear as terminals − A subVI is a VI that is inside of another VI
on the block diagram
− Similar to a function in a text-based programming
language
Icon Connector Pane

ni.com/training ni.com/training
5 6

1
Demonstration D. Project Explorer
Use LabVIEW Projects to:
Starting A VI • group together LabVIEW files and non-LabVIEW files
• create build specifications
• deploy or download files to targets

Demonstrate using the


Getting Started dialog box
GOAL

and the New dialog box


to start a VI.

ni.com/training ni.com/training
8

Demonstration E. Front Panel

Project Explorer

Demonstrate creating a project, adding files, and


removing files.
GOAL

ni.com/training ni.com/training
10

E. Front Panel – Controls Palette E. Front Panel – Front Panel Toolbar


• 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 ni.com/training
11 12

2
E. Front Panel – Numeric
E. Front Panel – Controls & Indicators
Controls/Indicators
• Controls The numeric data type can represent numbers of various
− Knobs, push buttons, dials, and other input devices types, such as integer or real
− Simulate instrument input devices and supply data to the
block diagram of the VI
• Indicators Numeric Control
− Graphs, LEDs, and other displays Increment/Decrement Buttons
− Simulate instrument output devices and display data the block
diagram acquires or generates
Numeric Indicator

ni.com/training ni.com/training
13 14

E. Front Panel – Boolean


E. Front Panel – Strings
Controls/Indicators
• The Boolean data type represents data that only has two • The string data type is a sequence of ASCII characters
parts, such as True and False or On and Off • Use string controls to receive text from the user such as a
• Use Boolean controls and indicators to enter and display password or user name
Boolean (True or False) values • Use stringg indicators to display
p y text to the user
• Boolean objects simulate switches, push buttons, and
LEDs

Boolean Boolean
Control Indicator

ni.com/training ni.com/training
15 16

E. Front Panel – Shortcut Menus E. Front Panel – Property Dialog Box


• All LabVIEW objects have • Right-click a front panel
associated shortcut menus object and select
• As you create a VI, use the Properties to display
shortcut menu items to change • The options available on
the look or behavior of front the pproperty
p y dialogg box
panel and block diagram are similar to the options
objects available on the shortcut
• To access the shortcut menu, menu for that object
right-click the object

ni.com/training ni.com/training
17 18

3
F. Block Diagram F. Block Diagram – Functions Palette

Block diagram objects include the Contains the VIs, functions, and constants
following: you use to create the block diagram
• Terminals
• SubVIs
• Functions
• Constants
• Structures
• Wires

ni.com/training ni.com/training
19 20

F. Block Diagram – Block Diagram Toolbar 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 ni.com/training
21 22

F. Block Diagram Terminals 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 ni.com/training
23 24

4
F. Block Diagram – Function Nodes F. Block Diagram – SubVI Nodes

• Fundamental operating elements of LabVIEW • SubVI: VIs that you build to use inside of another VI
• Do not have front panels or block diagrams, but do have • Any VI has the potential to be used as a subVI
connector panes • When you double-click a subVI on the block diagram, you
• Double-clickingg a function onlyy selects the function – does can view the front ppanel and block diagram
g of the subVI
not open it like a VI − The upper right corner of the front panel and block diagram
• Has a pale yellow background on its icon 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 ni.com/training
25 26

F. Block Diagram – SubVI Nodes F. Block Diagram – Icons/Expandable 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 ni.com/training
27 28

F. Block Diagram – Wires F. Block Diagram – Wiring Tips

• Transfer data between block diagram objects through wires • Press <Ctrl>-B to delete all broken wires
• Wires are different colors, styles, and thicknesses, • Right-click and select Clean Up Wire to reroute the wire
depending on their data types
• A broken wire appears
pp 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 ni.com/training
29 30

5
Exercise 2-1: Exploring a VI G. Searching for Controls, VIs & Functions

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


the Controls and Functions palette.

Concept Exercise
Identify the parts of an existing VI.
GOAL

ni.com/training ni.com/training
32

Exercise 2-2: Navigating Palettes 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
Concept Exercise of the tool selected
Learn to use the palettes and search for controls,
GOAL

• When using the Automatic Tool Selection, LabVIEW


functions and VIs. chooses which tool to select based on the current location
of the mouse

ni.com/training ni.com/training
34

Exercise 2-3: Selecting A Tool 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
pp data to the output
p terminals onlyy when the
node finishes execution
Concept Exercise
Gain experience using the Automatic Tool Selection to
GOAL

select which tool to use.

ni.com/training ni.com/training
36

6
I. Dataflow – Quiz I. Dataflow – Quiz Answers
Which node executes first? NO CORRECT ANSWER
a) Add
b) Subtract Which node executes first?
c) Random Number a) Add – possibly
d) Divide
Di id b) Subtract
S bt t – definitely
d fi it l nott
e) Sine c) Random Number – possibly
d) Divide – possibly
e) Sine – definitely not

ni.com/training ni.com/training
37 38

Exercise 2-4: Dataflow J. Building a Simple VI

Concept Exercise
Understand how dataflow determines the execution order
GOAL

in a VI.

ni.com/training ni.com/training
40

J. Building a Simple VI – Acquire J. Building a Simple VI – Analyze

Acquire Express VIs: Analyze Express VIs:

• DAQ Assistant Express VI • Amplitude and Level Measurements Express VI

• Instrument I/O Assistant Express VI • Statistics Express VI

• Spectral Measurements Express VI


• Simulate Signal Express VI
• Tone Measurements Express VI
• Read from Measurement File Express VI
• Filter Express VI

ni.com/training ni.com/training
41 42

7
J. Building a Simple VI – Present J. Building A Simple VI – Running

• Present tasks are Express VIs that perform a function or 1. Place Express VI on the block diagram
indicators that present data on the front panel of the VI 2. Configure the dialog box that opens
• Indicators include the Waveform Chart, the Waveform 3. Wire Express VIs together
Graph, and the XY Graph 4. Save and run the VI
• 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 The Run button appears broken when the VI you
are creating or editing contains errors

ni.com/training ni.com/training
43 44

Exercise 2-5: Simple Acquire, Analyze, and


Demonstration Present VI

DAQ Signal
Accessory

Demonstrate the different aspects of the DAQ Signal Create a simple VI that acquires data, analyzes data, and
Accessory. presents the results.
GOAL

GOAL

ni.com/training ni.com/training

Summary—Quiz Summary—Quiz Answers


1. Which function executes first: 1. Which function executes first:
Add or Subtract? Add or Subtract?
a) Add a) Add
b) Subtract b) Subtract
c) Unknown c) Unknown
2. Which function executes first: 2. Which function executes first:
Sine or Divide? Sine or Divide?
a) Sine a) Sine
b) Divide b) Divide
c) Unknown c) Unknown

ni.com/training ni.com/training
47 48

8
Summary—Quiz Summary—Quiz Answers
3. Which of the following 3. Which of the following
functions executes first? functions executes first?
a) Random Number a) Random Number
b) Divide b) Divide
c) Add c) Add
d) Unknown d) Unknown
4. Which of the following 4. Which of the following
functions execute last? functions execute last?
a) Random Number a) Random Number
b) Subtract b) Subtract
c) Add c) Add
d) Unknown d) Unknown
ni.com/training ni.com/training
49 50

Summary—Quiz Summary—Quiz Answer

5. What are the three parts of a VI? 5. What are the three parts of a VI?
a) Front Panel a) Front Panel
b) Block Diagram b) Block Diagram
c) Project c) Project
d) Icon/Connector Pane d) Icon/Connector Pane

ni.com/training ni.com/training
51 52

9
Lesson 3 A. LabVIEW Help Utilities – Context Help
Troubleshooting and Debugging VIs
• Displays basic information about LabVIEW objects when
you move the cursor over each object
• Select Help»Show
TOPICS Context Help, press
A. LabVIEW Help Utilities <Ctrl-H> or
click the Show Context
B. Correcting Broken VIs
Help Window button
C. Debugging Techniques on the toolbar
D. Undefined or Unexpected Data
E. Error Checking and Error Handling
ni.com/training ni.com/training
2

A. LabVIEW Help Utilities – NI Example


A. LabVIEW Help Utilities – LabVIEW Help
Finder
• 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 ni.com/training
3 4

Exercise 3-1: Using Help B. Correcting Broken VIs

Concept Exercise
Become familiar with using the Context Help window, the
GOAL

LabVIEW Help, and the NI Example Finder.

ni.com/training ni.com/training
5 6

1
B. Correcting Broken VIs C. Debugging Techniques

Common Issues Your VI isn’t broken, but you are getting unexpected data or
• Broken wire behavior
− You wired a Boolean control • Any unwired or hidden subVIs?
to a String indicator • Incorrect default data beingg used?
− You wired a Numeric control • Undefined data being passed?
to a Numeric control
• Numeric representation correct?
• A required block diagram terminal is unwired
• Node execution order correct?
• 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 ni.com/training
7 8

C. Debugging Techniques –
C. Debugging Techniques – Single Stepping
Execution Highlighting
• Use execution highlighting to watch the data flow through Single-step through the VI to view each action of the VI on
the block diagram the block diagram
• If the VI runs more slowly than expected, confirm that you Suspend the execution of a subVI to edit values of controls
turned off execution highlighting in subVIs 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 ni.com/training
9 10

C. Debugging Techniques – Probes C. Debugging Techniques – Breakpoints

• Use the Probe tool to observe intermediate data • When you reach a breakpoint during execution, the VI
values and to check the error output of VIs pauses and the Pause button appears red
and functions, especially those performing I/O • You can take the following actions at a breakpoint:
• Retain the values in the wires so that you can − Single-step through execution using the single-stepping
probe wires for data after execution has finished 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 ni.com/training
11 12

2
D. Undefined or Unexpected Data E. Error Checking and Error Handling

• ∞ (Inf) • No matter how confident you are in the VI you create, you
− Infinity cannot predict every problem a user can encounter
− Divided a number by zero? • Without a mechanism to check for errors, you know only
• NaN that the VI does not work properly
− Not a number • Error checking tells you why and where errors occur
− Produced by invalid operations, such as taking the square − Automatic error handling
root of a negative number − Manual error handling
• Check for unexpected Inf values or NaN values in your
mathematical operations

ni.com/training ni.com/training
13 14

E. Error Checking and Error Handling – E. Error Checking and Error Handling –
Automatic Error Handling Manual Error Handling
• LabVIEW automatically handles any known error when a VI • To disable automatic error handling for a subVI or function,
runs by: wire its error out cluster to the error in cluster of another
− suspending execution, subVI or function or to an error out indicator
− highlighting the subVI or function where the error occurred, • Use the LabVIEW error handling VIs,
− and displaying the Error dialog box functions, and parameters
• Select File»VI Properties and select Execution from the to manage errors
Category pull-down menu to disable automatic error
handling for a specific VI

ni.com/training ni.com/training
15 16

E. Error Checking and Error Handling –


Exercise 3-2: Debugging
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 Concept Exercise
Use the debugging tools built into LabVIEW.
GOAL

− Source

ni.com/training ni.com/training
17 18

3
Summary—Quiz Summary—Quiz Answer

1. How do you disable automatic error handling? 1. How do you disable automatic error handling?
a) Select Operate»Disable Error Handling a) Select Operate»Disable Error Handling
b) Enable execution highlighting b) Enable execution highlighting
c) Wire the error out cluster of a subVI to the error in c) Wire the error out cluster of a subVI to the error in
cluster of another subVI cluster of another subVI
d) Place a checkmark in the Show Warnings checkbox d) Place a checkmark in the Show Warnings checkbox
of the Error List dialog box of the Error List dialog box

ni.com/training ni.com/training
19 20

Summary—Quiz Summary—Quiz Answer

2. Which of the following are the contents of the error 2. Which of the following are the contents of the error
cluster? cluster?
a) Status: Boolean a) Status: Boolean
b)) Error: Stringg b)) Error: Stringg
c) Code: 32-bit integer c) Code: 32-bit integer
d) Source: String d) Source: String

ni.com/training ni.com/training
21 22

4
Lesson 4 A. Front Panel Design
Implementing a VI
• Inputs and outputs lead to front panel design
• Retrieve the inputs by the following methods:
− Acquiring from a device
TOPICS − Readingg directlyy from a file
A. Front Panel Design G. Iterative Data Transfer − Manipulating controls
B. LabVIEW Data Types H. Plotting Data • Output data by the following methods:
C. Documenting Code I. Case Structures
− Displaying with indicators
D. While Loops
− Logging to a file
E. For Loops
− Outputting to a device
F. Timing A VI
ni.com/training ni.com/training

A. Front Panel Design – Labels/Captions A. Front Panel Design – Color Tips

• Labels – short descriptions Start with a gray scheme


• Captions – long descriptions • Select one or two shades of gray
• Captions do not appear on block diagram • Add highlight colors sparingly for important settings—on
plots, abort buttons, and the slider thumbs

ni.com/training ni.com/training

A. Front Panel Design – Text & Fonts


A. Front Panel Design – Spacing Bad Example

ni.com/training ni.com/training

1
A. Front Panel Design – Tab Controls A. Front Panel Design – Decorations
Use tab controls to • Use decorations to visually
overlap front panel group or separate objects on
controls and indicators a front panel with boxes, lines,
in a smaller area or arrows
• These objects are for
decoration only

ni.com/training ni.com/training

B. LabVIEW Data Types – Terminals B. LabVIEW Data Types – Numerics

Terminals visually communicate information about the data • The numeric data type represents
type represented 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 ni.com/training

B. LabVIEW Data Types – Boolean Demonstration

• Behavior of Boolean controls is specified by the Mechanical Action of Booleans


mechanical action
• In LabVIEW, the Boolean
data type is represented
with the color green
Use the Mechanical Action of Booleans VI located in the
NI Example Finder to learn about the different switch and
GOAL

latch actions.

ni.com/training ni.com/training

2
B. Data Types – String B. Data Types – Enum

• A sequence of displayable or non-displayable An enum


ASCII characters represents a
• On the front panel, strings appear as tables, pair of values,
text entry boxes, and labels a string and a
• Change the display type from the short-cut n meric where
numeric, here the
menu: Normal, ‘\’ Codes, Password and Hex enum can be one
of a defined list of
• Edit and manipulate strings with the String functions on the values
block diagram
• In LabVIEW, the string data type is represented with the
color pink
ni.com/training ni.com/training

B. Data Types – Enum B. Data Types – Dynamic

• Enum: enumerated • Stores the information generated or acquired by an


control, constant, or Express VI
indicator • Non-Express VIs do not accept the dynamic data type
• Enums are useful because it is easier − To use a built-in VI or function to analyze or process the
to manipulate numbers than strings dynamic data type, you must convert the data type
on the block diagram − 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 ni.com/training

C. Documenting Code – Front Panels C. Documenting Code – Naming

• Tip Strips Giving controls and indicators logical and descriptive names
• Descriptions adds usability to front panels
• VI Properties
• Good Design

ni.com/training ni.com/training

3
C. Documenting Code – Block Diagram Exercise 4-1: Determine Warnings VI

• Use block diagram comments to:


− Describe algorithms
− Explain the data contents of wires
• Use the Labelingg tool or pplace a
free label from the Functions
palette Create and document a VI.

GOAL
ni.com/training ni.com/training

D. While Loops D. While Loops

• Iteration terminal: returns number of times loop has


executed; zero indexed
Repeat (code); • Conditional terminal: defines when the loop stops
Until Condition met;
End;

Iteration Terminal Conditional Terminal

LabVIEW While Loop Flowchart Pseudo Code

ni.com/training ni.com/training

D. While Loops - Error Checking and Error


D. While Loops – Tunnels Handling
• Tunnels transfer data into and out of structures Use an error cluster in a While Loop to stop the While Loop if
• The tunnel adopts the color of the data type wired to the an error occurs
tunnel
• Data ppass out of a loopp after the loopp terminates
• When a tunnel
passes data into
a loop, the loop
executes only
after data arrive
at the tunnel
ni.com/training ni.com/training

4
Exercise 4-2: Auto Match VI E. For Loops

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

Use a While Loop and an iteration terminal and pass data End;

through a tunnel.
GOAL

LabVIEW For Loop Flowchart Pseudo Code

ni.com/training ni.com/training

E. For Loops E. For Loops – Conditional Terminal

• Create a For Loop the same way you create a While Loop You can add a conditional terminal to configure a For Loop to
• If you need to replace an existing While Loop with a For stop when a Boolean condition or an error occurs
Loop, right-click the border of the While Loop, and select
Replace with For Loop from the shortcut menu
• The value in the count terminal (an input terminal)
indicates how many times to repeat the subdiagram

ni.com/training ni.com/training

E. For Loops – Conditional Terminal E. For Loop/While Loop Comparison

For Loops configured for a conditional exit have: For Loop While Loop
• Red glyph next to the count terminal
• Conditional terminal in the lower right corner

• Executes a set number of times • Stops executing only if the value at


unless a conditional terminal is added the 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 ni.com/training

5
E. For Loops – Numeric Conversion E. For Loops – Numeric Conversion

• If you wire a double-precision, floating-point numeric value • Normally, when you wire different representation types to
to the count terminal, LabVIEW converts the larger numeric the inputs of a function, the function returns an output in
value to a 32-bit signed integer the larger
or wider format Coercion Dot
• A For Loop can only execute an integer number of times
• LabVIEW chooses the
representation that
uses more bits

ni.com/training ni.com/training

Exercise 4-3: While Loops vs For


F. Timing a VI
Loops
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 processingg the user interface

Concept Exercise
Understand when to use a While Loop and when to use a
GOAL

For Loop.

ni.com/training ni.com/training

F. Timing a VI – Wait Functions F. Timing a VI – Elapsed Time Express VI

• A wait function inside a loop allows the VI to sleep for a set • Determines how much time elapses after some point in
amount of time your VI
• Allows the processor to address other tasks during the wait • Keep track of time while the VI continues to execute
time • Does not pprovide the pprocessor with
• Uses the operating system millisecond clock time to complete other tasks

ni.com/training ni.com/training

6
Demonstration G. Iterative Data Transfer

Wait Chart VI • 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

Compare and contrast using a Wait function and the


Elapsed Time Express VI for software timing.
GOAL

ni.com/training ni.com/training

G. Iterative Data Transfer – Shift Registers G. Iterative Data Transfer – Initializing


Run once VI finishes Run again
• Right-click the border and select Add Shift Register from
Block Diagram 1st run 2nd run
the shortcut menu
Initialized
• Right shift register stores data on completion of an iteration
Shift Output = 5 Output = 5
• Left shift register
g provides stored data at beginning
g g of the g
Register
next iteration

Not
Initialized Output = 4 Output = 8
Shift
Register

ni.com/training ni.com/training

G. Iterative Data Transfer –


Exercise 4-4: Average Temperature VI
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
Use a For Loop and shift registers to average data.
GOAL

ni.com/training ni.com/training

7
H. Plotting Data – Waveform Chart H. Plotting Data – Chart Update Modes

• Special type of numeric indicator that displays one or more • Right-click the chart and select Advanced»Update Mode
plots of data, typically acquired at a constant rate from the shortcut menu
• Displays single or multiple plots • Strip chart is the default update mode
• Scope
p chart and Sweepp chart modes display p y pplots
significantly faster than the strip chart mode

ni.com/training ni.com/training

H. Plotting Data 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 ni.com/training

Exercise 4-5: Temperature Multiplot VI 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
t t t iin ttext-based
t b d programming
i llanguages
Plot multiple data sets on a single waveform chart and
customize the chart view.
GOAL

ni.com/training ni.com/training

8
I. Case Structures I. Case Structures – Default Case

• Case Selector Label: contains the name of the current case • You can specify a default case
and decrement and increment buttons on each side for the Case structure
− If you specified cases for 1, 2,
and 3, but you get an input of
4 th
4, the C
Case structure
t t executes t
the default case
• Right-click the Case structure
border to add, duplicate,
• Selector Terminal: Wire an input value, or selector, to remove, or rearrange cases
determine which case executes and to select a default case

ni.com/training ni.com/training

I. Case Structures – Input & Output Tunnels I. Case Structures – Use Default if Unwired

You can create multiple input and output tunnels Default values are: Data Type Default Value

• Inputs are available to all cases if needed Numeric 0


• You must define each output tunnel for each case 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 ni.com/training

I. Case Structures – Boolean I. Case Structures – Integer

Boolean input creates two cases: True and False • Add a case for each integer as necessary
• Integers without a defined case use the default case

ni.com/training ni.com/training

9
I. Case Structures – String I. Case Structures – Enum

• Add a case for each string as necessary • Gives users a list of items from which to select
• Strings without a defined case use the default case • The case selector displays a case for each item in the
enumerated type control

ni.com/training ni.com/training

I. Case Structures - Error Checking and Error


Handling
Exercise 4-6: Determine Warnings VI
Use Case Structures inside VIs to execute the code if there
is no error and skip the code if there is an error

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


decision.
GOAL

ni.com/training ni.com/training

Summary—Quiz Summary—Quiz Answer

1.Which identifies the control or indicator on the block 1.Which identifies the control or indicator on the block
diagram? diagram?
a) Caption a) Caption
b)) Location b)) Location
c) Label c) Label
d) Value d) Value

ni.com/training ni.com/training

10
Summary—Quiz Summary—Quiz Answer

2. Which structure must run at least one time? 2. Which structure must run at least one time?
a) While Loop a) While Loop
b) For Loop b) For Loop

ni.com/training ni.com/training

Summary—Quiz Summary—Quiz Answer


3. Which is only available on the block diagram? 3. Which is only available on the block diagram?
a) Control a) Control
b) Constant b) Constant
c)) Indicator c)) Indicator
d) Connector Pane d) Connector Pane

ni.com/training ni.com/training

Summary—Quiz Summary—Quiz Answer


4. Which mechanical action causes a Boolean in the False state 4. Which mechanical action causes a Boolean in the False state
to change to True when you click it and stay True until you to change to True when you click it and stay True until you
release it and LabVIEW has read the value? release it and LabVIEW has read the value?
a) Switch Until Released a) Switch Until Released
b) Switch When Released b) Switch When Released
c) Latch Until Released c) Latch Until Released
d) Latch When Released d) Latch When Released

ni.com/training ni.com/training

11
Lesson 5 A. Arrays
Relating Data
• An array consists of elements and dimensions
− Elements: data that make up the array
− Dimension: the length, height, or depth of an array
TOPICS − An array can have one or more dimensions
A. Arrays and as many as (231)–1 elements per
dimension, memory permitting
B. Clusters
• Consider using arrays when you work with
C. Type Definitions
a collection of similar data and when you
perform repetitive computations

ni.com/training ni.com/training
2

A. Arrays A. Arrays – Creating

• The first element shown in the array (3.00) is at index 1 1. Place an array shell on the front panel
and the second element (1.00) is at index 2 2. Drag a data object or element into the array shell
• 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 ni.com/training
3 4

A. Arrays – 2D Array A. Arrays – Initializing

• Stores elements in a grid • You can initialize an array, or leave it uninitialized


• Requires a column index and a row index to locate an • For initialized arrays, you define the number of elements in
element, both of which are zero-based each dimension, and the contents of each element
• To create a multidimensional arrayy on the front ppanel, right-
g • Uninitialized arrays
y have dimension but no elements
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 ni.com/training
5 6

1
A. Arrays – Creating Constants A. Arrays – Auto-indexing

• To create an array constant: • If you wire an array to or from a For Loop or While Loop,
− Select an array constant on the you can link each iteration of the loop to an element in that
Functions palette array by enabling auto-indexing on tunnel
− Place the array shell on the block diagram • The tunnel changes from a solid square to the image
− Place a constant in the array shell shown above to indicate auto-indexing
• 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 ni.com/training
7 8

A. Arrays – Auto-indexing Input A. Arrays – Auto-indexing Output


For Loop executes • When you auto-index an array output tunnel, the output
a number of times array receives a new element from every iteration of the
equal to the number
loop
of elements in the
array • Auto-indexed output arrays are always equal in size to the
number of iterations

ni.com/training ni.com/training
9 10

A. Arrays – Creating 2D Arrays Exercise 5-1: Manipulating Arrays

You can use two For Loops, one inside the other, to create a
2D array

Concept Exercise
Manipulate arrays using various LabVIEW functions.
GOAL

ni.com/training ni.com/training
11 12

2
B. Clusters B. Clusters – Array vs Cluster

• Clusters group data elements of mixed types • Clusters differ from arrays in that they are a fixed size
• Similar to a record or a struct in text-based programming • Clusters can contain mixed data types; arrays contain only
languages one data type
• Like an array,
y a cluster is either a control or an indicator
and cannot contain a mixture of controls and indicators

ni.com/training ni.com/training
13 14

B. Clusters – Creating B. Clusters – Constants

To create a cluster control or indicator on the front panel: • To create a cluster constant:
• Place a cluster shell on the front panel 1. Select a cluster constant on the Functions palette
• Drag a data object or element, 2. Place the cluster shell on the block diagram
which can be a numeric, Boolean, 3. Place a constant in the cluster shell
string, path, refnum, array, or
cluster control or indicator into • If you have a cluster control or indicator, right-click the
the cluster shell cluster on the block diagram and select Create»Constant
from the shortcut menu

ni.com/training ni.com/training
15 16

B. Clusters – Order B. Clusters – Assembling a Cluster

• Cluster elements have a logical order unrelated to their Use the Bundle function to assemble a new cluster
position in the shell
• You can view and modify the
cluster order by right-clicking
the cluster border and
selecting Reorder Controls
In Cluster from
the shortcut menu

ni.com/training ni.com/training
17 18

3
B. Clusters – Modifying a Cluster B. Clusters – Disassembling a Cluster

Use the Bundle By Name or the Bundle function to modify an Use the Unbundle By Name or Unbundle function to use
existing cluster individual items in a cluster

ni.com/training ni.com/training
19 20

B. Clusters – Error Clusters Exercise 5-2: 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
g integer
g that identifies the error
− source: String that identifies where the error occurred
Concept Exercise
Create clusters on the front panel, reorder clusters, and
GOAL

use the cluster functions to assemble and disassemble


clusters.

ni.com/training ni.com/training
21 22

C. Type Definitions – Custom Controls C. Type Definitions – Control Editor

Use custom controls and indicators to extend the available • Use the Control Editor window to customize controls and
set of front panel objects indicators
1. Create and save a • To display the Control Editor
custom control window, right-click a control
or indicator or indicator and select
2. Use the custom control Advanced»Customize
or indicator on other
front panels

ni.com/training ni.com/training
23 24

4
C. Type Definitions C. Type Definitions – Control Type

You can save a custom control as: Control


• Control • No connection between the custom control or indicator you
• Type Definition saved and the instance of the custom control or indicator in
• Strict Type Definition the VI
• Update the file, but the
instances are not updated

ni.com/training ni.com/training
25 26

C. Type Definitions – Type Definition C. Type Definitions – Strict Type Definition

Type Definition (type def): Strict Type Definition:


• Edit the saved file, and have all instances update with the • Similar to a type definition, except a strict type definition
changes made forces everything about an instance to be identical to the
• Forces the data type
yp of each instance to be identical strict type definition, except:
• Example: − label
− Add an item to the type definition of an − description
enum, the instances of the enum − default value
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 ni.com/training
27 28

Exercise 5-3: Type Definition Summary—Quiz

1. You can create an array of arrays. True or False?

Create a type defined enumerated control and explore the


differences between a type definition and a strict type
GOAL

definition.

ni.com/training ni.com/training
29 30

5
Summary—Quiz Answer Summary—Quiz

1. You can create an array of arrays. False. 2. What is the value of the Iterations indicator
after running this VI?

ni.com/training ni.com/training
31 32

Summary—Quiz Answer Summary—Quiz

2. What is the value of the Iterations indicator 3. You customize a control, select Control from the Type
after running this VI? Value of Iterations = 4 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
modif the control,
control does the control on the front
panel change?

ni.com/training ni.com/training
33 34

Summary—Quiz Answer Summary—Quiz

3. You customize a control, select Control from the Type 4. You are inputting data that represents a circle. The circle data
Def. Status pull-down menu, and save the control as a includes three double precision numerics: x position, y position
and radius. In the future, you might need to expand all instances
.ctl file. You then use an instance of the custom
of the circle data to include the color of the circle, represented as
control on your front panel. If you open the .ctl file an integer. How should you represent the circle on your front
and modify
modif the control,
control does the control on the front panel?
panel change? No. 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 ni.com/training
35 36

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

7
Lesson 6 A. Understanding File I/O
Storing Measurement Data
• File I/O writes to or reads from a file
• A typical file I/O operation involves the following process:

TOPICS
A. Understanding File I/O
Open/ Read
B. Understanding High-level File I/O Create/ and/or
Close Check for
File Errors
C. Understanding Low-level File I/O Replace File Write to File

ni.com/training ni.com/training
2

A. Understanding File I/O – File Formats A. Understanding File I/O – File Formats

LabVIEW can use or create the following file formats: • In this course, you learn about creating text (ASCII) files
• Binary—Underlying file format of all other file formats • Use text files in the following situations:
• ASCII—Specific type of binary file that is a standard used − You want to access the file from another application
byy most programs
g p
− Disk space and file I/O speed
p are not crucial
• LVM— The LabVIEW measurement data file (.lvm) is a − You must not perform random access reads or writes
tab-delimited text file you can open with a spreadsheet − Numeric precision is not important
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 ni.com/training
3 4

B. Understanding High-level File I/O B. Understanding High-Level File I/O

• High-level VIs Write to Spreadsheet File


− Perform all three steps for common • Converts an array of double-precision numbers to a text string and
file I/O operations writes the string to an ASCII file
− Might not be as efficient as the Read From Spreadsheet File
f ti
functions configured
fi d or designed
d i d ffor • Reads a specified number of lines or rows
individual operations from a numeric text file and outputs a
2D array of double-precision numbers
• Low-level VIs
− Individual VI for each step Write to/Read from Measurement File
• Express VIs that write data to or read data
− If you are writing to a file in a loop,
from an LVM or TDMS file format
use low-level file I/O functions
ni.com/training ni.com/training
5 6

1
C. Understanding Low-Level File I/O VIs Exercise 6-1: Spreadsheet Example VI

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


readable file.

GOAL
ni.com/training ni.com/training
7 8

Exercise 6-2: Temperature Log VI 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
Modify a VI to create an ASCII file using disk streaming.
GOAL

ni.com/training ni.com/training
9 10

Summary—Quiz Answer Summary—Quiz


1. Your continuously running test program logs to a single file the 2. If you want to view data in a text editor like Notepad, what file
results of all tests that occur in one hour as they are calculated. If format should you use to save the data?
you are concerned about the execution speed of your program, a) ASCII
should you use low-level or high-level File I/O VIs? b) TDMS
a) Low-level file I/O VIs
b) High-level file I/O VIs

ni.com/training ni.com/training
11 12

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

3
Lesson 7 A. Understanding Modularity
Developing Modular Applications
• Modularity defines the degree to which a program is
composed of discrete modules such that a change to one
module has minimal impact on other modules
TOPICS • Modules in LabVIEW are called subVIs
A. Understanding Modularity
B. Icon and Connector Pane
C. Using SubVIs

ni.com/training ni.com/training
2

A. Understanding Modularity – SubVIs A. Understanding Modularity – SubVIs

• A VI within another VI is a subVI


• SubVIs correspond to subroutines in text-based
programming languages
• The upper right
g corner of the front panel and block diagram
g
displays the icon for the VI
• This icon identifies the VI when you place the VI on the
block diagram

ni.com/training ni.com/training
3 4

A. Understanding Modularity – SubVIs 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 ni.com/training
5 6

1
B. Icon and Connector Pane B. Icon and Connector Pane – Create Icon

• After you build a VI, build the icon and the connector pane • Create custom icons by right-clicking the icon in the upper
so you can use the VI as a subVI right corner of the front panel or block diagram and
• The icon and connector pane correspond to the function selecting Edit Icon or by double-clicking the icon
prototype in text-based programming languages • You also can drag a graphic from anywhere in your file
• Every VI displays an icon in the upper-right corner of the system and drop it on the icon
front panel and block diagram windows • Refer to the
• An icon is a graphical representation of a VI Icon Art Glossary at
• If you use a VI as a subVI, the icon identifies the subVI on ni.com for standard
the block diagram of the VI graphics to use in
a VI icon
ni.com/training ni.com/training
7 8

B. Icon and Connector Pane – Setting up


B. Icon and Connector Pane – Standards
the Connector Pane
• Right-click the icon in the upper • Use this connector pane layout as a standard
right corner of the front panel
and select Show Connector
− Each rectangle on the connector • Top terminals are usually reserved for references, such as
pane represents a terminal a file reference
− Use the terminals to assign inputs
and outputs • Bottom terminals are
• Select a different pattern by usually reserved for
right-clicking the connector error clusters
pane and selecting Patterns
from the shortcut menu

ni.com/training ni.com/training
9 10

C. Using SubVIs C. Using SubVIs – Terminal Setting

• To place a subVI on the block diagram • Bold: Required terminal


− Click Select a VI on the Functions palette • Plain: Recommended
terminals
− Navigate to the VI you want to use as a subVI
• Dimmed: Optional terminals
− 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 ni.com/training
11 12

2
C. Using SubVIs – Section to SubVI Exercise 7-1: Determine Warnings VI

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

Create the icon and connector pane for a VI so you can


use the VI as a subVI.

GOAL
ni.com/training ni.com/training
13 14

Summary—Quiz Summary—Quiz Answer

1. On a subVI, which terminal setting causes an error if the 1. On a subVI, which terminal setting causes an error if the
terminal is not wired? terminal is not wired?
a) Required a) Required
b)) Recommended b)) Recommended
c) Optional c) Optional

ni.com/training ni.com/training
15 16

Summary—Quiz Summary—Quiz Answer

2. True or False? You must create a custom icon to use a 2. True or False? You must create a custom icon to use a
VI as a subVI. VI as a subVI. False.

ni.com/training ni.com/training
17 18

3
Lesson 8 A. Using Hardware
Data Acquisition
1. Signal
2. Terminal Block
3. Cable
TOPICS
4. DAQ Device
A. Using Hardware F. Using Counters 5. Computer
B. Using Software G. Using Digital I/O
C. Simulating a DAQ device
D. Measuring Analog Input
E. Generating Analog Output
ni.com/training ni.com/training
2

A. Using Hardware – Terminal Block & Cable A. Using Hardware – DAQ Device

DAQ Signal Accessory—terminal block used in this course • 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
• If you do not have a DAQ device, you can simulate one in
Measurement and Automation Explorer (MAX) to complete
your software testing

ni.com/training ni.com/training
3 4

B. Using Software B. Using Software – Configuration

• Driver Engines: NI-DAQmx and Traditional NI-DAQ


• Configuration: MAX
• Application Software: LabVIEW, LabWindows™/CVI™,
and DAQ Assistant

ni.com/training ni.com/training
5 6

1
Exercise 8-1:
C. Simulating a DAQ Device
Measurement and Automation Explorer
• Create NI-DAQmx simulated devices in NI-DAQmx 7.4 or
later
• 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 Concept Exercise
have the physical device installed To use MAX to examine, configure, and test a device.

GOAL
ni.com/training ni.com/training
7 8

D. Measuring Analog Input D. Measuring Analog Input – ADC

The process of measuring an analog signal and transferring Acquiring an analog signal with a computer requires analog-
the measurement to a computer for analysis, display, or to-digital conversion, a process that transfers an electrical
storage signal into digital data so that a computer can process the
• An analog signal is a signal that varies continuously data
• Analog input most commonly measures voltage or current

ni.com/training ni.com/training
9 10

D. Measuring Analog Input – Task Timing D. Measuring Analog Input –


Task Triggering
• Acquire 1 Sample
• When a device controlled by NI-DAQmx
− On-demand operation
does something, it performs an action
• Acquire n Samples • Two very common actions are producing
− Uses hardware timingg and a buffer in computer
p memoryy to a sample and starting a waveform acquisition
acquire data more efficiently at a consistent Δt
• Every NI-DAQmx action needs a stimulus or cause
• Acquire Continuously
• Causes for actions are called triggers
− Uses hardware timing and a buffer in computer memory to
acquire data − The start trigger starts the acquisition
− Each read operation extracts a subset of the buffer − The reference trigger establishes the reference point in a set
of input samples
− Stopped manually
ni.com/training ni.com/training
11 12

2
Exercise 8-2: Triggered Analog Input VI E. Generating 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
Acquire an analog signal using a DAQ device and a digital for a task are voltage and current
trigger. • To perform a voltage or current
GOAL

task, a compatible device must be


installed that can generate that
type of signal
ni.com/training ni.com/training
13 14

E. Generating Analog Output – DAC E. Generating Analog Output – Task Timing

• The opposite of analog-to-digital conversion Generate 1 Sample


• A digital-to-analog converter (DAC) accepts data and uses • Use single updates if the signal level is more important
it to vary the voltage on an output pin over time than the generation rate (constant, DC signal)
• When used with a high g speed clock, the DAC can create a • Use software timingg to control when the device ggenerates a
signal that appears to vary constantly and smoothly signal

ni.com/training ni.com/training
15 16

E. Generating Analog Output – Task Timing F. Using Counters

• Generate n Samples • A counter is a digital timing device typically used for event
− Generate multiple samples for one or more channels by counting, frequency measurement, period measurement,
generating single samples repetitively using hardware timing position measurement, and pulse generation
− Use Generate n Samples if you want to generate a finite • A counter has a fixed number it can count to as determined
ti
time-varying
i signal
i l by the resolution of the counter
• Generate Continuously • For example, a 24-bit counter
− Similar to Generate n Samples, can count to:
except that an event must occur 2(Counter Resolution) – 1 = 224 – 1 = 16,777,215
to stop the generation

ni.com/training ni.com/training
17 18

3
Exercise 8-3: Count Events VI G. Using 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
it h andd LED
LEDs
Use the DAQ Assistant to input a counter value. − Used to transfer data
• program devices
GOAL

• communicate between devices


− Use digital signals as clocks or triggers to
control or synchronize other measurements
ni.com/training ni.com/training
19 20

G. Using Digital I/O Exercise 8-4: Digital Count VI

• Digital Lines
− Use digital lines in a DAQ device to acquire a digital value
− On some devices, you can configure the lines individually to
either measure or generate digital samples
• Digital Ports
− Use the digital port(s) in a DAQ device to acquire a digital OPTIONAL
value from a collection of digital lines Use the DAQ Assistant for digital I/O.
GOAL

− You can configure the ports individually to either measure or


generate digital samples

ni.com/training ni.com/training
21 22

Summary—Quiz Summary—Quiz Answer


1. You are reading a signal at 50kHz. You want to acquire the signal 1. You are reading a signal at 50kHz. You want to acquire the signal
until the user clicks a stop button. Which task timing should you until the user clicks a stop button. Which task timing should you
use? use?
a) 1 Sample a) 1 Sample
b)) N Samples
p b)) N Samples
p
c) Continuous c) Continuous

ni.com/training ni.com/training
23 24

4
Summary—Quiz Summary—Quiz Answer
2. Your VI monitors a factory floor. Part of the VI controls an LED 2. Your VI monitors a factory floor. Part of the VI controls an LED
which alerts users to the status of the system. Which task timing which alerts users to the status of the system. Which task timing
should you use? should you use?
a) 1 Sample a) 1 Sample
b)) N Samples
p b)) N Samples
p
c) Continuous c) Continuous

ni.com/training ni.com/training
25 26

5
Lesson 9 A. Introduction to Instrument Control
Instrument Control
• When you use a PC to automate a test system, you are not
limited to the type of instrument you can control
• You can mix and match instruments from various
TOPICS categories
A. Introduction F. Instrument I/O Assistant • The most common categories are GPIB, serial, modular
B. GPIB G. VISA instruments, and PXI modular instruments
C. Serial H. Instrument Drivers • You must understand properties of the instrument, such as
the communication protocols to use
D. Using Other Interfaces
E. Software Architecture
ni.com/training ni.com/training
2

B. GPIB B. GPIB
GPIB (general purpose
interface bus) is a
standard interface for
• The bus supports one system controller, usually a
communication between computer, and up to 14 additional instruments
instruments and controllers • Controller:
from various vendors
− Defines the communication links
− Responds to devices that request service
− Sends GPIB commands
− Passes/receives control of the bus

ni.com/training ni.com/training
3 4

B. GPIB – Data Transfer Termination B. GPIB – Data Transfer Rate


• Informs listeners that all data • To achieve the high data transfer rate that the GPIB was
has been transferred designed for:
• Terminate the following ways: − Limit the number of devices on the bus
− Assert the End Or Identify (EOI)
hardware line with the last data − Limit the physical distance between devices
byte - preferred method
• You can obtain faster data rates with
− Place a specific end-of-string (EOS)
character at end of data HS488 devices and controllers
− Allow the listener count the bytes
transferred by handshaking and
stop reading when the listener
reaches a byte count limit

ni.com/training ni.com/training
5 6

1
C. Serial C. Serial

Serial communication A character frame packages each transmitted character as a


• Transmits data between a computer and a peripheral single start bit followed by the data bits
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 ni.com/training
7 8

C. Serial – RS-232 Standard C. Serial – RS-422 Standard

• Used historically for connecting a mouse, printer, or modem • Uses a differential electrical signal as opposed to the
• Used for industrial instrumentation unbalanced (single-ended) signals referenced to ground with
• Limited to point-to-point connections between PC serial ports RS-232
and devices • Differential transmission, which uses two lines each to
transmit and receive signals, results in greater noise
immunity and longer transmission distances as compared to
RS-232

ni.com/training ni.com/training
9 10

C. Serial – RS-485 Standard D. Using Other Interfaces

• Variation of RS-422 • Several devices communicate with serial or GPIB


• Allows you to connect up to 32 devices to a single port and instruments through the Ethernet, USB, or IEEE 1394
define the necessary electrical characteristics to ensure (FireWire®) ports and bypass the need for a serial port or
adequate signal voltages under maximum load GPIB board on your computer
• Can create networks of devices connected to a single RS- • When using these devices, program them just as you
485 serial port would if they were using the serial port or a GPIB board
• Good choice in industrial applications that require many
distributed devices networked to a controller

ni.com/training ni.com/training
11 12

2
E. Software Architecture Exercise 9-1: GPIB Configuration with MAX

• Interface Drivers: Instrument interfaces such as GPIB


include a set of drivers for the interface
• Configuration: Use MAX to configure the interface
• Application:
pp VISA is a common API to communicate with
the interface drivers and is the preferred method used
when programming for instrument control in LabVIEW Concept Exercise
• Instrument Drivers: An instrument driver is a set of VIs Learn to configure the NI Instrument Simulator and use

GOAL
specially written to communicate with an instrument MAX to examine the GPIB interface settings, detect
instruments, and communicate with an instrument.

ni.com/training ni.com/training
13 14

F. Instrument I/O Assistant Demonstration

Instrument I/O Assistant

Configure the Instrument I/O Assistant.


GOAL

ni.com/training ni.com/training
15 16

Exercise 9-2: Instrument I/O Assistant G. VISA

• Virtual Instrument Software Architecture (VISA):


− Lower layer of functions in the LabVIEW instrument driver VIs
that communicate with the driver software
− High-level API that calls low-level drivers
− Can control VXI, GPIB, serial, or computer-based instruments
Concept Exercise and makes the appropriate driver calls depending on the type
Configure a serial or GPIB instrument and communicate of instrument used
GOAL

with the instrument using the Instrument I/O Assistant. • If you choose not to use the Instrument I/O Assistant to
automatically generate code for you, you can use VISA
functions instead to communicate with the instrument
ni.com/training ni.com/training
17 18

3
G. VISA – Programming Terminology G. VISA – Serial

• Resource The VISA Configure Serial Port VI initializes the port


Any instrument in the system, including serial and parallel ports identified by VISA resource name to the specified settings
• 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 ni.com/training
19 20

Exercise 9-3: VISA Write and Read VI H. 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
Concept Exercise
Communicate with a serial or GPIB interface to an
GOAL

instrument using VISA functions.

ni.com/training ni.com/training
21 22

H. Instrument Drivers – What Are They? H. Instrument Drivers – Where are they?

• A LabVIEW Plug and Play instrument driver is a set of VIs • You can locate most LabVIEW Plug and Play instrument
that control a programmable instrument drivers in the Instrument Driver Finder
• Each VI corresponds to an instrument operation, such as − Access within LabVIEW by selecting Tools»
configuring, triggering, and reading measurements from the Instrumentation»Find Instrument Drivers or Help»Find
instrument I t
Instrumentt Drivers
Di
• Instrument drivers help you get started using instruments − Connects you with ni.com to find instrument drivers
from a PC, and save you development time and cost • When you install an instrument driver, an example program
because you need not learn the programming protocol for using the driver is added to the NI Example Finder
each instrument

ni.com/training ni.com/training
23 24

4
H. Instrument Drivers – Example Exercise 9-4: NI Devsim VI

To install an instrument driver and explore the example


programs that are installed with the driver.

GOAL
ni.com/training ni.com/training
25 26

Summary—Quiz Summary—Quiz Answer

1. Which instrument interface does not use the VISA API? 1. Which instrument interface does not use the VISA API?
a) Serial a) Serial
b) DAQ b) DAQ
c) GPIB c) GPIB
d) Ethernet d) Ethernet

ni.com/training ni.com/training
27 28

Summary—Quiz Summary—Quiz Answer

2. What API does the Instrument I/O Assistant use? 2. What API does the Instrument I/O Assistant use?
a) C a) C
b) Visual Basic b) Visual Basic
c) VISA c) VISA
d) NI-DAQmx d) NI-DAQmx

ni.com/training ni.com/training
29 30

5
Summary—Quiz Summary—Quiz Answer

3. Which of the following is a way to inform listeners that all 3. Which of the following is a way to inform listeners that all
data has been transferred? data has been transferred?
a) Asserting the End or Identify (EOI) line. a) Asserting the End or Identify (EOI) line.
b) Placing a end-of-string (EOS) character at the beginning b) Placing a end-of-string (EOS) character at the beginning
of the data being transferred. of the data being transferred.
c) Using the VISA Close function. c) Using the VISA Close function.
d) Turning off the power to the controller. d) Turning off the power to the controller.

ni.com/training ni.com/training
31 32

6
Lesson 10 A. Sequential Programming
Common Design Techniques • 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
TOPICS
A. Sequential Programming
B. State Programming
C. State Machines
D. Parallelism

ni.com/training ni.com/training

A. Sequential Programming A. Sequential Programming


To force execution order, use a Sequence structure
Use error clusters to force order of execution • 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 ni.com/training

A. Sequential Programming A. Sequential Programming

• Avoid overusing Sequence structures The best way to write this VI is to enclose the dialog boxes in
• You cannot stop the execution part way through a Case structures, wiring the error cluster to the case selectors
sequence

ni.com/training ni.com/training

1
B. State Programming C. State Machines

Although Sequence structures or sequentially wired subVIs • The state machine design pattern implements a state
accomplish the purpose, it is not always the best choice: diagram or flow chart
• What if you need to change the order of the sequence? • When to use state machines?
• What if yyou need to repeat
p one item in the sequence
q more − Commonly used to create user interfaces, where different
often than the other items? user actions send the user interface into different states
• What if some items in the sequence execute only when − Commonly used for process tests, where a state represents
certain conditions are met? each segment of the process
• What if you need to stop the program immediately, rather
than waiting until the end of the sequence?

ni.com/training ni.com/training

C. State Machines – Infrastructure C. State Machines – Default Transition

• 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

Case Structure ni.com/training ni.com/training


Shift Register

C. State Machines – C. State Machines –


Transition Between Two States Case Structure Transition

ni.com/training ni.com/training

2
C. State Machines –
Demonstration
Transition Array Transition
Course Project

Demonstrate an implementation of a state machine.

GOAL
C:\Exercises\LabVIEW Basics I\Course Project

ni.com/training ni.com/training

Exercise 10-1: State Machine VI D. Parallelism

• Often, you need to program multiple tasks so that they


execute at the same time
• In LabVIEW, tasks can run in parallel if they do not have a
data dependency between them, and if they do not use the
same shared resource
Create a simple state machine using a type-defined − An example of a shared resource is a file, or an instrument
enumerated control and practice the skills learned • You learn about LabVIEW design patterns for executing
GOAL

throughout this course. multiple tasks at the same time in LabVIEW Basics II
− These design patterns include parallel loops and
producer/consumer
ni.com/training ni.com/training

Summary Continuing Your LabVIEW Education

The benefits of using a state machine instead of a sequential • Instructor Led Training
programming structure include: − LabVIEW Basics II: Learn about parallel loops, variables,
• You can change the order of the sequence property nodes and building an executable
• You can repeat
p individual items in the sequence
q − Hardware courses such as Data Acquisition and Signal
P
Processing
i
• You can set conditions to determine when an item in the
− Online courses such as Machine Vision and LabVIEW Real-
sequence should execute
Time
• You can stop the program at any point in the sequence
• Self-Paced: a variety of instructional packages and tools
designed to educate you at your own pace

ni.com/training ni.com/training

3
Courses
New User Experienced User Advanced User
Continue Your Learning
LabVIEW Basics I LabVIEW Intermediate I LabVIEW Advanced I
LabVIEW Basics II LabVIEW Intermediate II
• ni.com/support
Skills learned: Skills learned: Skills learned:
− Access product manuals, KnowledgeBase, example code, • LabVIEW environment • Modular application • Large application design
tutorials, application notes, and discussion forums navigation development • Advanced development
• Basics application creation • Structured design and techniques
− Request technical support using LabVIEW development practices • Implementing multideveloper
• Basics of data acquisition and • Inter-application projects
• Info-LabVIEW: www.info-labview.org instrument control communication and
connectivity techniques
• Alliance Program: ni.com/alliance Certifications

• Publications: ni.com/reference/books/ Certified LV Associate Certified LabVIEW Certified LabVIEW


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

ni.com/training ni.com/training

Please complete the course survey


and retrieve your course CD.
THANK YOU!

ni.com/training

You might also like