Dear all,

Im new with pyusb, I just bought a device and this device have a
pressure/push and twist sensors. As my starting point to learn is I want to
read the sensors value from my device and display it in my PyQT application.

First thing first, I use the libusb-win32 to install the driver and get the
information about my device, see bellow picture:

[image: http://img830.imageshack.us/img830/9748/usbs.jpg]

That is my device information, I got my VendorID, ProductID and the
interface number and address of device Endpoint. with this code I can detect
that my device is already present on my system bus:
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')

# set the active configuration. With no arguments, the first
# configuration will be the active one
dev.set_configuration()
print "Device found!"


I've got everything right at this point. then next step is I want to
send/receive some data packet to/from my device (to read the two sensors;
pressure/push and twist sensor).
I've got the manual from my vendor for reading and writing into the device,
here it is:

[image: http://img12.imageshack.us/img12/9519/protocoly.jpg]

I tried to read the sensor value from the device by writing data to the
device first in order to enable the senseors and then reading the value
itself afterward  (according the manual):

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')

# set the active configuration. With no arguments, the first
# configuration will be the active one
dev.set_configuration()

dev.write(0x01,'\0x08,\0x0,\0x0,\0x0,\0x0,\0x0,\0x0,\0x0F',0)
dev.write(0x01,'\0x09,\0x0,\0x0,\0x0,\0x0,\0x0,\0x0,\0x0',0)

test = dev.read(0x81,8,0,1000)
sret = ''.join([chr(x) for x in test])
print "data: ", sret

*But I got the following error:*

G:\matix\Stress Ball\Project\Code\src>detectdev.py
Traceback (most recent call last):
  File "G:\D. Hartanto\Stress Ball\Project\Code\src\detectdev.py", line 24,
in <module>
    dev.write(0x01,'\0x08,\0x0,\0x0,\0x0,\0x0,\0x0,\0x0,\0x0F',0)
  File "C:\Python26\lib\site-packages\usb\core.py", line 594, in write
    fn = fn_map[self._ctx.get_endpoint_type(self, endpoint, intf)]
  File "C:\Python26\lib\site-packages\usb\core.py", line 180, in
get_endpoint_type
    etype = util.endpoint_type(e.bmAttributes)
AttributeError: 'NoneType' object has no attribute 'bmAttributes'

Trying looking around into the net to solve the problem but still got no
luck, did I missed something here? I really want to have connection with my
device, so I can read those sensors value into my PC.
Thank you very much guys,

Regards,
Pratams.
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users

Reply via email to