1 def search_port(port_name): 2 # 获取连接电脑的设备的所有端口信息 3 port_list = list(comports()) 4 print("port_list",port_list) 5 6 if len(port_list) > 0: 7 # 遍历所有端口信息,根据端口名称port_name查找需要的端口号 8 for port in port_list: 9 print(port.description,port.device) 10 if port_name in port.description: 11 port_com = port.device 12 return port_com 13 else: 14 return None 15 else: 16 return None 17 18 19 self.m_ser_hdl = serial.Serial(self.m_at_dev, 115200, timeout=30) 20 def at_cmd_exec(self, cmd, *exp): 21 if not cmd.endswith("\r") and not cmd.endswith("\r\n"): 22 cmd += "\r" 23 24 try: 25 self.m_ser_hdl.write(cmd.encode()) 26 except Exception as e: 27 print(e) 28 return None 29 30 response = self.at_cmd_response() 31 if response: 32 return response 33 else: 34 return None
标签:return,list,self,cmd,电脑,port,端口,连接 From: https://www.cnblogs.com/r0mrnel/p/18440677