03-23-2012 09:05 PM
I am new to LV and have been experiementing with SubVI's. I cannot get my sub VI to execute and exchange variables in my main VI.
I want to be able to run this sub VI 3 times in paralell (attached is only 1 subvi). How do I need to modify my VI to make this work, addiionally can I copy and paste this VI 2 more times and run 3 independant subVI's?
I believe my problem may have something to do with my SubVI's outer loop.. however if I get rid of it I dont know how to impliment my enum constants that control my state machine.
Thanks for the help!
-Mike
03-23-2012 09:18 PM
Your code makes very little sense and there are no "variables" in your main VI. I don't even know what you mean by "variables". Can you explain?
If you want to run multiple independent instances of your subVI, you need to make it re-entrant, but I think your problems are much deeper.
Can you explain in more detail what the VI is supposed to do? It cannot be deduced by looking at the code.
(Why do you need te same wait inside all cases of a case structure, all you need is one instance outside the case structure, right. What's up will all these inner "CPU burner" loops? They will cause the subVIs not to play nice, especially if several run in parallel.)
03-23-2012 09:21 PM
Your Dig1.vi doesn't have anything in it!
If you have a subVI, you generally won't want a while loop in it that will keep it running. And if it is stopped by way of a front panel control, there is no way to stop it unless you call the VI in a way that will open the front panel.
You should move the while loop out of the subVI and put it into the main VI. Pass your enum into an out of the subVI to control your state machine.
If you need to execute multiple VI's simultaneously, you'll want to set the subVI to be re-entrant.
Since you are new to VI, I would recommend looking at the online LabVIEW tutorials.
LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours
03-24-2012 02:56 AM
can you please explain what exactly you want to do.
Tushar Jambhekar
tushar@jambhekar.com
Jambhekar Automation Solutions
LabVIEW Consultancy, LabVIEW Training
Rent a LabVIEW Developer, My Blog
03-26-2012 09:11 AM
I have to apologize, my "dig" VI got altered before I uploaded it. In fact both VI were not as I intended to post. I posted the revisions. Please open them and play with the "SubVI" front panel, I think you'll find quiet fast what I'm trying to accomplish.
My "subVI" will use DAQmx functions to control a digital output with simple Boolean logic; for now I just have LED indicators in my VI. The "SubVI's inner while loops in the ON and OFF statements are used for timing the on and off "times" of the LED light; if you have a better way please let me know.
I know that my "SubVI" program executes the way it should and works fine as a stand-alone VI. Furthermore, I think its written fairly decent for somebody with no training, I would love to hear how to improve it or use different methods to accomplish the task.
Moving on, I simply want my "dig" VI to run the subVI, that's it, for now. Later on, I would like to run multiply "SubVI" in parallel to control multiple digital output channels simultaneously.
Thank you for the comments and suggestions!
-Michael
03-26-2012 10:51 AM
Your subVI is interactive, but it is not set to open the front panel when called. Since it cannot complete without user intereaction (e.g. pressing the stop button), the loop in the calling VI will stall forever.
Dataflow dictates that outputs will only be returned to the calling VI when the subVI completes.
Even the subVI is highly congested with these inner cpu burner loops that might take a long time while using 100% of the CPU doing nothing but poll the time. A simple wait would be equivalent.
From an architectural point of view your code still makes absolutely no sense. Try to rethink it from scratch, it probably can be done with half the code. 😉
03-26-2012 01:37 PM
"Dataflow dictates that outputs will only be returned to the calling VI when the subVI completes."
Now that makes sense as to why my main VI is not interactive, thank you!
I tickled with the idea of using waits but had some limitations, I will revisit this concept.
I respect the critism that my program "makes no sense from an architectural point of view"; my goal is to make this as professional as possible, I dont like to settle.
Would you suggest that I keep my state machine format, or use a sequence structure, etc? Any advice with respect to structure of this specific program would be helpful, I thought my dataflow made sense from a stand-alone VI perspective but i guess I was wrong lol.
Thanks,
Mike
03-26-2012 03:29 PM
I would like your feedback on my modified program, which I attached.
I followed your advice, I simplified my subVI by removing the inner while loops and replacing them with the wait function. I also removed the outer while loops and handled my enums in a different fashion. I hope my program is more elegant then it was before in your eyes. I also have two separate subVI running in parallel with any apparent issues.
Thanks Again,
Mike