protected int readAsciiByte() throws IOException {
  if (commPort != null && commPort.isOpen()) {
    byte[] buffer=new byte[1];
    int cnt=commPort.readBytes(buffer,1);
    if (cnt != 1) {
      throw new IOException("Cannot read from serial port");
    }
 else     if (buffer[0] == ':') {
      return ModbusASCIITransport.FRAME_START;
    }
 else     if (buffer[0] == '\r' || buffer[0] == '\n') {
      return ModbusASCIITransport.FRAME_END;
    }
 else {
      logger.debug("Read From buffer: " + buffer[0] + " ("+ String.format("%02X",buffer[0])+ ")");
      byte firstValue=buffer[0];
      cnt=commPort.readBytes(buffer,1);
      if (cnt != 1) {
        throw new IOException("Cannot read from serial port");
      }
 else {
        logger.debug("Read From buffer: " + buffer[0] + " ("+ String.format("%02X",buffer[0])+ ")");
        int combinedValue=(Character.digit(firstValue,16) << 4) + Character.digit(buffer[0],16);
        logger.debug("Returning combined value of: " + String.format("%02X",combinedValue));
        return combinedValue;
      }
    }
  }
 else {
    throw new IOException("Comm port is not valid or not open");
  }
}

protected int readAsciiByte ( ) throws IOException { if ( commPort != null && commPort . isOpen ( ) ) { byte [ ] buffer = new byte [ 1 ] ; int cnt = commPort . readBytes ( buffer , 1 ) ; if ( cnt != 1 ) { throw new IOException ( "Cannot read from serial port" ) ; } else if ( buffer [ 0 ] == ':' ) { return ModbusASCIITransport . FRAME_START ; } else if ( buffer [ 0 ] == '\r' || buffer [ 0 ] == '\n' ) { return ModbusASCIITransport . FRAME_END ; } else { logger . debug ( "Read From buffer: " + buffer [ 0 ] + " (" + String . format ( "%02X" , buffer [ 0 ] ) + ")" ) ; byte firstValue = buffer [ 0 ] ; cnt = commPort . readBytes ( buffer , 1 ) ; if ( cnt != 1 ) { throw new IOException ( "Cannot read from serial port" ) ; } else { logger . debug ( "Read From buffer: " + buffer [ 0 ] + " (" + String . format ( "%02X" , buffer [ 0 ] ) + ")" ) ; int combinedValue = ( Character . digit ( firstValue , 16 ) << 4 ) + Character . digit ( buffer [ 0 ] , 16 ) ; logger . debug ( "Returning combined value of: " + String . format ( "%02X" , combinedValue ) ) ; return combinedValue ; } } } else { throw new IOException ( "Comm port is not valid or not open" ) ; } }
reads an ascii byte from the input stream it handles the special start and end frame markers
