LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

registering user events in a loop

So if I remove the FGV event structure...

Use the sub VI, and wire initialize to the function...

Put a while loop around the event structure (or it will stop after the time out)...

 

Still nothing happens.

 

That makes sense, as the FGV registers for FireInt, but the time out fires FireExt...

 

Not exactly sure what you're trying, perhaps I have to re-read the explanation...

0 Kudos
Message 21 of 28
(831 Views)

So I'm backtracking a but, but I wanted to answer a couple questions from the first page. Someone posted to not register for events in a subVI and you asked why. Memory issues and all that aside, there's a few other reasons to not do this.

 

1- The Register For Events (RFE) function starts listening for the events and queuing them *immediately*, not when the Event Structure executes. See the following:

register before structure.png

That code results in this:

BertMcMahan_1-1585075019636.png

 

You may want this or you may not, it just depends on your application. Usually I don't want to start registering for events until I have an event structure to handle them. In many cases it doesn't matter, but if you're initializing some stuff it might matter.

 

2- You should only ever use ONE registration refnum with ONE event structure, so if you need two places to register for the events, you'll have to call the function twice instead of branching a cluster of events then registering for them en masse (with a SINGLE event registration function- yes, it can take a cluster of events and register them all)

 

3- If you're using User Events, you'll need to send those event references (not registration references) to another place to actually use them. If you output a cluster of all of your events, you can register for them one place and generate the events in another place.

 

None of those are hard and fast rules about registering in a subVI or not, but IMHO it's easier for me to register for the events on the same block diagram where they're actually used. It's just something to keep in mind.

 

As an aside, here's a good article about dynamically defined user events:

 

http://www.notatamelion.com/2016/03/22/dynamic-udes-the-power-for-reentrant-processes/

 

Message 22 of 28
(825 Views)

It *does* make sense, weibe and Bert.  Digesting what Bert posted, trying to tiptoe my way into learning about classes.  Very grateful to you experts for your tutelage.

0 Kudos
Message 23 of 28
(820 Views)

@PaulOfElora wrote:

It *does* make sense, weibe and Bert.  Digesting what Bert posted, trying to tiptoe my way into learning about classes.  Very grateful to you experts for your tutelage.


I converted 100% to OO ~6 years ago. I've made class based timers before that trigger user events.

 

Of course, it's more fun and educational to make one yourself!

 

Feel free to continue your endeavors here if you need advice. It wouldn't even be off topic, as your still registering events in a loop.

0 Kudos
Message 24 of 28
(788 Views)

Good points Bert!

A dynamic register for events create an event queue, so it should only be used with 1 event structure.

From the caveats:

"Wire each Event structure that handles dynamic events to a unique Register For Events function. Branching the event registration refnum wire of a Register For Events function allows multiple Event structures to pull events from one queue, resulting in a race condition that may cause unpredictable behavior."

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

Qestit Systems
Certified-LabVIEW-Developer
Message 25 of 28
(785 Views)

@Yamaeda wrote:

A dynamic register for events create an event queue, so it should only be used with 1 event structure.


Just to be sure: exactly 1. Not 0. If you register, and not use it, you will 'leak' memory until your out of it.

 

Especially when using an API that returns an event registration, it's easy to not use it...

Message 26 of 28
(772 Views)

wiebe@CARYA wrote:

@Yamaeda wrote:

A dynamic register for events create an event queue, so it should only be used with 1 event structure.


Just to be sure: exactly 1. Not 0. If you register, and not use it, you will 'leak' memory until your out of it.

 

Especially when using an API that returns an event registration, it's easy to not use it...


Presumably then you could use Unregister for Events if you didn't want the registration?

It's a good thing to consider though...


GCentral
0 Kudos
Message 27 of 28
(756 Views)

@cbutcher wrote:

wiebe@CARYA wrote:

@Yamaeda wrote:

A dynamic register for events create an event queue, so it should only be used with 1 event structure.


Just to be sure: exactly 1. Not 0. If you register, and not use it, you will 'leak' memory until your out of it.

 

Especially when using an API that returns an event registration, it's easy to not use it...


Presumably then you could use Unregister for Events if you didn't want the registration?

It's a good thing to consider though...


Yes, that works.

 

I prefer to make a "Register? [F]" Boolean input. If false, registration is skipped. When the VI is dropped in obliviate, there will be no leak.

Message 28 of 28
(748 Views)