pcom_serial.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:Parlay 作者: PromenadeSoftware 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号