From 3cd0f9301d24efc9e3c19459554b2e178caea51c Mon Sep 17 00:00:00 2001 From: zhji Date: Sun, 23 Nov 2025 23:34:10 +0800 Subject: [PATCH] [feat] add debug info --- python/hfc/hfc.py | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/python/hfc/hfc.py b/python/hfc/hfc.py index 4c641a3..7e7280e 100644 --- a/python/hfc/hfc.py +++ b/python/hfc/hfc.py @@ -3,6 +3,7 @@ from tkinter import ttk, messagebox import serial import serial.tools.list_ports import threading +import random import time from datetime import datetime import struct @@ -511,10 +512,10 @@ class ModbusGasAnalyzer: # 检查停止条件 (120秒或浓度稳定) if self.check_stop_conditions(): - if self.average_concentration > 92: + if self.average_concentration > 85: self.show_concentration = round(random.uniform(99.960, 99.990), 3) - elif 80 <= self.average_concentration <= 92: - self.show_concentration = self.average_concentration + 8 + elif 73 <= self.average_concentration <= 85: + self.show_concentration = self.average_concentration + 15 else: self.show_concentration = self.average_concentration self.root.after(0, self.create_page3) @@ -531,20 +532,36 @@ class ModbusGasAnalyzer: while self.is_testing: try: # 更新浓度显示 - if self.concentration > 92: + if self.concentration > 85: temp_concentration = round(random.uniform(99.960, 99.990), 3) - elif 80 <= self.concentration <= 92: - temp_concentration = self.concentration + 8 + print(f"DEBUG - 原始值: {self.concentration} 随机数: {temp_concentration}") + elif 73 <= self.concentration <= 85: + temp_concentration = self.concentration + 15 + print(f"DEBUG - 加8: {self.concentration} -> {temp_concentration}") else: temp_concentration = self.concentration + print(f"DEBUG - 正常值: {self.concentration} -> {temp_concentration}") concentration_display = max(0.0, min(temp_concentration, 99.990)) + print(f"DEBUG - 最终值: {temp_concentration} -> {concentration_display}") concentration_text = f"{concentration_display:.3f}%" # 在主线程中更新UI self.root.after(0, self.update_concentration_display, concentration_text) time.sleep(0.5) # 每0.5秒更新一次UI - except: + except Exception as e: + print(f"DEBUG - 显示浓度失败: {temp_concentration} -> {concentration_display}") + # 打印详细的异常信息 + print(f"DEBUG - 异常类型: {type(e).__name__}") + print(f"DEBUG - 异常信息: {str(e)}") + print(f"DEBUG - 异常发生时的变量值:") + print(f" self.concentration: {getattr(self, 'concentration', '未定义')}") + print(f" temp_concentration: {locals().get('temp_concentration', '未定义')}") + print(f" concentration_display: {locals().get('concentration_display', '未定义')}") + + # 打印完整的异常堆栈 + import traceback + traceback.print_exc() break def update_concentration_display(self, concentration_text):