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

**URL:** <https://forum.universal-robots.com/t/how-to-read-a-tool-analog-input-over-tcp-ip/380>\
**Category:** URScript\
**Created:** [November 25, 2016, 3:00pm UTC](https://forum.universal-robots.com/t/how-to-read-a-tool-analog-input-over-tcp-ip/380 "2016-11-25T15:00:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon67492748](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@anon67492748](https://forum.universal-robots.com/u/anon67492748)\
**Post date:** [November 25, 2016, 3:00pm UTC](https://forum.universal-robots.com/t/how-to-read-a-tool-analog-input-over-tcp-ip/380/1 "2016-11-25T15:00:44Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jbm](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/jbm/32/614_2.png) [@jbm](https://forum.universal-robots.com/u/jbm)\
**Post date:** [November 28, 2016, 8:08am UTC](https://forum.universal-robots.com/t/how-to-read-a-tool-analog-input-over-tcp-ip/380/2 "2016-11-28T08:08:00Z")

</div>

@anon67492748

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](http://forum.universal-robots.com/t/communication-interfaces/29/5) and [this Support Site article](https://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/remote-control-via-tcpip-16496/) 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.

---

<div class="post-metadata">

**Author:** ![ajp](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/ajp/32/471_2.png) [@ajp](https://forum.universal-robots.com/u/ajp)\
**Post date:** [November 28, 2016, 9:22am UTC](https://forum.universal-robots.com/t/how-to-read-a-tool-analog-input-over-tcp-ip/380/3 "2016-11-28T09:22:15Z")

</div>

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](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](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.

---

<div class="post-metadata">

**Author:** ![anon67492748](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@anon67492748](https://forum.universal-robots.com/u/anon67492748)\
**Post date:** [November 29, 2016, 6:05pm UTC](https://forum.universal-robots.com/t/how-to-read-a-tool-analog-input-over-tcp-ip/380/4 "2016-11-29T18:05:48Z")

</div>

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?
