0

My code to retrieve a value from a USB device in Python is as follows:

import usb.core
import usb.util

VENDOR_ID = 0x0922
PRODUCT_ID = 0x8005

# find the USB device
device = usb.core.find(idVendor=VENDOR_ID,
                       idProduct=PRODUCT_ID)

# use the first/default configuration
device.set_configuration()
# first endpoint
endpoint = device[0][(0,0)][0]

# read a data packet
attempts = 10
data = None
while data is None and attempts > 0:
    try:
        data = device.read(endpoint.bEndpointAddress,
                           endpoint.wMaxPacketSize)
    except usb.core.USBError as e:
        data = None
        if e.args == ('Operation timed out',):
            attempts -= 1
            continue

print data

When I run this is the error message:

File "/Library/Python/2.7/site-packages/usb/backend/libusb1.py", line 552, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 19] No such device (it may have been disconnected)

Why is this happening and how can I fix it? Thanks!

James Anderson
  • 556
  • 3
  • 16
  • 41
  • 5
    can you post the whole traceback to see where the error occurs? – WoJ May 16 '15 at 14:32
  • Just in case, make sure you add the basic control error code: `# was it found? if device is None: raise ValueError('Device not found')` – Layo May 16 '15 at 14:37
  • http://ubuntuforums.org/archive/index.php/t-2044904.html check this might be helpful Your code didn't show any errors for my external hard disk,after i've added few permissions @ /etc/udev/rules.d/99-garmin.rules.But i got an error for my dongle. – Ajay May 17 '15 at 12:24
  • What does `lsusb` show? – kichik May 21 '15 at 18:19

1 Answers1

1

well you should follow all necessary steps from the tutorial, especially the part where the device is searched. https://github.com/walac/pyusb/blob/master/docs/tutorial.rst

and: are you sure your device matches the defined vendor and product id? You can use lsusb to identify the USB device and grab the ids from there. http://www.linuxnix.com/2013/05/find-usb-device-details-in-linuxunix-using-lsusb-command.html

aronadaal
  • 9,083
  • 1
  • 19
  • 33