3 releases

0.1.2 Jan 26, 2025
0.1.1 Jan 26, 2025
0.1.0 Jul 8, 2024

#295 in Asynchronous

Download history 37/week @ 2024-10-23 8/week @ 2024-10-30 43/week @ 2024-11-06 25/week @ 2024-11-13 22/week @ 2024-11-20 19/week @ 2024-11-27 111/week @ 2024-12-04 44/week @ 2024-12-11 10/week @ 2024-12-18 56/week @ 2024-12-25 114/week @ 2025-01-01 164/week @ 2025-01-08 213/week @ 2025-01-22 34/week @ 2025-01-29 11/week @ 2025-02-05

262 downloads per month

MIT/Apache

14KB
186 lines

Crate kioto-serial

Crates.io Documentation Crate License

Provide serial port I/O using tokio.

Except on Windows (see below), the implementation uses synchronous blocking I/O to the serial port in newly spawned threads (one for reading and a cloned handle for writing) and then wraps these with asynchronous channels.

This crate provides an interface very similar to tokio-serial with a different implementation. Ideally, it can serve as a drop-in replacement. In other words, in Cargo.toml [dependencies] section, you could use

tokio-serial = { package = "kioto-serial", version = "0.1.0" }

and continue with code originally written for tokio-serial.

In Windows, tokio-serial is re-rexported because the approach used here, cloning the serial port handle, simply does not work. Specifically, a blocking read from the port blocks writing. (Potential future investigation: use an async implementation using overlapped I/O based on sources such as serial2 or rust-serial-prototype or implement our own async implementation using overlapped I/O based on sources such as this or this.)

Why write this and not just use tokio-serial?

As noted above, this crate uses spawned threads and blocking serial I/O. Theoretically, this is not optimal because it is an async facade over a fundamentally blocking implementation. So why are we taking this approach?

We were experiencing long latencies from the tokio scheduler when using tokio-serial. Specifically, in a linux program involving simultaneous serial connections to different devices and other tokio tasks such as a webserver and a tokio::time::Interval timer with 1 msec resolution, the ticks from the timer would be very irregular. In the process of debugging, we wrote kioto-serial and found that using it instead of tokio-serial solved this latency issue. Since that point, we have not delved deeper into tokio-serial to attempt to localize the issue. See https://github.com/berkowski/tokio-serial/issues/72.

License

Licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~5–14MB
~168K SLoC