Are you using SoftwareSerial, and it's read() is blocking you, or are you using hardware serial, and attempting to read a specified length of data via a while loop?
If the latter, you can do something like this:
// clear out any previous command data
memset(input_serial_buffer, 0, sizeof(char) * SER_COM_BUFFER_LEN);
serial_time = millis();
// populate command data buffer
for( int i = 1; i <= com_byte_count; i++ ) {
// get com_byte_count character values from the serial
// buffer
// wait until we have data ready
while( ! Serial.available() ) {
if( millis() - serial_time > SERIAL_TIMEOUT ) {
// timed out waiting for complete input
// send 'fail' response
serial_write((byte)0);
serial_write((byte)0);
return( 0 );
}
}
input_serial_buffer[i - 1] = (byte) Serial.read();
}