private void createSerialPort ( ) { Constructor < ? extends SerialPort > constructor ; try { constructor = configuration . getSerialPortAdapterClass ( ) . getDeclaredConstructor ( String . class , Integer . class , SerialPortDataBits . class , SerialPortStopBits . class , SerialPortParity . class ) ; } catch ( NoSuchMethodException e ) { log . error ( "Unable to construct SerialPort object. Programming error. Your class adapter must support " + "a constructor with input args of" + "YourSerialPort(String.class, Integer.class, SerialPortDataBits.class, " + "SerialPortStopBits.class, SerialPortParity.class);" ) ; e . printStackTrace ( ) ; throw new RuntimeException ( "Cannot construct SerialPort adapter!" ) ; } try { serialPort = constructor . newInstance ( configuration . getSerialPortID ( ) , configuration . getSerialPortBaudRate ( ) , configuration . getSerialPortDataBits ( ) , configuration . getSerialPortStopBits ( ) , configuration . getSerialPortParity ( ) ) ; } catch ( InstantiationException | IllegalAccessException | InvocationTargetException e ) { log . error ( "Unable to construct SerialPort object. Programming error. Instantiation error. {}" , e . getMessage ( ) ) ; e . printStackTrace ( ) ; throw new RuntimeException ( "Cannot construct SerialPort adapter!" ) ; } }
Generate the SerialPort object using the SerialPort adapter class provided in the FirmataConfiguration If there is any issue constructing this object toss a RuntimeException as this is a developer error in implementing the SerialPort adapter for this library .