Software Serial conditional Forward - Help please

Guys, Help please...

I have a device connected to my nano with software serial on digital 9 and 10. Everything works great if I upload the software serial example, bi-directional data with no missed characters or anything. what I need though is the ability to send commands, (characters) through the nano serial port that will control other digial ports, etc but when I send for example "!" all subsequent characters sent via the serial port are forwarded to the software serial port and any response is replied to the serial port. Then if "@" is sent via the serail port, it stops sending the characters to the software serial port...

I am not sure if I am discribing this well, but please let me know if you need more detals.

Thanks so much. I feel like I am missing something basic.

Post your full code, AND USE CODE TAGS!

Look for the # above the smiley faces, that is your code tag.

That seems fairly straightforward.

You should find various examples showing how to forward serial traffic in both directions by serial.available() to test whether there is a character, serial.read() to read it and serial.write() to output it to the other port - do that in both directions and you have the initial solution.

void loop()
{
  char c;
  if(Serial.available())
  {
    c = Serial.read();
    mySerial.write(c);
  }
  if(mySerial.available())
  {
    c = mySerial.read();
    Serial.write(c);
  }
}

What you want to add to that is the ability to recognise specific characters received from the hardware serial port and turn the forwarding on and off. You'll need a global flag to indicate whether forwarding is currently on, test each received character to see whether it is '!' or '@' and turn the forwarding flag true or false accordingly. You haven't said whether you want the '!' or '@' characters themselves to be forwarded under any conditions - you can choose whether/when you want them forwarded. In the example below I assumed you want to suppress the characters that change the forwarding state but let everything else through. Also, you didn't say whether you wanted to disable forwarding in both directions, or just one. I've only shown one direction below; you could disable the other direction too if you wanted.

boolean forwarding = false;
void loop()
{
  char c;
  if(Serial.available())
  {
    c = Serial.read();
    if(forwarding && (c == '@'))
    {
        forwarding = false;
    }
    else if (!forwarding && (c == '!'))
    {
        forwarding = true;
    }
    else if(forwarding)
    {
      mySerial.write(c);
    }
  }
  if(mySerial.available())
  {
    c = mySerial.read();
    Serial.write(c);
  }
}

Thank you for the quick reply guys!!!!

I will experiment with your samples later today, I did not have any code as of yet to post - was trying to map it out conceptually first...

for the "!" and "@" I would NOT want them forwarded, and once forwarding = false nothing would get forwarded either way any longer...

Thanks again for the direction. I will keep you posted on how it works :)