Sending UR-Script to robot via socket connection

Hello,

I am working with an UR5e in my university project. Currently I am trying to activate my gripper through setting the “Tool Digital Output 1” to true, which works when changing its value on the robots controller.
While searching for a way I found the possibility of sending an UR-Script command via a socket to the robot. While it seems to work for the examples I found, the value does not change for my robot.
Is my code (see below) correct or am I missing something?

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("192.168.12.200", 30002))
output = "set_tool_digital_out(1,True)"
      
s.send(output)

data = s.recv(1024)
s.close

print("Received", repr(data))

Specs:
Ubuntu 20.04
Python: 3.8
Robot: UR5e (Software Version: 5.12)

We found out, that everything was correct, we were just missing the “\n” after the command and forgot to turn the robot control on the controller on “remote control”.

Everything works as intended.

Hi,

could you please provide your UR program ?

Do you use your robot in remote control or you are using a script command as ‘socket_read_string()’ ?

I am trying to activate a digital output from a similar code you wrote up there, but the string received by the robot is not executed as it could be in remote control through the socket port 30002…

Lucas