From: Andhika P. <and...@gm...> - 2011-10-18 09:58:30
|
Hi all, I've got to manage *reading *the value from my device, here's example of my code: import usb.core import usb.util import sys # find our device dev = usb.core.find(idVendor=0x1D34, idProduct=0x0020) # was it found? if dev is None: raise ValueError('Device not found') # configuration will be the active one dev.set_configuration() print "Device found!" print dev #Read value from device for bRequest in range(255): try: read = dev.ctrl_transfer(0x81, bRequest, 0, 0, 8) #read 8 bytes print "bRequest ", bRequest print read except: # failed to get data for this request pass And here's the output value from my device, I did the *ctrl_transfer() *as Costa suggestion from previous email. and I did the iterative *bRequest *to know which value that give me the return. and apparently only *bRequest *0, 8 and 9 that give me the return value. G:\madeinjavax\Stress Ball\Project\Code\src>read.py *Device found! <usb.core.Device object at 0x00C648F0> bRequest 0 array('B', [0, 0]) bRequest 8 array('B', [1]) bRequest 9 array('B')* Now its getting fun :-) If I had this bellow protocol communication for my device, how I can put it into the *ctrl_transfer()* format? **Commands by PC (control endpoint)** [packet = 8 byte long] +========== byte =========+==Description==+ | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | | +****+**+***+**+**+**+***+*********+*********************| |0x08 | / | / | / | / | / | / | 0x0F | Enable senseor | |0x09 | / | / | / | / | / | / | / | Get sensor value | +========================+=============+ **Response by MCU (IN endpoint)** +================= byte =============+ Description ==+ | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | | +*****+***+***+***+****+********+*********+*********+******************| |0x01 | / | / | / | / | / | / | / | ACK | |0x03 | / | / | / | / | value a | value b | value c | Sensor value | +===============================================+ I'd already diggin' around and tried couple of combination to put this protocol into the *ctrl_transfer() *format but none of those works. here's my code: dev.ctrl_transfer(0x81, bRequest, 0, 0, '\0x08,\0x0,\0x0,\0x0,\0x0,\0x0,\0x0,\0x0F') dev.ctrl_transfer(0x81, bRequest, 0, 0, '\0x09\,\0x0,\0x0,\0x0,\0x0,\0x0,\0x0,\0x0') Please let me how to put those protocol format into the *ctrl_transfer() *function correctly since Im new in the hardware programming thus Im still in the learning phase. Thanks for the sharing Gurus. Best regards, Pratams. On Thu, Oct 6, 2011 at 12:00 AM, Wander Lairson Costa < wan...@gm...> wrote: > 2011/10/5 Tormod Volden <lis...@gm...>: > > On Wed, Oct 5, 2011 at 9:29 PM, Andhika Pratama wrote: > > > >> > >> As you can see from my screen capture above that my device endpoint > >> address is 0x81, and I check couple of example also had the same > address, > >> that is 0x81. and my device only have one endpoint. > > > > Well, you are writing to endpoint 1, whereas the documentation you linked > to > > says commands go to the control endpoint (=0). > > > > And bear in mind that transfer through endpoint 0 is by ctrl_transfer > function. > > > -- > Best Regards, > Wander Lairson Costa > https://github.com/walac > https://gitorious.org/~walac > |