LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with Dynamic Events

Solved!
Go to solution

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. 

0 Kudos
Message 1 of 17
(1,448 Views)

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.

0 Kudos
Message 2 of 17
(1,434 Views)
Solution
Accepted by rhodesengr

Here is the your code modified as explained by Kyle97330.

 

simple two LED Event Case Structure (mod)_BD.png

Marc Dubois
HaroTek LLC
www.harotek.com

Message 3 of 17
(1,420 Views)

@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.

 

Spoiler
I have seen a lot of really bad code in my time. Some of which has left me with the feeling that the previous developer of some LV applications have run away screaming after finishing an application swearing to never touch LabVIEW again.

 

Ben 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 17
(1,388 Views)

Here is some more rope:

 

Take a look at the "Value (Signaling)" property node...

0 Kudos
Message 5 of 17
(1,380 Views)

@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

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 6 of 17
(1,372 Views)

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.

 

Dynam 1.jpg

0 Kudos
Message 7 of 17
(1,359 Views)

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.

Marc Dubois
HaroTek LLC
www.harotek.com

0 Kudos
Message 8 of 17
(1,353 Views)

This really is simple enough to do without any dynamic events.

 

Two easy options:

  1. use a signaling value property (as has been mentioned already, but that requires changing to switch action, but you can reset the buttons in it's event)
  2. Manipulate and utilize the timeout event (see attached).

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. 


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 9 of 17
(1,349 Views)

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.

0 Kudos
Message 10 of 17
(1,336 Views)