LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Question with dynamic call vi

There is a sub vi which  for register an event callback. Now I called this sub vi dynamic, after the sub vi executed completed,  then it can not trigger the event i registered. I found that the reference for the event callback register is invalid. Is there some method to keep the event register reference in the memory?

 

thanks!

0 Kudos
Message 1 of 5
(2,791 Views)

Looks like your overthinking things. I'll break down your post (literally, not figurally), but please also explain what you want to do.

 


@J.Alvin wrote:

There is a sub vi which  for register an event callback.


You mean you register a sub VI as event callback? The moment you run that, the VI will be locked until the calling VI (all calling VI's) stops running.

 


@J.Alvin wrote:

Now I called this sub vi dynamic,  


You're calling the dynamic callback VI dynamically? I don't see how that would be useful. Please explain.

 


@J.Alvin wrote:

after the sub vi executed completed, 


 You mean the callback VI? Still not sure why you'd want that.

 


@J.Alvin wrote:

then it can not trigger the event i registered. 


What did you try? Triggering the registered callback event has little to do with the callback VI itself. could it be you're mixing a few concepts (like user event and callback event)?

 

 

 


@J.Alvin wrote:

I found that the reference for the event callback register is invalid. 


 How did you get the event callback register in the first place? This register reference will become invalid once the VI stops running. All references go invalid once the top level hierarchy VI stops running, including callback event register references.

 


@J.Alvin wrote:

Is there some method to keep the event register reference in the memory?


Not stopping the calling VI... But again, explain what you want to do... I've never had the need to do this.

 

0 Kudos
Message 2 of 5
(2,776 Views)

Try make subVI reentrant.


Show your (simle) code.

0 Kudos
Message 3 of 5
(2,771 Views)

I also don't quite understand what you are trying to do but:

 

bear in mind that refnums (such as the event registration refnum or the event callback refnum) share the operative lifetime of the VI they are created in.  If your sub-VI being called dynamically creates the refnum and then subsequently stops executing (goes to "Idle") then any refnums it created will become invalid at that point.  This might be what is causing your refnum to go invalid.

 

You may need to make your dynamic VI reentrant and somehow leave it running until the event registration is destroyed.  I'm sure others have some insight on how to best go about this.

0 Kudos
Message 4 of 5
(2,762 Views)

@Artem.SPb wrote:

Try make subVI reentrant.


I usually change them to non-reentrant. They're reentrant by default (when LV makes them), but that makes them even harder to debug. Still wandering if OP should use callback VI's...

 

We need to know what you want to do and why. I agree, an example would help.

0 Kudos
Message 5 of 5
(2,758 Views)