File tree Expand file tree Collapse file tree 1 file changed +9
-17
lines changed Expand file tree Collapse file tree 1 file changed +9
-17
lines changed Original file line number Diff line number Diff line change 1
1
import typing
2
2
import serial
3
+ import serial .tools .list_ports
3
4
import sys
4
5
import glob
5
6
import os
@@ -124,25 +125,16 @@ def list_serial_ports():
124
125
:returns:
125
126
A list of the serial ports available on the system
126
127
"""
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" )):
135
129
raise EnvironmentError ("Unsupported platform" )
136
130
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 )
146
138
147
139
148
140
def get_camera_index_by_name (name ):
You can’t perform that action at this time.
0 commit comments