Java 端口未列出

Java 端口未列出,java,linux,rxtx,Java,Linux,Rxtx,我想在linux中使用USB GSM调制解调器进行串行通信。我使用了以下代码。但是portList.hashElements返回为false。我使用了RXTX librarry 2.1.7版本。请帮帮我 代码 import java.io.*; import java.util.*; import gnu.io.*; public class SimpleWrite { static Enumeration portList; static CommPortIdentifier portId

我想在linux中使用USB GSM调制解调器进行串行通信。我使用了以下代码。但是portList.hashElements返回为false。我使用了RXTX librarry 2.1.7版本。请帮帮我

代码

import java.io.*;
import java.util.*;
import gnu.io.*;

public class SimpleWrite {

static Enumeration portList;
static CommPortIdentifier portId;
static String messageString = "Hello, world!\n";
static SerialPort serialPort;
static OutputStream outputStream;
private static SerialPort p;

public static void main(String[] args) throws NoSuchPortException {


    Enumeration ports = CommPortIdentifier.getPortIdentifiers();
    System.out.println("start: "+ ports.hasMoreElements());
    while(ports.hasMoreElements())
    {
        CommPortIdentifier port = (CommPortIdentifier) ports.nextElement();
        System.out.print(port.getName() + " -> " + port.getCurrentOwner() + " -> ");
        switch(port.getPortType())
        {
            case CommPortIdentifier.PORT_PARALLEL:
                System.out.println("parell");
            break;
            case CommPortIdentifier.PORT_SERIAL:
                System.out.println("serial");
            try {
                p = (SerialPort) port.open("SimpleWrite", 1000);
                int baudRate = 57600; // 57600bps
                p.setSerialPortParams(
                        baudRate,
                        SerialPort.DATABITS_8,
                        SerialPort.STOPBITS_1,
                        SerialPort.PARITY_NONE);
            } catch (PortInUseException e) {
                System.out.println(e.getMessage());
            } catch (UnsupportedCommOperationException e) {
                System.out.println(e.getMessage());
            }
            break;
        }
    }
    System.out.println("stop");
}
}
输出为:

稳定库 本机库版本=RXTX-2.1-7 Java库版本=RXTX-2.1-7 开始:false 停止 实验性:调用JNI_OnLoad


System.out.println(“开始:+ports.hasMoreElements());正在打印为“假”。请帮帮我。谢谢

注意设备命名,因为linux不识别任何命名模式

也许我的回答可以帮助你:


在Ubuntu 14.04下,我遇到了类似的错误。端口未列出。
通过以root用户身份运行程序找到了解决方法。

看起来像用于LTP和COM端口的RXTX库,而不是用于USB。