diff --git a/platformio/__init__.py b/platformio/__init__.py index 31611539..3c76b90d 100644 --- a/platformio/__init__.py +++ b/platformio/__init__.py @@ -14,7 +14,7 @@ import sys -VERSION = (2, 9, "3.dev0") +VERSION = (2, 9, "3.dev1") __version__ = ".".join([str(s) for s in VERSION]) __title__ = "platformio" diff --git a/platformio/builder/scripts/atmelavr.py b/platformio/builder/scripts/atmelavr.py index a4b53263..ff3ceadf 100644 --- a/platformio/builder/scripts/atmelavr.py +++ b/platformio/builder/scripts/atmelavr.py @@ -65,7 +65,7 @@ def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621 if not upload_options.get("disable_flushing", False): env.FlushSerialBuffer("$UPLOAD_PORT") - before_ports = [i['port'] for i in get_serialports(use_grep=True)] + before_ports = get_serialports() if upload_options.get("use_1200bps_touch", False): env.TouchSerialPort("$UPLOAD_PORT", 1200) diff --git a/platformio/builder/scripts/atmelsam.py b/platformio/builder/scripts/atmelsam.py index a78febf0..79eca59e 100644 --- a/platformio/builder/scripts/atmelsam.py +++ b/platformio/builder/scripts/atmelsam.py @@ -41,7 +41,7 @@ def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621 if not upload_options.get("disable_flushing", False): env.FlushSerialBuffer("$UPLOAD_PORT") - before_ports = [i['port'] for i in get_serialports(use_grep=True)] + before_ports = get_serialports() if upload_options.get("use_1200bps_touch", False): env.TouchSerialPort("$UPLOAD_PORT", 1200) diff --git a/platformio/builder/tools/pioupload.py b/platformio/builder/tools/pioupload.py index caebdb56..80d66461 100644 --- a/platformio/builder/tools/pioupload.py +++ b/platformio/builder/tools/pioupload.py @@ -14,6 +14,7 @@ from __future__ import absolute_import +import sys from os.path import isfile, join from shutil import copyfile from time import sleep @@ -49,21 +50,25 @@ def TouchSerialPort(env, port, baudrate): def WaitForNewSerialPort(env, before): print "Waiting for the new upload port..." + prev_port = env.subst("$UPLOAD_PORT") new_port = None elapsed = 0 - while elapsed < 5: - now = [i['port'] for i in get_serialports(use_grep=True)] - diff = list(set(now) - set(before)) - if diff: - new_port = diff[0] - break - + while elapsed < 5 and new_port is None: + now = get_serialports() + for p in now: + if p not in before: + new_port = p['port'] + break before = now sleep(0.25) elapsed += 0.25 - if not new_port and env.subst("$UPLOAD_PORT") in now: - new_port = env.subst("$UPLOAD_PORT") + if not new_port: + for p in now: + if prev_port == p['port']: + new_port = p['port'] + break + if not new_port: env.Exit("Error: Couldn't find a board on the selected port. " "Check that you have the correct port selected. " diff --git a/platformio/util.py b/platformio/util.py index 13a9b9e6..36576295 100644 --- a/platformio/util.py +++ b/platformio/util.py @@ -280,34 +280,7 @@ def exec_command(*args, **kwargs): return result -def get_serialports(use_grep=False): - - def _grep_serial_ports(): - result = [] - if system() == "Windows": - output = exec_command(["mode"]).get("out", "") - for line in output.split("\n"): - line = line.strip() - if "COM" in line: - result.append({"port": line[line.index("COM"):-1], - "description": "", "hwid": ""}) - else: - if system() == "Linux": - patterns = ["/dev/%s*" % p for p in ( - "ttyS", "ttyUSB", "ttyACM", "ttyAMA", "rfcomm", "ttyO")] - else: - patterns = ["/dev/tty.*", "/dev/cu.*"] - for pattern in patterns: - for port in glob(pattern): - result.append( - {"port": port, "description": "", "hwid": ""}) - return result - - if use_grep: - result = _grep_serial_ports() - if result: - return result - +def get_serialports(): try: from serial.tools.list_ports import comports except ImportError: @@ -325,9 +298,9 @@ def get_serialports(use_grep=False): result.append({"port": p, "description": d, "hwid": h}) # fix for PySerial - if not result and not use_grep and system() == "Darwin": - result = _grep_serial_ports() - + if not result and system() == "Darwin": + for p in glob("/dev/tty.*"): + result.append({"port": p, "description": "", "hwid": ""}) return result