11-19-2012 12:36 PM
I am developing an application that consist of a main VI and several sub VIs that include different utilities. I would like to be able to open multiple utilities (sub VIs) at the same time from the main VI. So far I have noticed that when opening a sub VI from the main VI, the main VI gets stuck in the execution of the sub VI and cannot perform any other operations until the sub VI is closed.
Does anyone know of a way around this?
Solved! Go to Solution.
11-19-2012 12:49 PM
Check out this thread:http://forums.ni.com/t5/LabVIEW/subVI/m-p/2223756#M708575
11-19-2012 01:10 PM
This is a basic feature of LabVIEW. You can create parallel path.
You need to understand the data flow concept behind the execution of the code in LabVIEW.
You can experiment by using highlight execusion.
Back to your question. Yes, most people know if a way around your problem.
Depending on how you want to code it (scalability), there are many ways to accomplish this.
The simplest way is to wire the VI's in parallel. WIll it do what you want? Maybe... probably.
Is it the best solution for your code? Dunno.. Haven't seen your code. Dunno what it does.
Can it be done? Of course.. Think of your sub-vi's as seperate functions. Just as you can wire functions from your function palette in parallel, so can you do it with subVIs.
I'll whip up a quick snippet.
11-19-2012 01:11 PM
That's not exactly what I was looking for. Maybe I should try to explain better:
The main VI of my application has the ability to open several different utilities. One utility to control a servo, one utility to program an IC, to name a few. I want to be able to call these utilities from the main VI and use multiple utilities at the same time. For instance, if I wanted to control the motion of a servo while programming an IC, I would want to open and use 2 utilities at the same time. Each utility has a fully functional front panel with controls and an event structure, so moving the while loop from the sub VI to the main VI as proposed in the above thread would not solve this problem.
I would like to avoid having seperate applications for the different utilities.
Any ideas?
11-19-2012 01:21 PM - edited 11-19-2012 01:25 PM
OK.. I'll skip what I was about to post... 😉
What you need is to use a producer-consumer architecture, where your producer is an event handler. It will take care of the operator selections.
The consumer loop will be a state machine. It will process the buttons that were pushed.
The trick is to use an Open VI Reference with an Invoke Node. At the Invoke Node, select Run VI and set the Wait Until Done to False.
In the appropriate state of the state machine, wire the path of the appropriate subVI to the vi path terminal of the Open VI Reference.
At the end (wxit program state) close the references. I would also recommend using type def enum to select the states.
11-19-2012 02:00 PM
I get an error when trying the invoke node method.
The VI called out in the error is the sub VI that is being called from the main app.
Any idea on what could be causing this?
11-19-2012 05:47 PM
Another option to consider:
User Events can be used to open and stop your sub vis.
Attached is a barebones example in LV 2010.
steve
11-20-2012 05:32 AM
Is your vi already running when you call it using this method?
It might be running with its panel closed. You might want to add another Invoke Node for Front Panel Open (FP Open).
I think I mentionned that you have to close the reference at the end, when you exit.
But typically error 1000 is because the VI you are calling is already running. If you want multiple instances of the same VI to run in parallel, you have to make it re-entrant.
11-20-2012 05:36 AM
@stevem181 wrote:
Another option to consider:
User Events can be used to open and stop your sub vis.
Attached is a barebones example in LV 2010.
steve
Steve,
You have to be careful when using the method you suggested which is to do the calls within the Event Structure itself. I did not look at your code, but I am familiar with people's misfortunes at using this style. In other words, I've had to debug many people's programs who were not careful about the fact that the program was held inside the event structure; which caused the program not to respond to operator selections.
11-20-2012 10:11 AM
You could start your VIs using the "Start Asynchronous Call". You will need to use some type of user event/queue or notifier to control your subVIs if you want to have a single Stop in yo9ur application.