代码之家  ›  专栏  ›  技术社区  ›  fred basset

当端口存在时,为什么我会得到一个JavaNoSuchPortException?

  •  3
  • fred basset  · 技术社区  · 14 年前

        final String portName = getSerialPort();
        try {
            final CommPortIdentifier id = CommPortIdentifier.getPortIdentifier(portName);
            port = (SerialPort) id.open(getName(), 1000);
        } catch (NoSuchPortException nspe) {
            report(SeverityCode.LEVEL2, getName(), "PIN Pad is not connected to " + portName + " port, or the port does not exist.");
            return;
        } catch (PortInUseException piue) {
            report(SeverityCode.LEVEL2, getName(), portName + " port is already in-use by some other device. Reason: " + piue.getMessage());
            return;
        }
    
    1 回复  |  直到 14 年前
        1
  •  2
  •   itisravi    14 年前

    尝试使用枚举系统上可用的端口列表 CommPortIdentifier.getPortIdentifiers() 并打印所列内容。是否确定已将jar文件和dll安装在正确的文件夹中?如果是,则尝试使用添加COM4 CommPortIdentifier.addPortName(java.lang.String portName, int portType, CommDriver driver)