Send string via TCP/IP

Hi,

I have connected a UR3e to a medical testing device via TCP/IP, and need to send commands to the device to control it.

I can send a string to SocketTest from robot that seem to look correct

image

and I can send the same string to the testing device from SocketTest and get a response

image

but when I send the string to from the robot to the testing device I get no response.

I use these lines to send the command:

  socket_send_string("<command name=")
  socket_send_byte(34)
  socket_send_string("GetSystemStatus")
  socket_send_byte(34)
  socket_send_string(" />")

Any ideas why this is?

//Tor

Could be something simple the SocketTest does automatically that you need to replicate. First thing that comes to my mind is including a Line Feed (\n) or carriage return character (\r) or possibly both at the end of your command.

I now realised that I’m not actually connecting with the device. When I connect with SocketTest I connect immediately to the network.

image

On the robot use these lines to connect:

while (Sock_connect == False ):
Sock_connect=socket_open(“127.0.0.1”,50012)
sleep(0.01)
end

Is it something with that IP address “localhost”? Right now I have computer and robot on a “normal” network: 192.168.0.X

I wouldn’t think so. Localhost is just an IP address saying “this device” and should be irrespective of subnet mask. That said, you could certainly try putting the actual IP address of the robot in there and see if anything changes, or put in the IP address of the device. I tend to muddle my way through issues by just poking around long enough.

I used the computers IP instead and with appears to work!

I’ve tried both \r and \n, but no success :frowning:

image

I found some old code where I used socket_send_byte(10) after sending the string. It should be Line Feed in Ascii, you can try it.

Might also be able to use str_cat to simplify your code (IE build string all at once and then send it together with the CR LF)

Hi,
Thank you for your replies.
Sending socket_send_byte(10) was the trick! Trying to send \n using ascii just made a string with those characters.

My next challenge is to retrieve the code and the message. I can use find_str() to get the position of code and message. Now I want to find out how many characters are between the " " after code. Is there a way to search for " using find_str()?

tor,
Use the find_str() to locate the message= “Success” text and subtract one from the other this will give you how many characters are between code and message.

you might have to play around a bit to get the correct values
find_str(src, code, 0) will give the location of the c not the e of code.

Matt