优化日志显示
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""设备连接(UCD323 / CA410)相关逻辑(Step 4 重构)。
|
||||
"""设备连接(UCD323 / CA410)相关逻辑(Step 4 重构)。
|
||||
|
||||
从 pqAutomationApp.PQAutomationApp 中搬迁。每个函数第一行 `self = app`
|
||||
以保留原有 `self.xxx` 属性访问不变。
|
||||
@@ -23,7 +23,7 @@ def get_available_com_ports(self):
|
||||
ports = serial.tools.list_ports.comports()
|
||||
return [port.device for port in ports]
|
||||
except Exception as e:
|
||||
self.log_gui.log(f"获取COM端口列表出错: {e}")
|
||||
self.log_gui.log(f"获取COM端口列表出错: {e}", level="error")
|
||||
return []
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ def check_port_connection(self, is_ucd=True):
|
||||
if not self.ucd.open(self.ucd_list_var.get()):
|
||||
self.log_gui.log(
|
||||
f"设备 {self.ucd_list_var.get()} 异常,UCD323连接失败"
|
||||
)
|
||||
, level="error")
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
@@ -147,12 +147,12 @@ def check_port_connection(self, is_ucd=True):
|
||||
else:
|
||||
self.log_gui.log(
|
||||
f"端口 {self.config.device_config["ca_com"]} 异常,色温仪连接失败"
|
||||
)
|
||||
, level="error")
|
||||
self.ca.close()
|
||||
self.ca = None
|
||||
return False
|
||||
except Exception as e:
|
||||
self.log_gui.log(f"端口连接失败: {e}")
|
||||
self.log_gui.log(f"端口连接失败: {e}", level="error")
|
||||
return False
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ def disconnect_com_connections(self):
|
||||
pass
|
||||
finally:
|
||||
self.ucd.status = False
|
||||
self.log_gui.log("UCD连接已断开")
|
||||
self.log_gui.log("UCD连接已断开", level="info")
|
||||
|
||||
# 断开CA连接
|
||||
if self.ca is not None:
|
||||
@@ -183,7 +183,7 @@ def disconnect_com_connections(self):
|
||||
pass
|
||||
finally:
|
||||
self.ca = None
|
||||
self.log_gui.log("CA连接已断开")
|
||||
self.log_gui.log("CA连接已断开", level="info")
|
||||
|
||||
# 重新启用相关控件
|
||||
self.enable_com_widgets()
|
||||
@@ -192,7 +192,7 @@ def disconnect_com_connections(self):
|
||||
self.status_var.set("串口连接已断开")
|
||||
|
||||
except Exception as e:
|
||||
self.log_gui.log(f"断开连接时发生错误: {str(e)}")
|
||||
self.log_gui.log(f"断开连接时发生错误: {str(e)}", level="info")
|
||||
messagebox.showerror("错误", f"断开连接失败: {str(e)}")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user