LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   linux and java: javax.comm works in linux? (http://www.linuxquestions.org/questions/programming-9/linux-and-java-javax-comm-works-in-linux-4175423858/)

eantoranz 08-24-2012 04:38 PM

linux and java: javax.comm works in linux?
 
Hi!

I'm goint to test an application that uses javax.comm to handle some serial ports. It was developed in windows and now I'm going to use it on linux (on x86 but then I'll move it to a DreamPlug so it will be running on ARM).

I'm listing the available ports on my box and I see none (and I have a USB dongle that provides 3 ports, ttyUSB0 1 and 2).

Code:

Enumeration<CommPortIdentifier>        ports = CommPortIdentifier.getPortIdentifiers();
System.out.println("Puertos disponibles:");
while (ports.hasMoreElements()) {
        CommPortIdentifier port = ports.nextElement();
        System.out.println(port.getName());
}
System.out.println("Eso es todo");

Result:
Code:

Puertos disponibles:
Eso es todo

Be it as a normal user or as root. Is this api supported in linux (again, keep in mind I'll put it on ARM later on)?

I could just use one abstraction layer to handle javax.comm on windows and use the serial port device directly on linux but would like to skip it if possible.

Thanks in advance.

414N 08-25-2012 09:07 AM

Maybe you're lacking platform specific support (read: JNI libraries) for javax.comm on Linux.
If you look at this old page, it seems like you need to install rxtx first, then you should be able to use the javax.comm API flawlessly upon proper configuration.

eantoranz 08-25-2012 12:20 PM

Well, this is fairly interesting. I was able to list the serial ports available after working with rxtx on my box.

Now I want to be able to do the same thing on the beagleboard. I downloaded rxtx and compiled it there. Now see what happens when I try to run it:

Code:

$ java -cp bin:lib/comm.jar:/home/ubuntu/Downloads/rxtx-2.1-7r2/RXTXcomm.jar la.cps.comm.SimpleRead
java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver
Error al tratar de listar los dispositivos
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.<clinit>(CommPortIdentifier.java:83)
        at la.cps.comm.SimpleRead.main(SimpleRead.java:34)
Caught java.lang.NoClassDefFoundError: Could not initialize class gnu.io.RXTXCommDriver while loading driver gnu.io.RXTXCommDriver
port /dev/ttyUSB0 not found.
$ export LD_LIBRARY_PATH=/home/ubuntu/Downloads/rxtx-2.1-7r2/armv7l-unknown-linux-gnu/.libs/
$ java -cp bin:lib/comm.jar:/home/ubuntu/Downloads/rxtx-2.1-7r2/RXTXcomm.jar la.cps.comm.SimpleRead
java.lang.UnsatisfiedLinkError: gnu.io.RXTXCommDriver.nativeGetVersion()Ljava/lang/String; thrown while loading gnu.io.RXTXCommDriver
java.lang.NoClassDefFoundError: Could not initialize class gnu.io.RXTXCommDriver thrown while loading gnu.io.RXTXCommDriver
Lista de puertos disponibles
Eso es todo

Caught java.lang.NoClassDefFoundError: Could not initialize class gnu.io.RXTXCommDriver while loading driver gnu.io.RXTXCommDriver
port /dev/ttyUSB0 not found.

So I guess the problem has to deal with the so from rxtx. Any ideas how I should move ahead? Thanks in advance

eantoranz 08-25-2012 07:03 PM

Ok.... After a lot of fiddling I ended up being able to use rxtx on the beagleboard.
Had to hack it a little bit in order to build it (given that utsrelease.h has moved location or something).

Will try on the dreamplug on monday.

eantoranz 08-25-2012 07:05 PM

Oh... forgot to mention that I was able to make it work on rxtx-2.2 (prerelease)


All times are GMT -5. The time now is 07:10 PM.