LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

subvi while loop

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

Download All
0 Kudos
Message 1 of 20
(16,768 Views)

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.

Message 2 of 20
(16,759 Views)

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? 😮

Message 3 of 20
(16,757 Views)

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?

0 Kudos
Message 4 of 20
(16,748 Views)

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).

Message Edited by JeffOverton on 09-04-2008 02:22 PM
Message 5 of 20
(16,744 Views)

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" ?

 

 

 

0 Kudos
Message 6 of 20
(16,737 Views)
if you want to call an existing app from something you're making, you're going to have to get involved in the internals.  you can use queues, functional globals, notifiers, semaphores, etc to transfer between parallel nodes.  If you do some searching for how to communicate between parallel loops, you'll get a lot of this stuff as well.
Message 7 of 20
(16,726 Views)
i too having the same problem at present .... i created a subvi with while loop and in the main.vi will the data to send to the subvi but the program is not running.. its because the data from main.vi (ie: from controls) its not passing to subvi..... pls if u know tell me... i'm waiting for our reply.....
Regards,
N. Srinivasan
0 Kudos
Message 8 of 20
(16,128 Views)

Hi srinivasan,

 

have you really read this thread?

 

Especially explanations in message 2&3 and the solution given in message 5?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 20
(16,124 Views)
srinivasans message is just a duplicate post, continue here...
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 20
(16,119 Views)