Date post: | 21-Jul-2016 |
Category: |
Documents |
Upload: | krushnasamy-suramaniyan |
View: | 21 times |
Download: | 2 times |
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 instrumentsTraditional instruments Virtual instrumentsVendor-defined User-defined
Function-specific, stand-alone withlimited connectivity
Application-oriented system withconnectivity to networks, peripherals,and applications
Hardware is the key Software is the key
Expensive Low-cost, reusable
Closed, fixed functionality Open, flexible functionality leveragingoff familiar computer technology
Slow turn on technology (5–10 year lifecycle)
Fast turn on technology (1–2 year lifecycle)
High development and maintenancecosts
Software minimizes development andmaintenance 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
ButtonAbort ExecutionPause/Continue
ButtonText SettingsAlign Objects
Distribute ObjectsReorder
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 Customiz
e 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
SearchPalette Options
Click pushpin to tack down palette
Up to OwningPalette
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)
NumericControl
NumericIndicator Owned
Labels
IncrementButtons
BooleanControl
BooleanIndicator
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 PageRight-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
NodesWires
ControlTerminals
Block DiagramFront PanelIndicator 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 NodesIcon 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 Array1D 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 Items»Terminals
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
Help»Show Context Help, press the <Ctrl-H> keys, or press the Show Context Help Window button in the toolbar
Move cursor over objectto display help
Connections:Required – boldRecommended – normalOptional - dimmed
Simple/Detailed Context Help Lock Help More Help
36
LabVIEW Help Click the More Help button in the Context Help
window Select Help»VI, 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 Help»Find Examples
Web-integrated Search by keyword,
example type, hardware type, etc.
38
Debugging Techniques
Finding ErrorsClick on broken Run button. A window showing the error appears
Execution HighlightingClick on Execution Highlighting button; data flow is animated using bubbles. Values are displayed on wires.
39
Debugging TechniquesProbe
Right-click on wire and select probe and it shows data as it flows through the wire segment
BreakpointsRight-click on wire and select Set Breakpoint; pause execution at the breakpoint.
Conditional ProbeCombination 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 steppingOnce 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• Tools»Options 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
TOPICSSubVIsIcon and Connector PaneUsing SubVIsCreating a SubVI from sections of a VI
43
LabVIEW Hierarchy
SubVI
44
SubVIsFunction Pseudo Codefunction average (in1, in2,
out){out = (in1 + in2)/2.0;}
SubVI Block Diagram
Calling Program Pseudo Codemain{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 PaneTerminal colors match the data types to which they are connectedClick 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
TOPICSWhile LoopsFor LoopsAccessing Previous Loop Data
55
While Loops
LabVIEW While Loop Flow Chart Pseudo Code
Repeat (code);Until Condition met;End;
56
While Loops1. Select While Loop 2. Enclose code to be repeated
3. Drop or drag additional nodes and then wire
57
Select the Loop ConditionClick the Conditional Terminal with the Operating tool to define when the loop stopsDefault: 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 Multiplefunction
61
Wait Functions
Wait Until Next ms Multiple
Functions»Time & Dialog palette
62
Wait (ms)
Functions»Time & Dialog palette
Time Delay
Functions»Time & 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
SecondIteration
LastIteration
Initial Value
Value 1
Value 1
Value 2
Value 2
Value 3
Value 3
InitialValue
66
Additional Shift Register Elements
Latest valueis passed toright 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 ago2 loops ago3 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 Functions»Structures palette
69
Initialized Shift Registers & Feedback Nodes
Run Once VI stops execution Run Again
Output = 5Output = 5
Output = 5 Output = 5
70
Uninitialized Shift Registers & Feedback Nodes
Run Once VI stops execution Run Again
Output = 8Output = 4
Output = 4 Output = 8
71
Making Decisions in a VI
TOPICSDecision making with the Select functionCase StructuresFormula 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 CasesString 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 semicolonFormula Node
78
Decision Making with Formula Nodes
Two different ways of using an if-then statement in a Formula NodeBoth structures produce the same result
79
Arrays
TOPICSIntroduction to ArraysAuto Indexing ArraysArray FunctionsPolymorphism
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
index10-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 60 1 2 34
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-IndexingWire 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 elementsin the array equalsthe count terminalinput
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 typesAll LabVIEW arithmetic functions are polymorphic
Scalar + Scalar
Array + Scalar
Combination ResultScalar
Array
Array
Array + Array
Array + Array
Array
Polymorphism
91
Clusters
TOPICSIntroduction to ClustersCluster FunctionsError 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 Indicators2. Place objects inside the
shell
94
Creating Cluster Constants1. 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 terminalOvercomes 28-terminal limit Simplifies wiring
97
Cluster Functions - BundleBu
ndle
Bund
le
By
Nam
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 ClusterUse 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 Controls»Array & 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 HandlerUse the Simple Error Handler to handle the error at the end of the execution flow.
The Simple Error Handler is located on the Functions»All Functions»Time 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
TOPICSWaveform ChartsWaveform and XY GraphsIntensity Graphs
105
Waveform ChartsSelected from the Controls»Graphs and Charts palette
106
Wiring to ChartsSingle-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 GraphsRight-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 anotherPlot Legend
(point and line styles)
Graph PaletteScale Legend
Graphs
110
Uniform X axisInitial X = 0.0Delta X = 1.0
Uniform X axisyou specify point spacing
Single-Plot Waveform Graphs
111
Multiple-Plot Waveform Graphs
Each row is a separate plot: Initial X = 0Delta 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 SummaryUse 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
TOPICSHow to create string controls and indicatorsHow to use several String functionsAbout file I/O operationsHow to use the high-level File I/O VIsHow to use the low-level File I/O VIsHow 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 ModesNormal display
Password display
\ code display
Hex display
118
Concatenate Strings(spaces here)
String Length
String Functions
119
String FunctionsString Subset
Match Pattern
120
Converting Numerics to Strings: Build String
121
Converting Strings to Numerics: Scan From String
122
Edit Format StringScan From String Function
123
File Input and Output
Four Hierarchy Levels:High-level File VIsIntermediate File VIs and FunctionsAdvanced File Functions subpaletteExpress 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 FileClose
FileCheck 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 VariablesIn 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 subVI’s).
rate := 0.05principle := 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 VariablesIn the example, both rate and principal are local variables.
Typical global variables for VI’s 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 VariablesStart 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 Node0
G P IB A D D R E S S
C urrent D ata F ile
0.00
M aximum V o ltage
0.00
M inimum V o ltage
G P IB A D D R E S S
G P IB A D D R E S S
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