NewSoftSerial Library: An AFSoftSerial update

Here's the code portion of the above post since I couldn't post it.

/*
Arduino FIO + XBee Radio + RS-232 Breakout (DB9 Female)
Created this to allow the XBee radio to sleep. Gauges can't
wake the module. The FIO board wakes the radio.

Below are the steps this sketch should take to work properly

1. When serial data is recieved. Hold the Data
2. Wake up the XBee Radio (Set DTR(PN D5) HIGH)
3. Wait for XBee to signal it's ready. (Check CTS(PN D4) LOW)
4. Wait a few mili seconds.
5. Send received serial data through XBee

Added RTS/CTS support through setting the pins high and low.

Created by: Jarvis J Stubblefield
Created on: 2010/11/05
Updated on: 2010/11/12
*/

#include <NewSoftSerial.h>
#include <avr/power.h>
#include <avr/sleep.h>

//Pin CONSTANTS
const byte pinRx   = 2;
const byte pinTx   = 3;
const byte pinCTS  = 4;
const byte pinDTR  = 5;
const byte pinGRTS = 6;
const byte pinGCTS = 7;

//String for Serial Data
String strData;

//Counter for Auto-Sleep
int intCounter;

//Soft Serial for Storing Data
NewSoftSerial objGauge(pinRx, pinTx); //This function takes care of setting pinMode

void setup() {
  pinMode(pinGRTS, INPUT);
  digitalWrite(pinGRTS, LOW);
  pinMode(pinGCTS, OUTPUT);
  digitalWrite(pinGCTS, HIGH);
  pinMode(pinDTR, OUTPUT); //Set DTR to be an OUTPUT pin
  digitalWrite(pinDTR, HIGH); //Set pin to HIGH so we can wake with LOW
  digitalWrite(pinCTS, HIGH); //Set pin to HIGH so we can later wake and check for LOW
  Serial.begin(9600);
  Serial.println("Setup almost done.");
  objGauge.begin(9600);
  intCounter = 0;
}

void loop() {
  if (digitalRead(pinGRTS) == HIGH) {
    Serial.println("RTS: HIGH");
  }
  else if (digitalRead(pinGRTS) == LOW) {
    Serial.println("RTS: LOW");
    digitalWrite(pinGRTS, HIGH);
  }
  if (digitalRead(pinGCTS) == HIGH) {
    Serial.println("CTS: HIGH");
  }
  else if (digitalRead(pinGCTS) == LOW) {
    Serial.println("CTS: LOW");
    digitalWrite(pinGCTS, HIGH);
  }
  
  if (objGauge.available())
  {
    char chrIncoming;
    
    //Serial Data is coming in. Wake up the XBee.
    if (digitalRead(pinDTR) == HIGH) {
      digitalWrite(pinDTR, LOW);
    }
    
    //Read in the characters until you have a full string.
    while (objGauge.available()) {
      chrIncoming = (char)objGauge.read();
      strData += chrIncoming;
      // If you find a LFCR or CRLF then you have a full reading.
      if (strData.endsWith("\n\r") || strData.endsWith("\r\n")){
        break;
      }
    }
    
    delay(50); //Delay to wait for XBee to wake.
    //Check for the radio to be awake (CTS = LOW)
    if (digitalRead(pinCTS) == LOW) {
      if (strData.length() > 0) {
        Serial.print(strData);
        strData = ""; //Prepare for new data coming in.
        delay(50); //Wait a bit then sleep again.
        digitalWrite(pinDTR, HIGH);
        Serial.flush(); //Flush the serial stream.
        objGauge.flush(); //Flush the gauge stream.
      } //End strData has length
    } //End pinCTS == LOW
  } //End objGauge.available()
  delay(100); //Sleep a little between looping (ms)
  intCounter++;
  
  if (intCounter == 10)
  {
    intCounter = 0; //Reset counter
    //sleepNow();
  }
}

void sleepNow()
{
    /* Now is the time to set the sleep mode. In the Atmega8 datasheet
     * http://www.atmel.com/dyn/resources/prod_documents/doc2486.pdf on page 35
     * there is a list of sleep modes which explains which clocks and 
     * wake up sources are available in which sleep modus.
     *
     * In the avr/sleep.h file, the call names of these sleep modus are to be found:
     *
     * The 5 different modes are:
     *     SLEEP_MODE_IDLE         -the least power savings 
     *     SLEEP_MODE_ADC
     *     SLEEP_MODE_PWR_SAVE
     *     SLEEP_MODE_STANDBY
     *     SLEEP_MODE_PWR_DOWN     -the most power savings
     *
     *  the power reduction management <avr/power.h>  is described in 
     *  http://www.nongnu.org/avr-libc/user-manual/group__avr__power.html
     */

  set_sleep_mode(SLEEP_MODE_IDLE);   // sleep mode is set here

  // enables the sleep bit in the mcucr register so sleep is possible. just a safety pin 
  sleep_enable(); 

  //Turn OFF unused modules to pull even less power.
  power_adc_disable();
  power_spi_disable();
  power_timer0_disable();
  power_timer1_disable();
  power_timer2_disable();
  power_twi_disable();
  
  sleep_mode(); // here the device is actually put to sleep!!
 
// THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
  sleep_disable(); // first thing after waking from sleep: disable sleep...

  power_all_enable(); // Turn EVERYTHING back on.
}

Thanks again for all help and suggestions,
Jarvis