CommPortIdentifier.getPortIdentifiers为空

时间:2013-04-11 17:51:49

标签: java serial-port javax.comm

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

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

CommPortIdentifier cpi = null;
        Enumeration 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文件放在正确的位置。

你知道问题是什么吗?

谢谢

4 个答案:

答案 0 :(得分:6)

请记住,您需要将javax.comm.zip中的所有解压缩文件添加到 jre

win32com.dll - jre / bin

comm.jar - jre / lib / ext

java.comm.properties - jre / lib (添加此项后我发现已解决的异常问题)

答案 1 :(得分:3)

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

答案 2 :(得分:1)

这适用于我(我安装了x86 jdk)并按照步骤

您的问题是Windows无法将正确的PORT通知您的JAVA计划。

您必须通过以下链接将正确的文件复制到正确的位置。

http://kishor15389.blogspot.com/2011/05/how-to-install-java-communications.html

答案 3 :(得分:-1)

查找设备正在运行的端口(尝试使用电源shell或超级终端查找所有COM端口,请尝试link

相关问题