#NEWLINE# def __init__( self , device_path , parent_instance_id = 0 , instance_id = '' ) : #NEWLINE# #INDENT# 'Interface for HID device as referenced by device_path parameter' #NEWLINE# self . __open_status = False #NEWLINE# self . __input_report_templates = dict ( ) #NEWLINE# self . __button_caps_storage = list ( ) #NEWLINE# self . report_set = dict ( ) #NEWLINE# self . __evt_handlers = dict ( ) #NEWLINE# self . __reading_thread = None #NEWLINE# self . __input_processing_thread = None #NEWLINE# self . __raw_handler = None #NEWLINE# self . _input_report_queue = None #NEWLINE# self . hid_caps = None #NEWLINE# self . ptr_preparsed_data = None #NEWLINE# self . hid_handle = None #NEWLINE# self . usages_storage = dict ( ) #NEWLINE# self . device_path = device_path #NEWLINE# self . instance_id = instance_id #NEWLINE# self . parent_instance_id = parent_instance_id #NEWLINE# self . product_name = '' #NEWLINE# self . vendor_name = '' #NEWLINE# self . serial_number = '' #NEWLINE# self . vendor_id = 0 #NEWLINE# self . product_id = 0 #NEWLINE# self . version_number = 0 #NEWLINE# HidDeviceBaseClass . __init__ ( self ) #NEWLINE# h_hid = INVALID_HANDLE_VALUE #NEWLINE# try : #NEWLINE# #INDENT# h_hid = int ( winapi . CreateFile ( device_path , ( winapi . GENERIC_READ | winapi . GENERIC_WRITE ) , ( winapi . FILE_SHARE_READ | winapi . FILE_SHARE_WRITE ) , None , winapi . OPEN_EXISTING , 0 , 0 ) ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# if ( h_hid == INVALID_HANDLE_VALUE ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# hidd_attributes = winapi . HIDD_ATTRIBUTES ( ) #NEWLINE# hidd_attributes . cb_size = sizeof ( hidd_attributes ) #NEWLINE# if ( not hid_dll . HidD_GetAttributes ( h_hid , byref ( hidd_attributes ) ) ) : #NEWLINE# #INDENT# del hidd_attributes #NEWLINE# return #NEWLINE# #UNINDENT# self . vendor_id = hidd_attributes . vendor_id #NEWLINE# self . product_id = hidd_attributes . product_id #NEWLINE# self . version_number = hidd_attributes . version_number #NEWLINE# del hidd_attributes #NEWLINE# vendor_string_type = ( c_wchar * self . MAX_MANUFACTURER_STRING_LEN ) #NEWLINE# vendor_name = vendor_string_type ( ) #NEWLINE# if ( ( not hid_dll . HidD_GetManufacturerString ( h_hid , byref ( vendor_name ) , sizeof ( vendor_name ) ) ) or ( not len ( vendor_name . value ) ) ) : #NEWLINE# #INDENT# self . vendor_name = 'Unknown manufacturer' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . vendor_name = vendor_name . value #NEWLINE# #UNINDENT# del vendor_name #NEWLINE# del vendor_string_type #NEWLINE# product_name_type = ( c_wchar * self . MAX_PRODUCT_STRING_LEN ) #NEWLINE# product_name = product_name_type ( ) #NEWLINE# if ( ( not hid_dll . HidD_GetProductString ( h_hid , byref ( product_name ) , sizeof ( product_name ) ) ) or ( not len ( product_name . value ) ) ) : #NEWLINE# #INDENT# path_parts = device_path [ len ( '\\\\.\\' ) : ] . split ( '#' ) #NEWLINE# h_register = winreg . OpenKey ( winreg . HKEY_LOCAL_MACHINE , ( ( ( ( ( 'SYSTEM\\CurrentControlSet\\Enum\\' + path_parts [ 0 ] ) + '\\' ) + path_parts [ 1 ] ) + '\\' ) + path_parts [ 2 ] ) ) #NEWLINE# ( self . product_name , other ) = winreg . QueryValueEx ( h_register , 'DeviceDesc' ) #NEWLINE# winreg . CloseKey ( h_register ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . product_name = product_name . value #NEWLINE# #UNINDENT# del product_name #NEWLINE# del product_name_type #NEWLINE# serial_number_string = ( c_wchar * self . MAX_SERIAL_NUMBER_LEN ) #NEWLINE# serial_number = serial_number_string ( ) #NEWLINE# if ( ( not hid_dll . HidD_GetSerialNumberString ( h_hid , byref ( serial_number ) , sizeof ( serial_number ) ) ) or ( not len ( serial_number . value ) ) ) : #NEWLINE# #INDENT# self . serial_number = '' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . serial_number = serial_number . value #NEWLINE# #UNINDENT# del serial_number #NEWLINE# del serial_number_string #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# winapi . CloseHandle ( h_hid )