protected void flushSerialBuffer() throws RunnerException, SerialException { // Cleanup the serial buffer try { Serial serialPort = new Serial(); byte[] readBuffer; while (serialPort.available() > 0) { readBuffer = serialPort.readBytes(); try { Thread.sleep(100); } catch (InterruptedException e) { } } serialPort.setDTR(false); serialPort.setRTS(false); try { Thread.sleep(100); } catch (InterruptedException e) { } serialPort.setDTR(true); serialPort.setRTS(true); serialPort.dispose(); } catch (SerialNotFoundException e) { throw e; } catch (Exception e) { e.printStackTrace(); throw new RunnerException(e.getMessage()); } }