LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Nugget of the week: Dynamic event registration



@wpolk wrote:

Is that so different from inserting a subpanel?

Yes, because user events do not necessarily have to deal with UI elements and because the event can be handled for a control in the caller VI (or any other VI). You can even make the subVI reentrant and have it handle multiple controls.

See the attached for a very quick example of how a generic tool would look like. In this case, for example, I went with Ton's idea of picture controls and I made a generic process which will draw points in picture controls.

BTW, this quick example has some bugs in it. For example, it's slightly off. Also, it doesn't take the origin property into consideration. It also has a race condition, since the value of the image can be changed from elsewhere after it's read and before it's written, but this just shows the concept.

Some other nice things about user events:

The event refnum is typed, so it holds all the event data. That means (as Tomi mentioned) that you can use them to pass data around. See for example the stop event in my example which reads the value from the event structure terminals. You can create complex structures for this.

If you don't wire anything into the dynamic event terminal on the right side of the event structure, it will retain the same information it had when it entered your case. You can use this to do state machines where you don't have to wire your data cluster through events where it is not needed, because it will simply be passed through.


___________________
Try to take over the world!
Message 11 of 77
(12,113 Views)

Excellent Nugget Ton. Right to the point and you sure pushed my knowledge.

Your example will be incorported into future designs I am sure. When I have done similar apps I was faced with the issue of CPU spinning away because of the events.

My use of dynamic event registration has been mostly DSC event.

I liked tst's example so much I made a couple of changes for Ton Smiley Happy.

Thank you and feel free to post more when the inspiration hits you.

Ben

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 12 of 77
(12,086 Views)

Another BTW - you can also use this to register the same event for several controls if you build their references into an array and wire that array into the registration node.

If you build a cluster out of those references, you will get a single event for each reference in the cluster.


___________________
Try to take over the world!
Message 13 of 77
(12,057 Views)

Please see this thread for more discusions reagarding the nature of events.

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 14 of 77
(11,758 Views)


@TonP wrote:

I was not fully sure this was necassary, I thought this only was needed for user events because you have to destroy those.



Yes LV will continue sending events to all VIs that are registered to receive it - even if they aren't actually executing at the moment. This really becomes a problem if you have an event registration set to "Lock panel till handler completes". In this case the handeler never completes because the VI containing the handler code isn't even executing.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

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

For help with grief and grieving.
Message 15 of 77
(11,760 Views)
The Code Capture Tool includes an example of using dynamic events in a separate process to pan a picture control.

___________________
Try to take over the world!
Message 16 of 77
(10,437 Views)
Sorry to jump into this thread late, just thought someone may have a quick answer for me.

If I build multiple references into an array, and wire that array into the dynamic event structure, how can I assign a name to the array such that the event structure can "see" it, and not have the default <?> event name.

I have tried to use a front panel array control with nothing in it, then I use replace array subset to essentially name my array of references. This seems to work in that the event structure can pick up on the name of the control, but the actual events no longer work! (See attached...)

Any ideas?
Message 17 of 77
(10,289 Views)
Hi nrp,

what kind of event do you want to process? When the array of references changes??? Why do you need the name of that array in the event structure?
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 18 of 77
(10,286 Views)
GerdW,

Using an array is just for convenience. In one instance I have several difference boolean controls which I all have the same response, i.e I want to process them in one event structure, so it seems sensible to group them together using an array.

In another circumstance, I have several boolean controls all with similar desired response, I wish to use an array and then in my event structure detect which of the elements has caused the event.

I want to "name" the grouping of references so that in the event structure I can see the actual names rather than <?> which comes up if the references do not have a name.
Message 19 of 77
(10,281 Views)
Ton,
I am a bit confused by this.  In your advanced example, two of the events are on a ref constant.  How can you have an event on a ref constant?  I thought that I understood what you were doing by registering a constant, you were turning off an event.  I am trying to write a VI that allows a user to click and drag a data point on a graph.  My intention is that on mouse up, the cursor is placed on a data point.  If the cursor is on the correct data point, the user then could click and drag (mouse move enable) the y axis value of the point.  Upon mouse up, the drag (mouse move) would be disabled again.
Jim

LV 2020
Download All
Message 20 of 77
(9,672 Views)