LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

don't do anything until switch is activated (basic question)

I have a program that after you run the vi I don't want it to do anything until the user hits a start button... I'm pretty new to LabVIEW and can think of 2 ways to do this... either putting my start button in a while loop and letting the loop loop indefinitely until the start button is hit to break out of it... or just having all my code contained in a huge case statement and having so that nothing happens until the button is pressed and a true is sent to the case statement...

 

My question is:  Are both of these equally good methods of doing this?  Good programming technique?  and.... if not, is there another better way to accomplish the same thing?

 

Much Thanks

 

PS - I've included some pics... it's not my actual program but just to illustrate what I'm trying to say....

Download All
0 Kudos
Message 1 of 7
(3,265 Views)
I don't know much about your program, but from what you stated above it looks like a state machine is the way to go for this program.  There is a StateMachine template that ships with labview that will be useful for you.  Also, a search for State Machine on the forums should turn up some useful info.
Message 2 of 7
(3,260 Views)

Monse wrote:

My question is:  Are both of these equally good methods of doing this?  Good programming technique?  and.... if not, is there another better way to accomplish the same thing?


No, these are not good techniques, especially since you don't even have a small wait statement in the polling loop. This means they spin millions of times/second doing nothing except consume all available CPU. (See also this illustration)

 

A state machine is the correct way to do things. A finished program should be set to "run when openend" and start up in some initialization state or wait state.

Message 3 of 7
(3,255 Views)

Hi monsy,

                Instead of using the while loop use this.If starting at a click all that you want.

 

Message Edited by muks on 08-30-2008 08:11 AM
0 Kudos
Message 4 of 7
(3,228 Views)

ok, I really appreciate people telling me that that isn't a good way to have a start button... I'm just getting started with labview and am trying to avoid starting bad habits early.... so, I've looked at some state machine examples and changed my start button... is this a good way now?  I'm assuming this doesn't hog up the cpu like my previous methods...

 

Thanks,

M

 

 

0 Kudos
Message 5 of 7
(3,202 Views)

ok, I really appreciate people telling me that that isn't a good way to have a start button... I'm just getting started with labview and am trying to avoid starting bad habits early.... so, I've looked at some state machine examples and changed my start button... is this a good way now?  I'm assuming this doesn't hog up the cpu like my previous methods...

 

Thanks,

M

 

 

0 Kudos
Message 6 of 7
(3,201 Views)

Why don't you open the task manager and look at the CPU usage?

 

A n UI polling loop such as this need a wait statement, e.g. 100ms. Without it, the loop will poll the button several millions times per second, consuming 100% of one CPU core. A 100ms wait reduces the loop rate to 10 per second, which is about a million times less demanding. 🙂

Message Edited by altenbach on 08-30-2008 09:47 PM
Message 7 of 7
(3,194 Views)