LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to determine if a vi in a subpanel has stopped?

Solved!
Go to solution

I have multiple subpanels with instances of the same vi running (set to "Preallocated clone reentrant execution") inside them (started via Start Asynchronous Call). I want to know if a vi in a subpanel has stopped execution. I have tried getting a reference to the inserted vi and checking the execution state property (see attached snipped) but it always returns "running" once a vi has been started, even if the vi has finished execution. 

0 Kudos
Message 1 of 6
(213 Views)
Solution
Accepted by topic author elyte_dev

When you open the reference using Open VI Reference to the subVI to insert into the subpanel, started with Start Asynchronous Call, you need to set the appropriate flags. See the list here:

 

https://www.ni.com/docs/en-US/bundle/labview-api-ref/page/functions/open-vi-reference.html

 

The Help for Start Asynchronous Call indicates you need to use either 0x80 or 0x100. 0x80 specifically says "Use this when you do not need to know when [...] the VI returns." So that leaves option 0x100, which includes info on using Wait on Asynchronous Call:

 

https://www.ni.com/docs/en-US/bundle/labview-api-ref/page/vi-lib/dlg-ctls-llb/wait-on-asynchronous-c....

 

So, retain the reference you used when you started it, then use a Wait on Asynchronous Call to wait until that VI is done waiting. You can also add a timeout via a right-click menu if you just want to check the status without waiting on it. I assume you can call it in a loop if you want to poll it instead of waiting on it.

 

Your method didn't work because "Running" actually means "VI is reserved for execution by one or more active top-level VI's" (see documentation here). I'd argue the naming of that property is pretty poor, as it's been a point of confusion multiple times. At least back in 2014 there wasn't a way to do that- and, as far as I know, there has been very little (if any) changes to core VI server functionality in the last decade.

Message 2 of 6
(210 Views)

And of course Paul Cardinale has a solution that attempts to work around this:

 

https://forums.ni.com/t5/LabVIEW-Idea-Exchange/Need-a-way-to-visualize-VI-call-chain-hierarchy/idi-p...

 

(According to the documentation, Wait on Asynchronous Call is the "right" way to do what you're trying to do, but Paul's method might help you as well, being a more general solution.)

0 Kudos
Message 3 of 6
(203 Views)

thanks, I may have found a way to (somewhat) achieve what I need: 

snip.png

It's not a perfect solution, tough. Each time this check is run, return values (if any) must be handled and the vi refrence must be invalidated, because subsequent calls with a reference to a stopped vi will generate timeout errors again (as if the vi was running). 

0 Kudos
Message 4 of 6
(130 Views)

Paul Cardinale's solution does not work for me (at least not out of the box). I assume this is because it checks for any error code, which would also match for a vi that is not running (but I'll need to look deeper into this)

0 Kudos
Message 5 of 6
(64 Views)

I changed Cardinale's solution slightly::

cardinale.png

If the vi is not running the invoke node will generate error code 1000. 

This works in labview but not with the lv runtime engine, meaning its not a viable solution for my problem. 

0 Kudos
Message 6 of 6
(56 Views)