LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

TCP/IP communication

Hi there,

I am working on a machine vision project with LabVIEW.

The camera will locate some parts and send their coordinates via TCP/IP 

and I created a client also with LabVIEW to display these coordinates here is how the communication going.

First, if the camera detects something then msg will be sent to the client to inform him.

then if msg was received correctly client responds with another msg to request the coordinates. 

at last, the server sends the coordinates to the client. 

here I faced some problems

1- the msg sent are with variable length ("x=0,y=0,Rz=0"==> "x=225,y=255,Rz=5" ==> "x=225,y=255,Rz=90"  length vary between 16 and 22 ) with the constant "byte to read " it will not display the full msg.

2-the client works fine but at a certain time, it shows errors like ("LabVIEW: (Hex 0x80) Open connection limit exceeded";;;;;; "LabVIEW: (Hex 0x42) The network connection was closed by the peer. If you are using the Open VI Reference function on a remote VI Server connection, verify that the machine is allowed access by selecting Tools>>Options>>VI Server on the server side"

 

 

0 Kudos
Message 1 of 6
(1,086 Views)

First the application probably sends something extra at the end of the string. Ideally this is a <cr><lf> (carriage return/line feed) character combination. If that is the case you can use the TCP/IP Read with CRLF mode, and pass a number of bytes to read that is guaranteed to be larger than the largest message you receive.

 

If it is something else you have to do more work. Typically you use TCP Read in Immediate mode inside a loop and check for yourself for the actual termination character before terminating the loop (don't forget to terminate also when TCP Read returns any error).

 

The error you see seems to indicate that your camera runs out of sockets. Are you opening and closing the TCP/IP connection for each Read attempt? It would be probably better to only open it once and keep it open, unless you notice any other error than a timeout error when calling TCP Read. When you see such an error (exclusive timeout which is a legit error that you should not usually treat as an error but simply as indication that the remote side hasn't send anything yet) only then close the connection and try to reopen it.

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 6
(1,047 Views)

thank you sir for your reply

 I forgot to attach the images.

 I am still new with LabVIEW so please if you have any example of  "CRLF" data transfer please attach it here 

0 Kudos
Message 3 of 6
(1,009 Views)

Don't attach images. Attach the VI.

0 Kudos
Message 4 of 6
(1,002 Views)

here the VI

Download All
0 Kudos
Message 5 of 6
(992 Views)

Many errors in your "images".

 

tcp3.png : You open a new connection in every loop iteration but only close the last one after your loop terminates. No wonder that your camera runs out of sockets as it gets a new connection at each iteration but that connection stays open forever (well until your LabVIEW program stops)

 

 

 

Rolf Kalbermatter
My Blog
0 Kudos
Message 6 of 6
(978 Views)