From: Phil H. <ph...@ha...> - 2008-12-22 09:47:49
Attachments:
signature.asc
|
Hello, All appears to be going to plan, I have sent a hello to my device and got a hello back (via interruptWrite then interruptRead). I can query the devices current key state using the same interruptWrite then Read, however the next time I send a query asking it about its storage capacity it returns random data. Is there something I have to do to clear a buffer? Again if I send the hello and ask the device to enter transmit mode (where pen coordinates are issued) I just get junk out. I guess I am failing to understand just how to receive data from a USB device. The data I am getting is not an out of sequence packet so I do not understand, what the data is. I could do with some more examples, do people have any that are not: missle.py lsusb.py usbenum.py PlugUSB.py gotemp-pyusb.py Which are all the examples I have found on the internet. Regards Phil Hannent |
From: Wander L. <wan...@gm...> - 2008-12-22 14:10:12
|
Well, I think you are doing things in the right way, may be the problem is a device protocol issue. Perhaps you are issuing the wrong command to get what you want... How do you get the storage capacity? How many bytes are expected to return? Please, post the code here (with comments). 2008/12/22 Phil Hannent <ph...@ha...>: > Hello, > > All appears to be going to plan, I have sent a hello to my device and > got a hello back (via interruptWrite then interruptRead). > > I can query the devices current key state using the same interruptWrite > then Read, however the next time I send a query asking it about its > storage capacity it returns random data. > > Is there something I have to do to clear a buffer? Again if I send the > hello and ask the device to enter transmit mode (where pen coordinates > are issued) I just get junk out. > > I guess I am failing to understand just how to receive data from a USB > device. The data I am getting is not an out of sequence packet so I do > not understand, what the data is. > > I could do with some more examples, do people have any that are not: > missle.py > lsusb.py > usbenum.py > PlugUSB.py > gotemp-pyusb.py > > Which are all the examples I have found on the internet. > > Regards > Phil Hannent > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Pyusb-users mailing list > Pyu...@li... > https://lists.sourceforge.net/lists/listinfo/pyusb-users > > |
From: Phil H. <ph...@ha...> - 2008-12-22 15:10:05
Attachments:
signature.asc
|
Hello, Wander Lairson wrote: > Well, I think you are doing things in the right way, may be the > problem is a device protocol issue. Perhaps you are issuing the wrong > command to get what you want... How do you get the storage capacity? > How many bytes are expected to return? Please, post the code here > (with comments). > Thanks for the reply, I am going to try an paste functions to see if it helps: This section says hello to the device in question and works just fine. sent_bytes = self.handle.interruptWrite(PlugUSBDevice.PLUG_BULK_IN_EP, PlugUSBDevice.MIMIO_HELLO, 1000) print "Sent hello" if sent_bytes: read_bytes = self.handle.interruptRead(PlugUSBDevice.PLUG_BULK_OUT_EP,8); self.readDevice(read_bytes) readDevice starts: def readDevice(self, response): #response = self.handle.interruptRead(PlugUSBDevice.PLUG_BULK_OUT_EP,8); if response: print "readDevice", response if response == PlugUSBDevice.MAX_PACKET_SIZE: return #print response #firstByte = response[0] #print firstByte #print [hex(d) for d in response] if response[0] == 0x21: print "Device responded to hello" self.devicestate = response[1] And I get the device telling me it responded. I can now issue several other commands which query the storage information in a similar way and get the information I expect. My main issue is that I cannot issue a data transmit command and get pen xy coordinates, I just get: usb.USBError: No error I start it by issuing a command like the others: def startDataXmit(self, timeout = 100): sent_bytes = self.handle.interruptWrite(PlugUSBDevice.PLUG_BULK_IN_EP, PlugUSBDevice.MIMIO_STARTDATATRANS, 1000) if sent_bytes: read_bytes = self.handle.interruptRead(PlugUSBDevice.PLUG_BULK_OUT_EP,sent_bytes); self.readDevice(read_bytes) print "startDataXmit" Then in a loop I call: def getDataPacket(self, bytesToGet) : """ Assume bytesToGet is two bytes wide. """ print "getDataPacket" read_bytes = self.handle.interruptRead(PlugUSBDevice.PLUG_BULK_OUT_EP,bytesToGet); #read_bytes = self.handle.bulkRead(PlugUSBDevice.PLUG_BULK_OUT_EP,bytesToGet,1000) self.readDevice(read_bytes) Where I get the "No error" error on the interruptRead line. The documentation for the protocol does not talk about low level USB details only that the if the data becomes out of sync I must issue a stop command and re-sync the communication channel (of which I am not sure what that is). Any hints on the "No error" problem? Regards Phil Hannent |
From: Wander L. <wan...@gm...> - 2008-12-22 15:24:38
|
What are the constants PLUG_BULK_IN_EP and PLUG_BULK_OUT_EP? 2008/12/23 Phil Hannent <ph...@ha...>: > Hello, > > Wander Lairson wrote: >> Well, I think you are doing things in the right way, may be the >> problem is a device protocol issue. Perhaps you are issuing the wrong >> command to get what you want... How do you get the storage capacity? >> How many bytes are expected to return? Please, post the code here >> (with comments). >> > > Thanks for the reply, I am going to try an paste functions to see if it > helps: > > This section says hello to the device in question and works just fine. > > sent_bytes = > self.handle.interruptWrite(PlugUSBDevice.PLUG_BULK_IN_EP, > PlugUSBDevice.MIMIO_HELLO, 1000) > print "Sent hello" > if sent_bytes: > read_bytes = > self.handle.interruptRead(PlugUSBDevice.PLUG_BULK_OUT_EP,8); > self.readDevice(read_bytes) > > readDevice starts: > def readDevice(self, response): > #response = > self.handle.interruptRead(PlugUSBDevice.PLUG_BULK_OUT_EP,8); > if response: > print "readDevice", response > if response == PlugUSBDevice.MAX_PACKET_SIZE: > return > #print response > #firstByte = response[0] > #print firstByte > #print [hex(d) for d in response] > if response[0] == 0x21: > print "Device responded to hello" > self.devicestate = response[1] > > And I get the device telling me it responded. I can now issue several > other commands which query the storage information in a similar way and > get the information I expect. My main issue is that I cannot issue a > data transmit command and get pen xy coordinates, I just get: > usb.USBError: No error > > I start it by issuing a command like the others: > def startDataXmit(self, timeout = 100): > sent_bytes = > self.handle.interruptWrite(PlugUSBDevice.PLUG_BULK_IN_EP, > PlugUSBDevice.MIMIO_STARTDATATRANS, 1000) > if sent_bytes: > read_bytes = > self.handle.interruptRead(PlugUSBDevice.PLUG_BULK_OUT_EP,sent_bytes); > self.readDevice(read_bytes) > print "startDataXmit" > > Then in a loop I call: > def getDataPacket(self, bytesToGet) : > """ > Assume bytesToGet is two bytes wide. > """ > print "getDataPacket" > read_bytes = > self.handle.interruptRead(PlugUSBDevice.PLUG_BULK_OUT_EP,bytesToGet); > #read_bytes = > self.handle.bulkRead(PlugUSBDevice.PLUG_BULK_OUT_EP,bytesToGet,1000) > self.readDevice(read_bytes) > > Where I get the "No error" error on the interruptRead line. The > documentation for the protocol does not talk about low level USB details > only that the if the data becomes out of sync I must issue a stop > command and re-sync the communication channel (of which I am not sure > what that is). > > Any hints on the "No error" problem? > > Regards > Phil Hannent > > > > > > > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Pyusb-users mailing list > Pyu...@li... > https://lists.sourceforge.net/lists/listinfo/pyusb-users > > |
From: Phil H. <ph...@ha...> - 2008-12-22 15:29:02
Attachments:
signature.asc
|
Wander Lairson wrote: > What are the constants PLUG_BULK_IN_EP and PLUG_BULK_OUT_EP? > They are: PLUG_BULK_IN_EP = 0x2 PLUG_BULK_OUT_EP = 0x81 The device enumerates to: Device: 006 Device class: 255 Device sub class: 0 Device protocol: 255 Max packet size: 8 idVendor: 2259 idProduct: 1 Device Version: 00.01 Configuration: 1 Total length: 32 selfPowered: 0 remoteWakeup: 0 maxPower: 200 Interface: 0 Alternate Setting: 0 Interface class: 255 Interface sub class: 0 Interface protocol: 255 Endpoint: 0x81L Type: 3 Max packet size: 8 Interval: 1 Endpoint: 0x2L Type: 3 Max packet size: 8 Interval: 1 I have just been googling some more and found this: http://osdir.com/mlpython.pyusb.user/2008-05/msg00001.html Where the suggestion is to claim the interface. This is my open function: def open(self) : self.device = self.device_descriptor.getDevice() self.handle = self.device.open() self.handle.reset() if sys.platform == 'darwin' : # XXX : For some reason, Mac OS X doesn't set the # configuration automatically like Linux does. self.handle.setConfiguration(1) self.handle.claimInterface(self.device_descriptor.interface_id) What do you think? |
From: Wander L. <wan...@gm...> - 2008-12-23 04:36:37
|
By I remmember from USB Spec, endpoint 0x81 should be IN (MSB 1) and endpoint 0x2 should be OUT (MSB 0). I don't what are exactly the side effects of inverting them... Did you write the device firmware also? If not, probably you should swap the values of PLUG_BULK_IN_EP and PLUG_BULK_OUT_EP. If so, revise your fw source code to follow the correct USB Spec. After that, report the result to the list. 2008/12/23 Phil Hannent <ph...@ha...>: > Wander Lairson wrote: >> What are the constants PLUG_BULK_IN_EP and PLUG_BULK_OUT_EP? >> > They are: > PLUG_BULK_IN_EP = 0x2 > PLUG_BULK_OUT_EP = 0x81 > > The device enumerates to: > Device: 006 > Device class: 255 > Device sub class: 0 > Device protocol: 255 > Max packet size: 8 > idVendor: 2259 > idProduct: 1 > Device Version: 00.01 > Configuration: 1 > Total length: 32 > selfPowered: 0 > remoteWakeup: 0 > maxPower: 200 > Interface: 0 > Alternate Setting: 0 > Interface class: 255 > Interface sub class: 0 > Interface protocol: 255 > Endpoint: 0x81L > Type: 3 > Max packet size: 8 > Interval: 1 > Endpoint: 0x2L > Type: 3 > Max packet size: 8 > Interval: 1 > > I have just been googling some more and found this: > http://osdir.com/mlpython.pyusb.user/2008-05/msg00001.html > > Where the suggestion is to claim the interface. This is my open function: > def open(self) : > self.device = self.device_descriptor.getDevice() > self.handle = self.device.open() > self.handle.reset() > if sys.platform == 'darwin' : > # XXX : For some reason, Mac OS X doesn't set the > # configuration automatically like Linux does. > self.handle.setConfiguration(1) > self.handle.claimInterface(self.device_descriptor.interface_id) > > What do you think? > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Pyusb-users mailing list > Pyu...@li... > https://lists.sourceforge.net/lists/listinfo/pyusb-users > > |
From: Phil H. <ph...@ha...> - 2008-12-23 11:24:58
Attachments:
signature.asc
|
Wander Lairson wrote: > By I remmember from USB Spec, endpoint 0x81 should be IN (MSB 1) and > endpoint 0x2 should be OUT (MSB 0). I don't what are exactly the side > effects of inverting them... Did you write the device firmware also? > If not, probably you should swap the values of PLUG_BULK_IN_EP and > PLUG_BULK_OUT_EP. If so, revise your fw source code to follow the > correct USB Spec. After that, report the result to the list. > Very interesting, no I did not write the firmware and I have nothing to do with it. I have tried swapping the values and it causes it to fail at the "Hello" with a "usb.USBError: No error" message. I noticed that pyGarmin has the same values as I do. http://bazaar.launchpad.net/~pygarmin-dev/pygarmin/trunk/annotate/head%3A/garmin.py I was thinking that when I am doing the read the interrupt might not have any data and that might be why it crashes: read_bytes = self.handle.interruptRead(PlugUSBDevice.PLUG_BULK_OUT_EP,8); usb.USBError: No error Do I have to catch the error and ignore it in this case just because someone has not put a pen against the board yet? Regards Phil |
From: Phil H. <ph...@ha...> - 2008-12-23 12:47:08
Attachments:
signature.asc
|
Phil Hannent wrote: > Wander Lairson wrote: > >> By I remmember from USB Spec, endpoint 0x81 should be IN (MSB 1) and >> endpoint 0x2 should be OUT (MSB 0). I don't what are exactly the side >> effects of inverting them... Did you write the device firmware also? >> If not, probably you should swap the values of PLUG_BULK_IN_EP and >> PLUG_BULK_OUT_EP. If so, revise your fw source code to follow the >> correct USB Spec. After that, report the result to the list. >> >> > Very interesting, no I did not write the firmware and I have nothing to > do with it. I have tried swapping the values and it causes it to fail > at the "Hello" with a "usb.USBError: No error" message. > > I noticed that pyGarmin has the same values as I do. > http://bazaar.launchpad.net/~pygarmin-dev/pygarmin/trunk/annotate/head%3A/garmin.py > > I was thinking that when I am doing the read the interrupt might not > have any data and that might be why it crashes: > read_bytes = self.handle.interruptRead(PlugUSBDevice.PLUG_BULK_OUT_EP,8); > usb.USBError: No error > > Do I have to catch the error and ignore it in this case just because > someone has not put a pen against the board yet? > Woohoo, success. I have the pen data coming out of the board. I ignore the No error message. I also had a delay within my loop so that I could see the messages, I reduced the time.sleep(0.5) to time.sleep(0.005) and the interrupt is reading the packets just fine 90% of the time. It gets offset at sometimes but I am sure that will be a tuning issue. Thanks for the help so far. PyUSB is a fantastic tool. Regards Phil Hannent |