36 stable releases

2.6.1 Mar 2, 2024
2.5.1 Jan 28, 2024
2.4.1 Jul 21, 2023
2.2.0 Mar 6, 2023
0.2.0 Mar 12, 2016

#5 in Hardware support

Download history 23412/week @ 2024-01-02 26869/week @ 2024-01-09 27122/week @ 2024-01-16 27988/week @ 2024-01-23 31539/week @ 2024-01-30 25684/week @ 2024-02-06 19532/week @ 2024-02-13 24686/week @ 2024-02-20 25743/week @ 2024-02-27 27205/week @ 2024-03-05 26598/week @ 2024-03-12 28666/week @ 2024-03-19 25747/week @ 2024-03-26 28464/week @ 2024-04-02 27272/week @ 2024-04-09 23547/week @ 2024-04-16

108,646 downloads per month
Used in 232 crates (111 directly)

MIT license

410KB
9K SLoC

C 5K SLoC // 0.2% comments Rust 4K SLoC // 0.1% comments Automake 28 SLoC

hidapi Version License: MIT Documentation Chat

This crate provides a rust abstraction over the features of the C library hidapi. Based off of hidapi-rs by Osspial.

Usage

This crate is on crates.io and can be used by adding hidapi to the dependencies in your project's Cargo.toml.

Example

extern crate hidapi;

let api = hidapi::HidApi::new().unwrap();
// Print out information about all connected devices
for device in api.device_list() {
    println!("{:#?}", device);
}

// Connect to device using its VID and PID
let (VID, PID) = (0x0123, 0x3456);
let device = api.open(VID, PID).unwrap();

// Read data from device
let mut buf = [0u8; 8];
let res = device.read(&mut buf[..]).unwrap();
println!("Read: {:?}", &buf[..res]);

// Write data to device
let buf = [0u8, 1, 2, 3, 4];
let res = device.write(&buf).unwrap();
println!("Wrote: {:?} byte(s)", res);

Documentation

Available at docs.rs.

Dependencies

~0–11MB
~98K SLoC