DEV-NOTES - Development notes for the cal_sta_server Java code Author: John Sexton Date: 3/20/11 SUMMARY: -Tried to install Sun's Java Comm API, doesn't work for 64-bit machines. -Changed from open source IcedTea Java 6 to Sun's Java 6. -Tried to install RXTX library. Need special version for 64-bit. Does not allow you to open any port, only can open what it scans. -Downloaded RXTX source code, added "arduino" and "robot" port prefixes to RXTX library, compiled it and installed it on Marvin. USEFUL JAVA LOCATIONS: /usr/lib/jvm - location of java installations /usr/lib/jvm/java-6-sun/jre/lib/ext - java extension .jar files (like RXTXcomm.jar) go here (for Sun's Java) /usr/lib/jvm/java-6-sun/jre/lib/amd64 - the librxtx______.so files go here (for Sun's Java + 64-bit) /usr/lib/jvm/java-6-sun/jre/lib/amd64 ^ ^ Sun's Java 64-bit architecture USEFUL WEBSITES: http://en.wikibooks.org/wiki/Serial_Programming/Serial_Java - General overview of serial programming in Java. http://download.oracle.com/docs/cd/E17802_01/products/products/javacomm/reference/api/index.html - API for javax.comm / gnu.io http://www.capybara.org/~dfraser/archives/29 - Article describing how to edit RXTX source code to add port prefixes. http://rxtx.qbang.org/wiki/index.php/Main_Page - RXTX development wiki. Very good resource for installing and obtaining source code. http://www.cloudhopper.com/opensource/rxtx/ - Location of 64-bit compiled binaries for RXTX library. NOTES: Java does not play nice with serial ports right out of the box. You must install additional libraries to gain the ability to speak to serial ports in Java. The most common library that I found is the JAVA COMMUNICATIONS API LIBRARY. == Sun's Java Communications API == Sun does a very poor job of maintaining this library (after all, they support platform-independent development and this is difficult when a serial port inherently relies on the underlying hardware). My first attempts to successfully listen over a serial port involved using Sun's implementation of the Java Communications API. It was difficult to find a good download of this online, but I eventually ended up using an Oracle website (http://www.oracle.com/technetwork/java/index-jsp-141752.html) to obtain the library. Followed installation instructions and successfully installed, but when I tried to run a program I got an error which cited the ELF compiled binary file. Also mentioned the word size might be wrong. This error was confirmed online where I found support for the fact that Sun/Oracle only supports 32-bit versions of the Java Communications API and doesn't support windows. All of these limitations led me to abandon using Sun's version. == RXTX Library == I found an open source library called the RXTX library which follows the Java Communications API exactly (except it's called 'gnu.io' instead of 'javax.comm'). The development website (http://rxtx.qbang.org/wiki/index.php/Main_Page) was very useful. I was able to successfully install the RXTX library, but when I tried to run sample code, Java seg-faulted (OMG... XD). In an attempt to fix this, I removed the open source IcedTea java and installed Sun's Java, but the error still remained. I then traced the error back to the Thread function, so I believe the problem is not actualy with the RXTX functionality that we need and instead has to do with using threads with the RXTX library. I proceeded to write a small Java program to test the RXTX library, and discovered that you can only address ports which the library finds on its own. This was a problem because the library only looked for a few prefixes and did not show the 'arduino' or the 'robot#' nodes in the /dev folder. I found an article online (http://www.capybara.org/~dfraser/archives/29) which describes how to edit the source code for the RXTX library to include more ports. I used the link included in the article to obtain the source code, but when I edited the necessary source file (RXTXCommDriver.java), recompiled it into a .jar file again (had to remove a 'import javax.comm.*' line from the source file which seemed strange to me), and transfered it into the proper directory (/usr/lib/jvm/java-6-sun/jre/lib/ext) it did not work. Java threw an error which I can't remember the content of at the moment (but it wasn't a seg-fault like the thread error). To obtain a better copy of the source code, I again resorted to the RXTX development wiki (http://rxtx.qbang.org/wiki/index.php/Main_Page). I downloaded a recent copy of the source code, unzipped it, ran '/configure', and ran 'make'. I received some errors, but there was still a brand new 'RXTXComm.jar' file in the folder now, so I proceeded to install it (replace the RXTXComm.jar file in the /usr/lib/jvm/java-6-sun/jre/lib/ext folder). To my relief, my test program did NOT throw an error this time. I did get a warning that looked like this: WARNING: RXTX Version mismatch Jar version = RXTX-2.2 native lib Version = RXTX-2.2pre2 (versions are not the same as the versions I saw, but I did have a mismatch warning). To solve this, I just went back to the development wiki and found the version that made these two lines agree (turned out to be rxtx-2.2pre2). Now (finally), my little test program can find the 'arduino' and 'robot#' ports and listen to them! Hope this helps for anyone who has to take this project up after me!