12-03-2011 08:24 AM
Hi ppl,
I've been searching through the forum about the topic above but still dont know how to do this. Maybe one of you can post the solution of that important issue.
I attached some very simple program: I did some while loop as a main program and subvi as a secondary program. Inside the subvi also runs some while loop. All I want to do is to push stop button in the main program that will stop the while loop in the secondary program; to create some kind of reference stop in the main program that will influence only the stop button of the subvi; meanwhile the while loop of the main program will still run.
Thank you.
Solved! Go to Solution.
12-03-2011 09:04 AM
I can't open your VIs because I only have LV2009 but this post (message 4) could give you an idea.
12-03-2011 09:06 AM
It is not good to write code in this way. The caller VI while loop will be blocked from iterating until all code in the loop has completed execution. Since you have a subVI that does not exit there is no way (from the caller loop) to send any kind of message to the subVI once it is called.
You should put the subVI outside the while loop. There are many ways to send data between separate loops - global variables (not good for many well established reasons), queues, events, notifiers, functional global variables, TCP/IP, etc.
I think you want the numeric value to be available to the main while loop when it changes. Use one of the above techniques to send from that loop to the "main" loop.
12-04-2011 08:51 AM
Actuaaly main program is scanner; every time it enters to the subvi program to make scan and then enters from that subvi and do it again (depends how many times I want to make scan). what are you talking about seems to me to much difficult. meanwhile I did the following thing: I make something that will show me the subvi when it the main program calls it and then there when I push stop button it gets me out from this subvi. in the subvi I added output of the stop (boolean value) (meaning when I pushed stop button boolean button is 1).. then it goes from that subvi and enters to the stop button of the main function and there I did some condition: if this boolean is 1 logic the main program will stop. that's the simplest way I choosed. 🙂
any suggestions?
Thank you.
Dima.
12-05-2011 04:37 PM
Hey Dima,
Calling the SubVI’s front panel is a good way to ensure that you will exit the while loop on the SubVI.
As for other ways to program this, in your program are you just trying to make the subVI execute a finite number of times based on the number of scans? It might be easier and more sound programming to use a For Loop where you wire the number of iterations to the number of scan? I don’t know if this would work with you program or not but it is worth looking into.
Kira T
12-06-2011 06:32 AM
Hi Dima,
you can use a global variable to stop the sub vi as the following, make a boolean global variable, add a new while loop to your main vi, connect a stop control to the global variable, take anothe instance from the global variable to be the stop condition of the while loop inside the sub vi.
hope this help.
Zaki
12-06-2011 06:40 AM
I have modified the code you attached. check.
12-07-2011 02:05 AM
yeah man.. good and simple idea.. thanx 🙂