In Void Serial Problem

HI, sorry my english, but i need help because i’m developing a serial common action software, by easy concept i send a string and other Arduino receive the comand and do something.

in this case the code work:

void loop() 
{

  if (mySerial.available() > 0) {

      Serial.print("CMD << ");
      char Recved = mySerial.read();   

        if (Recved == EndChar){
              Serial.println();
        }else{
               Serial.print(Recved);
        }
      
  }

}

In the latter case NOT

void loop() 
{

 Listen(mySerial , EndC)

}


void Listen(SoftwareSerial SelectedSerial , char EndChar){
  
  if (SelectedSerial.available() > 0) {

      Serial.print("CMD << ");
      char Recved =  SelectedSerial.read();
          
         if (Recved == EndChar){
             Serial.println();
         }else{
         Serial.print(Recved);
         }

     }
   
}

I’m using an other Void like this for send a string and when i send, all work fine, but when i try to listen a custom SoftwareSerial socked inside a function i can’t receive anything.

How do I let go a serial.read in a function?

HI & Tnx

It will work with a pointer.

SoftwareSerial *pSoft = &mySerial;
...
Listen(pSoft, EndC);
...
void Listen(SoftwareSerial *pS, char EndChar){
  if (pS->available() > 0) {

I’m not entirely sure but I think it might also work with a reference (once character code change):

void Listen(SoftwareSerial &SelectedSerial , char EndChar) {  // <- note the '&' making it a reference
  if (SelectedSerial.available() > 0) {
      Serial.print("CMD << ");
      char Recved =  SelectedSerial.read();
         if (Recved == EndChar){
             Serial.println();
         } else {
         Serial.print(Recved);
         }
     }
}