Use an Arduino to "intercept" transparently serial communication to Grbl? I need to have an Arduino "spying" on communications between the PC and another Arduino with GRBL. The goal is to intercept a couple of GCode commands and act on them instead of Grbl.

My first step is to attempt to be as transparent as possible, but so far, I am not getting from Grbl the clear answer I expect. For example, I get Grbl 1.1d [?2???B???u5 instead of Grbl 1.1d ['$' for help]

Here is my code so far.

#include &lt;SoftwareSerial.h&gt;

int PortOneTX = 10;
int PortOneRX = 11;

const String USB = "USB";
const String GRBL = "GRBL";

char endOfLine = '\n';

SoftwareSerial portOne(PortOneRX, PortOneTX);

String grblBytes = "";
String USBBytes = "";

void setup()
{
    Serial.begin(115200);
    while (!Serial)
    {
        ; // Do nothing, just wait till we are connected through USB
    }
    portOne.begin(115200);
    portOne.write("\r\n");
    delay(2);       ;
}

String stringtoWrite = "";

void loop()
{   
    if (portOne.available() &gt; 0)//while (portOne.available())
    {
        stringtoWrite = portOne.readStringUntil(endOfLine); 
        for (int i = 0; i &lt; stringtoWrite.length(); i++)
        { 
            Serial.write(stringtoWrite[i]);
        }   
        Serial.write(endOfLine);

    }
    if (Serial.available() &gt; 0)//while (Serial.available())
    { 
        stringtoWrite = Serial.readStringUntil(endOfLine); 
        for (int i = 0; i &lt; stringtoWrite.length(); i++)
        { 
            portOne.write(stringtoWrite[i]);
        }   
        portOne.write(endOfLine);

    }   
}


I feel that I should be using events instead of if (serial.available) in the loop, but I am not sure how to go about it. I thought it would be easy! 

Anyway, as I want Grbl-Panel to work totally transparently, I need this first step to be Ok before doing anything else.

Thanks for your help.
I finally solved my problem by buying an Arduino Due! It was a problem of speed, not of code. The Uno is just not powerfull enough to read an write to Software Serial at 115200 Bauds, or even 9600, which I tried.

The Due has absolutly no problem. I made a small code test to intercept "words" coming form "USB" To "GRBL", and it works just as expected, while GCODE is send (using Grbl-Panel on the PC) through the Due (USB) to the Uno (Grbl).

It's the very first time I solve what I thought to be a code problem by an hardware solution. 

BTW, in case anyone wonder, yes, I am using a level shifter between the 2.