Beispiel #1
0
  public boolean openPort(String portName) throws SerialPortException {

    serialPort = new SerialPort(portName);
    if (!serialPort.openPort()) {
      return false;
    }

    if (!serialPort.setParams(
        SerialPort.BAUDRATE_9600,
        SerialPort.DATABITS_8,
        SerialPort.STOPBITS_1,
        SerialPort.PARITY_NONE)) {
      return false;
    }

    serialPort.addEventListener(this::onSerialPortEvent, SerialPort.MASK_RXCHAR);

    return true;
  }