View Full Version : XML-RPC Java Example Client Problems
TimWhite
08-02-2010, 03:55 PM
It looks like the files for the SNAPconnect client were renamed when the product was renamed from SNAP Gateway, but the classes weren't renamed.
So I had to edit SNAPconnect.java and SNAPconnectFaultCodes.java to change their classnames to match the file names in order to get them to run.
Java is picky about the "Class Name Must Match File Name". :)
Thanks,
Tim
TimWhite
09-27-2010, 01:25 PM
I was using a USB dongle just like the example code was defaulted to use.
Did you update your Serial settings to specify serial instead of USB, and the right serial port?
For example (don't have the Java example handy, but here's the python version):
CONN_TYPE_USB = 2
CONN_TYPE_SERIAL = 1
srv.connectSerial(CONN_TYPE_SERIAL, 3) # Connects to Serial Port COM3
mgenti
09-27-2010, 01:26 PM
You may need to set a breakpoint in the exception handler at line 137 to find out what error the server is returning.
jchang
09-27-2010, 01:51 PM
Yes, I also found that portCombo.getSelectionIndex()+1 return wrong number when I select the port number from the combo box. Therefore, I changed
srv.connectSerial(typeCombo.getSelectionIndex()+1, portCombo.getSelectionIndex()+1, false);
to
srv.connectSerial(1, 6, false); // The bridge is on Com6
It is still not working. I will try the USB stick.
I was able to get python client to work.
Jimmy
jchang
09-29-2010, 01:57 PM
You may need to set a breakpoint in the exception handler at line 137 to find out what error the server is returning.
I still cannot get java Multicast Counter client to work. I have added debug at line 137. I got
redstone.xmlrpc.XmlRpcFault: <type 'exceptions.Exception'>:method ".connectSerial" is not supported
at redstone.xmlrpc.XmlRpcClient.handleResponse(Unknow n Source)
at redstone.xmlrpc.XmlRpcClient.endCall(Unknown Source)
at redstone.xmlrpc.XmlRpcClient.invoke(Unknown Source)
at redstone.xmlrpc.XmlRpcProxy.invoke(Unknown Source)
at $Proxy0.connectSerial(Unknown Source)
at MulticastCounter$1.widgetSelected(MulticastCounter .java:132)
at org.eclipse.swt.widgets.TypedListener.handleEvent( Unknown Source)
at org.eclipse.swt.widgets.EventTable.sendEvent(Unkno wn Source)
at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Display.runDeferredEvents( Unknown Source)
at org.eclipse.swt.widgets.Display.readAndDispatch(Un known Source)
at MulticastCounter.main(MulticastCounter.java:88)
Any idea?
I saw comment "Before this is run, be sure to set up the launch configuration (Arguments->VM Arguments)" in the code. Don't know what this is. Is this causing the problem?
Thanks
admin
09-29-2010, 04:17 PM
That message is related to using SWT and not XML-RPC. I just tried with the latest JDK and eclipse and I am unable to reproduce the connectSerial error you are describing.
jchang
09-30-2010, 01:39 PM
I installed Java Ganymede SR2 on my PC as indicated in SNAPconnect Manual. SWT does not come with Ganymede. I download "swt-3.7M1-win32-win32-x86.zip" separately and add swt.jar to the build path. I download redstone-simple-xmlrpc-1.0 and add xmlrpc-1.1.1.jar to the build path.
I run MulticastCounter.java example and I got
redstone.xmlrpc.XmlRpcFault: <type 'exceptions.Exception'>:method ".connectSerial" is not supported
from fault.printStackTrace(); in the catch block. What did I do wrong? I really like to get this working. Please help!
mgenti
09-30-2010, 01:41 PM
What environment do you currently do your Java development in?
jchang
09-30-2010, 01:43 PM
Windows XP Service Pack 3.
mgenti
09-30-2010, 01:44 PM
Right that is the OS you are using but what do you currently use as your IDE for Java? Is it all via the command line or do you use something like Eclipse or IntelliJ?
jchang
09-30-2010, 01:47 PM
Sorry, Eclipse Ganymede.
mgenti
09-30-2010, 01:48 PM
That is what you normally use for Java development or just what you downloaded to try the example?
jchang
09-30-2010, 01:51 PM
I just download to try the example.
kbanks
09-30-2010, 07:27 PM
Try running just from the command line, to ensure the issues have nothing to do with the IDE.
Eclipse is pretty complicated, we won't be able to "talk you through it" using the forum.
You may have to trim your example down into something we can reasonably support via the forum.
We use mostly Python here at Synapse, we only dig out the other languages in order to make the occasional example program.
As Mark said, the JAVA example still works for him here.
jeffw
11-20-2010, 04:37 AM
On Linux (Ubuntu 10.04) it seems the problem is that USB is not supported. Starting SNAPconnect with serial connect params.
$ ./SNAPconnect -t 2 -n 1
02:30:39:751 DEBUG SNAPconnect ******** Synapse SNAPconnect Debug Log - 2.1.35 ********
02:30:39:753 DEBUG serialwrapper.PyserialDriver .
02:30:39:753 ERROR serialwrapper.PyserialDriver An error occured while setting up the serial port
Traceback (most recent call last):
File "Synapse/Components/serialwrapper.PyserialDriver", line 239, in setupSerialDriver
SerialOpenException: Synapse USB devices are not currently supported on this platform
Traceback (most recent call last):
File "<string>", line 760, in <module>
File "<string>", line 754, in Main
File "<string>", line 596, in __init__
File "<string>", line 244, in connectSerial
File "Synapse/Components/serialwrapper.PyserialDriver", line 221, in setOutputType
File "Synapse/Components/serialwrapper.PyserialDriver", line 271, in setupSerialDriver
serialwrapper.PyserialDriver.SerialOpenException: An error occured while setting up the serial port
jeffw
11-20-2010, 04:42 AM
...and... the message
02:24:43:557 INFO http_server <?xml version='1.0'?>
<methodResponse>
<fault>
<value><struct>
<member>
<name>faultCode</name>
<value><int>1</int></value>
</member>
<member>
<name>faultString</name>
<value><string><type 'exceptions.Exception'>:method ".connectSerial" is not supported</string></value>
</member>
</struct></value>
</fault>
</methodResponse>
is being thrown by SNAPconnect, not the client Java program. This is not an SWT or Java VM version issue. Someone needs to look at the C code that implements that part of SNAPconnect, and either A) come up with a better error message, or B) give us some sense of how to deal with this.
BTW: Portal does not use connectSerial to connect to a USB gateway. It uses this command to get at the device driver directly.
02:16:39:256 INFO http_server waitOnEvent(000001, True, 1, /dev/ttyUSB0, )
02:16:39:282 INFO http_server mcastRpc(000001, 0001, 5, vmStat, [5, 2], )
02:16:39:299 INFO http_server 127.0.0.1:37163 - - "POST /RPC2 HTTP/1.1" 200 269
admin
11-22-2010, 10:17 AM
On Linux (Ubuntu 10.04) it seems the problem is that USB is not supported.
That is correct, if you want to use a Synapse USB device in Linux or Mac it will need to bet setup as a virtual COM port.
admin
11-22-2010, 10:22 AM
is being thrown by SNAPconnect, not the client Java program. This is not an SWT or Java VM version issue. Someone needs to look at the C code that implements that part of SNAPconnect, and either A) come up with a better error message, or B) give us some sense of how to deal with this.
You didn't explicitly say but since you posted this in the Java thread I'm guessing you are trying to get our Java example client to run? The code should be calling "connectSerial" (without the period) not ".connectSerial".
BTW: Portal does not use connectSerial to connect to a USB gateway. It uses this command to get at the device driver directly.
02:16:39:256 INFO http_server waitOnEvent(000001, True, 1, /dev/ttyUSB0, )
02:16:39:282 INFO http_server mcastRpc(000001, 0001, 5, vmStat, [5, 2], )
02:16:39:299 INFO http_server 127.0.0.1:37163 - - "POST /RPC2 HTTP/1.1" 200 269
Yes, that is an alternate approach so that you don't have to make two calls but is all done with one call. This is documented in the SNAP Connect manual.
jeffw
11-22-2010, 12:08 PM
Portal is working, so the VCP is not the issue.
I'm following the directions that are scattered on these forums, and it's not working for me. Your Java example code makes a call srv.serialConnect() that gets mapped to a .serialConnect XML-RPC call in SNAPconnect. Maybe that's wrong, but then how did the example work for you? (I believe that if you were to also try this from scratch on a fresh Linux instance it would not work - a fresh instance can be setup in a VM in minutes.)
What should I do?
jeffw
11-22-2010, 04:44 PM
I made a symbolic link from /dev/ttyUSB0 to a /dev/ttySx (to a port that was one higher than an actual port/driver in the system). Then I selected that "one higher" port in the running Java example and now the Java example works. My feeling is that the prohibition against using the USB option of serialConnect in SNAPconnect is artificial (and untested).
Here are the problems getting up on Linux:
The Portal archive does not come with SNAPpy scripts, so it doesn't work.
The forum provided SNAPpy scripts have the wrong line endings (why does this matter?)
Portal has dependencies that are not clear (and not pulled in via a package manager).
Portal requires glibc-2.11 (forcing latest kernel), but this is not documented.
The Java example has misnamed classes.
The Java project import step doesn't take into consideration that the XML-RPC JAR and synapse.ico file will be left behind if you select "copy into workspace" (and the project won't run).
SNAPconnect doesn't seem to respect the same rules and restrictions for serial i/o as Portal. (Leading to a confusing support situation.)
Anyone setting out to run under Linux will have hours of heartache in store for them. It would be a good idea to have install/run on a fresh Linux instance as a regression test for releasing.
admin
11-23-2010, 10:12 AM
Then I selected that "one higher" port in the running Java example and now the Java example works. My feeling is that the prohibition against using the USB option of serialConnect in SNAPconnect is artificial (and untested).
The USB-to-RS232 chip that we currently use on our SNAP sticks do not have "native" USB drivers for Linux or Mac. This is why we recommend settings up the device as a Virtual COM Port. When you set it up as a VCP, in your SNAP Connect app you can connect to it like connectSerial(1, '/dev/ttyUSB0').
The Portal archive does not come with SNAPpy scripts, so it doesn't work.
The Portal archive does come with a folder called snappyImages, however that directory is not automatically copied into your ~/Portal directory. Once you copy these files into that directory they should appear when you launch Portal. We will try to mention this in our next version of the Portal manual.
Portal has dependencies that are not clear (and not pulled in via a package manager). Portal requires glibc-2.11 (forcing latest kernel), but this is not documented.
Portal is always built using the latest updates provided for Ubuntu 10.04. It is also tested in a completely clean, and updated, version of Ubuntu 10.04 to verify that no external dependencies are required. It sounds like maybe the dependency is that we built Portal with an update that you had not applied yet?
SNAPconnect doesn't seem to respect the same rules and restrictions for serial i/o as Portal. (Leading to a confusing support situation.)
Yes, as mentioned earlier the vendor for our USB-to-RS232 does not have complete support for Linux and Mac in their "native" access mode. However once they are in VCP mode you should have no problems.
Thank you for letting us know your frustrations and problems, we hope to continue to make our multi-OS support better.
jeffw
11-23-2010, 11:43 AM
If Portal is working then I'm already using VCP, right? By symlinking /dev/ttyUSB0 to /dev/ttySx I'm able to get the XML-RPC call to work (because /dev/ttyUSB0 is a VCP).
I don't see documentation for connectSerial(1, '/dev/ttyUSB0'). Does that exist? According to your docs the API is: connectSerial( portType, portNum, reconnect ).
You say it works, and it doesn't, so I don't know what to do. It would be great if you guys would really try this from scratch (running the Java example out-of-the-box) on a fresh Linux instance.
mgenti
11-23-2010, 03:13 PM
To clarify, are you still not getting the Java example to work at all or it is working with the workarounds you have described?
jeffw
11-23-2010, 04:29 PM
Yes, I found a hack, but the OS erases the symlink each time it boots, so no it's not solved for production systems. It doesn't seem like there's any interest in solving my problem, so I give up.
mgenti
11-24-2010, 05:04 PM
Sorry that it has taken longer than usual for us to get back to you, we have some people out of the office due to the holidays.
I just updated my clean copy of Ubuntu 10.04 to the latest updates today and then downloaded the latest version of Portal from the forums. I then was able to successfully connect to /dev/ttyUSB0 without having to do any symbolic links. Does /dev/ttyUSB0 show up in the Portal connection dropdown?
The Java example may not be as straight forward in Linux as it is in Windows, since Windows uses numbers instead of strings when connecting to serial ports. The Java GUI made an assumption that you are on Windows, as most of our users are, so gives you a lists of port numbers to choose from instead of allowing you to type a port in. For Linux you could modify the GUI to allow a port to be typed in and then also modify the XML-RPC SNAP Connect class definition to have connectSerial to allow a string as the port number.
vBulletin® v3.8.0, Copyright ©2000-2012, Jelsoft Enterprises Ltd.