arduino / arduino/ArduinoCore-API
add isFlushed() to Stream/HardwareSerial
- Dominant language
- C++
- Stars
- 306
- Forks
- 150
- PR merge metrics
- No merged PRs in 30d
Description
Please add Serial.isFlushed() method for checking that all data in Tx buffer have been flushed. We need it for non-blocking Serial.write() to half duplex communication (such as RS485).
At the moment I use something like this in my non-blocking code:
```
while (Serial.availableForWrite() > 0 && ndx < sizeof(buffer)) {
Serial.write(buffer[ndx]);
ndx++;
}
if (Serial.availableForWrite() == SERIAL_TX_BUFFER_SIZE - 1 && ndx > sizeof(buffer)) {
ndx = 0;
// Disable RS485 transmit and start receiving
}
```
But Serial.availableForWrite() == SERIAL_TX_BUFFER_SIZE - 1 is not reliable for checking that Tx buffer has been flushed.
Here is an earlier PR which was never merged:
https://github.com/arduino/Arduino/pull/3737
and a similar PR for ArduinoCore-sam here:
https://github.com/arduino/ArduinoCore-sam/pull/7
I would help, but coding Arduino core is beyond my skills.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reviewing Stream/HardwareSerial and the earlier Arduino PRs linked in the issue to understand the proposed API and affected core implementations. Verify how transmit-buffer state is exposed today, then define done as Serial.isFlushed() reliably reporting that all transmit data has left the buffer for half-duplex use, with matching coverage where the relevant cores test serial behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- api, embedded-iot
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100