Listing 1

public void serialEvent(SerialPortEvent event) {
  if (event.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
    byte[] readBuffer = new byte[inputStream.available];
    String message = "";
    try {
      while (inputStream.available() > 0) {
        int numBytes = inputStream.read(readBuffer);
      }
      message = new String(readBuffer);
      System.out.println("Received :" + message);
    } catch (IOException e) {
      e.printStackTrace();
    }
}