我只是运行一些代码以获取我的cmputer的可用端口列表,当我有3个免费端口时,它将我返回我的false。如何解决这个问题?

我的代码:

public static void main(String[] args) {
        //SerialParameters params=new SerialParameters();
       // System.out.println(CommPortIdentifier.PORT_SERIAL );
        Enumeration portList = CommPortIdentifier.getPortIdentifiers();
        System.out.println(portList.hasMoreElements());
        while(portList.hasMoreElements()){
            System.out.println("Has more elements");
             CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
               if (portId.getPortType() == CommPortIdentifier.PORT_PARALLEL) {
                    System.out.println(portId.getName());
               }
               else{
                     System.out.println(portId.getName());
               }

        }
}

输出:false

有帮助吗?

解决方案

看起来您的Javax.comm API的设置可能不正确。确保您完成了以下操作:

  1. 放置 comm.jar 文件中的文件 jre/lib/ext 目录。
  2. 放置 javax.comm.properties 文件中的文件 jre/lib 目录。
  3. 放置 win32com.dll 在里面 jre/bin 目录。

上述每个组件都应可用 这里.

其他提示

我正在使用Ubuntu,我的计算机没有任何串行/帕拉雷尔端口。

在这种情况下,您需要模拟此端口。

我的答案:

在Ubuntu上使用Java的串行端口标识

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top