I keep getting "usb.core.USBError: [Errno 16] Resource busy" when trying to read from a USB device using pyusb

I keep getting "usb.core.USBError: [Errno 16] Resource busy" when trying to read from a USB device using pyusb

我正在尝试使用 Pyusb 模块 Python 与此设备通信

设备是 DualSense Ps5 控制器,我是 运行 Rasbian Lite(没有桌面环境)

到目前为止我的代码是:

import usb.core

dev = usb.core.find(idVendor=0x054c,idProduct=0x0ce6)
ep = dev[0].interfaces()[5].endpoints()[0]

i = dev[0].interfaces()[5].bInterfaceNumber

dev.reset()

if dev.is_kernel_driver_active(i):
    dev.detach_kernel_driver(i)
    
dev.set_configuration()

eaddr = ep.bEndpointAdress

r = dev.read(eaddr,1024)
print(len(r))

我不断收到的错误是:

Traceback (most recent call last):
  File "readUsb.py", line 25, in <module>
    dev.set_configuration()
  File "/usr/local/lib/python3.7/dist-packages/usb/core.py", line 905, in set_configuration
    self._ctx.managed_set_configuration(self, configuration)
  File "/usr/local/lib/python3.7/dist-packages/usb/core.py", line 113, in wrapper
    return f(self, *args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/usb/core.py", line 159, in managed_set_configuration
    self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
  File "/usr/local/lib/python3.7/dist-packages/usb/backend/libusb1.py", line 812, in set_configuration
    _check(self.lib.libusb_set_configuration(dev_handle.handle, config_value))
  File "/usr/local/lib/python3.7/dist-packages/usb/backend/libusb1.py", line 604, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 16] Resource busy

我对USB设备如何通信知之甚少,我选择的接口有点随意。如果您有任何关于如何释放此资源或与一般设备通信的建议,我们将不胜感激。

以下对我有用:

if dev.is_kernel_driver_active(i):
    try:
        dev.detach_kernel_driver(i)
    except usb.core.USBError as e:
        sys.exit("Could not detatch kernel driver from interface({0}): {1}".format(i, str(e)))

如果这不起作用,请使用它,但也要删除 dev.set_configuration(),它应该会起作用。