XML-RPC
Response to XML-RPC requests sent by the robot script. You can send positions, numbers, string to the robot.
Overview
This feature allows a robot to request or transmit information to the PC.
The XML-RPC protocol is used. Via this SDK, the PC is a server and opens a TCP Listener on a specified port (default is 50000).
When a request from the robot arrives, the library raises the event XmlRpcServerRequest which contains the name of the method called, its arguments, the IP of the robot and an Answer property which you can set and which contains the value returned to the robot.
To communicate with your app, the robot should execute the following script on your robot. If you don't know your PC IP, you can check the property robot.PrimaryInterface.LocalEndPoint.
For more information about XML-RPC, see : https://www.universal-robots.com/articles/ur/interface-communication/xml-rpc-communication/
# Connect to the SDK and specifie the IP and port of the PCrpc:=rpc_factory("xmlrpc","http://192.168.0.10:50000")# Call method get_answer and wait for the reply. The reply will be assigned in variable "answer"answer:=rpc.get_answer("Hello", True, False, 12, 12.2, p[100,100,120,0.1,0,0], [12,1.2,123])
using UnderAutomation.UniversalRobots;using UnderAutomation.UniversalRobots.Common;using UnderAutomation.UniversalRobots.XmlRpc;namespace CSharpSnippets{class XmlRpc{static void Main(string[] args){// Create a new robot instancevar robot = new UR();// Setup connection to the robotvar param = new ConnectParameters();param.IP = "192.168.0.1";// Enable XML-RPC server on port 50000param.XmlRpc.Enable = true;param.XmlRpc.Port = 50000;// Connect to the robotrobot.Connect(param);robot.XmlRpc.XmlRpcServerRequest += XmlRpc_XmlRpcServerRequest;//...}// Method called when the robot sends a request// You shoud execute on your robot : rpc:=rpc_factory("xmlrpc","http://192.168.0.10:50000")// Replace the IP address 192.168.0.10 with the IP of the machine running this .NET code// If you don't know your IP, you can find it in your interface properties or in with this SDK in the property : ur.DataStreamingLocalEndPointprivate static void XmlRpc_XmlRpcServerRequest(object sender, XmlRpcEventArg request){Console.WriteLine("Robot IP : " + request.EndPoint.Address);// Prints :// Robot IP : 192.168.0.1// Set the returned answer according to the method and its argumentsswitch (request.MethodName){case "get_answer":// Robot script : answer1:=rpc.get_answer("Hello", True, False, 12, 12.2, p[100,100,120,0.1,0,0], [12,1.2,123])// Reply : answer1:=TRUEforeach (var argument in request.Arguments){Console.WriteLine(argument.ToString()); // Prints argument value : "Hello", "true", "false", "12", ...}request.Answer = true;break;case "GetPose":// Robot script : answer2:=rpc.GetPose()// Reply : answer2:=p[100,200,100,0,0,0]request.Answer = new Pose(100, 200, 100, 0, 0, 0);break;case "HowAreYou":// Robot script : answer3:=rpc.HowAreYou("Alfred")// Reply : answer3:="Fine thx Alfred"request.Answer = "Fine thx " + request.Arguments[0];break;case "SumFirstArray":// Robot script : answer4:=rpc.SumFirstArray([1,3.5,-2])// Reply : answer4:=2.5double[] argument1 = request.Arguments[0];double sum1 = 0;for (int i = 0; i < argument1.Length; i++) sum1 += argument1[i];request.Answer = sum1;break;case "SumMyArguments":// Robot script : answer5:=rpc.SumMyArguments(1,3.5,-2)// Reply : answer5:=2.5double sum = 0;for (int i = 0; i < request.Arguments.Length; i++){double argValue = request.Arguments[i];sum += argValue;}request.Answer = sum;break;default:// Do not reply and the answer variable is not assignedbreak;}}}}
It is possible to create a socket server outside an instance of UR.
To do this, you just need to instantiate a XmlRpcServer object.
using UnderAutomation.UniversalRobots.XmlRpc;class XmlRpcDirect{static void Main(string[] args){var server = new XmlRpcServer();server.Start(50000);server.XmlRpcServerRequest += Server_XmlRpcServerRequest;}private static void Server_XmlRpcServerRequest(object sender, XmlRpcEventArg request){string methodName = request.MethodName;}}
Example
A urp program file can be downloaded here : xml_rpc_sample.urp

You can try it with this sample below or with the downloadable Winforms and console examples.
Winforms
In the Winforms example, a popup is displayed and contains all information about the request and allows you to return a typed object to the robot with buttons.

Console
The console example returns a default value for each methods.
LabVIEW
The LabVIEW example is used to respond to the GetPose() method and return a position. The position returned to the robot can be entered in the Front Panel.
For all other requests a string is returned. However, you can adapt this example to return arrays, numbers, ...

A Callback VI is called when a XML RPC request is received from the robot.

XML-RPC types
Represents a request that has just been received from the robot
| Member | Type | Description |
|---|---|---|
Answer Field | XmlRpcValue | Response to be provided to the robot by the user |
Arguments Field | XmlRpcValue[] | The arguments of the method called |
EndPoint Field | IPEndPoint | IP address of the robot |
MethodName Field | string | The method called by the robot |
XmlRequest Field | XDocument | The XML document received via HTTP |
The class XmlRpcValue has implicit operators that allow it to be implicitly casted in native types (int, double, string, Pose, array). This is why it is for example possible to write request.Answer = 12 instead of request.Answer = new XmlRpcIntegerValue(12).
Base class of all elements transmitted by XML-RPC. La propriété Type donne le type dans lequel cette objet peut être casté pour obtenir la valeur
| Member | Type | Description |
|---|---|---|
XmlRpcValue() Constructor | ||
Type Property read only | XmlRpcType | Determines the class of this message |
Xml Property read only | XElement | The XML description of the message that has been received from the robot or will be sent to the robot |
ToString() Method | string | |
implicit operator XmlRpcValue(bool) Operator static | XmlRpcValue | |
implicit operator XmlRpcValue(bool[]) Operator static | XmlRpcValue | |
implicit operator XmlRpcValue(double) Operator static | XmlRpcValue | |
implicit operator XmlRpcValue(double[]) Operator static | XmlRpcValue | |
implicit operator XmlRpcValue(int) Operator static | XmlRpcValue | |
implicit operator XmlRpcValue(int[]) Operator static | XmlRpcValue | |
implicit operator XmlRpcValue(string) Operator static | XmlRpcValue | |
implicit operator XmlRpcValue(string[]) Operator static | XmlRpcValue | |
implicit operator XmlRpcValue(Pose) Operator static | XmlRpcValue | |
implicit operator XmlRpcValue(Pose[]) Operator static | XmlRpcValue | |
implicit operator bool(XmlRpcValue) Operator static | bool | |
implicit operator bool[](XmlRpcValue) Operator static | bool[] | |
implicit operator double(XmlRpcValue) Operator static | double | |
implicit operator double[](XmlRpcValue) Operator static | double[] | |
implicit operator int(XmlRpcValue) Operator static | int | |
implicit operator int[](XmlRpcValue) Operator static | int[] | |
implicit operator string(XmlRpcValue) Operator static | string | |
implicit operator string[](XmlRpcValue) Operator static | string[] | |
implicit operator Pose(XmlRpcValue) Operator static | Pose | |
implicit operator Pose[](XmlRpcValue) Operator static | Pose[] | |
implicit operator XmlRpcValue(XmlRpcValue[]) Operator static | XmlRpcValue |
The classes XmlRpcIntegerValue, XmlRpcDoubleValue, XmlRpcBooleanValue, XmlRpcStringValue, XmlRpcPoseValue, XmlRpcArrayValue, XmlRpcStructValue inherits from XmlRpcValue and have a Type field that contains the value in the right type.
If an unknown object is received, a XmlRpcUnknownValue value is returned that contains a AdditionalInformation explaining why it is not supported.