Using the outlined examples I copied the code from Example_2. The problem remains the same
void loop() {
unsigned int pos = 0;
bool newData = false;
while(Serial.available()>0 && newData == false) {
Serial.print ("T "); // test if loop is triggered
byte r = Serial.read();
Serial.println(r); // test if loop is triggered
if(r != '\n') {
data[pos] = r;
pos++;
} else {
Serial.println("N"); // test path is triggered
data[pos] = '\0';
newData = true;
break;
}
}
Serial.println("O"); // outside while
if(newData) {
Serial.println(data);
}
}
The output constantly reads
T 120
T 120
...
Apparently Serial.available() becomes false after '120' is transmitted and no newline or other characters are detected over all the Serial.read() command that follows. Until the next telegram is transmitted ("x12").
Removing the debugging prints (T,O,N) does not affect the output, so it should not be a timing issue.