I'm working on a FTDI chip and want to connect this chip to the operating system Windows 10 via a serial port. I'm using this code below and the results show me the all visible ports what I don't want. what I need is to detect only the port which the chip is connected to and ignore the rest. for example Com 4, so I just want my program written in Python to detect Com4 ONLY. I'm using Pyserial by the way. I'm pretty thankful and grateful for your help in advance
def serial_ports():
if sys.platform.startswith('win'):
ports = ['COM%s' % (i + 1) for i in range(256)]
print ports
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:
raise EnvironmentError('Unsupported platform')
result = []
print ports
for port in ports:
try:
s = serial.Serial(port)
s.close()
result.append(port)
except (OSError, serial.SerialException):
pass
return result