# Xml - rpc python to java

**URL:** <https://forum.universal-robots.com/t/xml-rpc-python-to-java/18479>\
**Category:** URCaps SDK\
**Created:** [January 5, 2022, 3:33pm UTC](https://forum.universal-robots.com/t/xml-rpc-python-to-java/18479 "2022-01-05T15:33:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![zoehermans.1996](https://avatars.discourse-cdn.com/v4/letter/z/4bbf92/32.png) [@zoehermans.1996](https://forum.universal-robots.com/u/zoehermans.1996)\
**Post date:** [January 5, 2022, 3:33pm UTC](https://forum.universal-robots.com/t/xml-rpc-python-to-java/18479/1 "2022-01-05T15:33:05Z")

</div>

Hello all,

I am trying to extract values from the controller box by reading them with modbus communication. In it I am processing an xml-rpc server that from the python script needs to send something to a java xml-rpc client. In the ProgramNodeContribution, when clicking a button, it should take over these values.

I used part of the myDaemon example for this, but it doesn’t work and I can’t find the error.  
This is my code:

**python xml rpc server** - The modbus in python has been tested and works

 ![Schermafbeelding 2022-01-05 om 16.01.20](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/2/2b6f7afab50c57184caccd2a2a637260952dc3b5.png)

**java xml rpc client** - this is largely taken from the myDaemon example

 ![Schermafbeelding 2022-01-05 om 16.03.08](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/0/0ba1be143df8568901e34b856c8a7cf541627d03.jpeg)

**contribution variables**

 ![Schermafbeelding 2022-01-05 om 16.05.39](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/4/436072cf031e9f21f00f3e897c13a7222e2eefc6.jpeg)

**Contribution button - getting the values  
When I look in the console I then get the message:  
“IT DOESN’T WORK” (from the red block in the picture)**

 ![Schermafbeelding 2022-01-05 om 16.05.20](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/2/2733f537a1cfdcd26cbae8b3cecba45941a878a0.jpeg)

Is there anyone who can help me with this?😊

yours sincerely,  
Zoe

---

<div class="post-metadata">

**Author:** ![eric.feldmann](https://avatars.discourse-cdn.com/v4/letter/e/94ad74/32.png) [@eric.feldmann](https://forum.universal-robots.com/u/eric.feldmann)\
**Post date:** [January 5, 2022, 4:39pm UTC](https://forum.universal-robots.com/t/xml-rpc-python-to-java/18479/2 "2022-01-05T16:39:52Z")

</div>

Doing a little more debugging might help narrow the cause. For example, if you’re hitting the red block of code there, and seeing “IT DOESN’T WORK” that must mean an exception was thrown when you called the “getWaypoints()” function. So the problem lies in there, would be my guess.

Looking at that, we have 2 potential points of failure: the .execute() with your store\_waypoints function, or the processString() function. Try putting some more System.outs in between these calls and see if it runs. For example, if you put a println after the .execute() but before the processString() and it DOESN’T run, then your problem is in the client.execute(Store\_Waypoints) bit. If it DOES run, then your problem is in the processString() function.

It might also help to post your code for the store\_waypoints function. This is the one written in Python I assume? You may be encountering some sort of typing error, where Java is looking for an ArrayList of Strings, but Python is returning ints or doubles or whatever. Just a thought.

---

<div class="post-metadata">

**Author:** ![fujikit](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/fujikit/32/6042_2.png) [@fujikit](https://forum.universal-robots.com/u/fujikit)\
**Post date:** [January 6, 2022, 9:06am UTC](https://forum.universal-robots.com/t/xml-rpc-python-to-java/18479/3 "2022-01-06T09:06:52Z")

</div>

Hi, can mydaemon sample can be running on your environment?  
If it can’t be running, please check the below.

[I cannot start daemon (XMLRPCmath) - URCap Development - Universal Robots Forum (universal-robots.com)](https://forum.universal-robots.com/t/i-cannot-start-daemon-xmlrpcmath/6097/2)

---

<div class="post-metadata">

**Author:** ![zoehermans.1996](https://avatars.discourse-cdn.com/v4/letter/z/4bbf92/32.png) [@zoehermans.1996](https://forum.universal-robots.com/u/zoehermans.1996)\
**Post date:** [January 7, 2022, 9:27am UTC](https://forum.universal-robots.com/t/xml-rpc-python-to-java/18479/4 "2022-01-07T09:27:35Z")

</div>

You’ve killed two birds with one stone.

It was indeed Integers[] instead of Strings and the problem seems to be in the processString. I changed this to Integer and Integer[] and neither solution seems to work. (Of course I changed the contribution as well.)

**python**

 ![Schermafbeelding 2022-01-07 om 10.06.05](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/b/b611c9f2350294733e3c0adb98c7c56720722713.png)

**java xml-rpc**

 ![Schermafbeelding 2022-01-07 om 10.07.00](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/d/dcb23950890b70c1c1813f05dde64c051f579530.jpeg)

I think I understand what the processString function does, but I don’t understand how to convert the operation to reading data from an Integer arrayList instead of from a String.

Sorry if this is a simple question, I have yet to learn to be a bit more self-sufficient in terms of finding and fixing bugs.

---

<div class="post-metadata">

**Author:** ![eric.feldmann](https://avatars.discourse-cdn.com/v4/letter/e/94ad74/32.png) [@eric.feldmann](https://forum.universal-robots.com/u/eric.feldmann)\
**Post date:** [January 7, 2022, 12:49pm UTC](https://forum.universal-robots.com/t/xml-rpc-python-to-java/18479/5 "2022-01-07T12:49:53Z")

</div>

So the processString function looks like all it’s doing is checking that the generic “object” returned from the function is of type integer[]. If it is, it casts it to an integer array (by putting the (Integer[]) part in front of response) and then returns this. So you’re still getting the else statement, which means the result of client.execute() IS NOT of type Integer[].

Looking at your python code, you need to determine what data type “pose” is, as this is what is being returned. In Java, you’ve typed it as “Object” which is fine, but won’t get you an explicit type like String, Int, Double, etc. It might need to be this way since Java doesn’t really know what Python is going to return. This is why you’re checking the type later with processString.

My guess would be Python is returning either a double, or a list of doubles (double[]). I’m just kinda assuming this because a robot pose would normally be an array of 6 doubles. So either find out what the data type is in Python, or just shotgun approach it in Java by putting a bunch of if()s checking for various data types. if(instance of String), if(instance of int), if(instance of double) etc and see if any of them turn up a result.

I had done a similar test with our CAP a while back, so I just dug this up. This is the Python function:  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/2/222bf5dfab2bafa93b59c84d1cc3c5ccd4634aba.png)

It’s REALLY basic, all it does is add 5 to whatever value you pass it. But you’ll notice I use int(value) to force it to be an int. This way I know Python is returning an int.

So in Java:

![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/3/396808d92a3098c9580125dd2ad3f26f0ccd0c2f.png)

I can check purely for if it’s an instance of Integer, and if it is, I type cast the result to an int (that way Java knows what it is from now on and I can perform integer operations on it).

---

<div class="post-metadata">

**Author:** ![zoehermans.1996](https://avatars.discourse-cdn.com/v4/letter/z/4bbf92/32.png) [@zoehermans.1996](https://forum.universal-robots.com/u/zoehermans.1996)\
**Post date:** [January 24, 2022, 11:16am UTC](https://forum.universal-robots.com/t/xml-rpc-python-to-java/18479/6 "2022-01-24T11:16:53Z")

</div>

Hello @eric.feldmann,

Sorry for the late response. I found out that my network was not good. Passing a single variable as a String and an Int is going well now. To make sure I am working with an Int I created an array of int’s to test. But passing an array still doesn’t work.

 ![Schermafbeelding 2022-01-24 om 11.59.59](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/b/b3cce96ca0eab770e6d4edc9e07c179abfad2bea.png)

I tried .getClass().isArray(), which returns true, so it should be an array.

I have tried it with all possible variable types with instanceOf and the only one that seems to work is Object. From that I get an @ value that I can’t do anything with (I think),

 ![Schermafbeelding 2022-01-24 om 12.01.46](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/7/79fedea0ddebf5a79c736ebed3d46a06416fbba2.jpeg)

 ![Schermafbeelding 2022-01-24 om 12.02.57](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/d/deda99552b790ff690bad310e2d07d7fe57a492d.png)

Then of course when I want to put it into an Integer ArrayList I get an error message.

 ![Schermafbeelding 2022-01-24 om 12.00.56](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/c/c5bb3961d8a97fe47bf1da25fcd1b4cc145b5f5f.jpeg)

 ![Schermafbeelding 2022-01-24 om 11.54.55](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/2/2976317478f2fd97db12dfdf06809299cfb5b189.png)

So I expect that it is also an Object that I get forwarded from the Python script. I found how to convert it to an Integer, but because (I think) the value is weird, I can’t use this.

What should I do to convert the @… to just an array of values.

Thanks a lot for your help!

Regards Zoë

---

<div class="post-metadata">

**Author:** ![eric.feldmann](https://avatars.discourse-cdn.com/v4/letter/e/94ad74/32.png) [@eric.feldmann](https://forum.universal-robots.com/u/eric.feldmann)\
**Post date:** [January 24, 2022, 2:37pm UTC](https://forum.universal-robots.com/t/xml-rpc-python-to-java/18479/7 "2022-01-24T14:37:34Z")

</div>

Nice debugging! I just did a quick search to verify, but you cannot do a simple cast of Object to Int.

Here’s the stack overflow link: [types - How to cast Object[] to int[] java? - Stack Overflow](https://stackoverflow.com/questions/38578995/how-to-cast-object-to-int-java)

A little further down in that page, someone talks about various methods for unboxing the object. Basically, the type Int does not extend Object, which means the compiler doesn’t know how it should convert it. As humans, you and I can say “it’s so easy! Just take each number in the object array and stick it into an int array!” Soooo that’s exactly what you have to tell the compiler!

```auto
// Using cast to specific type and auto-unboxing (object cast)
int[] arr1 = new int[A1.length];
for (int i = 0; i < A1.length; i++)
    arr1[i] = (Integer)A1[i];

```

Here we’re saying: Make a new array that is as large as the Object array. Then use a for() loop to iterate through that object, grab each ELEMENT, cast it to an Integer, and store it back to our new int array. We are providing the compile an explicit order of operations so it can’t just throw its hands in the air and give up. The compiler has no problem casting each element inside the object array to an int, it just doesn’t know how to convert the whole array in one go. Please give this a shot and see if it solves your error.

---

<div class="post-metadata">

**Author:** ![zoehermans.1996](https://avatars.discourse-cdn.com/v4/letter/z/4bbf92/32.png) [@zoehermans.1996](https://forum.universal-robots.com/u/zoehermans.1996)\
**Post date:** [January 26, 2022, 7:14am UTC](https://forum.universal-robots.com/t/xml-rpc-python-to-java/18479/8 "2022-01-26T07:14:17Z")

</div>

@eric.feldmann

It worked! I used the forloop from your comment in combination with an @Override toString method

Thanks you so much for your help again!

Regards Zoë
