Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add isFlushed() to Stream/HardwareSerial #110

Open
budulinek opened this issue Apr 5, 2020 · 0 comments
Open

add isFlushed() to Stream/HardwareSerial #110

budulinek opened this issue Apr 5, 2020 · 0 comments

Comments

@budulinek
Copy link

budulinek commented Apr 5, 2020

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:
arduino/Arduino#3737

and a similar PR for ArduinoCore-sam here:
arduino/ArduinoCore-sam#7

I would help, but coding Arduino core is beyond my skills.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant