java CommPortIdentifier.getPortIdentifiers 为空
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15955530/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CommPortIdentifier.getPortIdentifiers is empty
提问by Saher Ahwal
I am building a simple application that communicates through Serial Port using the Java Communication API javax.comm.
我正在构建一个简单的应用程序,它使用 Java 通信 API javax.comm 通过串行端口进行通信。
Here is some code in my java main method I wrote:
这是我编写的 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());
}
Enumeration e is always empty even though I am connected to a COM 4 port when running this.
即使我在运行时连接到 COM 4 端口,枚举 e 始终为空。
also, running this code:
此外,运行此代码:
portRead = CommPortIdentifier.getPortIdentifier("COM8");
cause the throw of NoSuchPortException
导致抛出 NoSuchPortException
I think I have done the installation part correctly and placed the properties file, the win32com.dll file in the right places.
我想我已经正确地完成了安装部分并将属性文件 win32com.dll 文件放在了正确的位置。
Do you know what the problem could be?
你知道可能是什么问题吗?
Thank You
谢谢
采纳答案by Outlier
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.
确保 win32com.dll(与 javax.com 一起提供)在 jre\bin 目录中。确保 javax.comm.properties(与 javax.com 一起提供)在 jdk\lib 目录中。
回答by user3311900
Remember always you need to add all the unzipped files from javax.comm.zip to jre
请始终记住,您需要将 javax.comm.zip 中的所有解压缩文件添加到jre
win32com.dll - jre/bin
win32com.dll - jre/bin
comm.jar - jre/lib/ext
comm.jar - jre/lib/ext
java.comm.properties - jre/lib(after adding this I found resolved exception problem )
java.comm.properties - jre/lib(添加这个后我发现解决了异常问题)
回答by Algerowalid
This works for me (I installed x86 jdk ) and followed the steps
这对我有用(我安装了 x86 jdk )并按照步骤操作
Your problem is that windows could'nt communicate the right PORT to your JAVA Program.
您的问题是 Windows 无法将正确的端口传送到您的 JAVA 程序。
You have to copy the right files in the right location by following this link.
您必须按照此链接将正确的文件复制到正确的位置。
http://kishor15389.blogspot.com/2011/05/how-to-install-java-communications.html
http://kishor15389.blogspot.com/2011/05/how-to-install-java-communications.html