我正在尝试从操纵杆中读取按钮和其他信息。我的代码给我一个“错误13:访问被拒绝”
Traceback (most recent call last):
File "./JOYSTICK.py", line 17, in <module>
ep.wMaxPacketSize)
File "/usr/local/lib/python3.6/site-packages/usb/core.py", line 975, in read
intf, ep = self._ctx.setup_request(self, endpoint)
File "/usr/local/lib/python3.6/site-packages/usb/core.py", line 102, in wrapper
return f(self, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/usb/core.py", line 216, in setup_request
self.managed_claim_interface(device, intf)
File "/usr/local/lib/python3.6/site-packages/usb/core.py", line 102, in wrapper
return f(self, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/usb/core.py", line 167, in managed_claim_interface
self.backend.claim_interface(self.handle, i)
File "/usr/local/lib/python3.6/site-packages/usb/backend/libusb1.py", line 811, in claim_interface
_check(self.lib.libusb_claim_interface(dev_handle.handle, intf))
File "/usr/local/lib/python3.6/site-packages/usb/backend/libusb1.py", line 595, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 13] Access denied (insufficient permissions)
我尝试使用sudo python3 JOYSTICK.py
(具有正确的shebang)以sudo模式启动它,但是它不起作用。我也尝试过以sudo激活我的虚拟环境,但是从根目录启动时,它无法识别source
命令。
#!/usr/bin/env python3
import usb.core
dev = usb.core.find(idVendor=0x044f, idProduct=0xb108)
dev.set_configuration(1) # from print usb.core.find()
cfg = dev.get_active_configuration()
intf = cfg[(0,0)]
ep = intf[0]
print(ep)
while (True):
data = dev.read(ep.bEndpointAddress,
ep.wMaxPacketSize)
print(data)
我希望我的代码在按下操纵杆上的按钮或更改轴时显示换行符。
谢谢。