使用 libusb_open_device_with_vid_pid 打开设备是成功的
使用 libusb_claim_interface 注册接口时候失败 返回值: -6
打印来的结果:usb_claim_interface error -6 No such device or address
折腾了一下午没结果,到这里请教一下 先谢谢了
代码和设备信息如下:
复制代码- static int find_device7001(void)
- {
- devh7001 = libusb_open_device_with_vid_pid(NULL, 0x0925, 0x7001);
- return devh7001 ? 0 : -EIO;
- }
- int main(void){
- libusb_device **devs;
- int r;
- ssize_t cnt;
- r = libusb_init(NULL);
- if (r < 0)
- return r;
- //cnt = libusb_get_device_list(NULL, &devs);
- //if (cnt < 0)
- // return (int) cnt;
- //print_devs(devs);
- //libusb_free_device_list(devs, 1);
- r = find_device7001();
- if (r < 0) {
- fprintf(stderr, "Could not find/open device\n");
- goto out;
- }
- r = libusb_claim_interface(devh7001, 0);
- if (r < 0) {
- fprintf(stderr, "usb_claim_interface error %d %s\n", r, strerror(-r));
- goto out;
- }
- printf("claimed interface\n");
-
-
- out:
- libusb_close(devh7001);
- libusb_exit(NULL);
- return 0;;
- }
|
执行 lsusb是这样的
复制代码- [root@FriendlyARM lib]# lsusb
- Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
- Bus 001 Device 004: ID 0925:7001 Lakeview Research
- Bus 001 Device 003: ID 0925:7002 Lakeview Research
- Bus 001 Device 002: ID 0424:2514 Standard Microsystems Corp.
- Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
|
Bus 001 Device 004: ID 0925:7001 Lakeview Research
Bus 001 Device 003: ID 0925:7002 Lakeview Research
上面这2个是我的设备
-------------------
自己解决了,原因是设备没有激活,代码如下
复制代码-
- Can you detach it? Try
- r = libusb_kernel_driver_active(hd, 0);
- printf("libusb_kernel_driver_active = %d\n", r);
- if (r == 1) {
- r = libusb_detach_kernel_driver(hd, 0);
- printf("libusb_detach_kernel_driver = %d\n", r);
- }
|
[ 此帖被eagleblue在2012-08-03 22:13重新编辑 ]