列出Java中的所有串行端口

Ketan Sachan

我已经在Java中为Modbus硬件设备创建了一个应用程序。我可以在运行良好的Windows系统上安装我的应用程序。但是,当我尝试使用应用程序Linux操作系统时,我遇到了问题。此问题背后的原因是串行端口,因此我无法将我的应用程序与Windows操作系统以外的硬件连接。现在,我想查找串行端口列表(从操作系统角度而言)并将其添加到comport位置的JComboBox中(请参见下图)。我需要在Windows,Linux,MacOS上分发此应用程序。我可以通过我的代码检测到操作系统。我检查了很多资源,但是对我没有用。

需要一些帮助来检测系统的串行端口。

提前致谢。

连接建立页面

库玛·阿尼尔·乔拉斯亚

此代码可能会对您有所帮助。它将为您提供串行端口上已连接设备的列表。使用https://fazecast.github.io/jSerialComm/库运行此代码。

public class Test {
    public static void main(String[] args) {
        SerialPort[] ports = SerialPort.getCommPorts();
        List<String> list = new ArrayList<String>();
        for (SerialPort port : ports) {
            System.out.println(port.getSystemPortName());
            list.add(port.getSystemPortName());
        }
        System.out.println("List of serial port is : "+list);
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章