Serial Reception of Bytes

Hello Forum,

Happy Holidays and Happy New Year.

I have a question regarding serial communication, specifically receiving bytes. See the snippet of code below.

byte rx_byte[6];

if(Serial1.available())

{

Serial1.readBytes(rx_byte,6);

}

Everytime I send a command from the host microcontroller(Arduino Mega 2560) to a touchscreen OR press a “soft” button on the touchscreen, the touchscreen sends and ACK or NACK back to the host microcontroller. In some cases, the touchscreen sends 5 bytes back, and in some cases the touchscreen sends 6 bytes back to the host microcontroller.

Will the above Serial1.readBytes(rx_byte,6); handle both 5 and 6 bytes? Isn’t there a serial timeout after which time the serial port will stop receiving a particular stream and then wait for the next stream? In other words, if the serial port receives 5 bytes and a 6th byte isn’t received, then won’t the serial port timeout and just take the 5 bytes?

TIA,

–Neal

try setting Serial.setTimeout()