The Arduino needs to use 2 extra pins one in and one out
The code below is not engineered but should give you the idea
uint8_t CTS = 4; // CLEAR TO SEND
uint8_t RTS = 5; // REQUEST TO SEND
....
if (digitalRead(RTS) == HIGH) // the PC want to send data
{
if (buffer is empty)
{
digitalWrite(CTS, HIGH); // allow sending of data
while (Serial.available() == 0) ; // wait for data to come in.
digitalWrite(CTS, LOW); // signal to stop sending data
process data from serial
}
}
...
a variation sometimes seen, (depends on the sending hardware
uint8_t CTS = 4; // CLEAR TO SEND
uint8_t RTS = 5; // REQUEST TO SEND
....
if (digitalRead(RTS) == HIGH) // the PC want to send data
{
if (buffer is empty)
{
// give a pulse to signal send allow
digitalWrite(CTS, HIGH);
delay(n); // n typical 1 or 2 milliseconds.
digitalWrite(CTS, LOW);
while (digitalRead(RTS) == HIGH); // wait for LOW. ==> CTS is recieved.
while (Serial.available() == 0) ; // wait for data to come in.
x = Serial.read();
...
}
}
...
should give you the idea.
more about CTS/RTS
To make RTS/CTS really work it should be embedded in the hardware serial core code.