PyUSB USBError:[Errno无]未知错误

时间:2015-05-11 18:35:12

标签: python usb pyusb

我正在尝试运行set_configuration()方法来连接我的USB设备但收到以下错误:

[Errno None] Unknown error Traceback (most recent call last):
  File "usb_ruf_test.py", line 74, in <module>
    dev.set_configuration()
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 819, in set_configuration
    self._ctx.managed_set_configuration(self, configuration)
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 129, in managed_set_configuration
    self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 786, in set_configuration
    _check(self.lib.libusb_set_configuration(dev_handle.handle, config_value))
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 592, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
USBError: [Errno None] Unknown error

这是我正在使用的代码:

import usb.core
import usb.util
import time
import traceback

attempts = 0
dev = usb.core.find(idVendor=0x0ffd, idProduct=0xff00)
while dev is None:
    attempts += 1
    dev = usb.core.find(idVendor=0x0ffd, idProduct=0xff00)
    print "(" + str(attempts) + " attempts) Waiting 5 seconds before trying again..."
    time.sleep(5)

print "Connected " + str(dev)

try:
    dev.set_configuration()
    cfg = dev.get_active_configuration()

    intf = cfg[(0,0)]

    outputEndpoint = usb.util.find_descriptor(intf, custom_match = lambda e: usb.util.endpoint_direction(e.bEndpointAddress) == usb.util.ENDPOINT_OUT)

    message = reading_start_message()
    print "\nMessage sent:", "\n\n", message, "\n"
    outputEndpoint.write( message )

    print "Received:\n"
    good_reads_count = 0
    result = dev.read(0x81, 2000, 5000)
    while len(result) != 0:
        good_reads_count += 1
        print result.tostring()
        result = dev.read(0x81, 2000, 5000)

    print "Good reads: " + str(good_reads_count)

except Exception, e:
    print("There was an error")
    print e, traceback.format_exc()

print "Disconnected"

这是设备的USB信息:

Connected DEVICE ID 0ffd:ff00 on Bus 001 Address 008 =================
 bLength                :   0x12 (18 bytes)
 bDescriptorType        :    0x1 Device
 bcdUSB                 :  0x200 USB 2.0
 bDeviceClass           :    0x0 Specified at interface
 bDeviceSubClass        :    0x0
 bDeviceProtocol        :    0x0
 bMaxPacketSize0        :   0x40 (64 bytes)
 idVendor               : 0x0ffd
 idProduct              : 0xff00
 bcdDevice              :  0x100 Device 1.0
 iManufacturer          :    0x1 Error Accessing String
 iProduct               :    0x2 Error Accessing String
 iSerialNumber          :    0x0
 bNumConfigurations     :    0x1
  CONFIGURATION 1: 500 mA ==================================
   bLength              :    0x9 (9 bytes)
   bDescriptorType      :    0x2 Configuration
   wTotalLength         :   0x20 (32 bytes)
   bNumInterfaces       :    0x1
   bConfigurationValue  :    0x1
   iConfiguration       :    0x0
   bmAttributes         :   0x80 Bus Powered
   bMaxPower            :   0xfa (500 mA)
    INTERFACE 0: Vendor Specific ===========================
     bLength            :    0x9 (9 bytes)
     bDescriptorType    :    0x4 Interface
     bInterfaceNumber   :    0x0
     bAlternateSetting  :    0x0
     bNumEndpoints      :    0x2
     bInterfaceClass    :   0xff Vendor Specific
     bInterfaceSubClass :    0x1
     bInterfaceProtocol :    0x1
     iInterface         :    0x0
      ENDPOINT 0x81: Bulk IN ===============================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x81 IN
       bmAttributes     :    0x2 Bulk
       wMaxPacketSize   :  0x200 (512 bytes)
       bInterval        :    0x0
      ENDPOINT 0x2: Bulk OUT ===============================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :    0x2 OUT
       bmAttributes     :    0x2 Bulk
       wMaxPacketSize   :  0x200 (512 bytes)
       bInterval        :    0x0

我是pyusb的新手,但我觉得我基本上是按照github page的指示。我正在使用Rasbian OS在树莓派上运行此代码。我也使用Python 2.7.3并以root身份运行。设备只有一个配置和一个接口,所以我做错了什么?

0 个答案:

没有答案