按照各技术贴的配置方法,已经在libusb中的这几个文件做了修改,添加了liusb_open_fd函数。安卓方也做了权限设置。但是在调用我方提供的openDev函数后,出现了崩溃的现象,经过排查是调用了libusb_open_fd函数后奔溃。openDev中就是这样写的。请各路大牛能帮我提供问题出现的原因或者解决方法。在此感谢!!!!急!!!
这是解决崩溃后的
```int IBUsbDev:: OpenDevice(int fd)
{
libusb_device **devs; //pointer to pointer of device, used to retrieve a list of devices
int ret = (-1);
int cnt=0;
int configure = 1;
if (libusb_init(&ctx) < 0) //initialize a library session
{
return (-1);
}
libusb_set_debug(ctx, LIBUSB_LOG_LEVEL_INFO);
cnt=libusb_get_device_list(ctx,&devs); //get the list of devices
if(cnt < 0) {
perror("Get Device Error\n"); //there was an error
return 1;
}
ret = libusb_open_fd(*devs,&udev,fd);
if(ret!=0)
{
printf("Cannot open device\n");
libusb_exit(ctx);
return -2;
}
libusb_free_device_list(devs, 1);
//libusb_detach_kernel_driver(udev,0);
libusb_reset_device(udev);
libusb_get_configuration(udev,&configure);
if(libusb_kernel_driver_active(udev, 0) == 1) { //find out if kernel driver is attached
cout<<"Kernel Driver Active"<<endl;
if(libusb_detach_kernel_driver(udev, 0) == 0) //detach it
cout<<"Kernel Driver Detached!"<<endl;
}
ret = libusb_claim_interface(udev, 0);
if (ret<0)
{
return (ret);
}
return 0;
}