<s> """<STR_LIT>""" <EOL> from interface import Interface <EOL> import logging , os <EOL> try : <EOL> import pywinusb . hid as hid <EOL> except : <EOL> if os . name == "<STR_LIT>" : <EOL> logging . error ( "<STR_LIT>" ) <EOL> available = False <EOL> else : <EOL> available = True <EOL> class PyWinUSB ( Interface ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> available = available <EOL> def __init__ ( self ) : <EOL> super ( PyWinUSB , self ) . __init__ ( ) <EOL> self . report = [ ] <EOL> self . rcv_data = [ ] <EOL> self . device = None <EOL> return <EOL> def rx_handler ( self , data ) : <EOL> self . rcv_data . append ( data [ <NUM_LIT:1> : ] ) <EOL> def open ( self ) : <EOL> self . device . open ( ) <EOL> reports = self . device . find_output_reports ( ) <EOL> if len ( reports ) != <NUM_LIT:1> : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> self . report = reports [ <NUM_LIT:0> ] <EOL> self . device . set_raw_data_handler ( self . rx_handler ) <EOL> @ staticmethod <EOL> def getConnectedInterfaces ( vid , pid ) : <EOL> """<STR_LIT>""" <EOL> all_devices = hid . find_all_hid_devices ( ) <EOL> all_mbed_devices = [ ] <EOL> for d in all_devices : <EOL> if ( d . vendor_id == vid ) and ( d . product_id == pid ) : <EOL> all_mbed_devices . append ( d ) <EOL> if not all_mbed_devices : <EOL> logging . debug ( "<STR_LIT>" ) <EOL> return <EOL> boards = [ ] <EOL> for dev in all_mbed_devices : <EOL> new_board = PyWinUSB ( ) <EOL> new_board . vendor_name = dev . vendor_name <EOL> new_board . product_name = dev . product_name <EOL> new_board . serial_number = dev . serial_number <EOL> new_board . vid = dev . vendor_id <EOL> new_board . pid = dev . product_id <EOL> new_board . path = dev . device_path <EOL> new_board . device = dev <EOL> boards . append ( new_board ) <EOL> return boards <EOL> def write ( self , data ) : <EOL> """<STR_LIT>""" <EOL> for _ in range ( <NUM_LIT:64> - len ( data ) ) : <EOL> data . append ( <NUM_LIT:0> ) <EOL> self . report . send ( [ <NUM_LIT:0> ] + data ) <EOL> return <EOL> def read ( self , timeout = - <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> while len ( self . rcv_data ) == <NUM_LIT:0> : <EOL> pass <EOL> return self . rcv_data . pop ( <NUM_LIT:0> ) <EOL> def setPacketCount ( self , count ) : <EOL> self . packet_count = count <EOL> def __eq__ ( self , other ) : <EOL> return self . path == other . path <EOL> def close ( self ) : <EOL> """<STR_LIT>""" <EOL> logging . debug ( "<STR_LIT>" ) <EOL> self . device . close ( ) </s>
