spacepaste

  1.  
  2. import usb.core
  3. import usb.util
  4. import sys
  5. # find our device
  6. dev = usb.core.find(idVendor=0x0403, idProduct=0x6001)
  7. # was it found?
  8. if dev is None:
  9. raise ValueError('Device not found')
  10. else:
  11. print 'Device was found'
  12. print '----------------\n' + \
  13. 'Configuration of the device:'
  14. for cfg in dev:
  15. sys.stdout.write('bConfigurationValue: ' + str(cfg.bConfigurationValue) + '\n')
  16. for intf in cfg:
  17. sys.stdout.write('\tbInterfaceNumber: ' + str(intf.bInterfaceNumber) + '\n' + \
  18. '\tbAlternateSetting: ' + str(intf.bAlternateSetting) + '\n' + \
  19. '\tbLength: ' + str(intf.bLength) + '\n')
  20. for ep in intf:
  21. sys.stdout.write('\t\tbEndpointAddress: ' + \
  22. str(ep.bEndpointAddress) + \
  23. '\n')
  24. #dev.set_configuration(1)
  25. #dev.set_configuration()
  26. #cfg = util.find_descriptor(dev, bConfiguration=1)
  27. #cfg.set()
  28. #dev.set_configuration(cfg)
  29. print '----------------\n' + \
  30. 'start reading test'
  31. epAddress = 129
  32. nrByteRead = 9
  33. ifNumber = 0
  34. timeout = 100
  35. ret = dev.read(epAddress, nrByteRead, ifNumber, timeout)
  36. sret = ''.join([chr(x) for x in ret])
  37. print '-'+sret+'-'
  38. print 'end reading test'
  39.