LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Nugget of the week: Dynamic event registration

One tip I would register the event in the subVI, keep the registration and the event handling tight together.

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 41 of 77
(4,293 Views)

Thanks Ton,

 

I'll have a look at this and double-check functionality...still getting to grips with all of this ..

 

cheers

 

Neil

0 Kudos
Message 42 of 77
(4,281 Views)

TonP wrote:

One tip I would register the event in the subVI, keep the registration and the event handling tight together.

 

Ton


Yes good point.

 

If you have to add or manipulate the events, only the sub-VI changes.

 

Ben

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

Thanks again for this.  I've recoded and it works!  My initial concern was that the 'lock front panel' selector option in the drop down (see above) might be associated with the 'front panel' of the wiring diagram within which it is placed.  Evidently not!

 

I think the help you have provided here is important and that the specific example I have been working on here should probably be in the NI examples database: now that I can register front panel events in a calling vi and pass it into a sub-vi where all the work is done, I can reduce coding drastically (albeit at the expense of using some sophisticated aspectes of the Labview capability.)

 

For the record it is possible to create several calling vi's which may want to access the event sub-vi capability, create an array of references for the controls of each vi front panel and then concatenate the reference array inputs just prior for feed into the 'register for events' function.  This way you can have several vi's whose front panel activities can all be detected by the single 'event handling' sub-vi pretty mind-blowing stuff!

 

Will post revised code for completeness ...soon as.

 

Thank you again.

 

Neil

Blueside

0 Kudos
Message 44 of 77
(4,217 Views)

Blueside wrote: 
This way you can have several vi's whose front panel activities can all be detected by the single 'event handling' sub-vi pretty mind-blowing stuff!

 

The other way around is possible as well, one event being handled in multiple event cases in several sub-VIs. That can be very handy as well.

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 45 of 77
(4,208 Views)

Blueside wrote:

Thanks again for this.  I've recoded and it works! ...

 

For the record it is possible to create several calling vi's which may want to access the event sub-vi capability, create an array of references for the controls of each vi front panel and then concatenate the reference array inputs just prior for feed into the 'register for events' function.  This way you can have several vi's whose front panel activities can all be detected by the single 'event handling' sub-vi pretty mind-blowing stuff!

 

Will post revised code for completeness ...soon as.

 

Thank you again.

 

Neil

Blueside


Glad it helped out.

 

Yes you can register for events from multiple places but I want to give you one "heads-up". You need one "register for event" for every event structure. Do NOT try yo branch the wire coing out of the "register for" node. This would have the same effect as splitting a queue ref wire to two readers of teh queue in that one will get the event and the other will miss it.

 

so

 

One "Register for Events" for every event structure recieving those events.

 

Have fun,

 

Ben

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

Ben wrote:

This would have the same effect as splitting a queue ref wire to two readers of teh queue in that one will get the event and the other will miss it.


Just to clarify - the effect is actually worse, because you might get some events in both structure and some might disappear entirely.

 

The bottom line is as Ben said, though - one structure per node!


___________________
Try to take over the world!
Message 47 of 77
(4,201 Views)
Follow up: Community Video Nugget on event structures and locked FPs
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 48 of 77
(3,911 Views)

I know this is an oldish thread, but it contains some great tips and could use a bump anyway...so here goes.

 

Is there a way to register a bunch of events inside a subVI and then pass the Event Registration Refnum out to a parent VI?

 

I have tried this, but it only works when the subVI is kept open, i.e. during debugging I have the FP open when running it.

 

As per the LV help: 

Registered events stay registered until you explicitly unregister them or until the VI that registered the events finishes running or you abort the VI. If the VI which registered for events was a subVI, events are unregistered when that VI's top-level VI finishes execution or is aborted. If you use the Run VI method to execute a subVI that registered for events, events are unregistered when the subVI finishes execution or is aborted.

 

How do I get the registered event to stay registered when done inside a subVI?

0 Kudos
Message 49 of 77
(3,274 Views)

Based on your description, I think you might be misunderstanding this. Presumably, to register for an FP event in a subVI, the subVI's FP should be loaded (which is usually not done automatically when the subVI is loaded). The easiest way to do this is to create a property node for one of the controls in the subVI. The property node does not have to do anything, just be there. It's enough to load the FP and then hopefully the code should work.

 

The quote you provided from the help refers to actual execution. As long as the hierarchy where the original reference was created executes (or is in a run state), the reference remains valid. When it stops executing, the reference is automatically closed. This is true of all other references as well, BTW.

 

I don't think this is your case, however.

 

In any case, passing event registration refnums around is a BAD idea. Generally, Reg for Events nodes should be right next to the event structure getting the event reference. If you want to register for an event on a control in a subVI, pass the reference to the control out of the subVI and then register for it near each event structure where it's going to be used.

 

If this doesn't help, you should upload some example code.


___________________
Try to take over the world!
0 Kudos
Message 50 of 77
(3,242 Views)