LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to read TCPIP data so that it doesn't hang when there is no data present?

Solved!
Go to solution

Hi,

 

I've got a loop in my code that uses a TCP read function. My problem is that the loop hangs if there is no data available. What I would like to do is check if there is data available, then do the read otherwise move on to the rest of the code if no data is available and then try again on the next loop.

 

Thanks,

Ryan

0 Kudos
Message 1 of 4
(2,386 Views)
Solution
Accepted by topic author ryanshewcraft

I'm guessing you are leaving the timeout terminal unwired. Wire a number to it in milliseconds. If it times out you will get an error 56. Check the error code and if it's 56 you didn't get data; if there's no error, you read data.

Message 2 of 4
(2,377 Views)

In addition to using a non-standard timeout, such as 100ms or so, one can also play with the Read Mode input of the TCP Read. Those modes are a bit pesky and not always trivial to understand but they can be useful. Read the documentation to the TCP Read function that explains these modes a bit and then start to make small experiments to verify your understanding of those operations.

Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 4
(2,362 Views)

The timeout works (don't know how I overlooked such a simple solution.) Thanks!

0 Kudos
Message 4 of 4
(2,311 Views)