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 Thanks, Ryan On Tue, Dec 25, 2012 at 11:10 AM, Wander Lairson Costa < wander.lair...@gmail.com> wrote: > 2012/12/24 Ryan Speers <rmspe...@gmail.com>: > > Hello, > > > > I'm trying to update a program to support the new pyUSB 1.x. I'm having > > several issues: > > > > First of all, legacy support isn't being compatible -- this is because > the > > code uses the bus and dev numbers, such as 002:005, to indicate a unique > > device. The code needs to be able to express the fact that there are > > possibly many devices of the exact same type plugged in, and that is one > of > > the reasons this numbering scheme allows us to make a short identifier > > accessible to the user. When pyUSB 1.x loads and does the usb.legacy > import, > > I then don't get these numbers back. The first place the code uses them > is > > when it scans for devices, and reports them in part using: > > ''.join([bus.dirname + ":" + dev.filename]) > > In the new code, I think I'd do a find_all to get all the devices I want, > > but then how do I give the user nice selectors they can feed back in to > > choose which device to use for specific things? > > > > The other issue is I don't see an elegant way to know which version of > pyUSB > > I have installed at runtime, so that I can have the code handle things > > differently, if needed. Currently what I found is to try to import > usb.core > > and if it fails, I know I'm in the 0.x code, and if it succeeds, I know > I'm > > in 1.x. Anyone have better ideas? > > > > Hi, > > I didn't get exactly what you are trying to do. Do you want your > application support both PyUSB 1 and 0.x or are you trying to use > PyUSB 1.0 legacy mode? PyUSB has the bus number and bus address > attributes [1]. Legacy mode currently put every device in a fake bus, > but this will change. > > [1] https://github.com/walac/pyusb/blob/master/docs/tutorial.rst. > Section "Dealing with multiple identical devices". > > -- > Best Regards, > Wander Lairson Costa > > > ------------------------------------------------------------------------------ > LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial > Remotely access PCs and mobile devices and provide instant support > Improve your efficiency, and focus on delivering more value-add services > Discover what IT Professionals Know. Rescue delivers > http://p.sf.net/sfu/logmein_12329d2d > _______________________________________________ > pyusb-users mailing list > pyusb-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/pyusb-users >
------------------------------------------------------------------------------ Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery and much more. Keep your Java skills current with LearnJavaNow - 200+ hours of step-by-step video tutorials by Java experts. SALE $49.99 this month only -- learn more at: http://p.sf.net/sfu/learnmore_122612
_______________________________________________ pyusb-users mailing list pyusb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pyusb-users