@@ -40,9 +40,9 @@ def __init__(self):
4040 def list_mbeds (self ):
4141 """! Returns detailed list of connected mbeds
4242
43- @return Returns list of structures with detailed info about each mbed
43+ @return Returns list of structures with detailed info about each mbed
4444
45- @details Function returns list of dictionaries with mbed attributes such as mount point, TargetID name etc.
45+ @details Function returns list of dictionaries with mbed attributes such as mount point, TargetID name etc.
4646 """
4747 self .ERRORLEVEL_FLAG = 0
4848
@@ -65,32 +65,29 @@ def list_mbeds(self):
6565 def discover_connected_mbeds (self , defs = {}):
6666 """! Function produces list of mbeds with additional information and bind mbed with correct TargetID
6767
68- @return Returns [(<mbed_mount_point>, <mbed_id>, <com port>, <board model>), ..]
68+ @return Returns [(<mbed_mount_point>, <mbed_id>, <com port>, <board model>), ..]
6969
70- @details Notice: this function is permissive: adds new elements in-places when and if found
70+ @details Notice: this function is permissive: adds new elements in-places when and if found
7171 """
7272 mbeds = [(m [0 ], m [1 ], None , None ) for m in self .get_connected_mbeds ()]
7373 for i in range (len (mbeds )):
7474 mbed = mbeds [i ]
75- mnt , mbed_id = mbed [0 ], mbed [ 1 ]
76- mbed_id_prefix = mbed_id [ 0 : 4 ]
75+ mnt = mbed [0 ]
76+ mbed_htm_target_id = self . get_mbed_htm_target_id ( mnt )
7777 # Deducing mbed-enabled TargetID based on available targetID definition DB.
7878 # If TargetID from USBID is not recognized we will try to check URL in mbed.htm
79- mbed_htm_target_id = self .get_mbed_htm_target_id (mnt )
80- if mbed_htm_target_id :
81- mbed_id = mbed_htm_target_id if mbed_htm_target_id is not None else mbed_id
79+ mbed_id = mbed_htm_target_id if mbed_htm_target_id is not None else mbed [1 ]
8280 mbed_id_prefix = mbed_id [0 :4 ]
8381 board = defs [mbed_id_prefix ] if mbed_id_prefix in defs else None
84- mbeds [i ] = (mnt , mbed_id , mbeds [i ][2 ], board )
85-
8682 port = self .get_mbed_com_port (mbed [1 ])
87- if port :
88- mbeds [i ] = (mnt , mbed_id , port , mbeds [i ][3 ], mbed [1 ], mbed_htm_target_id )
83+ mbeds [i ] = (mnt , mbed_id , port , board , mbed [1 ], mbed_htm_target_id )
8984 return mbeds
9085
91- def get_mbed_com_port (self , id ):
86+ def get_mbed_com_port (self , tid ):
9287 """! Function checks mbed serial port in Windows registry entries
9388
89+ @param tid TargetID
90+
9491 @return Returns None if port is not found. In normal circumstances it should never return None
9592
9693 @details This goes through a whole new loop, but this assures that even if serial port (COM)
@@ -100,13 +97,13 @@ def get_mbed_com_port(self, id):
10097 usb_devs = self .winreg .OpenKey (self .winreg .Enum , 'USB' )
10198
10299 if self .DEBUG_FLAG :
103- self .debug (self .get_mbed_com_port .__name__ , 'ID: ' + id )
100+ self .debug (self .get_mbed_com_port .__name__ , 'ID: ' + tid )
104101
105- # first try to find all devs keys (by id )
102+ # first try to find all devs keys (by tid )
106103 dev_keys = []
107104 for vid in self .iter_keys (usb_devs ):
108105 try :
109- dev_keys += [self .winreg .OpenKey (vid , id )]
106+ dev_keys += [self .winreg .OpenKey (vid , tid )]
110107 except :
111108 pass
112109
@@ -137,6 +134,8 @@ def get_mbed_com_port(self, id):
137134 return port
138135 except :
139136 pass
137+ # If everything fails, return None
138+ return None
140139
141140 def get_connected_mbeds (self ):
142141 """! Function return mbeds with existing mount point
@@ -157,11 +156,11 @@ def get_mbeds(self):
157156 mbeds = []
158157 for mbed in self .get_mbed_devices ():
159158 mountpoint = re .match ('.*\\ \\ (.:)$' , mbed [0 ]).group (1 )
160- # id is a hex string with 10-48 chars
161- id = re .search ('[0-9A-Fa-f]{10,48}' , mbed [1 ]).group (0 )
162- mbeds += [(mountpoint , id )]
159+ # TargetID is a hex string with 10-48 chars
160+ tid = re .search ('[0-9A-Fa-f]{10,48}' , mbed [1 ]).group (0 )
161+ mbeds += [(mountpoint , tid )]
163162 if self .DEBUG_FLAG :
164- self .debug (self .get_mbeds .__name__ , (mountpoint , id ))
163+ self .debug (self .get_mbeds .__name__ , (mountpoint , tid ))
165164 return mbeds
166165
167166 # =============================== Registry ====================================
0 commit comments