Core 1 - Combined Slides With Custom Slideshows

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 417

LabVIEW Core 1

TOPICS

Lesson 1, Slide 1
What You Need to Get Started

• LabVIEW Core 1 Course Manual


• LabVIEW Core 1 Exercise Manual
• LabVIEW Core 1 Course CD
• Multifunction DAQ device*
• BNC-2120, wires, and cable*
• GPIB interface*
• NI Instrument Simulator and power supply*
• GPIB cables*
Computer running
LabVIEW 2012 or later *Required for hardware exercises only
and Windows XP or later

Lesson 1, Slide 2
File Locations

The course installer places the course files in the following


location:

Exercises LabVIEW
Root Directory <or>
Solutions Core 1

Lesson 1, Slide 3
Instructional Methods

Demonstrations

Concept
Quizzes
Exercise

Development
Lecture Topic Exercise

Lesson 1, Slide 4
Getting the Most out of this Course

• Ask questions!
• Experiment with hands-on exercises to understand the
methods used
• Explore solutions
• Implementations explore a possible solution—you may find
a better one

Lesson 1, Slide 5
New User Experienced User Advanced User

LabVIEW Core 1 LabVIEW Core 3 Managing Software


Engineering in LabVIEW
LabVIEW Core 2
Advanced Architectures
LabVIEW Connectivity
in LabVIEW
Object-Oriented Design
and Programming in LabVIEW

LabVIEW Performance
Certifications
Certified LV Associate Certified LabVIEW Certified LabVIEW
Developer Exam Developer Exam Architect Exam

Other Courses

LabVIEW Real-Time 1 LabVIEW Instrument Control LabVIEW FPGA


LabVIEW Real-Time 2 LabVIEW Modular Instruments DAQ & Signal Conditioning

Lesson 1, Slide 6
Course Learning Map
Lesson 1 Lesson 4 Lesson 7
Developing Modular Using Sequential and State
Navigating LabVIEW
Applications Machine Algorithms

Lesson 2 Lesson 5 Lesson 8


Troubleshooting & Debugging Creating and Leveraging Data Solving Dataflow Challenges
VIs Structures with Variables

Lesson 3 Lesson 6
Managing File and Hardware
Implementing a VI
Resources

Lesson 1, Slide 7
Course Goals

This course prepares you to do the following:


• Solve problems using LabVIEW
• Develop, debug, and test LabVIEW VIs
• Use modular programming practices
• Select, create, and leverage common data structures
• Use data acquisition and instrument control in LabVIEW
applications
• Effectively use a state-machine architecture

Lesson 1, Slide 8
Lesson 1
Navigating LabVIEW

TOPICS
A. What Is LabVIEW? F. Searching for Controls, VIs
B. Project Explorer and Functions
C. Parts of a VI G. Selecting a Tool
D. Front Panel H. Dataflow
E. Block Diagram I. Building a Simple VI

Lesson 1, Slide 9
A. What Is LabVIEW?

Lesson 1, Slide 10
What Is LabVIEW?
— A graphical programming environment used to develop
sophisticated measurement, test, and control systems.

LabVIEW:
• Interfaces with wide
variety of hardware
• Scales across
different targets and
OSs
• Provides built-in
analysis libraries

Lesson 1, Slide 11
LabVIEW Language Characteristics

LabVIEW Core 1 LabVIEW Core 2


Topics and Later Topics
• Graphical • Event-driven
• Dataflow-oriented • Multi-threaded
• Compiled • Object-oriented
• Multi-platform • Multi-target
• Synchronous • Memory-
Managed

Lesson 1, Slide 12
B. Project Explorer
Project Explorer Window
Files Types
Project Folders

Lesson 1, Slide 13
Project Explorer

• Find, access, and organize


project files
• Prevent, detect, and resolve
incorrect links
• Deploy or download files to
targets
• Manage code for build options
− Executables, installers, and zip files
• Integrate with source code
control providers

Lesson 1, Slide 14
LabVIEW Files

Common LabVIEW file


extensions:

LabVIEW project —.lvproj


Virtual instrument (VI) — .vi
Custom control — .ctl

Lesson 1, Slide 15
Adding Folders to a Project
• Virtual folder
− Organizes project items and
does not represent files on
disk
• Auto-populating folder
− Adds a directory on disk to the
project
− LabVIEW continuously
monitors and updates the
folder according to changes
made in the project and on
disk

Lesson 1, Slide 16
C. Parts of a VI
Front Panel
Block Diagram
Icon
Connector Pane

Lesson 1, Slide 17
Parts of a VI
VIs have 3 main components:
Icon/Connector pane

Block diagram

Front panel

Lesson 1, Slide 18
Parts of a VI – Front Panel

Front Panel – User interface for the VI

You build the front


panel with
controls (inputs) and
indicators (outputs).

Lesson 1, Slide 19
Parts of a VI – Block Diagram
Block Diagram – Contains the
graphical source code

Front panel objects


appear as terminals
on the block diagram.

Lesson 1, Slide 20
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 appears on the block diagram of another VI.
− A subVI is similar to a subroutine or function in a text-based
programming language.

Lesson 1, Slide 21
Using the Project Explorer and Starting a VI

• Open an existing project.


• Identify the parts of a VI.
• Create a new project.
• Add and remove files and folders.
• Create a new VI.

DEMONSTRATION
D. Front Panel
Controls and Indicators
Object Styles
Object Types
Boolean
Numeric
String
Lesson 1, Slide 23
Front Panel

Lesson 1, Slide 24
Controls and Indicators
Controls Indicators
− Input devices − Output devices
− Knobs, buttons, slides − Graphs, LEDs
− Supply data to the block − Display data the block diagram
diagram acquires or generates

Lesson 1, Slide 25
Front Panel Object Styles

Lesson 1, Slide 26
Numeric Controls and Indicators

The numeric data in a control or indicator can represent


numbers of various types, such as integer or floating-point.

Numeric control
Increment/Decrement buttons

Numeric indicator

Lesson 1, Slide 27
Boolean Controls and Indicators

• The Boolean data type represents data that has only two
options, such as True/False or On/Off.
• Use Boolean controls and indicators to enter and display
Boolean (TRUE/FALSE) values.
• Boolean objects simulate switches, push buttons, and LEDs.

Boolean Boolean
control indicator

Lesson 1, Slide 28
Strings
• The string data type is a sequence of ASCII characters .
• Use string controls to receive text from the user, such as a
password or user name.
• Use string indicators to display text to the user.

Lesson 1, Slide 29
E. Block Diagram
Terminals
Nodes
Wires
Context Help

Lesson 1, Slide 30
Block Diagram

Lesson 1, Slide 31
Block Diagram

Block diagram items:


• Terminals
• Constants
• Nodes
− Functions
− SubVIs
− Structures
• Wires
• Free labels

Lesson 1, Slide 32
Terminals

Same label name

Lesson 1, Slide 33
Terminals for Front Panel Objects

• Terminals are:
– Entry and exit ports that exchange information between the
front panel and block diagram.
– Analogous to parameters in text-based programming
languages.
• Double-click a terminal to locate the corresponding front
panel object.

Lesson 1, Slide 34
View Terminals as Icons

• By default, View as Icon option


enabled.
• Deselect View as Icon for a more
compact view.

Lesson 1, Slide 35
Nodes
Nodes are objects on the block diagram that have inputs
and/or outputs and perform operations when a VI runs.

Nodes

Lesson 1, Slide 36
Function Nodes

• Functions are:
− Fundamental operating elements of LabVIEW.
− Do not have front panels or block diagrams, but do have
connector panes.
− Has a pale yellow background on its icon.
• Double-clicking a function only selects the function.
• Functions do not open like VIs and subVIs.

Lesson 1, Slide 37
SubVI Nodes

• SubVIs :
− Are VIs that you use on the block diagram of another VI.
− Have front panels and block diagrams.
− Use the icon from the upper-right corner of the front panel as
the icon that appears when you place the subVI on a block
diagram.
• When you double-click a subVI, the front panel and block
diagram open.
• Any VI has the potential to be used as a subVI.

Lesson 1, Slide 38
Express VIs
• Express VIs:
− Are a special type of subVI.
− Require minimal wiring because you configure them
with dialog boxes.
− Save each configuration as a subVI.
• Icons for Express VIs appear on the block diagram
as icons surrounded by a blue field.

Lesson 1, Slide 39
Node View Options

Lesson 1, Slide 40
Wires
• Wires transfer data between block diagram objects.
• Wires are different colors, styles, and thicknesses,
depending on their data types.
• A broken wire appears as a dashed
black line with a red X in the middle.

Floating-point Integer String Boolean

Scalar
1-D Array
2-D Array

Lesson 1, Slide 41
Context Help
• Displays basic information
about wires and nodes when
you move the cursor over an
object.
• Can be shown or hidden in
the following ways.
− Select Help»Show Context
Help from the LabVIEW menu.
− Press <Ctrl-H>.
− Click the following button on the
toolbar:

Lesson 1, Slide 42
LabVIEW Help
• Contains detailed descriptions and instructions for most
palettes, menus, tools, VIs, and functions.
• Can be accessed by:
− Selecting Help»
LabVIEW Help from the
menu.
− Clicking the Detailed help
link in the
Context Help window.
− Right-clicking an object
and selecting Help from
the shortcut menu.
Lesson 1, Slide 43
Examples
• LabVIEW includes
hundreds of example
VIs.
• Use NI Example Finder
to browse and search
installed examples.
− Select Help»Find
Examples in the menu.
• Click the example buttons in LabVIEW Help topics.

Lesson 1, Slide 44
Group Exercise 1-1
Concept: Exploring a VI

Identify the parts of an existing VI.


GOAL
Group Exercise 1-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
F. Searching for Controls, VIs, and
Functions
Palettes
Quick Drop
NI Global Search

Lesson 1, Slide 47
Searching for Controls, VIs, and Functions

Ways to find controls, VIs, and functions:


• Search or navigate the palettes.
− Controls palette
− Functions palette
• Search by name of object.
− Quick Drop dialog box
• Search palettes, LabVIEW Help, and ni.com.
− Search text box in toolbar

Lesson 1, Slide 48
Controls Palette

• Contains the controls and


indicators you use to create
the front panel.
• Navigate the subpalettes or
use the Search button to
search the Controls palette.

Lesson 1, Slide 49
Functions Palette

• Contains the VIs, functions,


and constants you use to
create the block diagram.
• Navigate the subpalettes or
use the Search button to
search the Functions palette.

Lesson 1, Slide 50
Searching with Quick Drop

• Lets you quickly find controls,


functions, VIs, and other
items by name.
• Press the <Ctrl-Space> keys
to display the Quick Drop
dialog box.

Lesson 1, Slide 51
Global Search

Use the Search bar in the top right of the front panel and block
diagram windows to search palettes, LabVIEW Help, and
ni.com.

Lesson 1, Slide 52
Search for Controls, VIs, and Functions

• Configure palettes to customize visible palettes.


• Search and navigate the palettes.
• Search for help using global search.
• Use Quick Drop to search by name.

DEMONSTRATION
Exercise 1-2
Concept: Locating Controls, Functions, and VIs

Learn to use the palettes and search for controls, functions


and VIs.
GOAL
Exercise 1-2
Concept: Locating Controls, Functions, and VIs

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


in the Functions palette?
• Why would you use the Quick Drop dialog box instead of the
Search button on the Controls and Functions palettes?

DISCUSSION
G. Selecting a Tool
Selecting a Tool
Block Diagram Clean-Up

Lesson 1, Slide 56
Selecting a Tool

• A tool is a special operating mode of the


mouse cursor.
• Create, modify, and debug VIs using the
tools provided by LabVIEW.
• By default, LabVIEW automatically selects
tools based on the context of the cursor.
• If you need more control, use the Tools
palette to select a specific tool.
− Select View»Tools Palette to open the
Tools palette.

Lesson 1, Slide 57
Wiring Tips
• Press <Ctrl-B> to delete all broken wires.
• Right-click and select Clean Up Wire to reroute the wire.

Lesson 1, Slide 58
Wiring Tips – Clean Up Diagram
Use the Clean Up Diagram tool to reroute multiple wires and
objects and to improve readability.
1. Select a section of your block diagram.
2. Click the Clean Up Diagram button on the block diagram
toolbar.

Lesson 1, Slide 59
Cloning and Moving Items
• Clone an object in LabVIEW using the following steps:
1. Select the Positioning tool.
2. Press the <Ctrl> key while clicking an object.
3. Drag the copy to new location.
• Move an object using the following steps:
1. Select the Positioning tool.
2. Click and drag the object to new location.

Note: Avoid cutting and pasting objects as this can impact related items.
For example, cutting and pasting a block diagram terminal also moves the
front panel object.
Lesson 1, Slide 60
Selecting, Editing, Resizing and Wiring

• Select item to move, copy, or delete


• Edit text
• Resize an object
• Wire terminals and nodes

DEMONSTRATION
Exercise 1-3
Concept: Selecting a Tool

Gain experience using the Automatic Tool Selection to select


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

How do you enable automatic tool selection?

DISCUSSION
H. Dataflow

Lesson 1, Slide 64
Dataflow
LabVIEW follows a dataflow model for running VIs.
• A node executes only when data are available at all of its
required input terminals.
• A node supplies data to the output terminals only when the
node finishes execution.

Lesson 1, Slide 65
Dataflow – Quiz

Which node executes first?


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

Lesson 1, Slide 66
Dataflow – Quiz Answers

No single correct answer.

Which node executes first?


a) Add – Possibly
b) Subtract – Definitely not
c) Random Number – Possibly
d) Divide – Possibly
e) Sine – Definitely not

Lesson 1, Slide 67
Group Exercise 1-4
Concept: Dataflow

Identify dataflow execution order in the following block


diagrams.

GOAL
Group Exercise 1-4
Concept: Dataflow

Which node executes first? Last?


Where are the data dependencies?

DISCUSSION
Group Exercise 1-4
Concept: Dataflow

Which Express VI executes last?

DISCUSSION
Group Exercise 1-4
Concept: Dataflow

Which Express VI executes last?

DISCUSSION
Group Exercise 1-4
Concept: Dataflow

Which Tone Measurement


executes last?

DISCUSSION
I. Building a Simple VI

Lesson 1, Slide 73
Building a Simple VI

Lesson 1, Slide 74
Acquire Express VIs

• DAQ Assistant Express VI

• Instrument I/O Assistant Express VI

• Simulate Signal Express VI

• Read from Measurement File Express VI

Lesson 1, Slide 75
Analyze Express VIs

• Amplitude and Level Measurements Express VI

• Statistics Express VI

• Spectral Measurements Express VI

• Tone Measurements Express VI

• Filter Express VI

Lesson 1, Slide 76
Present Express VIs and Indicators

• Display Message Express VI

• Play Waveform Express VI

• Report Express VI

• Write Measurement File Express VI

• DIAdem Report Express VI

Lesson 1, Slide 77
Building and Running a VI

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.

Lesson 1, Slide 78
Exercise 1-5, Part A – Group Exercise
Simple Acquire, Analyze, and Present Design

Scenario:
• Acquire a sine waveform 0.1 seconds.
• Determine the average value of the waveform.
• Log the data.
• Display the data to a graph.

GOAL
Exercise 1-5, Part A – Group Exercise
Simple Acquire, Analyze, and Present Design

DISCUSSION
Exercise 1-5, Part A – Group Exercise
Simple Acquire, Analyze, and Present Design

Which Express VI would you use for following tasks?


• Acquiring a sine wave from a data acquisition device
• Determining the average value
• Logging data to a file
• Displaying data to a graph
• Displaying average value

DISCUSSION
Exercise 1-5, Part B
Simple Acquire, Analyze, and Present VI

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


presents the results.
GOAL
Exercise 1-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

Lesson 1, Slide 84
Summary—Quiz Answer
1. Which function executes first:
Add or Subtract?
a) Add
b) Subtract
c) Unknown

Lesson 1, Slide 85
Summary—Quiz
2. Which function executes first:
Sine or Divide?
a) Sine
b) Divide
c) Unknown

Lesson 1, Slide 86
Summary—Quiz Answer
2. Which function executes first:
Sine or Divide?
a) Sine
b) Divide
c) Unknown

Lesson 1, Slide 87
Summary—Quiz
3. Which of the following
functions executes first:
Random Number, Add or
Divide?
a) Random Number
b) Divide
c) Add
d) Unknown

Lesson 1, Slide 88
Summary—Quiz Answer
3. Which of the following
functions executes first:
Random Number, Add or
Divide?
a) Random Number
b) Divide
c) Add
d) Unknown

Lesson 1, Slide 89
Summary—Quiz
4. Which of the following
functions executes last:
Random Number, Subtract or
Add?
a) Random Number
b) Subtract
c) Add
d) Unknown

Lesson 1, Slide 90
Summary—Quiz Answer
4. Which of the following
functions executes last:
Random Number, Subtract or
Add?
a) Random Number
b) Subtract
c) Add
d) Unknown

Lesson 1, Slide 91
Summary—Quiz

5. What are the three parts of a VI?


a) Front panel
b) Block diagram
c) Project
d) Icon/Connector pane

Lesson 1, Slide 92
Summary—Quiz Answer

5. What are the three parts of a VI?


a) Front panel
b) Block diagram
c) Project
d) Icon/Connector pane

Lesson 1, Slide 93
Lesson 2
Troubleshooting and Debugging VIs

TOPICS
A. Correcting Broken VIs
B. Debugging Techniques
C. Undefined or Unexpected Data
D. Error Handling

Lesson 2, Slide 1
A. Correcting Broken VIs

Lesson 2, Slide 2
Correcting Broken VIs

Broken Run arrow  VI cannot be compiled  VI cannot be executed

Lesson 2, Slide 3
Common Causes of Broken VIs

• Broken wires exist on the block


diagram.
− 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.

Lesson 2, Slide 4
B. Debugging Techniques
Execution Highlighting
Single-Stepping
Probes
Breakpoints

Lesson 2, Slide 5
Debugging Techniques

What to look for if a VI produces unexpected data or behavior:


• Are there any unwired or hidden subVIs?
• Is the default data correct?
• Does the VI pass undefined data?
• Are numeric representations correct?
• Are node executed in the correct order?

Lesson 2, Slide 6
Execution Highlighting
• Use execution highlighting to watch the data flow through
the block diagram.
• If the VI runs more slowly than expected, confirm that you
turned off execution highlighting in subVIs.

Lesson 2, Slide 7
Single-Stepping
• Single-step through the VI to view each action of the VI on
the block diagram.
• Suspend the execution of a subVI to edit values of controls
and indicators, to control the number of times it runs, or to
go back to the beginning of the execution of the subVI.
− Open subVI and select Operate»Suspend When Called from
the shortcut menu.

Lesson 2, Slide 8
Probes
• Use the Probe tool to observe intermediate data
values and check the error output of VIs
and functions, especially those performing I/O.
• Specify to retain the values in the wires so that
you can probe wires for data after execution.

Lesson 2, Slide 9
Breakpoints
• When you reach a breakpoint during execution, the
VI pauses and the Pause button appears red.
• You can take the following actions at a breakpoint:
− Single-step through execution using the single-stepping buttons.
− Probe wires to check intermediate values.
− Change values of front panel controls.
− Click the Pause button to continue running to the next breakpoint
or until the VI finishes running.

Lesson 2, Slide 10
C. Undefined or Unexpected Data

Lesson 2, Slide 11
Undefined or Unexpected Data
Check for unexpected Inf values or NaN values in your
mathematical operations:
• ∞ (Inf)
− Infinity
− Produced by dividing a number by zero.
• NaN
− Not a number
− Produced by invalid operations, such as taking the square root
of a negative number.

Lesson 2, Slide 12
Exercise 2-1
Concept: Debugging

Use the debugging tools built into LabVIEW.


GOAL
Exercise 2-1
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
D. Error Handling
Automatic and Manual Error Handling
Merge Errors Function
Error Clusters
Warnings

Lesson 2, Slide 15
Error Handling
Error Handling – Anticipation, detection,
and resolution of warnings and errors
• You cannot predict every problem a user can encounter.
• Without a mechanism to check for errors, you know only that
the VI does not work properly.
• Error handling tells you why and where errors occur.
− Automatic error handling
− Manual error handling

Lesson 2, Slide 16
Automatic Error Handling
• By default, LabVIEW automatically handles any known error
when a VI runs by:
− Suspending execution.
− Highlighting the subVI or function where the error occurred.
− Displaying the Error list window.
• Automatic error handling is:
− Acceptable for quick prototypes.
− Not recommended for professional application development.
− Not included in LabVIEW-built executables.

Lesson 2, Slide 17
Manual Error Handling
• You control when dialog boxes appear.
• Propagate errors by wiring the error out cluster to error in
cluster of next node to execute.
• Terminate the error chain with a call to Simple Error Handler
VI.

Lesson 2, Slide 18
Automatic vs. Manual Error Handling

Demonstrate the difference between automatic and manual


error handling.

DEMONSTRATION
Disable Automatic Error Handling
• Options Dialog Box
− Block Diagram page
• Uncheck
− Enable automatic error handling in new VIs
− Enable automatic error handling dialogs
• Other suggested changes
− Front Panel page
• Set Control Style for New VIs to Silver style
− Block Diagram page
• Uncheck
− Place front panel terminals as icons
• Configure Block Diagram Cleanup to customize your block diagram

Lesson 2, Slide 20
Merge Errors

• Propagate errors along wires.


• Merge errors from different wire paths.

Lesson 2, Slide 21
Merge Errors Function
• Merge Errors function returns the first error found. If no error
is found, it returns the first warning.
• The Merge Errors function does not concatenate errors.

Lesson 2, Slide 22
Error Clusters
• Use the error cluster controls and indicators to create error
inputs and outputs in subVIs.
• The error in and error
out clusters include the
following components
of information:
− Status
− Code
− Source

Lesson 2, Slide 23
Errors and Warnings
Status = FALSE
Status = TRUE Code = Non-zero

Error Warning
Lesson 2, Slide 24
Errors and Warnings Recommendations

• Report errors and warnings with the Simple Error Handler VI


− Modify Type of Dialog to detect warnings.
• Call the Simple Error Handler VI from the top-level VI.
• Avoid error dialogs in subVIs.

Lesson 2, Slide 25
Summary—Quiz

1. Which of the following will result in a broken run arrow?


a) A subVI is broken.
b) The diagram includes a divide by zero.
c) A required subVI input is unwired.
d) A Boolean terminal is wired to a numeric indicator.

Lesson 2, Slide 26
Summary—Quiz Answer

1. Which of the following will result in a broken run arrow?


a) A subVI is broken.
b) The diagram includes a divide by zero.
c) A required subVI input is unwired.
d) A Boolean terminal is wired to a numeric indicator.

Lesson 2, Slide 27
Summary—Quiz

2. Which of the following are the components and data types


of the error cluster?
a) Status: Boolean
b) Error: String
c) Code: 32-bit integer
d) Source: String

Lesson 2, Slide 28
Summary—Quiz Answer

2. Which of the following are the components and data types


of the error cluster?
a) Status: Boolean
b) Error: String
c) Code: 32-bit integer
d) Source: String

Lesson 2, Slide 29
Summary—Quiz

3. All errors have negative error codes and all warnings have
positive error codes.
a) True
b) False

Lesson 2, Slide 30
Summary—Quiz Answer

3. All errors have negative error codes and all warnings have
positive error codes.
a) True
b) False

Lesson 2, Slide 31
Summary—Quiz

4. Merge Errors function concatenates error information from


multiple sources.
a) True
b) False

Lesson 2, Slide 32
Summary—Quiz Answer

4. Merge Errors function concatenates error information from


multiple sources.
a) True
b) False

Lesson 2, Slide 33
Lesson 3
Implementing a VI

TOPICS
A. Front Panel Basics F. Timing a VI
B. LabVIEW Data Types G. Data Feedback in Loops
C. Documenting Code H. Plotting Data – Waveform Chart
D. While Loops I. Case Structures
E. For Loops

Lesson 3, Slide 1
A. Front Panel Basics

Lesson 3, Slide 2
Front Panel Basics

Front panel controls and indicators create terminals on the


block diagram.

Lesson 3, Slide 3
B. LabVIEW Data Types
Shortcut Menu and Properties Dialog Box
Numeric Types
Boolean Types
String Types
Enums and Other Types

Lesson 3, Slide 4
LabVIEW Data Types

Terminals visually communicate information about the data


type represented

Lesson 3, Slide 5
Shortcut Menus
• All LabVIEW objects have
associated shortcut
menus.
• Use shortcut menu items
to change the look or
behavior of objects.
• To access the shortcut
menu, right-click the
object.

Lesson 3, Slide 6
Properties Dialog Box
• All LabVIEW objects have
properties.
• To access properties,
right-click the object and
select Properties.
• Property options are
similar to shortcut menu
options.
• Select multiple objects to
simultaneously configure
shared properties.

Lesson 3, Slide 7
Numerics
Various data type
representations:
• Floating-point
• Unsigned integers
• Signed integers

Lesson 3, Slide 8
Numeric Conversion Coercion Dot

• Coercion dots indicate that LabVIEW


converted the value passed into a node to
a different representation.
− Occurs when a node expects an input with a
different representation.
• LabVIEW chooses the representation that
uses more bits.
• Avoid coercion by programmatically
converting to a matching data type.

Lesson 3, Slide 9
Booleans
• Behavior of Boolean
controls is specified by the
mechanical action.
• Boolean have only
TRUE/FALSE values.

Lesson 3, Slide 10
Mechanical Action of Booleans

Lesson 3, Slide 11
Mechanical Action of Booleans

Use the Properties»Operations tab of a Boolean control to


learn about the different switch and latch actions.

DEMONSTRATION
Strings
• A string is a sequence
of ASCII characters.
• Strings have various
display styles.
− Backslash codes
− Password
− Hex

Lesson 3, Slide 13
Enums
• Enums give users a list of
items from which to
select.
• Each item represents a
pair of values.
− String
− 16-bit Integer

Lesson 3, Slide 14
Other Data Types
Refer to LabVIEW Help for complete list of terminal symbols
for different types of controls and indicators.
• Dynamic
− Stores the information generated or acquired by an Express VI.
• Path
− Stores the location of a file or directory using the standard
syntax for the platform you are using.
• Waveform
− Carries the data, start time, and dt of a waveform.

Lesson 3, Slide 15
Searching Help for Data Types

Use LabVIEW Help to learn about LabVIEW data types.

DEMONSTRATION
C. Documenting Code
VI Descriptions
Tip Strips
Labels
Free
Owned

Lesson 3, Slide 17
Documenting Code

VI Front Panel Block Diagram

• Name • Label Names • Label Names


• Description • Tip Strips • Free Labels
• Descriptions • Owned
• Free Labels Labels
• SubVI
Descriptions

Lesson 3, Slide 18
Creating Descriptions and Tip Strips

Use the Properties


dialog box to create
documentation for
an object.

Lesson 3, Slide 19
Documenting Block Diagram Code
Free labels: Owned labels:
• Describe algorithms. • Explain data contents of wires
• Have pale yellow backgrounds. and objects.
• Double-click in any open space • Move with object.
to create. • Have transparent
backgrounds.
• Select Visible Items»Label
from the shortcut menu to
create.

Lesson 3, Slide 20
Exercise 3-1
Temperature Warnings VI

Create and document a VI.


GOAL
Exercise 3-1
Temperature Warnings VI

What happens if the Max. Temperature value is lower than the


Min. Temperature value?

DISCUSSION
D. While Loops
Iteration and Conditional Terminals
Tunnels
Error Checking

Lesson 3, Slide 23
While Loops

Repeat (code);
Until Condition met;
End;

LabVIEW While Loop Flowchart Pseudo Code

Lesson 3, Slide 24
While Loops
Iteration terminal Conditional terminal
• Returns number of times loop • Defines when the loop stops.
has executed. • Has two options.
• Is zero-indexed. − Stop if True
− Continue if True

Iteration Terminal Conditional Terminal

Lesson 3, Slide 25
While Loops – Tunnels
• Tunnels transfer data into and out of structures.
• Data pass out of a loop after the loop terminates.
• When a tunnel passes
data into a loop, the loop
executes only after
data arrive at the tunnel.

Lesson 3, Slide 26
While Loops – Error Checking and Error Handling
Use an error cluster in a While Loop to stop the While Loop if
an error occurs.

Lesson 3, Slide 27
Exercise 3-2
Auto Match VI

Use a While Loop and an iteration terminal and pass data


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

How many times is the Number of Iterations indicator


updated? Why?

DISCUSSION
E. For Loops
Conditional Terminal
Comparison with While Loops
Numeric Conversion for Count Terminal

Lesson 3, Slide 30
For Loops

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

LabVIEW For Loop Flowchart Pseudo Code

Lesson 3, Slide 31
For Loops

• Create a For Loop the same way you create a While Loop.
• You can replace a While Loop with a For Loop by right-
clicking the border of the While Loop and selecting
Replace with For Loop from the shortcut menu.
• The value in the count terminal (an input terminal)
indicates how many times to repeat the subdiagram
in the For Loop.

Lesson 3, Slide 32
For Loops – Conditional Terminal
You can add a conditional terminal to configure a For Loop to
stop when a Boolean condition is true or an error occurs.

Lesson 3, Slide 33
For Loops – Conditional Terminal
For Loops configured with a conditional terminal have:
• A red glyph next to the count terminal.
• A conditional terminal in the lower right corner

Lesson 3, Slide 34
For Loop/While Loop Comparison
For Loop While Loop
• Executes a set number of times • Stops executing only if the value
unless a conditional terminal is at the conditional terminal meets
added. the condition.
• Can execute zero times. • Must execute at least once.
• Tunnels automatically output an • Tunnels automatically output the
array of data. last value.

Lesson 3, Slide 35
For Loops – Numeric Conversion
• The number of iterations a For Loop executes must be specified in
non-negative integers.
• If you wire a double-precision, floating-point numeric value to the
count terminal, LabVIEW converts the numeric value to a 32-bit
signed integer.

Lesson 3, Slide 36
Group Exercise 3-3
Concept: While Loops versus For Loops

Understand when to use a While Loop and when to use a For


Loop.
GOAL
F. Timing a VI
Reasons To Use Timing
Wait Functions and Express VIs

Lesson 3, Slide 38
Timing a VI

Why do you need timing in a VI?


• To control the frequency at which a loop executes.
• To provide the processor with time to complete other tasks,
such as processing the user interface.

Lesson 3, Slide 39
Wait Functions
A wait function inside a loop:
• Allows the VI to sleep for a set amount of time.
• Allows the processor to address other tasks during the wait
time.
• Uses the operating system millisecond clock.

Lesson 3, Slide 40
Elapsed Time Express VI
• Determines how much time elapses after some point in
your VI.
• Keeps track of time while the VI continues to execute.
• Does not provide the processor with
time to complete other tasks.

Lesson 3, Slide 41
Wait Chart VI

Compare and contrast using a Wait function and the Elapsed


Time Express VI for software timing.

DEMONSTRATION
G. Data Feedback in Loops
Shift Registers
Initializing Shift Registers
Default for Unwired Values
Compound Shift Registers

Lesson 3, Slide 43
Data Feedback in Loops
• When programming with loops, you often need to know the
values of data from previous iterations of the loop.
• Shift registers transfer values from one loop iteration to the
next.

Lesson 3, Slide 44
Shift Registers
• Right-click the border and select Add Shift Register from
the shortcut menu.
• Right shift register stores data on completion of an iteration.
• Left shift register provides stored data at beginning of the
next iteration.

Lesson 3, Slide 45
Initializing Shift Registers
Run once VI finishes Run again

Block Diagram 1st run 2nd run


Initialized
Shift Output = 5 Output = 5
Register

Not
Initialized Output = 4 Output = 8
Shift
Register

Lesson 3, Slide 46
Use Default if Unwired

Default values vary by data type:


Data Type Default Value

Numeric 0

Boolean FALSE

String Empty

Uninitialized shift registers use default values for first run.

Lesson 3, Slide 47
Multiple Previous Iterations
• Stacked shift registers remember values from multiple
previous iterations and carry those values to the next
iterations.
• Right-click the left shift register and select Add Element
from the shortcut menu to stack a shift register.

Lesson 3, Slide 48
Exercise 3-4
Average Temperature VI

Use a While Loop and shift registers to average data.


GOAL
Exercise 3-4
Average Temperature VI

You calculated the average of the last 5 temperature readings.


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

DISCUSSION
H. Plotting Data – Waveform Chart

Lesson 3, Slide 51
Plotting Data – Waveform Chart
• Waveform chart
is a special type
of numeric
indicator.
• Waveform charts
display single or
multiple plots.

Lesson 3, Slide 52
Waveform Chart Properties
Extensive plot
customization lets you:
• Show or hide legends.
• Change color and line
styles.
• Change interpolation
styles.

Lesson 3, Slide 53
Exercise 3-5
Temperature Monitor VI – Plot Multiple
Temperatures

Plot multiple data sets on a single waveform chart and


customize the chart view.
GOAL
Exercise 3-5
Temperature Monitor VI – Plot Multiple
Temperatures

In what ways do the following tools allow the user to interact with
the plot?
• Plot Legend
• Graph Palette
• Scale Legend

DISCUSSION
I. Case Structures
Parts of a Case Structure
Enum Case Structures
Error Case Structures
Input and Output Tunnels

Lesson 3, Slide 56
Case Structures
• Have two or more subdiagrams or cases.
• Use an input value to determine which case to execute.
• Execute and display only one case at a time.
• Are similar to case statements or if...then...else statements
in text-based programming languages.

Lesson 3, Slide 57
Case Structures
• Case Selector Label
− Contains the name of the current
case.
Case Selector Label
− Has decrement and increment
arrows.
• Selector Terminal
− Lets you wire an input value, or
selector, to determine which
case executes.

Selector Terminal
Lesson 3, Slide 58
Case Structures
Selector terminal data types:
• Boolean
− True case and False Case
• Error Cluster
− Error Case and No Error Case
• Integer, string, or enum
− Structure can have any
number of cases.
− Include a Default diagram to
avoid listing every possible
input value.

Lesson 3, Slide 59
Enum Case Structure
• Gives users a list of items from which to select
• The case selector displays a case for each item in the
enumerated type control

Lesson 3, Slide 60
Shortcut Menu
Use the shortcut menu of a
Case structure to:
− Customize the structure and
diagrams.
− Remove or replace the
structure.
− Add, duplicate, remove, or
rearrange cases.
− Specify the Default case.
− Switch cases.

Lesson 3, Slide 61
Error Case Structure
Use Case structures inside VIs to execute the code if there is
no error and skip the code if there is an error.

Lesson 3, Slide 62
Input and Output Tunnels
You can create multiple input and output tunnels.
• Inputs tunnels are available to all cases if needed.
• You must define each output tunnel for each case.

Lesson 3, Slide 63
Case Structures

• Create case structures using different data type selectors.


• Add, remove, and duplicate cases.
• Create different type of output tunnels.

DEMONSTRATION
Exercise 3-6
Temperature Warnings VI

Modify a VI to use Case structures to make a software


decision.
GOAL
Exercise 3-6
Temperature Warnings VI

• What happens if all the values are 10? How could you fix
this?
• Are all output tunnels defined? What happens if an output
is not defined?

DISCUSSION
Summary—Quiz
1. If an input to a function is marked with a red dot (known
as a coercion dot), what does the dot indicate?
a) Data was transferred into a structure.
b) A For Loop was configured with a conditional terminal.
c) A For Loop iteration terminal is unwired.
d) The value passed into a node was converted to a
different representation.

Lesson 3, Slide 67
Summary—Quiz Answer
1. If an input to a function is marked with a red dot (known
as a coercion dot), what does the dot indicate?
a) Data was transferred into a structure.
b) A For Loop was configured with a conditional terminal.
c) A For Loop iteration terminal is unwired.
d) The value passed into a node was converted to a
different representation.

Lesson 3, Slide 68
Summary—Quiz

2. Which structure must run at least one time?


a) While Loop
b) For Loop

Lesson 3, Slide 69
Summary—Quiz Answer

2. Which structure must run at least one time?


a) While Loop
b) For Loop

Lesson 3, Slide 70
Summary—Quiz

3. Which is only available on the block diagram?


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

Lesson 3, Slide 71
Summary—Quiz Answer

3. Which is only available on the block diagram?


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

Lesson 3, Slide 72
Summary—Quiz

4. Which mechanical action causes a Boolean control in the


FALSE state to change to TRUE when you click it and stay
TRUE until LabVIEW has read the value?
a) Switch Until Released
b) Switch When Released
c) Latch Until Released
d) Latch When Released

Lesson 3, Slide 73
Summary—Quiz Answer

4. Which mechanical action causes a Boolean control in the


FALSE state to change to TRUE when you click it and stay
TRUE until LabVIEW has read the value?
a) Switch Until Released
b) Switch When Released
c) Latch Until Released
d) Latch When Released

Lesson 3, Slide 74
Lesson 4
Developing Modular Applications

TOPICS
A. Understanding Modularity
B. Icon
C. Connector Pane
D. Using SubVIs

Lesson 4, Slide 1
A. Understanding Modularity

Lesson 4, Slide 2
Understanding Modularity

Modularity — The degree to which a program is


composed of discrete modules such that a change to
one module has minimal impact on other modules

LabVIEW uses subVIs to create modularity.

Lesson 4, Slide 3
Understanding Modularity – SubVIs

SubVI — A VI within another VI

• 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 a
block diagram.

Lesson 4, Slide 4
Understanding Modularity – SubVIs

Repeated code can become subVIs.

Lesson 4, Slide 5
Understanding Modularity – SubVIs

Lesson 4, Slide 6
Understanding Modularity – SubVIs
Function Code Calling Program Code
function average (in1, in2, main
out) {
{ average (point1, point2,
out = (in1 + in2)/2.0; pointavg)
} }

SubVI Block Diagram Calling VI Block Diagram

Lesson 4, Slide 7
B. Icon
Characteristics of a Good Icon
Using the Icon Editor

Lesson 4, Slide 8
Icon

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

Lesson 4, Slide 9
Characteristics of a Good Icon
Good icons convey the functionality of the VI using:
− Relevant graphics
− Descriptive text, if necessary

Lesson 4, Slide 10
Creating Icons - Icon Editor
Open the Icon Editor using one of these methods:
− Right-click the icon in the upper-right corner of the front panel
or block diagram and select Edit Icon.
− Double-click the icon.

Lesson 4, Slide 11
Icon Editor
Use the editing tools to modify an icon manually.

Lesson 4, Slide 12
Icon Editor
Use the Glyphs tab to display glyphs you can include in the icon.

Lesson 4, Slide 13
Icon Editor
Use the Icon Text tab to specify the text to display in the icon.

Lesson 4, Slide 14
Icon Editor
Use the Templates tab to display icon templates you can use as a
background for the icon.

Lesson 4, Slide 15
C. Connector Pane
Patterns
Standards

Lesson 4, Slide 16
Connector Pane

• The connector pane is displayed


next to the icon in the upper
right corner of the front panel.
− 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.

Lesson 4, Slide 17
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.

Lesson 4, Slide 18
D. Using SubVIs
Using on Block Diagram
Terminal Settings
Handling Errors
Creating from a Section of Block Diagram

Lesson 4, Slide 19
Using SubVIs

Options to place a subVI on the block diagram:


• Drag the VI from the Project Explorer to the block diagram.
• Click Select a VI on the Functions palette and then
navigate to the VI.
• Drag the icon from an open VI to the block diagram of
another VI.

Lesson 4, Slide 20
Terminal Settings

• Bold
− Required terminal
• Plain
− Recommended
terminal
• Dimmed
− Optional terminal

Lesson 4, Slide 21
Handling Errors
Use a Case structure to handle errors passed into the subVI.

Lesson 4, Slide 22
Handling Errors
Avoid using LabVIEW error handler VIs inside subVIs.

Lesson 4, Slide 23
Convert a Section of a VI to SubVI
To convert a section of a VI into a subVI:
1. Use the Positioning tool to select the section of the block
diagram you want to reuse.
2. Select Edit»Create SubVI.

Lesson 4, Slide 24
Exercise 4-1
Temperature Warnings VI

Create the icon and connector pane for a VI so you can use
the VI as a subVI. Call the subVI from a test VI.
GOAL
Exercise 4-1
Temperature Warnings VI

• Do the terminal names in the calling VI need to match the


subVI terminal names?
• Do the data types in the calling VI need to match the subVI
terminal data types?

DISCUSSION
Summary—Quiz

1. On a subVI, which terminal setting causes a broken VI if


the terminal is not wired?
a) Required
b) Recommended
c) Optional

Lesson 4, Slide 27
Summary—Quiz Answer

1. On a subVI, which terminal setting causes a broken VI if


the terminal is not wired?
a) Required
b) Recommended
c) Optional

Lesson 4, Slide 28
Summary—Quiz

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


a) True
b) False

Lesson 4, Slide 29
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.

Lesson 4, Slide 30
Lesson 5
Creating and Leveraging Data Structures

TOPICS
A. Arrays
B. Common Array Functions
C. Polymorphism
D. Auto-Indexing
E. Clusters
F. Type Definitions

Lesson 5, Slide 1
A. Arrays
1D and 2D Arrays
Creating an Array Control and Constant
Initializing Arrays

Lesson 5, Slide 2
Arrays
An array:
• Is a collection of data elements
that are of same type.
• Has one or more dimensions.
• Contains up to (231)–1 elements
per dimension, memory
permitting.
• Accesses elements by its index.
Note: The first element is index 0.

Lesson 5, Slide 3
Arrays – 1D and 2D Examples

ID array
One row of 10-elements
0 1 2 3 4 5 6 7 8 9
1.2 3.2 8.2 8.0 4.8 5.1 6.0 1.0 2.5 1.7

Index
2D array
Five-row by seven-column table of 35 numbers
elements
0 1 2 3 4 5 6
0
1
2
3
4

Lesson 5, Slide 4
Why Use Arrays?

Use arrays when you work with a collection of similar data and
when you perform repetitive computations.

Lesson 5, Slide 5
Viewing Arrays on the Front Panel
The elements at First element
Second
index 0 are not at index 1 element at
shown because index 2
element 1 is selected
in the index display.

The element selected in the index display always refers to the


element shown in the upper-left corner of the element display.

Lesson 5, Slide 6
Creating an Array Control
For a new array:
1. Select an Array control from the
Controls palette on the front panel.
2. Place a data object, such as a
numeric control, into the array
shell.
3. Add a second dimension, if necessary, by
resizing the index.
From a block diagram terminal or wire:
1. Right-click the object and select Create»Control
or Create»Indicator.

Lesson 5, Slide 7
Creating an Array Constant
For a new array:
1. Select Array Constant from the Functions
palette on the block diagram.
2. Place a constant, such as a numeric,
into the array shell.
3. Add a second dimension, if necessary, by
resizing the index.
From a block diagram terminal or wire:
1. Right-click and select Create»Constant.

Lesson 5, Slide 8
Initializing Arrays
• You can initialize an array or leave it uninitialized.
• For initialized arrays, you define the number of elements in
each dimension and the contents of each element.
• Uninitialized arrays have dimension but no elements.

Lesson 5, Slide 9
2D Arrays

• 2D arrays:
− Store elements in a grid.
− Require a column index and a row index to locate an element,
both of which are zero-based.
• Create a multidimensional array on the front panel by right-
clicking the index display and selecting Add Dimension
from the shortcut menu.
• Resize the index display until you have as many dimensions
as you want.

Lesson 5, Slide 10
B. Common Array Functions
Array Size
Initialize Array
Array Subset
Build Array
Index Array

Lesson 5, Slide 11
Common Array Functions

• Array Size
• Initialize Array
• Array Subset
• Build Array
• Index Array

Lesson 5, Slide 12
Array Size

Lesson 5, Slide 13
Initialize Array

Lesson 5, Slide 14
Array Subset

Lesson 5, Slide 15
Build Array

Lesson 5, Slide 16
Index Array

Lesson 5, Slide 17
C. Polymorphism

Lesson 5, Slide 18
Polymorphism
Polymorphism - The ability of VIs and functions to
automatically adapt to accept input data of different
data types

Functions are polymorphic to varying degrees:


• None, some, or all of their inputs can be polymorphic.
• Some accept numeric or Boolean values.
• Some accept numeric or strings.
• Some accept scalars, numeric arrays, or clusters of
numerics.

Lesson 5, Slide 19
Arithmetic Functions Are Polymorphic
Combination Result

Lesson 5, Slide 20
D. Auto-Indexing
Use in For Loops and While Loops
Waveform Graphs
Auto-Indexing with a Conditional Terminal
Creating 2D Arrays
Auto-Indexing Input to a Loop

Lesson 5, Slide 21
Auto-Indexing Auto-Indexing Enabled

Wire becomes thicker


• Allows For Loops and While
Loops to accumulate arrays at
their boundaries.
1D Array
• Is the default behavior for
For Loops. 0 1 2 3 4 5

• Is disabled by default for Auto-Indexing Disabled


While Loops.
Wire remains the same size
• Is enabled/disabled by right-
clicking on a tunnel.
• Produces arrays that are always
equal in size to the number of Only one value (last
iteration) is passed out of
iterations of the loop. the loop

Lesson 5, Slide 22
Waveform Graph
• Is a graphical display of data.
• Displays one or more plots of
evenly sampled measurements.
• Is used to plot pre-generated
arrays of data.
• Can display plots with any
number of data points.

Lesson 5, Slide 23
Charts vs. Graphs – Single-Plot

Lesson 5, Slide 24
Auto-Indexing with a Conditional Tunnel

Right-click on a tunnel and select


Tunnel Mode»Conditional.

Lesson 5, Slide 25
Creating 2D Arrays

1D Array 2D Array

0 1 2 3 4 5

• Inner loop creates column elements.


• Outer loop stacks column elements into rows.

Lesson 5, Slide 26
Auto-Indexing Input
If the iteration count terminal is wired and arrays of different
sizes are wired to auto-indexed tunnels, the actual number of
iterations becomes the smallest of the choices.

Lesson 5, Slide 27
Auto-Indexing Input
Use an auto-indexing input array to perform calculations
on each element in an array.
• Wire an array to an auto-indexing tunnel on a For Loop.
• You do not need to wire the count (N) terminal.
− The For Loop executes
the number of times
equal to the
number of
elements in the array.
− The Run button is not broken.

Lesson 5, Slide 28
Exercise 5-1
Concept: Manipulating Arrays

Manipulate arrays using various LabVIEW functions.


GOAL
Exercise 5-1
Concept: Manipulating Arrays

• In the All Data Channel case, how can you verify that the
two approaches yield the same results?
– Polymorphic Add of array + scalar
– Auto-indexed array elements added to scalar

DISCUSSION
E. Clusters
Reasons To Use Clusters
Cluster vs. Arrays
Creating a Cluster Control and Constant
Ordering Items and Resizing Clusters
Disassembling and Modifying Clusters
Plotting Data
Lesson 5, Slide 31
Clusters
• Clusters group data elements of mixed types.
• Clusters are similar to a record or a struct in text-based
programming languages.

Lesson 5, Slide 32
Why Use Clusters?
• Keep data organized.
− Logically group related data values together.
− Improve diagram readability by eliminating wire clutter.
• Reduce the number of connector pane terminals.

Lesson 5, Slide 33
Clusters vs. Arrays
• Clusters are a fixed size. • Arrays vary in size.
• Clusters can contain mixed • Arrays contain only one data
data types. type.
• Clusters can be a control, an • Arrays can be a control, an
indicator, or a constant. indicator, or a constant.
− All elements have to be controls,
indicators, or constants.

Lesson 5, Slide 34
Create a Cluster Control
For a new cluster:
1. On the front panel, select Cluster
from the Controls palette.
2. Place a data object into the
cluster shell.
3. Place additional data objects,
if necessary, into the shell.
From block diagram terminal or wire:
1. Right-click and select Create»Control or Create»Indicator.

Lesson 5, Slide 35
Create a Cluster Constant
For a new cluster:
1. On the block diagram, select Cluster
Constant from the Functions palette.
2. Place a constant into the cluster shell.
3. Place additional data objects, if
necessary, into the cluster shell.
From block diagram terminal or wire:
1. Right-click and select Create»Constant.

Lesson 5, Slide 36
Cluster Order
• Cluster elements have a logical
order unrelated to their position
in the shell.
• You can view and modify the
cluster order by right-clicking
the cluster border and
selecting Reorder Controls
In Cluster.

Lesson 5, Slide 37
Autosizing Clusters
• Autosizing helps you
arrange elements in
clusters.
• NI recommends the
following:
− Arrange cluster elements
vertically.
− Arrange elements compactly.
− Arranges elements in their
preferred order.

Lesson 5, Slide 38
Disassembling a Cluster
• Use the Unbundle By Name function whenever possible.
• Use Unbundle function when some or all cluster elements
are unnamed.

Lesson 5, Slide 39
Modifying a Cluster
• Use Bundle By Name whenever possible to access
elements in a cluster.
• Use Bundle when some or all cluster elements are
unnamed.

You must
wire the
input
cluster
terminal.

Lesson 5, Slide 40
Creating a Cluster on the Diagram
• Use the Bundle function to programmatically create a
cluster on a block diagram.
• If the elements that are bundled have labels, you can
access them using the Unbundle By Name function.
Otherwise use the Unbundle function.

Lesson 5, Slide 41
Charts vs. Graphs – Multi-plot and XY Graph

Lesson 5, Slide 42
Plotting Data
Use the Context Help window to determine how to wire
multi-plot data to Waveform Graphs, Charts and XY Graphs.

Lesson 5, Slide 43
Error Clusters
• LabVIEW uses error clusters to pass error information.
• An error cluster contains the following elements:
− status—Boolean value that reports True if an error occurs.
− code—32-bit signed integer that identifies the error.
− source—String that identifies where the error occurred.

Lesson 5, Slide 44
Exercise 5-2
Temperature Warnings – Clusters

Create clusters, reorder clusters, and use the cluster functions


to assemble and disassemble elements.
GOAL
Exercise 5-2
Temperature Warnings – Clusters

• What would happen if you reordered cluster elements?


• What would happen if you added a cluster element to
Weather Data Out?

DISCUSSION
F. Type Definitions
Type Definitions and Custom Data Types
Creating and Identifying Type Definitions
Controls
Strict Type Definitions

Lesson 5, Slide 47
Type Definitions (Type Def)
• A type definition is a master copy of a custom data type
(control, indicator, or constant).
− A custom data type is saved in a .ctl file.
− Instances of a type def are linked to the .ctl file.
• Instances can be controls, indicators, or constants.
• When the type def changes, instances automatically update.
− Changes include data type changes, elements added,
elements removed, and adding items to an enum.

Lesson 5, Slide 48
Creating Type Definitions (Type Def)
1. Right-click a control, indicator or constant and select
Make Typedef.
2. Right-click the object again and select Open Type Def.
3. Edit control, if needed.
4. Save control as a .ctl file.

Lesson 5, Slide
Identifying Type Definitions (Type Def)
• Look for a glyph marking the upper left corner of terminals
and constants.
• Hover cursor over glyph to view tip strip.
• View Context Help while hovering cursor over terminal or
constant.

Lesson 5, Slide
Other Control Options
You can save a custom control as:
• Control
• Type Definition
• Strict Type Definition

Lesson 5, Slide 51
Control
• Instances are not linked to a.ctl file.
• Each instance is an independent copy of the control.
• Used to create controls that behave like existing controls but
look different.

Lesson 5, Slide 52
Strict Type Definition
• Strict type definitions are similar to a type definition in that:
− All instances link to .ctl file.
− When attributes or data types change, all instances update.
• Examples: Changing a knob to a dial, a round LED to a square
LED, or a double to an integer.
• Strict type definitions enforce every aspect of a instance
except label, description, and default value.
• Use strict type definitions to ensure all front panel instances
have the same appearance.

Lesson 5, Slide 53
Exercise 5-3
Weather Warnings – Type Definition

Create and modify a type-defined cluster control. Use the


type definition in a calling VI and a subVI.
GOAL
Exercise 5-3
Weather Warnings – Type Definition

Now that the Weather Data control is saved as a type


definition, how many instances of the cluster would need to be
updated to add wind speed data?

DISCUSSION
Summary—Quiz
1. You can create an array of arrays.
a) True
b) False

Lesson 5, Slide 56
Summary—Quiz Answer
1. You can create an array of arrays.
a) True
b) False

You cannot drag an array data type into an array


shell. However, you can create two-dimensional
arrays.

Lesson 5, Slide 57
Summary—Quiz
2. What is the value of the Iterations indicator
after running this VI?

Lesson 5, Slide 58
Summary—Quiz Answer
2. What is the value of the Iterations indicator
after running this VI?
4

Lesson 5, Slide 59
Summary—Quiz
3. Which of the following custom control settings defines the
data type of all instances of a control but allows for
different colors and font styles?
a) Control
b) Type definition
c) Strict type definition
d) Cluster control

Lesson 5, Slide 60
Summary—Quiz Answer
3. Which of the following custom control settings defines the
data type of all instances of a control but allows for
different colors and font styles?
a) Control
b) Type definition
c) Strict type definition
d) Cluster control

Lesson 5, Slide 61
Summary—Quiz
4. You have input data representing a circle: X Position, Y Position,
and Radius. In the future, you might need to modify your data to
include the color of the circle.
What data structure should you use to represent the circle in your
application?
a) Three separate controls for the two positions and the radius
b) A cluster containing all of the data (X,Y)
c) A custom control containing a cluster
d) A type definition containing a cluster
e) An array with three elements R

Lesson 5, Slide
Summary—Quiz Answer
4. You have input data representing a circle: X Position, Y Position,
and Radius. In the future, you might need to modify your data to
include the color of the circle.
What data structure should you use to represent the circle in your
application?
a) Three separate controls for the two positions and the radius
b) A cluster containing all of the data (X,Y)
c) A custom control containing a cluster
d) A type definition containing a cluster
e) An array with three elements R

Lesson 5, Slide
Lesson 6
Managing File and Hardware Resources

TOPICS
A. Understanding File and Hardware Resources
B. File I/O
C. Acquiring Measurements with a DAQ System
D. Controlling Instruments

Lesson 6, Slide 1
A. Understanding File and Hardware
Resources
Definition of Resources
Accessing Resources in LabVIEW

Lesson 6, Slide 2
What are Resources?

Resources – An addressable file, hardware device,


object, or network connection available on your system

• LabVIEW includes VIs and functions to allow you to


access your resources.
• Resources are known to the system by a path,
name, port, or other identifier.

Lesson 6, Slide 3
Accessing Resources in LabVIEW
A typical resource operation involves the following process:

Open, Read
Check for
Initialize or and/or Close
Errors
Create Write

• Specify the path or device name. • The refnum becomes obsolete.


• LabVIEW creates a refnum as a unique
identifier to the resource.
• A refnum is a temporary pointer to the resource.

Lesson 6, Slide 4
Accessing Resources in LabVIEW
Sample refnum wires:

Lesson 6, Slide 5
B. File I/O
Understanding File I/O
File Formats
High-Level and Low-Level I/O

Lesson 6, Slide 6
File I/O

• Understanding File I/O


• File Formats
• High-Level File I/O VIs
• Low-Level File I/O VIs

Lesson 6, Slide 7
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

Lesson 6, Slide 8
File Formats
LabVIEW can use or create the following file formats:
• Binary—Efficient, compact, and allows random access
reading but not a human-readable file. Commonly used for
high-speed and multi-channel DAQ.
• ASCII—Human-readable text file where data is represented
as strings. Commonly used for low-speed DAQ.
• LVM—Format built on ASCII, the LabVIEW measurement
data file (.lvm) is a tab-delimited text file you can open with a
spreadsheet application or a text-editing application.
• TDMS—An NI-specific binary file format that contains data
and stores properties about the data.

Lesson 6, Slide 9
ASCII File Format
• In this course, you learn about creating text (ASCII) files.
• Use ASCII files in the following situations:
− You want to access the file from another application.
− Disk space and file I/O speed are not crucial.
− You do not need to perform random access reads or writes.
− Numeric precision is not important.

Lesson 6, Slide 10
High-Level File I/O
• High-level File I/O functions:
− Perform all three steps (open,
read/write, close) for common file I/O
operations.
− Might not be as efficient as the
functions configured or designed for
individual operations.
• Low-level File I/O functions:
− Provide individual functions for each
step.
− Are efficient for writing to a file in a
loop.

Lesson 6, Slide 11
High-Level File I/O
Write to Spreadsheet File
• Converts an array of double-precision numbers to a text string and
writes the string to an ASCII file.
Read From Spreadsheet File
• Reads a specified number of lines or rows
from a numeric text file and outputs a
2D array of double-precision numbers.
Write To/Read From Measurement File
• Express VIs that write data to or read data
from an LVM or TDMS file format.

Lesson 6, Slide 12
Understanding Low-Level File I/O VIs

Lesson 6, Slide 13
Exercise 6-1
Concept: Spreadsheet Example VI

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


file.
GOAL
Exercise 6-2
Temperature Monitor VI – Logging Data

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


GOAL
Exercise 6-2
Temperature Monitor VI – Logging Data

What would happen if you used the Write to Measurement File


Express VI inside the While loop?

DISCUSSION
C. Acquiring Measurements with a
DAQ System
DAQ Hardware
Analog I/O, Digital I/O, and Counters
Configuring and Simulating DAQ Hardware
Programming DAQ

Lesson 6, Slide 17
DAQ Hardware

1. Signal
2. Terminal Block
3. Cable
4. DAQ Device
5. Computer

Lesson 6, Slide 18
DAQ Terminal Block
BNC-2120 features:
• Quadrature encoder
• 8 LEDs for digital I/O
• Counter I/O
• Function generator
• Function generator frequency
and amplitude control
• Temperature sensor
• Analog input
• Analog output

Lesson 6, Slide 19
DAQ Hardware – DAQ Device

Most DAQ devices have four standard elements:


• Analog input
• Analog output
• Digital I/O
• Counters

Lesson 6, Slide 20
Analog Input
The process of measuring an analog signal and transferring
the measurement to a computer for analysis, display, or
storage.
• An analog signal is a signal that varies continuously.
• Analog input most commonly measures voltage or current.

Lesson 6, Slide
Analog Output
Analog output is the process of generating analog signals
from your computer.
• Performing digital-to-analog (D/A)
conversions generates analog output.
• The available analog output types
are voltage and current.
• To perform a voltage or current
output, a compatible device must be
installed that can generate that
type of signal.

Lesson 6, Slide 22
Digital I/O
Digital signals are:
− Electrical signals that transfer digital data (on/off, high/low, 1/0)
using a wire.
− Used to control or measure digital or finite state devices, such
as switches and LEDs.
− Used to transfer data:
• To program devices.
• To communicate between devices.
− Used as clocks or triggers to control or
synchronize other measurements.

Lesson 6, Slide 23
Counters
• A counter is a digital timing device typically used for event
counting, frequency measurement, period measurement,
position measurement, and pulse generation.
• A counter can count to a fixed limit as determined by the
resolution of the counter.
For example, a 24-bit counter
can count to:
2(Counter Resolution) – 1 = 224 – 1 = 16,777,215

Lesson 6, Slide 24
Configuring DAQ Hardware
Configure and test hardware using the NI Measurement &
Automation Explorer (MAX).

Lesson 6, Slide 25
Simulating a DAQ Device
• Using NI-DAQmx simulated devices, you can try different NI
products in your application without the hardware.
• With NI-DAQmx simulated devices, you can export a
physical device configuration onto a system that does not
have the physical device installed.

Lesson 6, Slide 26
Exercise 6-3
Concept: Measurement & Automation Explorer

Use MAX to examine, configure, and test a DAQ device.


GOAL
Exercise 6-3
Concept: Measurement & Automation Explorer

What is a possible real-world application using DAQ?

DISCUSSION
DAQ Programming – Software Overview
• NI-DAQmx
− Driver level software
− Detects DAQ devices
− Installs NI-DAQmx functions in LabVIEW

• Measurement & Automation Explorer


− Configures and tests DAQ devices

• DAQ Assistant
− Configurable Express VI used to create a DAQ
application.

• DAQmx API
− Provides a set of VIs to program DAQ applications.

Lesson 6, Slide 29
DAQ Programming – Basic Flow
A basic DAQmx application involves the following process:

Acquire or
Create Configure Start Clear Check for
Generate
Task Task Task Task Errors
Data

Lesson 6, Slide 30
Step 1 - Create Task
The Create Virtual Channel VI:
• Creates a virtual channel and adds it to a task.
• Uses a pull-down menu to select the appropriate instance of
this VI.

Lesson 6, Slide 31
Step 2 - Configure Task
• Configure the timing of a task if reading multiple samples.
− Sample rate, timing source, etc.
• Configure the triggering if necessary for application.
− Configures the task to start or stop on a rising or falling digital
edge, analog edge, or during analog windows.

Lesson 6, Slide 32
Step 3 - Start Task
The Start Task VI starts the task after the task has been
configured.

Lesson 6, Slide 33
Step 4 - Acquire or Generate Data
• The DAQmx Read or DAQmx Write VIs acquire or generate
data from the DAQ device.
• Make sure the pull-down menu selection is compatible with
the task configuration.

Lesson 6, Slide 34
Step 5 - Clear Task
The DAQmx Clear Task VI:
• Stops the task.
• Releases any resources the task reserved.
• Clears the task.

Lesson 6, Slide 35
DAQ Programming – Example
This is an example program of an acquisition with triggering.

Lesson 6, Slide 36
Exercise 6-4 Using DAQmx (DAQ)

Explore a DAQmx example program that continuously


acquires data, and modify it to wait on a digital trigger.
GOAL
Exercise 6-4 Using DAQmx (DAQ)

What types of VIs did you use outside of the While Loop?

DISCUSSION
D. Controlling Instruments
Benefits
GPIB
Instrument Control Software
VISA
Instrument Drivers

Lesson 6, Slide 39
Instrument Control
• Use software on a PC to control an instrument over an
instrument control bus.
• Mix and match instruments from various categories.
• Understand the properties of the instrument, such as the
communication protocols to use.

Lesson 6, Slide 40
Benefits of Instrument Control
• Automates processes.
• Saves time.
• Uses one platform for multiple tasks.
• Is easy to use.
• Is compatible with many types of instruments.

Lesson 6, Slide 41
GPIB – General Purpose Interface Bus
GPIB is a standard
interface for
communication between a
controller and instruments
from various vendors.

Lesson 6, Slide 42
GPIB
• The bus supports one system controller, usually a computer,
and up to 14 additional instruments.
• The controller:
− Defines the communication links.
− Sends GPIB commands.
− Responds to devices that request service.
− Passes/receives control of the bus.

Lesson 6, Slide 43
Using Instrument Control Software
• Interface Drivers: Instrument interfaces such as GPIB
include a set of drivers for the interface.
• Configuration: Use MAX to configure the interface.

Lesson 6, Slide 44
Exercise 6-5
Concept: GPIB Configuration with MAX

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 6-5
Concept: GPIB Configuration with MAX

What is a possible real-world application using instrument


control?

DISCUSSION
Instrument Control Programming
Virtual Instrument Software Architecture (VISA):
− Is a high-level API that calls low-level drivers.
− Can control instruments over GPIB, USB, Ethernet, serial, and
other interfaces as it makes the appropriate driver calls
depending on the type of instrument used.

Lesson 6, Slide 47
VISA

VISA
Virtual Instrument System Architecture

Serial GPIB Ethernet USB

Lesson 6, Slide 48
VISA – Programming Terminology
• Resource
Any instrument in the system, including serial and parallel ports.
• Session
You must open a VISA session to a resource to communicate
with it, similar to a communication channel. When you open a session
to a resource, LabVIEW returns a VISA session number, which is a
unique refnum to that instrument. You must use the session number in
all subsequent VISA functions.
• Instrument Descriptor
Specifies the interface type (GPIB, USB, TCP/IP, ASRL), the address of the
device, and the VISA session type (INSTR or Event).

Lesson 6, Slide 49
VISA Alias
Assign a user-defined name to a device or resource in place
of the instrument descriptor.

Lesson 6, Slide 50
VISA Programming
VISA functions operate similar to File I/O functions.

Open Session Close


Perform I/O Check for
to Session to
Operation(s) Errors
Instrument(s) Instrument(s)

Lesson 6, Slide 51
VISA Open and Close Functions
• VISA Open Function
− Establishes a communication line to the resource.
− Is generally used once per resource.
− Returns a VISA Resource Name.

Lesson 6, Slide 52
VISA I/O Functions
VISA Write and VISA Read Functions

Lesson 6, Slide 53
VISA Write and Read Example

Lesson 6, Slide 54
Application Development
Instrument Drivers Environment (ADE)

• Are an organized set of VIs that control


a programmable instrument. Instrument Driver

− Each VI performs multiple instructions. Instrument Commands


(*idn?, meas?)
− Grouped by operation type
(configuration, data, etc).
• Reduce development time. Bus Communication Protocol
(configure, read, write, trigger)
− Simplify instrument control.
− Are reusable.
− Are a common architecture and
interface.

Lesson 6, Slide 55
Using Instrument Drivers
• When you use an instrument driver, the driver contains the
code specific to the instrument.
• If you change instruments, replace the instrument driver VIs
with the instrument driver VIs for the new instrument, which
greatly reduces your redevelopment time.

Lesson 6, Slide 56
Using Instrument Drivers – Where are they?
• You can locate most LabVIEW Plug and Play instrument drivers in the
Instrument Driver Finder.
− Access within LabVIEW by selecting Tools» Instrumentation»Find
Instrument Drivers or Help»Find Instrument Drivers.
− Use it to connect with ni.com to find instrument drivers.
− You can also find instrument drivers at ni.com/idnet
• When you install an instrument driver, the installer:
− Adds an example program using the driver to the NI Example Finder.
− Adds instrument driver VIs to the Instrument I/O»Instrument Drivers
palette in the Functions palette.
− Extracts instrument driver VIs and supporting files to the
<LabVIEW>\instr.lib directory.

Lesson 6, Slide 57
Instrument Driver Example

Lesson 6, Slide 58
Exercise 6-6 NI Devsim VI (GPIB)

Install the NI Instrument Simulator instrument driver and run


the example programs that accompany it.
GOAL
Exercise 6-6 NI Devsim VI (GPIB)

How would modify the example programs if you wanted to


continuously acquire data?

DISCUSSION
Summary—Quiz
1. After opening a file, which output does the Open/Create/Replace
File function return?
a) File path
b) File name
c) Refnum out
d) Task out

Lesson 6, Slide 61
Summary—Quiz Answer
1. After opening a file, which output does the Open/Create/Replace
File function return?
a) File path
b) File name
c) Refnum out
d) Task out

Lesson 6, Slide 62
Summary—Quiz
2. What is Measurement & Automation Explorer (MAX)?
a) A tool to configure and test DAQ devices
b) A tool to test instrument communication
c) A configurable Express VI
d) A window to view LabVIEW project files

Lesson 6, Slide 63
Summary—Quiz Answer
2. What is Measurement & Automation Explorer (MAX)?
a) A tool to configure and test DAQ devices
b) A tool to test instrument communication
c) A configurable Express VI
d) A window to view LabVIEW project files

Lesson 6, Slide 64
Summary—Quiz
3. Which of the following are benefits of instrument control?
a) Automate processes
b) Save time
c) One platform for multiple tasks
d) Limited to only one type of instrument

Lesson 6, Slide 65
Summary—Quiz Answers
3. Which of the following are benefits of instrument control?
a) Automate processes
b) Save time
c) One platform for multiple tasks
d) Limited to only one type of instrument

Lesson 6, Slide 66
Summary—Quiz
4. VISA is a high-level API that calls low-level drivers.
a) True
b) False

Lesson 6, Slide 67
Summary—Quiz Answer
4. VISA is a high-level API that calls low-level drivers.
a) True
b) False

Lesson 6, Slide 68
Lesson 7
Using Sequential and
State Machine Algorithms

TOPICS
A. Using Sequential Programming
B. Using State Programming
C. State Machines

Lesson 7, Slide 1
A. Using Sequential Programming
Flow-Through Parameters
Sequence Structures
Error Case Structures

Lesson 7, Slide 2
Using Sequential Programming
• Many of the VIs you write accomplish sequential tasks.
• By default, LabVIEW does not force sequential programming.

Example: Nothing forces the execution order of these tasks.


Any one of these tasks could happen first.
Lesson 7, Slide 3
Flow-Through Parameters Force Execution Order
Use error clusters and refnums to force order of execution.

Lesson 7, Slide 4
Sequence Structures Force Execution Order
• Sequence structures are a structure with frames, where each frame
executes in order.
• The second frame cannot begin execution until everything in the first
frame completes execution.

Lesson 7, Slide 5
Avoid Overuse of Sequence Structures
You cannot stop the execution in the middle of a sequence.

Lesson 7, Slide 6
Better to Use Error Case Structures
The best way to write this VI is to enclose the dialog boxes in
Case structures, wiring the error cluster to the case selectors.

Lesson 7, Slide 7
B. Using State Programming
State Programming
State Transition Diagrams

Lesson 7, Slide 8
State Programming
State programming helps you solve the following issues that
sequential programming or flow-through parameters do not:
• What if you need to change the order of the sequence?
• What if you need to repeat one item in the sequence more
often than other items?
• What if some items in the sequence execute only when
certain conditions are met?
• What if you need to stop the program immediately, rather
than waiting until the end of the sequence?

Lesson 7, Slide 9
State Transition Diagram
A state transition diagram is a type of flowchart that indicates
the states of a program and transitions between states.

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

Lesson 7, Slide 10
State Transition Diagram

Furnace
Example:

Lesson 7, Slide 11
C. State Machines
Common Uses
Infrastructure
Transitions

Lesson 7, Slide 12
State Machines
• The state machine design pattern implements a state
diagram or flow chart.
• Common uses of state machines:
− To create user interfaces, where different user actions send the
user interface into different states.
− For process tests, where a state represents each segment of
the process.

Lesson 7, Slide 13
State Machines – Infrastructure
• A state machine consists of a set of states and a transition
function that maps to the next state.
• Each state can lead to one or multiple states or end the
process flow.
While Loop

Type-Defined
Enum

Case Structure
Shift Register

Lesson 7, Slide 14
State Machines – Default Transition

Lesson 7, Slide 15
State Machines – Transition Between Two
States

Lesson 7, Slide 16
State Machines – Case Structure Transition

Lesson 7, Slide 17
State Machines – Transition Array Transition

Lesson 7, Slide 18
Course Project Transition Diagram

Lesson 7, Slide 19
Course Project

Demonstrate an implementation of a state machine.

<Solution>\LabVIEW Core 1\Exercise7-1

DEMONSTRATION
Exercise 7-1
Weather Station Project

Create a Weather Station application using a state machine


design pattern. Practice skills learned throughout this course.
GOAL
Exercise 7-1
Weather Station Project

How would you change the diagram to add an Initialize and


Shutdown state?

DISCUSSION
Summary—Quiz
1. When using a Sequence structure, you can stop the execution in
the middle of a sequence.
a) True
b) False

Lesson 7, Slide 23
Summary—Quiz Answer
1. When using a Sequence structure, you can stop the execution in
the middle of a sequence.
a) True
b) False

You cannot stop the execution in the middle of a


sequence.

Lesson 7, Slide 24
Summary—Quiz
2. Which of the following are benefits of using a state machine
instead of a sequential structure?
a) You can change the order of the sequence.
b) You can repeat individual items in the sequence.
c) You can set conditions to determine when an item in the
sequence should execute.
d) You can stop the program at any point in the sequence.

Lesson 7, Slide 25
Summary—Quiz Answers
2. Which of the following are benefits of using a state machine
instead of a sequential structure?
a) You can change the order of the sequence.
b) You can repeat individual items in the sequence.
c) You can set conditions to determine when an item in the
sequence should execute.
d) You can stop the program at any point in the sequence.

Lesson 7, Slide 26
Lesson 8
Solving Dataflow Challenges with Variables

TOPICS
A. Communicating Between Parallel Loops
B. Writing to Controls & Reading from Indicators
C. Variables
D. Local Variables
E. Race Conditions

Lesson 8, Slide 1
A. Communicating Between Parallel
Loops

Lesson 8, Slide 2
Communicating Between Parallel Loops

Dual chart example: Execute multiple tasks at the same time.

Lesson 8, Slide 3
How do the loops stop in this example?

Passing data among parallel loops is a challenge.

Lesson 8, Slide 4
How do the loops stop in this example?

You cannot pass data between parallel loops with a wire.

Lesson 8, Slide 5
B. Writing to Controls & Reading from
Indicators

Lesson 8, Slide 6
Writing to Controls & Reading from Indicators
How would you handle the following dataflow challenges?
− Initialize front panel controls with values from a configuration file?
− Copy a “Ship To” address to a “Bill To” address?
− Initialize indicators that will be written to later in your code?
− Write to an indicator in two cases of a Case structure without
writing to it in all cases?

Sometimes you need to write to a control or read from an


indicator.

Lesson 8, Slide 7
C. Variables

Lesson 8, Slide 8
Variables

Variables – Block diagram elements that allow


you to access or store data in another location
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.

Lesson 8, Slide 9
D. Local Variables
When To Use Local Variables
Local Variables and Boolean Mechanical Actions
How To Create Local Variables

Lesson 8, Slide 10
Local Variables

Use local variables to pass data within a single VI.

Lesson 8, Slide 11
Local Variables

Use local variables to modify front panel control values.

Lesson 8, Slide 12
Use Switch Mechanical Action
• Boolean controls with
associated local
variables must use
switch mechanical
action.
• Boolean latch action
is incompatible with
local variables.

Lesson 8, Slide 13
Creating Local Variables

Create and use local variables.

<Exercises>\LabVIEW Core 1\Demonstrations\Local


Variables

DEMONSTRATION
Exercise 8-1
Weather Station UI with Local Variable VI

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


GOAL
Exercise 8-1
Weather Station UI with Local Variable VI

What functionality does the local variable provide for this


application?

DISCUSSION
E. Race Conditions
Definition
How To Avoid Race Conditions
Controlling Shared Resources

Lesson 8, Slide 17
Race Conditions
Race Condition – A situation where the timing of
events or the scheduling of tasks may unintentionally
affect an output or data value

Race conditions are a common problem for programs


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

Lesson 8, Slide 18
What is the final value of the Value variable?

Four possible outcomes:

• Value = (Value * 5) +2
• Value = (Value + 2) * 5
• Value = Value * 5
• Value = Value +2

Lesson 8, Slide 19
Race Conditions
• Race conditions are very difficult to identify and debug.
• Often, code with a race condition can return the same result
thousands of times in testing, but still be capable of
returning a different result.
• Avoid race conditions by:
− Controlling shared resources.
• Use one writer, multiple readers.
− Properly sequencing instructions.
− Reducing use of variables.

Lesson 8, Slide 20
Controlling Shared Resources

Lesson 8, Slide 21
Summary—Quiz
1. You should use variables in your VI whenever possible.
a) True
b) False

Lesson 8, Slide 22
Summary—Quiz Answer
1. You should use variables in your VI whenever possible.
a) True
b) False

You should use variables only when necessary. Use


wires to transfer data whenever possible.

Lesson 8, Slide 23
Summary—Quiz
2. When controlling resources, which combination of writers and
readers reduces chance of race conditions?
a) One writer, one reader
b) One writer, multiple readers
c) Multiple writers, one reader
d) Multiple writers, multiple readers

Lesson 8, Slide 24
Summary—Quiz Answer
2. When controlling resources, which combination of writers and
readers reduces chance of race conditions?
a) One writer, one reader
b) One writer, multiple readers
c) Multiple writers, one reader
d) Multiple writers, multiple readers

Lesson 8, Slide 25
Continuing Your LabVIEW Education
• Instructor Led Training:
− LabVIEW Core 2: Learn about multiple loop design patterns, property
nodes and building an executable.
− LabVIEW Real-Time 1
− LabVIEW FPGA
− LabVIEW Instrument Control
− Data Acquisition and Signal Conditioning
• Self-Paced Online: Accessible 24 hours a day, prerecorded video
training modules, interactive quizzes, and challenging exercises with
solutions.
• Printed Course Materials: a variety of instructional packages and tools
designed to educate you at your own pace

Lesson 8, Slide 26
NI LabVIEW Skills Guide

ni.com/skills-guide
• Identify skills you need
• Find courses and learning resources to develop those skills

Lesson 8, Slide
Continue Your Learning
• ni.com/support
− Access product manuals, KnowledgeBase, example code, tutorials,
application notes, and discussion forums.
− Request technical support.
• NI Community: ni.com/community/
− Ask and answer questions in discussion forums.
− Exchange code and ideas.
• User Groups: ni.com/usergroups
• Alliance Program: ni.com/alliance
• Publications: ni.com/reference/books/
• Practice!

Lesson 8, Slide 28
New Users Experienced Users Advanced Users

LabVIEW Core 3 Managing Software


LabVIEW Core 1
Engineering in LabVIEW
LabVIEW Core 2 LabVIEW OOP System
Design
Advanced Architectures
in LabVIEW

Certifications
Certified LV Associate Certified LabVIEW Certified LabVIEW
Developer Exam Developer Exam Architect Exam

Lesson 8, Slide 29
Thank you!
Please complete the course survey
and retrieve your course CD.

Lesson 8, Slide 30

You might also like