+ All Categories
Home > Documents > VI_unit_1

VI_unit_1

Date post: 21-Jul-2016
Category:
Upload: krushnasamy-suramaniyan
View: 21 times
Download: 2 times
Share this document with a friend
Description:
virtual instrumentation
135
REVIEW OF VIRTUAL INSTRUMENTATION Unit-1
Transcript
Page 1: VI_unit_1

REVIEW OF VIRTUAL INSTRUMENTATION

Unit-1

Page 2: VI_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.

Page 3: VI_unit_1

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.

Page 4: VI_unit_1

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

Page 5: VI_unit_1

Architecture of VI

Page 6: VI_unit_1

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

Page 7: VI_unit_1

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

Page 8: VI_unit_1

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

Page 9: VI_unit_1
Page 10: VI_unit_1

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

Page 11: VI_unit_1

Advantages of LabVIEW Easy to Learn Easy to Use Complete Functionality Modular Development

Page 12: VI_unit_1

VI in the Engineering Process

Page 13: VI_unit_1

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.

Page 14: VI_unit_1

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

Page 15: VI_unit_1

PROGRAMMING TECHNIQUES

Unit-2

Page 16: VI_unit_1

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.

Page 17: VI_unit_1

17

Introduction to LabVIEW

TOPICS LabVIEW Environment Front Panel Block Diagram LabVIEW Help and Manuals Debugging a VI

Page 18: VI_unit_1

18

Virtual Instruments (VIs)

Front Panel• Controls = Inputs• Indicators = Outputs

Block Diagram Accompanying “program”

for front panel Components wired

together

Page 19: VI_unit_1

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

Page 20: VI_unit_1

Controls Palette (Controls & Indicators)(Place items on the Front Panel Window)

Indicator:Numeric Slide

Control:Numeric Customiz

e Palette View

Page 21: VI_unit_1

Functions (and Structures) Palette(Place items on the

Block Diagram Window)

Structure:While Loop

Page 22: VI_unit_1

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

Page 23: VI_unit_1

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

Page 24: VI_unit_1

25

Build the front panel with controls (inputs) and indicators (outputs)

NumericControl

NumericIndicator Owned

Labels

IncrementButtons

BooleanControl

BooleanIndicator

Creating a VI Front Panel

Page 25: VI_unit_1

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

Page 26: VI_unit_1

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

Page 27: VI_unit_1

28

NodesWires

ControlTerminals

Block DiagramFront PanelIndicator Terminals

Creating a VI Block Diagram

Page 28: VI_unit_1

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

Page 29: VI_unit_1

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

Page 30: VI_unit_1

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

Page 31: VI_unit_1

32

Wiring the Block Diagram Scalar

Numeric

Boolean

String

2D Array1D Array

Dynamic

Page 32: VI_unit_1

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

Page 33: VI_unit_1

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

Page 34: VI_unit_1

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

Page 35: VI_unit_1

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.

Page 36: VI_unit_1

37

NI Example Finder To find an example,

select Help»Find Examples

Web-integrated Search by keyword,

example type, hardware type, etc.

Page 37: VI_unit_1

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.

Page 38: VI_unit_1

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.

Page 39: VI_unit_1

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

Page 40: VI_unit_1

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

Page 41: VI_unit_1

42

Modular Programming

TOPICSSubVIsIcon and Connector PaneUsing SubVIsCreating a SubVI from sections of a VI

Page 42: VI_unit_1

43

LabVIEW Hierarchy

SubVI

Page 43: VI_unit_1

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

Page 44: VI_unit_1

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

Page 45: VI_unit_1

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

Page 46: VI_unit_1

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

Page 47: VI_unit_1

48

Creating the Connector

Right-click the icon (Front Panel only)

Page 48: VI_unit_1

49

Creating the Connector - continued Click with

wiring tool

Page 49: VI_unit_1

50

The Connector PaneTerminal colors match the data types to which they are connectedClick the terminal to see its associated front panel object

Page 50: VI_unit_1

51

Using a VI as a SubVI

All Functions » Select a VI… <OR>

Drag icon onto target diagram

Page 51: VI_unit_1

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

Page 52: VI_unit_1

53

Create SubVI Option Enclose area to be converted into a subVI Select Create SubVI from the Edit Menu

Page 53: VI_unit_1

54

Repetition and Loops

TOPICSWhile LoopsFor LoopsAccessing Previous Loop Data

Page 54: VI_unit_1

55

While Loops

LabVIEW While Loop Flow Chart Pseudo Code

Repeat (code);Until Condition met;End;

Page 55: VI_unit_1

56

While Loops1. Select While Loop 2. Enclose code to be repeated

3. Drop or drag additional nodes and then wire

Page 56: VI_unit_1

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

Page 57: VI_unit_1

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.

Page 58: VI_unit_1

59

For Loops

LabVIEW For Loop Flow Chart Pseudo Code

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

Page 59: VI_unit_1

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

Page 60: VI_unit_1

61

Wait Functions

Wait Until Next ms Multiple

Functions»Time & Dialog palette

Page 61: VI_unit_1

62

Wait (ms)

Functions»Time & Dialog palette

Time Delay

Functions»Time & Dialog palette

Wait Functions

Page 62: VI_unit_1

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

Page 63: VI_unit_1

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.

Page 64: VI_unit_1

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

Page 65: VI_unit_1

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

Page 66: VI_unit_1

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

Page 67: VI_unit_1

68

Feedback Node Wire from output to

input to automatically create a feedback node

<OR> Place a feedback node

from the Functions»Structures palette

Page 68: VI_unit_1

69

Initialized Shift Registers & Feedback Nodes

Run Once VI stops execution Run Again

Output = 5Output = 5

Output = 5 Output = 5

Page 69: VI_unit_1

70

Uninitialized Shift Registers & Feedback Nodes

Run Once VI stops execution Run Again

Output = 8Output = 4

Output = 4 Output = 8

Page 70: VI_unit_1

71

Making Decisions in a VI

TOPICSDecision making with the Select functionCase StructuresFormula Nodes

Page 71: VI_unit_1

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.

Page 72: VI_unit_1

73

Boolean Case Structure Example:If Temp Scale is TRUE, execute True case; if temp scale is FALSE, execute False case.

Case Structures

Page 73: VI_unit_1

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

Page 74: VI_unit_1

75

Boolean and Numeric Cases

Wire all possible outputs of the case structure

Page 75: VI_unit_1

76

String, Enum, and Error CasesString Case Enum Case Error Case

Page 76: VI_unit_1

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

Page 77: VI_unit_1

78

Decision Making with Formula Nodes

Two different ways of using an if-then statement in a Formula NodeBoth structures produce the same result

Page 78: VI_unit_1

79

Arrays

TOPICSIntroduction to ArraysAuto Indexing ArraysArray FunctionsPolymorphism

Page 79: VI_unit_1

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

Page 80: VI_unit_1

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

Page 81: VI_unit_1

82

1. Select Array Constant shell from the Array subpalette

2. Place the data object in the array shell

Creating Array Constants

Page 82: VI_unit_1

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

Page 83: VI_unit_1

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

Page 84: VI_unit_1

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

Page 85: VI_unit_1

86

Array Size

Initialize Array

Common Array Functions

Page 86: VI_unit_1

87

Array Subset

Common Array Functions

Page 87: VI_unit_1

88

The Build Array Function

Building a higher dimension array

Concatenate Inputs

Appending an element

default

Page 88: VI_unit_1

89

The Index Array Function

Extracting an Element

Extracting an Element of a Row

Extracting a Row

Page 89: VI_unit_1

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

Page 90: VI_unit_1

91

Clusters

TOPICSIntroduction to ClustersCluster FunctionsError Clusters

Page 91: VI_unit_1

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

Page 92: VI_unit_1

93

1. Select a Cluster shell from the Array & Cluster subpalette

Cluster Controls and Indicators2. Place objects inside the

shell

Page 93: VI_unit_1

94

Creating Cluster Constants1. Select Cluster

Constant shell from the Cluster subpalette

2. Place objects in the Cluster shell

Page 94: VI_unit_1

95

Cluster Order Elements have a logical order (start with 0) To change order, right-click the border and select

Reorder Controls in Cluster...

Page 95: VI_unit_1

96

Using Clusters to Pass Data to SubVIs

Use clusters to pass several values to one terminalOvercomes 28-terminal limit Simplifies wiring

Page 96: VI_unit_1

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.

Page 97: VI_unit_1

98

Cluster Functions - Unbundle

Unbundle Unbundle By Name

Page 98: VI_unit_1

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

Page 99: VI_unit_1

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.

Page 100: VI_unit_1

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

Page 101: VI_unit_1

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.

Page 102: VI_unit_1

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.

Page 103: VI_unit_1

104

Plotting Data

TOPICSWaveform ChartsWaveform and XY GraphsIntensity Graphs

Page 104: VI_unit_1

105

Waveform ChartsSelected from the Controls»Graphs and Charts palette

Page 105: VI_unit_1

106

Wiring to ChartsSingle-Plot Chart

Multiple-Plot Chart

Page 106: VI_unit_1

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

Page 107: VI_unit_1

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

Page 108: VI_unit_1

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

Page 109: VI_unit_1

110

Uniform X axisInitial X = 0.0Delta X = 1.0

Uniform X axisyou specify point spacing

Single-Plot Waveform Graphs

Page 110: VI_unit_1

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

Page 111: VI_unit_1

112

Non-uniform X axis Separate X and Y arrays

define data points

XY Graphs

Page 112: VI_unit_1

113

Chart and Graph Use SummaryUse the Context Help window with charts and graphs

Page 113: VI_unit_1

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

Page 114: VI_unit_1

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

Page 115: VI_unit_1

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

Page 116: VI_unit_1

117

String Display ModesNormal display

Password display

\ code display

Hex display

Page 117: VI_unit_1

118

Concatenate Strings(spaces here)

String Length

String Functions

Page 118: VI_unit_1

119

String FunctionsString Subset

Match Pattern

Page 119: VI_unit_1

120

Converting Numerics to Strings: Build String

Page 120: VI_unit_1

121

Converting Strings to Numerics: Scan From String

Page 121: VI_unit_1

122

Edit Format StringScan From String Function

Page 122: VI_unit_1

123

File Input and Output

Four Hierarchy Levels:High-level File VIsIntermediate File VIs and FunctionsAdvanced File Functions subpaletteExpress VIs

Page 123: VI_unit_1

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

Page 124: VI_unit_1

125

File I/O Programming Model - Intermediate

Open/Create/

Replace File

Read and/or

Write to FileClose

FileCheck for

Errors

Page 125: VI_unit_1

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

Page 126: VI_unit_1

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

Page 127: VI_unit_1

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:

Page 128: VI_unit_1

129

Creating a Spreadsheet File

Can replace Format Into String and Write File with Format Into File in above example

Page 129: VI_unit_1

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

Page 130: VI_unit_1

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.

Page 131: VI_unit_1

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.

Page 132: VI_unit_1

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

Page 133: VI_unit_1

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

Page 134: VI_unit_1

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.

Page 135: VI_unit_1

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