Sei sulla pagina 1di 135

REVIEW OF VIRTUAL

INSTRUMENTATION
Unit-1
Contents
Define VI
Historical perspective
Need of VI
Advantages of VI
Block diagram & architecture of VI
Data flow techniques
Graphical programming in data flow
Comparison with conventional programming.

What is VI...??
A virtual instrumentation system is computer
software that a user would employ to develop a
computerized test and measurement system for
controlling from a computer desktop an external
measurement hardware device and for displaying test
or measurement data collected by the external device
on instrument-like panels on a computer screen.
Architecture of VI
A virtual instrument is composed of the following
blocks:
Sensor module
Sensor interface
Information systems interface
Processing module
Database interface
User interface
Architecture of VI
Traditional vs virtual instruments
Traditional instruments Virtual instruments
Vendor-defined User-defined
Function-specific, stand-alone with
limited connectivity
Application-oriented system with
connectivity to networks, peripherals,
and applications
Hardware is the key Software is the key
Expensive Low-cost, reusable
Closed, fixed functionality Open, flexible functionality leveraging
off familiar computer technology
Slow turn on technology (510 year life
cycle)
Fast turn on technology (12 year life
cycle)
High development and maintenance
costs
Software minimizes development and
maintenance costs
Advantages of VI
Performance
Platform-Independent Nature
Flexibility
Lower Cost
Plug-In and Networked Hardware
The Costs of a Measurement Application
Reducing System Specification Time Cost
Lowering the Cost of Hardware and Software

Evolution of LabVIEW
LabVIEW expanded as Laboratory Virtual Instrumentation
Engineering Workbench
LabVIEW is a powerful graphical development environment for
Signal acquisition
Measurement analysis
Data presentation
In 1986, when National Instruments introduced LabVIEW for
the Macintosh

Creating VI Using LabVIEW
Connectivity and Instrument Control
Open Environment
Reduces Cost and Preserves Investment
Multiple Platforms
Distributed Development
Analysis Capabilities
Visualization Capabilities
Flexibility and Scalability

Advantages of LabVIEW
Easy to Learn
Easy to Use
Complete Functionality
Modular Development
VI in the Engineering Process
Dataflow Programming
Block diagram executes
dependent on the flow of data;
block diagram does NOT
execute left to right
Node executes when data is
available to ALL input terminals
Nodes supply data to all output
terminals when done
C, C + +, JAVA, and most other
text-based programming
languages follow a control flow
model of program execution.

G programming

Execution of VI is determined by the structure of a
graphical block diagram (the LabVIEW-source code).
The wires propagate variables and any node can
execute as soon as all its input data become
available.
G is inherently capable of parallel execution.

PROGRAMMING TECHNIQUES
Unit-2

Contents
Introduction to LabVIEW
VIS and sub-VIS
Loops
Case & Sequence structures
Formula modes
Charts & Graphs
Arrays & Clusters
Local and Global variable
String & File input.
17

Introduction to LabVIEW
TOPICS
LabVIEW Environment
Front Panel
Block Diagram
LabVIEW Help and Manuals
Debugging a VI
18
Virtual Instruments (VIs)
Front Panel
Controls = Inputs
Indicators = Outputs

Block Diagram
Accompanying program
for front panel
Components wired
together
Run Button

Continuous Run Button

Abort Execution

Pause/Continue Button

Text Settings

Align Objects

Distribute Objects

Reorder

Resize front panel objects
Execution Highlighting
Button

Step Into Button

Step Over Button

Step Out Button

Additional Buttons on
the Diagram Toolbar
Toolbar
Controls Palette (Controls & Indicators)
(Place items on the Front Panel Window)
Indicator:
Numeric Slide
Control:
Numeric
Customize
Palette
View
Functions (and Structures) Palette
(Place items on the
Block Diagram Window)
Structure:
While Loop
23
Palette Tools
Graphical, floating palettes
Subpalettes can be converted to floating
palettes
Use Palette Options to change palette
view from Express to Advanced

Search Palette Options
Click pushpin to tack down palette
Up to Owning
Palette
24
Searching for Controls, VIs, and Functions
Press the search button to
perform text searches of
the palettes
Click and drag an item
from the search window to
the block diagram or
double-click an item to
open the owning palette
25
Build the front panel with controls (inputs)
and indicators (outputs)
Numeric
Control
Numeric
Indicator
Owned
Labels

Increment
Buttons
Boolean
Control
Boolean
Indicator
Creating a VI Front Panel
26
Shortcut Menus for Front Panel Objects
Right-click the label to
access its shortcut menu
Right-click the digital display
to access its shortcut menu
27
Property Page
Right-click a control
or indicator on the
front panel and
select Properties
from the shortcut
menu to access the
property dialog box
for that object
28
Nodes Wires
Control
Terminals
Block Diagram
Front Panel
Indicator
Terminals
Creating a VI Block Diagram
29
Express VIs, VIs and Functions
Express VIs: interactive VIs with configurable dialog page
Standard VIs: modularized VIs customized by wiring
Functions: fundamental operating elements of
LabVIEW; no front panel or block diagram
30
Block Diagram Nodes
Icon Expandable Node Expanded Node
Function Generator VI
Same VI, viewed three different ways
Yellow field designates a standard VI
Blue field designates an Express VI
31
Block Diagram Terminals
Terminals are entry and exit ports that
exchange information between the
panel and diagram
Terminals are analogous to parameters
and constants in text-based
programming languages
Right-click and toggle View As Icon to
change the icon view
32
Wiring the Block Diagram
Scalar
Numeric
Boolean
String
2D Array 1D Array
Dynamic
33
Wiring Techniques
Hot Spot
Automatic Wiring
Use Context Help Window when wiring
Right-click wire and select Clean Up Wire
Tip Strips
Automatic wire routing
Right-click terminals
and select Visible
ItemsTerminals
View the terminal connections to a function
34
Block diagram executes
dependent on the flow of data;
block diagram does NOT execute
left to right

Node executes when data is
available to ALL input terminals

Nodes supply data to all output
terminals when done
Dataflow Programming
35
Context Help
To display the Context Help window, select
HelpShow Context Help, press the <Ctrl-H> keys, or
press the Show Context Help Window button in the
toolbar
Move cursor over object
to display help
Connections:
Required bold
Recommended normal
Optional - dimmed

Simple/Detailed Context Help Lock Help More Help
36
LabVIEW Help
Click the More Help button in the Context Help window
Select HelpVI, Function, & How-To Help
Click the sentence Click here for more help in the
Context Help window.

Contains detailed descriptions of most palettes, menus,
tools, VIs, and functions, step-by-step instructions for
using LabVIEW features, links to the LabVIEW Tutorial,
PDF versions of all the LabVIEW manuals and Application
Notes, and technical support resources.
37
NI Example Finder
To find an example, select
HelpFind Examples
Web-integrated
Search by keyword,
example type, hardware
type, etc.
38
Debugging Techniques
Finding Errors
Click on broken Run button. A window showing the
error appears
Execution Highlighting
Click on Execution Highlighting button; data flow is
animated using bubbles. Values are displayed on
wires.
39
Debugging Techniques
Probe
Right-click on wire and select probe and it shows
data as it flows through the wire segment

Breakpoints
Right-click on wire and select Set Breakpoint; pause
execution at the breakpoint.
Conditional Probe
Combination of a breakpoint and a probe. Right-click on
wire and select custom probe.
40
Debugging Techniques
Step Into, Over, and Out buttons for Single Stepping
Click on Step Into button to enable single stepping
Once Single Stepping has begun, the button steps
into nodes



Click on Step Over button to enable single stepping
or to step over nodes


Click on Step Out button to step out of nodes
41
Tips
Common keyboard shortcuts










Access Tools Palette with <shift>-right-click
Increment/Decrement faster using <shift> key
ToolsOptions selection set preferences in LabVIEW
VI Properties (File menu)
Windows Sun Linux MacOS
<Ctrl-R> <-R> <M-R> <z-R> Run a VI
<Ctrl-F> <-F> <M-F> <z-F> Find object
<Ctrl-H> <-H> <M-H> <z-H> Activate Context Help window
<Ctrl-B> <-B> <M-B> <z-B> Remove all broken wires
<Ctrl-W> <-W> <M-W> <z-W> Close the active window
<Ctrl-E> <-E> <M-E> <z-E> Toggle btwn Diagram/Panel Window
42

Modular Programming
TOPICS
SubVIs
Icon and Connector Pane
Using SubVIs
Creating a SubVI from sections of a VI
43
LabVIEW Hierarchy
SubVI
44
SubVIs
Function Pseudo Code
function average (in1, in2, out)
{
out = (in1 + in2)/2.0;
}

SubVI Block Diagram
Calling Program Pseudo Code
main
{
average (point1, point2, pointavg)
}

Calling VI Block Diagram
45
Icon/Connector
An icon represents a VI in other
block diagrams

A connector passes data to and
receives data from a subVI through
terminals
Icon
Connector
terminals
terminals
46
SubVI Example Calculating Slope
A VI within another VI is called a subVI
To use a VI as a subVI, create an icon and a connector pane after building the
front panel and block diagram
47
Creating the Icon
Icon: graphical representation of a VI
Right-click in the icon pane (Panel or Diagram)
Always create a black and white icon
Default Icon Create a custom icon
48
Creating the Connector
Right-click the icon
(Front Panel only)
49
Creating the Connector - continued
Click with
wiring tool
50
The Connector Pane
Terminal colors match the data types to which they are connected
Click the terminal to see its associated front panel object
51
Using a VI as a SubVI
All Functions Select a VI
<OR>
Drag icon onto target diagram
52
Help and Classifying Terminals
Classify inputs and outputs:
Required Error if no connection
Recommended Warning if no
connection
Optional No effect if no
connection
53
Create SubVI Option
Enclose area to be converted into a subVI
Select Create SubVI from the Edit Menu
54

Repetition and Loops
TOPICS
While Loops
For Loops
Accessing Previous Loop Data
55
While Loops
LabVIEW While Loop Flow Chart Pseudo Code
Repeat (code);
Until Condition met;
End;

56
While Loops
1. Select While Loop 2. Enclose code to be repeated
3. Drop or drag additional nodes and then wire
57
Select the Loop Condition
Click the Conditional Terminal with the Operating tool to
define when the loop stops
Default: Stop if True
Iteration Terminal Conditional Terminal
58
Structure Tunnels
Tunnels feed data into and out of structures.
The tunnel is a block that appears on the border; the
color of the block is related to the data type wired to the
tunnel.
When a tunnel passes data into a loop, the loop executes
only after data arrive at the
tunnel.
Data pass out of a loop after
the loop terminates.

59
For Loops
LabVIEW For Loop Flow Chart Pseudo Code
N=100;
i=0;
Until i=N:
Repeat (code; i=i+1);
End;
60
For Loops
In Structures subpalette of Functions palette
Enclose code to be repeated and/or resize and add
nodes inside boundary
Executes diagram inside of loop a predetermined number
of times
Count terminal
(Numerical input)
Wait Until Next
ms Multiple
function
61
Wait Functions
Wait Until Next ms
Multiple




FunctionsTime
& Dialog palette
62
Wait (ms)



FunctionsTime
& Dialog palette
Time Delay





FunctionsTime
& Dialog palette
Wait Functions
63
Numeric Conversion
Numerics default to double-precision (8 bytes) or long integer
(4 bytes)
LabVIEW automatically converts to different representations
For Loop count terminal always converts to a long integer
Gray coercion dot on terminal indicates conversion
64
Numeric Conversion
LabVIEW chooses the representation that uses more bits.
If the number of bits is the same,
LabVIEW chooses unsigned over signed.
To choose the representation,
right-click on the terminal and
select Representation.

When LabVIEW converts floating-point numerics to integers,
it rounds to the nearest integer. LabVIEW rounds x.5 to the
nearest even integer.
For example, LabVIEW rounds 2.5 to 2 and 3.5 to 4.
65
Accessing Previous Loop Data Shift Register
Available at left or right border of loop structures
Right-click the border and select Add Shift Register
Right terminal stores data on completion of iteration
Left terminal provides stored data at beginning of next iteration
Before Loop
Begins
First
Iteration
Second
Iteration
Last
Iteration
Initial Value
Value 1
Value 1
Value 2
Value 2
Value 3
Value 3
Initial
Value
66
Additional Shift Register Elements
Latest value
is passed to
right terminal
Right-click
the left
terminal to
add new
elements
Previous values are available at
the left terminals
Right-click
the border
for a new
shift register
1 loop ago
2 loops ago
3 loops ago
67
Feedback Nodes
Appears automatically in a For Loop or While Loop if
you wire the output of a subVI, function, or group of
subVIs and functions to the input of that same VI,
function, or group.
Stores data when the loop completes an iteration,
sends that value to the next iteration of the loop, and
transfers any data type
68
Feedback Node
Wire from output to input
to automatically create a
feedback node
<OR>
Place a feedback node
from the
FunctionsStructures
palette
69
Initialized Shift Registers & Feedback Nodes
Run Once VI stops execution Run Again
Output = 5
Output = 5
Output = 5 Output = 5
70
Uninitialized Shift Registers & Feedback Nodes
Run Once VI stops execution Run Again
Output = 8
Output = 4
Output = 4 Output = 8
71

Making Decisions in a VI
TOPICS
Decision making with the Select function
Case Structures
Formula Nodes
72
Simple Decision: Select Function
If Temp Scale is TRUE, pass top input;
if temp scale is FALSE, pass bottom input.





If the decision to be made is more complex than a
Select function can execute, a Case Structure may be
what is required.

73
Boolean Case Structure Example:
If Temp Scale is TRUE, execute True case;
if temp scale is FALSE, execute False case.
Case Structures
74
In the Structures
subpalette of
Functions palette

Enclose nodes or
drag them inside
the structure

Stacked like a deck
of cards, only one
case visible at a
time
Case Structures
75
Boolean and Numeric Cases
Wire all possible outputs of the case structure
76
String, Enum, and Error Cases
String Case Enum Case Error Case
77
In the Structures subpalette
Implement complicated equations
Variables created at border
Variable names are case sensitive
Each statement must terminate with a semicolon (;)
Context Help Window shows available functions
Note semicolon
Formula Node
78
Decision Making with Formula Nodes
Two different ways of using an if-then statement in a Formula Node
Both structures produce the same result
79

Arrays
TOPICS
Introduction to Arrays
Auto Indexing Arrays
Array Functions
Polymorphism
80
Collection of data elements that are of same type
One or more dimensions, up to 2 elements per dimension
Elements accessed by their index; first element is index 0
index
10-element array
1.2 3.2 8.2 8.0 4.8 5.1 6.0 1.0 2.5 1.7
0 1 2 3 4 5 6 7 8 9
2D array
Five row by seven column array of 35 elements
0 1 2 3 4 5 6
0
1
2
3
4
Arrays
81
Add Dimension
for 2D arrays
1. Select the Array shell from the
Controls palette
2. Place data object inside shell
Array Controls and Indicators
82
1. Select Array Constant
shell from the Array
subpalette
2. Place the data object in the array shell
Creating Array Constants
83
Loops can
accumulate arrays at
their boundaries with
auto-indexing
For Loops auto-index by
default
While Loops output the
final value by default
Right-click on tunnel and
enable/disable auto-
indexing
Auto-Indexing
Wire becomes
thicker
Wire remains the same
size
Auto-Indexing Disabled
Auto-Indexing Enabled
Only one value (last
iteration) is passed out
of the loop
1D Array
0 1 2 3 4
5
84
Inner loop creates column elements
Outer loop stacks them into rows
Creating 2D Arrays
1D Array
0 1 2 3 4 5
2D Array
85
Auto-Index Input
An array input can be
used to set the For
Loop count terminal
Number of elements
in the array equals
the count terminal
input
Run arrow not
broken
86
Array Size
Initialize Array
Common Array Functions
87
Array Subset
Common Array Functions
88
The Build Array Function
Building a higher dimension array
Concatenate Inputs
Appending an element
default
89
The Index Array Function
Extracting an Element
Extracting an Element of a Row
Extracting a Row
90
Function inputs can be of different types
All LabVIEW arithmetic functions are polymorphic
Scalar + Scalar
Array + Scalar
Combination
Result
Scalar
Array
Array
Array + Array
Array + Array
Array
Polymorphism
91

Clusters
TOPICS
Introduction to Clusters
Cluster Functions
Error Clusters
92
Clusters
Data structure that groups data together
Data may be of different types
Analogous to struct in C or a record in Pascal
Elements must be either all controls or all
indicators
Thought of as wires bundled into a cable
93
1. Select a Cluster shell
from the Array &
Cluster subpalette
Cluster Controls and Indicators
2. Place objects inside the shell
94
Creating Cluster Constants
1. Select Cluster Constant
shell from the Cluster
subpalette
2. Place objects in the Cluster shell
95
Cluster Order
Elements have a logical order (start with 0)
To change order, right-click the border and select
Reorder Controls in Cluster...
96
Using Clusters to Pass Data to SubVIs
Use clusters to pass
several values to one
terminal
Overcomes 28-terminal
limit
Simplifies wiring
97
Cluster Functions - Bundle
B
u
n
d
l
e

B
u
n
d
l
e


B
y

N
a
m
e

Create new cluster Modify existing cluster
Must have an
existing cluster to
use this function.
98
Cluster Functions - Unbundle
Unbundle Unbundle By Name
99
Error Cluster
Use the error in and error out clusters in each VI you use
or build to handle errors in the VI.
The error clusters located on the ControlsArray & Cluster
palette include the components of information shown
100
Error Cluster Details
Status is a Boolean value that reports
TRUE if an error occurred. Most VIs,
functions, and structures that accept
Boolean data also recognize this
parameter.
Code is a signed 32-bit integer that
identifies the error numerically. A non-zero
error code coupled with a status of FALSE
signals a warning rather than a fatal error.
Source is a string that identifies where
the error occurred.
101
Error Handling with Clusters
LabVIEW does not handle errors automatically. In
LabVIEW, you can make these error handling decisions on
the block diagram of the VI.
Error handling in LabVIEW follows the dataflow model. Just
as data flow through a VI, so can error information.
Wire the error information from the beginning of the VI to
the end.
Error Cluster
102
Simple Error Handler
Use the Simple Error Handler to handle the error at the
end of the execution flow.

The Simple Error Handler is located on the
FunctionsAll FunctionsTime and Dialog palette.
Wire the error cluster to the Error In (no error) input.
103
Using While Loops for Error Handling
You can wire an error cluster to the conditional terminal of
a While Loop to stop the iteration of the While Loop.
Only the TRUE or FALSE value of the status parameter of
the error cluster is passed to the terminal.
When an error occurs, the
While Loop stops.
104

Plotting Data
TOPICS
Waveform Charts
Waveform and XY Graphs
Intensity Graphs
105
Waveform Charts
Selected from the ControlsGraphs and Charts palette
106
Wiring to Charts
Single-Plot Chart





Multiple-Plot Chart
107
Modifying Chart Properties
Change the
appearance
Set the format
and precision of
the axis
Choose the plot
type
Edit the scales
Document the
chart
108
Customizing Charts and Graphs
Right-click and select Visible Items to view the
following items:
Plot Legend
Digital Display
Scrollbar
X and Y Scale
Graph Palette
Scale Legend
Graph Palette
Scale
Legend
Zoom
Subpalette

109
Selected from the Graph subpalette
Waveform Graph Plot an array of numbers against
their indices
XY Graph Plot one array against another
Plot Legend
(point and line
styles)
Graph Palette
Scale Legend
Graphs
110
Uniform X
axis
Initial X = 0.0
Delta X = 1.0
Uniform X
axis
you specify
point
spacing
Single-Plot Waveform Graphs
111
Multiple-Plot Waveform Graphs
Each row is a
separate plot:
Initial X = 0
Delta X = 1
Each row is a
separate plot:
Bundle
specifies point
spacing of the
X axis
112
Non-uniform X axis
Separate X and Y arrays
define data points
XY Graphs
113
Chart and Graph Use Summary
Use the Context Help window with charts and graphs
114
Intensity Plots and Graphs
Useful in displaying terrain, temperature patterns, spectrum analysis,
and image processing
Data type is a 2D array of numbers; each number represents a color
Use these options to set and display color mapping scheme
Cursor also adds a third dimension
115

Strings and File I/O
TOPICS
How to create string controls and indicators
How to use several String functions
About file I/O operations
How to use the high-level File I/O VIs
How to use the low-level File I/O VIs
How to format text files for use in spreadsheets
116
A string is a sequence of displayable or - characters (ASCII)
Many uses displaying messages, instrument control, file I/O
String control/indicator is in the Controls String subpalette
Strings
117
String Display Modes
Normal display
Password display
\ code display
Hex display
118
Concatenate Strings
(spaces here)
String Length
String Functions
119
String Functions
String Subset
Match Pattern
120
Converting Numerics to Strings: Build String
121
Converting Strings to Numerics:
Scan From String
122
Edit Format String
Scan From String Function
123
File Input and Output
Four Hierarchy Levels:
High-level File VIs
Intermediate File VIs and Functions
Advanced File Functions subpalette
Express VIs
124
Write to Spreadsheet File
Read from Spreadsheet File
Write Characters to File
Read Characters from File
Read Lines from File
High-level File I/O VIs
125
File I/O Programming Model - Intermediate


Open/
Create/
Replace File
Read
and/or
Write to File
Close
File
Check for
Errors
126
Write to File Example
Open/Create/Replace opens the existing file TEST1.DAT and generates
refnum and error cluster
Write File writes the data
Close File closes the file
Simple Error Handler checks for errors
127
Reading Data from a File
Open/Create/Replace opens the file
Read File reads the specified number of bytes from the file
Close File closes the file
Simple Error Handler checks for errors
128
Formatting a Spreadsheet String
Spreadsheets are popular tools for data handling and analysis
There are many formats for spreadsheet data. One of the most popular
is tab-delimited:
Columns are separated by a tab character
Rows are separated by an end-of-line character
Tab End of Line
A spreadsheet yields:
129
Creating a Spreadsheet File
Can replace Format Into String and
Write File with Format Into File
in above example
130
Write LabVIEW Measurement File
Includes the open, write, close and error handling
functions
Handles formatting the string with either a tab or comma
delimiter
Merge Signals function is used to combine data into the
dynamic data type
Global and Local Variables
In all programming languages, the programmer has the ability to define local
variables (within a subroutine or subVI) or global variables (accessible to VI
and all subVIs).
rate := 0.05
principle := 1000.
money := principle
For I:= 0 to 10
money:=money+money*rate
Next I
In the above example, the user might input the rate of interest
earned and the amount of principle in an account to calculate the
compounded interest.
Global and Local Variables
In the example, both rate and principal are local variables.
Typical global variables for VIs might include
a GPIB address of a instrument
the current name of an output file
default settings for an instrument, etc.
Setting up these variables in LabVIEW is similar to setting up a subVI.
Defining Variables
Start by using Functions>>All Functions>>Structures palette and
selecting the GLOBAL variable
A node appears on the block diagram for the global variable
Double click on it to open its front panel.
Assign a name (label) to each control because you must refer to the
variable by that label.
You can define a Global Node to have more than 1 variable
You can define more than 1 Global Node
Sample Global Node
Sharing Global Variables
Once you save the global node as a VI, you can insert it as a Global node in an
VI or subVI
CAUTION: Do not overuse global variables!!!
Due to dataflow architecture, it is difficult to know when a block of code
is writing/ reading global variable.
Since a global variable is BOTH an indicator and control, you have
flexibility, but also more opportunity for errors.
Local Variables
Only used in a single VI or subVI
As with Global variable, you refer to Local variable by its label.
Create a Local variable by Functions>>All Functions>>Structures and select local
variable or right click on control/ indicator and select CREATE>>Local Variable.
Remember, variables can act as Controls and Indicators
Advantage of Local variables over Global variables is that Local variables do not
need a separate VI FRONT PANEL.
Eg. for the traffic light lab, you can put everything in one VI using local variables,
or put traffic lights in separate front panel from time controls.
Local Variable Example

Potrebbero piacerti anche