python - detect the specific serial port which is conneced to FTDI chip -


i'm working on ftdi chip , want connect chip operating system windows 10 via serial port. i'm using code below , results show me visible ports don't want. need detect port chip connected , ignore rest. example com 4, want program written in python detect com4 only. i'm using pyserial way. i'm pretty thankful , grateful in advance

def serial_ports():

if sys.platform.startswith('win'):     ports = ['com%s' % (i + 1) in range(256)]     print ports elif sys.platform.startswith('linux') or sys.platform.startswith('cygwin'):     # excludes 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 port in ports:     try:         s = serial.serial(port)         s.close()         result.append(port)     except (oserror, serial.serialexception):         pass return result  

read

serial.tools.list_ports

this module can executed list of ports (python -m serial.tools.list_ports).
contains following functions.

serial.tools.list_ports.comports() returns:    iterable yields listportinfo objects. 

the function returns iterable yields tuples of 3 strings:
port name can passed serial.serial or serial.serial_for_url()
description in human readable form
sort of hardware id. e.g. may contain vid:pid of usb-serial adapters.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -