LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to programatically stop a subVI consisting of a parallel loop

Solved!
Go to solution

Hi guys,

 

I would like to abort a running subVI (consisting of a parallel loop) programatically.

 

The abort-invoke-node leaves an error message (Vi not in a state compatible with operation) and I cannot add a conditional terminal to the loop because it is a parallel one.

 

Is there any (nice or not nice) way to force the subVI to stop?

 

Best

volfi

0 Kudos
Message 1 of 15
(2,682 Views)

Abort will force something to stop.  But certainly isn't a nice way to do it.

 

You can use notifiers or even global or local variables if used carefully to pass information between parallel loops.

 

Hard to give much information since you hadn't provided some code for us to look at and all the information is just a few short sentences.

Message 2 of 15
(2,674 Views)

Usually you will want the subVI to be abortable "internally". Instead of forcing it to close, it should have some sort of messaging system to allow callers to ask it to abort.

 

For example, give it a queue reference with a Boolean type (it could be a string, enum, whatever). Generate the queue in the calling VI, then give the reference to the subVI. When the caller wants to close the subVI, send a True on the queue.

 

Inside the subVI, have a "Dequeue element" at the start of its loop with a timeout set to 0. Each time the loop starts, check if there's a message in the queue. If there is, the caller has asked for an abort, so the subVI can shut down gracefully. If there are no elements in the queue, it'll continue on with no delay (since the timeout is 0).

 

You can also do this with User Events if your subVI is based around an Event Structure- the method is basically exactly the same.

 

The benefit to this method is that you can also send the subVI other information, not just a Stop request. For example, if the subVI is a datalogger, you could send it new data to log, or if it's a user interface, a new piece of data to plot. For simple "shut down" messages a Boolean type will suffice, but once you get the idea down you can look into using strings or enums bundled with a variant to send a "Command"/"Payload" style message to your subVI's.

 

There are lots of ways to skin this cat 🙂

Message 3 of 15
(2,673 Views)

The sub-VI can get a ref to the top level VI and register for a "close" event and shutdown when that happens.

 

There are other ways but that is about as simple as it gets.

 

Ben

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

Sorry that I did not make clear it is a parallel FOR loop that I am talking about. The subVI is just as simple as that, but I cannot add a conditional terminal to the loop, so I need to find another way to interrupt the loop.

0 Kudos
Message 5 of 15
(2,618 Views)
Solution
Accepted by volfi
See image as example . Simple Local variable used to detect an situation and then skip all remaning "actions" in all Parralel instances
Floris Reinders
Senior Project Engineer / CLA
Message 6 of 15
(2,607 Views)

Can you not just add a 'Conditional Terminal' to the 'For Loop'

Capture.PNG

0 Kudos
Message 7 of 15
(2,599 Views)

Nope it will leave a broken arrow

0 Kudos
Message 8 of 15
(2,586 Views)

@volfi wrote:

Nope it will leave a broken arrow


Only if you leave it unwired.

 

Wire the local that flas the stop to the terminal and it will prevent the loop from iterating instead of spinning and devouring CPU as it counts.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 9 of 15
(2,579 Views)

@Ben wrote:

@volfi wrote:

Nope it will leave a broken arrow


Only if you leave it unwired.

 

Wire the local that flas the stop to the terminal and it will prevent the loop from iterating instead of spinning and devouring CPU as it counts.

 

Ben


That's not what I see.

0 Kudos
Message 10 of 15
(2,567 Views)