From e1e4ee01ef0b1541f34623455aa511f0c8fc3632 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Sat, 17 Apr 2021 12:27:18 +0100 Subject: [PATCH] List valid com ports on windows. --- helpers/device_manager.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/helpers/device_manager.py b/helpers/device_manager.py index 7cdb576..889d190 100644 --- a/helpers/device_manager.py +++ b/helpers/device_manager.py @@ -2,6 +2,8 @@ from typing import Any, Dict, List, Optional, Tuple import sounddevice as sd from helpers.os_environment import isLinux, isMacOS, isWindows import glob +if isWindows(): + from serial.tools.list_ports_windows import comports # TODO: https://wiki.libsdl.org/FAQUsingSDL maybe try setting some of these env variables for choosing different host APIs? WINDOWS_APIS = ["Windows DirectSound"] @@ -55,9 +57,8 @@ class DeviceManager: :returns: A list of the serial ports available on the system """ - # TODO: Get list of COM ports properly. (Can't use ) if isWindows(): - ports = ["COM%s" % (i + 1) for i in range(8)] + ports = [port.device for port in comports()] elif isLinux(): # this excludes your current terminal "/dev/tty" ports = glob.glob("/dev/tty[A-Za-z]*")