08-29-2008 03:45 PM
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....
08-29-2008 03:53 PM
08-29-2008 04:02 PM
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.
08-30-2008 08:11 AM - edited 08-30-2008 08:11 AM
Hi monsy,
Instead of using the while loop use this.If starting at a click all that you want.
08-30-2008 11:16 PM
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
08-30-2008 11:17 PM
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
08-30-2008 11:45 PM - edited 08-30-2008 11:47 PM
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. 🙂