LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I make a non-blocking TCP/IP read/write?

I am trying to make a non-blocking tcp read call. I used a zero for the timeout, but that just caused strange behavior (the program slows down and speeds up oddly).  I would like to have it check the buffer and return if no data is available, similar to how it can be done in C++.  Anyone know how to do this?
0 Kudos
Message 1 of 5
(3,911 Views)


@gsoren wrote:
I am trying to make a non-blocking tcp read call. I used a zero for the timeout, but that just caused strange behavior (the program slows down and speeds up oddly).  I would like to have it check the buffer and return if no data is available, similar to how it can be done in C++.  Anyone know how to do this?


I can't confirm the odd behaviour you are seeing. What LabVIEW version is this? And try with a timeout of 1ms instead.

Rolf Kalbermatter
Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 5
(3,899 Views)
It's LabVIEW 7.1.  I had a 1 ms timeout and then switched it to 0, and that's when the odd behavior started. The program would run at normal speed for about 5 seconds, then slow down dramatically for about 5 seconds and then speed back up. It stopped when I put the timeout back to 1 ms.  I would really like it to be a non-blocking call, but it seems like you can't do that in LabVIEW. 
0 Kudos
Message 3 of 5
(3,885 Views)


@gsoren wrote:
It's LabVIEW 7.1.  I had a 1 ms timeout and then switched it to 0, and that's when the odd behavior started. The program would run at normal speed for about 5 seconds, then slow down dramatically for about 5 seconds and then speed back up. It stopped when I put the timeout back to 1 ms.  I would really like it to be a non-blocking call, but it seems like you can't do that in LabVIEW. 


Could it be that in your application you are trying to do very fast non-blocking calls. If you have a loop trying to do no-blocking calls with timeout 0 repeatedly for some time you could encounter this behaviour. LabVIEW basically will check as fast as possible if there is something to be read from the TCP/IP socket and this might monopolize the CPU for other things. In that case try to make a significant  delay between calls to a TCP Read with 0 timeout.
No sense in checking several thousend times per second if something has arrived.

Rolf Kalbermatter
Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 5
(3,881 Views)

Have you tried putting the tcp requests in its own timed loop (multitthread).  One loop can run independently communicating with TCP and the rest of the program can run asynchronously.  This might solve the problem of blocking because the TCP wait will not hold up your programs normal execution, then you can increase your timeout settings so that the tcp will request data at a slower rate and the main program will execute at a high speed.  Communicating between loops can be done with queues or shared variables.

 

Paul

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 5 of 5
(3,876 Views)