How to read a string through the serial port

Hi, it seems to be an easy problem but i didn t found anything, i know how to read the first byte on the buffer with serial.read()
but i should i read the other byte if my pc send to my arduino a 256 char buffer?
thanks a lot

If your PC sends 256 characters to your Arduino, better make sure you read them out as quickly as possible, because the serial input buffer is only 128 characters long.
There are plenty of examples around, post your code and people will help, but don't expect them to write it for you.

I don't think the buffer size is 128 bytes but that's not the point. The point is there is a buffer of some size so read the bytes out before the buffer is completely full and starts dropping incoming bytes.

https://github.com/arduino/Arduino/blob/master/hardware/arduino/cores/arduino/HardwareSerial.cpp

mkwired:
I don't think the buffer size is 128 bytes but that's not the point.

Extract from arduino-022 HardwareSerial.cpp:

#if (RAMEND < 1000)
  #define RX_BUFFER_SIZE 32
#else
  #define RX_BUFFER_SIZE 128
#endif

PeterH:

mkwired:
I don't think the buffer size is 128 bytes but that's not the point.

Extract from arduino-022 HardwareSerial.cpp:

#if (RAMEND < 1000)

#define RX_BUFFER_SIZE 32
#else
  #define RX_BUFFER_SIZE 128
#endif

Giving that we don't know which chip and/or which version of the Arduino codebase he is using, we cannot know how "big" the buffer is. Sidenote: I didn't realize these numbers changed between versions.

victorjung:
Hi, it seems to be an easy problem but i didn t found anything, i know how to read the first byte on the buffer with serial.read()
but i should i read the other byte if my pc send to my arduino a 256 char buffer?
thanks a lot

Every time you Serial.read() a character, it is removed from the buffer which is a FIFO (first in, first out) stack. So your next read will get the next character, etc, until the buffer is empty.

If you don't want to remove the character from the buffer then use Serial.peek().