out of order - the list didn't like it when I sent it before, so... trying again with the code & messages as an attachment
-Sarah --- On Fri, 2/25/11, Sarah Messer <ikust...@yahoo.com> wrote: Thanks for the patch, Wander. I'm reporting a partial success. your patch fixes the claimInterface() call My code then crashes on the first attempt to write to a bulk-out endpoint on the device. Using my original claim-by-interface code with your patched usb/legacy.py gives the following output. (The first few lines are my own error/warning messages; the ultimate errors are further down in the Traceback) (See the attached file for code & resultant messages) I also tried a work-around with the unpatched pyusb 1.0 and an integer (0) in place of the Interface in the call to claimInterface(). That yielded analogous results, although instead of a TypeError, I think I got a SegmentationFault. I'm going to branch my code into 1.0-friendly and 0.1-friendly versions. If you want to fire patches at me as you have time, I'll try running them through the 0.1-friendly code. In the meantime, I'll try to learn 1.0. What I've seen of 1.0 so far looks like it's much nicer than 0.1, but I'm still trying to learn how it goes. There also seems to be some changes since http://pyusb.sourceforge.net/docs/1.0/tutorial.html was written: Manually stepping through the sample code, I get AttributeError: 'Device' object has no attribute 'get_interface_altsetting' Thanks for putting all this together! As a general comment, I've just discovered "pydoc -w usb"... which makes me giddy. Giddy, I tell you. -Sarah --- On Wed, 2/23/11, wander.lairson <wander.lair...@gmail.com> wrote: From: wander.lairson <wander.lair...@gmail.com> Subject: Re: [pyusb-users] TypeError with legacy DeviceHandle.claimInterface(Interface) To: pyusb-users@lists.sourceforge.net Cc: "Sarah Messer" <ikust...@yahoo.com> Date: Wednesday, February 23, 2011, 3:22 PM [snip] The wiki page that I used to use for reference (http://wiki.erazor-zone.de/wiki:projects:python:pyusb:pydoc) doesn't appear to talk about conversion or use of the new & improved pyusb... Could someone tell me where to go for conversion / interface docs? I'd like to do as little code conversion as possible, but I'm not sure where to start. You actually have found a bug. The interface is only working when you pass the interface number. I'll provide a fix as soon as I can (which not necessarily means fast). ------------------------------------------------------------------------------ Free Software Download: Index, Search & Analyze Logs and other IT data in Real-Time with Splunk. Collect, index and harness all the fast moving IT data generated by your applications, servers and devices whether physical, virtual or in the cloud. Deliver compliance at lower cost and gain new business insights. http://p.sf.net/sfu/splunk-dev2dev _______________________________________________ pyusb-users mailing list pyusb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pyusb-users -- Best Regards, Wander Lairson Costa LCoN - Laboratório de Computação Natural - Natural Computing Laboratory (http://www.mackenzie.com.br/lcon.html) Programa de Pós-Graduação em Engenharia Elétrica (PPGEE) Faculdade de Computação e Informática (FCI) Universidade Presbiteriana Mackenzie - SP - Brazil
------CODE OUTPUT----- Computing message header sending to address 0:7-6 with 4.000000-second timeout: ['\x01', '\x01', '\xfe', '\x00', '\x07', '\x00', '\x00', '\x00', '\x01', '\x00', '\x00', '\x00', 'l', 'o', 'c', ' ', 'a', 'l', 'l', '\x00'] Exception in thread OperateScope15: Traceback (most recent call last): File "/usr/lib/python2.6/threading.py", line 532, in __bootstrap_inner self.run() File "/usr/lib/python2.6/threading.py", line 484, in run self.__target(*self.__args, **self.__kwargs) File "./acquisition/ACQutil.py", line 390, in Operate self.Arm() File "./acquisition/ACQutil.py", line 420, in Arm self.Scope.arm(self.run._TrigStr) File "./acquisition/scope.py", line 504, in arm self.reset() File "./acquisition/scope.py", line 539, in reset self.write('loc all') #lock all File "./acquisition/scope.py", line 1036, in write self.hand.bulkWrite(self.bo.address,sending,scopetimeout*1000) File "/usr/local/lib/python2.6/site-packages/usb/legacy.py", line 148, in bulkWrite return self.dev.write(endpoint, buffer, self.__claimed_interface, timeout) File "/usr/local/lib/python2.6/site-packages/usb/core.py", line 601, in write _interop.as_array(data), File "/usr/local/lib/python2.6/site-packages/usb/_interop.py", line 134, in as_array return array.array('u', data) TypeError: array item must be unicode character ------/END CODE OUTPUT-------------- I'm also attaching the method which generated the above output: ----------CODE SNIPPET---------- def write(self, message): '''Sends a command to the USB scope and does not expect a response. declaration: write(self, message) message - the string to be sent to the scope.''' self.runlog.log(3,'Computing message header') msgID=chr(0x01) #DEV_DEP_MSG_OUT (cmd to Bulk-Out Endpoint) bTagInv=chr((~self.bTag)&(0xff)) #bitwise inverse(bTag) msg=list(message) msglen=len(msg) if msglen== 0: self.runlog.log(-1,'null message not allowed') #spec allows much longer lengths, but these #aren't yet implemented if msglen>255: self.runlog.log(-1,'message too long') #pad to a length with a multiple of 4 bytes if msglen%4 == 1 : msg.extend([chr(0x00),chr(0x00),chr(0x00)]) elif msglen%4 == 2 : msg.extend([chr(0x00),chr(0x00)]) elif msglen%4 == 3 : msg.extend([chr(0x00)]) #Force conversions to single-byte elements, #since Python prefers to use 16-bit integers #internally #self.runlog.log(3,'compiling full message') sending=[msgID,chr(self.bTag),bTagInv,NULL] sending.extend(Num2List(msglen)) sending.extend([chr(0x01),NULL,NULL,NULL]) sending.extend(msg) self.runlog.log(3,'sending to address %s-%d with %f-second timeout: %s'%(self.id[2], self.bo.address, scopetimeout, sending)) self.hand.bulkWrite(self.bo.address,sending,scopetimeout*1000) self.runlog.log(3,'message sent') self.bTag+=1 if self.bTag>255: self.bTag=0x01 ------------/END CODE SNIPPET-----------
------------------------------------------------------------------------------ Free Software Download: Index, Search & Analyze Logs and other IT data in Real-Time with Splunk. Collect, index and harness all the fast moving IT data generated by your applications, servers and devices whether physical, virtual or in the cloud. Deliver compliance at lower cost and gain new business insights. http://p.sf.net/sfu/splunk-dev2dev
_______________________________________________ pyusb-users mailing list pyusb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pyusb-users