Skip to content

Commit 407383d

Browse files
author
Developer
committed
Enhanced comments, updated 'Add requested port' routine to take first match only (for Wi-Fi ports named the same), and removed self.appdir patch for future testing and possible elimination.
1 parent eb179bd commit 407383d

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

PropellerLoad.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class PropellerLoad:
1919

2020

2121
def __init__(self):
22+
2223
self.logger = logging.getLogger('blockly.loader')
2324
self.logger.info('Creating loader logger.')
2425

@@ -49,7 +50,8 @@ def __init__(self):
4950

5051

5152
def get_ports(self):
52-
self.logger.info('Get ports')
53+
# Find COM/Wi-Fi serial ports
54+
self.logger.info('Received port list request')
5355

5456
# Return last results if we're currently downloading
5557
if self.loading:
@@ -67,33 +69,41 @@ def get_ports(self):
6769
# Get Wi-Fi ports
6870
(success, out, err) = loader(self, ["-W"])
6971
if success:
72+
# Save Wi-Fi port record(s)
7073
self.wports = out.splitlines()
71-
# Extract Wi-Fi module names and sort them
74+
# Extract Wi-Fi module names (from Wi-Fi records) and sort them
7275
wnames = []
7376
for i in range(len(self.wports)):
7477
wnames.extend([getWiFiName(self.wports[i])])
7578
wnames.sort(None, None, False)
7679
else:
7780
self.logger.debug('WiFi Port request returned %s', err)
7881

82+
# Append Wi-Fi ports to COM ports list
7983
self.ports.extend(wnames)
80-
self.logger.debug('Port count: %s', len(self.ports))
84+
self.logger.debug('Found %s ports', len(self.ports))
8185

8286
return self.ports
8387

8488

8589
def download(self, action, file_to_load, com_port):
90+
# Download application to Propeller
8691
self.loading = True
8792

88-
# Patch until we figure out why the __init__ is not getting called
93+
# Patch - see if __init__ is back in full operation
8994
if not self.appdir or self.appdir == "" or self.appdir == "/":
90-
# realpath expands to full path if __file__ or sys.argv[0] contains just a filename
91-
self.appdir = os.path.dirname(os.path.realpath(__file__))
92-
if self.appdir == "" or self.appdir == "/":
93-
# launch path is blank; try extracting from argv
94-
self.appdir = os.path.dirname(os.path.realpath(sys.argv[0]))
95-
96-
# Set command download to RAM or EEPROM and run afterwards
95+
self.logger.info('ERROR: LOADER FOLDER NOT FOUND!')
96+
return False, ' ', ' '
97+
# Patch below removed temporarily during platform testing
98+
# # Patch until we figure out why the __init__ is not getting called
99+
# if not self.appdir or self.appdir == "" or self.appdir == "/":
100+
# # realpath expands to full path if __file__ or sys.argv[0] contains just a filename
101+
# self.appdir = os.path.dirname(os.path.realpath(__file__))
102+
# if self.appdir == "" or self.appdir == "/":
103+
# # launch path is blank; try extracting from argv
104+
# self.appdir = os.path.dirname(os.path.realpath(sys.argv[0]))
105+
106+
# Set command download to RAM or EEPROM and to run afterward download
97107
command = []
98108
if self.loaderAction[action]["compile-options"] != "":
99109
# if RAM/EEPROM compile-option not empty, add it to the list
@@ -102,12 +112,15 @@ def download(self, action, file_to_load, com_port):
102112

103113
# Add requested port
104114
if com_port is not None:
115+
# Find port(s) named com_port
105116
targetWiFi = [l for l in self.wports if isWiFiName(l, com_port)]
106-
if len(targetWiFi) == 1:
117+
if len(targetWiFi) > 0:
118+
# Found Wi-Fi match
107119
self.logger.debug('Requested port %s is at %s', com_port, getWiFiIP(targetWiFi[0]))
108120
command.extend(["-i"])
109121
command.extend([getWiFiIP(targetWiFi[0]).encode('ascii', 'ignore')])
110122
else:
123+
# Not Wi-Fi match, should be COM port
111124
self.logger.debug('Requested port is %s', com_port)
112125
command.extend(["-p"])
113126
command.extend([com_port.encode('ascii', 'ignore')])
@@ -130,7 +143,7 @@ def loader(self, cmdOptions):
130143
cmdLine = [self.appdir + self.loaderExe[platform.system()]]
131144
cmdLine.extend(cmdOptions)
132145

133-
self.logger.info('Running loader command: %s', cmdLine)
146+
self.logger.debug('Running loader command: %s', cmdLine)
134147

135148
# Run command
136149
if platform.system() == "Windows":

0 commit comments

Comments
 (0)