mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 10:07:14 +02:00
Implement grep serial ports for Windows
This commit is contained in:
@ -285,19 +285,28 @@ def get_serialports(use_grep=False):
|
|||||||
def _grep_serial_ports():
|
def _grep_serial_ports():
|
||||||
result = []
|
result = []
|
||||||
if system() == "Windows":
|
if system() == "Windows":
|
||||||
return result
|
output = exec_command(["mode"]).get("out", "")
|
||||||
if system() == "Linux":
|
for line in output.split("\n"):
|
||||||
patterns = ["/dev/%s*" % p for p in (
|
line = line.strip()
|
||||||
"ttyS", "ttyUSB", "ttyACM", "ttyAMA", "rfcomm", "ttyO")]
|
if "COM" in line:
|
||||||
|
result.append({"port": line[line.index("COM"):-1],
|
||||||
|
"description": "", "hwid": ""})
|
||||||
else:
|
else:
|
||||||
patterns = ["/dev/tty.*", "/dev/cu.*"]
|
if system() == "Linux":
|
||||||
for pattern in patterns:
|
patterns = ["/dev/%s*" % p for p in (
|
||||||
for port in glob(pattern):
|
"ttyS", "ttyUSB", "ttyACM", "ttyAMA", "rfcomm", "ttyO")]
|
||||||
result.append({"port": port, "description": "", "hwid": ""})
|
else:
|
||||||
|
patterns = ["/dev/tty.*", "/dev/cu.*"]
|
||||||
|
for pattern in patterns:
|
||||||
|
for port in glob(pattern):
|
||||||
|
result.append(
|
||||||
|
{"port": port, "description": "", "hwid": ""})
|
||||||
return result
|
return result
|
||||||
|
|
||||||
if use_grep and system() != "Windows":
|
if use_grep:
|
||||||
return _grep_serial_ports()
|
result = _grep_serial_ports()
|
||||||
|
if result:
|
||||||
|
return result
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from serial.tools.list_ports import comports
|
from serial.tools.list_ports import comports
|
||||||
@ -316,7 +325,7 @@ def get_serialports(use_grep=False):
|
|||||||
result.append({"port": p, "description": d, "hwid": h})
|
result.append({"port": p, "description": d, "hwid": h})
|
||||||
|
|
||||||
# fix for PySerial
|
# fix for PySerial
|
||||||
if not result:
|
if not result and not use_grep:
|
||||||
result = _grep_serial_ports()
|
result = _grep_serial_ports()
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@ -326,7 +335,7 @@ def get_logicaldisks():
|
|||||||
disks = []
|
disks = []
|
||||||
if system() == "Windows":
|
if system() == "Windows":
|
||||||
result = exec_command(
|
result = exec_command(
|
||||||
["wmic", "logicaldisk", "get", "name,VolumeName"]).get("out")
|
["wmic", "logicaldisk", "get", "name,VolumeName"]).get("out", "")
|
||||||
disknamere = re.compile(r"^([A-Z]{1}\:)\s*(\S+)?")
|
disknamere = re.compile(r"^([A-Z]{1}\:)\s*(\S+)?")
|
||||||
for line in result.split("\n"):
|
for line in result.split("\n"):
|
||||||
match = disknamere.match(line.strip())
|
match = disknamere.match(line.strip())
|
||||||
|
Reference in New Issue
Block a user