简体   繁体   English

Java:与未列为 COM 端口的 USB 端口进行串行通信

[英]Java: Serial Communication with USB port that is not listed as COM-port

I am trying to establish a serial communication with a USB driven hardware.我正在尝试与 USB 驱动的硬件建立串行通信。 Unfortunately, the hardware is not recognized in the device manager under the listed COM ports.不幸的是,硬件在列出的 COM 端口下的设备管理器中无法识别。 Therefore, it does not appear in my list and I don't know its COM port number.因此,它没有出现在我的列表中,我也不知道它的 COM 端口号。 Instead the device is listed as another type of hardware.相反,该设备被列为另一种类型的硬件。

How can I still connect with it?我怎样才能与它保持联系?

I am currently using the following code to open my USB ports.我目前正在使用以下代码打开我的 USB 端口。

    public ArrayList<String> getPorts() {
CommPortIdentifier serialPortId;
ArrayList<String> portID = new ArrayList<String>();
Enumeration enumComm = CommPortIdentifier.getPortIdentifiers();
while (enumComm.hasMoreElements()) {
    serialPortId = (CommPortIdentifier) enumComm.nextElement();
    if (serialPortId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
        String portString= new String(serialPortId.getName());
        portID.add(portString);
    }
}
return portID;
   }

How can I still connect with it?我怎样才能与它保持联系?

You need a java binding to whatever driver the hardware actually uses, like LibUSB or hidapi.您需要将 java 绑定到硬件实际使用的任何驱动程序,例如 LibUSB 或 hidapi。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM