Serial.readString trunc long text

Hello,

i don't understand why my text is truncated.
this is a exemple of my message:

4200;0;100;0|0;0;0;400|0;0;0;-100|0;0;1;0|-247;0;100;0|0;0;0;500|0;0;0;-100|0;0;1;0|-466;0;124;0|0;0;0;500|0;0;0;-100|0;0;1;0|0;0;124;0|0;0;0;500|0;0;0;-100|0;0;1;0|0;0;137;0|0;0;0;500|0;0;0;-100|0;0;1;0|0;0;137;0|0;0;0;500|0;0;0;-100|0;0;1;0|714;0;173;0|0;0;0;500|0;0;0;-100|0;0;1;0|-714;0;149;0|0;0;0;500|0;0;0;-100|0;0;1;0|0;0;149;0|0;0;0;500|0;0;0;-100|0;0;1;0|0;0;137;0|0;0;0;500|0;0;0;-100|0;0;1;0|466;0;173;0|0;0;0;500|0;0;0;-100|0;0;1;0|-507;-744;137;0|0;0;0;500|0;0;0;-100|0;0;1;0|97;-441;126;0|0;0;0;500|0;0;0;-100|0;0;1;0|0;0;147;0|0;0;0;500|0;0;0;-100|0;0;1;0|263;-65;108;0|0;0;0;500|0;0;0;-100|0;0;1;0|0;0;166;0|0;0;0;500|0;0;0;-100|0;0;1;0|-199;-499;158;0|0;0;0;500|0;0;0;-100|0;0;1;0|0;0;115;0|0;0;0;500|0;0;0;-100|0;0;1;0|-10;-959;120;0|0;0;0;500|0;0;0;-100|0;0;1;0|0;0;154;0|0;0;0;500|0;0;0;-100|0;0;1;0|0;-1580;154;0|0;0;0;500|0;0;0;-100|0;0;1;0|0;0;120;0|0;0;0;500|0;0;0;-100|0;0;1;0|10;-959;158;0|0;0;0;500|0;0;0;-100|0;0;1;0|0;0;115;0|0;0;0;500|0;0;0;-100|0;0;1;0|199;-499;108;0|0;0;0;500|0;0;0;-100|0;0;1;0|0;0;166;0|0;0;0;500|0;0;0;-100|0;0;1;0|-263;-65;126;0|0;0;0;500|0;0;0;-100|0;0;1;0|0;0;147;0|0;0;0;500|0;0;0;-100|0;0;1;0|-97;-441;137;0|0;0;0;500|0;0;0;-100|0;0;1;0|507;-744;100;0|0;0;0;500|0;0;0;-100|0;0;1;0|-466;0;137;0|0;0;0;500|0;0;0;-100|0;0;1;0|466;0;173;0|0;0;0;500|0;0;0;-100|0;0;1;0|-507;13255;137;0|0;0;0;500|0;0;0;-100|0;0;1;0|97;-441;147;0|0;0;0;500|0;0;0;-100|0;0;1;0|0;0;126;0|0;0;0;500|0;0;0;-100|0;0;1;0|263;-65;166;0|0;0;0;500|0;0;0;-100|0;0;1;0|0;0;108;0|0;0;0;500|0;0;0;-100|0;0;1;0|-199;-499;158;0|0;0;0;500|0;0;0;-100|0;0;1;0|0;0;115;0|0;0;0;500|0;0;0;-100|0;0;1;0|-10;-959;120;0|0;0;0;500|0;0;0;-100|0;0;1;0|0;0;154;0|0;0;0;500|0;0;0;-100|0;0;1;0|0;-1580;120;0|0;0;0;500|0;0;0;-100|0;0;1;0|0;0;154;0|0;0;0;500|0;0;0;-100|0;0;1;0|10;-959;158;0|0;0;0;500|0;0;0;-100|0;0;1;0|0;0;115;0|0;0;0;500|0;0;0;-100|0;0;1;0|199;-499;166;0|0;0;0;500|0;0;0;-100|0;0;1;0|0;0;108;0|0;0;0;500|0;0;0;-100|0;0;1;0|-263;-65;147;0|0;0;0;500|0;0;0;-100|0;0;1;0|0;0;126;0|0;0;0;500|0;0;0;-100|0;0;1;0|-97;-441;137;0|0;0;0;500|0;0;0;-100|0;0;1;0|-6892;0;0;-100|

this text is 2089 characters long


int countStep(String *text, int text_length){
  int c=0;
  for (int i=0; i < text_length; i++)
  { 
    if(text->charAt(i) == '|') 
    { 
      c++; 
    }
  }
  return c;
}


void setup() {
  Serial.begin(9600);
}

void loop() {
  while (!Serial.available());
  val_Text = Serial.readString();
  int text_length = val_Text.length();
  Serial.println(text_length);
  Serial.println(val_Text);
  int counterStep_ = countStep(&val_Text, text_length);
  Serial.println(counterStep_);
}

but when we print text length with find 1486 for exemple

What is arduino board you are use?

arduino UNO

What baud rate is the Serial monitor

Uno has 2048 bytes of RAM only
There is no way it can accept a line in 2089 chars

and note that part of RAM is used by your program, so the maximum string will even shorter, like your 1489 bytes...

it s a arduino Uno so i use 9600 or 115200

Okay so your using 9600

aie ok thank you

yes i used 9600

Tell us about your project. Why do you need to send such long lines?

There are two questions here -

  1. Why do you going to transfer this line at once? long strings are usually broken into short parts, say 100 characters each, and transmitted one by one

  2. What are you going to do with a string over 2000 characters on a board with 2k memory? even if you can accept this line in parts, you still won’t be able to process it as a whole

it's for a radial printer, it s print point in gel texture

These parts, separated by '|' stick - looks like separate instructions for a printer?
so you can transfer and print one instruction at once

yes it was i did in first, but it was complicated with the delay, so that the instructions do not overlap I had to add time and the print was less fluid

Do not use readString() because delays. Read chars one by one with read(), separating instructions by '|' as in the big string
There are lot of string parsing tutorials in the net

it works like a stack ? the texts will be added one after the other ?

i do not understand
Where the texts will be added?

when we read character by character, if we send several strings, the loop will go to the next text once it has done all the characters of the previous text? or it will overwrite

Transmitter sends text chars one by one and receiver accepts it in the same sequence.
The chars can't overlap.
Once the receiver get the '|', it understands that the instruction is received in full and print this line at the printer.
The lines are not stored at the receiver.

ok i understand thank a lot <3

but note, in this case the rest of the program must not contain delays, otherwise characters will be lost.