Trying to write a function that would distribute command to various serial ports

I am controlling 8 motors with 4 serial ports,

The commands are a string of hex numbers and then I use a switch case to send each one to the right port.

void Motor_ShutDn (uint8_t motor_id)  //not used, it does not read the current correclty anymore
{
  byte cmd_send_buf[5];
  cmd_send_buf[0] = 0x3E;  //header
  cmd_send_buf[1] = 0x80;   // cmd_id-- 80=MOTOR SHUT DOWN .
  if (motor_id <= 10)
    cmd_send_buf[2] = motor_id;
  else
    cmd_send_buf[2] = motor_id - 10; // for ch B

  cmd_send_buf[3] = 0x00;      // data lenght
  cmd_send_buf[4] = cmd_send_buf[0] + cmd_send_buf[1] + cmd_send_buf[2] + cmd_send_buf[3]; // check sum
  byte buf_Size = 5;
  switch (motor_id)   // Switch to code based on StepNO
  {

    case 1:  // case used to command from the tablet leg configurationss
      Serial2.write (cmd_send_buf, buf_Size);  ///ch A
      break;

    case 2:  // case used to command from the tablet leg configurationss
      Serial2.write (cmd_send_buf, buf_Size);  ///ch A
      break;

    case 3:  // case used to command from the tablet leg configurationss
      Serial1.write (cmd_send_buf, buf_Size);  ///ch A
      break;

    case 5:  // case used to command from the tablet leg configurationss
      Serial4.write (cmd_send_buf, buf_Size);  ///ch A
      break;

    case 6:  // case used to command from the tablet leg configurationss
      Serial4.write (cmd_send_buf, buf_Size);  ///ch A
      break;

    case 7:  // case used to command from the tablet leg configurationss
      Serial4.write (cmd_send_buf, buf_Size);  ///ch A
      break;

    case 11:  // case used to command from the tablet leg configurationss
      Serial1.write (cmd_send_buf, buf_Size);  ///ch A
      break;

    case 12:  // case used to command from the tablet leg configurationss
      Serial3.write (cmd_send_buf, buf_Size);  ///ch A
      break;

    case 13:  // case used to command from the tablet leg configurationss
      Serial3.write (cmd_send_buf, buf_Size);  ///ch A
      break;


  }

}

I have about 20 commands so I would rather not do the switch case at the end of each one…

So I made a function:

void Dist_Comm (byte cmd_send_buf, uint8_t motor_id, byte buf_Size)
{
   
  switch (motor_id)   // Switch to code based on StepNO
  {

    case 1:  // case used to command from the tablet leg configurationss
      Serial2.write (cmd_send_buf, buf_Size);  ///ch A
      break;

    case 2:  // case used to command from the tablet leg configurationss
      Serial2.write (cmd_send_buf, buf_Size);  ///ch A
      break;

    case 3:  // case used to command from the tablet leg configurationss
      Serial1.write (cmd_send_buf, buf_Size);  ///ch A
      break;

    case 5:  // case used to command from the tablet leg configurationss
      Serial4.write (cmd_send_buf, buf_Size);  ///ch A
      break;

    case 6:  // case used to command from the tablet leg configurationss
      Serial4.write (cmd_send_buf, buf_Size);  ///ch A
      break;

    case 7:  // case used to command from the tablet leg configurationss
      Serial4.write (cmd_send_buf, buf_Size);  ///ch A
      break;

    case 11:  // case used to command from the tablet leg configurationss
      Serial1.write (cmd_send_buf, buf_Size);  ///ch A
      break;

    case 12:  // case used to command from the tablet leg configurationss
      Serial3.write (cmd_send_buf, buf_Size);  ///ch A
      break;

    case 13:  // case used to command from the tablet leg configurationss
      Serial3.write (cmd_send_buf, buf_Size);  ///ch A
      break;


  }

But it won’t work, I get an error
no matching function for call to ‘write(byte&, byte&)’
Serial1.write (cmd_send_buf, buf_Size); ///ch A

what am I doing wrong

Thanks

You need to modify the function prototype

void Dist_Comm (byte cmd_send_buf[], uint8_t motor_id, byte buf_Size)
{

If you do that, the compilation error about the Serial.write() call goes away.

You are OK calling the function like this.
Dist_Comm(cmd_send_buf,1,5);

Yey, that worked , pretty basic, I am learning,

Thanks a lot