LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

unable to stop a while loop

Solved!
Go to solution

Hello,

 

I have built a small test udp program which listens to a port and displays a message as shown in the figure and attached vi (labview 2009 format). But when I press the stop button on the front panel, it does not stop. I have to do abort. What is going wrong in here.

 

Thank you for your time.

Download All
0 Kudos
Message 1 of 10
(4,422 Views)

Your "UDP Read" has a default timeout of 25 seconds... so depending on when you click Stop it will be somewhere between 0 and 25 seconds before you loop actually stops.

 

Just change the timeout to 200ms or something and it'll work.

Message 2 of 10
(4,407 Views)

What's your timeout for the UDP read? Your loop can only stop after a read/timeout.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 10
(4,406 Views)

It could actually be nearly 50 seconds.

 

The stop button is probably read very early in the loop.  So the Stop button is read as false, and the UDP Read begins trying to read.

 

If you then hit stop, you still have to wait the nearly 25 seconds of the UDP timeout, but the stop button as already been read as false.

 

UDP timesout, loop doesn't stop because it was initially false.  Loop reiterates.

 

Stop button is now read as true, but another UDP Read takes another 25 seconds to timeout.  Finally it times out and the loop stops.

Total time any where from 25-49.99999999 seconds after you originally hit the stop button.

0 Kudos
Message 4 of 10
(4,403 Views)

The timeout on the UDP session is 25 Seconds.  So, if there is no datagram the while loop will need up to 25 seconds to time-out and exit with error.  Try wiring something reasonable to the timeout and see if error 56 occurs.

 

Edit: Oops I forgot to look at the responses first.  Hey, RF! error 56 gets thrown on a timeout and the while loop exits on error, 50 seconds is not possible.


"Should be" isn't "Is" -Jay
0 Kudos
Message 5 of 10
(4,389 Views)

yes, error 56 occurred when I changed the timeout to 200ms. What if I want the UDP to listen continuously until I manually click stop. I added "-1" to timeout so that I can continuously listen. In this case there is no way to stop it at all sanely?

0 Kudos
Message 6 of 10
(4,378 Views)

Don't wire the error wire to the stop terminal.  Or if you do, at least clear the error if it is a timeout error.

0 Kudos
Message 7 of 10
(4,374 Views)

Even when the error wire is not connected to the stop terminal, the stop button on the Front panel does not seem to work.

Download All
0 Kudos
Message 8 of 10
(4,364 Views)

-1 means never timeout.  So it will sit there and wait forever until it receives data, then the while loop will stop. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 9 of 10
(4,342 Views)
Solution
Accepted by topic author johndoe1920

@johndoe1920 wrote:

yes, error 56 occurred when I changed the timeout to 200ms. What if I want the UDP to listen continuously until I manually click stop. I added "-1" to timeout so that I can continuously listen. In this case there is no way to stop it at all sanely?


Nope, no way to stop that sanely at all if there are no Datagrams under that condition.

 

Worse, (as Raven's Fan alluded to but did not state) with the original code exiting with error 56 there is a great possibility that the Stop Boolean does not get read after it is latched and stays True when the vi finishes.  A simple work around for that is to use a sequence structure to control when the latcher is read

Capture.PNG

 

Now onto mods needed to " I want the UDP to listen continuously until I manually click stop."

 

To meet that requirement you need a different design pattern.

Capture.PNG

See the pdf attachment for hidden cases EDIT: Forgot to close the UDP Connection in the original


"Should be" isn't "Is" -Jay
0 Kudos
Message 10 of 10
(4,331 Views)