def _filter_com_ports(potential_com_ports):
"""
Filters the provided list of COM ports based on the string descriptor provided by the USB connection.
If the string descriptor matches those provided generally by ST Micro the port will be added to the filtered
list. If no new filtered ports are found the old list is returned.
:param potential_com_ports: list of potential COM ports found using list_ports.comports() (from serial.tools)
:return:
"""
def _is_valid_port(port_name):
return PCOMSerial.STM_VCP_STRING in port_name[1] or PCOMSerial.USB_SERIAL_CONV_STRING in port_name[1] or \
PCOMSerial.FTDI_VENDOR_ID in port_name[2] or (PCOMSerial.ST_VENDOR_ID in port_name[2] and
PCOMSerial.STLINK_STRING not in port_name[1]) or \
PCOMSerial.ST_VENDOR_ID in port_name[2] and PCOMSerial.ST_SNR in port_name[2]
result_list = []
try:
for port in potential_com_ports:
logger.info("PORT:")
logger.info(port)
if _is_valid_port(port):
result_list.append(port)
except Exception as e:
logger.error("[PCOM] Could not filter ports because of exception: {0}".format(e))
return potential_com_ports
return result_list if result_list else potential_com_ports
评论列表
文章目录