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 11import typing
22import serial
3+ import serial .tools .list_ports
34import sys
45import glob
56import 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
148140def get_camera_index_by_name (name ):
You can’t perform that action at this time.
0 commit comments