Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Serial.availableForWrite function #798
We can check if the TX buffer is full or not to allow applications to implement flow control.
Currently, the hardware serial devices corrupt data if fed too quickly. I feel the default should be to block until the buffer is emptied, so the application doesn't have to concern itself with how fast it writes data by default. For most, having the correct data output is more important than writing it quickly and getting corrupted data. For cases where performance is critical, a new method.
The USB serial device write function includes a delay as a simple form of flow control. Instead, it should check if the buffer would overrun and block, similarly to Serial1. One additional point is that the buffer is not emptied if no USB host is connected, so the method should block only when a host is connected. This can be detected by checking the established linerate.