NewSoftSerial Library: An AFSoftSerial update

Patrick, I happen to be working with this multi-port receive issue in some writing I'm doing. Perhaps this sample sketch might give you an idea how you might structure your code. This kind of solution isn't for everyone, but it might be enlightening.

Here I have an XBee radio that I am listening for input on. As soon as I get a 'y' from the radio, I want to note my position, as defined by the serial GPS device I also have connected. Here's a solution that will work with NewSoftSerial:

#include <NewSoftSerial.h>
const int rxpin1 = 2;
const int txpin1 = 3;
const int rxpin2 = 4;
const int txpin2 = 5;
NewSoftSerial gps(txpin1, rxpin1); // gps device connected to pins 2 and 3
NewSoftSerial xbee(txpin2, rxpin2); // gps device connected to pins 2 and 3

void setup()
{
  gps.begin(4800);
  xbee.begin(9600);
}

void loop()
{
  if (xbee.available() > 0) // xbee is active.  Any characters available?
  {
    if (xbee.read() == 'y') // if xbee received a 'y' character
    {
      unsigned long start = millis(); // begin listening to the GPS for 10 seconds
      while (start + 100000 > millis())
      {
        if (gps.available() > 0) // now gps device is active
        {
          char c = gps.read();
          // *** process gps data here
        }
      }
    }
  }
}

After 10 seconds of processing GPS, it returns to listening to the XBee. This paradigm isn't for everyone, but something similar might work for you.

Mikal