Switch SoftSerial names

Hello,
In my project I'm using 1 hardware and 3 SoftSerial ports and everything works fine.
Now I have to listen and read softSerial Port1 or Port2, and process received bytes in both the same way. The Code for that would be redundant, as only the port names are different.
I would like to program a function to read and process the received bytes, but for that I have to change the ports objects names.
Like serPort.read() or wifiPort.read() would become xxport.read() and xx is replaced by a variable.
Is there a way to do that?
Thanks
L

Like serPort.read() or wifiPort.read() would become xxport.read() and xx is replaced by a variable.
Is there a way to do that?

Not like that, no. It is possible to pass to the function the instance to use (serPort or wifiPort).

That would be great. How do I do that?

How do I do that?

Post a snippet or two of code that is unrelated to the problem. Then, we'll argue about it for a couple of days until you are thoroughly confused about which of 47 ways might work.

Or, post all of your code, so we have some idea what you are talking about.

This is the part of code I’d like to put in a function. serPort should be replaceable.

serPort.listen();
  if (serPort.available()){
      int rec_i = 0;
      int inByteCommand;
      commandLine[0] = '\0';
      unsigned long int previousMillis = millis();
      // Discard data read before valid protocol
      do {
        inByteCommand = serPort.read();
      } 
      while ( inByteCommand != '

&& ( millis() - previousMillis ) < 20 );

// Read command
     // Maximum 30 Bytes, Timout 50ms, stop command @ LF (\n)
     commandLine[0] = inByteCommand;
     previousMillis = millis();
     while( inByteCommand != ‘\n’ && inByteCommand != ‘*’ &&
       rec_i < 30 && (millis()- previousMillis) < 50 ) {
       inByteCommand = serPort.read();
       if( inByteCommand != -1 ) {
         commandLine[++rec_i] = inByteCommand;
       }
     }
     commandLine[rec_i+1] = ‘\0’;
   }
 }

someReturnType someFunctionName(SoftwareSerial &thePort)
{
   thePort.listen();
   if(thePort.available() > 0)
   {
      // Do some stuff
   }

   // return something, if needed
}

Then, call that function:

   someFunctionName(serPort);
   // or
   someFunctionName(wifiPort);

Ah, thanks. Nice.
Now I have to deal with the missing hardware buffer, because when I call both requests I think the SoftwareSerial does not have the time to read the data on the ports. None of the ports receives something.