LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem reading device responses over TCP connection

Hey all,
 
I have a device that I am sending commands too, and then trying to read back the responses. I just took the TCP Communicator - Active from the NI examples and modified it a little. All the commands I am sending to the device are working (it is responding as expected) but I am only able to read back the response from the first command that I send. Immediatly after it reads back the first response the TCP read outputs an Error 66 (Connection Closed).
My question is this. I want to be able to send multiple commands and have it read back the response from each one, does anyone know why the TCP Read would immediatly return a Connection Closed error after reading the response from the first command? Do I need to re-establish the connection between each command?
 
It just seems weird that I can send multiple commands to the device (and see the expected results on the device itself, so I know the connection is still good), but can't read back multiple responses. Any help would be appreciated. I have attached the vi I am working with.
 
Thanks,
 
Paul
0 Kudos
Message 1 of 5
(3,816 Views)

Sorry, I can't open your VI, but look on this pictures. It should work like a TCP/IP Terminal.

 

 

 




Message Edited by Eugen Graf on 02-19-2008 11:50 AM
Download All
0 Kudos
Message 2 of 5
(3,810 Views)
 I have tried the setup you showed and various other ways of setting it up and I still have the same problem. After the first command I send I get the Connection Closed error from the TCP Read right after the response from the first command is read. Do you know why this might be happening? Is this some default in the TCP Read or could the device I am communicating with be causing the error?
 
Paul
0 Kudos
Message 3 of 5
(3,785 Views)
Hi Paul,
 
I think you have a "race condition" here.  With this VI, you would not want a parallel loop structure with the write and read.  You should force the data flow so that the TCP send occurs first, then the error wire flows into the TCP receive portion to receive the rest of the program flow.  In cases where you have communication, you should always attempt to write first to the device, then wait for a response, or vice versa.  Both at the same time makes LabVIEW choose which loop to run arbitrarily. 
0 Kudos
Message 4 of 5
(3,755 Views)
Usually error 66 is the other end of the connection closed the connection.  So, whatever you are talking to may be closing the connection, not your LabVIEW program.  If that is the case, then you will have to open a connection everytime.

If all of your commands are easy ASCII commands, you MAY be able to test this by using Hyperterminal.  Set it up for Winsock and set the IP address and port.  I sometimes have issues with Hyperterminal detecting a dropped connection.  You can also use DOS's telnet application by going to a command prompt and typeing:

telnet <IP Address> <port>

This usually detects dropped connections pretty well.

I saw nothing in your VI which should cause the connection to drop.
0 Kudos
Message 5 of 5
(3,751 Views)