CommPortIdentifier.getPortIdentifiers为空 [英] CommPortIdentifier.getPortIdentifiers is empty

查看:1468
本文介绍了CommPortIdentifier.getPortIdentifiers为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个使用Java Communication API javax.comm通过串行端口进行通信的简单应用程序。



以下是我编写的java main方法中的一些代码:

  CommPortIdentifier cpi = null; 
枚举e = CommPortIdentifier.getPortIdentifiers();
while(e.hasMoreElements()){
try {
cpi =(CommPortIdentifier)e.nextElement();
} catch(NoSuchElementException n){

}
System.out.println(cpi.getName());
}

即使我连接到COM 4端口,枚举e也始终为空运行此。



此外,运行此代码:

  portRead = CommPortIdentifier.getPortIdentifier( COM8); 

导致抛出 NoSuchPortException



我想我已经正确完成了安装部分并将属性文件win32com.dll放在了正确的位置。



<你知道问题是什么吗?



谢谢你

解决方案

确保win32com.dll(javax.com附带)位于jre\bin目录中。
确保javax.comm.properties(javax.com附带)位于jdk \lib目录中。


I am building a simple application that communicates through Serial Port using the Java Communication API javax.comm.

Here is some code in my java main method I wrote:

CommPortIdentifier cpi = null;
        Enumeration e = CommPortIdentifier.getPortIdentifiers();
        while (e.hasMoreElements()) {
            try {
                cpi = (CommPortIdentifier) e.nextElement();
            } catch (NoSuchElementException n) {

            }
            System.out.println(cpi.getName());
        }

Enumeration e is always empty even though I am connected to a COM 4 port when running this.

also, running this code:

portRead = CommPortIdentifier.getPortIdentifier("COM8");

cause the throw of NoSuchPortException

I think I have done the installation part correctly and placed the properties file, the win32com.dll file in the right places.

Do you know what the problem could be?

Thank You

解决方案

Make sure that win32com.dll (comes with javax.com) is in the jre\bin directory. Make sure javax.comm.properties (comes with javax.com) is in the jdk\lib directory.

这篇关于CommPortIdentifier.getPortIdentifiers为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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