From 8b0e7819eb5dff9aa1f0ffdcd39b1e5b4c9f62c7 Mon Sep 17 00:00:00 2001 From: Conor Keegan Date: Tue, 6 Sep 2016 10:42:30 +0100 Subject: [PATCH 1/2] Add check for USB ID when getting COM port --- mbed_lstools/lstools_win7.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/mbed_lstools/lstools_win7.py b/mbed_lstools/lstools_win7.py index 10024d5..fe9ec03 100644 --- a/mbed_lstools/lstools_win7.py +++ b/mbed_lstools/lstools_win7.py @@ -124,6 +124,14 @@ def get_mbed_com_port(self, tid): return port except: pass + + # Check for a target USB ID from tid + target_usb_ids = self.get_connected_mbeds_usb_ids() + if tid in target_usb_ids: + if target_usb_ids[tid] != tid: + # Try again with the target USB ID + return self.get_mbed_com_port(target_usb_ids[tid]) + # If everything fails, return None return None @@ -134,6 +142,19 @@ def get_connected_mbeds(self): """ return [m for m in self.get_mbeds() if os.path.exists(m[0])] + def get_connected_mbeds_usb_ids(self): + """! Function return mbeds with existing mount point's + target ID mapped to their target USB ID + @return Returns {: , ...} + @details Helper function + """ + connected_mbeds_ids = {} + for mbed in self.get_connected_mbeds(): + htm_target_id = self.get_mbed_htm_target_id(mbed[0]) + target_id = htm_target_id if htm_target_id else mbed[1] + connected_mbeds_ids[target_id] = mbed[1] + return connected_mbeds_ids + def get_mbeds(self): """! Function filters devices' mount points for valid TargetID @return Returns [(, ), ..] From 1442ea0c28c7e5f46a3f518cc381b2836058db5c Mon Sep 17 00:00:00 2001 From: Conor Keegan Date: Wed, 7 Sep 2016 10:35:04 +0100 Subject: [PATCH 2/2] Remove duplicate logic --- mbed_lstools/lstools_win7.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/mbed_lstools/lstools_win7.py b/mbed_lstools/lstools_win7.py index fe9ec03..0eaf13a 100644 --- a/mbed_lstools/lstools_win7.py +++ b/mbed_lstools/lstools_win7.py @@ -62,17 +62,15 @@ def list_mbeds(self): def discover_connected_mbeds(self, defs={}): """! Function produces list of mbeds with additional information and bind mbed with correct TargetID - @return Returns [(, , , ), ..] + @return Returns [(, , , , + , ), ..] @details Notice: this function is permissive: adds new elements in-places when and if found """ mbeds = [(m[0], m[1], None, None) for m in self.get_connected_mbeds()] for i in range(len(mbeds)): mbed = mbeds[i] mnt = mbed[0] - mbed_htm_target_id = self.get_mbed_htm_target_id(mnt) - # Deducing mbed-enabled TargetID based on available targetID definition DB. - # If TargetID from USBID is not recognized we will try to check URL in mbed.htm - mbed_id = mbed_htm_target_id if mbed_htm_target_id is not None else mbed[1] + mbed_id, mbed_htm_target_id = self.get_mbed_target_id(mnt, mbed[1]) mbed_id_prefix = mbed_id[0:4] board = defs[mbed_id_prefix] if mbed_id_prefix in defs else None port = self.get_mbed_com_port(mbed[1]) @@ -150,8 +148,7 @@ def get_connected_mbeds_usb_ids(self): """ connected_mbeds_ids = {} for mbed in self.get_connected_mbeds(): - htm_target_id = self.get_mbed_htm_target_id(mbed[0]) - target_id = htm_target_id if htm_target_id else mbed[1] + target_id, htm_target_id = self.get_mbed_target_id(mbed[0], mbed[1]) connected_mbeds_ids[target_id] = mbed[1] return connected_mbeds_ids @@ -169,6 +166,19 @@ def get_mbeds(self): self.debug(self.get_mbeds.__name__, (mountpoint, tid)) return mbeds + def get_mbed_target_id(self, mnt, target_usb_id): + """! Function gets the mbed target and HTM IDs + @param mnt mbed mount point (disk / drive letter) + @param target_usb_id mbed target USB ID + @return Function returns (, ) + @details Helper function + """ + mbed_htm_target_id = self.get_mbed_htm_target_id(mnt) + # Deducing mbed-enabled TargetID based on available targetID definition DB. + # If TargetID from USBID is not recognized we will try to check URL in mbed.htm + mbed_id = mbed_htm_target_id if mbed_htm_target_id is not None else target_usb_id + return mbed_id, mbed_htm_target_id + # =============================== Registry ==================================== def iter_keys_as_str(self, key):