Universal Robots Forum

Xml-rpc documentation inconsistency?

I’m a complete newbie to UR robot programming trying to write a script to interface to a vision server.

In The URScript Programming Language manual, Version 3.2 April 15, 2016:

on page 5 the example of the rpc_factory() function does not specify a port number
rpc_factory(“xmlrpc”, “”)

on page 48 the example specifies a port number
rpc_factory(“xmlrpc”, “”)

which is correct?

1 Like

If you do not specify a port, as in:
handle = rpc_factory("xmlrpc", "")
Then you will use the default http-port, which is port 80.

However it it recommended that you use a port different from the most commonly used ports and the ports used by UR.
E.g. consider NOT to use port 21, 22 as they are already used for FTP, sFTP and SSH, port 80 (HTTP) or UR specific ports such as 29999, 30001, 30002, 30003 and 30004.

handle = rpc_factory("xmlrpc", "http://<ip-address>:<port>/<path>")
would be the safer choice.

The <path parameter is optional and depends on the XMLRPC server configuration.

Thanks, that helps a lot with the setup.

Another question: Do you have an example of a simple UR script template that:

  1. Sets up communication with the xml-rpc server.

  2. Sends a value to the server.

  3. Retrieves an array of values from the server

I recognize that this would be a template only because what is received depends on what the server offers. However, our server has already been tested with a non-UR client. Now I’m trying to prepare a simple UR script that will serve both as a basis for testing xml-rpc communication at our local UR distributor, and as a template for anyone wanting to interface UR robots to our color machine vision software.


In URScript, you create the XML-RPC handle as:
camera = rpc_factory("xmlrpc","")

  • camera = the handle created
  • = the IP-address of the XML-RPC server, here localhost/ inside the controller
  • 33000 = the port on which the XML-RPC server is listening

If the XML-RPC server has two registered functions as GetNumberAndReplyArray(int num) and GetBooleanAndReplyInteger(bool status) then you can access this in URScript as:

camera = rpc_factory("xmlrpc","")
var1 = 3
var2 = camera.GetNumberAndReplyArray(var1)
var3 = True
var4 = camera.GetBooleanAndReplyInteger(var3)

If the XML-RPC server is running, it will receive the integer number 3, and will reply with an array.
The variables tab might then look like:

var1 = 3
var2 = [1.234, 2.345, 3.456, 0, 0, 3.1415]
var3 = True
var4 = 7

Since variables in URScript are first type casted when they are first written to, var1 is an integer, var3 is a boolean, and var2 and var4 will be whatever the XML-RPC server replies.
If the XML-RPC server replies with a numerical array, then var2 will be a numerical array with the length equivalent to the replied amount of numbers.

Note that for arrays; all entries must be of same type (e.g. boolean or numeric) and the length is fixed at declaration.
So if the amount of data you need to send varies, you should “zero pad” the rest of the array, thus you do not overwrite var2 with e.g. different lengths and data types.

Thanks, that’s very helpful. So there is no need or advantage to define or set var2 or var4 before calling camera.Get…(). The UR xml-rpc handler infers the variable type from the string returned by the server?.

In executing the line:
var4 = camera.GetBooleanAndReplyInteger(var3)
Does the argument string sent to the server contain the string “True” or an xml-rpc compatible integer representation of True (the integer 1)?

On another matter, during the course of reading the manuals I’ve encountered a few typos. If you’d like me to send a list of these to UR please send me a contact email address (off-line).

No, you do not need to initialize the variables.

The XML-RPC call will eventually use the default XML-RPC data types.
Thus 0/1, but if your XML-RPC in e.g. Python, you’d get a True or False, likewise in URScript.

@jbm what is the largest array length you can return from the xml-rpc factory? We ahve had a few occasions where we need an array of 40 or more and there is no clean way to do that in URScript, at least not that I know of. If there is a way it would be awesome. My thought is I could have a factory function that takes an integer and returns a zero padded array which is created from the integer that I sent in.


Hi Matt

There should not be any strict limit to max array length.
Have you hit a limit in an array length, then please let me know.

What is the use case of creating a super-long zero-padded array?

The use case is we use it to store location data on palletized materials in cells. So we will have a pallet that may have 10 parts, or 100 parts on it. When a new pallet is loaded we run down through the pallet and determine which pockets actually have parts in them. We store this in the array, we then change the value of the array as we are processing the pallet and then this is displayed in our iPhone app in real time as the pallet is consumed. You can quickly see the status of each pocket on the pallet.

We will then have a couple of other arrays that hold the x and y coordinate data for each of the pockets, in case they are not in a tabular design but rather interspersed to maximize quantity on the pallet. The robot is capable of running several different pallets of products by simply telling it which pallet is currently loaded via the iOS app. It then will use the appropriate pallet data to fill out the in use pallet array. Since the number of items on the pallet can vary we have to zero pad an array to start with that is sized to handle the largest array that we can possible have.

My thought was instead of creating by hand a super long list at the beginning of the program in the before-start section I could just make an RPC call and return the exact array that I need each time. I know one of the URScripts returns a list and we thought about using that originally but it will only return a list that is 30 long. I think it is one of the socket read API’s, its been a few months since I tried using that to shortcut the system.


Hi Matt

The XML-RPC returned array of the actual needed length sounds like a good approach.
In that way, you do not use unnecessary memory for empty arrays.

As mentioned, there should not be a max length to an array, if you should encounter this, let me know.


I know this is an old thread and I’m not sure if you’re still doing support, but if you look at my latest post in the exceptions forum I believe I’m running into an array length limit in 5.6.