Buffer data parsing

Hey guys, I’m retrieving the data received from my serial port and storing it in a buffer, which will then be parsed to separate the data. The packets received should be of the following format:
<(id)-(data)>
for example: in <1-1023>, the id is 1 and data is 1023. The data ranges from 0 to 1023, so this means the buffer may vary in size (<1-0> to <1-1023>).

When simply storing the data in the buffer, I don’t encounter any problems, but when I try to parse the data, it seems to screw up the buffer as well :o

Here’s my code:

#define SOP '<' // Start of packet
#define EOP '>' // End of packet
#define PAD '-' // Packet (device) address delimiter
// Example of a packet: <1-1022> ---> device address = 1, data = 1022

// Data config -- information to be sent to the web server
int device = 0;
int data = 0;

String inputString = "";

int index = 0;
int i = 0;
int j = 0;
char tmp = 0; //temporary variable to store serial data input, that will be parsed.
char in_buffer[16]; //buffer to hold incoming data.
char parse_buffer[16]; //buffer to hold data to be parsed.
boolean bufferComplete = false;

// Declare as many devices as you have. In my case, I only have 2. The data received from the devices will respectively be stored in these variables.
int device1 = 0;
int device2 = 0;

void setup() {
  Serial.begin(9600);               // Used for serial debugging
  inputString.reserve(200);
  //Serial.println("Program running...");
}

void loop() {
  while (Serial.available()) {
    // get the new byte:
    tmp = (char)Serial.read();
    if (tmp == '\0') {
      bufferComplete = true;
      Serial.println(in_buffer);
    }
    else {
      in_buffer[index] = tmp;
      index++;
    }
  }
  if (bufferComplete) {
    //j = 0;
    for (i = 0; i <= sizeof(in_buffer); i++) {
      if (in_buffer[i] == SOP) {
        j = 0;
      }
      else if (in_buffer[i] == EOP) {
        data = atoi(parse_buffer);
        j = 0;
        break;
      }
      else {
        parse_buffer[j] = in_buffer[i];
        j++;
        if (in_buffer[i] == PAD) {
          device = atoi(parse_buffer);
          j = 0;
        }
      }
    }
    Serial.println("Device ID: ");
    Serial.println(device);
    Serial.println("Data: ");
    Serial.println(data);
    //memset(in_buffer,0,sizeof(in_buffer));
    //memset(parse_buffer,0,sizeof(parse_buffer));
    bufferComplete = false;
  }
}

And here’s what I get on the serial monitor:

<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1022>
Device ID: 
1
Data: 
1023
<1-1023><1-1022>
Device ID: 
1
Data: 
1023
<1-<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<q-<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1]1<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023

When printing the buffer, it seems to mess it up… If I were to remove the data parsing portion of my program, it prints the buffer correctly as <1-1023> every time. (I tried it).

What am I doing wrong?

Thank you to everyone willing to help me out :slight_smile:

Well I notice that you have an outer for loop with an index variable "i". Inside the for loop, you modify it (set it to zero). This is a usually a bad idea. There are cases where it is useful, but the approach is known to be a common source of errors. In most cases it reflects an awkward construction of the flow, which can be refactored to make more sense. In many cases, it just creates bugs.

Can’t believe I left that in there, wasn’t supposed to be there anymore ^^
After removing it, I’m still having the same issue, and the serial monitor stops displaying any more data after the last line (<1-1), which means it had to crash somewhere…

Here’s the serial monitor output:

<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-Ì<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1022>
Device ID: 
1
Data: 
1023
<1-1023><1-1022>
Device ID: 
1
Data: 
1023
<1-1<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1022>
Device ID: 
1
Data: 
1023
<1-1023><1-1022>
Device ID: 
1
Data: 
1023
<1-1<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-Ì<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1022>
Device ID: 
1
Data: 
1023
<1-1023><1-1022>
Device ID: 
1
Data: 
1023
<1-1<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-Ì<1-1022>
Device ID: 
1
Data: 
1022
<1-1022><1-1023>
Device ID: 
1
Data: 
1022
<1-1022><1-1023>
Device ID: 
1
Data: 
1022
<1-1<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1023>
Device ID: 
1
Data: 
1023
<1-1<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1022>
Device ID: 
1
Data: 
1023
<1-1023><1-1022>
Device ID: 
1
Data: 
1023
<1Ë<1-1023>
Device ID: 
1
Data: 
1023
<1-1023><1-1022>
Device ID: 
1
Data: 
1023
<1-1023><1-1022>
Device ID: 
1
Data: 
1023
<1-1

Thanks for the help!

First - Always auto-format you code BEFORE POSTING, I stop reading your code as soon as the formating went wrong.

If you can't be bothered to spend a second auto formatting the code i'm not going to read it.

char in_buffer[16]; //buffer to hold incoming data.
char parse_buffer[16]; //buffer to hold data to be parsed.

Why do you have 2 of these?

  1. This
    if (tmp == '\0') {
      bufferComplete = true;
      Serial.println(in_buffer);
    }

will never be true.

Mark

Well I notice that you have a break statement inside the else if, inside the for loop. It will terminate the parsing on finding an EOP. Is that really what you wanted to do?

@holmes4

  1. My apologies, I thought I did auto format I didn’t double check… I edited my first post with the most recent auto-formatted code.

  2. I’m dumping the serial data read into the first one, in_buffer, and the second one is used for the parsing. What I want to do is isolate the device ID and the data from my packet (refer to my first post to see example of the packets), and to do so I inserted a start of packet delimiter (<), end of packet delimiter (>) and address (device id) delimiter (-). Therefore, when I start storing the data from the serial buffer (in_buffer) into my parse_buffer when I detect my SOP, and stop to convert what I received when I detect my PAD, reset the parse_buffer index to 0 so I can start storing the data until I detect my EOP.

Let me know if anything seems unclear, trying to do my best to explain my situation :slight_smile:

  1. How will it never be true? There’s a null character at the end of my serial packet, so once it’s detected it’ll be true, right? I might be wrong, just trying to understand what you mean :slight_smile:

@arrg Yes indeed, it will terminate the parsing once it finds the EOP (end of packet delimiter), which is what I intend to do. :slight_smile:

Thank you both for your help/time! :smiley:

atoi() requires a null-terminated string. At no point do you ever explicitly terminate in your array with '\0' before passing it to atoi()

Arrch: atoi() requires a null-terminated string. At no point do you ever explicitly terminate in your array with '\0' before passing it to atoi()

So I'd need to add a null character to my array before converting it for it to work properly?

brother6: So I'd need to add a null character to my array before converting it for it to work properly?

or else use strcpy() to make a copy and run atoi() on that.

I doubted that was going to fix my problem (didn't seem like the problem was with the conversion), but at least it'll prevent another one :D (ty aarg)

Still getting the same problem as before after the modification.

aarg: or else use strcpy() to make a copy and run atoi() on that.

But strcpy() also requires a null terminator.

christop: But strcpy() also requires a null terminator.

Sorry, it's strlcpy().

Forgot to mention I didn't use strcopy, but strcat to add the null character at the end of my string

Here's how I do it:

      else if (in_buffer[i] == EOP) {
        strcat(parse_buffer, NULL_CHAR);
        data = atoi(parse_buffer);
        j = 0;
        break;
      }
      else {
        parse_buffer[j] = in_buffer[i];
        j++;
        if (in_buffer[i] == PAD) {
          strcat(parse_buffer, NULL_CHAR);
          device = atoi(parse_buffer);
          j = 0;
        }
      }

I defined NULL_CHAR as '\0' at the top of my program. (still getting the same problem though)

strcat() requires a null terminated string as the first parameter. You haven’t got one yet. Right? How do you think strcat() would know where the end of the string is, without the null?

Besides, strcat takes two strings, not a string and a character.

If you have control of how the data is being sent, it might be easier to skip the start of packet delimiter and just use the end of packet delimiter and the internal data delimiter. Below is some code that perform that type of parsing.

//zoomkat 11-12-13 String capture and parsing  
//from serial port input (via serial monitor)
//and print result out serial port
//copy test strings and use ctrl/v to paste in
//serial monitor if desired
// * is used as the data string delimiter
// , is used to delimit individual data 

String readString; //main captured String 
String angle; //data String
String fuel;
String speed1;
String altidude;

int ind1; // , locations
int ind2;
int ind3;
int ind4;

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

void loop() {

  //expect a string like 90,low,15.6,125*
  //or 130,hi,7.2,389*

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == '*') {
      //do stuff
      
      Serial.println();
      Serial.print("captured String is : "); 
      Serial.println(readString); //prints string to serial port out
      
      ind1 = readString.indexOf(',');  //finds location of first ,
      angle = readString.substring(0, ind1);   //captures first data String
      ind2 = readString.indexOf(',', ind1+1 );   //finds location of second ,
      fuel = readString.substring(ind1+1, ind2+1);   //captures second data String
      ind3 = readString.indexOf(',', ind2+1 );
      speed1 = readString.substring(ind2+1, ind3+1);
      ind4 = readString.indexOf(',', ind3+1 );
      altidude = readString.substring(ind3+1); //captures remain part of data after last ,

      Serial.print("angle = ");
      Serial.println(angle); 
      Serial.print("fuel = ");
      Serial.println(fuel);
      Serial.print("speed = ");
      Serial.println(speed1);
      Serial.print("altidude = ");
      Serial.println(altidude);
      Serial.println();
      Serial.println();
      
      readString=""; //clears variable for new input
      angle="";
      fuel="";
      speed1="";
      altidude="";
    }  
    else {     
      readString += c; //makes the string readString
    }
  }
}

Thank you all for your input, I decided to go back to my first attempt at parsing (first program I did a couple days ago, that seemed to work for the most part, but now with zoomkat’s input I was able to fix some stupid mistakes I did). I scrapped my idea of keeping the serial data in a buffer that will then be parsed, and simply parsed the data as I was receiving it on my serial port.

Here’s my code:

#define SOP '<' // Start of packet
#define EOP '>' // End of packet
#define PAD '-' // Packet (device) address delimiter
// Example of a packet: <1-1022> ---> device address = 1, data = 1022

// Data config -- information to be sent to the web server
int device = 0;
int data = 0;

int index = 0;
char tmp = 0; //temporary variable to store serial data input, that will be parsed.
char in_buffer[8];
boolean end_of_packet = false;

// Declare as many devices as you have. In my case, I only have 2. The data received from the devices will respectively be stored in these variables.
int device1 = 0;
int device2 = 0;

void setup() {
  Serial.begin(9600);               // Used for serial debugging
  Serial.println("Program running...");
}

void loop() {
  while (Serial.available() > 0) {
    tmp = Serial.read();
    if (tmp == SOP) {
      index = 0;
    }
    else if (tmp == EOP) {
      index++;
      in_buffer[index] = '\0';
      data = atoi(in_buffer);
      end_of_packet = true;
      break; //exit while loop
    }
    else {
      in_buffer[index] = tmp;
      index++;
      if (tmp == PAD) {
        index++;
        in_buffer[index] = '\0';
        device = atoi(in_buffer);
        index = 0;
      }
    }
  }
  if (end_of_packet) {
    Serial.println("Device ID: ");
    Serial.println(device);
    Serial.println("Data: ");
    Serial.println(data);
    end_of_packet = false;
  }
}

And here’s what I get on the serial monitor:

Program running...
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1022
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1022
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1022
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1022
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1022
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1022
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1022
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1022
Device ID: 
1
Data: 
1022
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1022
Device ID: 
1
Data: 
1022
Device ID: 
1
Data: 
1022
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1022
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1022
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1022
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1022
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1022
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1022
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1022
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1023
Device ID: 
1
Data: 
1021
Device ID: 
1
Data: 
997
Device ID: 
1
Data: 
976
Device ID: 
1
Data: 
954
Device ID: 
1
Data: 
931
Device ID: 
1
Data: 
901
Device ID: 
1
Data: 
865
Device ID: 
1
Data: 
833
Device ID: 
1
Data: 
784
Device ID: 
1
Data: 
741
Device ID: 
1
Data: 
693
Device ID: 
1
Data: 
659
Device ID: 
1
Data: 
629
Device ID: 
1
Data: 
609
Device ID: 
1
Data: 
587
Device ID: 
1
Data: 
560
Device ID: 
1
Data: 
535
Device ID: 
1
Data: 
508
Device ID: 
1
Data: 
485
Device ID: 
1
Data: 
468
Device ID: 
1
Data: 
446
Device ID: 
1
Data: 
432
Device ID: 
1
Data: 
407
Device ID: 
1
Data: 
388
Device ID: 
1
Data: 
373
Device ID: 
1
Data: 
334
Device ID: 
1
Data: 
286
Device ID: 
1
Data: 
243
Device ID: 
1
Data: 
219
Device ID: 
1
Data: 
198
Device ID: 
1
Data: 
184
Device ID: 
1
Data: 
155
Device ID: 
1
Data: 
119
Device ID: 
1
Data: 
729
Device ID: 
1
Data: 
229
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0
Device ID: 
1
Data: 
0

Everything seems to be working perfectly right now, as you can see the value goes from 1023 to 0, which is what I expected since I simply use a potentiometer (with 5V) on my input side for test purposes.

Thanks again to everyone! If I ever need anything else I’ll let you guys know, my experience so far on these forum has been great, got a lot of help so far :smiley:

Quick question, I was going to make a new topic to ask but thought I'd try here before ^^

Is it possible to read the serial port at a certain interval? For example, only read the data on the port every 5 seconds. The rest of the time just wait. I'm assuming it's possible, but haven't really seen anything about it around so far...

Thanks again!