質問

I'm trying to run simple code:

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import gnu.io.CommPortIdentifier; 
import gnu.io.SerialPort;
import gnu.io.SerialPortEvent; 
import gnu.io.SerialPortEventListener; 
import java.util.Enumeration;


public class SerialTest implements SerialPortEventListener {
SerialPort serialPort;
private BufferedReader input;
private OutputStream output;
private static final int TIME_OUT = 2000;
private static final int DATA_RATE = 9600;

public void initialize() {
CommPortIdentifier portId = null;
Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();
while (portEnum.hasMoreElements()) {
CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
System.out.println( "a " + currPortId.getName());
}
}

public synchronized void close() {
//...
}

public synchronized void serialEvent(SerialPortEvent oEvent) {
// ...
}

public static void main(String[] args) throws Exception {
SerialTest main = new SerialTest();
main.initialize();
}
}

and it should list available COM port in my system. I'm working on 3.2.0-39-generic #62-Ubuntu x86_64 x86_64 x86_64 GNU/Linux and Java 1.6

First I have RXTX install from apt-get repository but after some trouble I install it from source and it still don't work. I make chmod 777 on all ttyS* to be sure that this in not problem with permissions.
I try this and wouldn't help.

役に立ちましたか?

解決

You need to have the .so file on your class-path as well.

You can download the pre-built binaries from http://rxtx.qbang.org/wiki/index.php/Download unfortunately they are only available in 32-bit.

If your using Eclipse you can just drop the .so files in the root of your project and it should work. If that doesn't work you could try setting the java.library.path VM argument. Instructions for that are available at How to set the java.library.path from Eclipse

他のヒント

I've found the 64 bits version of the librxtxSerial.so library. I've tested it and it works.

Donwload this file and copy it to the /usr/lib folder

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top