labview workshop

Post on 11-Aug-2015

148 Views

Category:

Devices & Hardware

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Workshop 6 of 7

Welcome!

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

Review Question 1

True or False?

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

Review Question 1

True or False?

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

FALSE

Review Question 2

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

a) Required

b) Recommended

c) Optional

Review Question 2

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

a) Required

b) Recommended

c) Optional

Review Question 3

True or False?

Descriptions appear in the Context Help window.

Review Question 3

True or False?

Descriptions appear in the Context Help window.

TRUE

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

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

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

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

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

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

Review Question 2 Fill in the blanks for each block

______ ______ _____ ______

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

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

Review Question 3

True or False?

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

Review Question 3

True or False?

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

TRUE

• 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

• 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

Graphs & Charts

• 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

Demonstration: Comparing Graphs and Charts

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

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

ErrorStatus = TRUE

WarningStatus = FALSE Code is non-zero

Errors vs. Warnings

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

• Use error wires to propagate errors along and handle appropriately

• Merge errors from different wire paths

Error Handling: Detection and Reporting

• 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

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

30

Handling Errors with SubVIs

• 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

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

- 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

• 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

• 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

• 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

• 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

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.

Generic Object

GObject

Control

Boolean

VI Server: Organization

Pets

Dogs

Labrador

Poodle

Cats

Control

Boolean

Stop LED

Array

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

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

Demonstration: Creating Property and Invoke Nodes

Implicitly and Explicitly Linking Invoke/Property Nodes

Explicitly Linked(requires reference)

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

Property Node

Invoke Node

43

VI VI

Main VIMain VI

SubVI

Implicitly Linked Property Node Explicitly Linked Property Node

Why Implicitly Link?

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.

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

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

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

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

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

Single Process Shared Variables

• 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

Demonstration: Creating Variables

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

Using Variables: tips…this one?

55

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

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

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

Functional Global Variables: Timing

Very useful for performing customized elapsed time measurements

59

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

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

Race Conditions: Shared Resources

62

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

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

Race Condition: Critical Code

65

Inside the Functional GlobalProtecting critical code with Functional Global

Semaphores

Semaphores behave like a talking stick …

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

66

LAST Homework Assignment

Turn in ALL HOMEWORK soon!!

No Class Next Week!

Wednesday ,March 21 Toomey 199, prepare for a quiz

67

Homework

Review: Wednesday, April 4 at 4:00

Register

STUDY

• Go through the study guides

• Old Exams

• Webcasts

68

CLAD

top related