import usb #################################### RQ_SET_LED = 0 RQ_GET_SWITCH = 1 class BoardControl: def __init__(self): #print "Looking for MCU board..." dev = self.find_board() if not dev: raise "MCU board not found!" #print "MCU board found" self.handle = dev.open() def find_board(self): board = None for bus in usb.busses(): for dev in bus.devices: if dev.idVendor == 0x16c0 and dev.idProduct == 0x05dc: return dev return None def set_led(self,pin,val): reqType = usb.TYPE_VENDOR | usb.RECIP_DEVICE | usb.ENDPOINT_OUT self.handle.controlMsg(reqType, RQ_SET_LED, None, value=val*256+pin) def get_switch(self): reqType = usb.TYPE_VENDOR | usb.RECIP_DEVICE | usb.ENDPOINT_IN buf = self.handle.controlMsg(reqType, RQ_GET_SWITCH, 1) return buf[0] board = BoardControl()