12-01-2005 01:31 PM
12-01-2005 02:38 PM
If I understand the issue, then I have a relatively easy solution that seems to make sense.
You create and register for the events a single time. So as soon as your Manager is called the events are registered for, however they are registered a single time. So when you launch the SubVI it basically steals the event from the main VI. There is only 1 registered event between the 2 VIs.
To fix it is pretty easy. Whenever you are calling your manager in an init style you register for the events. So in the example simply move the register out of the case structure. Now each VI has its on instance of the registered events. You have registered to watch the single event in multiple locations.
Once I did that it seemed to work great.
12-01-2005 03:27 PM
Hi Evan:
I must be missing something. Because I think I effectively tried what you are saying by the
12-01-2005 04:25 PM
Sorry that last message came thru as it did (don't know why it did that!). Anyhow, if you see the version I have below, it effectively does what you say, reregistering the event. I tried this originally but did not rewire to the dynamic event terminal in main and I think that was the problem. By doing this, it seems that has allowed things to work. Now, however, the 'Stop' button in Main does not stop the subVI using the same user event strategy. Since I can move back and forth between mousing up in subvi and getting an invert to work in main because of reregistration, it is not clear to me why the 'Stop' User Event from main does not stop the subvi. I seem to need another eyes to check this if you don't mind.
Given all these headaches, it is probably just better to work with queues as others have suggested. I just believed User Events were a cool technology and wanted to try to extract maximum capability.
Sincerely,
Don
12-01-2005 04:55 PM
I took a look at your code and here is the problem. Every time you call the manager with an init you create a new User event. Below explains why that breaks your code.
So you start main and get Stop1, and register it, so main is watching for stop1. You now open the SubVI and it calls the manager and gets Stop1 back, so it is also watching for Stop1. In main you hit stop, which calls the manager with an Init, so you get a NEW stop user event stop2. You then fire Stop2. The problem is that the Sub was registered against stop1. Basically you have a user event leak.
Now, this is not a problem with the invert because of this.
You run main and get invert1. You open the sub and get invert1. Now in the main if you hit invert you create a new Invert event, invert2. But it works because you wire the events to the event structure so now main is watching for invert2. Now over to the subVI, when you cause the invert it looks into the Manager, but does NOT call an init so there is no new user event. So it simply fires the Invert2 event and is all good.
So basically you need to always return the same Stop user event, and not create the new Stop2 user event. Or figure a way to update the subVI to know a new Stop has been created. A down side to continually creating new user events is that you end up leaking them. What you really want to do is only create the user events 1 time. Then give all the subVIs those references. If the subVI wants to watch for them it should register the events on its own. You could remove the register from your Manager, and simply place that code at the init stage of your V
12-09-2005 08:11 AM
12-09-2005 10:26 AM
12-09-2005 01:42 PM
I did not address error handling in this simple example. Normally if an error is incurred, the program would be directed to an error case by inserting a 'go to error case' action into the queue.
If you don't mind, refactor my simple VI to better explain your handling of producer-consumer as you described in the last message and post.
Thanks,
Don
12-09-2005 03:09 PM
...ps. Would also be interested to know where it makes sense to also use User Events within a queue-driven architecture if you can define actions you want in the enum type def and just feed them to the queue for execution when needed.
Thanks again,
Don
12-12-2005 12:28 PM