I just installed latest version and got following error
The debugged program raised the exception TypeError
"'int' object is not iterable"
File: /usr/local/lib/python2.6/dist-packages/usb/_interop.py, Line: 134
I also seem to have over zealous in commenting out of un-necessary code :-(
On Tue, Nov 29, 2011 at 11:13 AM, Eric Hewett <eric.hew...@gmail.com> wrote:
> Hi Wander
> The source code (As you can see there are plenty of commented out
> ctrl_transfer options that I have tried to send a Feature_Report to the USB
> sensor, also commented out SQLite code which works but not necessary for
> this problem):
>
> #!/usr/bin/python
>
> import usb.core
> import usb.util
> import usb.control
> import sys, traceback
> from sqlite3 import dbapi2 as sqlite
> from time import strftime
> import time
>
> class find_class(object):
> def __init__(self, class_):
> self._class = class_
> def __call__(self, device):
> # first, let's check the device
> if device.bDeviceClass == self._class:
> return True
> # ok, transverse all devices to find an
> # interface that matches our class
> for cfg in device:
> # find_descriptor: what's it?
> intf = usb.util.find_descriptor(
> cfg,
> bInterfaceClass=self._class
> )
> if intf is not None:
> return True
> #printers = usb.core.find(find_all=True, bDeviceClass=0)
>
> return False
>
> #===========================================================
> class Sensors:
> def Loop(self, conn):
> sensors = usb.core.find(find_all=1, custom_match=find_class(3),
> idVendor=0x1b67)
> #sensors = usb.core.find(find_all=1, custom_match=find_class(3),
> idVendor=0x0683)
> print 'There are %d sensors in the system\n.' % ( len(sensors))
>
> # find our device 0683:1480
> #dev = usb.core.find(idVendor=0x1b67, idProduct=0x0009)
> #dev = usb.core.find(custom_match = lambda d: d.idProduct ==
> 0x0009 and d.idVendor == 0x1b67)
> #dev = usb.core.find(find_all=True, idVendor=0x1b67)
>
> # was it found?
> if sensors is None:
> raise ValueError('Device not found')
> else :
> print 'Sensors found :'
> print sensors
> print type(sensors)
>
>
> for dev in sensors:
> print dev
> if dev.is_kernel_driver_active(0) :
>
> print 'kernel driver active'
> try:
> #detach_kernel_driver(self, interface)
> dev.detach_kernel_driver(0)
> # set the active configuration. With no arguments, the
> first
> # configuration will be the active one
> except usb.core.USBError as e:
> sys.exit("Could not detact kernel driver: %s" % str(e))
> dev.set_configuration()
>
> cfg = dev.get_active_configuration()
>
> print "Config: %s " % (str(cfg.bConfigurationValue))
> print 'cfg length: %d ' %(cfg.bLength)
>
> for intf in cfg:
> # sys.stdout.write('\t' + \
> # str(intf.bInterfaceNumber) + \
> # ',' + \
> # str(intf.bAlternateSetting) + \
> # '\n')
>
>
> print "Interface"
> print intf
> #print 'interface length = %d' %(intf.length)
> for ep in intf:
> print "End Point"
> print ep
> print ep.bEndpointAddress
> channeldata = []
> for i in range(5):
> print 'device description:
> %s'%(usb.util.get_string(dev, 200,i, langid=None))
> print "Getting channel data"
> channeldata = dev.read(ep.bEndpointAddress,
> ep.wMaxPacketSize)
> print channeldata
> maTime = (channeldata[0] +channeldata[1] * 256)
>
> maValue = (channeldata[2] +channeldata[3] * 256)/1000.0
> print 'MilliAmps: %f|| %d'% (maValue, maTime)
> #conn.execute('insert into channeldata (ChannelId,
> DateandTime, ChannelValue) values(?,?,?)' ,[1, strftime("%Y-%m-%d
> %H:%M:%S"), maValue])
> #conn.commit()
> msg = '\x00\x01\x01\x01\x00\x01'
> #print dev.ctrl_transfer(0x40, INTERUPT_IN, 0, 0, msg)
>
> #print'write length: %d'
> %(ep.write('\x00\x00\x01\x01\x00\x02'))
> # print'write length: %d' %(ep.write('\0x00, \0x00,
> \0x01, \0x01, \0x00, \0x01'))
> #print'write length: %d' %(ep.write('\0x00, \0x01,
> \0x15, \0x00, \0x00,eric'))
> # ctrl_transfer(self, bmRequestType, bRequest,
> wValue=0, wIndex=0, data_or_wLength=None, timeout=None)
>
> #dev.write(ep.bEndpointAddress, msg, intf)
>
> #ret = dev.ctrl_transfer(0x40, CTRL_LOOPBACK_READ, 0,
> 0, len(msg))
> #ret = dev.ctrl_transfer(0x80, 0, msg, 0, len(msg))
> print dev.ctrl_transfer(0x60, 0x09, msg, 0, len(msg))
> #print dev.ctrl_transfer(0x80, 0x06, 0x00, 0x00, 0x12)
> #print dev.ctrl_transfer(0x40, 0x03, msg)
> #
> #usb.control.set_feature(dev, msg, None)
> def start():
> db_filename = '/home/dev/Documents/usbtest/gim.db'
> conn = sqlite.connect(db_filename)
> usbdevices = Sensors()
> for item in range(10):
> usbdevices.Loop(conn)
> #time.sleep(1)
> conn.close()
> if __name__ == '__main__':
> start()
>
> Thanks for your time.
>
> kind regards
> Eric Hewett
>
>
>
>
--
regards
Eric Hewett
eric.hew...@gmail.com
Twitter: @ehewett
Website: www.erichewett.com
------------------------------------------------------------------------------
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. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users