gpt4 book ai didi

c++ - `libusb_attach_kernel_driver` 不工作

转载 作者:IT王子 更新时间:2023-10-29 00:57:40 25 4
gpt4 key购买 nike

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

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

最佳答案

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

关于c++ - `libusb_attach_kernel_driver` 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31280258/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com