// https://forum.arduino.cc/t/sscanf-bug-what-i-am-doing-wrong/1046254
uint32_t myBeginTime;
uint32_t myEndTime;
uint32_t anotherBeginTime;
uint32_t anotherEndTime;
uint32_t bufferEmptyTime;
void setup()
{
Serial.begin(9600);
Serial.println("block no block");
// for (int nn = 10; nn <= 100; nn += 10)
// testBlockNoBlock(nn);
testBlockNoBlock(30);
}
void testBlockNoBlock(int nChars)
{
Serial.print("test with ");
Serial.println(nChars);
Serial.println();
myBeginTime = micros();
for (int i = 0; i < nChars; i ++)
{
Serial.write('X'); // send nChars X
}
Serial.println();
myEndTime = micros();
anotherBeginTime = micros();
Serial.flush();
anotherEndTime = micros();
int nAvailable = Serial.availableForWrite();
Serial.print(nChars);
Serial.print(" blocking time measurment : ");
Serial.println(myEndTime - myBeginTime);
Serial.print(nChars);
Serial.print(" flush() : ");
Serial.println(anotherEndTime - anotherBeginTime);
// - just reports 63. I guess the buffer is never really empty, haha.
// Serial.print(" after serial flush, availableForWrite() = ");
// Serial.println(nAvailable);
Serial.println();
delay(777); // why or why not, that is the question.
myBeginTime = micros();
for (int i = 0; i < nChars; i ++)
{
Serial.write('X'); // send nChars X
}
Serial.println();
myEndTime = micros();
anotherBeginTime = micros();
while (Serial.availableForWrite() != 63); // just hanging out
anotherEndTime = micros();
Serial.print(nChars);
Serial.print(" non-blocking time measurment : ");
Serial.println(myEndTime - myBeginTime);
Serial.print(nChars);
Serial.print(" waiting for buffer to empty : ");
Serial.println(anotherEndTime - anotherBeginTime);
Serial.println("");
}
void loop() { }