jonad
New Member
Posts: 1
|
Post by jonad on Nov 14, 2018 13:32:10 GMT
Hello everybody,
I am facing a problem during using the Serial.available() function.
I am triggering a 8 byte response from a sensor and waiting with a while loop til Serial.available() gives me 10 bytes in the input buffer (s. code Below). Now is the problem that the Serial.available() function gives me a return value of 118 despite 10 byte in the input buffer (s. Programm printout).
Is anybody familiar with this and can help me solve this problem?
LG Jona Programm Printout: . . . 6 Here 10 Here
6 Here 118 <- Strange Serial.available() value Here 6 38 0 255 45 0 76 209 36 134 (bold marked bytes in input buffer 10 ) 0 Here 0 Here 0 Here 0 Here 0 Here 0 Here . . (endless loop)
Program Code:
void loop()
{
Serial.write(0x06);
Serial.flush();
delayMicroseconds(220); // wait for measurement to be finished
Serial.write(0x26);
Serial.flush();
while (Serial.available() != 10) // waiting till all bytes from sensor arrived (10 bytes)
{
delay(1);
SerialASC.println(Serial.available());
SerialASC.println("Here");
if (Serial.available() == 118)
{
while(Serial.available() > 0)
{
SerialASC.println(Serial.read());
}
}
}
Serial.read(); // deleting sent bytes
Serial.read();
Serial.read();
Serial.read();
Serial.read();
Serial.read();
Serial.read();
Serial.read();
Serial.read();
Serial.read();
SerialASC.println(" ");
}
|
|