From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stop TCP-Read without killing the connection?

Solved!
Go to solution

Hello,

is there a way to abort TCP-Read without closing the connection?

 

Example:

My VI (client) is connected to a device (server).

My client is waiting at "TCP Read" with timeout 10sec.

In a parallel loop I want to abort the "TCP Read" faster than 10sec but the connection must not be killed with "TCP Close Connection".

0 Kudos
Message 1 of 5
(1,641 Views)

Can you make the timeout shorter?

0 Kudos
Message 2 of 5
(1,639 Views)

@Greil wrote:

Hello,

is there a way to abort TCP-Read without closing the connection?

 

Example:

My VI (client) is connected to a device (server).

My client is waiting at "TCP Read" with timeout 10sec.

In a parallel loop I want to abort the "TCP Read" faster than 10sec but the connection must not be killed with "TCP Close Connection".


Make a FOR loop around the TCP read where the amount of loops it runs divides the timeout.  So instead of waiting 10 seconds 1 time, wait 1 second 10 times, or 0.1 second 100 times.  Then just add a conditional terminal to the FOR loop to allow early termination via some form of messaging, or upon receipt of the expected message, and add a "Clear error" that clears a timeout error each loop (but does not clear other error types).

Message 3 of 5
(1,620 Views)
Solution
Accepted by Greil

The reason why the "TCP Close Connection" is 'no option' is because the device needs always a "stop" command before closing the connection (even on error), otherwise the device needs a reset before next use. The reset takes much more time ... so this must be avoided.

(jup, it is a stupid device)

 

Thank You, but I found another approach:

In the parallel loop now I do TCP-Write "stop" and then it is safe to use "TCP Close Connection". This will abort the "TCP-Read" and the device will not hang up.

 

I could also write something else like *IDN?" so the read finished immediately too.

 

Thank You.

0 Kudos
Message 4 of 5
(1,545 Views)
That's interesting. Usually I try to avoid talking to an instrument from 2 different loops, but it sounds like you're being careful about it so hopefully it won't cause any headaches.
0 Kudos
Message 5 of 5
(1,519 Views)