@@ -62,17 +62,15 @@ def list_mbeds(self):
6262
6363 def discover_connected_mbeds (self , defs = {}):
6464 """! Function produces list of mbeds with additional information and bind mbed with correct TargetID
65- @return Returns [(<mbed_mount_point>, <mbed_id>, <com port>, <board model>), ..]
65+ @return Returns [(<mbed_mount_point>, <mbed_id>, <com port>, <board model>,
66+ <usb_target_id>, <htm_target_id>), ..]
6667 @details Notice: this function is permissive: adds new elements in-places when and if found
6768 """
6869 mbeds = [(m [0 ], m [1 ], None , None ) for m in self .get_connected_mbeds ()]
6970 for i in range (len (mbeds )):
7071 mbed = mbeds [i ]
7172 mnt = mbed [0 ]
72- mbed_htm_target_id = self .get_mbed_htm_target_id (mnt )
73- # Deducing mbed-enabled TargetID based on available targetID definition DB.
74- # If TargetID from USBID is not recognized we will try to check URL in mbed.htm
75- mbed_id = mbed_htm_target_id if mbed_htm_target_id is not None else mbed [1 ]
73+ mbed_id , mbed_htm_target_id = self .get_mbed_target_id (mnt , mbed [1 ])
7674 mbed_id_prefix = mbed_id [0 :4 ]
7775 board = defs [mbed_id_prefix ] if mbed_id_prefix in defs else None
7876 port = self .get_mbed_com_port (mbed [1 ])
@@ -124,6 +122,14 @@ def get_mbed_com_port(self, tid):
124122 return port
125123 except :
126124 pass
125+
126+ # Check for a target USB ID from tid
127+ target_usb_ids = self .get_connected_mbeds_usb_ids ()
128+ if tid in target_usb_ids :
129+ if target_usb_ids [tid ] != tid :
130+ # Try again with the target USB ID
131+ return self .get_mbed_com_port (target_usb_ids [tid ])
132+
127133 # If everything fails, return None
128134 return None
129135
@@ -134,6 +140,18 @@ def get_connected_mbeds(self):
134140 """
135141 return [m for m in self .get_mbeds () if self .mount_point_ready (m [0 ])]
136142
143+ def get_connected_mbeds_usb_ids (self ):
144+ """! Function return mbeds with existing mount point's
145+ target ID mapped to their target USB ID
146+ @return Returns {<target_id>: <target_usb_id>, ...}
147+ @details Helper function
148+ """
149+ connected_mbeds_ids = {}
150+ for mbed in self .get_connected_mbeds ():
151+ target_id , htm_target_id = self .get_mbed_target_id (mbed [0 ], mbed [1 ])
152+ connected_mbeds_ids [target_id ] = mbed [1 ]
153+ return connected_mbeds_ids
154+
137155 def get_mbeds (self ):
138156 """! Function filters devices' mount points for valid TargetID
139157 @return Returns [(<mbed_mount_point>, <mbed_id>), ..]
@@ -148,6 +166,19 @@ def get_mbeds(self):
148166 self .debug (self .get_mbeds .__name__ , (mountpoint , tid ))
149167 return mbeds
150168
169+ def get_mbed_target_id (self , mnt , target_usb_id ):
170+ """! Function gets the mbed target and HTM IDs
171+ @param mnt mbed mount point (disk / drive letter)
172+ @param target_usb_id mbed target USB ID
173+ @return Function returns (<target_id>, <htm_target_id>)
174+ @details Helper function
175+ """
176+ mbed_htm_target_id = self .get_mbed_htm_target_id (mnt )
177+ # Deducing mbed-enabled TargetID based on available targetID definition DB.
178+ # If TargetID from USBID is not recognized we will try to check URL in mbed.htm
179+ mbed_id = mbed_htm_target_id if mbed_htm_target_id is not None else target_usb_id
180+ return mbed_id , mbed_htm_target_id
181+
151182 # =============================== Registry ====================================
152183
153184 def iter_keys_as_str (self , key ):
0 commit comments