LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Generic Event Handler

I would like to create a single event handler that is called any time one of my FP controls has a value change event. Is there any way to do this without putting each control into the event specifiers list?
 
Thanks,
+Ben
0 Kudos
Message 1 of 10
(3,511 Views)
Hello,

Yes, its possible.

With the VI property Panel you can retrieve the references to all controls on the front panel of a particular VI (any VI that you have a reference of).

Using dynamic event registration for the control references or a subset thereof you can select the event that you like to register for that group or individual control (e.g. Mouse down, Key up). Now you can select the dynamically registered event in your event handler.

Regards,

André
Regards,
André (CLA, CLED)
Message 2 of 10
(3,502 Views)
Okay I will give that a try, but to me it sounds like each of these events will still be registered as an independant event. I just want one block of code that executes any time a value changes on the front panel. Additionally, for code simplicity I would prefer not to use dynamic event registration.
 
+Ben
0 Kudos
Message 3 of 10
(3,498 Views)
Ben,

If you wire an array of control refs to the dynamic event registration and select e.g. "value changed". The event will show as one in the event handler and in the event case you can get the reference to the changed control to do something.

The creation of the array of controls can be done inside a subVI, I'm not sure for the event registration. But using a state-machine would get you acceptable code.

Normally I use a state-machine with three or four states depending on the architecture. Init, (Init ready), Main and Terminate. The VI starts in Init  where opens necessary references and do event registration. Then it goes to Main where handles events and stays until termination condition is met. In Terminate all remaining open references are closed.

Regards,

André
Regards,
André (CLA, CLED)
Message 4 of 10
(3,493 Views)
Hello,

the LabVIEW examples have a similar item, search for dynamic register for events. Where the mouse down and mouse up for any control is registered, similarly this can be done for 'value change'

Ton
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 5 of 10
(3,488 Views)
You did not explain the purpose of your quest.
 
If you have a toplevel UI loop and only want to spin it whenever things change, a quick&dirty way would be to simply place a "wait for front panel activity" in the loop. Might just be good enough, depending on the exact needs. 😉
 
The advantages over the other suggestions is "way less code!" 😄
 
 
It is in the Dialog&UI palette.

Message Edited by altenbach on 07-19-2007 12:39 PM

Message 6 of 10
(3,481 Views)
FYI, the purpose here is that I have a program with hundreds of controls that need to be monitored simultaneously. Each control initiates a unique action, although most of these actions fall into a dozen or so generic categories. Essentially, I would like to create unique handlers for these dozen types of action and use a lookup table to determine which handler should be called based on which control generated the event. Other lookup tables would contain information specific to the control to make the generic action behave specifically as intended.
 
Unfortunately, I can't use Wait on FP events because that VI does not return a reference to the event generator and also because the loop needs to continuously update other values on the FP.
 
I guess that dynamic registration will work for me. I was just hoping that I would be able to find an easier way to do this.
 
Thanks so much for all of your help.
0 Kudos
Message 7 of 10
(3,456 Views)
A variation on the theme that you were given earlier is if all the controls are in a cluster you could use a control reference to the cluster to read the cluster's Controls[] property which returns an array of control references to all the controls in the cluster. That would save needing to build all those separate references into an array.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 8 of 10
(3,445 Views)
I've discovered another problem with dynamically registering for events in my application. There does not appear to be a way to register a 'value change' event dynamically because I can't select 'value change' from the "Events" list in the register for events node. Maybe I am missing something...
 
Any further suggestions?
 
0 Kudos
Message 9 of 10
(3,439 Views)
Nevermind. After deleting the node and replacing it the value changed event has appeared.
0 Kudos
Message 10 of 10
(3,437 Views)