新增液位红色判断

This commit is contained in:
GukSang.Jin
2026-04-18 09:44:07 +08:00
parent cd1bee5c1e
commit 07d992d152

View File

@@ -55,6 +55,7 @@ namespace 全自动水压检测仪
// 温度模式状态跟踪(用于防抖优化)
private bool _lastHighTempMode = false;
private bool _lastLowTempMode = false;
private bool _liquidLevelStopIssued = false;
private Panel[] _normalTempLevelBarSegments = Array.Empty<Panel>();
private Panel[] _highTempLevelBarSegments = Array.Empty<Panel>();
@@ -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;
}
//切换实验模式(优化版本 - 减少延迟和卡顿)