Receiving full String asynchronous and processing it.

Hi,

I want to receive a Serial String while doing other stuff (mostly stuff on other interrupts).

Here is my example string:

$GPRMC,220516,A,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W*70

As you can see, it is NMEA.

I want to read everything there is in the buffer on every loop run and add it to a String (or char array?).

The end of each message is indicated by .

So, my first question is, how can I read the ? Will a '\r' or '\n' simply be added to the string?

Also, I found the "serialEvent()" function, but it says "Currently, serialEvent() is not compatible with the Esplora, Leonardo, or Micro" and underneath "Mega only", so does it work with the due?

My main focus is reading the serialport asynchronous, without delaying other functions.

thanks

So, my first question is, how can I read the ?

You read them like any other character.

Will a '\r' or '\n' simply be added to the string?

They will be in the stream. Whether you add them to the string you create, or not, is up to you.

so does it work with the due?

It doesn't do anything that you can't do by checking Serial.available() in loop().

You might try some code like below.

//zoomkat 7-30-13 simple delimited '\n' string parce test code
//from serial port input (via serial monitor with NL&CR enabled)
//and print result out serial port
// \n\r is the data packet delimiter

String readString;

void setup() {
  Serial.begin(9600);
  Serial.println("serial delimit test 1.0"); // so I can keep track of what is loaded
}

void loop() {

  //expect a string like $SDMTW, 31.4, C*02
  //followed by \n\r end of packet delimiter
  
  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == '\n') {  //looks for end of data packet marker 
      Serial.read(); //gets rid of following \r 
      Serial.println(readString); //prints string to serial port out
      
      //do stuff with captured readString
      
      readString=""; //clears variable for new input      
     }  
    else {     
      readString += c; //makes the string readString
    }
  }
}