This commit is contained in:
wxt
2026-01-19 11:22:19 +08:00
parent 79d7faa248
commit 3adffb102f
5 changed files with 258 additions and 76 deletions

View File

@@ -43,7 +43,6 @@
uiButton1 = new Sunny.UI.UIButton(); uiButton1 = new Sunny.UI.UIButton();
uiPanel2 = new Sunny.UI.UIPanel(); uiPanel2 = new Sunny.UI.UIPanel();
uiGroupBox1 = new Sunny.UI.UIGroupBox(); uiGroupBox1 = new Sunny.UI.UIGroupBox();
uiButton9 = new Sunny.UI.UIButton();
uiLabel28 = new Sunny.UI.UILabel(); uiLabel28 = new Sunny.UI.UILabel();
uiLight3 = new Sunny.UI.UILight(); uiLight3 = new Sunny.UI.UILight();
uiTextBox2 = new Sunny.UI.UITextBox(); uiTextBox2 = new Sunny.UI.UITextBox();
@@ -415,7 +414,6 @@
// uiGroupBox1 // uiGroupBox1
// //
uiGroupBox1.BackColor = Color.White; uiGroupBox1.BackColor = Color.White;
uiGroupBox1.Controls.Add(uiButton9);
uiGroupBox1.Controls.Add(uiLabel28); uiGroupBox1.Controls.Add(uiLabel28);
uiGroupBox1.Controls.Add(uiLight3); uiGroupBox1.Controls.Add(uiLight3);
uiGroupBox1.Controls.Add(uiTextBox2); uiGroupBox1.Controls.Add(uiTextBox2);
@@ -442,28 +440,6 @@
uiGroupBox1.Text = "激光参数"; uiGroupBox1.Text = "激光参数";
uiGroupBox1.TextAlignment = ContentAlignment.MiddleLeft; uiGroupBox1.TextAlignment = ContentAlignment.MiddleLeft;
// //
// uiButton9
//
uiButton9.Cursor = Cursors.Hand;
uiButton9.FillColor = Color.FromArgb(46, 204, 113);
uiButton9.FillColor2 = Color.FromArgb(46, 204, 113);
uiButton9.FillHoverColor = Color.FromArgb(39, 174, 96);
uiButton9.FillPressColor = Color.FromArgb(39, 174, 96);
uiButton9.Font = new Font("微软雅黑", 13F, FontStyle.Bold, GraphicsUnit.Point, 134);
uiButton9.Location = new Point(759, 167);
uiButton9.MinimumSize = new Size(1, 1);
uiButton9.Name = "uiButton9";
uiButton9.Radius = 8;
uiButton9.RectColor = Color.FromArgb(46, 204, 113);
uiButton9.RectHoverColor = Color.FromArgb(39, 174, 96);
uiButton9.Size = new Size(180, 44);
uiButton9.Style = Sunny.UI.UIStyle.Custom;
uiButton9.StyleCustomMode = true;
uiButton9.TabIndex = 20;
uiButton9.Text = "手动混氧";
uiButton9.TipsFont = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
uiButton9.Click += uiButton9_Click;
//
// uiLabel28 // uiLabel28
// //
uiLabel28.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134); uiLabel28.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
@@ -1522,13 +1498,13 @@
// //
uiLabel16.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134); uiLabel16.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
uiLabel16.ForeColor = Color.FromArgb(96, 98, 102); uiLabel16.ForeColor = Color.FromArgb(96, 98, 102);
uiLabel16.Location = new Point(16, 53); uiLabel16.Location = new Point(3, 53);
uiLabel16.Name = "uiLabel16"; uiLabel16.Name = "uiLabel16";
uiLabel16.Size = new Size(273, 195); uiLabel16.Size = new Size(286, 264);
uiLabel16.Style = Sunny.UI.UIStyle.Custom; uiLabel16.Style = Sunny.UI.UIStyle.Custom;
uiLabel16.StyleCustomMode = true; uiLabel16.StyleCustomMode = true;
uiLabel16.TabIndex = 0; uiLabel16.TabIndex = 0;
uiLabel16.Text = "P1:t ≥ 10 s\r\nP2:3 s ≤ t≤ 10 s\r\nP3:1 s ≤ t ≤3 s\r\nP4:t≤1 s\r\n\r\n注: P1材料需测量背面温度"; uiLabel16.Text = "P1:t ≥ 10 s\r\nP2:3 s ≤ t≤ 10 s\r\nP3:1 s ≤ t ≤3 s\r\nP4:t≤1 s\r\n\r\n注: P1材料需测量背面温度\r\n\r\n 穿透性测试只在21%氧浓\r\n 度环境下测试。";
// //
// PenetrationForm // PenetrationForm
// //
@@ -1650,7 +1626,6 @@
private Sunny.UI.UILabel uiLabel49; private Sunny.UI.UILabel uiLabel49;
private Sunny.UI.UILabel uiLabel50; private Sunny.UI.UILabel uiLabel50;
private Sunny.UI.UILabel uiLabel51; private Sunny.UI.UILabel uiLabel51;
private Sunny.UI.UIButton uiButton9;
private Sunny.UI.UIButton uiButton11; private Sunny.UI.UIButton uiButton11;
} }
} }

View File

@@ -330,8 +330,73 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
Debug.WriteLine($"读取状态3失败: {ex.Message}"); Debug.WriteLine($"读取状态3失败: {ex.Message}");
} }
try
{
if (_modbusMaster == null) return;
bool[] registers3 = await _modbusMaster.ReadCoilsAsync(1, 99, 1);//灭火
if (registers3 != null && registers3.Length >= 1)
{
bool value3 = registers3[0];
if (uiButton3.IsDisposed || !uiButton3.IsHandleCreated)
return;
if (uiButton3.InvokeRequired)
{
uiButton3.Invoke(new Action(() =>
{
// 再次检查,防止回调执行时控件已被销毁
if (!uiButton3.IsDisposed && uiButton3.IsHandleCreated && value3)
uiButton3.Text = "灭火中";
uiButton3.ForeColor = Color.Red;
}));
}
else
{
uiButton3.Text = "灭火";
uiButton3.ForeColor = Color.White;
}
}
}
catch (Exception ex)
{
Debug.WriteLine($"读取灭火状态失败: {ex.Message}");
}
try
{
if (_modbusMaster == null) return;
bool[] registers4 = await _modbusMaster.ReadCoilsAsync(1, 11, 1);//开灯
if (registers4 != null && registers4.Length >= 1)
{
bool value4 = registers4[0];
if (uiButton11.IsDisposed || !uiButton11.IsHandleCreated)
return;
if (uiButton11.InvokeRequired)
{
uiButton11.Invoke(new Action(() =>
{
// 再次检查,防止回调执行时控件已被销毁
if (!uiButton11.IsDisposed && uiButton11.IsHandleCreated && value4)
uiButton11.Text = "开灯中";
uiButton11.ForeColor = Color.Red;
}));
}
else
{
uiButton11.Text = "💡 灯开关";
uiButton11.ForeColor = Color.White;
}
}
}
catch (Exception ex)
{
Debug.WriteLine($"读取开灯状态失败: {ex.Message}");
}
} }
private bool _lastRunStatus = false; private bool _lastRunStatus = false;
@@ -1076,8 +1141,8 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
// 定义需要添加的选项数组 // 定义需要添加的选项数组
string[] options = { string[] options = {
"环境空气 (21%)", "环境空气 (21%)",
"富氧环境 (60%)", //"富氧环境 (60%)",
"富氧环境 (98%)", //"富氧环境 (98%)",
"无氧环境/灭火 (0%)" "无氧环境/灭火 (0%)"
}; };
uiComboBox1.Items.AddRange(options); uiComboBox1.Items.AddRange(options);
@@ -1201,19 +1266,11 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
ma?.BtnClickFunctionForNew(Function.ButtonType., 42);//停止测试 ma?.BtnClickFunctionForNew(Function.ButtonType., 42);//停止测试
} }
bool isbt3on = false;
private void uiButton3_Click(object sender, EventArgs e) private void uiButton3_Click(object sender, EventArgs e)
{ {
ToggleButtonWithText(uiButton3, ref isbt3on, "灭火中", "灭火");
ma?.BtnClickFunctionForNew(Function.ButtonType., 99);//灭火 ma?.BtnClickFunctionForNew(Function.ButtonType., 99);//灭火
} }
private void ToggleButtonWithText(UIButton button, ref bool state, string onText, string offText)
{
state = !state;
button.ForeColor = state ? Color.Red : Color.White;
button.Text = state ? onText : offText;
}
#endregion #endregion
private async void uiComboBox1_SelectedIndexChanged(object sender, EventArgs e) private async void uiComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{ {
@@ -1826,19 +1883,12 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
} }
#region #region
bool isbt11on =false;
bool isbt9on=false;
private void uiButton11_Click_1(object sender, EventArgs e) private void uiButton11_Click_1(object sender, EventArgs e)
{ {
ToggleButtonWithText(uiButton11, ref isbt11on, "开灯中", "💡 灯开关");
ma?.BtnClickFunctionForNew(Function.ButtonType., 11);//灯开关 ma?.BtnClickFunctionForNew(Function.ButtonType., 11);//灯开关
} }
private void uiButton9_Click(object sender, EventArgs e)
{
ToggleButtonWithText(uiButton9, ref isbt9on, "混氧中", "手动混氧");
ma?.BtnClickFunctionForNew(Function.ButtonType., 101);//混氧开关
}
#endregion #endregion
private void PenetrationForm_Shown(object sender, EventArgs e) private void PenetrationForm_Shown(object sender, EventArgs e)

View File

@@ -249,8 +249,94 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
} }
catch (Exception ex) catch (Exception ex)
{ {
Debug.WriteLine($"读取状态失败: {ex.Message}"); Debug.WriteLine($"读取激光状态失败: {ex.Message}");
} }
try
{
bool[] registers2 = await _modbusMaster?.ReadCoilsAsync(1, 101, 1);
if (registers2 != null && registers2.Length >= 1)
{
bool value2 = registers2[0];
this.Invoke(new Action(() =>
{
if (value2)
{
uiButton9.Text = "混氧中";
uiButton9.ForeColor= Color.Red;
}
else
{
uiButton9.Text = "手动混氧";
uiButton9.ForeColor = Color.White;
}
}));
}
}
catch (Exception ex)
{
Debug.WriteLine($"读取混氧状态失败: {ex.Message}");
}
try
{
bool[] registers3 = await _modbusMaster?.ReadCoilsAsync(1, 99, 1);
if (registers3 != null && registers3.Length >= 1)
{
bool value3 = registers3[0];
this.Invoke(new Action(() =>
{
if (value3)
{
uiButton3.Text = "灭火中";
uiButton3.ForeColor = Color.Red;
}
else
{
uiButton3.Text = "灭火";
uiButton3.ForeColor = Color.White;
}
}));
}
}
catch (Exception ex)
{
Debug.WriteLine($"读取灭火状态失败: {ex.Message}");
}
try
{
bool[] registers4 = await _modbusMaster?.ReadCoilsAsync(1, 11, 1);
if (registers4 != null && registers4.Length >= 1)
{
bool value4 = registers4[0];
this.Invoke(new Action(() =>
{
if (value4)
{
uiButton14.Text = "开灯中";
uiButton14.ForeColor = Color.Red;
}
else
{
uiButton14.Text = "💡 灯开关";
uiButton14.ForeColor = Color.White;
}
}));
}
}
catch (Exception ex)
{
Debug.WriteLine($"读取灭火状态失败: {ex.Message}");
}
} }
private bool _lastRunStatus = false; private bool _lastRunStatus = false;
@@ -1151,19 +1237,11 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
ma?.BtnClickFunctionForNew(Function.ButtonType., 55);//手动停止 ma?.BtnClickFunctionForNew(Function.ButtonType., 55);//手动停止
} }
bool isbt3on = false;
private void uiButton3_Click(object sender, EventArgs e) private void uiButton3_Click(object sender, EventArgs e)
{ {
ToggleButtonWithText(uiButton3, ref isbt3on, "灭火中", "灭火");
ma?.BtnClickFunctionForNew(Function.ButtonType., 99);//灭火 ma?.BtnClickFunctionForNew(Function.ButtonType., 99);//灭火
} }
private void ToggleButtonWithText(UIButton button, ref bool state, string onText, string offText)
{
state = !state;
button.ForeColor = state ? Color.Red : Color.White;
button.Text = state ? onText : offText;
}
private void PrimaryIgnitionForm_FormClosing(object sender, FormClosingEventArgs e) private void PrimaryIgnitionForm_FormClosing(object sender, FormClosingEventArgs e)
{ {
@@ -1319,17 +1397,14 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
} }
} }
bool isbt14on = false;
bool isbt9on = false;
private void uiButton9_Click(object sender, EventArgs e) private void uiButton9_Click(object sender, EventArgs e)
{ {
ToggleButtonWithText(uiButton9, ref isbt9on, "混氧中", "手动混氧");
ma?.BtnClickFunctionForNew(Function.ButtonType., 101);//混氧开关 ma?.BtnClickFunctionForNew(Function.ButtonType., 101);//混氧开关
} }
private void uiButton14_Click(object sender, EventArgs e) private void uiButton14_Click(object sender, EventArgs e)
{ {
ToggleButtonWithText(uiButton14, ref isbt14on, "开灯中", "💡 灯开关");
ma?.BtnClickFunctionForNew(Function.ButtonType., 11);//灯开关 ma?.BtnClickFunctionForNew(Function.ButtonType., 11);//灯开关
} }

View File

@@ -184,12 +184,8 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
{ {
try try
{ {
bool[] registers1 = await Task.Run(async () => bool[] registers1 = await _modbusMaster?.ReadCoilsAsync(1, 10, 1);
{
if (_modbusMaster == null)
return null;
return await _modbusMaster?.ReadCoilsAsync(1, 10, 1);
});
if (registers1 != null && registers1.Length >= 1) if (registers1 != null && registers1.Length >= 1)
{ {
bool value = registers1[0]; bool value = registers1[0];
@@ -212,6 +208,92 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
{ {
Debug.WriteLine($"读取状态失败: {ex.Message}"); Debug.WriteLine($"读取状态失败: {ex.Message}");
} }
try
{
bool[] registers2 = await _modbusMaster?.ReadCoilsAsync(1, 101, 1);
if (registers2 != null && registers2.Length >= 1)
{
bool value2 = registers2[0];
this.Invoke(new Action(() =>
{
if (value2)
{
uiButton9.Text = "混氧中";
uiButton9.ForeColor = Color.Red;
}
else
{
uiButton9.Text = "手动混氧";
uiButton9.ForeColor = Color.White;
}
}));
}
}
catch (Exception ex)
{
Debug.WriteLine($"读取混氧状态失败: {ex.Message}");
}
try
{
bool[] registers3 = await _modbusMaster?.ReadCoilsAsync(1, 99, 1);
if (registers3 != null && registers3.Length >= 1)
{
bool value3 = registers3[0];
this.Invoke(new Action(() =>
{
if (value3)
{
uiButton3.Text = "灭火中";
uiButton3.ForeColor = Color.Red;
}
else
{
uiButton3.Text = "灭火";
uiButton3.ForeColor = Color.White;
}
}));
}
}
catch (Exception ex)
{
Debug.WriteLine($"读取灭火状态失败: {ex.Message}");
}
try
{
bool[] registers4 = await _modbusMaster?.ReadCoilsAsync(1, 11, 1);
if (registers4 != null && registers4.Length >= 1)
{
bool value4 = registers4[0];
this.Invoke(new Action(() =>
{
if (value4)
{
uiButton14.Text = "开灯中";
uiButton14.ForeColor = Color.Red;
}
else
{
uiButton14.Text = "💡 灯开关";
uiButton14.ForeColor = Color.White;
}
}));
}
}
catch (Exception ex)
{
Debug.WriteLine($"读取灭火状态失败: {ex.Message}");
}
} }
private async Task ReadtimeAsync() private async Task ReadtimeAsync()
@@ -262,7 +344,7 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
RunStatus = currentRunStatus; RunStatus = currentRunStatus;
// 添加调试日志 // 添加调试日志
Debug.WriteLine($"读取状态: address=301, value={currentRunStatus}, last={_lastRunStatus}, reported={_isReported}"); //Debug.WriteLine($"读取状态: address=301, value={currentRunStatus}, last={_lastRunStatus}, reported={_isReported}");
if (!this.IsHandleCreated) if (!this.IsHandleCreated)
return; return;

View File

@@ -1,10 +1,10 @@
// <auto-generated/> // <auto-generated/>
global using System; global using global::System;
global using System.Collections.Generic; global using global::System.Collections.Generic;
global using System.Drawing; global using global::System.Drawing;
global using System.IO; global using global::System.IO;
global using System.Linq; global using global::System.Linq;
global using System.Net.Http; global using global::System.Net.Http;
global using System.Threading; global using global::System.Threading;
global using System.Threading.Tasks; global using global::System.Threading.Tasks;
global using System.Windows.Forms; global using global::System.Windows.Forms;