38 stable releases

2.6.3 Aug 7, 2024
2.6.1 Mar 2, 2024
2.4.1 Jul 21, 2023
2.2.0 Mar 6, 2023
0.2.0 Mar 12, 2016

#18 in Hardware support

Download history 37464/week @ 2024-12-08 30835/week @ 2024-12-15 11014/week @ 2024-12-22 18558/week @ 2024-12-29 35906/week @ 2025-01-05 39071/week @ 2025-01-12 36434/week @ 2025-01-19 35555/week @ 2025-01-26 42269/week @ 2025-02-02 43877/week @ 2025-02-09 29016/week @ 2025-02-16 36751/week @ 2025-02-23 38050/week @ 2025-03-02 42852/week @ 2025-03-09 36539/week @ 2025-03-16 39446/week @ 2025-03-23

160,283 downloads per month
Used in 289 crates (122 directly)

MIT license

410KB
9K SLoC

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

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–12MB
~83K SLoC