From 07d992d1528922fa41c838fb5209031e36793d04 Mon Sep 17 00:00:00 2001 From: "GukSang.Jin" Date: Sat, 18 Apr 2026 09:44:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=B6=B2=E4=BD=8D=E7=BA=A2?= =?UTF-8?q?=E8=89=B2=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 全自动水压检测仪/NormalTemperatureMode.cs | 65 +++++++++++++++++++++-- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/全自动水压检测仪/NormalTemperatureMode.cs b/全自动水压检测仪/NormalTemperatureMode.cs index dfc44bd..824c771 100644 --- a/全自动水压检测仪/NormalTemperatureMode.cs +++ b/全自动水压检测仪/NormalTemperatureMode.cs @@ -55,6 +55,7 @@ namespace 全自动水压检测仪 // 温度模式状态跟踪(用于防抖优化) private bool _lastHighTempMode = false; private bool _lastLowTempMode = false; + private bool _liquidLevelStopIssued = false; private Panel[] _normalTempLevelBarSegments = Array.Empty(); private Panel[] _highTempLevelBarSegments = Array.Empty(); @@ -265,6 +266,41 @@ namespace 全自动水压检测仪 } } + private static bool IsLiquidLevelAlertState(bool sensorA, bool sensorB) + { + return (!sensorA && !sensorB) || (sensorA && sensorB); + } + + private bool IsAnyLiquidLevelBarInAlert() + { + bool[] normalLow = _modbusMaster?.ReadCoils(1, 10042, 1); + bool[] normalHigh = _modbusMaster?.ReadCoils(1, 10043, 1); + bool[] highLow = _modbusMaster?.ReadCoils(1, 10040, 1); + bool[] highHigh = _modbusMaster?.ReadCoils(1, 10041, 1); + + bool normalAlert = TryGetCoilValue(normalLow, out bool normalSensorA) && + TryGetCoilValue(normalHigh, out bool normalSensorB) && + IsLiquidLevelAlertState(normalSensorA, normalSensorB); + + bool highAlert = TryGetCoilValue(highLow, out bool highSensorA) && + TryGetCoilValue(highHigh, out bool highSensorB) && + IsLiquidLevelAlertState(highSensorA, highSensorB); + + return normalAlert || highAlert; + } + + private void StopTestForLiquidLevelAlert(string source) + { + if (_liquidLevelStopIssued) + { + return; + } + + _liquidLevelStopIssued = true; + Debug.WriteLine($"[{source}] 检测到液位红色报警,执行停止测试"); + ma?.BtnClickFunctionForNew(Function.ButtonType.复归型, 10082); + } + private System.Windows.Forms.Timer InitAlarmMonitorTimer() { var timer = new System.Windows.Forms.Timer() @@ -671,13 +707,21 @@ namespace 全自动水压检测仪 UpdateLiquidLevelStatusBar(_highTempLevelBarSegments, highSensorA, highSensorB, "高温液位"); } - #region 调用停止 - if (a[0] || cc[0]) + bool normalAlert = TryGetCoilValue(a, out bool normalStopSensorA) && + TryGetCoilValue(b, out bool normalStopSensorB) && + IsLiquidLevelAlertState(normalStopSensorA, normalStopSensorB); + bool highAlert = TryGetCoilValue(cc, out bool highStopSensorA) && + TryGetCoilValue(d, out bool highStopSensorB) && + IsLiquidLevelAlertState(highStopSensorA, highStopSensorB); + if (normalAlert || highAlert) { - ma?.BtnClickFunctionForNew(Function.ButtonType.复归型, 10082); + StopTestForLiquidLevelAlert("ReadAndUpdateData"); + } + else + { + _liquidLevelStopIssued = false; } - #endregion //// 更新进度条 //if (uiProcessBar1 != null && !uiProcessBar1.IsDisposed) @@ -1874,8 +1918,20 @@ namespace 全自动水压检测仪 //启动测试 private void uiButton2_Click(object sender, EventArgs e) { + if (IsAnyLiquidLevelBarInAlert()) + { + _liquidLevelStopIssued = false; + StopTestForLiquidLevelAlert("uiButton2_Click"); + SafeInvoke(() => + { + MessageBox.Show("液位显示红色,禁止启动测试,请先处理液位状态。", "液位联锁", MessageBoxButtons.OK, MessageBoxIcon.Warning); + }); + return; + } + ma?.BtnClickFunctionForNew(Function.ButtonType.切换型, 10080); isAddTag = false; + _liquidLevelStopIssued = false; starttime = DateTime.Now; // 清除图表数据,开始新的测试 _chartManager?.ClearData(); @@ -1887,6 +1943,7 @@ namespace 全自动水压检测仪 private void uiButton3_Click(object sender, EventArgs e) { ma?.BtnClickFunctionForNew(Function.ButtonType.复归型, 10082); + _liquidLevelStopIssued = false; } //切换实验模式(优化版本 - 减少延迟和卡顿)