本文介绍了如何使用Java获取PC中可用串口的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是运行一些代码来获取cmputer中可用端口的列表,当我有3个可用的com端口时,它返回false.我该如何解决这个问题?
I just run some codes to get a list of available ports n my cmputer and it returned me false when I have 3 com ports that are free. How do I solve this prob?
我的代码:
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());
}
}
}
输出:错误
推荐答案
看来您对javax.comm API的设置可能不正确.确保您已完成以下操作:
It appears your setup of the javax.comm API may not be correct. Make sure you have done the following:
- 将
comm.jar
文件放置在jre/lib/ext
目录中. - 将
javax.comm.properties
文件放置在jre/lib
目录中. - 将
win32com.dll
放在jre/bin
目录中.
- Placed the
comm.jar
file in thejre/lib/ext
directory. - Placed the
javax.comm.properties
file in thejre/lib
directory. - Placed the
win32com.dll
in thejre/bin
directory.
在此处.
这篇关于如何使用Java获取PC中可用串口的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!