Using the same function for different Serial ports.

I am looking for a way to run the same function using different Serial ports, for example:

void pump_command(int code, String command){
  String prefix="";

and the same for Serial1, Serial 3 and so on. Surely, there is a better way to do this other than having separate functions that would be completely identical except for the port name, but I am at loss on what to google for. Could someone point me in the right direction, please.

You could pass the function the number of the serial port, and then use a series of if statements or switch statement.

void pump_command(int code, String command, int portNum)
  if(portNum == 0)
  else if(portNum == 1)
  // etc.

Or, you could make the function take a reference to the HardwareSerial class.

void pump_command(int code, String command, HardwareSerial &thePort)

Thank you, off to read about pointers.

off to read about pointers.

Why? References are not pointers.

I think I saw where someone created an array with each of the serial connections in it

Then they were (IIRC) addressed by myArray[0] or myArray[1] etc