@@ -41,6 +41,7 @@ static void Main(string[] args)
4141
4242 _ur = new UR ( ) ;
4343 _ur . CartesianInfoReceived += CartesianInfoReceived ;
44+ _ur . XmlRpcServerRequest += XmlRpcServerRequest ;
4445
4546 _ur . Connect ( ip ) ;
4647
@@ -61,6 +62,8 @@ static void Main(string[] args)
6162
6263 private static void CartesianInfoReceived ( object sender , CartesianInfoPackageEventArgs e )
6364 {
65+ // Clear console and display cartesian info every 200ms
66+
6467 if ( ( DateTime . Now - _lastReceived ) . TotalMilliseconds < 200 ) return ;
6568 _lastReceived = DateTime . Now ;
6669
@@ -73,5 +76,74 @@ private static void CartesianInfoReceived(object sender, CartesianInfoPackageEve
7376 Console . WriteLine ( $ "RZ = { e . Rz . ToString ( "0.00" ) } °") ;
7477 Console . WriteLine ( "Press any key to close..." ) ;
7578 }
79+
80+ // Method called when the robot sends a request
81+ // You shoud execute on your robot : rpc:=rpc_factory("xmlrpc","http://192.168.0.10:50000")
82+ // Replace the IP address 192.168.0.10 with the IP of the machine running this .NET code
83+ // If you don't know your IP, you can find it in your interface properties or in with this SDK in the property : ur.DataStreamingLocalEndPoint
84+ // Use xml_rpc_sample.urp program to test this feature
85+ private static void XmlRpcServerRequest ( object sender , XmlRpcEventArg request )
86+ {
87+ Console . WriteLine ( "Robot IP : " + request . EndPoint . Address ) ;
88+ // Prints :
89+ // Robot IP : 192.168.0.1
90+
91+ // Set the returned answer according to the method and its arguments
92+ switch ( request . MethodName )
93+ {
94+ case "get_answer" :
95+ // Robot script : answer1:=rpc.get_answer("Hello", True, False, 12, 12.2, p[100,100,120,0.1,0,0], [12,1.2,123])
96+ // Reply : answer1:=TRUE
97+
98+ foreach ( var argument in request . Arguments )
99+ {
100+ Console . WriteLine ( argument . ToString ( ) ) ; // Prints argument value : "Hello", "true", "false", "12", ...
101+ }
102+
103+ request . Answer = true ;
104+ break ;
105+
106+ case "GetPose" :
107+ // Robot script : answer2:=rpc.GetPose()
108+ // Reply : answer2:=p[100,200,100,0,0,0]
109+ request . Answer = new Pose ( 100 , 200 , 100 , 0 , 0 , 0 ) ;
110+ break ;
111+
112+ case "HowAreYou" :
113+ // Robot script : answer3:=rpc.HowAreYou("Alfred")
114+ // Reply : answer3:="Fine thx Alfred"
115+ request . Answer = "Fine thx " + request . Arguments [ 0 ] ;
116+ break ;
117+
118+ case "SumFirstArray" :
119+ // Robot script : answer4:=rpc.SumFirstArray([1,3.5,-2])
120+ // Reply : answer4:=2.5
121+ double [ ] argument1 = request . Arguments [ 0 ] ;
122+
123+ double sum1 = 0 ;
124+ for ( int i = 0 ; i < argument1 . Length ; i ++ ) sum1 += argument1 [ i ] ;
125+
126+ request . Answer = sum1 ;
127+
128+ break ;
129+
130+ case "SumMyArguments" :
131+ // Robot script : answer5:=rpc.SumMyArguments(1,3.5,-2)
132+ // Reply : answer5:=2.5
133+ double sum = 0 ;
134+ for ( int i = 0 ; i < request . Arguments . Length ; i ++ )
135+ {
136+ double argValue = request . Arguments [ i ] ;
137+ sum += argValue ;
138+ }
139+
140+ request . Answer = sum ;
141+ break ;
142+
143+ default :
144+ // Do not reply and the answer variable is not assigned
145+ break ;
146+ }
147+ }
76148 }
77149}
0 commit comments