pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

pastebin private pastebin - collaborative debugging tool What's a private pastebin?

Posted by fruitbat on Wed 28th Jan 17:00
download | new post

  1. #!/usr/bin/python
  2. #Return IR device....
  3.  
  4. import usb,threading,time
  5.  
  6.  
  7. #print dir(remote)
  8. #print "Vendor: ",remote.getString(remdev.iManufacturer,30)
  9. #print "Product: ",remote.getString(remdev.iProduct,30)
  10. #print "Serial: ",remote.getString(remdev.iSerialNumber,30)
  11. #for conf in remdev.configurations:
  12. #       print "Configuration:",conf.value
  13. #       for intf in conf.interfaces:
  14. #              print "\t Interface: ", intf[0].interfaceNumber
  15. #              for alt in intf:
  16. #                     print "\tAlt:",alt.alternateSetting
  17. #                     for ep in alt.endpoints:
  18. #                            print "\t\tEndpoint:",ep.address
  19. #                            print "\t\tType:",ep.type
  20. #                            print "\t\tMax packet size:",ep.maxPacketSize
  21. #                            print "\t\tInterval:",ep.interval
  22. #Endpoint 129 is the keyboard
  23. #Endpoint 130 is the mouse
  24.  
  25. class Interface(threading.Thread):
  26.         def getDevice(self,vendor,product):
  27.                 omnibus = usb.busses()
  28.                 for bus in omnibus:
  29.                         devices = bus.devices
  30.                         for dev in devices:
  31.                                 if dev.idVendor == vendor:
  32.                                         if dev.idProduct == product:
  33.                                                 #Will return the first device, dunno why you'd have 2 though..
  34.                                                 return dev
  35.                 return None
  36.         def __init__(self,interface):
  37.                 threading.Thread.__init__(self)
  38.                 self.interface = interface
  39.                 self.remdev = self.getDevice(1894,516)
  40.                 self.remote = self.remdev.open()
  41.                 self.remote.claimInterface(interface)
  42.                 self.endp = self.remdev.configurations[0].interfaces[interface][0].endpoints[0].address
  43.                 print self.endp
  44.         def start(self):
  45.                 threading.Thread.start(self)
  46.                 print self.getName()
  47.         def run(self):
  48.                 while (True):
  49.                         try:
  50.                                 data = self.remote.bulkRead(self.endp,8,500)
  51.                         except usb.USBError,e:
  52.                                 data = None
  53.                         if(data != None):
  54.                                 print self.getName(),":",str(data)
  55.                        
  56.                 #dereference stuff here!
  57.  
  58. # Setup threads
  59. keyboard = Interface(0)
  60. keyboard.setName("Keyboard")
  61. mouse = Interface(1)
  62. mouse.setName("Mouse")
  63. #Go....
  64. keyboard.start()
  65. mouse.start()
  66. print "Interfaces spawned"

Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Use syntax highlighting

To highlight particular lines, prefix each line with @@


Remember my settings