Rx led is blinking but serial.available() or serial Event is not responding

Hello, I am trying to send data from Simulink to Arduino Mega, in simulink I am using the "To instrument" block, I have configured the standard parameters: 9600, 8, None, 1. and I have tested it with virtual serial Monitor, the data is they are sending correctly in '% 3.2f' format; in Arduino I made a program that receives each of these data and orders them to form the quantity, for the moment I am using the data to vary the intensity of a led, I have also tried to send the data from the serial monitor of Arduino and it works correctly as well; I have even copied the data taken from the virtual serial Monitor and I have pasted it into the serial arduino monitor and it works correctly. but when sending the data directly from simulink to arduino, I can see the RX LED flashing but Serial Event or Serial.available do not respond. I attach my Arduino code, the Simulink file and screenshots so they can see what I'm talking about. Thank you very much, I hope you can help me.

const int LED = 11;
char ch;
int punto = 0;
int in;
float out;
int br;
int count = 0;
int countp = 0;
int x1 = 0;
int x2 = 0;
int x3 = 0;
float x1p = 0;
float x2p = 0;


void setup() {
  Serial.begin(9600);
  pinMode(LED, OUTPUT);
}

void loop() {
  while (Serial.available() > 0)  {
    ch = Serial.read();
    digitalWrite(LED, HIGH);
    if ((ch >= 48) && (punto == 0)) {

      //      Serial.println("holi");
      count++;
      in = ch - 48;
      switch (count) {
        case 1:
          x1 = in;
          //          Serial.print("x1 = ");
          //          Serial.println(x1);
          break;
        case 2:
          x2 = in;
          //          Serial.print("x2 = ");
          //          Serial.println(x2);
          break;
        case 3:
          x3 = in;
          //          Serial.print("x3= ");
          //          Serial.println(x3);
          break;
      }
    }

    else if (ch == 46) {
      //      Serial.println("holip");
      punto = 1;
    }
    else if ((ch >= 48) && (punto == 1)) {
      in = ch - 48;
      countp++;
      switch (countp) {
        case 1:
          x1p = in;
          //          Serial.print("x1p = ");
          //          Serial.println(x1p);
          break;
        case 2:
          x2p = in;
          //          Serial.print("x2p = ");
          //          Serial.println(x2p);
          break;
      }
      //      Serial.print("countp = ");
      //        Serial.println(countp);
      if (countp == 2) {
        //        Serial.println("switch");
        switch (count) {
          case 1:
            out = x1 + (x1p / 10) + (x2p / 100);
            count = 0;
            countp = 0;
            punto = 0;
            //            Serial.print("out1 = ");
            //            Serial.println(out);
            break;
          case 2:
            out = (x1 * 10) + x2 + (x1p / 10) + (x2p / 100);
            count = 0;
            countp = 0;
            punto = 0;
            //            Serial.print("out2 = ");
            //            Serial.println(out);
            break;
          case 3:
            out = (x1 * 100) + (x2 * 10) + x3 + (x1p / 10) + (x2p / 100);
            count = 0;
            countp = 0;
            punto = 0;
            //            Serial.print("out3 = ");
            //            Serial.println(out);
            break;
        }
      }
    }
  }

  br = round(out);
  br = map(br, 0, 160, 0, 255);
  //
  //  Serial.print("brillo = ");
  //  Serial.println(br);
  //analogWrite(LED, br);
}

PD: the line where I control the intensity of the led is commented because I'm trying to do a debugging and now I'm just trying to turn on the led when I receive a serial data.

serial_pwm.ino (2.47 KB)

Pendulo.zip (21.6 KB)

If sending data from serial monitor to arduino works and sending data from simulink to arduino does not work, the problem is (obviously) something that simulink does.

Did you select the correct com port in simulink?
2)
Your arduino code expects text and serial monitor does indeed send text. What does simulink send? Text or binary numbers? It should be easy to test writing the simplest of applications; at the arduino side, echo back what you receive

void loop()
{
  if(Serial.available() > 0)
  {
    byte b = Serial.read();
    Serial.print(b, HEX);
  }
}

In simulink display the characters and check if it matches with what you expect. If you send 1, you expect 1 back; if you send '1', you expect 31 back.

Note
Your code will be a lot more readable if you don't use e.g. 48 but use '0'.

If the serial console of your arduino is open, there is a chance that your simulink program cannot grab the serial port as well if you run from the same computer. It might get a ‘port busy’ answer and fail. How is that handled in simulink? (are you seing something saying failed to open serial port COM1?)

As you have a mega, you should use a USB to serial adapter and send data to Serial1 and keep Serial to debug to the arduino console