spacepaste

  1.  
  2. import usb.core
  3. import usb.util
  4. #find our device
  5. dev = usb.core.find(idVendor=0x04D8, idProduct=0x0204)
  6. #was it found?
  7. if dev is None:
  8. raise ValueError('Device not found')
  9. #set the active configuration. with no args we use first config.
  10. dev.set_configuration()
  11. #get in and out endpoint instances
  12. ep_out = usb.util.find_descriptor(
  13. dev.get_interface_altsetting(), # first interface
  14. # match the first OUT endpoint
  15. custom_match = \
  16. lambda e: \
  17. usb.util.endpoint_direction(e.bEndpointAddress) == \
  18. usb.util.ENDPOINT_OUT
  19. )
  20. ep_in = usb.util.find_descriptor(
  21. dev.get_interface_altsetting(), # first interface
  22. # match the first IN endpoint
  23. custom_match = \
  24. lambda e: \
  25. usb.util.endpoint_direction(e.bEndpointAddress) == \
  26. usb.util.ENDPOINT_IN
  27. )
  28. #turn light on
  29. ep_out.write([0x080])
  30. #recieve data
  31. ep_out.write([0x081])
  32. ep_in.read(8)
  33.