Você está na página 1de 18

Inside LabVIEW

Events
Jason King
Staff Software Engineer
email: jason.king@ni.com
Overview
What is event-driven programming
How to use events in LabVIEW
Caveats and common mistakes to avoid
What is planned for future versions of LabVIEW?
What Is Event-driven Programming?
An 'event' is an asynchronous notification that
some thing has occurred
Order of execution is influenced by events in the
system (user interface, external I/O, etc)
No need to poll for changes in the state of the
system
Generally a more efficient programming model
Benefits of Event-driven Programming in LabVIEW
Lower CPU usage than polling
Allows a cleaner block diagram with fewer wires
Ability to synchronize block diagram execution with front
panel interaction
Ability to detect user interactions not previously possible
Introducing...the Event Structure
What is it?
New structure node with multiple sub-
diagrams, like a Case Structure
How does it work?
Goes to sleep until an event occurs on the panel
Automatically executes the right event case (sub-diagram)
for the event
Structure completes when it finishes handling exactly
one event; does not implicitly loop
Parts of an Event Structure Parts of an Event Structure
Event Selector Label Identifies currently shown event case
Timeout Value in milliseconds to wait for events;
default value is 1 (indefinite)
Event Data Node Provides data about the event. Unique to
each event case
Event Filter Node Allows you to change
event data for a Filter event before it is
completely processed by LabVIEW or
discard it completely
Event Structure Basic Usage
Normally used in a While
Loop
Sleeps and handles exactly
one event per iteration
Event Structure Configuration
Event Structure is configured via dialog by right-clicking
its border and using Edit Events
Events are available for three classes of objects:
VI: Mouse Down/Move/Up, Key Down/Repeat/Up,
Menu Selection (App/User), Panel Closing
Control: Mouse Down/Up, Key Down/Repeat/Up,
Value Changed
Application: Application Exiting
Notify vs. Filter Events
Events are divided into two categories: Filter and Notify
Notify Events are after-the-fact notification that something
happened and LabVIEW has already reacted
Filter Events allow you to change the events data as it
happens, or discard the event entirely
Simple Event Demos
Watch for boolean value change
Confirmation dialog on closing of VI's front panel
Event Registration and Panel Locking
Events are registered when a VI with an event structure on
its diagram becomes reserved
Events are unregistered when the VI becomes idle
When a registered event occurs, it is queued until the event
structure(s) configured for it executes
It is not possible to miss events or process them out of order
By default, the front panel is locked until the event is handled
You can turn off locking, but only for Notify Events
Who Can Best Take Advantage?
Events may benefit any application that
polls for value changes on multiple controls
hides the window close box
uses the menu primitives
uses keyboard.llb to track keyboard state
needs to clean up or request confirmation when LabVIEW
shuts down
Just because you can use events, doesn't mean you
should
Caveats and Common Mistakes
Value Changed events and latched Booleans
Only reading the front panel terminal will reset the Boolean
Stop Booleans and the event-handling loop
Do not mix event-handling and polling in the same loop
Programmatic changes do not generate events
Static events generated for entire duration of VI
Make sure Event Structures are always in loops to handle events
Avoid complex processing in event-handling diagrams
Limitations of Events in LabVIEW 6.1
Static registration only; cannot register on the fly
Events are generated only by direct user interaction
No events on device I/O, etc.
Not possible to programmatically fake events in
LabVIEW 6.1
What Lies on the Horizon?
More user-interface events
Control-specific events (e.g. list box item double-click)
Dynamic registration and unregistration of events
using the VI server
User-defined events with user-defined data
Events triggered by non-user interface I/O
(ActiveX, DAQ)
Questions/Comments?
Resources
Shipping Examples
(examples/general/uievents.llb)
User manual and online reference
LabVIEW Technical Resource article (ltrpub.com)
A Powerful New Tool for UI Programming (Vol. 9, Issue 4)
Articles on NI Development Zone

(ni.com\zone search for


events and event-driven)

Você também pode gostar