Yeah I know that it is probably not good to mess with the core libraries. That is why I see it as a temporary workaround.
Using Serial.available before reading the byte on the one hand indeed solves the corruption problem. But on the other hand, the cause for the corruption which I now identified as a "simple" buffer overflow is not solved.
So what I am really wondering about, and also would like to ask, is why does this simple reading byte program (you obviously cannot name this a program) already leads to a max. buffer content of 45 bytes when I send a 106 byte command (My goal is actually a 960 byte command...)? I mean, is there any inefficiency or, can I optimize the read process?
I attached the modified version, where the not necessary prints are deleted and a print of the serial.avalaible function (returning the bytes stored in the buffer) is added.
unsigned char incoming_Char[230];
int a=0, b=0, c=0;
unsigned char Read_Serial=0;
void setup()
{
Serial.begin(115200);
}
void loop ()
{
a=0;
if (Serial.available()>0)
{
while (Serial.peek() != 241 )
{
Serial.println(Serial.available(),DEC);
incoming_Char[a]=Serial.read();
a++;
}
Read_Serial=1;
}
if (Read_Serial==1)
{
for (int a=0; a<230; a++)
{
Serial.print(a,DEC);
Serial.print(":");
Serial.println(incoming_Char[a],DEC);
}
Read_Serial=0;
}
}
Again, thanks for your help, it is very much appreciated!