LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

registering user events in a loop

In my application, I am creating a number of user events at initialization within a SubVI, which subsequently passes the Event Registration Refnum and the array of User Events to an event loop in the main application.  As I develop the application, I am discovering that I need to keep adding new events to the initialization SubVI, adding both an input to the Register for Events node and another element to the array of User Events out for each new user event.  My block diagram is starting to get messy, as I have now 19 such events.  As the user event data type for every one of these events is type Variant, I'm wondering if it is possible to pass the array of variants into a FOR loop which registers the event and concatenates the array of user events, or if event registration has to occur for all events on the same Register for Events node?  Every time I add an input to the Register for Events node, it breaks the output indicator for the Event Registration Refnum in my SubVI, and I have to delete it and recreate it, relinking it to a connector pane terminal, which is a pain.  Am I missing something?

 

0 Kudos
Message 1 of 28
(3,281 Views)

Do NOT put the registration inside of the the subVI.  And you might want to use a Cluster of your events.  You can register the cluster of events very easily.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 28
(3,276 Views)

But but... why NOT put Register for Event in a different VI then where it's being used and wired to a dynamic event terminal? I'm trying to create a Registration refnum, then pass it out of the VI, and into another VI.  I can add an event to the event structure dynamic terminal there, but can't "see" the event's data.  It compiles, but no data, no worky.  I'm confused.  I wanted to have to only have to generate my registration refnum once, and use it many times, not have to recreate it every time I run the VI with the event structure in it.  Seemed like a good idea...

0 Kudos
Message 3 of 28
(2,395 Views)

If you are implementing Register User Events in a sub VI, for each update in your input value the registration refnum value will get changed so you need to change the output node of sub VI. same update needs to done in dynamic user events for every update.

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 4 of 28
(2,379 Views)

Thanks for replying, Palanivel - So here's what I have. I create the Registration Refnum in "Timer FGV", and pass it out. My intent was to then pass it in to "Timer Event Loop".  But when I try to edit the event in that event loop, the (boolean) data doesn't appear / isn't available.  It's as if making the Registration Refnum an output of one function, then an argument of another, 'strips' the event data from it.  Now - to check, within the FGV VI, I made an event structure, wired the Registration Refnum to its dynamic terminal, and voila! The boolean data *is* available, and the event can behave properly  to catch an event.  So somehow, bringing the refnum out of one VI and in to another breaks the data.  I don't get why? paul

Download All
0 Kudos
Message 5 of 28
(2,355 Views)

OK, as I read the Help more carefully: "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."

 

So, when my 1st VI that registered the event finishes, the event gets unregistered. Game over.  So basically, you can't pass a registration refnum between VI's. Do you agree?

0 Kudos
Message 6 of 28
(2,344 Views)

@PaulOfElora wrote:

So, when my 1st VI that registered the event finishes, the event gets unregistered. Game over.  So basically, you can't pass a registration refnum between VI's. Do you agree?


You can, but not unconditionally.

 

I have subVIs that register for events. It's no problem whatsoever. The events will adapt to the indicator in the subVI, so you do need to update it when the event or registration changes labels.

 

If you dynamically start a VI that registers something, you can keep it alive until done. Again, no problems.

 

All of this goes for all LabVIEW references. A file reference has the exact same caveats. References live in the TLDS (top level data space). If the TLDS is gone, so is the reference.

 

Can't say I never been burned by this, but it is consistent and even convenient.

0 Kudos
Message 7 of 28
(2,336 Views)

Well, I don't think you're using Run VI, so there's a chance you can make it work so long as the VI that opens the reference doesn't go out of memory (I think that's what the help is saying).

 

Can you show how you're calling the code you gave in snippets? In particular, the calling/top level VI?

 

For example, this works:

eventsInner.png


GCentral
0 Kudos
Message 8 of 28
(2,335 Views)

@PaulOfElora wrote:

OK, as I read the Help more carefully: "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."

 

So, when my 1st VI that registered the event finishes, the event gets unregistered. Game over.  So basically, you can't pass a registration refnum between VI's. Do you agree?


No, it'll unregister when the top-level VI finishes.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 9 of 28
(2,328 Views)

@cbutcher wrote:

Well, I don't think you're using Run VI, so there's a chance you can make it work so long as the VI that opens the reference doesn't go out of memory (I think that's what the help is saying).


If that is what the help is saying, the help is wrong.

 

References are created in the top level data space, and if the VI that owns the top level dataspace (the top level VI in the hierarchy) stops, all references created in it's hierarchy are closed.

 

So the VI that created the reference can even be running, but in a different hierarchy. Running or in memory are not the criteria.

 

If the VI is idle, you know the references it created are dead. But if it's running top level or running, your reference that it created for you might not be alive.

 

If the VI left memory, the reference can't exist. But if it is in memory, your reference might not be alive.

0 Kudos
Message 10 of 28
(2,311 Views)