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

Read not reading all the data off a TTY port #97

Open
Austin-Crabtree opened this issue May 4, 2023 · 7 comments
Open

Read not reading all the data off a TTY port #97

Austin-Crabtree opened this issue May 4, 2023 · 7 comments

Comments

@Austin-Crabtree
Copy link

Using:

  • Beaglebone Black Rev C
  • Linux Debian 10
  • Rust 1.68.2
  • Serialport 4.2.0

when reading off a Beaglebone Black UART connection I am running into an issue when I have a message larger than 52 bytes not being pulled off the TTY buffer in one read, typically takes two reads. I am creating a sufficiently large enough buffer and the read isn't filling the vector. I have tried both open() and open_native() on the port with no help. I also have narrowed it down to the read being the issue becuase I have put a clear(ClearBuffer::All) after reading and parsing the data and I can't get the second half of the data anymore.

@mlsvrts
Copy link
Contributor

mlsvrts commented May 4, 2023

Does bytes_to_read indicate that there are 52 bytes available when you read?

Do you always get the same number of bytes from the first read request, or does it vary?

I'm wondering if the OS driver is doing some sort of buffering here...

@Austin-Crabtree
Copy link
Author

I haven't check the bytes_to_read function I can do that. But the amount of bytes to read is is variable based on the type of message that is being sent. All other messages are requests and don't have a data payload so each other message is the same size about 14 bytes in size.

@Austin-Crabtree
Copy link
Author

I will also say that I checked against my rust application by creating a quick python script using pyserial and was able to read all the data in one read.

@DanielJoyce
Copy link

DanielJoyce commented May 5, 2023

Raspberry PI Uart is 16 bytes. PySerial probably caches internally to another buffer transparently to read by other processes.

You're gonna need to read in a loop until there are no more bytes to read, stuffing them into a bigger buffer

@DanielJoyce
Copy link

https://github.com/pyserial/pyserial/blob/31fa4807d73ed4eb9891a88a15817b439c4eea2d/serial/serialposix.py#L570

Here, it reads into a buffer in a loop, only returning when the buffer is full, or timeout.

You will need to imple the same logic as serialport-rs is pretty low level.

@newcomertv
Copy link

This seems like a bug not a feature.. I'd expect a serial interface reader to read until the buffer is full or the transmission has timed-out if I can configure buffer size and timeout duration..

Is there a use-case where this is desired behaviour?

@DanielJoyce
Copy link

Its a feature since folks may want to buffer, some don't. Since you want to buffer, you need to buffer yourself.

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

4 participants