read a char tab[] coming from a pc through the serial port.

Hi, i know that's something really mainstream, but i didn't found anything working as i would like. I want to send a buffer[] of char from my pc to my board and also receive it as a char tab. i need to store every BYTE sended not only the first one! HOw can i do that, i m desperate! thanks a lot

I want to send a buffer of char from my pc to my board

You can do that.

also receive it as a char tab.

Now, that doesn’t make sense. Did you mean a char array? If so, you can do that.

HOw can i do that, i m desperate!

The first thing to do is determine how many characters we are talking about. If you are sending 80 characters, that’s one thing. If you are sending 8000 characters, that’s a different story.

The second thing to do is to define how the Arduino is to know when all the data in a packet has arrived. Just reading until there is no more serial data won’t work, since the Arduino can read faster than the PC can send data.

So, the PC needs to include some character that tells the Arduino that this is the end of the packet.

If you use < and > as start and end markers, this code:

#define SOP '<'
#define EOP '>'

bool started = false;
bool ended = false;

char inData[80];
byte index;

void setup()
{
   Serial.begin(57600);
   // Other stuff...
}

void loop()
{
  // Read all serial data available, as fast as possible
  while(Serial.available() > 0)
  {
    char inChar = Serial.read();
    if(inChar == SOP)
    {
       index = 0;
       inData[index] = '\0';
       started = true;
       ended = false;
    }
    else if(inChar == EOP)
    {
       ended = true;
       break;
    }
    else
    {
      if(index < 79)
      {
        inData[index] = inChar;
        index++;
        inData[index] = '\0';
      }
    }
  }

  // We are here either because all pending serial
  // data has been read OR because an end of
  // packet marker arrived. Which is it?
  if(started && ended)
  {
    // The end of packet marker arrived. Process the packet

    // Reset for the next packet
    started = false;
    ended = false;
    index = 0;
    inData[index] = '\0';
  }
}

can be used to collect the data between the < and the > in an array.

If you prefer different start and end of packet markers, change the values of SOP and EOP.

If you will be sending packets with more than 80 characters, change the 80 (and the 79) in the code to reflect the sizes that you need.