This commit is contained in:
GukSang.Jin
2026-02-04 17:37:52 +08:00
4 changed files with 822 additions and 626 deletions

View File

@@ -30,11 +30,13 @@ namespace 全自动水压检测仪
/// </summary>
public void InitializeChart(Control targetPanel)
{
if (targetPanel == null)
throw new ArgumentNullException(nameof(targetPanel));
targetPanel.Invoke(new Action(() =>
{
if (targetPanel == null)
throw new ArgumentNullException(nameof(targetPanel));
// 清除占位文字
targetPanel.Text = null;
// 清除占位文字
targetPanel.Text = null;
// 初始化数据集合
_pressureData = new List<DataPoint>();

File diff suppressed because it is too large Load Diff

View File

@@ -793,7 +793,6 @@ namespace 全自动水压检测仪
// 只有状态真正改变时才更新控件可见性
if (_lastLowTempMode != currentLowTempState)
{
_lastLowTempMode = currentLowTempState;
UpdateControlsVisibilityByMode();
}
}
@@ -804,10 +803,9 @@ namespace 全自动水压检测仪
bool currentHighTempState = modbusResults.HighStatus[0];
uiLight2.State = currentHighTempState ? UILightState.On : UILightState.Off;
// 只有状态真正改变时才更新控件可见性
if (_lastHighTempMode != currentHighTempState)
// 如果温度模式状态发生变化,更新控件可见性
if (previousHighTempState != currentHighTempState)
{
_lastHighTempMode = currentHighTempState;
UpdateControlsVisibilityByMode();
}
}
@@ -928,6 +926,7 @@ namespace 全自动水压检测仪
}
}
private void NormalTemperatureMode_Load(object sender, EventArgs e)
{
@@ -971,13 +970,15 @@ namespace 全自动水压检测仪
ma = new Function(_modbusMaster);
c = new DataChange();
// 暂时注释
_modbusMaster?.WriteSingleCoil(1, 10030, true);
//_modbusMaster?.WriteSingleCoil(1, 10030, false);
boolSignal1.OnRisingEdge += BoolSignal1_OnRisingEdge;
// 初始化图表
try
{
_chartManager.InitializeChart(uiPanel_ChartPlaceholder);
//_chartManager.InitializeChart(uiPanel_ChartPlaceholder);
Debug.WriteLine("[NormalTemperatureMode] 图表初始化成功");
}
catch (Exception ex)
@@ -1285,9 +1286,9 @@ namespace 全自动水压检测仪
try
{
// 暂停定时器避免并发访问Modbus
_readTimer?.Stop();
_readTimerTwo?.Stop();
_alarmMonitorTimer?.Stop();
//_readTimer?.Stop();
//_readTimerTwo?.Stop();
//_alarmMonitorTimer?.Stop();
// 在后台线程执行Modbus操作
await Task.Run(() =>
@@ -1298,10 +1299,9 @@ namespace 全自动水压检测仪
}
catch (Exception ex)
{
Debug.WriteLine($"[uiSwitch1_Click] 切换模式失败: {ex.Message}");
SafeInvoke(() =>
{
MessageBox.Show($"切换模式失败:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
Debug.WriteLine($"切换模式失败:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
});
}
});
@@ -1309,29 +1309,29 @@ namespace 全自动水压检测仪
// 缩短延迟时间从800ms减少到300ms
await Task.Delay(300);
// 更新控件可见性(已优化为批量更新)
// 更新控件可见性
SafeInvoke(() =>
{
UpdateControlsVisibilityByMode();
// 更新图表模式
bool isHighTempMode = uiLight2 != null && uiLight2.State == UILightState.On;
_chartManager?.UpdateChartMode(isHighTempMode);
});
// // 更新图表模式
// bool isHighTempMode = uiLight2 != null && uiLight2.State == UILightState.On;
// _chartManager?.UpdateChartMode(isHighTempMode);
//});
// 恢复定时器
_readTimer?.Start();
_readTimerTwo?.Start();
_alarmMonitorTimer?.Start();
//// 恢复定时器
//_readTimer?.Start();
//_readTimerTwo?.Start();
//_alarmMonitorTimer?.Start();
}
catch (Exception ex)
{
Debug.WriteLine($"[uiSwitch1_Click] 异常: {ex.Message}");
// 确保定时器恢复
_readTimer?.Start();
_readTimerTwo?.Start();
_alarmMonitorTimer?.Start();
//// 确保定时器恢复
//_readTimer?.Start();
//_readTimerTwo?.Start();
//_alarmMonitorTimer?.Start();
}
}
@@ -1395,7 +1395,7 @@ namespace 全自动水压检测仪
}
// 初始化时根据当前模式更新控件可见性
UpdateControlsVisibilityByMode();
//UpdateControlsVisibilityByMode();
}
//返回录入系统
@@ -1638,89 +1638,250 @@ namespace 全自动水压检测仪
/// 常温模式:显示常温相关参数(常温实时液位、常温加水)
/// 高温模式:显示高温相关参数(高温实时液位、箱体温度、出口温度、高温加水、水箱加热)
/// </summary>
private void UpdateControlsVisibilityByMode()
//private void UpdateControlsVisibilityByMode()
//{
// try
// {
// // 判断当前是否为高温模式uiLight2亮起表示高温模式
// bool isHighTempMode = uiLight2 != null && uiLight2.State == UILightState.On;
// bool isLowTempMode = uiLight1 != null && uiLight1.State == UILightState.On;
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] 开始更新 - 高温模式: {isHighTempMode}, 常温模式: {isLowTempMode}");
// // ========== 高温模式专属控件(高温模式显示,常温模式隐藏) ==========
// // 高温实时液位(mm) - uiPanel31包含uiLabel7, uiLabel8, uiLabel34, uiProcessBar2
// if (uiPanel31 != null && !uiPanel31.IsDisposed)
// {
// uiPanel31.Visible = isHighTempMode;
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel31(高温液位) Visible = {isHighTempMode}");
// }
// // 箱体温度(°C) - uiPanel35包含uiLabel42, uiLabel43实时数据监控区域
// if (uiPanel35 != null && !uiPanel35.IsDisposed)
// {
// uiPanel35.Visible = isHighTempMode;
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel35(箱体温度) Visible = {isHighTempMode}");
// }
// // 出口温度(°C) - uiPanel33包含uiLabel38, uiLabel39实时数据监控区域
// if (uiPanel33 != null && !uiPanel33.IsDisposed)
// {
// uiPanel33.Visible = isHighTempMode;
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel33(出口温度) Visible = {isHighTempMode}");
// }
// // 高温加水按钮 - uiButton5
// if (uiButton5 != null && !uiButton5.IsDisposed)
// {
// uiButton5.Visible = isHighTempMode;
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiButton5(高温加水) Visible = {isHighTempMode}");
// }
// // 高温加水指示灯 - uiLight11
// if (uiPanel43 != null && !uiPanel43.IsDisposed)
// {
// uiPanel43.Visible = isHighTempMode;
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel43(高温加水指示灯) Visible = {isHighTempMode}");
// }
// // 水箱加热按钮 - uiButton4用户操作设定区域
// if (uiButton4 != null && !uiButton4.IsDisposed)
// {
// uiButton4.Visible = isHighTempMode;
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiButton4(水箱加热) Visible = {isHighTempMode}");
// }
// // 出口温度判定设置 - uiLabel48和uiTextBox9用户操作设定区域
// if (uiLabel48 != null && !uiLabel48.IsDisposed)
// {
// uiLabel48.Visible = isHighTempMode;
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiLabel48(出口温度标签) Visible = {isHighTempMode}");
// }
// if (uiTextBox9 != null && !uiTextBox9.IsDisposed)
// {
// uiTextBox9.Visible = isHighTempMode;
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiTextBox9(出口温度输入) Visible = {isHighTempMode}");
// }
// // 写入按钮 - uiButton8用于写入联络单号和件号数据到PLC常温和高温模式都需要
// // 注意:写入按钮应该始终显示,因为联络单号和件号在两种模式下都需要
// if (uiButton8 != null && !uiButton8.IsDisposed)
// {
// uiButton8.Visible = true; // 始终显示写入按钮
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiButton8(写入按钮) Visible = true (始终显示)");
// }
// // 箱体温度设置 - uiLabel37和uiTextBox4用户操作设定区域
// if (uiLabel37 != null && !uiLabel37.IsDisposed)
// {
// uiLabel37.Visible = isHighTempMode;
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiLabel37(箱体温度标签) Visible = {isHighTempMode}");
// }
// if (uiTextBox4 != null && !uiTextBox4.IsDisposed)
// {
// uiTextBox4.Visible = isHighTempMode;
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiTextBox4(箱体温度输入) Visible = {isHighTempMode}");
// }
// // ========== 常温模式专属控件(常温模式显示,高温模式隐藏) ==========
// // 常温实时液位(mm) - uiPanel23包含uiLabel12, uiLabel16, uiLabel17, uiProcessBar1
// if (uiPanel23 != null && !uiPanel23.IsDisposed)
// {
// uiPanel23.Visible = !isHighTempMode;
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel23(常温液位) Visible = {!isHighTempMode}");
// }
// // 常温加水按钮 - uiButton13
// if (uiButton13 != null && !uiButton13.IsDisposed)
// {
// uiButton13.Visible = !isHighTempMode;
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiButton13(常温加水) Visible = {!isHighTempMode}");
// }
// // 常温加水指示灯 - uiLight6
// if (uiPanel38 != null && !uiPanel38.IsDisposed)
// {
// uiPanel38.Visible = !isHighTempMode;
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel38(常温加水指示灯) Visible = {!isHighTempMode}");
// }
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] 模式切换完成 - 高温模式: {isHighTempMode}");
// }
// catch (ObjectDisposedException ex)
// {
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] 控件已释放: {ex.Message}");
// }
// catch (Exception ex)
// {
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] 更新控件可见性失败: {ex.Message}");
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] 堆栈跟踪: {ex.StackTrace}");
// }
//}
private void UpdateControlsVisibilityByModeOptimized()
{
// 在更新前暂停布局计算
this.SuspendLayout();
try
{
// 判断当前是否为高温模式uiLight2亮起表示高温模式
bool isHighTempMode = uiLight2 != null && uiLight2.State == UILightState.On;
// 暂停布局更新,批量修改控件属性,减少重绘次数
this.SuspendLayout();
Debug.WriteLine($"[UpdateControlsVisibilityByMode] 开始更新 - 高温模式: {isHighTempMode}, 常温模式: {isLowTempMode}");
// ========== 高温模式专属控件(高温模式显示,常温模式隐藏) ==========
// 高温实时液位(mm)
// 高温实时液位(mm) - uiPanel31包含uiLabel7, uiLabel8, uiLabel34, uiProcessBar2
if (uiPanel31 != null && !uiPanel31.IsDisposed)
{
uiPanel31.Visible = isHighTempMode;
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel31(高温液位) Visible = {isHighTempMode}");
}
// 箱体温度(°C)
// 箱体温度(°C) - uiPanel35包含uiLabel42, uiLabel43实时数据监控区域
if (uiPanel35 != null && !uiPanel35.IsDisposed)
{
uiPanel35.Visible = isHighTempMode;
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel35(箱体温度) Visible = {isHighTempMode}");
}
// 出口温度(°C)
// 出口温度(°C) - uiPanel33包含uiLabel38, uiLabel39实时数据监控区域
if (uiPanel33 != null && !uiPanel33.IsDisposed)
{
uiPanel33.Visible = isHighTempMode;
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel33(出口温度) Visible = {isHighTempMode}");
}
// 高温加水按钮
// 高温加水按钮 - uiButton5
if (uiButton5 != null && !uiButton5.IsDisposed)
{
uiButton5.Visible = isHighTempMode;
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiButton5(高温加水) Visible = {isHighTempMode}");
}
// 高温加水指示灯
// 高温加水指示灯 - uiLight11
if (uiPanel43 != null && !uiPanel43.IsDisposed)
{
uiPanel43.Visible = isHighTempMode;
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel43(高温加水指示灯) Visible = {isHighTempMode}");
}
// 水箱加热按钮
// 水箱加热按钮 - uiButton4用户操作设定区域
if (uiButton4 != null && !uiButton4.IsDisposed)
{
uiButton4.Visible = isHighTempMode;
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiButton4(水箱加热) Visible = {isHighTempMode}");
}
// 出口温度判定设置
// 出口温度判定设置 - uiLabel48和uiTextBox9用户操作设定区域
if (uiLabel48 != null && !uiLabel48.IsDisposed)
{
uiLabel48.Visible = isHighTempMode;
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiLabel48(出口温度标签) Visible = {isHighTempMode}");
}
if (uiTextBox9 != null && !uiTextBox9.IsDisposed)
{
uiTextBox9.Visible = isHighTempMode;
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiTextBox9(出口温度输入) Visible = {isHighTempMode}");
}
// 箱体温度设置
// 写入按钮 - uiButton8用于写入联络单号和件号数据到PLC常温和高温模式都需要
// 注意:写入按钮应该始终显示,因为联络单号和件号在两种模式下都需要
if (uiButton8 != null && !uiButton8.IsDisposed)
{
uiButton8.Visible = true; // 始终显示写入按钮
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiButton8(写入按钮) Visible = true (始终显示)");
}
// 箱体温度设置 - uiLabel37和uiTextBox4用户操作设定区域
if (uiLabel37 != null && !uiLabel37.IsDisposed)
{
uiLabel37.Visible = isHighTempMode;
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiLabel37(箱体温度标签) Visible = {isHighTempMode}");
}
if (uiTextBox4 != null && !uiTextBox4.IsDisposed)
{
uiTextBox4.Visible = isHighTempMode;
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiTextBox4(箱体温度输入) Visible = {isHighTempMode}");
}
// ========== 常温模式专属控件(常温模式显示,高温模式隐藏) ==========
// 常温实时液位(mm)
// 常温实时液位(mm) - uiPanel23包含uiLabel12, uiLabel16, uiLabel17, uiProcessBar1
if (uiPanel23 != null && !uiPanel23.IsDisposed)
{
uiPanel23.Visible = !isHighTempMode;
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel23(常温液位) Visible = {!isHighTempMode}");
}
// 常温加水按钮
// 常温加水按钮 - uiButton13
if (uiButton13 != null && !uiButton13.IsDisposed)
{
uiButton13.Visible = !isHighTempMode;
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiButton13(常温加水) Visible = {!isHighTempMode}");
}
// 常温加水指示灯
// 常温加水指示灯 - uiLight6
if (uiPanel38 != null && !uiPanel38.IsDisposed)
{
uiPanel38.Visible = !isHighTempMode;
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel38(常温加水指示灯) Visible = {!isHighTempMode}");
}
// 写入按钮始终显示
if (uiButton8 != null && !uiButton8.IsDisposed)
uiButton8.Visible = true;
// 恢复布局更新,一次性重绘所有变更
this.ResumeLayout(true);
Debug.WriteLine($"[UpdateControlsVisibilityByMode] 模式切换完成 - 高温模式: {isHighTempMode}");
}
catch (ObjectDisposedException ex)
{
Debug.WriteLine($"[UpdateControlsVisibilityByMode] 控件已释放: {ex.Message}");
// 确保恢复布局
try { this.ResumeLayout(true); } catch { }
}
catch (Exception ex)
{
Debug.WriteLine($"[UpdateControlsVisibilityByMode] 更新控件可见性失败: {ex.Message}");
// 确保恢复布局
try { this.ResumeLayout(true); } catch { }
Debug.WriteLine($"[UpdateControlsVisibilityByMode] 堆栈跟踪: {ex.StackTrace}");
}
}
}
}

View File

@@ -209,14 +209,14 @@ namespace 全自动水压检测仪
this.tempModePanel.Controls.Add(this.uiLight2_Status);
// 当前模式显示
var currentModeLabel = new Sunny.UI.UILabel();
currentModeLabel.Location = new System.Drawing.Point(520, 65);
currentModeLabel.Size = new System.Drawing.Size(120, 30);
currentModeLabel.Text = "当前模式:";
currentModeLabel.Font = new System.Drawing.Font("微软雅黑", 11F);
currentModeLabel.ForeColor = System.Drawing.Color.FromArgb(100, 100, 100);
currentModeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.tempModePanel.Controls.Add(currentModeLabel);
//var currentModeLabel = new Sunny.UI.UILabel();
//currentModeLabel.Location = new System.Drawing.Point(520, 65);
//currentModeLabel.Size = new System.Drawing.Size(120, 30);
//currentModeLabel.Text = "当前模式:";
//currentModeLabel.Font = new System.Drawing.Font("微软雅黑", 11F);
//currentModeLabel.ForeColor = System.Drawing.Color.FromArgb(100, 100, 100);
//currentModeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//this.tempModePanel.Controls.Add(currentModeLabel);
// uiLabel11_Status
this.uiLabel11_Status.Location = new System.Drawing.Point(640, 65);