LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

is there an alternative way to stop TCP Listen inside a loop?

Hi there,

 

I was searching for a way to stop TCP Listen by using a STOP button inside a while loop. I thought of a solution but I was wondering if there isn't a better, more elegant one.

 

I tried several things:

1. If I leave the listen function to wait forever (that's what I wanted to do), the STOP button will have to wait, so the VI will never stop.

2. Then I thought that I could use an Event structure to check if the STOP button had been pressed. It checks, but also waits for the TCP Listen.

 

3. Then I used the STOP function inside the Event structure, but somehow the loop wouldn't work. The code inside the while would run once and then do nothing else. (I don't know why this happens)

 

The best option I found was to set a timeout for the listen and wait for it to send an Timeout error, clear this and repeat the loop. By doing so, everytime there's a timeout error, the VI checks if the STOP button was pressed.

Is there a better of doing this?

 

Thanks in advance.

0 Kudos
Message 1 of 4
(3,587 Views)

This is probably the best way that you could do it without breaking a few no-no rules.

 

Another option is to put the Listen VI with an infinite timeout in to a subVI. Within the subVI, put a While loop that's checking a stop variable. Once the stop variable goes True, stop the While loop and trigger a "Stop" node, which will force the VI to stop. Like this:

Force Stop Listen.png

 

This isn't really the right way to do it, though because you really don't ever want to force quit labview or a subVI. It can leave behind loose ends with references and stuff.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 2 of 4
(3,565 Views)

You can close the Listen refnum from a parallel loop.  That will cause the listening to error out (use the error to shutdown the loop).  No need to use "STOP".

Message 3 of 4
(3,556 Views)
Bam, give that guy a medal.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 4 of 4
(3,544 Views)