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

Support low latency mode #3

Open
jessebraham opened this issue Feb 7, 2022 · 1 comment
Open

Support low latency mode #3

jessebraham opened this issue Feb 7, 2022 · 1 comment
Labels
migrated This issue was migrated from GitLab

Comments

@jessebraham
Copy link
Member

This issue was migrated from GitLab. The original issue can be found here:
https://gitlab.com/susurrus/serialport-rs/-/issues/55

USB serial ports can have a latency problem when you're trying to receive small packets of data, because they try to buffer data to put into one USB packet for efficiency. For example FTDI serial ports have a timeout of 16 milliseconds by default, and if you're only receiving a few bytes at a time, you will only receive data every 16ms.

Linux supports an ASYNC_LOW_LATENCY which asks drivers to have less latency (perhaps at the efficiency of transferring large amounts of data) which alleviates this problem. Windows also seems to have a similar thing using the COMMTIMEOUTS struct (not tested). I couldn't immediately find a similar setting for macOS.

Having a set_low_latency method on platforms that support it would be useful.

@jessebraham jessebraham added the migrated This issue was migrated from GitLab label Feb 7, 2022
@michaellass
Copy link

michaellass commented Jun 29, 2023

We needed this functionality as well and created a separate small crate for it: https://github.com/michaellass/serialport_low_latency. It uses the TIOCGSERIAL and TIOCSSERIAL ioctls to change the serial line information and enable or disable low latency mode. This is basically the same as a setserial /dev/tty... low_latency would do.

It would be nice to incorporate this functionality directly into this crate. The reason why we haven't patched this into serialport-rs is portability and the necessity to run bindgen during build:

  • The numbers for the ioctls differ between CPU architectures. Hence, we are currently using bindgen on <asm/ioctls.h> to determine the correct values.
  • serialport-rs is cross-platform. I have no idea how to enable/disable the low latency mode on other Unixes or Windows.

Note that, if you have root permissions, it should also be possible to just write 1 into /sys/bus/usb-serial/devices/tty.../latency_timer. However, that file is typically writable only for root while the ioctls work for whoever can write to the tty device.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
migrated This issue was migrated from GitLab
Projects
None yet
Development

No branches or pull requests

2 participants