Why do I get Java NoSuchPortException when a port exists?

Got the following production code below, I am using it for a new driver. portName is COM4, ​​and this port exists on the PC (and I can connect to it using a hyper terminal), so why does Javacomm use a NoSuchPortException? COM4 is displayed perfectly in the mgr device. also

    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;
    }
+3
source share
1 answer

, , CommPortIdentifier.getPortIdentifiers() . , jarfiles dll ? , COM4 CommPortIdentifier.addPortName(java.lang.String portName, int portType, CommDriver driver). null, .

+2

Source: https://habr.com/ru/post/1749686/


All Articles