Universal Robots Forum

Get information from a global variable create by URScript

Hello, I ama beginner in URCaps development and I am trying to get back the status of a variable that I have create by UR script. The script is sent on the click of a button, and it open a socket connection and create a boolean variable. I want to read this variable and show it in a popup trigger after the connection. I don’t know what is possible to do this.

My best regards and thanks for reading.

Hello,

I am also a beginner in URCaps but I had a similar issue.

In my case was that I did not define the variable as global.

var_name = variable_value
global var_name = variable_value

If you have already defined the variable as global, could you explain a little more your URCap?

Does it work from the installation window or from the programming window as a function?

Regards

Hello carcagi,

My URcap work from the programming window in swing, I declare the global variable that return my socket connection status (like this: connection = socket_open(“172.31.1.160”, 502, “socketName”), it works well. But I don’t know how to use it into my URCaps application or others URCaps which come after.

I look to the tutorial “working_with_variables” but I don’t really get how work with them.

Thanks for your help, I continue to work on it

Hello stagiaire1,

First of all, sorry for my English. If you don’t understand something fell free to ask.

I think you have several options depending on how your project works.
The first one is using in contribution node,

@Override
	public void generateScript(ScriptWriter writer) {
	}

Defines script code that is added to the beginning of the script code executed when a program is launched.



This works if you want to create and use variables in a program, I don’t know the order of the different URCaps code is added.

An the other option is using socket communication and create small programs that you send to the controller and allows you the exchange of information from the robot and the java program.
I’ll recommend follow this example URCap-ScriptCommunicator

Best regards,
Carlos

Hello Carlos,

It work well with socket communicator ! i m now trying to use the URSCIPT functions (like socket_send_int(value, socket_name)) in a another URCap.
But in my application I want to send some arrays (of int, float or double) any idea ?
Thank you very much for your fast answer,

Best regards,
Yann