private Boolean testProtocolCommunication() {
        SynchronousMessageListener<ProtocolVersionMessage> versionListener =
                new SynchronousMessageListener<>(ProtocolVersionMessage.class);

        addMessageListener(versionListener);

        try {
            serialPort.getOutputStream().write(new ProtocolVersionQueryMessage().toByteArray());
        } catch (IOException e) {
            log.error("Unable to test protocol communications. Serial port error.");
            removeMessageListener(versionListener);
            return false;
        }

        ProtocolVersionMessage message = null;
        if (versionListener.waitForResponse()) {
            message = versionListener.getResponseMessage();
        }

        removeMessageListener(versionListener);

        if (message != null) {
            log.info("Detected Firmata device protocol version: {}.{}",
                    message.getMajorVersion(), message.getMinorVersion());
            if (message.getMajorVersion() < MIN_SUPPORTED_VERSION_MAJOR ||
                    (message.getMinorVersion() < MIN_SUPPORTED_VERSION_MINOR &&
                            message.getMajorVersion() >= MIN_SUPPORTED_VERSION_MAJOR)) {
                log.warn("Firmata device protocol version is too old for this library." +
                                " Some functionality may not work. Library min supported version: {}.{}",
                        MIN_SUPPORTED_VERSION_MAJOR, MIN_SUPPORTED_VERSION_MINOR);
            }
            return true;
        }

        return false;
    }
private Boolean testProtocolCommunication ( ) { SynchronousMessageListener < ProtocolVersionMessage > versionListener = new SynchronousMessageListener < > ( ProtocolVersionMessage . class ) ; addMessageListener ( versionListener ) ; try { serialPort . getOutputStream ( ) . write ( new ProtocolVersionQueryMessage ( ) . toByteArray ( ) ) ; } catch ( IOException e ) { log . error ( "Unable to test protocol communications. Serial port error." ) ; removeMessageListener ( versionListener ) ; return false ; } ProtocolVersionMessage message = null ; if ( versionListener . waitForResponse ( ) ) { message = versionListener . getResponseMessage ( ) ; } removeMessageListener ( versionListener ) ; if ( message != null ) { log . info ( "Detected Firmata device protocol version: {}.{}" , message . getMajorVersion ( ) , message . getMinorVersion ( ) ) ; if ( message . getMajorVersion ( ) < MIN_SUPPORTED_VERSION_MAJOR || ( message . getMinorVersion ( ) < MIN_SUPPORTED_VERSION_MINOR && message . getMajorVersion ( ) >= MIN_SUPPORTED_VERSION_MAJOR ) ) { log . warn ( "Firmata device protocol version is too old for this library." + " Some functionality may not work. Library min supported version: {}.{}" , MIN_SUPPORTED_VERSION_MAJOR , MIN_SUPPORTED_VERSION_MINOR ) ; } return true ; } return false ; }
Test if Firmata Protocol communication is possible over the serial port. Done by sending a ProtocolVersion
request to the device. If the device supports Firmata, it should reply with a ProtocolVersionMessage.
Listen for this message while sending the request, and if it is not received within 5 seconds, consider
the device unsupported.

@return true if communications were successful. False if there was a timeout or the data could not be
interpreted within 5 seconds.