Universal Robots Forum

Set variable values with python socket program

I’m trying to write a program to call waypoints with socket communication. Program looks like this.

switch var1
case 0
var2 = 0
var2 = 1

My questions are

  1. Is there a better way to do this?
  2. I managed to set “digital_out” value with an example code. But I can’t figure out how to set “var1” value with python socket program.
    How to read the “var2” value with python socket?

Thank you…!

You can’t modify variables with an incoming socket connection.
And even less read that value.
But you can make an urscript node that send the variable via socket in urscript, or to read a variable from a socket, I assume you find this easily on the urscript manual.

But you can send urscript from socket, that will be executed while the program is running. Or control the execution of multiple-parts program:
I assume you know you can send urscript from a socket, that will be executed as a complete, so it will stop your actualy running program:
$ echo "popup(\"hello\")" > /dev/tcp/
Same thing happen (current program stop) when you wrap it inside a function:
$ cat test.urp > /dev/tcp/
with that test.urp file:

def func():

Knowing that, you can imagine to “cut” you original program in multiple parts, and call these little program from the dashboard interface (port 29999) around you code you need to send from socket.

Last noticeable thing:
You can replace the “def” word with “sec” to execute that script while a program is running, and it won’t stop its execution, although, I don’t recommend this procedure for your problem, since you can’t modify vars from these script, even installation ones. And if you wan’t to send moveX procedures from your socket, you’ll need to know exactly how many time your move will take to reach the waypoint, because you’ll need to be in a Wait block (or a procedure that not move the robot) .

I’m assuming you’re using RTDE to control digital_out. Using RTDE you can write value to input_int_register_X and then read this value in program with var1 = input_integer_register(X)
Before you write any value, you have to register variables that you will be using.
Check out an example at the end of RTDE guide page

1 Like