Dear people,
I'm struggling with a parsing problem, actually I'm sending strings through the serial usb (each 100ms), it works fine for a while (1 minute or so) and then suddently it stops.
I've tried everything that came to my mind without success...
Here's a simplified code:
void setup(void) {
Serial.begin(115200);
Serial.setTimeout(5);
}
#define STR_SIZE 40
void loop(void) {
char input[STR_SIZE + 1];
while (Serial.available() > 0) {
Serial.readBytes(input, STR_SIZE);
// Serial.println(input);
char* p = strtok(input, " ");
char* p1 = strdup(p);
p = strtok(NULL," ");
char* p2 = strdup(p);
p = strtok(NULL," ");
char* p3 = strdup(p);
p = strtok(NULL," ");
char* p4 = strdup(p);
Serial.print (p1);
Serial.print (p2);
Serial.print (p3);
Serial.println(p4);
}
}
Hope to have some help... thanks!
E
I'm struggling with a parsing problem, actually I'm sending strings through the serial usb (each 100ms), it works fine for a while (1 minute or so) and then suddently it stops.
I've tried everything that came to my mind without success...
Here's a simplified code:
void setup(void) {
Serial.begin(115200);
Serial.setTimeout(5);
}
#define STR_SIZE 40
void loop(void) {
char input[STR_SIZE + 1];
while (Serial.available() > 0) {
Serial.readBytes(input, STR_SIZE);
// Serial.println(input);
char* p = strtok(input, " ");
char* p1 = strdup(p);
p = strtok(NULL," ");
char* p2 = strdup(p);
p = strtok(NULL," ");
char* p3 = strdup(p);
p = strtok(NULL," ");
char* p4 = strdup(p);
Serial.print (p1);
Serial.print (p2);
Serial.print (p3);
Serial.println(p4);
}
}
Hope to have some help... thanks!
E