LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I do a user controlled amount of subvi instances?

Hello!
 
I'm trying to write a dynamic application where the user can control which sub-vis get selected to run in parallel.  The problem I am having is that each sub-vi has it's own never ending while-loop, and that the execution of the first one prevents the execution of others.  See the example attached.
 
Now I know at first glance you may say, "Why use the for-loop?  Why not just have the two knobs control seperate conditional statements instead of an array that controls a single conditional inside a for-loop?"  The answer to that is because in my application, the size of the Control array that spawn sub-vis gets selected by them also!*  So I'm trying to take advantage of the for-loop's auto-indexing ability to spawn as many sub-vi instances as there are knobs in the Control array.
 
An alternative I thought of was to simply execute all the sub-vi's, and have the Control array simply select the correct outputs (outputs not demonstrated in the example attached), but I am running this in Real-Time on a FieldPoint unit, and the processor overhead of running all the sub-vi's that are not necessary will hurt my performance.
 
If you can understand the problem I am presenting (I may not be completely clear) and have a better way to spawn sub-vi's with internal while loops controlled by an array , I'd appreciate your help!
 
Thank You
 
 
*I'm doing this because the job I am working on will need to be modifiable after my contract is over, and the potential of expansion after I am gone is highly desired my my employer.  Sure, I'd rather be rehired to change the code everytime changes are needed, but that's obvously not the best solution for my employer. Smiley Wink
Download All
0 Kudos
Message 1 of 7
(2,541 Views)
You can start multiple subVIs and have them run in parallel by using the  Run VI method. You can stop them with the Abort VI method but if you replace the constant on the diagram with a control, you can stop them with the Set Control Value [Variant] method. Are all of the subVIs them same as in the examples you posted? If so, then you can save a single VI as a template (.vit extension) and call those with the invoke node. I don't have time to create a simple example but you can search the forum for examples. There have numerous postings on this technique.
Message 2 of 7
(2,528 Views)

No, all the sub-vi's are not the same. 

I will definately investigate the Run VI method you mentioned. 

Thanks for a quick reply!

0 Kudos
Message 3 of 7
(2,524 Views)
I concur that you have to use the VI server to launch the VIs dynamically, but I also wanted to point out that your basic framework also seems to imply that a user can launch the same subVI more than once. E.g., first element of array is set to "zero", and second element is also set to "zero". This implies that you need each subVI to be reentrant. I don't know if your logic in your real application prevents this from happening if it's not desired.
Message 4 of 7
(2,520 Views)
I considered that, but have no code that currently prevents it.  I am currently looking at how code 0x08 for Open VI Reference works....
0 Kudos
Message 5 of 7
(2,514 Views)
If that's the case then you will want to add some code that first verifies the array before you go off and start launching VIs. In your case it shouldn't be too difficult to create a small subVI that checks the array has no value in the array that repeats. For example, you could take the array and then for each allowed value (0, 1, or 2) delete the allowed value from the array. Do this for each allowed value. When you're done with all the allowed elements if the leftover array still has some elements you know something has been repeated, and that you need to tell the user to fix this.

In general you want to do this check this way rather than relying on the VI server to tell you a VI is already running by means of it generating an error code that you look at. While this will work, it's not really "good" programming.
Message 6 of 7
(2,508 Views)

Awesome.  I'll do that!

Smiley Very HappySmiley Very HappySmiley Very HappySmiley Very HappySmiley Very Happy

0 Kudos
Message 7 of 7
(2,504 Views)