03-27-2013 06:12 AM - edited 03-27-2013 06:34 AM
Hi Folks,
I need a help from you regarding SubVi.
I have a subvi in which two boolen inputs , two ouputs(one boolean and one string value)
Now i wanna start using one of the inputs and it goes in to a while loop infinitly. I have to stop the loop and exit from the subvi by using the other input .
Displayin the two outputs ....Bool and string
Can someone help me?
03-27-2013 06:30 AM
Care to share you VI? How do you plan on stopping the loop?
03-27-2013 06:41 AM
this is my subVI . I wanna use it in my final VI .
03-27-2013 07:13 AM
None of this code makes sense to me. What are you trying to do with this subVI?
03-27-2013 07:19 AM - edited 03-27-2013 07:19 AM
You can only provide the inputs to the subVI at the time you call it, therefore if you call your subVI and it enters an infinitely running while loop then you cannot stop it from the calling VI. If this subVI needs to be stopped at some stage then make the condition for stopping the while loop settable from within the subVI itself.
If your while loop is meant to repeat a task until a particular output is achieved, ensure a pass state causes the while loop to exit. Do not wire one of the subVI inputs to the while loop conditional terminal because once set by the calling VI this input cannot be changed (sensibly).
03-28-2013 03:03 AM
Hi Guys thanks a lot.
My Aim is to give the user to deicide whether the photodiode works fine .
There will be a block in front of it and so till that time the program is running continously.
Later it is stopped when he decides it ok or not .
I think i am clear in my explaination,.
03-28-2013 03:50 AM
Hi MaveenD,
I think it would be easy for people to help you if you post your main vi and sub vi. Looking into it, the experts in the forum will definetly able to suggest some approach(if any) that can help you to meet your requirement.
04-02-2013 08:36 AM
Hi MaveenD,
do you know to use Variables? That could help you with stopping a While Loop from outside or from another VI.
More information about Variables:
Tutorial: Local Variable, Global Variable, and Race Conditions
http://www.ni.com/white-paper/7585/en
Best Regards,
Martin
04-02-2013 08:46 AM
This design doesn't require a sub-vi, just a while loop in your main vi inside a case structure. Pressing a start button enters the while loop, the stop condition is wired to a Stop button on the front panel for the user.
As others have stated, the problem with trying to do this in a subvi is that the inputs are only evaluated at the time the subvi is called (your main code will not do anything until the subvi has finished running so a stop button on the main vi will do nothing and you subvi will NEVER stop).
To truly achieve this, you would have to run the two vi in parallel, opening the second one using VI reference and invoke node to run. The data would be passed between the two using either a global variable or a functional global variable. The problem with this, is that the user could still tell the main VI to run code which could interfere with the second vi, unless you programatically disable certain controls in this situation.
All in all, your desired function for this code sounds simple enough that it should just be inside your main vi.
04-02-2013 10:26 AM
Why is everyone suggesting using global variables. There are much better and preferred methods for passing data. I would recommend using queues, notifiers or user events to pass data between VIs.