Sei sulla pagina 1di 33

Welcome!

Workshop
6 of 7
Today's Topics
 VI Server
 Variables
 Race Conditions
 Semaphores
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.


VI Server: Organization Generic
Object
GObject

Pets Control

Control
Dogs Cats Boolean Array

Labrador Poodle Stop LED


Boolean
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


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

5
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 Implicitly Linked
(requires reference) (color/ label for data type/label)
Property
Node

Invoke
Node

8
Why Explicitly Link?
Implicitly Linked Property Node Explicitly Linked Property Node

Main VI Main VI

VI VI
SubVI
SubVIs, References and Invoke/Property Nodes

Edit»
Create
SubVI

1. Select the portion of


the block diagram that SubVI Front Panel SubVI Block Diagram
will be in the subVI.

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

10
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

12
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
• Shared - Transfers data between various distributed
targets connected together over a network

13
Variables: within a single VI
Use local variables to pass data within a single VI

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

14
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

15
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
Single Process Shared Variables
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….

19
Using Variables: tips
…this one?

20
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

21
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

22
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

23
Functional Global Variables: Timing
Very useful for performing customized elapsed
time measurements

24
Variables: Recap
Variable Type Scope Notes
Local variable A single VI • Tied to a front panel control/indicator
Global variable Multiple VIs on • Tied to a special global VI that has a front
same panel but no block diagram
computer
Functional Multiple VIs on • Implemented using a While Loop with an
global same uninitialized shift register to store global
computer data
Single-process Multiple VIs on • Implemented using a project library in a
shared variable same project
computer • Can easily convert into a network-
published shared variable
Network- Across an • Implemented using a project library in a
published Ethernet project
shared variable network • Often used to communicate with Real-
Time targets
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 and limiting shared resources
• Specifying the execution order
• Identifying and protecting critical sections within your code

26
Race Conditions: Shared Resources

27
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

28
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

29
Race Condition: Critical Code

30
Race Condition: Critical Code (Protected)
Protecting critical code with Functional Global Inside the Functional Global

31
Semaphores

Semaphores behave like a


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

32
Homework
• Programmatically change front panel objects

Potrebbero piacerti anche