Download - LabView Workshop

Transcript
Page 1: LabView Workshop

Workshop 6 of 7

Welcome!

Page 2: LabView Workshop

Today's Topics Review of Workshop 5

o Graphs & Charts

o Error Handling

o Debugging

o VI Server

o Variables

o Race Conditions

o Semaphores

Page 3: LabView Workshop

Review Question 1

True or False?

You must create a descriptive icon for a subVI and wire the connector pane

Page 4: LabView Workshop

Review Question 1

True or False?

You must create a descriptive icon for a subVI and wire the connector pane

FALSE

Page 5: LabView Workshop

Review Question 2

On a subVI, which terminal setting causes an error if the terminal is not wired?

a) Required

b) Recommended

c) Optional

Page 6: LabView Workshop

Review Question 2

On a subVI, which terminal setting causes an error if the terminal is not wired?

a) Required

b) Recommended

c) Optional

Page 7: LabView Workshop

Review Question 3

True or False?

Descriptions appear in the Context Help window.

Page 8: LabView Workshop

Review Question 3

True or False?

Descriptions appear in the Context Help window.

TRUE

Page 9: LabView Workshop

Review Question 4

Which of the following forms of documentation are available on the block diagram?

a) Free labels

b) Labels

c) Captions

d) Tip strips

Page 10: LabView Workshop

Review Question 4

Which of the following forms of documentation are available on the block diagram?

a) Free labels

b) Labels

c) Captions

d) Tip strips

Page 11: LabView Workshop

Review Question 5

Which of the following statements are true about high-level File I/O Vis?

a) High-level File I/O functions are more efficient than low-level I/O

b) High-level File I/O functions perform the open/create, read/write, and close within the VI

c) High-level File I/O functions are specific to one file type

Page 12: LabView Workshop

Review Question 5

Which of the following statements are true about high-level File I/O Vis?

a) High-level File I/O functions are more efficient than low-level I/O

b) High-level File I/O functions perform the open/create, read/write, and close within the VI

c) High-level File I/O functions are specific to one file type

Page 13: LabView Workshop

Review Question 1

You are logging data from multiple sensors over many hours that you will process later using VIs written by a colleague. Which file type would best to use?

a) Text (ASCII)

b) TDMS

c) Binary

Page 14: LabView Workshop

Review Question 1

You are logging data from multiple sensors over many hours that you will process later using VIs written by a colleague. Which file type would best to use?

a) Text (ASCII)

b) TDMS

c) Binary

Page 15: LabView Workshop

Review Question 2 Fill in the blanks for each block

______ ______ _____ ______

a) Close b) Open/Create/Replace c) Check for Errorsd) Read or Write

Page 16: LabView Workshop

Review Question 2 Fill in the blanks for each block

a) Close b) Open/Create/Replace c) Check for Errorsd) Read or Write

Open/Create/

Replace File

Read and/or

Write to File

Close File

Check forErrors

Page 17: LabView Workshop

Review Question 3

True or False?

All instances of a polymorphic VI must have the same connector pane.

Page 18: LabView Workshop

Review Question 3

True or False?

All instances of a polymorphic VI must have the same connector pane.

TRUE

Page 19: LabView Workshop

• Special type of numeric indicator that displays one or more plots of data, typically acquired at a constant rate

• Displays single or multiple plots

Waveform Graphs & Charts

Page 20: LabView Workshop

• Chart:• Remembers history – new point added to end of plot

• Good for inside a loop

Graphs vs. Charts

• Graph:• New plot of all new data

• Good for outside the loop

• Use the Context Help window to determine how to wire multi-plot data to Waveform Graphs and XY Graphs

Page 21: LabView Workshop

Graphs & Charts

Page 22: LabView Workshop

• Right-click the chart and select Advanced»Update Mode from the shortcut menu

• Strip chart is the default update mode

• Scope chart and Sweep chart modes display plots significantly faster than the strip chart mode

Chart Update Modes

Page 23: LabView Workshop

Demonstration: Comparing Graphs and Charts

Page 24: LabView Workshop

Anticipation, detection, and resolution of warnings and errors

Essential for:• Debugging - helps to catch programming errors• Stress testing - helps to test application boundary cases• Robustness - helps detect errors introduced by system

and environment differences

Error Handling

Page 25: LabView Workshop

Automatic: if error out is left unwired, LabVIEW will handle it automatically (dialog box)

Manual: wiring the error out terminal means manual error handling is occuring- you decide what to do with the error.

Remember... without a mechanism to check for errors, you know only that the VI does not work properly

Error Handling: Types

Page 26: LabView Workshop

ErrorStatus = TRUE

WarningStatus = FALSE Code is non-zero

Errors vs. Warnings

Page 27: LabView Workshop

Error Handling: Functions

Simple Error Handler VI

• creates a pop-up dialog box to notify user of error that has occurred

• Configurable to handle warnings, too

• Avoid using in subVIs

Merge Error VI

• combines multiple error wires into a single error wire

• error received on the top most input will be passed out, others will be ignored

Page 28: LabView Workshop

• Use error wires to propagate errors along and handle appropriately

• Merge errors from different wire paths

Error Handling: Detection and Reporting

Page 29: LabView Workshop

• Use shift-registers to detect errors and warnings in all loop iterations

• Use error status as a condition to stop a loop• While Loops

• Conditional For Loops

Error Handling: With Loops

Page 30: LabView Workshop

• Use a Case structure to handle errors passed into the subVI

30

Handling Errors with SubVIs

Page 31: LabView Workshop

• Refer to the LabVIEW Help for complete list of error code ranges:

• Fundamentals » Running and Debugging Vis » How-To » Error Codes and Messages » Ranges of LabVIEW Error Codes

Error Code Ranges

• Codes are subdivided into ranges according to product and VI grouping

• Most codes are unique, but some error codes are used by more than one product or VI grouping

Page 32: LabView Workshop

Your VI isn’t broken, but you are getting unexpected data or behavior…

Any unwired or hidden subVIs?

Incorrect default data being used?

Undefined data being passed?

Numeric representation correct?

Node execution order correct?

32

Debugging

Page 33: LabView Workshop

- use highlight execution

- use probes to see the current value in the wire

- set breakpoints to pause execution at a specific point in the code

- single-step through the code

Debugging Tools

Page 34: LabView Workshop

• 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

34

Debugging Tools: Highlight Execution

Page 35: LabView Workshop

• Use the Probe tool to • observe intermediate data values

• check the error output of VIs and functions, especially those performing I/O

• Values can be retained in the wires so that you can probe wires for data after execution has finished

35

Debugging Tools: Probes

Page 36: LabView Workshop

• 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

36

Debugging Tools: Breakpoints

Page 37: LabView Workshop

• 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

• control the number of times it runs

• go back to the beginning of the execution of the subVI

• Open subVI and select Operate»Suspend When Called from the shortcut menu

37

Debugging Tools: Single Stepping

Page 38: LabView Workshop

VI Server

LabVIEW organizes and operates on its parts (front panel, button, arrays, etc.) within an architecture called VI Server, which is object oriented.

Terminology:

A class defines what an object is able to do, what operations it can perform (methods), and what properties it has.

An object is a member of a class.

Methods perform an operation on an object.

Properties are the attributes of an object.

Page 39: LabView Workshop

Generic Object

GObject

Control

Boolean

VI Server: Organization

Pets

Dogs

Labrador

Poodle

Cats

Control

Boolean

Stop LED

Array

Page 40: LabView Workshop

Property Nodes

• Access the properties of an object

• Enable you to modify the appearance of front panel objects programmatically in response to certain inputs.

• For example,

If a user enters an invalid password, you might want a red LED to start blinking

If a data point is above a certain value, you might want to show a red trace instead of a green one

• Execute from top to bottomBy default, if an error occurs on 3rd of 5 terminals, last two do not execute

and error is output

40

Page 41: LabView Workshop

Invoke Nodes• Use the Invoke Node to perform actions, or methods, on

referenced items (VI, Control)

• Most methods have parameters

• Examples of VI Methods:

• Front Panel: Center

• Default Values: Reinitialize all to Default

• Print: VI to HTML

Method Name

Parameters

Page 42: LabView Workshop

Demonstration: Creating Property and Invoke Nodes

Page 43: LabView Workshop

Implicitly and Explicitly Linking Invoke/Property Nodes

Explicitly Linked(requires reference)

Implicitly Linked(color/ label for data type/label)

Property Node

Invoke Node

43

Page 44: LabView Workshop

VI VI

Main VIMain VI

SubVI

Implicitly Linked Property Node Explicitly Linked Property Node

Why Implicitly Link?

Page 45: LabView Workshop

SubVIs, References and Invoke/Property Nodes

45

SubVI Front Panel SubVI Block Diagram

Edit»Create SubVI

1. Select the portion of the block diagram that will be in the subVI.

2. Select Edit»Create SubVI; LabVIEW automatically creates the control references needed for the subVI.

Page 46: LabView Workshop

Demonstration: Creating References for Property and Invoke Nodes; Selecting a Class

Page 47: LabView Workshop

Variables

• Cannot pass data between parallel loops with a wire

• Variables allow you to circumvent normal dataflow by passing data from one place to another without connecting the two places with a wire

47

Page 48: LabView Workshop

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

Variables - Block diagram elements that allow you to access or store data in another location

48

Variables

Page 49: LabView Workshop

Use local variables to pass data within a single VI

49

Variables: within a single VI

NOTE: Boolean controls with associated local variables must use switch mechanical action; boolean latch action is incompatible with local variables

Page 50: LabView Workshop

Variables: between multiple VIs

Use a global variable to share data among VIs on the same computer, especially if you do not use a project file

Use a single process shared variable if you may need to share the variable information among VIs on multiple computers in the future

50

Page 51: LabView Workshop

Single Process Shared Variables

Page 52: LabView Workshop

• You must have a project open to create a shared variable

• Variable configuration data is stored in Project Libraries

• LabVIEW will automatically create a library if the variable was not created from an existing library

Shared Variables: creating and configuring

Page 53: LabView Workshop

Demonstration: Creating Variables

Page 54: LabView Workshop

Using Variables: tips

• Use wires if possible

• Variables go against LabVIEW’s data flow paradigm, so only use when necessary

• Variables create opportunity for race conditions (discussed later)

Which block diagram is easier to determine function? This one or….

54

Page 55: LabView Workshop

Using Variables: tips…this one?

55

Page 56: LabView Workshop

Using Variables: Initialization• Verify that variables

contain known data values before the VI runs

• If you do not initialize the variable before the VI reads it for the first time, it contains the default value of the associated front panel object

56

Page 57: LabView Workshop

Functional Global Variables Special subVI with purpose of storing data by using uninitialized shift register

General form includes

- an uninitialized shift register

- a single iteration For or While Loop

57

uninitialized shiftregister

True constant permits while loop to iterate only once

Page 58: LabView Workshop

Functional Global Variables

• A functional global variable usually has an action input parameter that specifies which task the VI performs

• The VI uses an uninitialized shift register in a While Loop to hold the result of the operation

58

Page 59: LabView Workshop

Functional Global Variables: Timing

Very useful for performing customized elapsed time measurements

59

Page 60: LabView Workshop

Variables: RecapVariable Type Scope Notes

Local variable A single VI • Tied to a front panel control/indicator

Global variable Multiple VIs on same computer

• Tied to a special global VI that has a front panel but no block diagram

Functional global Multiple VIs on same computer

• Implemented using a While Loop with an uninitialized shift register to store global data

Single-process shared variable

Multiple VIs on same computer

• Implemented using a project library in a project

• Can easily convert into a network-published shared variable

Network-published shared variable

Across an Ethernet network

• Implemented using a project library in a project

• Often used to communicate with Real-Time targets

Page 61: LabView Workshop

Race Condition

• Common problem for programs that execute multiple tasks in parallel and share data between the tasks

• 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

• Properly sequencing instructions

• Identifying and protecting critical sections within your code

• Reducing use of variables

A situation where the timing of events or the scheduling of tasks may unintentionally affect an output or data value

61

Page 62: LabView Workshop

Race Conditions: Shared Resources

62

Page 63: LabView Workshop

Race Conditions: Sequencing

What is the final value?

Four possible outcomes:• Value = (Value * 5) +2• Value = (Value + 2) * 5• Value = Value * 5• Value = Value +2

63

Page 64: LabView Workshop

Race Condition: Critical Code

• A critical section of code is code that may behave inconsistently if some shared resource is altered while it is running

• If one loop interrupts another loop while it is executing critical code, then a race condition can occur

• Eliminate race conditions by identifying and protecting critical code with:

Functional Global Variables

Semaphores

64

Page 65: LabView Workshop

Race Condition: Critical Code

65

Inside the Functional GlobalProtecting critical code with Functional Global

Page 66: LabView Workshop

Semaphores

Semaphores behave like a talking stick …

only the one with the semaphore/stick can talk/operator

66

Page 67: LabView Workshop

LAST Homework Assignment

Turn in ALL HOMEWORK soon!!

No Class Next Week!

Wednesday ,March 21 Toomey 199, prepare for a quiz

67

Homework

Page 68: LabView Workshop

Review: Wednesday, April 4 at 4:00

Register

STUDY

• Go through the study guides

• Old Exams

• Webcasts

68

CLAD


Top Related