@@ -64,23 +64,35 @@ def rx_task(self):
6464 self .rcv_data .append (self .ep_in .read (self .ep_in .wMaxPacketSize , - 1 ))
6565
6666 @staticmethod
67- def getAllConnectedInterface (vid , pid ):
67+ def getAllConnectedInterface ():
6868 """
6969 returns all the connected devices which matches PyUSB.vid/PyUSB.pid.
7070 returns an array of PyUSB (Interface) objects
7171 """
7272 # find all devices matching the vid/pid specified
73- all_devices = usb .core .find (find_all = True , idVendor = vid , idProduct = pid )
73+ all_devices = usb .core .find (find_all = True )
7474
7575 if not all_devices :
7676 logging .debug ("No device connected" )
77- return None
77+ return []
7878
7979 boards = []
8080
8181 # iterate on all devices found
8282 for board in all_devices :
8383 interface_number = - 1
84+ try :
85+ # The product string is read over USB when accessed.
86+ # This can cause an exception to be thrown if the device
87+ # is malfunctioning.
88+ product = board .product
89+ except usb .core .USBError as error :
90+ logging .warning ("Exception getting product string: %s" , error )
91+ continue
92+ if (product is None ) or (product .find ("CMSIS-DAP" ) < 0 ):
93+ # Not a cmsis-dap device so close it
94+ usb .util .dispose_resources (board )
95+ continue
8496
8597 # get active config
8698 config = board .get_active_configuration ()
@@ -108,8 +120,6 @@ def getAllConnectedInterface(vid, pid):
108120 else :
109121 ep_out = ep
110122
111- product_name = usb .util .get_string (board , 2 )
112- vendor_name = usb .util .get_string (board , 1 )
113123 """If there is no EP for OUT then we can use CTRL EP"""
114124 if not ep_in :
115125 logging .error ('Endpoints not found' )
@@ -119,11 +129,12 @@ def getAllConnectedInterface(vid, pid):
119129 new_board .ep_in = ep_in
120130 new_board .ep_out = ep_out
121131 new_board .dev = board
122- new_board .vid = vid
123- new_board .pid = pid
132+ new_board .vid = board . idVendor
133+ new_board .pid = board . idProduct
124134 new_board .intf_number = interface_number
125- new_board .product_name = product_name
126- new_board .vendor_name = vendor_name
135+ new_board .product_name = product
136+ new_board .vendor_name = board .manufacturer
137+ new_board .serial_number = board .serial_number
127138 new_board .start_rx ()
128139 boards .append (new_board )
129140
@@ -169,6 +180,9 @@ def setPacketCount(self, count):
169180 # No interface level restrictions on count
170181 self .packet_count = count
171182
183+ def getSerialNumber (self ):
184+ return self .serial_number
185+
172186 def close (self ):
173187 """
174188 close the interface
0 commit comments