hidapi-rs
hidapi-rs copied to clipboard
get_feature_report on Windows fails with DeviceIoControl error
use hidapi::HidApi;
fn main() {
env_logger::init();
let device = HidApi::new()
.expect("Failed to create HidApi instance")
.open(0x6603, 0x1003)
.expect("Failed to open device");
let mut report = [0u8; 512];
let report_r = device.get_feature_report(&mut report);
match report_r {
Ok(_) => {
let bytes: Vec<u8> = report.into_iter().skip(1).take_while(|&x| x != 0x00).collect();
let version = String::from_utf8(bytes).expect("Failed convert bytes to String");
log::debug!("Feature report: {version:#?}");
},
Err(e) => {
log::error!("Failed to get feature report: {e}");
}
}
}
This will fail on Windows with this error:
[2025-06-09T20:01:58Z ERROR] Failed to get feature report: hidapi error: Get Input/Feature Report DeviceIoControl: (0x00000001) Incorrect function.
But will work on Linux with the expected output:
[2025-06-09T20:01:24Z DEBUG fodock] Feature report: "V25.293N3_E.01.005"
As a point of comparison, this code will produce the expected result using nusb, but requires replacing the hidusb driver on Windows.
let (vid, pid) = (0x6603, 0x1003);
let interface = nusb::list_devices()
.expect("Failed to list devices")
.find(|dev| dev.vendor_id() == vid && dev.product_id() == pid)
.expect("Failed to find device")
.open()
.expect("Failed to open device")
.detach_and_claim_interface(0)
.expect("Failed to claim device");
let result = interface.control_in(ControlIn {
control_type: ControlType::Class,
recipient: Recipient::Interface,
request: 0x01,
value: 0x0100,
index: 0,
length: 512,
}).await;