How to read a tool analog input over TCP/IP?

Hello!

I’d like to set a tool output and read an tool input over the tcp connection in python. I can connect to the robot an set the output, I however to not understand what the robot returns. This is my script:

import socket
from time import sleep

HOST = "10.8.64.249"    # The remote host
PORT = 30003              # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))

s.send("set_tool_digital_out(0, True)\n")
sleep(0.2)
data = s.recv(100)
print ("Received", data, len(data))

s.send("get_tool_analog_in(1)\n")
data = s.recv(100
print ("Received", data, len(data))
s.close()

This is my result:
(‘Received’, ‘\x00\x00\x008\x14\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x03\tURControl\x03\x03\x00\x00\x00\x01\x00\x00\x00<Jul 08 2016, 16:07:20\x00\x00\x00\x18\x14\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x0c\x00\x00\x01\xe9\x00\x00\x00\xef\x01\x00\x00\x05\x1a\x10\x00\x00\x00.\x00\x00\x00\x00\x01t\x15K\xc0\x01\x01’, 100)

(‘Received’, ‘\x01\x00\x00\x00\x00\x07\x00?\xf0\x00\x00\x00\x00\x00\x00?\xf0\x00\x00\x00\x00\x00\x00?\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfb\x01?\xf2:- \x00\x00\x00?\xf2:_`\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00>} \x02B?\xc2\x8fA\xe7\$A\xf5\xed\xc0\xfd\xc0\x07\x93\xce\xe8\x88Z0\xc0\x07\x93\x9c\xa8\x88Z0\x00\x00\x00\x00\x00\x00\x00’, 100)

How can I interpret this data?

@engelhard

The client interfaces on port 30001, 30002 and 30003 can receive individual script codes.
They constantly transmit Robot State message + some additional data depending on which interface is chosen.
Check out this topic and this Support Site article which elaborates on the client interfaces.

Generally it could be a long streak to write a communication handler for the data received from the client interfaces.
Maybe sending a small script program that opens a socket and returns the tool input state would be easier.

You can use the python struct library to unpack the bytestream according to the format listed in the excel sheet attached to the article Jacob listed above.

https://docs.python.org/2/library/struct.html

There’s a brief example in this comment on the Zacobria support forum:

http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-via-socket-connection/#comment-148516

But as Jacob said, it’s quite a lot of work and there may be simpler approaches to achieve your goals.

1 Like

Hey! Thanks for the link! I’m currently parsing the uint8_t * buffer I got via TCP in C++. I can parse most of the variables, I’m however not getting valid results from the float-variables.
Is there any C+±Code that shows how this data can be parsed?

1 Like