RXTX 无法在 ubuntu 上列出端口 [英] RXTX can't list port on ubuntu

查看:74
本文介绍了RXTX 无法在 ubuntu 上列出端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行简单的代码:

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();
}
}

它应该列出我系统中可用的 COM 端口.我正在尝试3.2.0-39-generic #62-Ubuntu x86_64 x86_64 x86_64 GNU/Linux和 Java 1.6

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

首先,我从 apt-get 存储库安装了 RXTX,但在遇到一些麻烦之后,我从源代码安装了它,但它仍然无法正常工作.我在所有 ttyS* 上都设置了 chmod 777,以确保这在权限方面没有问题.
我尝试了这个,但无济于事.

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.

推荐答案

您的类路径中也需要有 .so 文件.

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

您可以从 http://rxtx.qbang 下载预构建的二进制文件.org/wiki/index.php/Download 不幸的是,它们仅提供 32 位版本.

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

如果您使用 Eclipse,您可以将 .so 文件放在项目的根目录中,它应该可以工作.如果这不起作用,您可以尝试设置 java.library.path VM 参数.如何设置 java.library 中提供了相关说明.来自 Eclipse 的路径

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

这篇关于RXTX 无法在 ubuntu 上列出端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆