Universal Robots Forum

Get variable/register value from Java

I need to get the value (in java) of either:
A) a general purpose register
B) a urscript variable

What is the best way of accomplishing this task? I have tried a number of things and they have all ended in failure.

Right now I am investigating setting up modbus communication to get the value but I am worried that this too will end in failure. Please advise asap.



When referring to general purpose registers, are you then referring to the GP registers in Modbus Server (addr. 128-255) or the Input_Integer_Register/Output_Integer_Register available over at the RTDE interface (including EthernetIP and Profinet)?

In either way, from the URCaps API classes com.ur.urcap.api.domain.io.* in respect to Modbus and Fieldbus registers, you are only able to read existing signals, that are present in the system.

For Modbus, this means, that there must be a “device” present in Modbus, and some signals added, before you can find these channels in the Collection<IO> returned by Collection<IO> collectionIO= api.getIOs().*.
Hence, the Modbus server values are not present here, unless you have added a device to connect to localhost, and read relevant channels.
In this case, it would probably be more relevant to create a Modbus client yourself to connect to localhost Modbus server.

For RTDE/fieldbus registers, these only show up in the Collection<IO> if they have been named in the “IO Setup” menu under installation. By convention, only named fieldbus registers that have been assigned a name, will show up in e.g. Set, Wait commands etc. Same applies to the collection you are handed.
In this case though, there have not been implemented support for reading the actual value of the register.
Hence, you can read whether the input/output is present (i.e. named), but it cannot be changed from Java.
This would typically happen in URScript, by using e.g. read_input_integer_register(address).

I will answer in respect to program Variables in the separate topic.

1 Like

I am interested in the RTDE GP registers. Basically, I want to, from java, connect to the RTDE socket and send some script across the line that performs a calculation and stores the result in a register. Then, from java, I want to read the value stored in the register.

I will take a look at the IO stuff.

Thanks for the prompt and detailed response! If you have any more tips I would love to hear them.

Just a note;
The implementation of Fieldbus/RTDE GP registers in the domain.io class allows you to get the registers and their associated name. I.e. you can list these, and allow the user to select the right one.
It has not been implemented that you can get and set the values stored in these registers.
Hence, the reading of these from Java, should probably be implemented as a separate custom method.

1 Like

I see the limitations that you are describing. I would like to put in a feature request to be able to return the value of some calculation to java without having to jump through so many hoops. It seems like it would be largely beneficial if URCap developers could easily send some urscript to the robot that performs a calculation and have the value returned without having to:

Set a global variable, run a daemon that listens for global variable updates, and then somehow poll for this value in java (or similar).


Are there any news to this topic. I do not understand the reason for these restrictions.