04-08-2019 05:44 PM
I am trying to get one case in an event structure to execute automatically after another case triggers. I read up on it and found I can do this with Dynamic Events. I found various things on internet including a Youtube video but I am just having trouble understanding how to make this work. I have attached a simplified VI. I want Case 2 to execute automatically after I trigger Case 1 . Please show me how to do this. Very confused by the Register Events, Create Events, and Generate Events VI's.
What I want to end up with is: If I press Case 1 button , LED 1 should light up and then LED 2 lights up as case 2 executes.
Solved! Go to Solution.
04-08-2019 06:15 PM
LabVIEW ships with some example code for this, you can find it here:
C:\Program Files (x86)\National Instruments\LabVIEW 2018\examples\Dialog and User Interface\Events\User Event Generation.vi
It's a bit more complex than you'll need but you can see in it the basic building blocks:
1. Create user event
2. Register that event
3. Wire that registration to an event case (after right-clicking to show Dynamic event terminals on it)
4. Create a case that runs that event
5. Use the Generate user event node to trigger it
...
X -1. Destroy user event when done
X. Unregister for events when done.
04-08-2019 08:24 PM
Here is the your code modified as explained by Kyle97330.
04-09-2019 09:18 AM
@rhodesengr wrote:
I am trying to get one case in an event structure to execute automatically after another case triggers. ...
What I want to end up with is: If I press Case 1 button , LED 1 should light up and then LED 2 lights up as case 2 executes.
While others have provided rope to hang yourself I will try to offer an alternative (life really is not that bad).
Have you considered creating a sub-VI that lights LED 2 ?
You can use that sub-VI in more than one event so it can be used in the event that lights LED 2 by itself OR it can be called in the Event for LED 1 AFTER LED 1 is lit?
Trying my best to save another LV life.
Ben
04-09-2019 09:58 AM
Here is some more rope:
Take a look at the "Value (Signaling)" property node...
04-09-2019 10:10 AM
@playerm1 wrote:
Here is some more rope:
Take a look at the "Value (Signaling)" property node...
Why stop with just a short chunk of rope?
See this old Nugget by Ton about dynamic event registration where offers a reel of rope. He demonstrates how to dynamically un-register, re-register...
"Oh what a tangled web we weave when first we practice to deceive dynamically register events."
Ben
04-09-2019 11:13 AM
MarcDub
Thanks to you and all the others for the ideas. After I posted, I sort of figured it out and I am showing that below. I notice that your input to the Reg Events is a little different than what I did and I'd like to understand the difference and how they would behave. I did mine by right clicking on the button in case one to get a Refnum. In my real VI I have quite a few buttons that run cases. Does your way work on any Boolean going true? I think my version might be specific to one switch.
Also, what is the difference between Unregister and Destroy? What happens if you don't include Destroy? What happens if you don't Unregister.
04-09-2019 11:26 AM
You have registered an event directly associated with one of your controls. What you did is the equivalent of creating a value-change event for Case1 directly in the event structure. My approach was to programmatically generate an event, independent from any control. It all depends what you want to do.
When you register events, LabVIEW is creating the structure to monitor those events. When you unregister the events, you let know LabVIEW that there is no need to monitor those events anymore.
Similarly, when creating an event, LabVIEW allocates some resources for that event. It is recommended practice to destroy it whenever you are finished with it. Notice that you can register an event with more than one event structures. That is why you should unregister first then destroy the event.
It is the recommended practice to unregister and destroy but for a single event structure, it might not matter much from a point of view memory management. LabVIEW will clear out the memory upon terminating the VI.
04-09-2019 11:33 AM - edited 04-09-2019 11:36 AM
This really is simple enough to do without any dynamic events.
Two easy options:
Of course for the second case you need to protect from the possibility that other events are pending, overwriting the timeout. I typically keep all state data in shift registers, manipulate it in the various event cases, then trigger the timeout event to update all indicators as needed.
04-09-2019 12:20 PM
MarcDub,
I tried your method but it doesn't seem to actually work. Maybe I missed something? I attached the VI
Mine works but I have to add an input in the Reg Event VI for each button. It would be nice if one input for any button going True triggers the VI I want triggered.