public synchronized void serialEvent(SerialPortEvent p_event)
   {
      try
      {
         Thread.sleep(20);
      }
      catch (InterruptedException e)
      {
         e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
      }
      if (p_event.getEventType() == SerialPortEvent.DATA_AVAILABLE)
      {
         try
         {
            // Handle incoming data
            // if (data is available)
            int available = input.available();
            System.out.println("Bytes available: " + available);
            byte message[] = new byte[available];
            int portNum;

            // Read the data
            input.read(message, 0, available);

            ByteArrayInputStream bais = new ByteArrayInputStream(message);
            while (bais.available() > 0)
            {
               // read 1st byte
               int type = bais.read();
               switch (type)
               {
                  case CommsConstants.PWM:
                     portNum = bais.read();
                     int value = bais.read();
                     m_app.getDataManager().updatePWM(portNum, value);
                     break;
                  case CommsConstants.RELAY:
                     portNum = bais.read();
                     int valA = bais.read();
                     int valB = bais.read();
                     m_app.getDataManager().updateRelay(portNum, valA, valB);
                     System.out.println("Relay " + portNum + ": A = " + valA + " - B = " + valB);
                     break;
                  case CommsConstants.PWM_POWER:
                     portNum = bais.read();
                     int hasPower = bais.read();
                     // TODO: update data
                     break;
                  case CommsConstants.I2C:
                     int val = bais.read();
                     System.out.println("Current byte: " + val);
                     break;
                  default:
                     break;
               }
            }
         } catch (Exception e) {
            e.printStackTrace();
         }
      }
      // Ignore all the other eventTypes, but you should consider the other ones.
   }