Universal Robots+

UR Script Python Communication over TCP/IP Socket: empty Answer

Dear Ladies and Gentlemen,

I’ve tried to make a Python Script that is able to send UR Script to the Robot (and Simulator) and recieves some Data form the Robot.

import socket
import struct

#Server erstellen, der die Daten annimmt
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.bind(("192.168.56.1", 31001))
serversocket.listen(5) #5 eingehende Verbindungen erlauben

#zum Roboter Verbinden, um Skript zu senden
HOST = "192.168.56.101"    # The remote host
PORT = 30002              # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))

#UR Script aus Datei laden
datei = open('ur_sendTemp.txt', 'r')
sendeString = datei.read()
datei.close()

#UR Script senden
print("Sende: " + sendeString)
if(s.send (sendeString.encode())):
    print("Senden Erfolgreich")
else:
    print("Senden nicht erfolgreich")

# Server nimmt verbindung an
print("Warte auf eingehende Daten")
(clientsocket, address) = serversocket.accept()

#Server empfängt
data = clientsocket.recv(1024)
print("Empfangen: ")
print(data.decode('ascii'))

#Server beenden
clientsocket.close()
serversocket.close()
s.close()
print("Server beendet")

the UR Script looks as follows:

socket_open("192.168.56.1", 31001, "socket_31001")
socket_send_string("URTest", socket_31001)
socket_close("socket_31001")

The main problem is that the string “URTest” is not send over Network connection. But the connection is well established (seen in the network tool wireshark).
Can you see any mistakes in the UR Script or in Python code?
btw if I set “” around socket_31001 in Line 2 of UR Script, I got no connection.
Sorry for comments in German, but I think they are not neccesary for understanding the simple code.

Thank you very much.

Regards Florian

Hi @spechtel,

Welcome to the forum!

I would not expect that.

What is the value of you socket_31001 variable in the URScript?
If you add the keyword global in front of your deceleration, then it will show up in the variable tab in Polyscope.

Thanks for the Welcome and fast response!

There is no declared variable socket_31001. What you see ist the “full” very short script. These are my first steps with UR Script.
Is anything else needed in UR Script for proper execution?

I just tried the following:

socket_open("127.0.0.1", 29999, "socket_29999")
socket_send_string("popup URTest", "socket_29999")
socket_close("socket_29999")

It is very similar to yours, and it worked just fine. It should also work if you don’t specify the socket_name

I have found the error. When it is wrapped in a Precedure( like def testproc(): … end ) it is working.
I know beginner mistake :wink:
Thanks for helping!