LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use "User Events" in different parts of an application

Hi,
 
"You programmatically can create and name your own events, called user events, to carry user-defined data. Like queues and notifiers, user events allow different parts of an application to communicate asynchronously. You can handle both user interface and programmatically generated user events in the same Event structure."
 
What you read was part of labview 7.1 user manual ( Chapter 9 - pg.12 ). I've some problems with the underlined sentence. I hope someone can help me.
 
When using Queues, the programmer may use a named queue everywhere in the application. there is no need to wire queue reference among VIs or using global variables to store queue reference. the name of the queue will be all that you need. I wonder if it is also possible with a event refnum that is the output of "Register for Event" node. As far as I've tested. the answer is Negative! I tried to copy-paste refnum in front panels and using the same name. but there is no connection between event refnums.
 
LV User manual claims that user events can be used like queues, but it doesn't seem so.
Does anybody have an idea?
 
Best Regards.
0 Kudos
Message 1 of 6
(3,323 Views)

Well, read the second part of the sentence:

allow different parts of an application to communicate asynchronously

It doesn't claim "that user events can be used like queues". The similar thing is the asynchronous comm, not the ability to use names. There are several ways in which you can pass the reference and you already mentioned two of them. If you want to, you can create a wrapper (using a LV2 global) which will maintain a list of the names and references for your dynamic events, and when you feed the name into it, it will extract the reference from your array, similar to what the Obtain Queue VI does.

___________________
Try to take over the world!
Message 2 of 6
(3,315 Views)
Hi,
 
Thank you for introducing LV2 Globals. I took a look at:
 
 
where,  Damien Gray has placed a valuable source about LV2 globals , but how much CPU overhead does USR impose? using a while loop in such a style makes me frightened! Have I gotten the idea correctly?
0 Kudos
Message 3 of 6
(3,295 Views)
I didn't look at Damien Gray's presentation recently, but if I remember it correctly, it is on a much higher level than what I meant, because it refers to LARGE application. This is a very simple one.
 
Using a functional global is not problematic CPU-wise, nor memory wise (unless you get into really big data structures, like hundreds of MBs), so you shouldn't be afraid to use it. I'm also not sure why you're afraid of the loop. The loop is only there to "hold" the USR. It only runs once. If you want, you can replace it with a for loop that runs once. I've recently learned that apparently, you can also get rid of the loop and use a local variable (look at the example called XY chart) instead of a USR. I don't think a local variable should have any more impact than a USR, but that needs to be tested. It can definitely be more convenient for some VIs where you don't have to wire the SR through the entire VI.
 
Anyway, you will need to have an "obtain ref" VI which will hold a 1D array of names and a corresponding array of refs. Then, you search the array for the name, and if it finds the name, it extracts the correct reference. You will also need a way to input references and names into the array and possibly a way to empty the array. You may need to have 2 levels - the inner VI will be the LV2 VI and the parent will be the obtain ref\fill array\close VI. You will need some error handling as well - what happens if you search for a name and it can't be found and so on...
 
Hope this helps.

___________________
Try to take over the world!
Message 4 of 6
(3,289 Views)
I'm in my first hours of working with lv2 globals. I wasn't aware of the concept at first.  you're right. there is no CPU or memory overhead. this method is quite smart.
 
About comparing local variables and USRs, I think there is an important advantage in using LV2s. please remember what I was looking for for user events. Queues, notifiers, global variables and LV2 globals are working interVIsly !! (new english)
 
there is no need to pass wires to subVIs containing their reference or anything else. they can be used everywhere in the application easily. While any of the parent VIs is in run mode, LV2 VI is reserved, so its value is preserved.
 
Thank you very much for openning another LV door to me.Smiley Happy
 
About the application that I'm developing: There is a main UI VI with freezed toolbars aside the screen. but there are also 6 UI VIs running at the background which may be shown in a subpanel in the main UI VI, each of which will cause some changes in the main UI VI menu.
The idea is to capture "menu selection" user interface events and then create user events for the VI that is being shown in the subpanel. Therefore event structures in any of those 6 VIs can handle their special menu selection event, though there is only one menu for the whole application.
 
Best Regards.
0 Kudos
Message 5 of 6
(3,282 Views)
Well, I don't really use dynamic events, but your setup sounds reasonable. You can dynamically register and unregister events as needed.
 
One thing to look out for in things that work interVIsly (NaW*) is race conditions. Wiring references into subVIs is not necessarily a bad thing - it helps to keep a certain sense of order and makes things easier to debug.
 
Good luck.
 
* NaW - not a word, with respects to JoeLabVIEW.

Message Edited by tst on 07-12-2005 11:26 AM


___________________
Try to take over the world!
0 Kudos
Message 6 of 6
(3,247 Views)