尝试使用 pyusb 从 USB 设备读取时,我一直遇到"usb.core.USBError: [Errno 16] Resource busy"



我正试图使用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(),它应该起作用。

相关内容

  • 没有找到相关文章

最新更新