wrapper_client.py 文件源码

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

项目:PJON-python 作者: Girgitt 项目源码 文件源码
def get_coms(self):
        close_fds = False if sys.platform == 'win32' else True

        if sys.platform == 'win32':
            cmd_subprc_pipe = subprocess.Popen("%s coms" % self._pjon_piper_path, shell=False, close_fds=close_fds, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=0, startupinfo=self._startupinfo, env=os.environ)
        else:
            cmd_subprc_pipe = subprocess.Popen([self._pjon_piper_path, "coms"], shell=False, close_fds=close_fds,
                                               stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
                                               bufsize=0, env=os.environ)

        coms = []
        #log.debug(">> cmd pipe out")
        while cmd_subprc_pipe:
            try:
                nex_tline = cmd_subprc_pipe.stdout.readline()
                if nex_tline == '':
                    break
                #log.debug(nex_tline.strip())
                if self.is_string_valid_com_port_name(nex_tline.strip()):
                    #log.debug("\_got a com port in the stdout")
                    coms.append(nex_tline.strip())
                else:
                    pass
                    #log.error("suspicious COM name in the output: %s" % nex_tline.strip())
            except AttributeError:
                pass
        #log.debug("<< cmd pipe out")
        cmd_subprc_pipe.terminate()

        if coms == []:
            log.warn("PJON-piper returned no serial ports; falling back to pyserial to enumerate available serials")
            from serial.tools import list_ports
            if sys.platform == 'win32':
                coms = [item.device for item in list_ports.comports()]
            elif sys.platform == 'linux2':
                coms = [item[0] for item in list_ports.comports()]

        return coms
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号