Crates.io | hidapi |
lib.rs | hidapi |
version | 2.6.3 |
source | src |
created_at | 2016-03-12 20:40:45.104449 |
updated_at | 2024-08-07 18:17:17.881249 |
description | Rust-y wrapper around hidapi |
homepage | |
repository | https://github.com/ruabmbua/hidapi-rs |
max_upload_size | |
id | 4433 |
size | 538,157 |
This crate provides a rust abstraction over the features of the C library hidapi. Based off of hidapi-rs by Osspial.
This crate is on crates.io and can be
used by adding hidapi
to the dependencies in your project's Cargo.toml
.
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);
Available at docs.rs.