Communication problem with C++

Elis:
Common error with a small difference. You check for serial to have 2 characters available (instead of the usual 1 character that available() > 0 ensures) and then you read more than 2 times.

Arduino is very much faster than serial data arrives. Perhaps > 1 should be >= characters to be read?

  while (Serial.available() > 1){

//lee el terminal
    terminal1 = Serial.read();
    terminal1 = (terminal1 - 48)*10;
    terminal2 = Serial.read();
    terminal2 = terminal2 - 48 + terminal1;

delay(5); //espera para que le lleguen todos los datos antes de leerlos
   
    if ( terminal2 == 5){
      //LEDS     
      //lee la tension
      tension1 = Serial.read();
      tension1 = (tension1 - 48)*100;
      tension2 = Serial.read();
      tension2 = (tension2 - 48)10 + tension1;
      tension3 = Serial.read();
      tension3 = 2
(tension3 - 48 + tension2);

analogWrite(terminal2, tension3);

}
    else{
      //servos
      pos1 = Serial.read();
      pos1 = (pos1 - 48)*100;
      pos2 = Serial.read();
      pos2 = (pos2 - 48)*10 + pos1;
      pos3 = Serial.read();
      pos3 = (pos3 - 48) + pos2;
      pos_f = (float)pos3/100.0 * max_ang;

g_servo8.write(pos_f);
   }
  }//end while
}