LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I exit a while loop while it is running if a button is pressed mid loop.

I have an acquisition loop reading data from a serial port. Because the timing of the signal can vary between a couple per second and one every few hours I have set the timeout to be hours. What this seems to have resulted in is that each time I press stop to end the program the loop is still waiting for the next value to be put onto the buffer before carrying out the rest of the loop and then stopping. With the next value going into the buffer being possibly three hours away it waits all this time before it completes the loop and stops. Is there any way to override everything else in the loop and stop what the loop is doing if a button is pressed?

Thanks

Ross H
0 Kudos
Message 1 of 3
(2,859 Views)
May be a possible solution is to set more reasonable timeouts (hmm, seconds) and then handle errors after Read operations? If there is a timeout error after read operation - then retry again. May be - if the communication syntax allows - you can just supervise the serial input buffer and reading it if something occurs (looking for user "stop" event also) .
Hope this helps.
0 Kudos
Message 2 of 3
(2,859 Views)
It's much better to use VISA Bytes at Serial Port to determine when and how much to read and use a reasonable timeout.
0 Kudos
Message 3 of 3
(2,859 Views)