Skip to content

Commit 9d04335

Browse files
committed
Add _detect_available_configs to serial_can
1 parent 2d672b3 commit 9d04335

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

can/interfaces/serial/serial_can.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
)
2222
serial = None
2323

24+
try:
25+
from serial.tools import list_ports
26+
except ImportError:
27+
list_ports = None
28+
2429

2530
class SerialBus(BusABC):
2631
"""
@@ -162,3 +167,15 @@ def fileno(self):
162167
return self.ser.fileno()
163168
# Return an invalid file descriptor on Windows
164169
return -1
170+
171+
@staticmethod
172+
def _detect_available_configs():
173+
channels = []
174+
serial_ports = []
175+
176+
if list_ports:
177+
serial_ports = list_ports.comports()
178+
179+
for port in serial_ports:
180+
channels.append({"interface": "serial", "channel": port.device})
181+
return channels

0 commit comments

Comments
 (0)