<s> """<STR_LIT>""" <EOL> from interface import Interface <EOL> import logging , os <EOL> try : <EOL> import hid <EOL> except : <EOL> if os . name == "<STR_LIT>" and os . uname ( ) [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> logging . error ( "<STR_LIT>" ) <EOL> available = False <EOL> else : <EOL> hid . enumerate ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> available = True <EOL> class HidApiUSB ( Interface ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> available = available <EOL> def __init__ ( self ) : <EOL> super ( HidApiUSB , self ) . __init__ ( ) <EOL> self . device = None <EOL> def open ( self ) : <EOL> try : <EOL> self . device . open ( self . vid , self . pid ) <EOL> except AttributeError : <EOL> pass <EOL> @ staticmethod <EOL> def getConnectedInterfaces ( vid , pid ) : <EOL> """<STR_LIT>""" <EOL> devices = hid . enumerate ( vid , pid ) <EOL> if not devices : <EOL> logging . debug ( "<STR_LIT>" ) <EOL> return <EOL> boards = [ ] <EOL> for deviceInfo in devices : <EOL> try : <EOL> dev = hid . device ( vendor_id = vid , product_id = pid , path = deviceInfo [ '<STR_LIT:path>' ] ) <EOL> except IOError : <EOL> logging . debug ( "<STR_LIT>" ) <EOL> return <EOL> new_board = HidApiUSB ( ) <EOL> new_board . vendor_name = deviceInfo [ '<STR_LIT>' ] <EOL> new_board . product_name = deviceInfo [ '<STR_LIT>' ] <EOL> new_board . serial_number = deviceInfo [ '<STR_LIT>' ] <EOL> new_board . vid = deviceInfo [ '<STR_LIT>' ] <EOL> new_board . pid = deviceInfo [ '<STR_LIT>' ] <EOL> new_board . path = deviceInfo [ '<STR_LIT: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 . device . write ( [ <NUM_LIT:0> ] + data ) <EOL> return <EOL> def read ( self , timeout = - <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> return self . device . read ( <NUM_LIT:64> ) <EOL> def close ( self ) : <EOL> """<STR_LIT>""" <EOL> self . device . close ( ) <EOL> def setPacketCount ( self , count ) : <EOL> self . packet_count = count <EOL> def __eq__ ( self , other ) : <EOL> return self . path == other . path </s>
