Java coming to the main distro

To the powers that be:

I noticed that Java is making it’s way into the main distro on this page: http://beagleboard.org/static/beaglebone/latest/README.htm

This is very exciting news for me. While I have been running Java on there, it’s lack of hardware interface support doesn’t make it ideal for building systems that need to communicate with external hardware. Just access to a UART channel would be a huge win. The RxTx project mentioned allows for this and is compiled for a great many different platforms. It provides native C libraries that allows access to the UART channels.

While I am Java guy, my C skills leave something to be greatly desired. There is a small .so file that is needed. They have a project called “ToyBox” which compiles like 38 different versions of this file for all the different platforms. I have tried all Linux iterations on the BeagleBone but have yet to have any success interfacing with it. Mostly getting C errors I don’t understand. (Sorry I don’t have an example handy).

I have used these on windows with much ease. It looks like it would work easily for a common processor architecture on Linux.

Might I suggest that you add the RxTx libraries to your package list.

Anyone been working on this?

RxTx Main Site: http://rxtx.qbang.org/wiki/index.php/Main_Page
RxTx ToyBox (compiled for many versions): http://rxtx.qbang.org/pub/rxtx/ToyBox/2.1-7-build1/

If anyone knows a good article on compiling .so files from C for a java guy that would be helpful too.

Cheers,

Gregg

opkg update ; opkg install rxtx openjdk-6-jre

OMG OMG OMG!!! Ok, yes I know I sound like a little girl, but this is awesome!!!

Ok, I am going to put my proof of concept code on my bone and see what I can get done. I will post results when I am done.

Thanks Koen!!!

Cheers,

Gregg

Ok, so I am getting the same thing when I install it via opkg as I was when installing it by hand.

When I try to run the code I get the following stack trace:

java.lang.UnsatisfiedLinkError: /usr/lib/jvm/java-6-openjdk/jre/lib/arm/librxtxSerial.so: /usr/lib/jvm/java-6-openjdk/jre/lib/arm/librxtxSerial.so: ELF file OS ABI invalid thrown while loading gnu.io.RXTXCommDriver
Exception in thread “main” java.lang.UnsatisfiedLinkError: /usr/lib/jvm/java-6-openjdk/jre/lib/arm/librxtxSerial.so: /usr/lib/jvm/java-6-openjdk/jre/lib/arm/librxtxSerial.so: ELF file OS ABI invalid
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1750)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1667)
at java.lang.Runtime.loadLibrary0(Runtime.java:840)
at java.lang.System.loadLibrary(System.java:1047)
at gnu.io.CommPortIdentifier.(CommPortIdentifier.java:83)
at com.greggharrington.flyingtoaster.RxTxPOC.main(RxTxPOC.java:20)

It’s the first line of code that accesses the RxTx library:

Enumeration thePorts = CommPortIdentifier.getPortIdentifiers();

This is the same error I was getting when I installed it by hand before. I took the following debugging steps:

  1. Uninstalled rxtx
  2. Uninstalled java (getting rid of any thing I might have done)
  3. Installed java and rxtx (as described above)
  4. Same error

Any thoughts?

Thanks,

Gregg

Note: I have decided to go with a fresh install and upgrade to the latest version of Angstrom. I am currently running the shipping version on the A4. I think it’s about 5 months old. Not sure if I need todo this or not, but I have wanted to anyway.

More updates:

With a fresh install of the latest Angstrom distro beagleboard.org I get the following error:

java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver
Exception in thread “main” java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1681)
at java.lang.Runtime.loadLibrary0(Runtime.java:840)
at java.lang.System.loadLibrary(System.java:1047)
at gnu.io.CommPortIdentifier.(CommPortIdentifier.java:83)
at com.greggharrington.flyingtoaster.RxTxPOC.main(RxTxPOC.java:20)

After trying to run my code. It has been my experience that this is the result of the .so file not being in the /usr/lib/jvm/java-6-openjdk/jre/lib/arm directory. I have downloaded all known copies I can find of the librxtxserial.so file that I have used on other linux and windows machines. The opkg install rxtx doesn’t seam to install this file and I can’t seam to find the jar file either. I even did a “find / | grep -i rxtx” to see if I could find it. Nothing. When I use the jar files I download I get a linking error:

Exception in thread “main” java.lang.NoClassDefFoundError: com/greggharrington/flyingtoaster/RxTxPOC
Caused by: java.lang.ClassNotFoundException: com.greggharrington.flyingtoaster.RxTxPOC
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: com.greggharrington.flyingtoaster.RxTxPOC. Program will exit.

This means it can’t find the jar file. Any way to tell what the opkg install rxtx does to the file system?

Thanks for all the help…

Gregg

Guys,

Ok, one more final update for the night… I have had some limited success with reading a USB port and none with reading a UART port. The UART port is actually the goal of this project as I am currently using python to proxy information to java via a socket.

Here is what I have done:

  1. Installed newest distro (not sure this made a difference, but needed to be done anyway)
  2. opkg update
  3. opkg install openjdk-6-jre
  4. opkg install rxtx
    4a. I had to copy all files from /usr/lib/jni/librxtx* to /usr/lib/jvm/java-6-openjdk/jre/lib/arm to make the libraries work at all. This was not done by the install rxtx above. Probably a better way todo this with a link if someone would like to comment on that.
  5. Run my program which basically just spits out the com ports. Output reads:

WARNING: RXTX Version mismatch
Jar version = RXTX-2.2pre1
native lib Version = RXTX-2.2pre2
RXTX Warning: Removing stale lock file. /var/lock/LCK…ttyUSB0
/dev/ttyUSB0 - Serial

Note: Changing the version of the jar file doesn’t get rid of the warning regardless. However, that is the USB device that is hooked up. It is spitting out a 9600 baud GPS signal from a UART to RS232 serial converter.

  1. When I run this on windows I come up with:

$GPRMC,053000.004,V,4035.6940,N,12223.2450,W,0.00,0.00,300512,N69
$GPVTG,0.00,T,M,0.00,N,0.00,K,N
32
$GPGGA,053001.004,4035.6940,N,12223.2450,W,0,0,172.8,M,-22.8,M,71
$GPGLL,4035.6940,N,12223.2450,W,053001.004,V,N
5A
$GPGSA,A,1,1E
$GPGSV,1,1,01,25,25
78
$GPRMC,053001.004,V,4035.6940,N,12223.2450,W,0.00,0.00,300512,N68
$GPVTG,0.00,T,M,0.00,N,0.00,K,N
32

  1. However, when I change only the port ID to /dev/ttyUSB0 it comes up with the following on the BeagleBone:

GGL43.90,22.40W54104VN5E.,M-28M,7
GGAA1,1
$PT,00,M00,00,*2325,00,.0301,N6
GGA,542044364,22.45,128,2.,*6
$PS,*E$PS,079
GRC03004V43.90,22.40W.000,05,*F
GGL43.90,22.40W54304VN5C.,M-28M,7
GGAA1,1

It’s obviously getting something and parts of it are right. However, it’s not getting it correctly. I would post all my code up here, but it’s several files. Here are the biggies though:

This code spins up some stuff:

inBuffer = new StringBuffer();
outBuffer = new StringBuffer();

portIdentifier = CommPortIdentifier.getPortIdentifier("/dev/ttyUSB0");

CommPort commPort = portIdentifier.open(“test”, 2000);

SerialPort serialPort = (SerialPort) commPort;

serialPort.setSerialPortParams(baudRate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);

reader = new SerialReader(serialPort.getInputStream(), inBuffer);
writer = new SerialWriter(serialPort.getOutputStream(), outBuffer);

new Thread(reader).start();
new Thread(writer).start();

Then later this code reads it. This is the thread that gets started:

byte[] buffer = new byte[1024];
int len = -1;
try {
while ((len = this.in.read(buffer)) > -1) {
if (pause) {
continue;
}

if(stop) {
return;
}

String str = new String(buffer, 0, len);

System.out.print(str);

inBuffer.append(str);
}
} catch (IOException e) {
e.printStackTrace();
}

If anyone could provide insight into getting a direct UART connection or even fixing this problem I would grateful. I will be spending some more time with this and update you guys if anything comes up.

Cheers,

Gregg