Universal Robots Forum

Xml - rpc python to java

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

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

contribution variables

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)

Is there anyone who can help me with this?:blush:

yours sincerely,
Zoe

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.

2 Likes

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)

1 Like

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

java xml-rpc

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.

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

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

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).