LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to run a sub-VI continuously?

Hi,
I have a main program that calls two sub-VIs and brings them up. In one of the subVI, there is a start button that if you clicked on it, it would execute once then stop. I need the subVI to run continuously so that i can just click on the start button everytime to run it.
I tried to use a while loop and include the whole subVI in it. I wired a "stop" control to the conditional terminal so I can click on the stop button to stop running the subVI. But the stop button doesn't work. when i clicked the stop button, the subVI doesn't do anything, the status bar is still "Running". is it got anything to do with the "mechanical action" of the boolean control?

thank you
0 Kudos
Message 1 of 4
(3,679 Views)
Inside the subVI you should have a main While loop which you could run until you manually stop the VI or stop it with a Close button from the front panel. Inside the While loop you should have a Case structure which you activate using the Start button (set to Latch when Release mechanical action). Inside the True case you would place all the code for your subVI.

See the attached example VI.

Christian L
NI Consulting Services
authored by
Christian L, CLA
Systems Engineering Manager - Automotive and Transportation
NI - Austin, TX


  
0 Kudos
Message 2 of 4
(3,679 Views)
Thank you for your help!
Could you please explain why you put a "wait until next ms multiple" in the vi? I have looked it up several times, because I saw it in may examples, but I can never understood it.
0 Kudos
Message 3 of 4
(3,679 Views)
Adding the Wait function to a LabVIEW loop is a good habit and common practice to release some processing time in the application to other tasks and processes. Without the Wait function, the While loop will run as fast as possible, meaning it will poll the Start and Close buttons and take up a large amount of processing time. The Wait function will only run the loop every 10ms or 100 times a second, thus releasing the application and processor to do other things while the loop is waiting to run again. In a larger LabVIEW application with many things going on in parallel, it is advisable to spend the appropriate amount of time and processing power on the right tasks. Since this task is just monitoring the user interface (waiting for someone t
o press a button) a response time of 10ms is very acceptable and could even be increased to 100ms without the user noticing the difference.

Christian L
NI Consulting Services
authored by
Christian L, CLA
Systems Engineering Manager - Automotive and Transportation
NI - Austin, TX


  
0 Kudos
Message 4 of 4
(3,679 Views)