10-05-2012 05:37 PM - edited 10-05-2012 05:38 PM
Hello,
I'm wondering the best way to send a serial command when a button is pressed. Right now I have a while loop that checks if the button is pressed each time. If is is, it sends the serial command and adds the response to a text box via a shift register. If not, the original text box info is passed to the shift register. However, this loop takes 100% cpu (ok, only one core at 100% so technically %50), and I think its because the text box is getting overwriten every cycle. However, I'm not sure how else to do it. Attached is a print screen, let me know if you would like the file.
Thanks,
Eric
Solved! Go to Solution.
10-05-2012 05:46 PM
An event structure is the best way. The next best way is to simply put in a wait in the loop.
10-05-2012 05:46 PM
You have what is known as a greedy loop. It is running as fast as it can which ultimately consumes 100% of your CPU. Simply place a Wait with a 0 delay in the loop and this will allow the scheduler to do other things and will prevent the CPU from being starved.
10-06-2012 09:00 AM
altenbach explained it best: http://forums.ni.com/t5/BreakPoint/LabTOONS-The-secret-life-of-LabVIEW-objects/m-p/724366#M5642