@Override
    protected boolean doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception {
        this.remoteAddress = remoteAddress;
        if (!(remoteAddress instanceof SerialSocketAddress)) {
            throw new IllegalArgumentException("Socket Address has to be of type " + SerialSocketAddress.class);
        }
        logger.debug("Connecting to Socket Address '{}'", ((SerialSocketAddress) remoteAddress).getIdentifier());

        try {
            // A bit hacky but to support testing check for custom handler
            final Optional<SerialChannelHandler> customHandler = ((SerialSocketAddress) remoteAddress).getHandler();
            comPort = customHandler.orElseGet(() -> new SerialChannelHandler.SerialPortHandler(remoteAddress, config));
            logger.debug("Using Com Port {}, trying to open port", comPort.getIdentifier());
            if (comPort.open()) {
                logger.debug("Opened port successful to {}", comPort.getIdentifier());
                comPort.registerSelectionKey(serialSelectionKey);

                this.active = true;
                return true;
            } else {
                logger.debug("Unable to open port {}", comPort.getIdentifier());
                return false;
            }
        } catch (Exception e) {
            logger.warn("exception caught", e);
            this.active = false;
            return false;
        }
    }
Create a new instance

@param parent the parent {@link Channel} by which this instance was created. May be {@code null}
@param ch     the underlying {@link SelectableChannel} on which it operates
plc4j/transports/serial/src/main/java/org/apache/plc4x/java/transport/serial/SerialChannel.java