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 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.
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.
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’ve adapted your code to my system and started to use it. Unfortunally it doesn’t work.
It seems like the Robot doesn’t interpret the send commands from the String as one programm and it tryies to run every line of the code at the same time.
The Robot Log shows the following lines while running the program:
2022-09-15 17:05:11.250 RTMachine Programm socket_send_string started
2022-09-15 17:05:11.345 RTMachine Programm socket_closed started
2022-09-15 17:05:11.347 RTMachine Programm socket_closed stopped
The Log sometimes also shows: socket_opened started, probably because the code gets interupted and the Port hasn’t been closed, due to the fact, that the URScript program doesn’t work as planed.
Has anybody run into the same problem and knows how to fix it?