Multiple available serial

Hi, My friends,
I connected gsm module and radio module (HC12) with Arduino MEGA

this is my code:

void setup() {
  Serial.begin(9600);
  gsm.begin(9300);
  HC.beging(93600);

}

void loop() {
  
if (gsm.available()) {
       Serial.write(gsm.read());  
            
  }

if (HC.available()){
    Serial.write(HC.read());
  }

}

My problem is in reception
Just One a receive data , Thanks

this is my code:

This is not your code as it doesn't compile.

My guess is that you're using two SoftwareSerial instances and one of the many drawbacks this horrible piece of code has is that only one instance at a time can listen.

As you state that you're using a Mega why don't you use the available hardware serial interfaces (the Mega has 4 of them)?

Thanks for your answer

pylon:
This is not your code as it doesn't compile.

I know selected just important in my code

pylon:
My guess is that you're using two SoftwareSerial instances and one of the many drawbacks this horrible piece of code has is that only one instance at a time can listen.

I already added in my code HC.listen(); & gsm.listen();
but Do not work efficiently , sometime HC receive Data some time don't.

I already added in my code HC.listen(); & gsm.listen();
but Do not work efficiently , sometime HC receive Data some time don't.

That's probably because they cannot listen at the same time even if you call the listen() methods. So while listen is active for the HC instance all characters that where sent by the GSM device are lost and vice-versa.

Did you read my last sentence in my first answer? Use the hardware serial interfaces and your problems are gone.

pylon:
Did you read my last sentence in my first answer? Use the hardware serial interfaces and your problems are gone.

I don't know how I can use this option, can u help me?

I don't know how I can use this option, can u help me?

Serial1, Serial2, and Serial3 are used just exactly like Serial or any SoftwareSerial instance.