主题 : 使用libusb时遇到的问题 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 13574
精华: 0
发帖: 14
金钱: 75 两
威望: 15 点
贡献值: 0 点
综合积分: 28 分
注册时间: 2010-01-26
最后登录: 2014-03-17
楼主  发表于: 2012-08-03 19:16

 使用libusb时遇到的问题

使用 libusb_open_device_with_vid_pid 打开设备是成功的
使用  libusb_claim_interface 注册接口时候失败 返回值: -6
打印来的结果:usb_claim_interface error -6 No such device or address
折腾了一下午没结果,到这里请教一下 先谢谢了
代码和设备信息如下:
复制代码
  1. static int find_device7001(void)
  2. {
  3.     devh7001 = libusb_open_device_with_vid_pid(NULL, 0x0925, 0x7001);
  4.     return devh7001 ? 0 : -EIO;
  5. }
  6. int main(void){
  7. libusb_device **devs;
  8.     int r;
  9.     ssize_t cnt;
  10.     r = libusb_init(NULL);
  11.     if (r < 0)
  12.         return r;
  13.     //cnt = libusb_get_device_list(NULL, &devs);
  14.     //if (cnt < 0)
  15.     //    return (int) cnt;
  16.     //print_devs(devs);
  17.     //libusb_free_device_list(devs, 1);
  18.     r = find_device7001();
  19.     if (r < 0) {
  20.         fprintf(stderr, "Could not find/open device\n");
  21.         goto out;
  22.     }
  23.     r = libusb_claim_interface(devh7001, 0);
  24.     if (r < 0) {
  25.         fprintf(stderr, "usb_claim_interface error %d %s\n", r, strerror(-r));
  26.         goto out;
  27.     }
  28.     printf("claimed interface\n");
  29.     
  30.     
  31. out:
  32.     libusb_close(devh7001);    
  33.     libusb_exit(NULL);
  34.     return 0;;
  35. }


执行 lsusb是这样的
复制代码
  1. [root@FriendlyARM lib]# lsusb
  2. Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
  3. Bus 001 Device 004: ID 0925:7001 Lakeview Research
  4. Bus 001 Device 003: ID 0925:7002 Lakeview Research
  5. Bus 001 Device 002: ID 0424:2514 Standard Microsystems Corp.
  6. 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个是我的设备

-------------------
自己解决了,原因是设备没有激活,代码如下
复制代码
  1.     
  2. Can you detach it? Try
  3.         r = libusb_kernel_driver_active(hd, 0);
  4.         printf("libusb_kernel_driver_active = %d\n", r);
  5.         if (r == 1) {
  6.                 r = libusb_detach_kernel_driver(hd, 0);
  7.                 printf("libusb_detach_kernel_driver = %d\n", r);
  8.         }
[ 此帖被eagleblue在2012-08-03 22:13重新编辑 ]