@@ -73,22 +73,20 @@ def get_descriptor(device, desc_type, index, buf, language_id=0):
7373 # pylint: disable=invalid-name
7474 wValue = desc_type << 8 | index
7575 wIndex = language_id
76- result = device .ctrl_transfer (
76+ device .ctrl_transfer (
7777 _REQ_RCPT_DEVICE | _REQ_TYPE_STANDARD | _DIR_IN ,
7878 _REQ_GET_DESCRIPTOR ,
7979 wValue ,
8080 wIndex ,
8181 buf ,
8282 )
83- if isinstance (result , array .array ):
84- buf [:] = result .tobytes ()
8583
8684
8785def get_device_descriptor (device ):
8886 """Fetch the device descriptor and return it."""
89- buf = bytearray (1 )
87+ buf = array . array ( "B" , bytearray (1 ) )
9088 get_descriptor (device , DESC_DEVICE , 0 , buf )
91- full_buf = bytearray (buf [0 ])
89+ full_buf = array . array ( "B" , bytearray (buf [0 ]) )
9290 get_descriptor (device , DESC_DEVICE , 0 , full_buf )
9391 return full_buf
9492
@@ -97,10 +95,10 @@ def get_configuration_descriptor(device, index):
9795 """Fetch the configuration descriptor, its associated descriptors and return it."""
9896 # Allow capitalization that matches the USB spec.
9997 # pylint: disable=invalid-name
100- buf = bytearray (4 )
98+ buf = array . array ( "B" , bytearray (4 ) )
10199 get_descriptor (device , DESC_CONFIGURATION , index , buf )
102100 wTotalLength = struct .unpack ("<xxH" , buf )[0 ]
103- full_buf = bytearray (wTotalLength )
101+ full_buf = array . array ( "B" , bytearray (wTotalLength ) )
104102 get_descriptor (device , DESC_CONFIGURATION , index , full_buf )
105103 return full_buf
106104
@@ -113,19 +111,17 @@ def get_report_descriptor(device, interface_num, length):
113111 if length < 1 :
114112 return None
115113
116- buf = bytearray (length )
114+ buf = array . array ( "B" , bytearray (length ) )
117115 try :
118116 # 0x81 = Dir: IN | Type: Standard | Recipient: Interface
119117 # wValue = 0x2200 (Report Descriptor)
120- result = device .ctrl_transfer (
118+ device .ctrl_transfer (
121119 _RECIP_INTERFACE | _REQ_TYPE_STANDARD | _DIR_IN ,
122120 _REQ_GET_DESCRIPTOR ,
123121 DESC_REPORT << 8 ,
124122 interface_num ,
125123 buf ,
126124 )
127- if isinstance (result , array .array ):
128- buf [:] = result .tobytes ()
129125 return buf
130126 except usb .core .USBError as e :
131127 print (f"Failed to read Report Descriptor: { e } " )
0 commit comments