'pyUSB not reading data but recognizing device
I am trying to read data from a custom PCB using pyUSB.
import usb.core
vid = 0xffff
pid = 0xfeff
device = usb.core.find(idVendor=vid, idProduct=pid)
print(device)
if I run the above, it recognizes the device. But if I try to read data from usb with the below code I get an error.
import usb.core
import usb.util
import sys
from time import sleep
vid = 0xffff
pid = 0xfeff
dev = usb.core.find(idVendor=vid, idProduct=pid)
if dev is None:
raise ValueError('Device not found')
dev.set_configuration()
cfg = dev.get_active_configuration()
intf = cfg[(0,0)]
ep = usb.util.find_descriptor(intf,custom_match = lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_IN)
assert ep is not None
#the error comes from these three lines
while True:
resp = ep.read(100,1000)
print(resp)
Running this code gives me the following error:
File "test_usb.py", line 24, in resp = ep.read(100,1000) File "/Users/Me/opt/anaconda3/lib/python3.7/site-packages/usb/core.py", line 423, in read return self.device.read(self, size_or_buffer, timeout) File "/Users/Me/opt/anaconda3/lib/python3.7/site-packages/usb/core.py", line 1021, in read intf, ep = self._ctx.setup_request(self, endpoint) File "/Users/Me/opt/anaconda3/lib/python3.7/site-packages/usb/core.py", line 113, in wrapper return f(self, *args, **kwargs) File "/Users/Me/opt/anaconda3/lib/python3.7/site-packages/usb/core.py", line 229, in setup_request self.managed_claim_interface(device, intf) File "/Users/Me/opt/anaconda3/lib/python3.7/site-packages/usb/core.py", line 113, in wrapper return f(self, *args, **kwargs) File "/Users/Me/opt/anaconda3/lib/python3.7/site-packages/usb/core.py", line 178, in managed_claim_interface self.backend.claim_interface(self.handle, i) File "/Users/Me/opt/anaconda3/lib/python3.7/site-packages/usb/backend/libusb1.py", line 829, in claim_interface _check(self.lib.libusb_claim_interface(dev_handle.handle, intf)) File "/Users/Me/opt/anaconda3/lib/python3.7/site-packages/usb/backend/libusb1.py", line 604, in _check raise USBError(_strerror(ret), ret, _libusb_errno[ret]) usb.core.USBError: [Errno 13] Access denied (insufficient permissions)
Other notes: I installed pyusb using pip, and tried to install libusb but not sure if installed correctly. I have gotten the same results on both Mac & Windows.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
