我正在尝试使用libusb,但收到以下错误消息:
usbfs:进程 24665(myprogram)在使用前未声明接口 0
我真的不明白为什么,因为据我所知,我是根据图书馆中的描述来做的。这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <libusb.h>
int main(void)
{
int result;
struct libusb_device_descriptor desc;
libusb_device **list;
libusb_device *my_device = NULL;
result = libusb_init(NULL);
libusb_set_debug(NULL, 3);
ssize_t count = libusb_get_device_list(NULL, &list);
for (int i = 0; i < count; i++) {
libusb_device *device = list[i];
result = libusb_get_device_descriptor(device, &desc);
if((desc.idVendor == 0x03f0) && (desc.idProduct == 0x241d)) {
my_device = device;
break;
}
}
if(my_device != NULL) {
libusb_device_handle *handle;
result = libusb_open(my_device, &handle);
int kernelActive = libusb_kernel_driver_active(handle, 0);
if(kernelActive == 1) {
result = libusb_detach_kernel_driver(handle, 0);
}
result = libusb_claim_interface (handle, 0);
result = libusb_control_transfer(handle,0x21,34,0x0003,0,NULL,0,0);
result = libusb_release_interface (handle, 0);
if(kernelActive == 1) {
result = libusb_attach_kernel_driver(handle, 0);
}
libusb_close(handle);
}
libusb_free_device_list(list, 1);
libusb_exit(NULL);
return EXIT_SUCCESS;
}
如您所见,我确实在转移之前声明了接口。(我也在其他 USB 设备上尝试过相同的代码,以防万一这与它有关。)
我正在使用 libusb-1.0.9,这是我能找到的最新版本。我在Ubuntu 12.04_64 (Precise Pangolin) 上运行这个东西。