Download - Inside Events
-
8/2/2019 Inside Events
1/16
National Instruments Confidential
Inside LabVIEW:Event-driven Programming
-
8/2/2019 Inside Events
2/16
National Instruments Confidential
Overview
What is event-driven programming
How to use events in LabVIEW
Caveats and common mistakes to avoid
-
8/2/2019 Inside Events
3/16
National Instruments Confidential
What Is Event-driven Programming?
Order of execution is influenced by events on the userinterface
Code executes in response to change in state of system
No need to poll for change in state Event loops versus call-backs
-
8/2/2019 Inside Events
4/16
National Instruments Confidential
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) forthe event
Structure completes when it finishes handling exactly oneevent; does not implicitly loop
-
8/2/2019 Inside Events
5/16
National Instruments Confidential
Event Structure Basic Usage
Normally used in a WhileLoop
Sleeps and handles exactlyone event per iteration
Event Data available interminals on structures leftborder
Can right-click on event data
and show only the terminalsyou need
-
8/2/2019 Inside Events
6/16
National Instruments Confidential
Event Structure Configuration
Event Structure is configured via dialog by right-clicking its border and using Edit Events
LabVIEW 6.1 events are divided into three classes:
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
-
8/2/2019 Inside Events
7/16National Instruments Confidential
Notify vs. Filter Events
Events are divided into two categories: Filterand Notify Notify Events are after-the-fact notification that something
happened
Filter Events allow you to change the events data as it
happens, or discard the event entirely Key events, Mouse events, Menu events, and the front panel window
closing event are all filter events
Filter Event Examples:
Make string controls that map upper- to lower-case Bring up a confirmation dialog when the user tries to close the panel
-
8/2/2019 Inside Events
8/16National Instruments Confidential
Parts of an Event Structure
Event Selector Label identifies currently shown event case Timeout - value in milliseconds to wait for events;
default value is1 (indefinite)
Event Data Node - data unique to each event case
Event Filter Node - allows you to changeor discard event data for a Filter event
before the event is completely processed
Defaulted Tunnels - new kind of tunnel
which allows unwired cases to providedefault values
-
8/2/2019 Inside Events
9/16National Instruments Confidential
Simple Event Demos
Event tracking of front panel controls Event Tracking.vi (LabVIEW 6.1 shipped example)
Confirmation dialog on closing of VI's front panel Event Conditional Stop.vi (LabVIEW 6.1 shipped example)
-
8/2/2019 Inside Events
10/16National Instruments Confidential
Event Registration and Panel Locking
Events are registered when a VI with an event structure onits diagram becomes reserved
When an 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, front panel is locked until the event is handled
You can turn off locking, but only for Notify Events
Events are unregistered when the VI becomes idle
-
8/2/2019 Inside Events
11/16National Instruments Confidential
Limitations of Events in LV 6.1
Static registration only; cant register on the fly Events are generated onlyby direct user interaction
No events on device I/O, etc.
Not possible to programmatically fake events in 6.1(without cheating)
-
8/2/2019 Inside Events
12/16National Instruments Confidential
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
Dont 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
An event-handling loop is not a state machine
-
8/2/2019 Inside Events
13/16National Instruments Confidential
Events and UI Design Patterns
Sophisticated UIs which use a state machine orqueued message handler design can be easily
retrofitted to use events
Simply replace the idle case in your state machinewhich does polling with an event structure configured
to detect the same UI changes
-
8/2/2019 Inside Events
14/16National Instruments Confidential
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
needs to clean up or request confirmation when LabVIEWshuts down
Events work with Remote Panels, with either a fullLabVIEW client or the web browser plug-in
-
8/2/2019 Inside Events
15/16National Instruments Confidential
Resources
Shipping Examples(examples/general/uievents.llb)
User manual and on-line reference
LabVIEW Technical Resource article (http://ltrpub.com)A Powerful New Tool for UI Programming (Vol. 9, Issue 4)
Articles on NI Dev-Zone (http://zone.ni.com - search forevents and event-driven)
See http://www.ni.com/infoand enter code niweek02 for on-line access to these slides and further information
http://ltrpub.com/http://zone.ni.com/http://www.ni.com/infohttp://www.ni.com/infohttp://zone.ni.com/http://ltrpub.com/ -
8/2/2019 Inside Events
16/16N ti l I t t C fid ti l
Questions/Comments?