add isFlushed() to Stream/HardwareSerial

Open
#110 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
api, embedded-iot

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.

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.

Dominant language
C++
Stars
306
Forks
150
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from arduino/ArduinoCore-API

All issues in arduino/ArduinoCore-API

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.