* If an error occurred when reading from the input stream
* @throws SerialPortException
* If timeout expires before connecting
*/
public synchronized byte[] readBytes() throws SerialPortTimeoutException, SerialPortException {
SerialPort sp = new SerialPort(serialPort);
byte[] buffer = null;
try {
sp.openPort();
sp.setParams(baud, dataBits, stopBits, parity);
sp.purgePort(SerialPort.PURGE_RXCLEAR);
sp.purgePort(SerialPort.PURGE_TXCLEAR);
buffer = sp.readBytes(byteCount, timeout);
log.info("Byte Count: " + byteCount);
log.info("Value: " + new String(buffer));
} catch (SerialPortTimeoutException e) {
throw e;
} catch (SerialPortException e) {
throw e;
} finally {
if (sp.isOpened())
sp.closePort();
}
return buffer;
}