int readBlockAndVerify(int pNumberOfBytes, byte pPktID)
{

    int totalNumBytes = pNumberOfBytes + 1; //account for the checksum
    
    int bytesRead;

    try{
        bytesRead = byteIn.read(inBuffer, 0, totalNumBytes);
    }
    catch(IOException e){
        logSevere(e.getMessage() + " - Error: 424");
        return(-1);
    }

    if (bytesRead == totalNumBytes){

        byte sum = 0;
        for(int i = 0; i < totalNumBytes; i++) {sum += inBuffer[i];}

        //calculate checksum to check validity of the packet
        if ( (pPktID + sum & (byte)0xff) != 0) {return(-1);}
    }
    else{
        //error -- not enough bytes could be read
        return(-1);
    }

    return(bytesRead);

}//end of Remote::readBlockAndVerify