-
- import usb.core
- import usb.util
-
- #find our device
- dev = usb.core.find(idVendor=0x04D8, idProduct=0x0204)
-
- #was it found?
- if dev is None:
- raise ValueError('Device not found')
-
- #set the active configuration. with no args we use first config.
- dev.set_configuration()
-
- #get in and out endpoint instances
- ep_out = usb.util.find_descriptor(
- dev.get_interface_altsetting(), # first interface
- # match the first OUT endpoint
- custom_match = \
- lambda e: \
- usb.util.endpoint_direction(e.bEndpointAddress) == \
- usb.util.ENDPOINT_OUT
- )
-
- ep_in = usb.util.find_descriptor(
- dev.get_interface_altsetting(), # first interface
- # match the first IN endpoint
- custom_match = \
- lambda e: \
- usb.util.endpoint_direction(e.bEndpointAddress) == \
- usb.util.ENDPOINT_IN
- )
-
- #turn light on
- ep_out.write([0x080])
-
- #recieve data
- ep_out.write([0x081])
- ep_in.read(8)
-