2013-03-20 78 views
1

端口我試圖運行簡單的代碼:RXTX不能列出在Ubuntu

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泛型#62,Ubuntu的x86_64的x86_64的x86_64的GNU/Linux的 和Java 1.6

首先我RXTX從apt-get的庫安裝但經過一些麻煩我從源代碼安裝它仍然不起作用。我在所有ttyS *上製作chmod 777,以確保這在權限方面沒有問題。
我嘗試this,並沒有幫助。

回答

1

你也需要在你的類路徑上有.so文件。

您可以從http://rxtx.qbang.org/wiki/index.php/Download下載預構建的二進制文件,但不幸的是,它們僅適用於32位版本。

如果您使用Eclipse,只需將.so文件放在項目的根目錄下即可。如果這不起作用,您可以嘗試設置java.library.path VM參數。有關這方面的說明,請參見How to set the java.library.path from Eclipse

+0

http://rxtx.qbang.org/wiki/index.php/Download -link失敗:(請上傳新的鏈接 – 2014-08-26 11:11:46

+0

我使用的是電腦的Xubuntu 14.04 - 64位 我下載了rxtx-2.1.-7-bins-r2.zip然後解壓縮 然後,我將librxtxSerial.so放在x86和64位的目錄中,並將它複製到jar目錄正在嘗試使用RXTX。 儘管如此,我仍然得到了java-library-path問題。 – javixanxez 2016-05-12 12:11:51

1

我發現了librxtxSerial.so library的64位版本。我測試過它,它工作。

Donwload這個文件,並將其複製到/usr/lib folder