serialPort.addEventListener(this);
serialPort.notifyOnDataAvailable(true);
serialPort.setSerialPortParams(BAUD, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
} catch (IOException e) {
throw new EHealthException(e);
} catch (PortInUseException e) {
throw new EHealthException(e);
} catch (UnsupportedCommOperationException e) {
throw new EHealthException(e);
} catch (TooManyListenersException e) {
throw new EHealthException(e);
}
} else {
StringBuilder sb = new StringBuilder();
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
CommPortIdentifier id = (CommPortIdentifier) portList.nextElement();
if (id.getPortType() == CommPortIdentifier.PORT_SERIAL) {
sb.append(id.getName() + "\n");
}
}
throw new EHealthException("Serial port '" + portName + "' could not be found. Available ports are:\n" + sb.toString());
}
}