src/main/java/com/stijndepestel/geminio/captures/SerialPortCapture.java
/**
     * Start the capture on the serial port.
     *
     * @throws SerialPortException
     *             When something went wrong during the start of the capture.
     */
Start the capture on the serial port.
@throws SerialPortException
When something went wrong during the start of the capture.
Start the capture on the serial port . @throws SerialPortException When something went wrong during the start of the capture .
public void start() throws SerialPortException {
        final Capture<Byte[]> capture = new Capture<>(
                arr -> new JSONObject().put("bytearray",
                        DatatypeConverter.printBase64Binary(
                                SerialPortCapture.unboxByteArray(arr))),
                this.persister);
        final SerialPort serialPort = new SerialPort(this.serialPortName);
        serialPort.openPort();
        if (this.serialPortParamsInts.length == SerialPortCapture.SERIAL_PORT_INTEGER_PARAMS_LENGTH) {
            if (this.serialPortParamsBools.length == SerialPortCapture.SERIAL_PORT_BOOLEAN_PARAMS_LENGTH) {
                serialPort.setParams(this.serialPortParamsInts[0],
                        this.serialPortParamsInts[1],
                        this.serialPortParamsInts[2],
                        this.serialPortParamsInts[3],
                        this.serialPortParamsBools[0],
                        this.serialPortParamsBools[1]);
            } else {
                serialPort.setParams(this.serialPortParamsInts[0],
                        this.serialPortParamsInts[1],
                        this.serialPortParamsInts[2],
                        this.serialPortParamsInts[3]);
            }
        }
        serialPort.addEventListener(event -> {
            this.filter.ifPresent(f -> {
                if (!f.apply(event)) {
                    return;
                }
            });
            try {
                System.out.print("x");
                final int nrOfBytes = event.getEventValue();
                capture.capture(SerialPortCapture
                        .boxByteArray(serialPort.readBytes(nrOfBytes)));
            } catch (final SerialPortException e) {
                SerialPortCapture.LOGGER.error(
                        "Something went wrong while reading the serial port input.",
                        e);
            }
        });
        final Scanner scan = new Scanner(System.in);
        System.out.println("Starting capture. Press return to stop.");
        capture.startCapture();
        scan.nextLine();
        capture.stopCapture();
        capture.saveEvents();
        scan.close();
    }
public void start ( ) throws SerialPortException { final Capture < Byte [ ] > capture = new Capture < > ( arr -> new JSONObject ( ) . put ( "bytearray" , DatatypeConverter . printBase64Binary ( SerialPortCapture . unboxByteArray ( arr ) ) ) , this . persister ) ; final SerialPort serialPort = new SerialPort ( this . serialPortName ) ; serialPort . openPort ( ) ; if ( this . serialPortParamsInts . length == SerialPortCapture . SERIAL_PORT_INTEGER_PARAMS_LENGTH ) { if ( this . serialPortParamsBools . length == SerialPortCapture . SERIAL_PORT_BOOLEAN_PARAMS_LENGTH ) { serialPort . setParams ( this . serialPortParamsInts [ 0 ] , this . serialPortParamsInts [ 1 ] , this . serialPortParamsInts [ 2 ] , this . serialPortParamsInts [ 3 ] , this . serialPortParamsBools [ 0 ] , this . serialPortParamsBools [ 1 ] ) ; } else { serialPort . setParams ( this . serialPortParamsInts [ 0 ] , this . serialPortParamsInts [ 1 ] , this . serialPortParamsInts [ 2 ] , this . serialPortParamsInts [ 3 ] ) ; } } serialPort . addEventListener ( event -> { this . filter . ifPresent ( f -> { if ( ! f . apply ( event ) ) { return ; } } ) ; try { System . out . print ( "x" ) ; final int nrOfBytes = event . getEventValue ( ) ; capture . capture ( SerialPortCapture . boxByteArray ( serialPort . readBytes ( nrOfBytes ) ) ) ; } catch ( final SerialPortException e ) { SerialPortCapture . LOGGER . error ( "Something went wrong while reading the serial port input." , e ) ; } } ) ; final Scanner scan = new Scanner ( System . in ) ; System . out . println ( "Starting capture. Press return to stop." ) ; capture . startCapture ( ) ; scan . nextLine ( ) ; capture . stopCapture ( ) ; capture . saveEvents ( ) ; scan . close ( ) ; }
Start the capture on the serial port.
Start the capture on the serial port .
// Create capture object. // CCreate serial port // Set parameters as necessary. // Set event listener // wait for return // stop capture