I read a comment form here:
"Serial.setTimeout() sets the maximum milliseconds to wait for serial data when using Serial.readBytesUntil(), Serial.readBytes(), Serial.parseInt() or Serial.parseFloat(). It defaults to 1000 milliseconds."
According to the latest webpage,
"Serial functions that use the timeout value set via Serial.setTimeout():
Serial.find()
Serial.findUntil()
Serial.parseInt()
Serial.parseFloat()
Serial.readBytes()
Serial.readBytesUntil()
Serial.readString()
Serial.readStringUntil()
"
So apparently, there's no direct indication to set a timeout option for Serial.read().
How to set a time out like Serial.setTimeout() for Serial.read()?
1 Answer 1
You can't set timeout for read(), but you can use readBytes() to read one byte.
byte b;
int count = Serial.readBytes(&b, 1); // read one byte with timeout
if (count) { // 0 or 1
Serial.write(b); //echo
}
-
So Serial.read() and Serial.readBytes() were like two different class of objects?ShoutOutAndCalculate– ShoutOutAndCalculate2020年01月27日 05:50:52 +00:00Commented Jan 27, 2020 at 5:50
-
1no. read() is the basic function. readBytes() is a function too and implemented with use of read().2020年01月27日 05:52:30 +00:00Commented Jan 27, 2020 at 5:52