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

#24 in Hardware support

Download history 32468/week @ 2024-08-03 30938/week @ 2024-08-10 29962/week @ 2024-08-17 31846/week @ 2024-08-24 27042/week @ 2024-08-31 29454/week @ 2024-09-07 20668/week @ 2024-09-14 27808/week @ 2024-09-21 29752/week @ 2024-09-28 30821/week @ 2024-10-05 32859/week @ 2024-10-12 36011/week @ 2024-10-19 36361/week @ 2024-10-26 37082/week @ 2024-11-02 35383/week @ 2024-11-09 32807/week @ 2024-11-16

147,644 downloads per month
Used in 238 crates (116 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
~85K SLoC