How to get list of available serial ports in my pc using Java?(如何使用 Java 获取我的电脑中可用串行端口的列表?)
问题描述
我只是运行一些代码来获取我的计算机上的可用端口列表,当我有 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.
上述每个组件都应该"在这里.
Each of the above components "should" be available here.
这篇关于如何使用 Java 获取我的电脑中可用串行端口的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 Java 获取我的电脑中可用串行端口的列表?


- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01