@@ -92,12 +92,26 @@ def set_packet_count(self, count):
9292 self .packet_count = count
9393
9494 def open (self ):
95- # Get device handle
96- dev = usb_find (idVendor = self .vid , idProduct = self .pid , serial_number = self .serial_number )
95+
96+ # Use pyUSB to get HID Interrupt EP wMaxPacketSize, since hidapi is not reliable
97+
98+ # Get device handle.
99+ # If multiple identical (same PID & VID) probes without serial number are connected,
100+ # assume they share the same wMaxPacketSize.
101+
102+ usb_serial = self .device_info ['serial_number' ]
103+
104+ kwargs = {'idVendor' : self .vid , 'idProduct' : self .pid }
105+ if usb_serial : # only pass a real USB serial
106+ kwargs ['serial_number' ] = usb_serial
107+
108+ probe_id = usb_serial or f"VID={ self .vid :#06x} :PID={ self .pid :#06x} "
109+
110+ dev = usb_find (** kwargs )
97111 if dev is None :
98- raise DAPAccessIntf .DeviceError (f"Probe { self . serial_number } not found" )
112+ raise DAPAccessIntf .DeviceError (f"Probe { probe_id } not found" )
99113
100- # get active config
114+ # Get active config
101115 config = dev .get_active_configuration ()
102116
103117 # Get count of HID interfaces and create the matcher object
@@ -107,7 +121,7 @@ def open(self):
107121 # Get CMSIS-DAPv1 interface
108122 interface = usb .util .find_descriptor (config , custom_match = matcher )
109123 if interface is None :
110- raise DAPAccessIntf .DeviceError (f"Probe { self . serial_number } has no CMSIS-DAPv1 interface" )
124+ raise DAPAccessIntf .DeviceError (f"Probe { probe_id } has no CMSIS-DAPv1 interface" )
111125
112126 # Set report sizes, assuming HID report size matches endpoint wMaxPacketSize.
113127 for endpoint in interface :
@@ -119,7 +133,7 @@ def open(self):
119133
120134 if self .report_in_size is None :
121135 raise DAPAccessIntf .DeviceError (
122- f"Could not determine packet sizes for { self . serial_number } " )
136+ f"Could not determine packet sizes for probe { probe_id } " )
123137
124138 if self .report_out_size is None :
125139 # No interrupt OUT endpoint. Out reports will be sent via control transfer.
0 commit comments