Sending the data coming to the serial port to serial 3

This code should copy the messages received from Serial to Serial3 and either Serial1 or Serial2

const char START_CHAR = '\x02';
const char END_CHAR = '\x0A';

const int BUF_SIZE = 32;

char message[BUF_SIZE];

void receive_message(HardwareSerial &serial)
{
  int rx_index = 0;
  char rx_char = '\0';

  while (rx_char != START_CHAR)
  {
    while (!serial.available()) {}
    rx_char = serial.read();
  }

  // skip STX
  while (!serial.available()) {}
  rx_char = serial.read();

  // read until END_CHAR
  while (rx_char != END_CHAR)
  {
    if (rx_char != END_CHAR)
    {
      if (rx_index < BUF_SIZE - 1)
      {
        message[rx_index] = rx_char;
        rx_index++;
      }
    }

    while (!serial.available()) {}
    rx_char = serial.read();
  }
  message[rx_index] = '\0';
}

void send_message(HardwareSerial &tx_serial)
{
  tx_serial.write (START_CHAR);

  for (int index = 2; index < strlen(message); index++)
  {
    tx_serial.write (message[index]);
  }

  tx_serial.write (END_CHAR);
}

void setup()
{
  Serial.begin(9600);
  Serial3.begin(9600);
  Serial1.begin(2400);
  Serial2.begin(2400);

}

void loop()
{
  receive_message(Serial);

  if (strncmp(message, "1", 1) == 0)
  {
    send_message(Serial1);
    send_message(Serial3);

  }
  else if (strncmp(message, "2", 1) == 0)
  {
    send_message(Serial2);
    send_message(Serial3);
  }
}

Still pending: Have you received the sketch from ChatGPT? :wink:

I assumed the most obvious ... It would be nice if this also worked for the lottery :wink:

No you did not.
Please read carefully

We will never know if the code you are posting is correct or not if it's not formatted correctly for posting on the forum.

The if condition doesn't work for you because you inserted an extra semicolon after the bracket:

(Serial.available() > 0) ; {
                         ^ - etxtra semicolon

After you remove it, this code will become correct:

if (Serial.available() > 0)   {
   Serial3.write(Serial.read());
}