Crates.io | cp211x_uart |
lib.rs | cp211x_uart |
version | 0.2.2 |
source | src |
created_at | 2017-09-28 22:45:35.374419 |
updated_at | 2017-12-31 12:02:52.87162 |
description | HID-to-UART driver for CP2110/CP2114 chipset |
homepage | |
repository | https://github.com/antage/cp211x_uart |
max_upload_size | |
id | 33850 |
size | 14,769 |
HID-to-UART driver for CP2110/CP2114 chipset.
It is wrapper around hid::Handle
intrinsically.
See documentation for details.
$ sudo apt-get install libudev-dev libhidapi-dev
$ cargo build
extern crate hid;
extern crate cp211x_uart;
use std::time::Duration;
use cp211x_uart::{HidUart, UartConfig, DataBits, StopBits, Parity, FlowControl};
fn run() -> Result<(), cp211x_uart::Error> {
let manager = hid::init()?;
for device in manager.find(Some(0x10C4), Some(0xEA80)) {
let handle = device.open()?;
let mut uart = HidUart::new(handle)?;
let config = UartConfig {
baud_rate: 9600,
data_bits: DataBits::Bits8,
stop_bits: StopBits::Short,
parity: Parity::None,
flow_control: FlowControl::None,
};
uart.set_config(&config)?;
uart.set_read_timeout(Duration::from_millis(50));
uart.set_write_timeout(Duration::from_millis(500));
uart.flush_fifos(true, true)?;
uart.write(&[0x01, 0x02, 0x03][..])?;
let mut buf: [u8; 256] = [0; 256];
uart.read(&mut buf)?;
}
}
fn main() {
match run() {
Ok() => {}
Err(err) => {
eprintln!("ERROR: {}", err);
}
}
}
This library licensed under the following: