Skip to content

Fix: Missing serial port after list refresh... #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions BabbleApp/utils/misc_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import typing
import serial
import serial.tools.list_ports
import sys
import glob
import os
Expand Down Expand Up @@ -124,25 +125,16 @@ def list_serial_ports():
:returns:
A list of the serial ports available on the system
"""
if sys.platform.startswith("win"):
ports = ["COM%s" % (i + 1) for i in range(256)]
elif sys.platform.startswith("linux") or sys.platform.startswith("cygwin"):
# this excludes your current terminal "/dev/tty"
ports = glob.glob("/dev/tty[A-Za-z]*")
elif sys.platform.startswith("darwin"):
ports = glob.glob("/dev/tty.*")
else:
if not sys.platform.startswith(("win", "linux", "cygwin", "darwin")):
raise EnvironmentError("Unsupported platform")

result = []
for port in ports:
try:
s = serial.Serial(port)
s.close()
result.append(port)
except (OSError, serial.SerialException):
pass
return result
ports = []
try:
for s in serial.tools.list_ports.comports():
ports.append(s.device)
except (AttributeError, OSError, serial.SerialException):
pass
return sorted(ports)


def get_camera_index_by_name(name):
Expand Down