2012/12/26 Ryan Speers <rmspe...@gmail.com>:
> Hello,
>
> Thanks --  I think that usb.legacy isn't exactly compatible yet in this
> regard, specifically as the bus.dirname and dev.filename attributes aren't
> set. So, I've decided to go ahead and detect what version of pyUSB is being
> used (by trying to import usb.core and catching the exception).
>
> But, here is the issue I'm having... when going down the USBVER==1 branch, I
> get timeout errors after the first connection attempt.
>         My device, an RZUSBSTICK has a hierarchy of:
>             Config value: 1
>                 Interface number 0, with alternate setting 0
>                     Endpoint 132 for responses
>                     Endpoint 2   for control
>                     Endpoint 129 for packets
>
> What I do for setup is:
> self.dev.set_configuration(1)
> self.dev.set_interface_altsetting(interface = 0, alternate_setting = 0)
>
> Then, in my write function, you see the following (first comes the pyUSB 0.x
> code, then the 1.x code as marked):
>         if USBVER == 0:
>             try:
>                 self.handle.bulkWrite(endpoint, data)
>                 # Returns a tuple, first value is an int as the RZ_RESP_*
> code
>                 response = self.handle.bulkRead(RZ_USB_RESPONSE_EP, 1)[0]
>             except usb.USBError, e:
>                 if e.args != ('No error',): # http://bugs.debian.org/476796
>                     raise e
>             time.sleep(0.0005)
>             if response != RZ_RESP_SUCCESS:
>                 if response in RESPONSE_MAP:
>                     raise Exception("Error: %s" % RESPONSE_MAP[response])
>                 else:
>                     raise Exception("Unknown USB write error: 0x%02x" %
> response)
>         else: #pyUSB 1.x
>             res = self.dev.write(endpoint, data, 0, 100)
>             if len(data) != res:
>                 raise Exception("Issue writing USB data {0} to endpoint {1},
> got a return of {2}.".format(data, endpoint, res))
>             response = self.dev.read(RZ_USB_RESPONSE_EP, 1, 0, 500).pop()
> #TODO reduce timeout?
>             if response != RZ_RESP_SUCCESS:
>                 if response in RESPONSE_MAP:
>                     raise Exception("Error: %s" % RESPONSE_MAP[response])
>                 else:
>                     raise Exception("Unknown USB write error: 0x%02x" %
> response)
>
> Second set of code:
>         if USBVER == 0:
>             try:
>                 pdata = self.handle.bulkRead(RZ_USB_PACKET_EP, timeout)
>             except usb.USBError, e:
>                 if e.args != ('No error',): # http://bugs.debian.org/476796
>                     if e.args[0] != "Connection timed out": # USB timeout
> issue
>                         print "Error args:", e.args
>                         raise e
>         else: # pyUSB 1.x
>             pdata = self.dev.read(RZ_USB_PACKET_EP, 1, 0, 100)
>             #TODO error handling
>
> The 0.x code has some odd code in there to deal with errors I've had in the
> past. Here is the exception I get back when the second self.dev.read() is
> called. I get the timeout error if I call the read on this second endpoint,
> as shown below, or if I call it on the first endpoint again (by running the
> program again).
>
> zbdump: listening on '2:12', link-type DLT_IEEE802_15_4, capture size 127
> bytes
> Traceback (most recent call last):
> ...
>   File "/usr/local/lib/python2.7/dist-packages/killerbee/dev_rzusbstick.py",
> line 443, in pnext
>     pdata = self.dev.read(RZ_USB_PACKET_EP, 1, 0, 100)
>   File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 654, in
> read
>     self.__get_timeout(timeout)
>   File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb10.py",
> line 541, in bulk_read
>     timeout)
>   File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb10.py",
> line 641, in __read
>     timeout))
>   File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb10.py",
> line 403, in _check
>     raise USBError(_str_error[ret], ret, _libusb_errno[ret])
> usb.core.USBError: [Errno 110] Operation timed out
>
>

You are using libusb 1.0 when using PyUSB 1.0, and libusb 0.1 when
using PyUSB 0.4. What about forcing libusb0 backend in PyUSB 1.0?

import usb.core
import usb.backend.libusb0

b = usb.backend.libusb0.get()
d = usb.core.find(backend = b, .....)

-- 
Best Regards,
Wander Lairson Costa

------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122712
_______________________________________________
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users

Reply via email to