public ArrayList<byte[]> readFromReceiver(Context context,int size){
  ArrayList<byte[]> bufferedMessages=null;
  byte[] readFromDevice=new byte[1024];
  int read=0;
  if (size >= 0) {
    log.debug("readFromReceiver!! a leer " + size + " bytes!!");
    try {
      read=mSerialDevice.read(readFromDevice);
    }
 catch (    Exception e) {
      Log.e(TAG,"Unable to read from serial device",e);
      log.error("Unable to read from serial device",e);
      return null;
    }
  }
  if (read > 0) {
    Log.d("medtronic","READ " + read);
    log.debug("Stream Received; bytes read: " + read);
  }
 else   log.debug("NOTHING TO READ");
  if (read > 0) {
    SharedPreferences.Editor editor=settings.edit();
    editor.putLong("lastDestroy",System.currentTimeMillis());
    editor.commit();
    try {
      bufferedMessages=parseMessageData(Arrays.copyOfRange(readFromDevice,0,read),read);
      checkCalibrationOutOfTime();
    }
 catch (    Exception e) {
      StringBuffer sb1=new StringBuffer("");
      sb1.append("EXCEPTION!!!!!! " + e.getMessage() + " "+ e.getCause());
      for (      StackTraceElement st : e.getStackTrace()) {
        sb1.append(st.toString());
      }
      sendMessageToUI(sb1.toString(),false);
      bufferedMessages=new ArrayList<byte[]>();
    }
  }
  return bufferedMessages;
}

public ArrayList < byte [ ] > readFromReceiver ( Context context , int size ) { ArrayList < byte [ ] > bufferedMessages = null ; byte [ ] readFromDevice = new byte [ 1024 ] ; int read = 0 ; if ( size >= 0 ) { log . debug ( "readFromReceiver!! a leer " + size + " bytes!!" ) ; try { read = mSerialDevice . read ( readFromDevice ) ; } catch ( Exception e ) { Log . e ( TAG , "Unable to read from serial device" , e ) ; log . error ( "Unable to read from serial device" , e ) ; return null ; } } if ( read > 0 ) { Log . d ( "medtronic" , "READ " + read ) ; log . debug ( "Stream Received; bytes read: " + read ) ; } else log . debug ( "NOTHING TO READ" ) ; if ( read > 0 ) { SharedPreferences . Editor editor = settings . edit ( ) ; editor . putLong ( "lastDestroy" , System . currentTimeMillis ( ) ) ; editor . commit ( ) ; try { bufferedMessages = parseMessageData ( Arrays . copyOfRange ( readFromDevice , 0 , read ) , read ) ; checkCalibrationOutOfTime ( ) ; } catch ( Exception e ) { StringBuffer sb1 = new StringBuffer ( "" ) ; sb1 . append ( "EXCEPTION!!!!!! " + e . getMessage ( ) + " " + e . getCause ( ) ) ; for ( StackTraceElement st : e . getStackTrace ( ) ) { sb1 . append ( st . toString ( ) ) ; } sendMessageToUI ( sb1 . toString ( ) , false ) ; bufferedMessages = new ArrayList < byte [ ] > ( ) ; } } return bufferedMessages ; }
this method reads from the serial device , and process the answer
