serialport-stream-rs
Pure event driven implementation of futures::Stream for reading data from serialport utilizing serialport-rs. Produces 1-N amount of bytes depending on polling interval. Initial poll starts background thread which will indefinitely wait for data in event, error or drop. Synchronous API is not available after first poll on stream. There is no backpressure handling, will indefinitely buffer the data.
Installation
Add this to your Cargo.toml:
[]
= "0.1.7"
= "2.0"
Usage
Basic Usage
use ;
use stream;
Using with Tokio
use new;
use StreamExt;
use Duration;
async
Synchronous Read/Write
use ;
let mut stream = new.open?;
// Write data synchronously
stream.write_all?;
stream.flush?;
// Read data synchronously
let mut buffer = ;
let n = stream.read?;
println!;
API Overview
Builder Functions
new(path, baud_rate)- Create a new builder.data_bits(DataBits)- Set data bits (5, 6, 7, 8).flow_control(FlowControl)- Set flow control (None, Software, Hardware).parity(Parity)- Set parity (None, Odd, Even).stop_bits(StopBits)- Set stop bits (One, Two).timeout(Duration)- Set read/write timeout.dtr_on_open(bool)- Control DTR signal on open.open()- Open the port and create the stream
SerialPortStream Methods
- Implements
std::io::Read- Synchronous reading - Implements
std::io::Write- Synchronous writing - Implements
futures::Stream- Asynchronous streaming - Item type:
Result<Vec<u8>, std::io::Error>
License
This project is licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Acknowledgments
This crate builds upon serialport-rs for cross-platform serial port access.