LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Communication Via TCP Send command and receive response

I am trying to set up a simple communication vi to send a command and receive the response via tcp.  I am able to send on Putty or Teraterm in a telnet session.  Commands and responses are in xml format.  a sample command would be ReadLiveDataRequest />  and the response would be.  <ReadLiveDataResponse><Tag ID="0" Value="1.97" /><Tag ID="1" Value="1.96" /><Tag ID="2" Value="1.97" /><Tag ID="3" Value="1.96" /><Tag ID="4" Value="1.97" /><Tag ID="5" Value="1.97" /><Tag ID="6" Value="1.98" /><Tag ID="7" Value="1.97" /><Tag ID="8" Value="1.96" /><Tag ID="9" Value="1.97" /><Tag ID="10" Value="1.97" /><Tag ID="11" Value="1.97" /><Tag ID="12" Value="1.97" /><Tag ID="13" Value="1.97" /><Tag ID="14" Value="2.49" /><Tag ID="15" Value="4.98" /></ReadLiveDataResponse>

 

I tried this and it does not work.  Any help would be appreciated

 

0 Kudos
Message 1 of 9
(4,733 Views)

What do you mean by "it doesn't work"?  You get nothing?  You get partial message?  There is an error message?  Your PC bursts into flames?

 

You have a constant 2 wired into the top of the TCP/IP read that is being coerced.  Who created that?  Delete the constant, write click on the terminal and pick Create Constant.  Then select the setting you want.  Now you have a documented Enum rather than a mysterious number that is being coerced to an enum.

 

What device are you communicating with?  That constant you have  set corresponds to CRLF mode.  Is your device sending a carriage return/line feed a the end?

 

You set your TCP/IP read for reading 100 bytes, but the example string you put there is at least 483 bytes long.

0 Kudos
Message 2 of 9
(4,676 Views)

By not working I mean it appears to open port but not sending or receiving messages. TCP is new to me so I am 100% understanding of the protocol .

 

At this time I am just trying to send a command from pc to the device and read back a response.  I tried may thins so this is why the 2 is wired on the read.  I was not able to get much information from the vendor that makes the device I am trying to communicate to other than the xml tags. Like I said I could send the string in Putty or tetraterm or in a telnet window.  I tried the telnet library in labview also .  It seems straight forward but I am stuck.  The return message will also vary in size depending on the sent string. If anyone has sample cod that would be great.  I am not sure what to try.

0 Kudos
Message 3 of 9
(4,630 Views)

hello buddy ,

I would suggest you to make sure the message which you'er sending is in correct format with proper termination(end charecter) and also increase the timeout preferably set it same as you have set in putty .

I dont think we can give a differnt sample because what you did seems good and we cannot know the proper parameters(constants)without knowing the device we are working with

 

with regards 

0 Kudos
Message 4 of 9
(4,615 Views)

Thanks.  The device I am trying to communicate is a part we make for a customer and they have not given me much to go on.  I am working to automate the testing of the part.  They did their programing in xml they have a webpage you can log into.  One question I have is If I send the command and want to append a EOL character is there any special way of doing this.  Would I just add a \r or \n to the end of the string I am sending? 

 

The command I will send is:

<WriteDataRequest TagID="400" Value="0" />

 

Would I just add the \n or \r right after it like this?

<WriteDataRequest TagID="400" Value="0" />\r\n

0 Kudos
Message 5 of 9
(4,610 Views)

the Eol chareter depends on the machine you are working with . you said you could send the command with putty right what did you use then ? just check the settings in putty to find out the eol charecter it is sending.

with regards

0 Kudos
Message 6 of 9
(4,603 Views)

Hi and thanks for the replies.  I played around wit different EOL characters and now it works!!! 

 

One last question.  For the TCP Read what is the best way to set the number of bytes read if they vary from command to command?

0 Kudos
Message 7 of 9
(4,592 Views)

i would suggest to keep it 9999 generally it would be enough . i am not sure how much effect it has on performance though

0 Kudos
Message 8 of 9
(4,590 Views)

If you're writing a string constant, the "normal" display mode will give you a slash and a r or n if you type those characters. Changing to the slash mode is one option, using concatenate strings with an End of Line constant, or preferably CR and LF constants as needed, is probably more self-documenting.


GCentral
0 Kudos
Message 9 of 9
(4,577 Views)