cp211x_uart

Crates.iocp211x_uart
lib.rscp211x_uart
version0.2.2
sourcesrc
created_at2017-09-28 22:45:35.374419
updated_at2017-12-31 12:02:52.87162
descriptionHID-to-UART driver for CP2110/CP2114 chipset
homepage
repositoryhttps://github.com/antage/cp211x_uart
max_upload_size
id33850
size14,769
(antage)

documentation

https://docs.rs/cp211x_uart

README

cp211x_uart

Documentation License: MIT Build Status

HID-to-UART driver for CP2110/CP2114 chipset. It is wrapper around hid::Handle intrinsically.

See documentation for details.

Building

Linux

$ sudo apt-get install libudev-dev libhidapi-dev
$ cargo build

Usage

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);
        }
    }
}

License

This library licensed under the following:

Commit count: 30

cargo fmt