08-23-2010 09:41 AM
Hello,
I have a set of VIs that I am trying to be able to call from a main vi. The main vi front panel is just a set of boolean controls. The block diagram for the main vi is a single while loop that contains all the controls which are each wired to a case structure that calls each vi when set to true. There is a different VI being called for each control and case structure. The loop has a condition of continue while true which is wired to constant true which is outside the loop of course. I have also tried the same with a timed loop, but either way it is very basic indeed.
Now when I run it, I can press one control and it will then start up the vi front panel that I selected. That's fine, but then after that, when I press another control on the main VI, nothing happens. Another thing I noticed is that if I turn ON all the controls and then run it, they will all work, meaning all VI front panels selected will appear.
The issue is that when one or more controls are set to true and the respective VIs are called, it seems that the loop that controls all the VIs is no longer running. I would like to be able to select one VI, and then continue to select another VI and so forth.
Any help would be greatly appreciated.
Thank you
08-23-2010 09:53 AM
This is most likely because you are blocking (synchronous calls) to the subvi, so the main loop has to wait for the subvi to return before executing the next itteration. If you dont want this you will have to make each (I would use events) button selection dynamically call your worker routine and not wait for completion. You will have to make sure that the subvis are thread safe (no shared resources) otherwise you will need to handle this with resource management like semaphores or some synchronization technique.
Do you really need the subvis to execute in parallel and if so there are many considerations involved (does each subvi execute reentrantly...)
08-23-2010 09:54 AM
You need to post your code or we will only be guessing at what is causing the problem. I would guess right now that you have them all in the same loop. When you press the button the first window comes up and you get stuck in that window. Just guessing.
Post some code for a better responce.
08-23-2010 09:54 AM
Hi nano_era,
If you wish to run multiple VIs and open them independantly you will need to use seperate loops. This will allow you to interact with each VI whilst the others are running.
Also, if you wish to stop all loops simultaneously, I would advise using a local variable. If you are planning to run the same VI multiple times at once it is important to make sure that the VI is set for 're-entrant' behaviour which will allow it to be accessed in multiple places at once.
I hope this helps but if not, just post back and I'll try again.
Chris
08-23-2010 10:14 AM
OK, I tried using a loop for each vi and it seems to work now. The issue with that is that it seems to really slow down now. I will keep working on it to see If I can get it to run smothly.
Thank you for the responses.
08-23-2010 10:16 AM
Make sure if you are using loops that you have a way to meter the loop. Place a wait for 10 milliseconds in the loop to ensure that you have time for the processor to process.
08-23-2010 10:20 AM
Tim has a good point. I should have mentioned this. If you have a multi-core processor, be sure to enable processing in all cores by multi-threading.
Chris
08-23-2010 12:13 PM
I would still consider dynamic launching of the subvi instead of making many loops, one for each subvi. The issue you will find (although the many loops is conceptually easier) will be in scalability, What happens if you want to launch 20 loops, are you going to drop 20 loops on your Block diagram, also what happens if you want to take advantage of the event structure (you really want to do this if you plan on a GUI of any complexity) you can put the event structure in each loop which will cause you to have to poll each loop and then you will need to do tempo control in each loop. From a readability stand point a single loop with an event case that launches the subvi is veary easy to follow as well. This is just my opinion though.
08-23-2010 12:24 PM
I would say that would depend on how the code is being used. That is why I suggested that the code be posted so that we could better server the interest of the OP. It is hard to suggest what might be the correct way of doing something without much more detail on what it is doing or what it need to achieve.
08-23-2010 12:48 PM
I think I've got it working the way I want it to. I used timed loops for each vi and I added a wait for front panel activity. That seems to have improved the speed of it to where it is now usable. I will continue to work on it. I understand the significance of showing the code for better understanding of the issue but I am simply not allowed to do that. Either way, I was able to receive some very helpful ideas from you all.
Thanks for the suggestions.