09-04-2008 01:04 PM
hi
My current task requires me to include a while loop in a subvi. But when I do that, it seems the data never get transmitted to the subvi and I am not able to stop the application by using the stop button.
The attahment is a very simple demo of this situation. It calculate addition of two variables in a while loop. It then be called by a main vi.
I searched but it seems no direct answer for this. Some suggested a delay in the while loop, which I tried but doesn't make a difference.
Thanks a lot.
Bo
09-04-2008 01:08 PM
Try running your mainvi in execution highlight mode.
As soon as you call mainvi, your stop button is read (false) and that false is passed to your subvi. This value won't change when you click on your mainvi control, because your mainvi control has already been read, which means your loop will spin forever with a false at the stop terminal. The connectors on a subvi are not user controls, they are more like initial conditions in which you start your subvi.
09-04-2008 01:10 PM
You should probably start with a few simple tutorials and familiarize yorself with the concept of dataflow.
The subVI will only output data to the main VI once the subVI has finished executing. So, once you stop the subvi, the data will go to the main VI.
Bo2008 wrote:Some suggested a delay in the while loop, which I tried but doesn't make a difference.
Who is "some"??? Never listen to "some". 😄 A delay will make a big difference in CPU use, but won't change the outcome. Any UI loop should have a small wait, it makes absolutely no sense to use 100% of the CPU to poll the controls every nanosecond. How fast can you possibly click? 😮
09-04-2008 01:16 PM
Thanks Guys~
I admit after occassionally using labview for 2 years, I am still a newbie.
Now I know why it cannot work. Then, how to make it right?
09-04-2008 01:20 PM - edited 09-04-2008 01:22 PM
That's a very, very complicated question that depends very, very much on what you want to accomlish and what else is going on.
To make that specific example work, I would put the while loop in mainvi, with your controls and stop inside the loop. This way, when the loop spins, it will read your controls, pass them to the subvi (which no longer has a loop) which will do the math on them, spit the answer out to an indicator (also inside the loop, or will not update until the loop ends), and then the loop spins again.
This would be where the wait (ms) comes in and keeps the loop from eating all your cpu cycles.
edit - run the attached in highlight mode, too, if you want to see the indicator-outside-the-loop problem. also, you can vary how many ms to wait and get an idea about how and when the timing happens (it doesn't accurately time things, it just makes sure they take a minimum time).
09-04-2008 01:27 PM
Well, that maybe the "right" solution: keep the while loop in the main program.
But what if I have to keep a while loop in the subvi. What should I look into? Keywords...
The situation I am facing is that I have a fairly large program and I want to call it. I am reluctant to change the program itself since it is written by someone else. Any "standard solutions" ?
09-04-2008 01:33 PM
10-16-2009 01:25 AM
10-16-2009 02:04 AM
10-16-2009 02:15 AM