This commit is contained in:
xyy
2026-01-15 17:30:45 +08:00
15 changed files with 940 additions and 812 deletions

View File

@@ -405,6 +405,7 @@
TitleFont = new Font("微软雅黑", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
ZoomScaleRect = new Rectangle(22, 22, 800, 450);
FormClosing += MainForm_FormClosing;
Load += MainForm_Load;
uiTableLayoutPanel1.ResumeLayout(false);
uiPanel4.ResumeLayout(false);
uiPanel3.ResumeLayout(false);

View File

@@ -1,5 +1,7 @@
using Modbus.Device;
using Sunny.UI;
using System.Diagnostics;
using System.Net.Sockets;
using System.Timers;
using .Data;
@@ -7,9 +9,14 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
{
public partial class MainForm : UIForm
{
private TcpClient _tcpClient => ModbusResourceManager.Instance.TcpClient;
private IModbusMaster _modbusMaster => ModbusResourceManager.Instance.ModbusMaster;
Function ma;
private Stopwatch pressStopwatch;
private const int LONG_PRESS_THRESHOLD = 1000; // 1000毫秒=1秒
System.Timers.Timer Timer;
System.Timers.Timer _datetimeTimer;
@@ -19,6 +26,7 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
InitializeComponent();
InitDateTimeTimer();
pressStopwatch = new Stopwatch();
}
private void InitDateTimeTimer()
@@ -53,6 +61,7 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
}
private void SwitchToForm<T>() where T : Form, new()
{
using (T form = new T())
@@ -140,5 +149,31 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
{
this.SwitchToForm<ReportForm>();//测试报告
}
private void MainForm_Load(object sender, EventArgs e)
{
string plcIp = "192.168.1.10";
//string plcIp = "127.0.0.1";
bool initSuccess = Data.ModbusResourceManager.Instance.Init(plcIp, 502);
if (!initSuccess)
{
MessageBox.Show("连接Modbus服务器失败", "错误");
this.Close();
return;
}
// 检查连接状态
if (_tcpClient == null || !_tcpClient.Connected)
{
MessageBox.Show("Modbus连接异常", "错误");
this.Close();
return;
}
ma = new Function(_modbusMaster);
_modbusMaster?.WriteSingleRegister(1, 2, 0);
}
}
}

View File

@@ -43,7 +43,7 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
{
var timer = new System.Windows.Forms.Timer()
{
Interval = 1000
Interval = 500
};
timer.Tick += async (s, e) =>
{
@@ -56,7 +56,7 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
catch { }
}
};
//timer.Start();
timer.Start();
return timer;
}
@@ -157,11 +157,12 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
}
ma = new Function(_modbusMaster);
_readTimer = InitTimer();
if (_modbusMaster != null)
{
_readTimer.Start();
}
//_readTimer = InitTimer();
//if (_modbusMaster != null)
//{
// _readTimer.Start();
//}
_modbusMaster?.WriteSingleRegister(1, 2, 0);
this.FormClosed += (s, args) =>
{
@@ -170,6 +171,7 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
};
initPort();
uiComboBox1.SelectedIndex = 0;
}
private void InitComboBoxPattern()
@@ -185,7 +187,7 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
"无氧环境/灭火 (0%)"
};
uiComboBox1.Items.AddRange(options);
}
private void ManualDebugForm_FormClosed(object sender, FormClosedEventArgs e)
@@ -208,26 +210,45 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
this.Close();//返回主页面
}
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;
}
bool isbt1on = false;
//bool isbt4on = false;
bool isbt2on=false;
bool isbt3on = false;
#region
private void uiButton1_Click(object sender, EventArgs e)
{
ToggleButtonWithText(uiButton1, ref isbt1on, "混氧中", "手动混氧");
ma?.BtnClickFunctionForNew(Function.ButtonType., 101);//混氧开关
}
private void uiButton4_Click(object sender, EventArgs e)
{
//ToggleButtonWithText(uiButton4, ref isbt4on, "光斑运行中", "⚫ 光斑开关");
ma?.BtnClickFunctionForNew(Function.ButtonType., 250);//光斑开关
}
private void uiButton2_Click(object sender, EventArgs e)
{
ToggleButtonWithText(uiButton2, ref isbt2on, "开灯中", "💡 灯开关");
ma?.BtnClickFunctionForNew(Function.ButtonType., 11);//灯开关
}
private void uiButton3_Click(object sender, EventArgs e)
{
ToggleButtonWithText(uiButton3, ref isbt3on, "灭火中", "🚨 灭火");
ma?.BtnClickFunctionForNew(Function.ButtonType., 99);//灭火
}
#endregion
private void uiComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
ushort selectedIndex = ushort.Parse(uiComboBox1.SelectedIndex.ToString());

View File

@@ -15,7 +15,7 @@ namespace 外科辅料和患者防护罩激光抗性测试仪.Model
public float? FireDate { get; set; }
public float? yuhui { get; set; }
public float? yuyan { get; set; }
public bool Iszixi { get; set; }
public string Iszixi { get; set; }
public double? costTime { get; set; }
public DateTime? Testtime { get; set; }

View File

@@ -225,6 +225,9 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
}
ma = new Function(_modbusMaster);
_modbusMaster?.WriteSingleRegister(1, 2, 0);
_readtimer = InitTimer();
if (_modbusMaster != null)
{

View File

@@ -62,9 +62,6 @@
uiLabel39 = new Sunny.UI.UILabel();
uiLabel48 = new Sunny.UI.UILabel();
uiLabel49 = new Sunny.UI.UILabel();
uiLabel27 = new Sunny.UI.UILabel();
comkou = new Sunny.UI.UIComboBox();
connect = new Sunny.UI.UIButton();
statusStrip1 = new StatusStrip();
toolStripStatusLabel1 = new ToolStripStatusLabel();
uiLabel25 = new Sunny.UI.UILabel();
@@ -662,9 +659,6 @@
uiPanel6.Controls.Add(uiLabel39);
uiPanel6.Controls.Add(uiLabel48);
uiPanel6.Controls.Add(uiLabel49);
uiPanel6.Controls.Add(uiLabel27);
uiPanel6.Controls.Add(comkou);
uiPanel6.Controls.Add(connect);
uiPanel6.Controls.Add(statusStrip1);
uiPanel6.Controls.Add(uiLabel25);
uiPanel6.Controls.Add(uiLabel26);
@@ -782,60 +776,6 @@
uiLabel49.Text = "试验舱温度(℃):";
uiLabel49.TextAlign = ContentAlignment.MiddleLeft;
//
// uiLabel27
//
uiLabel27.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
uiLabel27.ForeColor = Color.FromArgb(245, 108, 108);
uiLabel27.Location = new Point(850, 200);
uiLabel27.Name = "uiLabel27";
uiLabel27.Size = new Size(253, 34);
uiLabel27.TabIndex = 25;
uiLabel27.Text = "(请先连接功率计!!)";
uiLabel27.TextAlign = ContentAlignment.MiddleCenter;
//
// comkou
//
comkou.DataSource = null;
comkou.FillColor = Color.White;
comkou.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
comkou.ItemHoverColor = Color.FromArgb(155, 200, 255);
comkou.ItemSelectForeColor = Color.FromArgb(235, 243, 255);
comkou.Location = new Point(872, 78);
comkou.Margin = new Padding(4, 5, 4, 5);
comkou.MinimumSize = new Size(63, 0);
comkou.Name = "comkou";
comkou.Padding = new Padding(0, 0, 30, 2);
comkou.Size = new Size(203, 44);
comkou.SymbolSize = 24;
comkou.TabIndex = 24;
comkou.TextAlignment = ContentAlignment.MiddleLeft;
comkou.Watermark = "";
//
// connect
//
connect.Cursor = Cursors.Hand;
connect.FillColor = Color.FromArgb(144, 147, 153);
connect.FillColor2 = Color.FromArgb(144, 147, 153);
connect.FillHoverColor = Color.FromArgb(169, 172, 184);
connect.FillPressColor = Color.FromArgb(126, 130, 140);
connect.FillSelectedColor = Color.FromArgb(126, 130, 140);
connect.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
connect.Location = new Point(891, 137);
connect.MinimumSize = new Size(1, 1);
connect.Name = "connect";
connect.Radius = 6;
connect.RectColor = Color.FromArgb(144, 147, 153);
connect.RectHoverColor = Color.FromArgb(169, 172, 184);
connect.RectPressColor = Color.FromArgb(126, 130, 140);
connect.RectSelectedColor = Color.FromArgb(126, 130, 140);
connect.Size = new Size(151, 45);
connect.Style = Sunny.UI.UIStyle.Custom;
connect.StyleCustomMode = true;
connect.TabIndex = 23;
connect.Text = "🔗 连接功率计";
connect.TipsFont = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
connect.Click += uiButton11_Click;
//
// statusStrip1
//
statusStrip1.ImageScalingSize = new Size(24, 24);
@@ -859,7 +799,7 @@
uiLabel25.ForeColor = Color.FromArgb(64, 158, 255);
uiLabel25.Location = new Point(750, 220);
uiLabel25.Name = "uiLabel25";
uiLabel25.Size = new Size(60, 34);
uiLabel25.Size = new Size(80, 34);
uiLabel25.Style = Sunny.UI.UIStyle.Custom;
uiLabel25.StyleCustomMode = true;
uiLabel25.TabIndex = 21;
@@ -885,7 +825,7 @@
uiLabel2.ForeColor = Color.FromArgb(64, 158, 255);
uiLabel2.Location = new Point(750, 148);
uiLabel2.Name = "uiLabel2";
uiLabel2.Size = new Size(60, 34);
uiLabel2.Size = new Size(80, 34);
uiLabel2.Style = Sunny.UI.UIStyle.Custom;
uiLabel2.StyleCustomMode = true;
uiLabel2.TabIndex = 19;
@@ -1052,7 +992,7 @@
uiLabel12.ForeColor = Color.FromArgb(64, 158, 255);
uiLabel12.Location = new Point(460, 218);
uiLabel12.Name = "uiLabel12";
uiLabel12.Size = new Size(60, 34);
uiLabel12.Size = new Size(75, 34);
uiLabel12.Style = Sunny.UI.UIStyle.Custom;
uiLabel12.StyleCustomMode = true;
uiLabel12.TabIndex = 9;
@@ -1129,7 +1069,7 @@
uiLabel8.ForeColor = Color.FromArgb(64, 158, 255);
uiLabel8.Location = new Point(460, 146);
uiLabel8.Name = "uiLabel8";
uiLabel8.Size = new Size(60, 34);
uiLabel8.Size = new Size(75, 34);
uiLabel8.Style = Sunny.UI.UIStyle.Custom;
uiLabel8.StyleCustomMode = true;
uiLabel8.TabIndex = 3;
@@ -1155,7 +1095,7 @@
uiLabel7.ForeColor = Color.FromArgb(64, 158, 255);
uiLabel7.Location = new Point(460, 76);
uiLabel7.Name = "uiLabel7";
uiLabel7.Size = new Size(60, 34);
uiLabel7.Size = new Size(75, 34);
uiLabel7.Style = Sunny.UI.UIStyle.Custom;
uiLabel7.StyleCustomMode = true;
uiLabel7.TabIndex = 1;
@@ -1605,6 +1545,7 @@
FormClosing += PrimaryIgnitionForm_FormClosing;
FormClosed += PenetrationForm_FormClosed;
Load += PenetrationForm_Load;
Shown += PenetrationForm_Shown;
uiTableLayoutPanel1.ResumeLayout(false);
uiTableLayoutPanel2.ResumeLayout(false);
uiPanel3.ResumeLayout(false);
@@ -1679,9 +1620,6 @@
private Sunny.UI.UIButton uiButton1;
private StatusStrip statusStrip1;
private ToolStripStatusLabel toolStripStatusLabel1;
private Sunny.UI.UILabel uiLabel27;
private Sunny.UI.UIComboBox comkou;
private Sunny.UI.UIButton connect;
private Sunny.UI.UIGroupBox uiGroupBox4;
private Sunny.UI.UILabel uiLabel44;
private Sunny.UI.UILabel uiLabel45;

View File

@@ -62,7 +62,7 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
{
var timer = new System.Windows.Forms.Timer()
{
Interval = 200,
Interval = 500,
};
timer.Tick += async (s, e) =>
{
@@ -329,10 +329,66 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
{
Debug.WriteLine($"读取状态3失败: {ex.Message}");
}
}
private bool _lastRunStatus = false;
private bool _isReported = false;
//private async Task ReadStartStatusAsync()
//{
// try
// {
// bool[] registers3 = await _modbusMaster?.ReadCoilsAsync(1, 81, 1);
// if (registers3 != null && registers3.Length >= 1)
// {
// bool currentRunStatus = registers3[0];
// this.Invoke(new Action(() =>
// {
// uiLabel31.Text = currentRunStatus ? "运行中" : "空闲中";
// }));
// // ========== 关键修改1移除重复的插入逻辑只保留一段 ==========
// // 仅在「运行→停止」且未上报过的情况下执行一次插入
// if (_lastRunStatus && !currentRunStatus && !_isReported)
// {
// // 添加延迟确保数据稳定
// //await Task.Delay(500);
// //await Task.Delay(500);
// //加锁防止异步并发重复执行
// await _asyncLock.WaitAsync();
// try
// {
// // 二次校验,防止锁等待期间状态已变更
// if (!_isReported)
// {
// var model = await InsertReportAsync();
// if (model != null && !string.IsNullOrEmpty(model.Id2))
// {
// conductivityRepository.InsertReportItems(model);
// _isReported = true; // 标记已上报
// Debug.WriteLine($"报表插入成功:样品{model.sampleType2}, 分类{model.result2}");
// }
// }
// }
// finally
// {
// _asyncLock.Release(); // 释放锁
// }
// }
// _lastRunStatus = currentRunStatus;
// }
// }
// catch (Exception ex)
// {
// MessageBox.Show(ex.Message);
// _readtimer?.Stop();
// Debug.WriteLine($"读取状态失败: {ex.Message}");
// }
// //finally { _asyncLock.Release(); }
//}
private async Task ReadStartStatusAsync()
{
try
@@ -342,24 +398,31 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
if (registers3 != null && registers3.Length >= 1)
{
bool currentRunStatus = registers3[0];
if (!this.IsHandleCreated)
return;
this.Invoke(new Action(() =>
{
uiLabel31.Text = currentRunStatus ? "运行中" : "空闲中";
}));
// ========== 关键修改1移除重复的插入逻辑只保留一段 ==========
// 仅在「运行→停止」且未上报过的情况下执行一次插入
if (_lastRunStatus && !currentRunStatus && !_isReported)
// ========== 关键修改:修复状态机逻辑 ==========
// 检测到「运行→停止」的下降沿
if (_lastRunStatus && !currentRunStatus)
{
// 添加延迟确保数据稳定
//await Task.Delay(500);
//await Task.Delay(500);
// 加锁防止异步并发重复执行
Debug.WriteLine($"检测到运行停止:上次状态={_lastRunStatus},当前状态={currentRunStatus},已上报={_isReported}");
// 延迟等待数据稳定
await Task.Delay(300);
await _asyncLock.WaitAsync();
try
{
// 二次校验,防止锁等待期间状态已变更
// 只有在没有上报过时才执行插入
if (!_isReported)
{
Debug.WriteLine("开始执行InsertReportAsync...");
var model = await InsertReportAsync();
if (model != null && !string.IsNullOrEmpty(model.Id2))
{
@@ -367,13 +430,28 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
_isReported = true; // 标记已上报
Debug.WriteLine($"报表插入成功:样品{model.sampleType2}, 分类{model.result2}");
}
else
{
Debug.WriteLine("InsertReportAsync返回空模型或无效ID");
}
}
else
{
Debug.WriteLine("已上报过,跳过插入");
}
}
finally
{
_asyncLock.Release(); // 释放锁
_asyncLock.Release();
}
}
// 检测到「停止→运行」的上升沿,重置上报标记
else if (!_lastRunStatus && currentRunStatus)
{
_isReported = false;
_isCurrentRecordAdded = false;
Debug.WriteLine("检测到开始运行,重置上报标记");
}
_lastRunStatus = currentRunStatus;
}
@@ -384,7 +462,6 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
_readtimer?.Stop();
Debug.WriteLine($"读取状态失败: {ex.Message}");
}
//finally { _asyncLock.Release(); }
}
@@ -500,7 +577,9 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
ushort[] tem = _modbusMaster?.ReadHoldingRegisters(1, (ushort)tempRegAddress, 2);
if (tem != null && tem.Length >= 2)
{
temperature = c.UshortToFloat(tem[1], tem[0]);
float rawTemperature = c.UshortToFloat(tem[1], tem[0]);
// 保留一位小数
temperature = (float)Math.Round(rawTemperature, 1);
}
}
@@ -1002,7 +1081,7 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
"无氧环境/灭火 (0%)"
};
uiComboBox1.Items.AddRange(options);
uiComboBox1.SelectedIndex = 0;
}
@@ -1028,19 +1107,21 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
}
ma = new Function(_modbusMaster);
this.comkou.DataSource = SerialPort.GetPortNames();
//this.comkou.DataSource = SerialPort.GetPortNames();
//this.comkou.Items.Clear();
//this.comkou.Items.Add("COM2");
//this.comkou.SelectedIndex = 0;
_readtimer = InitTimer();
if (_modbusMaster != null)
{
_readtimer.Start();
}
_modbusMaster?.WriteSingleRegister(1, 2, 2);
this.FormClosed += (s, args) =>
{
// 当子窗体关闭时,显示主窗体
Application.OpenForms["MainForm"]?.Show();
};
initPort();
uiComboBox1.SelectedIndex = 0;
}
private void PenetrationForm_FormClosed(object sender, FormClosedEventArgs e)
@@ -1056,6 +1137,8 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
if (_isSerialPortAvailable && serialPort != null && serialPort.IsOpen)
{
Disconnect();
toolStripStatusLabel1.Text = "功率计已断开";
toolStripStatusLabel1.BackColor = Color.Red;
}
// 显示主窗体
@@ -1089,6 +1172,9 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
TaskDialog.ShowDialog(this, page);
}
#region
private void uiButton4_Click(object sender, EventArgs e)
{
ma?.BtnClickFunctionForNew(Function.ButtonType., 78);//余辉开始
@@ -1115,15 +1201,47 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
ma?.BtnClickFunctionForNew(Function.ButtonType., 42);//停止测试
}
bool isbt3on = false;
private void uiButton3_Click(object sender, EventArgs e)
{
ToggleButtonWithText(uiButton3, ref isbt3on, "灭火中", "灭火");
ma?.BtnClickFunctionForNew(Function.ButtonType., 99);//灭火
}
private void uiComboBox1_SelectedIndexChanged(object sender, EventArgs e)
private void ToggleButtonWithText(UIButton button, ref bool state, string onText, string offText)
{
ushort selectedIndex = ushort.Parse(uiComboBox1.SelectedIndex.ToString());
_modbusMaster?.WriteSingleRegister(1, 10, selectedIndex);//下拉框
state = !state;
button.ForeColor = state ? Color.Red : Color.White;
button.Text = state ? onText : offText;
}
#endregion
private async void uiComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//ushort selectedIndex = ushort.Parse(uiComboBox1.SelectedIndex.ToString());
//_modbusMaster?.WriteSingleRegister(1, 10, selectedIndex);//下拉框
// 1. 检查是否有选中项
//if (uiComboBox1.SelectedIndex == -1)
// return;
//// 2. 检查 _modbusMaster 是否有效、连接是否正常
//if (_modbusMaster == null || _tcpClient == null || !_tcpClient.Connected)
//{
// //MessageBox.Show("Modbus未连接无法写入数据");
// return;
//}
try
{
ushort selectedIndex = (ushort)uiComboBox1.SelectedIndex;
// 3. 使用异步方法(如果 Modbus 库支持避免UI线程阻塞
await _modbusMaster.WriteSingleRegisterAsync(1, 10, selectedIndex);
}
catch (Exception ex)
{
MessageBox.Show($"写入寄存器失败:{ex.Message}");
Debug.WriteLine($"WriteSingleRegister错误{ex}");
}
}
private void InitComboBox2Pattern()
@@ -1195,67 +1313,111 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
// }
//}
private void uiButton11_Click(object sender, EventArgs e)
{
if (this.connect.Text == "🔗 连接功率计")
{
lock (_serialLock)
{
try
{
_serialBuffer = "";
_waitingResponse = false;
//private void uiButton11_Click(object sender, EventArgs e)
//{
// if (this.connect.Text == "🔗 连接功率计")
// {
// lock (_serialLock)
// {
// try
// {
// _serialBuffer = "";
// _waitingResponse = false;
serialPort = new SerialPort();
serialPort.PortName = this.comkou.Text;
serialPort.BaudRate = 38400;
serialPort.DataBits = 8;
serialPort.Parity = Parity.None;
serialPort.StopBits = StopBits.One;
serialPort.NewLine = "\r\n";
// serialPort = new SerialPort();
// serialPort.PortName = this.comkou.Text;
// serialPort.BaudRate = 38400;
// serialPort.DataBits = 8;
// serialPort.Parity = Parity.None;
// serialPort.StopBits = StopBits.One;
// serialPort.NewLine = "\r\n";
serialPort.DataReceived += SerialPort_DataReceived;
// serialPort.DataReceived += SerialPort_DataReceived;
serialPort.Open();
// serialPort.Open();
_isSerialPortAvailable = true;
this.connect.Text = "断开连接";
toolStripStatusLabel1.Text = "功率计已连接";
toolStripStatusLabel1.BackColor = Color.Lime;
uiLabel27.Text = "";
WriteToLog("功率计串口连接成功");
// _isSerialPortAvailable = true;
// this.connect.Text = "断开连接";
// toolStripStatusLabel1.Text = "功率计已连接";
// toolStripStatusLabel1.BackColor = Color.Lime;
// uiLabel27.Text = "";
// WriteToLog("功率计串口连接成功");
_powerMeterTimer = new System.Windows.Forms.Timer();
_powerMeterTimer.Interval = 300; // 100ms读取一次
_powerMeterTimer.Tick += PowerMeterTimer_Tick;
_powerMeterTimer.Start();
// _powerMeterTimer = new System.Windows.Forms.Timer();
// _powerMeterTimer.Interval = 300; // 100ms读取一次
// _powerMeterTimer.Tick += PowerMeterTimer_Tick;
// _powerMeterTimer.Start();
//SendCommand("S01");
}
catch (Exception ex)
{
MessageBox.Show($"串口连接失败:{ex.Message}");
_isSerialPortAvailable = false;
WriteToLog($"串口连接失败: {ex.Message}");
return;
}
}
}
else
{
Disconnect();
this.connect.Text = "🔗 连接功率计";
uiLabel27.Text = "(请先连接功率计!!)";
toolStripStatusLabel1.Text = "功率计已断开";
toolStripStatusLabel1.BackColor = Color.Red;
}
}
// //SendCommand("S01");
// }
// catch (Exception ex)
// {
// MessageBox.Show($"串口连接失败:{ex.Message}");
// _isSerialPortAvailable = false;
// WriteToLog($"串口连接失败: {ex.Message}");
// return;
// }
// }
// }
// else
// {
// Disconnect();
// this.connect.Text = "🔗 连接功率计";
// uiLabel27.Text = "(请先连接功率计!!)";
// toolStripStatusLabel1.Text = "功率计已断开";
// toolStripStatusLabel1.BackColor = Color.Red;
// }
//}
// 串口数据接收事件
private void initPort()
{
lock (_serialLock)
{
try
{
// 创建串口对象
serialPort = new SerialPort();
serialPort.PortName = "COM2";
serialPort.BaudRate = 38400;
serialPort.DataBits = 8;
serialPort.Parity = Parity.None;
serialPort.StopBits = StopBits.One;
serialPort.NewLine = "\r\n";
// 设置数据接收事件
serialPort.DataReceived += SerialPort_DataReceived;
toolStripStatusLabel1.Text = "功率计已连接";
toolStripStatusLabel1.BackColor = Color.Lime;
serialPort.Open();
_isSerialPortAvailable = true;
_powerMeterTimer = new System.Windows.Forms.Timer();
_powerMeterTimer.Interval = 200; // 100ms读取一次
_powerMeterTimer.Tick += PowerMeterTimer_Tick;
_powerMeterTimer.Start();
//SendCommand("S01");
}
catch (Exception ex)
{
MessageBox.Show($"串口连接失败:{ex.Message}");
_isSerialPortAvailable = false;
return;
}
}
}
private void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
try
@@ -1624,19 +1786,19 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
//相机
private void uiButton8_Click(object sender, EventArgs e)
{
AutoCameraForm cameraForm = new AutoCameraForm(() => RunStatus);
this.SwitchToForm(() => cameraForm);
}
private void SwitchToForm(Func<Form> formCreator)
{
using (Form form = formCreator())
//AutoCameraForm cameraForm = new AutoCameraForm(() => RunStatus);
//this.SwitchToForm(() => cameraForm);
var cameraForm = new AutoCameraForm(() => RunStatus);
// 设置窗体关闭时释放资源
cameraForm.FormClosed += (s, args) =>
{
this.Hide();
form.ShowDialog();
this.Show();
this.Activate();
}
cameraForm.Dispose();
};
cameraForm.Show();
}
private void uiButton10_Click(object sender, EventArgs e)
{
@@ -1662,14 +1824,30 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
}
}
#region
bool isbt11on =false;
bool isbt9on=false;
private void uiButton11_Click_1(object sender, EventArgs e)
{
ToggleButtonWithText(uiButton11, ref isbt11on, "开灯中", "💡 灯开关");
ma?.BtnClickFunctionForNew(Function.ButtonType., 11);//灯开关
}
private void uiButton9_Click(object sender, EventArgs e)
{
ToggleButtonWithText(uiButton9, ref isbt9on, "混氧中", "手动混氧");
ma?.BtnClickFunctionForNew(Function.ButtonType., 101);//混氧开关
}
#endregion
private void PenetrationForm_Shown(object sender, EventArgs e)
{
if (_modbusMaster != null)
{
_readtimer = InitTimer();
_readtimer.Start();
}
}
}
}

View File

@@ -1449,6 +1449,7 @@
FormClosing += PrimaryIgnitionForm_FormClosing;
FormClosed += PrimaryIgnitionForm_FormClosed;
Load += PrimaryIgnitionForm_Load;
Shown += PrimaryIgnitionForm_Shown;
uiTableLayoutPanel1.ResumeLayout(false);
uiTableLayoutPanel2.ResumeLayout(false);
uiPanel3.ResumeLayout(false);

View File

@@ -70,11 +70,7 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
}
ma = new Function(_modbusMaster);
_readtimer = InitTimer();
if (_modbusMaster != null)
{
_readtimer.Start();
}
this.FormClosed += (s, args) =>
{
@@ -82,11 +78,11 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
Application.OpenForms["MainForm"]?.Show();
};
uiComboBox1.SelectedIndex = 0;
//// ch: 初始化 SDK | en: Initialize SDK
//MyCamera.MV_CC_Initialize_NET();
_modbusMaster?.WriteSingleRegister(1, 2, 1);
}
@@ -97,7 +93,7 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
{
var timer = new System.Windows.Forms.Timer()
{
Interval = 100,
Interval = 500,
};
timer.Tick += async (s, e) =>
{
@@ -272,6 +268,9 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
bool currentRunStatus = registers2[0]; // 当前运行状态
RunStatus = currentRunStatus;
if (!this.IsHandleCreated)
return;
this.Invoke(new Action(() =>
{
uiLabel23.Text = currentRunStatus ? "运行中" : "空闲中";
@@ -331,7 +330,7 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
private float firetime = 0;
private float yy = 0;
private float yh = 0;
private bool iszixi = false;
private string iszixi = string.Empty;
private double costtime = 0;
private bool _isCurrentRecordAdded = true;//重复添加标记
@@ -365,13 +364,15 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
//}
bool[] fire1 = await ReadModbusCoilAsync(280, 1);
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
if (fire1 != null && fire1.Length > 0 && !fire1[0])
if (fire1 != null && fire1.Length > 0 && fire1[0])
{
iszixi = true;//自熄
//iszixi = true;//自熄
iszixi = "true";
}
else if (fire2 != null && fire2.Length > 0 && fire2[0])
{
iszixi = false;
//iszixi = false;
iszixi = "false";
}
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 90, 2);
costtime = time[0];//总测试时长
@@ -396,11 +397,11 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
if (fire1 != null && fire1.Length > 0 && fire1[0])
{
iszixi = true;//自熄
iszixi = "true";
}
else if (fire2 != null && fire2.Length > 0 && fire2[0])
{
iszixi = false;
iszixi = "false";
}
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 90, 2);
costtime = time[0];//总测试时长
@@ -426,12 +427,13 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
if (fire1 != null && fire1.Length > 0 && fire1[0])
{
iszixi = true;//自熄
iszixi = "true";
}
else if (fire2 != null && fire2.Length > 0 && fire2[0])
{
iszixi = false;
iszixi = "false";
}
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 90, 2);
costtime = time[0];//总测试时长
}
@@ -456,11 +458,15 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
if (fire1 != null && fire1.Length > 0 && fire1[0])
{
iszixi = true;//自熄
iszixi = "true";
}
else if (fire2 != null && fire2.Length > 0 && fire2[0])
{
iszixi = false;
iszixi = "false";
}
else
{
iszixi = "null";
}
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 90, 2);
costtime = time[0];//总测试时长
@@ -496,11 +502,11 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
if (fire1 != null && fire1.Length > 0 && fire1[0])
{
iszixi = true;//自熄
iszixi = "true";
}
else if (fire2 != null && fire2.Length > 0 && fire2[0])
{
iszixi = false;
iszixi = "false";
}
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 92, 2);
costtime = time[0];//总测试时长
@@ -526,11 +532,11 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
if (fire1 != null && fire1.Length > 0 && fire1[0])
{
iszixi = true;//自熄
iszixi = "true";
}
else if (fire2 != null && fire2.Length > 0 && fire2[0])
{
iszixi = false;
iszixi = "false";
}
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 92, 2);
costtime = time[0];//总测试时长
@@ -556,11 +562,11 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
if (fire1 != null && fire1.Length > 0 && fire1[0])
{
iszixi = true;//自熄
iszixi = "true";//自熄
}
else if (fire2 != null && fire2.Length > 0 && fire2[0])
{
iszixi = false;
iszixi = "false";
}
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 92, 2);
costtime = time[0];//总测试时长
@@ -583,11 +589,15 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
if (fire1 != null && fire1.Length > 0 && fire1[0])
{
iszixi = true;//自熄
iszixi = "true";//自熄
}
else if (fire2 != null && fire2.Length > 0 && fire2[0])
{
iszixi = false;
iszixi = "false";
}
else
{
iszixi = "null";
}
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 92, 2);
costtime = time[0];//总测试时长
@@ -620,11 +630,11 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
if (fire1 != null && fire1.Length > 0 && fire1[0])
{
iszixi = true;//自熄
iszixi = "true";//自熄
}
else if (fire2 != null && fire2.Length > 0 && fire2[0])
{
iszixi = false;
iszixi = "false";
}
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 94, 2);
costtime = time[0];//总测试时长
@@ -648,11 +658,11 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
if (fire1 != null && fire1.Length > 0 && fire1[0])
{
iszixi = true;//自熄
iszixi = "true";//自熄
}
else if (fire2 != null && fire2.Length > 0 && fire2[0])
{
iszixi = false;
iszixi = "false";
}
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 94, 2);
costtime = time[0];//总测试时长
@@ -675,11 +685,11 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
if (fire1 != null && fire1.Length > 0 && fire1[0])
{
iszixi = true;//自熄
iszixi = "true";//自熄
}
else if (fire2 != null && fire2.Length > 0 && fire2[0])
{
iszixi = false;
iszixi = "false";
}
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 94, 2);
costtime = time[0];//总测试时长
@@ -703,11 +713,15 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
if (fire1 != null && fire1.Length > 0 && fire1[0])
{
iszixi = true;//自熄
iszixi = "true";//自熄
}
else if (fire2 != null && fire2.Length > 0 && fire2[0])
{
iszixi = false;
iszixi = "false";
}
else
{
iszixi = "null";
}
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 94, 2);
costtime = time[0];//总测试时长
@@ -739,11 +753,11 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
if (fire1 != null && fire1.Length > 0 && fire1[0])
{
iszixi = true;//自熄
iszixi = "true";//自熄
}
else if (fire2 != null && fire2.Length > 0 && fire2[0])
{
iszixi = false;
iszixi = "false";
}
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 96, 2);
costtime = time[0];//总测试时长
@@ -766,11 +780,11 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
if (fire1 != null && fire1.Length > 0 && fire1[0])
{
iszixi = true;//自熄
iszixi = "true";//自熄
}
else if (fire2 != null && fire2.Length > 0 && fire2[0])
{
iszixi = false;
iszixi = "false";
}
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 96, 2);
costtime = time[0];//总测试时长
@@ -793,11 +807,11 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
if (fire1 != null && fire1.Length > 0 && fire1[0])
{
iszixi = true;//自熄
iszixi = "true";//自熄
}
else if (fire2 != null && fire2.Length > 0 && fire2[0])
{
iszixi = false;
iszixi = "false";
}
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 96, 2);
costtime = time[0];//总测试时长
@@ -820,11 +834,15 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
if (fire1 != null && fire1.Length > 0 && fire1[0])
{
iszixi = true;//自熄
iszixi = "true";//自熄
}
else if (fire2 != null && fire2.Length > 0 && fire2[0])
{
iszixi = false;
iszixi = "false";
}
else
{
iszixi = "null";
}
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 96, 2);
costtime = time[0];//总测试时长
@@ -856,11 +874,11 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
if (fire1 != null && fire1.Length > 0 && fire1[0])
{
iszixi = true;//自熄
iszixi = "true";//自熄
}
else if (fire2 != null && fire2.Length > 0 && fire2[0])
{
iszixi = false;
iszixi = "false";
}
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 98, 2);
costtime = time[0];//总测试时长
@@ -883,11 +901,11 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
if (fire1 != null && fire1.Length > 0 && fire1[0])
{
iszixi = true;//自熄
iszixi = "true";//自熄
}
else if (fire2 != null && fire2.Length > 0 && fire2[0])
{
iszixi = false;
iszixi = "false";
}
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 98, 2);
costtime = time[0];//总测试时长
@@ -910,11 +928,11 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
if (fire1 != null && fire1.Length > 0 && fire1[0])
{
iszixi = true;//自熄
iszixi = "true";//自熄
}
else if (fire2 != null && fire2.Length > 0 && fire2[0])
{
iszixi = false;
iszixi = "false";
}
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 98, 2);
costtime = time[0];//总测试时长
@@ -939,11 +957,15 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
if (fire1 != null && fire1.Length > 0 && fire1[0])
{
iszixi = true;//自熄
iszixi = "true";//自熄
}
else if (fire2 != null && fire2.Length > 0 && fire2[0])
{
iszixi = false;
iszixi = "false";
}
else
{
iszixi = "null";
}
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 98, 2);
costtime = time[0];//总测试时长
@@ -1000,7 +1022,8 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
{
string currentTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
if (!this.IsHandleCreated)
return;
// 跨线程更新UI异步方法中仍需检查Invoke避免跨线程异常
if (uiLabel25.InvokeRequired)
{
@@ -1038,7 +1061,7 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
"无氧环境/灭火 (0%)"
};
uiComboBox1.Items.AddRange(options);
uiComboBox1.SelectedIndex = 0;
}
@@ -1072,10 +1095,32 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
ma?.BtnClickFunctionForNew(Function.ButtonType., 7);//实验结束
}
private void uiComboBox1_SelectedIndexChanged(object sender, EventArgs e)
private async void uiComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
ushort selectedIndex = ushort.Parse(uiComboBox1.SelectedIndex.ToString());
_modbusMaster?.WriteSingleRegister(1, 10, selectedIndex);//下拉框
//ushort selectedIndex = ushort.Parse(uiComboBox1.SelectedIndex.ToString());
//_modbusMaster?.WriteSingleRegister(1, 10, selectedIndex);//下拉框
// 1. 检查是否有选中项
//if (uiComboBox1.SelectedIndex == -1)
// return;
//// 2. 检查 _modbusMaster 是否有效、连接是否正常
//if (_modbusMaster == null || _tcpClient == null || !_tcpClient.Connected)
//{
// MessageBox.Show("Modbus未连接无法写入数据");
// return;
//}
try
{
ushort selectedIndex = (ushort)uiComboBox1.SelectedIndex;
// 3. 使用异步方法(如果 Modbus 库支持避免UI线程阻塞
await _modbusMaster.WriteSingleRegisterAsync(1, 10, selectedIndex);
}
catch (Exception ex)
{
MessageBox.Show($"写入寄存器失败:{ex.Message}");
Debug.WriteLine($"WriteSingleRegister错误{ex}");
}
}
private void uiButton7_Click(object sender, EventArgs e)
@@ -1106,11 +1151,20 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
ma?.BtnClickFunctionForNew(Function.ButtonType., 55);//手动停止
}
bool isbt3on = false;
private void uiButton3_Click(object sender, EventArgs e)
{
ToggleButtonWithText(uiButton3, ref isbt3on, "灭火中", "灭火");
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)
{
@@ -1216,20 +1270,32 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
}
}
private void uiButton8_Click(object sender, EventArgs e)
{
AutoCameraForm cameraForm = new AutoCameraForm(() => RunStatus);
this.SwitchToForm(() => cameraForm);
//AutoCameraForm cameraForm = new AutoCameraForm(() => RunStatus);
//this.SwitchToForm(() => cameraForm);
var cameraForm = new AutoCameraForm(() => RunStatus);
// 设置窗体关闭时释放资源
cameraForm.FormClosed += (s, args) =>
{
cameraForm.Dispose();
};
cameraForm.Show();
}
private void uiButton11_Click(object sender, EventArgs e)
{
ma?.BtnClickFunctionForNew(Function.ButtonType., 271);
ma?.BtnClickFunctionForNew(Function.ButtonType., 271);//未自熄
}
private void uiButton12_Click(object sender, EventArgs e)
{
ma?.BtnClickFunctionForNew(Function.ButtonType., 270);
ma?.BtnClickFunctionForNew(Function.ButtonType., 270);//自熄
}
private void uiButton13_Click(object sender, EventArgs e)
@@ -1253,14 +1319,28 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
}
}
bool isbt14on = false;
bool isbt9on = false;
private void uiButton9_Click(object sender, EventArgs e)
{
ToggleButtonWithText(uiButton9, ref isbt9on, "混氧中", "手动混氧");
ma?.BtnClickFunctionForNew(Function.ButtonType., 101);//混氧开关
}
private void uiButton14_Click(object sender, EventArgs e)
{
ToggleButtonWithText(uiButton14, ref isbt14on, "开灯中", "💡 灯开关");
ma?.BtnClickFunctionForNew(Function.ButtonType., 11);//灯开关
}
private void PrimaryIgnitionForm_Shown(object sender, EventArgs e)
{
if (_modbusMaster != null)
{
_readtimer = InitTimer();
_readtimer.Start();
}
}
}
}

View File

@@ -30,9 +30,9 @@
{
DataGridViewCellStyle dataGridViewCellStyle1 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle11 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle12 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle13 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle14 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle3 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle4 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle5 = new DataGridViewCellStyle();
@@ -41,9 +41,12 @@
DataGridViewCellStyle dataGridViewCellStyle8 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle9 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle10 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle14 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle11 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle15 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle16 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle27 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle28 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle29 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle17 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle18 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle19 = new DataGridViewCellStyle();
@@ -51,6 +54,22 @@
DataGridViewCellStyle dataGridViewCellStyle21 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle22 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle23 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle24 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle25 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle26 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle30 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle31 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle40 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle41 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle42 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle32 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle33 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle34 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle35 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle36 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle37 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle38 = new DataGridViewCellStyle();
DataGridViewCellStyle dataGridViewCellStyle39 = new DataGridViewCellStyle();
uiTableLayoutPanel1 = new Sunny.UI.UITableLayoutPanel();
uiPanel2 = new Sunny.UI.UIPanel();
uiGroupBox2 = new Sunny.UI.UIGroupBox();
@@ -254,14 +273,14 @@
uiDataGridView1.ColumnHeadersHeight = 42;
uiDataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
uiDataGridView1.Columns.AddRange(new DataGridViewColumn[] { id, O2, result, FireDate, yuyan, yuhui, iszixi, costtime, CreateTime });
dataGridViewCellStyle11.Alignment = DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle11.BackColor = Color.White;
dataGridViewCellStyle11.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewCellStyle11.ForeColor = Color.FromArgb(48, 48, 48);
dataGridViewCellStyle11.SelectionBackColor = Color.FromArgb(240, 248, 255);
dataGridViewCellStyle11.SelectionForeColor = Color.FromArgb(48, 49, 51);
dataGridViewCellStyle11.WrapMode = DataGridViewTriState.False;
uiDataGridView1.DefaultCellStyle = dataGridViewCellStyle11;
dataGridViewCellStyle12.Alignment = DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle12.BackColor = Color.White;
dataGridViewCellStyle12.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewCellStyle12.ForeColor = Color.FromArgb(48, 48, 48);
dataGridViewCellStyle12.SelectionBackColor = Color.FromArgb(240, 248, 255);
dataGridViewCellStyle12.SelectionForeColor = Color.FromArgb(48, 49, 51);
dataGridViewCellStyle12.WrapMode = DataGridViewTriState.False;
uiDataGridView1.DefaultCellStyle = dataGridViewCellStyle12;
uiDataGridView1.Dock = DockStyle.Fill;
uiDataGridView1.EnableHeadersVisualStyles = false;
uiDataGridView1.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
@@ -269,18 +288,18 @@
uiDataGridView1.Location = new Point(0, 0);
uiDataGridView1.Name = "uiDataGridView1";
uiDataGridView1.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
dataGridViewCellStyle12.Alignment = DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle12.BackColor = Color.FromArgb(240, 248, 255);
dataGridViewCellStyle12.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewCellStyle12.ForeColor = Color.FromArgb(48, 49, 51);
dataGridViewCellStyle12.SelectionBackColor = Color.FromArgb(52, 152, 219);
dataGridViewCellStyle12.SelectionForeColor = Color.White;
dataGridViewCellStyle12.WrapMode = DataGridViewTriState.True;
uiDataGridView1.RowHeadersDefaultCellStyle = dataGridViewCellStyle12;
uiDataGridView1.RowHeadersWidth = 62;
dataGridViewCellStyle13.BackColor = Color.White;
dataGridViewCellStyle13.Alignment = DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle13.BackColor = Color.FromArgb(240, 248, 255);
dataGridViewCellStyle13.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
uiDataGridView1.RowsDefaultCellStyle = dataGridViewCellStyle13;
dataGridViewCellStyle13.ForeColor = Color.FromArgb(48, 49, 51);
dataGridViewCellStyle13.SelectionBackColor = Color.FromArgb(52, 152, 219);
dataGridViewCellStyle13.SelectionForeColor = Color.White;
dataGridViewCellStyle13.WrapMode = DataGridViewTriState.True;
uiDataGridView1.RowHeadersDefaultCellStyle = dataGridViewCellStyle13;
uiDataGridView1.RowHeadersWidth = 62;
dataGridViewCellStyle14.BackColor = Color.White;
dataGridViewCellStyle14.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
uiDataGridView1.RowsDefaultCellStyle = dataGridViewCellStyle14;
uiDataGridView1.SelectedIndex = -1;
uiDataGridView1.Size = new Size(1375, 802);
uiDataGridView1.StripeOddColor = Color.FromArgb(240, 248, 255);
@@ -313,6 +332,9 @@
// result
//
result.DataPropertyName = "result";
dataGridViewCellStyle5.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle5.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
result.DefaultCellStyle = dataGridViewCellStyle5;
result.HeaderText = "分类结果";
result.MinimumWidth = 8;
result.Name = "result";
@@ -322,9 +344,9 @@
// FireDate
//
FireDate.DataPropertyName = "FireDate";
dataGridViewCellStyle5.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle5.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
FireDate.DefaultCellStyle = dataGridViewCellStyle5;
dataGridViewCellStyle6.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle6.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
FireDate.DefaultCellStyle = dataGridViewCellStyle6;
FireDate.HeaderText = "点火时间(s)";
FireDate.MinimumWidth = 8;
FireDate.Name = "FireDate";
@@ -334,9 +356,9 @@
// yuyan
//
yuyan.DataPropertyName = "yuyan";
dataGridViewCellStyle6.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle6.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
yuyan.DefaultCellStyle = dataGridViewCellStyle6;
dataGridViewCellStyle7.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle7.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
yuyan.DefaultCellStyle = dataGridViewCellStyle7;
yuyan.HeaderText = "余焰时间(s)";
yuyan.MinimumWidth = 8;
yuyan.Name = "yuyan";
@@ -346,9 +368,9 @@
// yuhui
//
yuhui.DataPropertyName = "yuhui";
dataGridViewCellStyle7.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle7.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
yuhui.DefaultCellStyle = dataGridViewCellStyle7;
dataGridViewCellStyle8.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle8.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
yuhui.DefaultCellStyle = dataGridViewCellStyle8;
yuhui.HeaderText = "余辉时间(s)";
yuhui.MinimumWidth = 8;
yuhui.Name = "yuhui";
@@ -358,9 +380,9 @@
// iszixi
//
iszixi.DataPropertyName = "Iszixi";
dataGridViewCellStyle8.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle8.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
iszixi.DefaultCellStyle = dataGridViewCellStyle8;
dataGridViewCellStyle9.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle9.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
iszixi.DefaultCellStyle = dataGridViewCellStyle9;
iszixi.HeaderText = "是否自熄";
iszixi.MinimumWidth = 8;
iszixi.Name = "iszixi";
@@ -370,9 +392,9 @@
// costtime
//
costtime.DataPropertyName = "costTime";
dataGridViewCellStyle9.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle9.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
costtime.DefaultCellStyle = dataGridViewCellStyle9;
dataGridViewCellStyle10.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle10.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
costtime.DefaultCellStyle = dataGridViewCellStyle10;
costtime.HeaderText = "总测试时长(s)";
costtime.MinimumWidth = 8;
costtime.Name = "costtime";
@@ -382,50 +404,50 @@
// CreateTime
//
CreateTime.DataPropertyName = "Testtime";
dataGridViewCellStyle10.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle10.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
CreateTime.DefaultCellStyle = dataGridViewCellStyle10;
dataGridViewCellStyle11.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle11.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
CreateTime.DefaultCellStyle = dataGridViewCellStyle11;
CreateTime.HeaderText = "测试时间";
CreateTime.MinimumWidth = 8;
CreateTime.Name = "CreateTime";
CreateTime.ReadOnly = true;
CreateTime.Width = 150;
CreateTime.Width = 220;
//
// tabPage2
//
tabPage2.BackColor = Color.White;
tabPage2.Controls.Add(uiDataGridView2);
tabPage2.Location = new Point(0, 45);
tabPage2.Location = new Point(0, 40);
tabPage2.Name = "tabPage2";
tabPage2.Size = new Size(1375, 802);
tabPage2.Size = new Size(200, 60);
tabPage2.TabIndex = 1;
tabPage2.Text = "📈 穿透性测试报告";
//
// uiDataGridView2
//
dataGridViewCellStyle14.BackColor = Color.FromArgb(240, 248, 255);
uiDataGridView2.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle14;
dataGridViewCellStyle15.BackColor = Color.FromArgb(240, 248, 255);
uiDataGridView2.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle15;
uiDataGridView2.BackgroundColor = Color.White;
uiDataGridView2.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
dataGridViewCellStyle15.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle15.BackColor = Color.FromArgb(52, 152, 219);
dataGridViewCellStyle15.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewCellStyle15.ForeColor = Color.White;
dataGridViewCellStyle15.SelectionBackColor = Color.FromArgb(52, 152, 219);
dataGridViewCellStyle15.SelectionForeColor = Color.White;
dataGridViewCellStyle15.WrapMode = DataGridViewTriState.True;
uiDataGridView2.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle15;
dataGridViewCellStyle16.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle16.BackColor = Color.FromArgb(52, 152, 219);
dataGridViewCellStyle16.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewCellStyle16.ForeColor = Color.White;
dataGridViewCellStyle16.SelectionBackColor = Color.FromArgb(52, 152, 219);
dataGridViewCellStyle16.SelectionForeColor = Color.White;
dataGridViewCellStyle16.WrapMode = DataGridViewTriState.True;
uiDataGridView2.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle16;
uiDataGridView2.ColumnHeadersHeight = 42;
uiDataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
uiDataGridView2.Columns.AddRange(new DataGridViewColumn[] { dataGridViewTextBoxColumn1, dataGridViewTextBoxColumn2, dataGridViewTextBoxColumn3, dataGridViewTextBoxColumn4, dataGridViewTextBoxColumn5, dataGridViewTextBoxColumn6, dataGridViewTextBoxColumn7, dataGridViewTextBoxColumn8, Column9, Column1 });
dataGridViewCellStyle16.Alignment = DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle16.BackColor = Color.White;
dataGridViewCellStyle16.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewCellStyle16.ForeColor = Color.FromArgb(48, 48, 48);
dataGridViewCellStyle16.SelectionBackColor = Color.FromArgb(240, 248, 255);
dataGridViewCellStyle16.SelectionForeColor = Color.FromArgb(48, 49, 51);
dataGridViewCellStyle16.WrapMode = DataGridViewTriState.False;
uiDataGridView2.DefaultCellStyle = dataGridViewCellStyle16;
dataGridViewCellStyle27.Alignment = DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle27.BackColor = Color.White;
dataGridViewCellStyle27.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewCellStyle27.ForeColor = Color.FromArgb(48, 48, 48);
dataGridViewCellStyle27.SelectionBackColor = Color.FromArgb(240, 248, 255);
dataGridViewCellStyle27.SelectionForeColor = Color.FromArgb(48, 49, 51);
dataGridViewCellStyle27.WrapMode = DataGridViewTriState.False;
uiDataGridView2.DefaultCellStyle = dataGridViewCellStyle27;
uiDataGridView2.Dock = DockStyle.Fill;
uiDataGridView2.EnableHeadersVisualStyles = false;
uiDataGridView2.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
@@ -433,26 +455,29 @@
uiDataGridView2.Location = new Point(0, 0);
uiDataGridView2.Name = "uiDataGridView2";
uiDataGridView2.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
dataGridViewCellStyle17.Alignment = DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle17.BackColor = Color.FromArgb(240, 248, 255);
dataGridViewCellStyle17.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewCellStyle17.ForeColor = Color.FromArgb(48, 49, 51);
dataGridViewCellStyle17.SelectionBackColor = Color.FromArgb(52, 152, 219);
dataGridViewCellStyle17.SelectionForeColor = Color.White;
dataGridViewCellStyle17.WrapMode = DataGridViewTriState.True;
uiDataGridView2.RowHeadersDefaultCellStyle = dataGridViewCellStyle17;
dataGridViewCellStyle28.Alignment = DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle28.BackColor = Color.FromArgb(240, 248, 255);
dataGridViewCellStyle28.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewCellStyle28.ForeColor = Color.FromArgb(48, 49, 51);
dataGridViewCellStyle28.SelectionBackColor = Color.FromArgb(52, 152, 219);
dataGridViewCellStyle28.SelectionForeColor = Color.White;
dataGridViewCellStyle28.WrapMode = DataGridViewTriState.True;
uiDataGridView2.RowHeadersDefaultCellStyle = dataGridViewCellStyle28;
uiDataGridView2.RowHeadersWidth = 62;
dataGridViewCellStyle18.BackColor = Color.White;
dataGridViewCellStyle18.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
uiDataGridView2.RowsDefaultCellStyle = dataGridViewCellStyle18;
dataGridViewCellStyle29.BackColor = Color.White;
dataGridViewCellStyle29.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
uiDataGridView2.RowsDefaultCellStyle = dataGridViewCellStyle29;
uiDataGridView2.SelectedIndex = -1;
uiDataGridView2.Size = new Size(1375, 802);
uiDataGridView2.Size = new Size(200, 60);
uiDataGridView2.StripeOddColor = Color.FromArgb(240, 248, 255);
uiDataGridView2.TabIndex = 1;
//
// dataGridViewTextBoxColumn1
//
dataGridViewTextBoxColumn1.DataPropertyName = "Id2";
dataGridViewCellStyle17.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle17.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewTextBoxColumn1.DefaultCellStyle = dataGridViewCellStyle17;
dataGridViewTextBoxColumn1.HeaderText = "测试项/样品";
dataGridViewTextBoxColumn1.MinimumWidth = 8;
dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1";
@@ -462,6 +487,9 @@
// dataGridViewTextBoxColumn2
//
dataGridViewTextBoxColumn2.DataPropertyName = "O22";
dataGridViewCellStyle18.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle18.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewTextBoxColumn2.DefaultCellStyle = dataGridViewCellStyle18;
dataGridViewTextBoxColumn2.HeaderText = "氧浓度(%";
dataGridViewTextBoxColumn2.MinimumWidth = 8;
dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2";
@@ -471,6 +499,9 @@
// dataGridViewTextBoxColumn3
//
dataGridViewTextBoxColumn3.DataPropertyName = "result2";
dataGridViewCellStyle19.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle19.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewTextBoxColumn3.DefaultCellStyle = dataGridViewCellStyle19;
dataGridViewTextBoxColumn3.HeaderText = "分类结果";
dataGridViewTextBoxColumn3.MinimumWidth = 8;
dataGridViewTextBoxColumn3.Name = "dataGridViewTextBoxColumn3";
@@ -480,6 +511,9 @@
// dataGridViewTextBoxColumn4
//
dataGridViewTextBoxColumn4.DataPropertyName = "temperature2";
dataGridViewCellStyle20.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle20.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewTextBoxColumn4.DefaultCellStyle = dataGridViewCellStyle20;
dataGridViewTextBoxColumn4.HeaderText = "P1背面温度(℃)";
dataGridViewTextBoxColumn4.MinimumWidth = 8;
dataGridViewTextBoxColumn4.Name = "dataGridViewTextBoxColumn4";
@@ -489,6 +523,9 @@
// dataGridViewTextBoxColumn5
//
dataGridViewTextBoxColumn5.DataPropertyName = "yuyan2";
dataGridViewCellStyle21.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle21.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewTextBoxColumn5.DefaultCellStyle = dataGridViewCellStyle21;
dataGridViewTextBoxColumn5.HeaderText = "燃烧时间(s)";
dataGridViewTextBoxColumn5.MinimumWidth = 8;
dataGridViewTextBoxColumn5.Name = "dataGridViewTextBoxColumn5";
@@ -498,6 +535,9 @@
// dataGridViewTextBoxColumn6
//
dataGridViewTextBoxColumn6.DataPropertyName = "yuhui2";
dataGridViewCellStyle22.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle22.Font = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewTextBoxColumn6.DefaultCellStyle = dataGridViewCellStyle22;
dataGridViewTextBoxColumn6.HeaderText = "余辉时间(s)";
dataGridViewTextBoxColumn6.MinimumWidth = 8;
dataGridViewTextBoxColumn6.Name = "dataGridViewTextBoxColumn6";
@@ -507,6 +547,9 @@
// dataGridViewTextBoxColumn7
//
dataGridViewTextBoxColumn7.DataPropertyName = "Isfire";
dataGridViewCellStyle23.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle23.Font = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewTextBoxColumn7.DefaultCellStyle = dataGridViewCellStyle23;
dataGridViewTextBoxColumn7.HeaderText = "是否起火";
dataGridViewTextBoxColumn7.MinimumWidth = 8;
dataGridViewTextBoxColumn7.Name = "dataGridViewTextBoxColumn7";
@@ -516,6 +559,9 @@
// dataGridViewTextBoxColumn8
//
dataGridViewTextBoxColumn8.DataPropertyName = "costTime2";
dataGridViewCellStyle24.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle24.Font = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewTextBoxColumn8.DefaultCellStyle = dataGridViewCellStyle24;
dataGridViewTextBoxColumn8.HeaderText = "总测试时长(s)";
dataGridViewTextBoxColumn8.MinimumWidth = 8;
dataGridViewTextBoxColumn8.Name = "dataGridViewTextBoxColumn8";
@@ -525,6 +571,9 @@
// Column9
//
Column9.DataPropertyName = "penetime2";
dataGridViewCellStyle25.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle25.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
Column9.DefaultCellStyle = dataGridViewCellStyle25;
Column9.HeaderText = "穿透时间(s)";
Column9.MinimumWidth = 8;
Column9.Name = "Column9";
@@ -534,11 +583,14 @@
// Column1
//
Column1.DataPropertyName = "Testtime2";
dataGridViewCellStyle26.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle26.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
Column1.DefaultCellStyle = dataGridViewCellStyle26;
Column1.HeaderText = "测试时间";
Column1.MinimumWidth = 8;
Column1.Name = "Column1";
Column1.ReadOnly = true;
Column1.Width = 150;
Column1.Width = 220;
//
// tabPage3
//
@@ -552,29 +604,29 @@
//
// uiDataGridView3
//
dataGridViewCellStyle19.BackColor = Color.FromArgb(240, 248, 255);
uiDataGridView3.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle19;
dataGridViewCellStyle30.BackColor = Color.FromArgb(240, 248, 255);
uiDataGridView3.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle30;
uiDataGridView3.BackgroundColor = Color.White;
uiDataGridView3.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
dataGridViewCellStyle20.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle20.BackColor = Color.FromArgb(52, 152, 219);
dataGridViewCellStyle20.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewCellStyle20.ForeColor = Color.White;
dataGridViewCellStyle20.SelectionBackColor = Color.FromArgb(52, 152, 219);
dataGridViewCellStyle20.SelectionForeColor = Color.White;
dataGridViewCellStyle20.WrapMode = DataGridViewTriState.True;
uiDataGridView3.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle20;
dataGridViewCellStyle31.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle31.BackColor = Color.FromArgb(52, 152, 219);
dataGridViewCellStyle31.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewCellStyle31.ForeColor = Color.White;
dataGridViewCellStyle31.SelectionBackColor = Color.FromArgb(52, 152, 219);
dataGridViewCellStyle31.SelectionForeColor = Color.White;
dataGridViewCellStyle31.WrapMode = DataGridViewTriState.True;
uiDataGridView3.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle31;
uiDataGridView3.ColumnHeadersHeight = 42;
uiDataGridView3.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
uiDataGridView3.Columns.AddRange(new DataGridViewColumn[] { dataGridViewTextBoxColumn16, dataGridViewTextBoxColumn17, dataGridViewTextBoxColumn18, dataGridViewTextBoxColumn20, dataGridViewTextBoxColumn21, dataGridViewTextBoxColumn22, dataGridViewTextBoxColumn23, Column2 });
dataGridViewCellStyle21.Alignment = DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle21.BackColor = Color.White;
dataGridViewCellStyle21.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewCellStyle21.ForeColor = Color.FromArgb(48, 48, 48);
dataGridViewCellStyle21.SelectionBackColor = Color.FromArgb(240, 248, 255);
dataGridViewCellStyle21.SelectionForeColor = Color.FromArgb(48, 49, 51);
dataGridViewCellStyle21.WrapMode = DataGridViewTriState.False;
uiDataGridView3.DefaultCellStyle = dataGridViewCellStyle21;
dataGridViewCellStyle40.Alignment = DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle40.BackColor = Color.White;
dataGridViewCellStyle40.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewCellStyle40.ForeColor = Color.FromArgb(48, 48, 48);
dataGridViewCellStyle40.SelectionBackColor = Color.FromArgb(240, 248, 255);
dataGridViewCellStyle40.SelectionForeColor = Color.FromArgb(48, 49, 51);
dataGridViewCellStyle40.WrapMode = DataGridViewTriState.False;
uiDataGridView3.DefaultCellStyle = dataGridViewCellStyle40;
uiDataGridView3.Dock = DockStyle.Fill;
uiDataGridView3.EnableHeadersVisualStyles = false;
uiDataGridView3.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
@@ -582,18 +634,18 @@
uiDataGridView3.Location = new Point(0, 0);
uiDataGridView3.Name = "uiDataGridView3";
uiDataGridView3.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
dataGridViewCellStyle22.Alignment = DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle22.BackColor = Color.FromArgb(240, 248, 255);
dataGridViewCellStyle22.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewCellStyle22.ForeColor = Color.FromArgb(48, 49, 51);
dataGridViewCellStyle22.SelectionBackColor = Color.FromArgb(52, 152, 219);
dataGridViewCellStyle22.SelectionForeColor = Color.White;
dataGridViewCellStyle22.WrapMode = DataGridViewTriState.True;
uiDataGridView3.RowHeadersDefaultCellStyle = dataGridViewCellStyle22;
dataGridViewCellStyle41.Alignment = DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle41.BackColor = Color.FromArgb(240, 248, 255);
dataGridViewCellStyle41.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewCellStyle41.ForeColor = Color.FromArgb(48, 49, 51);
dataGridViewCellStyle41.SelectionBackColor = Color.FromArgb(52, 152, 219);
dataGridViewCellStyle41.SelectionForeColor = Color.White;
dataGridViewCellStyle41.WrapMode = DataGridViewTriState.True;
uiDataGridView3.RowHeadersDefaultCellStyle = dataGridViewCellStyle41;
uiDataGridView3.RowHeadersWidth = 62;
dataGridViewCellStyle23.BackColor = Color.White;
dataGridViewCellStyle23.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
uiDataGridView3.RowsDefaultCellStyle = dataGridViewCellStyle23;
dataGridViewCellStyle42.BackColor = Color.White;
dataGridViewCellStyle42.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
uiDataGridView3.RowsDefaultCellStyle = dataGridViewCellStyle42;
uiDataGridView3.SelectedIndex = -1;
uiDataGridView3.Size = new Size(1375, 802);
uiDataGridView3.StripeOddColor = Color.FromArgb(240, 248, 255);
@@ -602,6 +654,9 @@
// dataGridViewTextBoxColumn16
//
dataGridViewTextBoxColumn16.DataPropertyName = "Id3";
dataGridViewCellStyle32.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle32.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewTextBoxColumn16.DefaultCellStyle = dataGridViewCellStyle32;
dataGridViewTextBoxColumn16.HeaderText = "测试项/样品";
dataGridViewTextBoxColumn16.MinimumWidth = 8;
dataGridViewTextBoxColumn16.Name = "dataGridViewTextBoxColumn16";
@@ -611,6 +666,9 @@
// dataGridViewTextBoxColumn17
//
dataGridViewTextBoxColumn17.DataPropertyName = "O23";
dataGridViewCellStyle33.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle33.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewTextBoxColumn17.DefaultCellStyle = dataGridViewCellStyle33;
dataGridViewTextBoxColumn17.HeaderText = "氧浓度(%";
dataGridViewTextBoxColumn17.MinimumWidth = 8;
dataGridViewTextBoxColumn17.Name = "dataGridViewTextBoxColumn17";
@@ -620,6 +678,9 @@
// dataGridViewTextBoxColumn18
//
dataGridViewTextBoxColumn18.DataPropertyName = "result3";
dataGridViewCellStyle34.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle34.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewTextBoxColumn18.DefaultCellStyle = dataGridViewCellStyle34;
dataGridViewTextBoxColumn18.HeaderText = "分类结果";
dataGridViewTextBoxColumn18.MinimumWidth = 8;
dataGridViewTextBoxColumn18.Name = "dataGridViewTextBoxColumn18";
@@ -629,6 +690,9 @@
// dataGridViewTextBoxColumn20
//
dataGridViewTextBoxColumn20.DataPropertyName = "yuyan3";
dataGridViewCellStyle35.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle35.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewTextBoxColumn20.DefaultCellStyle = dataGridViewCellStyle35;
dataGridViewTextBoxColumn20.HeaderText = "余焰时间(s)";
dataGridViewTextBoxColumn20.MinimumWidth = 8;
dataGridViewTextBoxColumn20.Name = "dataGridViewTextBoxColumn20";
@@ -638,6 +702,9 @@
// dataGridViewTextBoxColumn21
//
dataGridViewTextBoxColumn21.DataPropertyName = "yuhui3";
dataGridViewCellStyle36.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle36.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewTextBoxColumn21.DefaultCellStyle = dataGridViewCellStyle36;
dataGridViewTextBoxColumn21.HeaderText = "余辉时间(s)";
dataGridViewTextBoxColumn21.MinimumWidth = 8;
dataGridViewTextBoxColumn21.Name = "dataGridViewTextBoxColumn21";
@@ -647,6 +714,9 @@
// dataGridViewTextBoxColumn22
//
dataGridViewTextBoxColumn22.DataPropertyName = "Iszixi3";
dataGridViewCellStyle37.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle37.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewTextBoxColumn22.DefaultCellStyle = dataGridViewCellStyle37;
dataGridViewTextBoxColumn22.HeaderText = "是否自熄";
dataGridViewTextBoxColumn22.MinimumWidth = 8;
dataGridViewTextBoxColumn22.Name = "dataGridViewTextBoxColumn22";
@@ -656,6 +726,9 @@
// dataGridViewTextBoxColumn23
//
dataGridViewTextBoxColumn23.DataPropertyName = "Isdianhuo3";
dataGridViewCellStyle38.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle38.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
dataGridViewTextBoxColumn23.DefaultCellStyle = dataGridViewCellStyle38;
dataGridViewTextBoxColumn23.HeaderText = "是否点火";
dataGridViewTextBoxColumn23.MinimumWidth = 8;
dataGridViewTextBoxColumn23.Name = "dataGridViewTextBoxColumn23";
@@ -665,11 +738,14 @@
// Column2
//
Column2.DataPropertyName = "Testtime3";
dataGridViewCellStyle39.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle39.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
Column2.DefaultCellStyle = dataGridViewCellStyle39;
Column2.HeaderText = "测试时间";
Column2.MinimumWidth = 8;
Column2.Name = "Column2";
Column2.ReadOnly = true;
Column2.Width = 150;
Column2.Width = 220;
//
// uiPanel1
//
@@ -1067,6 +1143,10 @@
private DataGridViewTextBoxColumn dataGridViewTextBoxColumn15;
private Sunny.UI.UIDataGridView uiDataGridView2;
private Sunny.UI.UIDataGridView uiDataGridView3;
private Sunny.UI.UIComboBox uiComboBox1;
private Sunny.UI.UIComboBox uiComboBox2;
private Sunny.UI.UIButton uiButton4;
private Sunny.UI.UIComboBox uiComboBox3;
private DataGridViewTextBoxColumn id;
private DataGridViewTextBoxColumn O2;
private DataGridViewTextBoxColumn result;
@@ -1086,7 +1166,6 @@
private DataGridViewTextBoxColumn dataGridViewTextBoxColumn8;
private DataGridViewTextBoxColumn Column9;
private DataGridViewTextBoxColumn Column1;
private Sunny.UI.UIComboBox uiComboBox1;
private DataGridViewTextBoxColumn dataGridViewTextBoxColumn16;
private DataGridViewTextBoxColumn dataGridViewTextBoxColumn17;
private DataGridViewTextBoxColumn dataGridViewTextBoxColumn18;
@@ -1095,8 +1174,5 @@
private DataGridViewTextBoxColumn dataGridViewTextBoxColumn22;
private DataGridViewTextBoxColumn dataGridViewTextBoxColumn23;
private DataGridViewTextBoxColumn Column2;
private Sunny.UI.UIComboBox uiComboBox2;
private Sunny.UI.UIButton uiButton4;
private Sunny.UI.UIComboBox uiComboBox3;
}
}

View File

@@ -1,4 +1,5 @@
using OfficeOpenXml;
using Modbus.Device;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using Sunny.UI;
using System;
@@ -7,9 +8,11 @@ using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using .Data;
using ;
@@ -17,6 +20,11 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
{
public partial class ReportForm : UIForm
{
#region
private TcpClient _tcpClient => ModbusResourceManager.Instance.TcpClient;
private IModbusMaster _modbusMaster => ModbusResourceManager.Instance.ModbusMaster;
#endregion
ConductivityRepository conductivityRepository;
public ReportForm()
{
@@ -44,6 +52,29 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
// 当子窗体关闭时,显示主窗体
Application.OpenForms["MainForm"]?.Show();
};
string plcIp = "192.168.1.10";
//string plcIp = "127.0.0.1";
bool initSuccess = Data.ModbusResourceManager.Instance.Init(plcIp, 502);
if (!initSuccess)
{
MessageBox.Show("连接Modbus服务器失败", "错误");
this.Close();
return;
}
// 检查连接状态
if (_tcpClient == null || !_tcpClient.Connected)
{
MessageBox.Show("Modbus连接异常", "错误");
this.Close();
return;
}
_modbusMaster?.WriteSingleRegister(1, 2, 0);
}
private void ReportForm_FormClosed(object sender, FormClosedEventArgs e)

View File

@@ -32,6 +32,7 @@
uiTableLayoutPanel2 = new Sunny.UI.UITableLayoutPanel();
uiPanel3 = new Sunny.UI.UIPanel();
uiGroupBox2 = new Sunny.UI.UIGroupBox();
uiButton14 = new Sunny.UI.UIButton();
uiButton8 = new Sunny.UI.UIButton();
uiLabel25 = new Sunny.UI.UILabel();
uiLabel26 = new Sunny.UI.UILabel();
@@ -99,7 +100,6 @@
uiLabel20 = new Sunny.UI.UILabel();
uiComboBox3 = new Sunny.UI.UIComboBox();
uiLabel17 = new Sunny.UI.UILabel();
uiButton14 = new Sunny.UI.UIButton();
uiTableLayoutPanel1.SuspendLayout();
uiTableLayoutPanel2.SuspendLayout();
uiPanel3.SuspendLayout();
@@ -202,6 +202,28 @@
uiGroupBox2.Text = "测试控制";
uiGroupBox2.TextAlignment = ContentAlignment.MiddleLeft;
//
// uiButton14
//
uiButton14.Cursor = Cursors.Hand;
uiButton14.FillColor = Color.FromArgb(241, 196, 15);
uiButton14.FillColor2 = Color.FromArgb(241, 196, 15);
uiButton14.FillHoverColor = Color.FromArgb(243, 156, 18);
uiButton14.FillPressColor = Color.FromArgb(243, 156, 18);
uiButton14.Font = new Font("微软雅黑", 13F, FontStyle.Bold, GraphicsUnit.Point, 134);
uiButton14.Location = new Point(697, 58);
uiButton14.MinimumSize = new Size(1, 1);
uiButton14.Name = "uiButton14";
uiButton14.Radius = 8;
uiButton14.RectColor = Color.FromArgb(241, 196, 15);
uiButton14.RectHoverColor = Color.FromArgb(243, 156, 18);
uiButton14.Size = new Size(180, 85);
uiButton14.Style = Sunny.UI.UIStyle.Custom;
uiButton14.StyleCustomMode = true;
uiButton14.TabIndex = 25;
uiButton14.Text = "💡 灯开关";
uiButton14.TipsFont = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
uiButton14.Click += uiButton14_Click;
//
// uiButton8
//
uiButton8.Cursor = Cursors.Hand;
@@ -1365,28 +1387,6 @@
uiLabel17.Text = "测试样品项:";
uiLabel17.TextAlign = ContentAlignment.MiddleLeft;
//
// uiButton14
//
uiButton14.Cursor = Cursors.Hand;
uiButton14.FillColor = Color.FromArgb(241, 196, 15);
uiButton14.FillColor2 = Color.FromArgb(241, 196, 15);
uiButton14.FillHoverColor = Color.FromArgb(243, 156, 18);
uiButton14.FillPressColor = Color.FromArgb(243, 156, 18);
uiButton14.Font = new Font("微软雅黑", 13F, FontStyle.Bold, GraphicsUnit.Point, 134);
uiButton14.Location = new Point(697, 58);
uiButton14.MinimumSize = new Size(1, 1);
uiButton14.Name = "uiButton14";
uiButton14.Radius = 8;
uiButton14.RectColor = Color.FromArgb(241, 196, 15);
uiButton14.RectHoverColor = Color.FromArgb(243, 156, 18);
uiButton14.Size = new Size(180, 85);
uiButton14.Style = Sunny.UI.UIStyle.Custom;
uiButton14.StyleCustomMode = true;
uiButton14.TabIndex = 25;
uiButton14.Text = "💡 灯开关";
uiButton14.TipsFont = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
uiButton14.Click += uiButton14_Click;
//
// SecondaryIgnitionForm
//
AutoScaleMode = AutoScaleMode.None;
@@ -1402,6 +1402,7 @@
FormClosing += SecondaryIgnitionForm_FormClosing;
FormClosed += SecondaryIgnitionForm_FormClosed;
Load += SecondaryIgnitionForm_Load;
Shown += SecondaryIgnitionForm_Shown;
uiTableLayoutPanel1.ResumeLayout(false);
uiTableLayoutPanel2.ResumeLayout(false);
uiPanel3.ResumeLayout(false);

View File

@@ -221,6 +221,9 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
string currentTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
if (!this.IsHandleCreated)
return;
// 跨线程更新UI异步方法中仍需检查Invoke避免跨线程异常
if (uiLabel25.InvokeRequired)
{
@@ -257,37 +260,68 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
{
bool currentRunStatus = registers2[0];
RunStatus = currentRunStatus;
// 添加调试日志
Debug.WriteLine($"读取状态: address=301, value={currentRunStatus}, last={_lastRunStatus}, reported={_isReported}");
if (!this.IsHandleCreated)
return;
this.Invoke(new Action(() =>
{
uiLabel23.Text = currentRunStatus ? "运行中" : "空闲中";
}));
// ========== 关键修改1移除重复的插入逻辑只保留一段 ==========
// 仅在「运行→停止」且未上报过的情况下执行一次插入
if (_lastRunStatus && !currentRunStatus && !_isReported)
// ========== 关键修复:改进状态机逻辑 ==========
// 检测到「运行→停止」的变化
if (_lastRunStatus && !currentRunStatus)
{
// 添加延迟确保数据稳定
Debug.WriteLine($"检测到运行停止:{_lastRunStatus} → {currentRunStatus}");
// 延迟确保数据稳定
await Task.Delay(500);
// 加锁防止异步并发重复执行
await _asyncLock.WaitAsync();
try
// 只有在没有上报过时才执行插入
if (!_isReported)
{
// 二次校验,防止锁等待期间状态已变更
if (!_isReported)
Debug.WriteLine("尝试执行InsertReportAsync...");
await _asyncLock.WaitAsync();
try
{
var model = await InsertReportAsync();
if (model != null && !string.IsNullOrEmpty(model.Id3))
// 二次校验(在锁内)
if (!_isReported)
{
conductivityRepository.InsertReportItems(model);
_isReported = true; // 标记已上报
Debug.WriteLine($"报表插入成功:样品{model.sampleType3}, 分类{model.result3}");
var model = await InsertReportAsync();
if (model != null && !string.IsNullOrEmpty(model.Id3))
{
conductivityRepository.InsertReportItems(model);
_isReported = true; // 标记已上报
Debug.WriteLine($"报表插入成功:样品{model.sampleType3}, 分类{model.result3}");
}
else
{
Debug.WriteLine("InsertReportAsync返回无效结果");
}
}
}
finally
{
_asyncLock.Release();
}
}
finally
else
{
_asyncLock.Release(); // 释放锁
Debug.WriteLine("已上报过,跳过插入");
}
}
// 检测到「停止→运行」的变化,重置标记
else if (!_lastRunStatus && currentRunStatus)
{
_isReported = false;
_isCurrentRecordAdded = false;
Debug.WriteLine("设备开始运行,重置上报标记");
}
_lastRunStatus = currentRunStatus;
}
@@ -297,7 +331,6 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
MessageBox.Show(ex.Message);
Debug.WriteLine($"读取状态失败: {ex.Message}");
}
}
public async Task<bool[]> ReadModbusCoilAsync(ushort registerAddress, ushort readCount)
@@ -312,452 +345,130 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
List<SecondaryIgnitionModel> reportList = new List<SecondaryIgnitionModel>();
private string classify = null;
private float yy = 0;
private float yh = 0;
private bool iszixi = false;
private bool isdianhuo = false;
//private string classify = null;
//private float yy = 0;
//private float yh = 0;
//private bool iszixi = false;
//private bool isdianhuo = false;
private bool _isCurrentRecordAdded = false;//重复添加标记
private async Task<SecondaryIgnitionModel> InsertReportAsync()
{
if (_isReported) return new SecondaryIgnitionModel();
if (!_isReported)
Debug.WriteLine("进入InsertReportAsync方法");
// 先检查是否已上报
if (_isReported)
{
if (uiComboBox2.Text != null && uiComboBox2.Text.Trim() == "样品1")
Debug.WriteLine("已上报过,返回空模型");
return new SecondaryIgnitionModel();
}
try
{
// 获取UI数据需要在UI线程上执行
string sampleText = "";
string o2Text = "";
string idText = "";
this.Invoke(new Action(() =>
{
bool[] value1 = await ReadModbusCoilAsync(230, 1);
bool[] value2 = await ReadModbusCoilAsync(231, 1);
bool[] value3 = await ReadModbusCoilAsync(232, 1);
bool[] value4 = await ReadModbusCoilAsync(233, 1);
sampleText = uiComboBox2?.Text?.Trim() ?? "";
o2Text = uiComboBox1?.Text ?? "";
idText = uiComboBox2?.Text ?? "";
}));
if (value1 != null && value1.Length > 0 && value1[0] && value3 != null && value3.Length > 0 && value3[0])
{
classify = "SI3";//分类
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 330, 4);
//if (yhlocation != null && yhlocation.Length >= 3)
//{
yy = float.Parse(uiLabel8.Text);//余焰
yh = float.Parse(uiLabel12.Text);
//}
if (value2[0])
{
iszixi = true; //自熄
}
else if (value3[0])
{
iszixi = false;
}
if (value1[0])
{
isdianhuo = true;//点火
}
else if (value4[0])
{
isdianhuo = false;
}
}
else if (value1 != null && value1.Length > 0 && value1[0] && value2 != null && value2.Length > 0 && value2[0])
{
classify = "SI2";//分类
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 330, 4);
//if (yhlocation != null && yhlocation.Length >= 3)
//{
yy = float.Parse(uiLabel8.Text);//余焰
yh = float.Parse(uiLabel12.Text);
//}
if (value2[0])
{
iszixi = true; //自熄
}
else if (value3[0])
{
iszixi = false;
}
if (value1[0])
{
isdianhuo = true;//点火
}
else if (value4[0])
{
isdianhuo = false;
}
}
else if (value4 != null && value4.Length > 0 && value4[0])
{
classify = "SI1";//分类
iszixi = false;
isdianhuo = false;
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 330, 4);
//if (yhlocation != null && yhlocation.Length >= 3)
//{
yy = float.Parse(uiLabel8.Text);//余焰
yh = float.Parse(uiLabel12.Text);
//}
}
}
if (uiComboBox2.Text != null && uiComboBox2.Text.Trim() == "样品2")
if (string.IsNullOrEmpty(sampleText))
{
bool[] value1 = await ReadModbusCoilAsync(230, 1);
bool[] value2 = await ReadModbusCoilAsync(231, 1);
bool[] value3 = await ReadModbusCoilAsync(232, 1);
bool[] value4 = await ReadModbusCoilAsync(233, 1);
if (value1 != null && value1.Length > 0 && value1[0] && value3 != null && value3.Length > 0 && value3[0])
{
classify = "SI3";//分类
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 330, 4);
//if (yhlocation != null && yhlocation.Length >= 3)
//{
yy = float.Parse(uiLabel8.Text);//余焰
yh = float.Parse(uiLabel12.Text);
//}
if (value2[0])
{
iszixi = true; //自熄
}
else if (value3[0])
{
iszixi = false;
}
if (value1[0])
{
isdianhuo = true;//点火
}
else if (value4[0])
{
isdianhuo = false;
}
}
else if (value1 != null && value1.Length > 0 && value1[0] && value2 != null && value2.Length > 0 && value2[0])
{
classify = "SI2";//分类
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 330, 4);
//if (yhlocation != null && yhlocation.Length >= 3)
//{
yy = float.Parse(uiLabel8.Text);//余焰
yh = float.Parse(uiLabel12.Text);
//}
if (value2[0])
{
iszixi = true; //自熄
}
else if (value3[0])
{
iszixi = false;
}
if (value1[0])
{
isdianhuo = true;//点火
}
else if (value4[0])
{
isdianhuo = false;
}
}
else if (value4 != null && value4.Length > 0 && value4[0])
{
classify = "SI1";//分类
iszixi = false;
isdianhuo = false;
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 330, 4);
//if (yhlocation != null && yhlocation.Length >= 3)
//{
yy = float.Parse(uiLabel8.Text);//余焰
yh = float.Parse(uiLabel12.Text);
//}
}
}
if (uiComboBox2.Text != null && uiComboBox2.Text.Trim() == "样品3")
{
bool[] value1 = await ReadModbusCoilAsync(230, 1);
bool[] value2 = await ReadModbusCoilAsync(231, 1);
bool[] value3 = await ReadModbusCoilAsync(232, 1);
bool[] value4 = await ReadModbusCoilAsync(233, 1);
if (value1 != null && value1.Length > 0 && value1[0] && value3 != null && value3.Length > 0 && value3[0])
{
classify = "SI3";//分类
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 330, 4);
//if (yhlocation != null && yhlocation.Length >= 3)
//{
yy = float.Parse(uiLabel8.Text);//余焰
yh = float.Parse(uiLabel12.Text);
//}
if (value2[0])
{
iszixi = true; //自熄
}
else if (value3[0])
{
iszixi = false;
}
if (value1[0])
{
isdianhuo = true;//点火
}
else if (value4[0])
{
isdianhuo = false;
}
}
else if (value1 != null && value1.Length > 0 && value1[0] && value2 != null && value2.Length > 0 && value2[0])
{
classify = "SI2";//分类
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 330, 4);
//if (yhlocation != null && yhlocation.Length >= 3)
//{
yy = float.Parse(uiLabel8.Text);//余焰
yh = float.Parse(uiLabel12.Text);
//}
if (value2[0])
{
iszixi = true; //自熄
}
else if (value3[0])
{
iszixi = false;
}
if (value1[0])
{
isdianhuo = true;//点火
}
else if (value4[0])
{
isdianhuo = false;
}
}
else if (value4 != null && value4.Length > 0 && value4[0])
{
classify = "SI1";//分类
iszixi = false;
isdianhuo = false;
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 330, 4);
//if (yhlocation != null && yhlocation.Length >= 3)
//{
yy = float.Parse(uiLabel8.Text);//余焰
yh = float.Parse(uiLabel12.Text);
//}
}
}
if (uiComboBox2.Text != null && uiComboBox2.Text.Trim() == "样品4")
{
bool[] value1 = await ReadModbusCoilAsync(230, 1);
bool[] value2 = await ReadModbusCoilAsync(231, 1);
bool[] value3 = await ReadModbusCoilAsync(232, 1);
bool[] value4 = await ReadModbusCoilAsync(233, 1);
if (value1 != null && value1.Length > 0 && value1[0] && value3 != null && value3.Length > 0 && value3[0])
{
classify = "SI3";//分类
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 330, 4);
//if (yhlocation != null && yhlocation.Length >= 3)
//{
yy = float.Parse(uiLabel8.Text);//余焰
yh = float.Parse(uiLabel12.Text);
//}
if (value2[0])
{
iszixi = true; //自熄
}
else if (value3[0])
{
iszixi = false;
}
if (value1[0])
{
isdianhuo = true;//点火
}
else if (value4[0])
{
isdianhuo = false;
}
}
else if (value1 != null && value1.Length > 0 && value1[0] && value2 != null && value2.Length > 0 && value2[0])
{
classify = "SI2";//分类
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 330, 4);
//if (yhlocation != null && yhlocation.Length >= 3)
//{
yy = float.Parse(uiLabel8.Text);//余焰
yh = float.Parse(uiLabel12.Text);
//}
if (value2[0])
{
iszixi = true; //自熄
}
else if (value3[0])
{
iszixi = false;
}
if (value1[0])
{
isdianhuo = true;//点火
}
else if (value4[0])
{
isdianhuo = false;
}
}
else if (value4 != null && value4.Length > 0 && value4[0])
{
classify = "SI1";//分类
iszixi = false;
isdianhuo = false;
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 330, 4);
//if (yhlocation != null && yhlocation.Length >= 3)
//{
yy = float.Parse(uiLabel8.Text);//余焰
yh = float.Parse(uiLabel12.Text);
//}
}
}
if (uiComboBox2.Text != null && uiComboBox2.Text.Trim() == "样品5")
{
bool[] value1 = await ReadModbusCoilAsync(230, 1);
bool[] value2 = await ReadModbusCoilAsync(231, 1);
bool[] value3 = await ReadModbusCoilAsync(232, 1);
bool[] value4 = await ReadModbusCoilAsync(233, 1);
if (value1 != null && value1.Length > 0 && value1[0] && value3 != null && value3.Length > 0 && value3[0])
{
classify = "SI3";//分类
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 330, 4);
//if (yhlocation != null && yhlocation.Length >= 3)
//{
yy = float.Parse(uiLabel8.Text);//余焰
yh = float.Parse(uiLabel12.Text);
//}
if (value2[0])
{
iszixi = true; //自熄
}
else if (value3[0])
{
iszixi = false;
}
if (value1[0])
{
isdianhuo = true;//点火
}
else if (value4[0])
{
isdianhuo = false;
}
}
else if (value1 != null && value1.Length > 0 && value1[0] && value2 != null && value2.Length > 0 && value2[0])
{
classify = "SI2";//分类
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 330, 4);
//if (yhlocation != null && yhlocation.Length >= 3)
//{
yy = float.Parse(uiLabel8.Text);//余焰
yh = float.Parse(uiLabel12.Text);
//}
if (value2[0])
{
iszixi = true; //自熄
}
else if (value3[0])
{
iszixi = false;
}
if (value1[0])
{
isdianhuo = true;//点火
}
else if (value4[0])
{
isdianhuo = false;
}
}
else if (value4 != null && value4.Length > 0 && value4[0])
{
classify = "SI1";//分类
iszixi = false;
isdianhuo = false;
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 330, 4);
//if (yhlocation != null && yhlocation.Length >= 3)
//{
yy = float.Parse(uiLabel8.Text);//余焰
yh = float.Parse(uiLabel12.Text);
//}
}
}
try
{
string selectedO2Text = uiComboBox1.Text;
string id = uiComboBox2.Text;
var model = new SecondaryIgnitionModel
{
Id3 = id,
Iszixi3 = iszixi,
Isdianhuo3 = isdianhuo,
O23 = selectedO2Text,
result3 = classify,
sampleType3 = uiComboBox2.Text.Contains("1") ? 1
: uiComboBox2.Text.Contains("2") ? 2
: uiComboBox2.Text.Contains("3") ? 3
: uiComboBox2.Text.Contains("4") ? 4
: uiComboBox2.Text.Contains("5") ? 5 : 0,
yuhui3 = yh,
yuyan3 = yy,
Testtime3 = DateTime.Now
};
reportList.Add(model);
_isCurrentRecordAdded = true; // 标记为已添加,避免重复
await Task.Delay(100);
return model;
}
catch (Exception ex)
{
Debug.WriteLine($"报表插入失败: {ex.Message}");
Debug.WriteLine("样品选择为空");
return new SecondaryIgnitionModel();
}
// 读取线圈状态
bool[] value1 = await ReadModbusCoilAsync(230, 1);
bool[] value2 = await ReadModbusCoilAsync(231, 1);
bool[] value3 = await ReadModbusCoilAsync(232, 1);
bool[] value4 = await ReadModbusCoilAsync(233, 1);
// 检查读取结果
if (value1 == null || value2 == null || value3 == null || value4 == null)
{
Debug.WriteLine("读取线圈状态失败");
return new SecondaryIgnitionModel();
}
// 分类逻辑(可以简化)
string classify = null;
bool iszixi = false;
bool isdianhuo = false;
// 判断分类
if (value1[0] && value3[0])
{
classify = "SI3";
iszixi = false; // value3[0]为true时不是自熄
isdianhuo = true; // value1[0]为true时是点火
}
else if (value1[0] && value2[0])
{
classify = "SI2";
iszixi = true; // value2[0]为true时是自熄
isdianhuo = true;
}
else if (value4[0])
{
classify = "SI1";
iszixi = false;
isdianhuo = false;
}
if (classify == null)
{
Debug.WriteLine("未检测到有效分类");
return new SecondaryIgnitionModel();
}
// 读取余焰和余辉
float yy = 0, yh = 0;
this.Invoke(new Action(() =>
{
if (float.TryParse(uiLabel8.Text, out float yyValue))
yy = yyValue;
if (float.TryParse(uiLabel12.Text, out float yhValue))
yh = yhValue;
}));
// 解析样品类型
int sampleType = 0;
if (sampleText.Contains("1")) sampleType = 1;
else if (sampleText.Contains("2")) sampleType = 2;
else if (sampleText.Contains("3")) sampleType = 3;
else if (sampleText.Contains("4")) sampleType = 4;
else if (sampleText.Contains("5")) sampleType = 5;
// 创建模型
var model = new SecondaryIgnitionModel
{
Id3 = idText,
Iszixi3 = iszixi,
Isdianhuo3 = isdianhuo,
O23 = o2Text,
result3 = classify,
sampleType3 = sampleType,
yuhui3 = yh,
yuyan3 = yy,
Testtime3 = DateTime.Now
};
reportList.Add(model);
_isCurrentRecordAdded = true;
Debug.WriteLine($"创建成功: 样品{sampleType}, 分类{classify}, 余焰{yy}, 余辉{yh}");
return model;
}
else
catch (Exception ex)
{
_isCurrentRecordAdded = false;
Debug.WriteLine($"InsertReportAsync异常: {ex.Message}");
return new SecondaryIgnitionModel();
}
}
@@ -782,17 +493,15 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
}
ma = new Function(_modbusMaster);
_readtimer = InitTimer();
if (_modbusMaster != null)
{
_readtimer.Start();
}
_modbusMaster?.WriteSingleRegister(1, 2, 3);
this.FormClosed += (s, args) =>
{
// 当子窗体关闭时,显示主窗体
Application.OpenForms["MainForm"]?.Show();
};
uiComboBox1.SelectedIndex = 0;
}
private void InitComboBoxPattern()
@@ -808,7 +517,7 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
"无氧环境/灭火 (0%)"
};
uiComboBox1.Items.AddRange(options);
uiComboBox1.SelectedIndex = 0;
}
private void InitComboBox2Pattern()
{
@@ -856,7 +565,7 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
}
}
#region
private void uiButton4_Click(object sender, EventArgs e)
{
ma?.BtnClickFunctionForNew(Function.ButtonType., 224);//余辉开始
@@ -892,11 +601,20 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
ma?.BtnClickFunctionForNew(Function.ButtonType., 304);//手动停止
}
bool isbt3on=false;
private void uiButton3_Click(object sender, EventArgs e)
{
ToggleButtonWithText(uiButton3, ref isbt3on, "灭火中", "灭火");
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
private void uiButton7_Click(object sender, EventArgs e)
{
string message = "帮助一:请目测判断丝光棉是否燃尽,如燃尽请按下“丝光棉燃尽”按钮;\n帮助二请目测判断样品是否燃尽如燃尽请按下“火焰未自熄”按钮如未燃尽请按下“火焰自熄”按钮\n帮助三请目测是否有余辉有余辉请立即点击“余辉开始”按钮余辉时间开始计时余辉结束请立即点击“余辉结束”按钮余辉时间计时结束。";
@@ -914,10 +632,32 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
TaskDialog.ShowDialog(this, page);
}
private void uiComboBox1_SelectedIndexChanged(object sender, EventArgs e)
private async void uiComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
ushort selectedIndex = ushort.Parse(uiComboBox1.SelectedIndex.ToString());
_modbusMaster?.WriteSingleRegister(1, 10, selectedIndex);//下拉框
//ushort selectedIndex = ushort.Parse(uiComboBox1.SelectedIndex.ToString());
//_modbusMaster?.WriteSingleRegister(1, 10, selectedIndex);//下拉框
// 1. 检查是否有选中项
//if (uiComboBox1.SelectedIndex == -1)
// return;
//// 2. 检查 _modbusMaster 是否有效、连接是否正常
//if (_modbusMaster == null || _tcpClient == null || !_tcpClient.Connected)
//{
// //MessageBox.Show("Modbus未连接无法写入数据");
// return;
//}
try
{
ushort selectedIndex = (ushort)uiComboBox1.SelectedIndex;
// 3. 使用异步方法(如果 Modbus 库支持避免UI线程阻塞
await _modbusMaster.WriteSingleRegisterAsync(1, 10, selectedIndex);
}
catch (Exception ex)
{
MessageBox.Show($"写入寄存器失败:{ex.Message}");
Debug.WriteLine($"WriteSingleRegister错误{ex}");
}
}
@@ -933,8 +673,17 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
private void uiButton8_Click(object sender, EventArgs e)
{
AutoCameraForm cameraForm = new AutoCameraForm(() => RunStatus);
this.SwitchToForm(() => cameraForm);
//AutoCameraForm cameraForm = new AutoCameraForm(() => RunStatus);
//this.SwitchToForm(() => cameraForm);
var cameraForm = new AutoCameraForm(() => RunStatus);
// 设置窗体关闭时释放资源
cameraForm.FormClosed += (s, args) =>
{
cameraForm.Dispose();
};
cameraForm.Show();
}
private void SwitchToForm(Func<Form> formCreator)
{
@@ -1028,14 +777,28 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
}
}
bool isbt14on = false;
bool isbt9on = false;
private void uiButton9_Click(object sender, EventArgs e)
{
ToggleButtonWithText(uiButton9, ref isbt9on, "混氧中", "手动混氧");
ma?.BtnClickFunctionForNew(Function.ButtonType., 101);//混氧开关
}
private void uiButton14_Click(object sender, EventArgs e)
{
ToggleButtonWithText(uiButton14, ref isbt14on, "开灯中", "💡 灯开关");
ma?.BtnClickFunctionForNew(Function.ButtonType., 11);//灯开关
}
private void SecondaryIgnitionForm_Shown(object sender, EventArgs e)
{
if (_modbusMaster != null)
{
_readtimer = InitTimer();
_readtimer.Start();
}
}
}
}