`libusb_attach_kernel_driver` 不工作

Posted

技术标签:

【中文标题】`libusb_attach_kernel_driver` 不工作【英文标题】:`libusb_attach_kernel_driver` not working 【发布时间】:2015-09-25 15:08:44 【问题描述】:

我在彻底关闭使用libusb 的 Linux 应用程序时遇到问题(内核不回收接口):

int rc;

rc = libusb_reset_device(handle_);
if (rc < 0) 
    cerr << "Error resetting the device: " << libusb_error_name(rc);


for (int ifnum = 0; ifnum < 2; ifnum++) 
    rc = libusb_release_interface(handle_, ifnum);
    if (rc < 0) 
        cerr << "Error releasing interface: " << libusb_error_name(rc);
    
    if (libusb_kernel_driver_active(handle_, ifnum)) 
        cerr << "Reattaching CDC ACM kernel driver.";
        rc = libusb_attach_kernel_driver(handle_, ifnum);
        if (rc < 0) 
            cerr << "Error reattaching CDC ACM kernel driver: " << libusb_error_name(rc);
        
    


libusb_close(handle_);
libusb_exit(NULL);

问题是重新附加内核驱动程序不起作用。实际上libusb_kernel_driver_active 不会返回 1,但即使我将其注释掉并始终调用libusb_attach_kernel_driver,我也永远不会找回我的/dev/ttyACM0 设备。在这种情况下,我得到LIBUSB_ERROR_NOT_FOUND

【问题讨论】:

请使用 libusb_set_debug() 进行详细说明。 【参考方案1】:

我已经调试了 linux cdc-acm 驱动程序附加代码,并找出了问题的根本原因。重新附加不起作用的原因是我声称拥有 CDC ACM 设备的控制和数据接口。如果我只分离/附加控制接口(ifnum == 0),那么一切都按预期工作。这应该记录在某处。

【讨论】:

以上是关于`libusb_attach_kernel_driver` 不工作的主要内容,如果未能解决你的问题,请参考以下文章