LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stop a subVI and return a value

I know similar questions have been asked, but I could not find a solution exactly for my case.

 

I am currently using a VI in the vision module to do some real-time checking of an object and calculate its's location. The problem is when the object is out the sight of the camera, the calculation takes too long before it tells it can't find the object. I want to stop the VI if it runs too long (say 100ms) and then return 0. My first idea is to use a Timeout event. But I do not know what should I put inside the event structure to stop the whole VI. Some help here will be appreciated. 

 

0 Kudos
Message 1 of 9
(2,796 Views)

Well, if you had attached your VI, we could make suggestions that would work for your current code, or could suggest how you could modify your code.  The basic idea is that your processing routine probably has a loop -- what you need to do is to get a "stop" signal into that loop from the Event Structure.  Look up the Producer/Consumer Design Pattern (you can find a Template for this by going to the File menu and choosing "New ..." (the three dots are important!), choosing VI\From Template\Design Patterns\Producer/Consumer Design Pattern (Events)" and studying the example it produces.

 

Bob Schofr

0 Kudos
Message 2 of 9
(2,759 Views)

There is no loop in the subVI. I tried to use "stop function", but it stopped everything.  Another question is: if a subVI is still running, can I execute it by giving it new inputs? 

Download All
0 Kudos
Message 3 of 9
(2,735 Views)

As I've gotten older and crotchetier (is that a word?), I have lost all interest in trying to untangle messy block diagrams.  If you make it nice an neat, I'll take another look at it.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 4 of 9
(2,708 Views)

@paul_cardinale wrote:

As I've gotten older and crotchetier (is that a word?), I have lost all interest in trying to untangle messy block diagrams.  If you make it nice an neat, I'll take another look at it.


'Grumpier' works. 🙂

/Y

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

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

I the VI hangs in a IMAQ function, it simply can't be stopped.

 

Those IMAQ functions call a dll function, and dll functions can't be interrupted. Even if you manually try to stop the VI, you'll get a "resetting VI" dialog. This will not go away until the function is done.

 

The event structure will work (if the dll function isn't the problem), but there are a few problems. In the time out case, you'd have to actually stop the VI (with a abort method). If you don't, the event structure will simply finish. The VI will still wait for the rest of the code. Another problem is the VI won't stop, because it isn't running top level. So you'd have to run it top level, with VI Server. If you do run it with VI server, you'd also have to dynamically set the control values, and get the indicator values when done. You might run into new problems, as some values that are created in the sub VI won't live anymore once it stops. I'm not sure if IMAQ images work that way...If it doesn't, you might get leaks because the images aren't closed (although IIRC the memory is recycled if you use the same name). You'll basically run into a waterfall of misery. Fix one problem, get two new problems for free...

 

I'd try to make a fast initial IMAQ test for the object. Perhaps the same test on a reduced image size? Once you establish it's there, do the accurate test that takes time.

 

Stopping a VI because it takes to long is symptom treatment. If you get it working, it will never be pretty.

0 Kudos
Message 6 of 9
(2,685 Views)

And if you wander where your precious CPU power goes...

 

It's wasted by polling the stop button. That will drain one core. At least put an event structure in the loop!

0 Kudos
Message 7 of 9
(2,684 Views)

I am wondering why NI do not put a control for the number of iterations in the pattern match VI. It seems very simple. Is it any way I can give a feedback to NI so that they can implement that in their next version of Vision Development module? 

0 Kudos
Message 8 of 9
(2,651 Views)

@Jacobier wrote:

I am wondering why NI do not put a control for the number of iterations in the pattern match VI. It seems very simple. Is it any way I can give a feedback to NI so that they can implement that in their next version of Vision Development module? 


Vision-Idea-Exchange

Message 9 of 9
(2,640 Views)