RXTX can't list port on ubuntu

烂漫一生 提交于 2019-12-11 07:04:35

问题


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.


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/15533310/rxtx-cant-list-port-on-ubuntu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!