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

USART serial availableForWrite() not working #1017

Closed
rickkas7 opened this issue Jun 6, 2016 · 3 comments

Comments

@rickkas7
Copy link
Contributor

commented Jun 6, 2016

There’s a simple typo in the implementation of USARTSerial::availableForWrite():

int USARTSerial::availableForWrite(void)
{
return HAL_USART_Available_Data(_serial);
}
int USARTSerial::available(void)
{
return HAL_USART_Available_Data(_serial);
}

https://github.com/spark/firmware/blob/develop/wiring/src/spark_wiring_usartserial.cpp#L69

It should probably be HAL_USART_Available_Data_For_Write. However, if I fix that and use it with code like:

        Serial.printlnf("%d", Serial1.availableForWrite());
        Serial1.println("01234567890123456789012345678901234567890123456789");
        Serial.printlnf("%d", Serial1.availableForWrite());

The output is:

0
50

I’m unclear of how the function is supposed to work. Should it:

  1. Return the number of bytes waiting to be written out from the buffer (0=empty send buffer), which is what it does.
  2. Return the number of bytes you can write to the buffer without blocking, which would be SERIAL_BUFFER_SIZE - the value currently returned.

Thanks,
Rick


Completeness:

  • Minimum test case added
  • Device, system and user firmware versions stated
  • Particle confirmed
@m-mcgowan

This comment has been minimized.

Copy link
Contributor

commented Jun 7, 2016

@avtolstoy Any thoughts on this?

@avtolstoy

This comment has been minimized.

Copy link
Member

commented Jun 7, 2016

Confirmed and fixed in #1020 :

  1. A typo in USARTSerial::availableForWrite()
  2. availableForWrite() behavior, which should behave as described in docs:

Retrieves the number of bytes (characters) that can be written to this serial port without blocking.

@rickkas7

This comment has been minimized.

Copy link
Contributor Author

commented Jun 7, 2016

Thanks! Sorry, I swear I looked it up in the docs and didn’t see it, but yes, the correct behavior is documented.

@rickkas7 rickkas7 closed this Jun 7, 2016

@technobly technobly added the bug label Jun 10, 2016

@technobly technobly added this to the 0.6.x milestone Jun 10, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.