Sei sulla pagina 1di 67

Welcome!

Workshop
6 of 7
1

Today's Topics
Review of Workshop 5

Graphs & Charts Error Handling

Debugging

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)
b) c)

Required Recommended Optional

Review Question 2
On a subVI, which terminal setting causes an error if the terminal is not wired?
a)
b) c)

Required Recommended 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) b) c) d)

Free labels Labels Captions Tip strips

Review Question 4
Which of the following forms of documentation are available on the block diagram?
a) b) c) d)

Free labels Labels Captions Tip strips

10

Review Question 5
Which of the following statements are true about high-level File I/O Vis?
a)

b)

c)

High-level File I/O functions are more efficient than low-level I/O High-level File I/O functions perform the open/create, read/write, and close within the VI High-level File I/O functions are specific to one file type

11

Review Question 5
Which of the following statements are true about high-level File I/O Vis?
a)

b)

c)

High-level File I/O functions are more efficient than low-level I/O High-level File I/O functions perform the open/create, read/write, and close within the VI High-level File I/O functions are specific to one file type

12

Waveform Graphs & Charts


Special

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

single or multiple plots

13

Graphs vs. Charts


Chart:

Remembers history new point added to end of plot Good for inside a loop

Graph:
New plot of all new data
Good for outside the loop Use the Context Help window to determine how to wire multiplot data to Waveform Graphs and XY Graphs

14

Graphs & Charts

15

Chart Update Modes

Right-click the chart and select AdvancedUpdate 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

16

Demonstration: Comparing Graphs and Charts

17

Error Handling

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

18

Error Handling: Types


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

19

Errors vs. Warnings


Error Status = TRUE
Warning Status = FALSE Code is non-zero

20

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

21

Error Handling: Detection and Reporting

Use error wires to propagate errors along and handle appropriately Merge errors from different wire paths

22

Error Handling: With Loops

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

23

Handling Errors with SubVIs

Use a Case structure to handle errors passed into the subVI

24

24

Error Code Ranges


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

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

25

Debugging
Your VI isnt 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?

26

26

Debugging Tools
-use -use

highlight execution

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

27

Debugging Tools: Highlight Execution


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

28

28

Debugging Tools: Probes

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

29

29

Debugging Tools: Breakpoints

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

30

30

Debugging Tools: Single Stepping

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 OperateSuspend When Called from the shortcut menu

31

31

Homework
Debug and add error handling to the VI, FixMe.vi

32

32

Welcome!

Workshop
6 of 7
33

Today's Topics

Review of Workshop 5

VI Server Variables Race Conditions Semaphores

34

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) b) c)

Text (ASCII) TDMS Binary

35

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) b) c)

Text (ASCII) TDMS Binary

36

Review Question 2

Fill in the blanks for each block

______

______

_____

______

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


37

Review Question 2

Fill in the blanks for each block

Open/ Create/ Replace File

Read and/or Write to File

Close File

Check for Errors

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


38

Review Question 3 True or False?

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

39

Review Question 3 True or False?

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

40

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.

41

VI Server: Organization
Generic Object GObject
Pets

Control

Control
Dogs Cats

Boolean

Array

Labrador

Poodle

Stop

LED
Boolean

42

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 bottom


o

By default, if an error occurs on 3rd of 5 terminals, last two do not execute and error is output

43

43

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

44

Demonstration: Creating Property and Invoke Nodes

45

Implicitly and Explicitly Linking Invoke/Property Nodes


Explicitly Linked (requires reference) Property Node Implicitly Linked (color/ label for data type/label)

Invoke Node

46

46

Why Implicitly Link?


Implicitly Linked Property Node Main VI Explicitly Linked Property Node Main VI

VI

VI SubVI

47

SubVIs, References and Invoke/Property Nodes


Edit Create SubVI

1. Select the portion of the block diagram that will be in the subVI. 2. Select EditCreate SubVI; LabVIEW automatically creates the control references needed for the subVI.

SubVI Front Panel

SubVI Block Diagram

48

48

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

49

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

50

50

Variables
Variables - Block diagram elements that allow you to access or store data in another location
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

51

51

Use local variables to pass data within a single VI

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

52

52

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

53

53

Single Process Shared Variables

54

Shared Variables: creating and configuring


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

55

Demonstration: Creating Variables

56

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
57

57

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

uninitialized shift register

True constant permits while loop to iterate only on


58

58

Functional Global Variables: Timing


Very useful for performing customized elapsed time measurements

59

59

Variables: Recap
Variable Type Local variable Global variable Scope A single VI Notes Tied to a front panel control/indicator Multiple VIs on Tied to a special global VI that has a front same panel but no block diagram computer Multiple VIs on Implemented using a While Loop with an same uninitialized shift register to store global computer data Multiple VIs on Implemented using a project library in a same project computer Can easily convert into a networkpublished shared variable Across an Ethernet network Implemented using a project library in a project Often used to communicate with RealTime targets
60

Functional global Single-process shared variable

Networkpublished shared variable

Race Condition
A situation where the timing of events or the scheduling of tasks may unintentionally affect an output or data value
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

61

61

Race Conditions: Shared Resources

62

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

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:
o o

Functional Global Variables Semaphores

64

64

Race Condition: Critical Code


Protecting critical code with Functional Global Inside the Functional Global

65

65

Semaphores

Semaphores behave like a talking stick only the one with the semaphore/stick can talk/operator

66

66

Homework
Programmatically

change front panel objects

67

Potrebbero piacerti anche