I have modify the read_control() in device_handle.rs to print out some useful informations:
pub fn read_control(&self, request_type: u8, request: u8, value: u16, index: u16, buf: &mut [u8], timeout: Duration) -> ::Result<usize> {
if request_type & LIBUSB_ENDPOINT_DIR_MASK != LIBUSB_ENDPOINT_IN {
return Err(Error::InvalidParam);
}
let ptr = buf.as_mut_ptr() as *mut c_uchar;
let len = buf.len() as u16;
let timeout_ms = (timeout.as_secs() * 1000 + timeout.subsec_nanos() as u64 / 1_000_000) as c_uint;
let res = unsafe {
println!("libusb_control_transfer: len {:?}",len);
libusb_control_transfer(self.handle, request_type, request, value, index, ptr, len, timeout_ms)
};
println!("libusb_control_transfer: res {:?}",res);
if res < 0 {
Err(error::from_libusb(res))
} else {
Ok(res as usize)
}
}
When I try to read my bluetooth HID mouse, I got the error.
Here is the out put:
libusb_control_transfer: len 256
libusb_control_transfer: res -8
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Overflow', src\libcore\result.rs:999:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
I have modify the read_control() in device_handle.rs to print out some useful informations:
When I try to read my bluetooth HID mouse, I got the error. Here is the out put:
After modify
to
it just works. Here is the output:
My enviroment: Default host: x86_64-pc-windows-gnu installed toolchains nightly-2019-04-21-i686-pc-windows-msvc (default) installed targets for active toolchain i686-pc-windows-msvc nightly-2019-04-21-i686-pc-windows-msvc (default) rustc 1.36.0-nightly (33fe1131c 2019-04-20)
libusb-1.0.dll version: 1.0.20.11004