Skip to content

Commit ad61f14

Browse files
committed
Fix: Missing serial port after list refresh 'n "SteamVR dashboard reload":
#63
1 parent 50d03ce commit ad61f14

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

BabbleApp/utils/misc_utils.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import typing
22
import serial
3+
import serial.tools.list_ports
34
import sys
45
import glob
56
import os
@@ -124,25 +125,16 @@ def list_serial_ports():
124125
:returns:
125126
A list of the serial ports available on the system
126127
"""
127-
if sys.platform.startswith("win"):
128-
ports = ["COM%s" % (i + 1) for i in range(256)]
129-
elif sys.platform.startswith("linux") or sys.platform.startswith("cygwin"):
130-
# this excludes your current terminal "/dev/tty"
131-
ports = glob.glob("/dev/tty[A-Za-z]*")
132-
elif sys.platform.startswith("darwin"):
133-
ports = glob.glob("/dev/tty.*")
134-
else:
128+
if not sys.platform.startswith(("win", "linux", "cygwin", "darwin")):
135129
raise EnvironmentError("Unsupported platform")
136130

137-
result = []
138-
for port in ports:
139-
try:
140-
s = serial.Serial(port)
141-
s.close()
142-
result.append(port)
143-
except (OSError, serial.SerialException):
144-
pass
145-
return result
131+
ports = []
132+
try:
133+
for s in serial.tools.list_ports.comports():
134+
ports.append(s.device)
135+
except (AttributeError, OSError, serial.SerialException):
136+
pass
137+
return sorted(ports)
146138

147139

148140
def get_camera_index_by_name(name):

0 commit comments

Comments
 (0)