1302 lines
57 KiB
C#
1302 lines
57 KiB
C#
using BasicDemo;
|
||
using Modbus.Device;
|
||
using MvCamCtrl.NET;
|
||
using Sunny.UI;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Diagnostics;
|
||
using System.Drawing;
|
||
using System.Globalization;
|
||
using System.Linq;
|
||
using System.Net.Sockets;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
using 外科辅料和患者防护罩激光抗性测试仪.Data;
|
||
using 外科辅料和患者防护罩激光抗性测试仪.Model;
|
||
using 材料热传导系数;
|
||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||
|
||
namespace 外科辅料和患者防护罩激光抗性测试仪
|
||
{
|
||
public partial class PrimaryIgnitionForm : UIForm
|
||
{
|
||
#region 私有字段
|
||
private TcpClient _tcpClient => ModbusResourceManager.Instance.TcpClient;
|
||
private IModbusMaster _modbusMaster => ModbusResourceManager.Instance.ModbusMaster;
|
||
#endregion
|
||
|
||
Function ma;
|
||
DataChange c = new DataChange();
|
||
|
||
private System.Windows.Forms.Timer _readtimer;
|
||
private readonly SemaphoreSlim _asyncLock = new SemaphoreSlim(1, 1);
|
||
|
||
public bool RunStatus = false;
|
||
|
||
ConductivityRepository conductivityRepository;
|
||
|
||
public PrimaryIgnitionForm()
|
||
{
|
||
InitializeComponent();
|
||
|
||
InitComboBoxPattern();
|
||
InitComboBox2Pattern();
|
||
|
||
InitTimer();
|
||
conductivityRepository = new ConductivityRepository();
|
||
}
|
||
|
||
private void PrimaryIgnitionForm_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);
|
||
|
||
_readtimer = InitTimer();
|
||
if (_modbusMaster != null)
|
||
{
|
||
_readtimer.Start();
|
||
}
|
||
|
||
this.FormClosed += (s, args) =>
|
||
{
|
||
// 当子窗体关闭时,显示主窗体
|
||
Application.OpenForms["MainForm"]?.Show();
|
||
};
|
||
|
||
|
||
//// ch: 初始化 SDK | en: Initialize SDK
|
||
//MyCamera.MV_CC_Initialize_NET();
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
private System.Windows.Forms.Timer InitTimer()
|
||
{
|
||
var timer = new System.Windows.Forms.Timer()
|
||
{
|
||
Interval = 500,
|
||
};
|
||
timer.Tick += async (s, e) =>
|
||
{
|
||
if (_modbusMaster != null)
|
||
{
|
||
try
|
||
{
|
||
await ReadDataAsync();
|
||
}
|
||
catch { }
|
||
}
|
||
};
|
||
return timer;
|
||
|
||
}
|
||
|
||
private async System.Threading.Tasks.Task ReadDataAsync()
|
||
{
|
||
try
|
||
{
|
||
if (_modbusMaster == null || _tcpClient == null || !_tcpClient.Connected)
|
||
{
|
||
return;
|
||
}
|
||
var tasks = new List<Task>
|
||
{
|
||
|
||
ReadFloatAsync(30,1,uiLabel10,"F0",""),//测试项
|
||
ReadFloatAsync(38,2,uiLabel7,"F1",""),//点火时间
|
||
ReadFloatAsync(44,2,uiLabel8,"F1",""),//余焰时间
|
||
ReadFloatAsync(48,2,uiLabel12,"F1",""),//余辉时间
|
||
ReadFloatAsync(34,1,uiLabel37,"F1",""),//总测试时间
|
||
|
||
ReadFloatAsync(1334,2,uiLabel48,"F1",""),//试验舱温度
|
||
ReadFloatAsync(1384,2,uiLabel40,"F1",""),//试验舱湿度
|
||
ReadFloatAsync(102,2,uiLabel36,"F1",""),//试验舱氧浓度
|
||
|
||
ReadLightStatusAsync(),
|
||
|
||
ReadtimeAsync(),//实时时间
|
||
|
||
ReadStartStatusAsync()
|
||
|
||
};
|
||
await Task.WhenAll(tasks);
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
//ShowError($"读取数据失败:{ex.Message}");
|
||
}
|
||
}
|
||
|
||
private async Task ReadFloatAsync(int address, int length, Label control, string format, string unit)
|
||
{
|
||
if (control == null) return;
|
||
|
||
try
|
||
{
|
||
var modbusMaster = _modbusMaster;
|
||
if (modbusMaster == null) return;
|
||
|
||
ushort[] registers = modbusMaster.ReadHoldingRegistersAsync(1, (ushort)address, (ushort)length).Result;
|
||
|
||
|
||
if (registers == null || registers.Length == 0)
|
||
{
|
||
System.Diagnostics.Debug.WriteLine($"读取地址{address}失败:未获取到有效寄存器数据");
|
||
return;
|
||
}
|
||
|
||
string text;
|
||
if (registers.Length >= 2 && length >= 2)
|
||
{
|
||
float value = c.UshortToFloat(registers[1], registers[0]);
|
||
text = $"{value.ToString(format, CultureInfo.InvariantCulture)}{unit}";
|
||
}
|
||
else if (registers.Length >= 1)
|
||
{
|
||
int value = registers[0];
|
||
text = $"{value.ToString(format, CultureInfo.InvariantCulture)}{unit}";
|
||
}
|
||
else
|
||
{
|
||
return;
|
||
}
|
||
|
||
UpdateControlText(control, text);
|
||
}
|
||
catch (OperationCanceledException)
|
||
{
|
||
return;
|
||
}
|
||
catch (Exception ex) when (ex is TimeoutException ||
|
||
ex is InvalidOperationException ||
|
||
ex.Message.Contains("Modbus", StringComparison.OrdinalIgnoreCase))
|
||
{
|
||
Debug.WriteLine($"Modbus通信错误 - 地址{address}: {ex.Message}");
|
||
UpdateControlText(control, "通信错误");
|
||
}
|
||
catch (ObjectDisposedException)
|
||
{
|
||
return;
|
||
}
|
||
}
|
||
private void UpdateControlText(Label control, string text)
|
||
{
|
||
if (control.IsDisposed) return;
|
||
|
||
if (control.InvokeRequired)
|
||
{
|
||
try
|
||
{
|
||
control.BeginInvoke(new Action(() =>
|
||
{
|
||
if (!control.IsDisposed)
|
||
control.Text = text;
|
||
}));
|
||
}
|
||
catch (ObjectDisposedException)
|
||
{
|
||
}
|
||
}
|
||
else
|
||
{
|
||
control.Text = text;
|
||
}
|
||
}
|
||
|
||
private async Task ReadLightStatusAsync()
|
||
{
|
||
try
|
||
{
|
||
bool[] registers1 = await _modbusMaster?.ReadCoilsAsync(1, 10, 1);
|
||
|
||
if (registers1 != null && registers1.Length >= 1)
|
||
{
|
||
bool value = registers1[0];
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
if (value)
|
||
{
|
||
uiLight1.State = UILightState.On;
|
||
|
||
|
||
}
|
||
else
|
||
{
|
||
uiLight1.State = UILightState.Off;
|
||
}
|
||
}));
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Debug.WriteLine($"读取状态失败: {ex.Message}");
|
||
}
|
||
}
|
||
|
||
private bool _lastRunStatus = false;
|
||
private bool _isReported = false;
|
||
|
||
private async Task ReadStartStatusAsync()
|
||
{
|
||
try
|
||
{
|
||
bool[] registers2 = _modbusMaster?.ReadCoilsAsync(1, 51, 1).Result;
|
||
|
||
|
||
if (registers2 != null && registers2.Length >= 1)
|
||
{
|
||
bool currentRunStatus = registers2[0]; // 当前运行状态
|
||
RunStatus = currentRunStatus;
|
||
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
uiLabel23.Text = currentRunStatus ? "运行中" : "空闲中";
|
||
}));
|
||
|
||
// ========== 关键修改1:移除重复的插入逻辑,只保留一段 ==========
|
||
// 仅在「运行→停止」且未上报过的情况下执行一次插入
|
||
if (_lastRunStatus && !currentRunStatus && !_isReported)
|
||
{
|
||
// 添加延迟确保数据稳定
|
||
await Task.Delay(500);
|
||
// 加锁防止异步并发重复执行
|
||
await _asyncLock.WaitAsync();
|
||
try
|
||
{
|
||
// 二次校验,防止锁等待期间状态已变更
|
||
if (!_isReported)
|
||
{
|
||
var model = await InsertReportAsync();
|
||
if (model != null && !string.IsNullOrEmpty(model.Id))
|
||
{
|
||
conductivityRepository.InsertReportItems(model);
|
||
_isReported = true; // 标记已上报
|
||
Debug.WriteLine($"报表插入成功:样品{model.sampleType}, 分类{model.result}");
|
||
}
|
||
}
|
||
}
|
||
finally
|
||
{
|
||
_asyncLock.Release(); // 释放锁
|
||
}
|
||
}
|
||
|
||
_lastRunStatus = currentRunStatus;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.Message);
|
||
Debug.WriteLine($"读取状态失败: {ex.Message}");
|
||
}
|
||
}
|
||
|
||
public async Task<bool[]> ReadModbusCoilAsync(ushort registerAddress, ushort readCount)
|
||
{
|
||
if (_modbusMaster == null) return null;
|
||
return await Task.Run(async () =>
|
||
{
|
||
return await _modbusMaster.ReadCoilsAsync(1, registerAddress, readCount);
|
||
});
|
||
}
|
||
|
||
|
||
|
||
List<PrimaryIgnitionModel> reportList = new List<PrimaryIgnitionModel>();
|
||
private string classify = null;
|
||
private float firetime = 0;
|
||
private float yy = 0;
|
||
private float yh = 0;
|
||
private string iszixi = string.Empty;
|
||
private double costtime = 0;
|
||
|
||
private bool _isCurrentRecordAdded = true;//重复添加标记
|
||
private async Task<PrimaryIgnitionModel> InsertReportAsync()
|
||
{
|
||
if (_isReported) return new PrimaryIgnitionModel();
|
||
if (!_isReported)
|
||
{
|
||
if (uiLabel10.Text != null && uiLabel10.Text.Trim() == "1")
|
||
{
|
||
bool[] value1 = await ReadModbusCoilAsync(110, 1);
|
||
bool[] value2 = await ReadModbusCoilAsync(120, 1);
|
||
bool[] value3 = await ReadModbusCoilAsync(130, 1);
|
||
bool[] value4 = await ReadModbusCoilAsync(140, 1);
|
||
|
||
if (value1 != null && value1.Length > 0 && value1[0])
|
||
{
|
||
classify = "I4x";//分类
|
||
|
||
firetime = float.Parse(uiLabel7.Text);
|
||
yy = float.Parse(uiLabel8.Text);
|
||
yh = float.Parse(uiLabel12.Text);
|
||
//ushort[] fire = _modbusMaster?.ReadHoldingRegisters(1, 190, 2);
|
||
//firetime = c.UshortToFloat(fire[1], fire[0]);//点火时间
|
||
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 300, 4);
|
||
//if (yhlocation != null && yhlocation.Length >= 3)
|
||
//{
|
||
// //yy = c.UshortToFloat(yhlocation[1], yhlocation[0]); //余焰
|
||
// yy = c.UshortToFloat(yhlocation[1], yhlocation[0]);
|
||
// yh = c.UshortToFloat(yhlocation[3], yhlocation[2]);//余辉
|
||
//}
|
||
bool[] fire1 = await ReadModbusCoilAsync(280, 1);
|
||
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];//总测试时长
|
||
}
|
||
|
||
else if (value2 != null && value2.Length > 0 && value2[0])
|
||
{
|
||
classify = "I3x";//分类
|
||
|
||
firetime = float.Parse(uiLabel7.Text);
|
||
yy = float.Parse(uiLabel8.Text);
|
||
yh = float.Parse(uiLabel12.Text);
|
||
//ushort[] fire = _modbusMaster?.ReadHoldingRegisters(1, 190, 2);
|
||
//firetime = c.UshortToFloat(fire[1], fire[0]);//点火时间
|
||
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 308, 4);
|
||
//if (yhlocation != null && yhlocation.Length >= 3)
|
||
//{
|
||
// yy = c.UshortToFloat(yhlocation[1], yhlocation[0]); //余焰
|
||
// yh = c.UshortToFloat(yhlocation[3], yhlocation[2]);//余辉
|
||
//}
|
||
bool[] fire1 = await ReadModbusCoilAsync(280, 1);
|
||
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
|
||
if (fire1 != null && fire1.Length > 0 && fire1[0])
|
||
{
|
||
iszixi = "true";
|
||
}
|
||
else if (fire2 != null && fire2.Length > 0 && fire2[0])
|
||
{
|
||
iszixi = "false";
|
||
}
|
||
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 90, 2);
|
||
costtime = time[0];//总测试时长
|
||
}
|
||
else if (value3 != null && value3.Length > 0 && value3[0])
|
||
{
|
||
classify = "I2x";//分类
|
||
|
||
firetime = float.Parse(uiLabel7.Text);
|
||
yy = float.Parse(uiLabel8.Text);
|
||
yh = float.Parse(uiLabel12.Text);
|
||
|
||
//ushort[] fire = _modbusMaster?.ReadHoldingRegisters(1, 190, 2);
|
||
//firetime = c.UshortToFloat(fire[1], fire[0]);//点火时间
|
||
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 304, 4);
|
||
//if (yhlocation != null && yhlocation.Length >= 3)
|
||
//{
|
||
// yy = c.UshortToFloat(yhlocation[1], yhlocation[0]); //余焰
|
||
// yh = c.UshortToFloat(yhlocation[3], yhlocation[2]);//余辉
|
||
//}
|
||
|
||
bool[] fire1 = await ReadModbusCoilAsync(280, 1);
|
||
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
|
||
if (fire1 != null && fire1.Length > 0 && fire1[0])
|
||
{
|
||
iszixi = "true";
|
||
}
|
||
else if (fire2 != null && fire2.Length > 0 && fire2[0])
|
||
{
|
||
iszixi = "false";
|
||
}
|
||
|
||
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 90, 2);
|
||
costtime = time[0];//总测试时长
|
||
}
|
||
else if (value4 != null && value4.Length > 0 && value4[0])
|
||
{
|
||
classify = "I1x";//分类
|
||
|
||
firetime = float.Parse(uiLabel7.Text);
|
||
yy = 0;
|
||
yh = float.Parse(uiLabel12.Text);
|
||
|
||
//ushort[] fire = _modbusMaster?.ReadHoldingRegisters(1, 190, 2);
|
||
//firetime = c.UshortToFloat(fire[1], fire[0]);//点火时间
|
||
//yy = 0;
|
||
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 314, 2);
|
||
//if (yhlocation != null && yhlocation.Length >= 1)
|
||
//{
|
||
// yh = c.UshortToFloat(yhlocation[1], yhlocation[0]);//余辉
|
||
//}
|
||
|
||
bool[] fire1 = await ReadModbusCoilAsync(280, 1);
|
||
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
|
||
if (fire1 != null && fire1.Length > 0 && fire1[0])
|
||
{
|
||
iszixi = "true";
|
||
}
|
||
else if (fire2 != null && fire2.Length > 0 && fire2[0])
|
||
{
|
||
iszixi = "false";
|
||
}
|
||
else
|
||
{
|
||
iszixi = "null";
|
||
}
|
||
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 90, 2);
|
||
costtime = time[0];//总测试时长
|
||
}
|
||
}
|
||
|
||
if (uiLabel10.Text != null && uiLabel10.Text.Trim() == "2")
|
||
{
|
||
|
||
bool[] value5 = await ReadModbusCoilAsync(111, 1);
|
||
bool[] value6 = await ReadModbusCoilAsync(121, 1);
|
||
bool[] value7 = await ReadModbusCoilAsync(131, 1);
|
||
bool[] value8 = await ReadModbusCoilAsync(141, 1);
|
||
|
||
if (value5 != null && value5.Length > 0 && value5[0])
|
||
{
|
||
classify = "I4x";//分类
|
||
|
||
firetime = float.Parse(uiLabel7.Text);
|
||
yy = float.Parse(uiLabel8.Text);
|
||
yh = float.Parse(uiLabel12.Text);
|
||
|
||
//ushort[] fire = _modbusMaster?.ReadHoldingRegisters(1, 192, 2);
|
||
//firetime = c.UshortToFloat(fire[1], fire[0]);//点火时间
|
||
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 300, 4);
|
||
//if (yhlocation != null && yhlocation.Length >= 3)
|
||
//{
|
||
// yy = c.UshortToFloat(yhlocation[1], yhlocation[0]); //余焰
|
||
// yh = c.UshortToFloat(yhlocation[3], yhlocation[2]);//余辉
|
||
//}
|
||
|
||
bool[] fire1 = await ReadModbusCoilAsync(280, 1);
|
||
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
|
||
if (fire1 != null && fire1.Length > 0 && fire1[0])
|
||
{
|
||
iszixi = "true";
|
||
}
|
||
else if (fire2 != null && fire2.Length > 0 && fire2[0])
|
||
{
|
||
iszixi = "false";
|
||
}
|
||
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 92, 2);
|
||
costtime = time[0];//总测试时长
|
||
}
|
||
else if (value6 != null && value6.Length > 0 && value6[0])
|
||
{
|
||
classify = "I3x";//分类
|
||
|
||
firetime = float.Parse(uiLabel7.Text);
|
||
yy = float.Parse(uiLabel8.Text);
|
||
yh = float.Parse(uiLabel12.Text);
|
||
|
||
//ushort[] fire = _modbusMaster?.ReadHoldingRegisters(1, 192, 2);
|
||
//firetime = c.UshortToFloat(fire[1], fire[0]);//点火时间
|
||
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 308, 4);
|
||
//if (yhlocation != null && yhlocation.Length >= 3)
|
||
//{
|
||
// yy = c.UshortToFloat(yhlocation[1], yhlocation[0]); //余焰
|
||
// yh = c.UshortToFloat(yhlocation[3], yhlocation[2]);//余辉
|
||
//}
|
||
|
||
bool[] fire1 = await ReadModbusCoilAsync(280, 1);
|
||
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
|
||
if (fire1 != null && fire1.Length > 0 && fire1[0])
|
||
{
|
||
iszixi = "true";
|
||
}
|
||
else if (fire2 != null && fire2.Length > 0 && fire2[0])
|
||
{
|
||
iszixi = "false";
|
||
}
|
||
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 92, 2);
|
||
costtime = time[0];//总测试时长
|
||
}
|
||
else if (value7 != null && value7.Length > 0 && value7[0])
|
||
{
|
||
classify = "I2x";//分类
|
||
|
||
firetime = float.Parse(uiLabel7.Text);
|
||
yy = float.Parse(uiLabel8.Text);
|
||
yh = float.Parse(uiLabel12.Text);
|
||
|
||
//ushort[] fire = _modbusMaster?.ReadHoldingRegisters(1, 192, 2);
|
||
//firetime = c.UshortToFloat(fire[1], fire[0]);//点火时间
|
||
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 304, 4);
|
||
//if (yhlocation != null && yhlocation.Length >= 3)
|
||
//{
|
||
// yy = c.UshortToFloat(yhlocation[1], yhlocation[0]); //余焰
|
||
// yh = c.UshortToFloat(yhlocation[3], yhlocation[2]);//余辉
|
||
//}
|
||
|
||
bool[] fire1 = await ReadModbusCoilAsync(280, 1);
|
||
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
|
||
if (fire1 != null && fire1.Length > 0 && fire1[0])
|
||
{
|
||
iszixi = "true";//自熄
|
||
}
|
||
else if (fire2 != null && fire2.Length > 0 && fire2[0])
|
||
{
|
||
iszixi = "false";
|
||
}
|
||
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 92, 2);
|
||
costtime = time[0];//总测试时长
|
||
}
|
||
else if (value8 != null && value8.Length > 0 && value8[0])
|
||
{
|
||
classify = "I1x";//分类
|
||
firetime = float.Parse(uiLabel7.Text);
|
||
yy = 0;
|
||
yh = float.Parse(uiLabel12.Text);
|
||
//ushort[] fire = _modbusMaster?.ReadHoldingRegisters(1, 192, 2);
|
||
//firetime = c.UshortToFloat(fire[1], fire[0]);//点火时间
|
||
//yy = 0;
|
||
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 314, 2);
|
||
//if (yhlocation != null && yhlocation.Length >= 1)
|
||
//{
|
||
// yh = c.UshortToFloat(yhlocation[1], yhlocation[0]);//余辉
|
||
//}
|
||
bool[] fire1 = await ReadModbusCoilAsync(280, 1);
|
||
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
|
||
if (fire1 != null && fire1.Length > 0 && fire1[0])
|
||
{
|
||
iszixi = "true";//自熄
|
||
}
|
||
else if (fire2 != null && fire2.Length > 0 && fire2[0])
|
||
{
|
||
iszixi = "false";
|
||
}
|
||
else
|
||
{
|
||
iszixi = "null";
|
||
}
|
||
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 92, 2);
|
||
costtime = time[0];//总测试时长
|
||
}
|
||
}
|
||
|
||
if (uiLabel10.Text != null && uiLabel10.Text.Trim() == "3")
|
||
{
|
||
|
||
bool[] value9 = await ReadModbusCoilAsync(112, 1);
|
||
bool[] value10 = await ReadModbusCoilAsync(122, 1);
|
||
bool[] value11 = await ReadModbusCoilAsync(132, 1);
|
||
bool[] value12 = await ReadModbusCoilAsync(142, 1);
|
||
|
||
if (value9 != null && value9.Length > 0 && value9[0])
|
||
{
|
||
classify = "I4x";//分类
|
||
firetime = float.Parse(uiLabel7.Text);
|
||
yy = float.Parse(uiLabel8.Text);
|
||
yh = float.Parse(uiLabel12.Text);
|
||
//ushort[] fire = _modbusMaster?.ReadHoldingRegisters(1, 194, 2);
|
||
//firetime = c.UshortToFloat(fire[1], fire[0]);//点火时间
|
||
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 300, 4);
|
||
//if (yhlocation != null && yhlocation.Length >= 3)
|
||
//{
|
||
// yy = c.UshortToFloat(yhlocation[1], yhlocation[0]); //余焰
|
||
// yh = c.UshortToFloat(yhlocation[3], yhlocation[2]);//余辉
|
||
//}
|
||
bool[] fire1 = await ReadModbusCoilAsync(280, 1);
|
||
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
|
||
if (fire1 != null && fire1.Length > 0 && fire1[0])
|
||
{
|
||
iszixi = "true";//自熄
|
||
}
|
||
else if (fire2 != null && fire2.Length > 0 && fire2[0])
|
||
{
|
||
iszixi = "false";
|
||
}
|
||
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 94, 2);
|
||
costtime = time[0];//总测试时长
|
||
}
|
||
else if (value10 != null && value10.Length > 0 && value10[0])
|
||
{
|
||
classify = "I3x";//分类
|
||
firetime = float.Parse(uiLabel7.Text);
|
||
yy = float.Parse(uiLabel8.Text);
|
||
yh = float.Parse(uiLabel12.Text);
|
||
//ushort[] fire = _modbusMaster?.ReadHoldingRegisters(1, 194, 2);
|
||
//firetime = c.UshortToFloat(fire[1], fire[0]);//点火时间
|
||
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 308, 4);
|
||
//if (yhlocation != null && yhlocation.Length >= 3)
|
||
//{
|
||
// yy = c.UshortToFloat(yhlocation[1], yhlocation[0]); //余焰
|
||
// yh = c.UshortToFloat(yhlocation[3], yhlocation[2]);//余辉
|
||
//}
|
||
|
||
bool[] fire1 = await ReadModbusCoilAsync(280, 1);
|
||
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
|
||
if (fire1 != null && fire1.Length > 0 && fire1[0])
|
||
{
|
||
iszixi = "true";//自熄
|
||
}
|
||
else if (fire2 != null && fire2.Length > 0 && fire2[0])
|
||
{
|
||
iszixi = "false";
|
||
}
|
||
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 94, 2);
|
||
costtime = time[0];//总测试时长
|
||
}
|
||
else if (value11 != null && value11.Length > 0 && value11[0])
|
||
{
|
||
classify = "I2x";//分类
|
||
firetime = float.Parse(uiLabel7.Text);
|
||
yy = float.Parse(uiLabel8.Text);
|
||
yh = float.Parse(uiLabel12.Text);
|
||
//ushort[] fire = _modbusMaster?.ReadHoldingRegisters(1, 194, 2);
|
||
//firetime = c.UshortToFloat(fire[1], fire[0]);//点火时间
|
||
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 304, 4);
|
||
//if (yhlocation != null && yhlocation.Length >= 3)
|
||
//{
|
||
// yy = c.UshortToFloat(yhlocation[1], yhlocation[0]); //余焰
|
||
// yh = c.UshortToFloat(yhlocation[3], yhlocation[2]);//余辉
|
||
//}
|
||
bool[] fire1 = await ReadModbusCoilAsync(280, 1);
|
||
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
|
||
if (fire1 != null && fire1.Length > 0 && fire1[0])
|
||
{
|
||
iszixi = "true";//自熄
|
||
}
|
||
else if (fire2 != null && fire2.Length > 0 && fire2[0])
|
||
{
|
||
iszixi = "false";
|
||
}
|
||
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 94, 2);
|
||
costtime = time[0];//总测试时长
|
||
}
|
||
else if (value12 != null && value12.Length > 0 && value12[0])
|
||
{
|
||
classify = "I1x";//分类
|
||
firetime = float.Parse(uiLabel7.Text);
|
||
yy = 0;
|
||
yh = float.Parse(uiLabel12.Text);
|
||
|
||
//ushort[] fire = _modbusMaster?.ReadHoldingRegisters(1, 194, 2);
|
||
//firetime = c.UshortToFloat(fire[1], fire[0]);//点火时间
|
||
//yy = 0;
|
||
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 314, 2);
|
||
//if (yhlocation != null && yhlocation.Length >= 1)
|
||
//{
|
||
// yh = c.UshortToFloat(yhlocation[1], yhlocation[0]);//余辉
|
||
//}
|
||
bool[] fire1 = await ReadModbusCoilAsync(280, 1);
|
||
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
|
||
if (fire1 != null && fire1.Length > 0 && fire1[0])
|
||
{
|
||
iszixi = "true";//自熄
|
||
}
|
||
else if (fire2 != null && fire2.Length > 0 && fire2[0])
|
||
{
|
||
iszixi = "false";
|
||
}
|
||
else
|
||
{
|
||
iszixi = "null";
|
||
}
|
||
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 94, 2);
|
||
costtime = time[0];//总测试时长
|
||
}
|
||
}
|
||
|
||
if (uiLabel10.Text != null && uiLabel10.Text.Trim() == "4")
|
||
{
|
||
bool[] value13 = await ReadModbusCoilAsync(113, 1);
|
||
bool[] value14 = await ReadModbusCoilAsync(123, 1);
|
||
bool[] value15 = await ReadModbusCoilAsync(133, 1);
|
||
bool[] value16 = await ReadModbusCoilAsync(143, 1);
|
||
|
||
if (value13 != null && value13.Length > 0 && value13[0])
|
||
{
|
||
classify = "I4x";//分类
|
||
firetime = float.Parse(uiLabel7.Text);
|
||
yy = float.Parse(uiLabel8.Text);
|
||
yh = float.Parse(uiLabel12.Text);
|
||
//ushort[] fire = _modbusMaster?.ReadHoldingRegisters(1, 196, 2);
|
||
//firetime = c.UshortToFloat(fire[1], fire[0]);//点火时间
|
||
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 300, 4);
|
||
//if (yhlocation != null && yhlocation.Length >= 3)
|
||
//{
|
||
// yy = c.UshortToFloat(yhlocation[1], yhlocation[0]); //余焰
|
||
// yh = c.UshortToFloat(yhlocation[3], yhlocation[2]);//余辉
|
||
//}
|
||
bool[] fire1 = await ReadModbusCoilAsync(280, 1);
|
||
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
|
||
if (fire1 != null && fire1.Length > 0 && fire1[0])
|
||
{
|
||
iszixi = "true";//自熄
|
||
}
|
||
else if (fire2 != null && fire2.Length > 0 && fire2[0])
|
||
{
|
||
iszixi = "false";
|
||
}
|
||
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 96, 2);
|
||
costtime = time[0];//总测试时长
|
||
}
|
||
else if (value14 != null && value14.Length > 0 && value14[0])
|
||
{
|
||
classify = "I3x";//分类
|
||
firetime = float.Parse(uiLabel7.Text);
|
||
yy = float.Parse(uiLabel8.Text);
|
||
yh = float.Parse(uiLabel12.Text);
|
||
//ushort[] fire = _modbusMaster?.ReadHoldingRegisters(1, 196, 2);
|
||
//firetime = c.UshortToFloat(fire[1], fire[0]);//点火时间
|
||
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 308, 4);
|
||
//if (yhlocation != null && yhlocation.Length >= 3)
|
||
//{
|
||
// yy = c.UshortToFloat(yhlocation[1], yhlocation[0]); //余焰
|
||
// yh = c.UshortToFloat(yhlocation[3], yhlocation[2]);//余辉
|
||
//}
|
||
bool[] fire1 = await ReadModbusCoilAsync(280, 1);
|
||
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
|
||
if (fire1 != null && fire1.Length > 0 && fire1[0])
|
||
{
|
||
iszixi = "true";//自熄
|
||
}
|
||
else if (fire2 != null && fire2.Length > 0 && fire2[0])
|
||
{
|
||
iszixi = "false";
|
||
}
|
||
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 96, 2);
|
||
costtime = time[0];//总测试时长
|
||
}
|
||
else if (value15 != null && value15.Length > 0 && value15[0])
|
||
{
|
||
classify = "I2x";//分类
|
||
firetime = float.Parse(uiLabel7.Text);
|
||
yy = float.Parse(uiLabel8.Text);
|
||
yh = float.Parse(uiLabel12.Text);
|
||
//ushort[] fire = _modbusMaster?.ReadHoldingRegisters(1, 196, 2);
|
||
//firetime = c.UshortToFloat(fire[1], fire[0]);//点火时间
|
||
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 304, 4);
|
||
//if (yhlocation != null && yhlocation.Length >= 3)
|
||
//{
|
||
// yy = c.UshortToFloat(yhlocation[1], yhlocation[0]); //余焰
|
||
// yh = c.UshortToFloat(yhlocation[3], yhlocation[2]);//余辉
|
||
//}
|
||
bool[] fire1 = await ReadModbusCoilAsync(280, 1);
|
||
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
|
||
if (fire1 != null && fire1.Length > 0 && fire1[0])
|
||
{
|
||
iszixi = "true";//自熄
|
||
}
|
||
else if (fire2 != null && fire2.Length > 0 && fire2[0])
|
||
{
|
||
iszixi = "false";
|
||
}
|
||
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 96, 2);
|
||
costtime = time[0];//总测试时长
|
||
}
|
||
else if (value16 != null && value16.Length > 0 && value16[0])
|
||
{
|
||
classify = "I1x";//分类
|
||
firetime = float.Parse(uiLabel7.Text);
|
||
yy = 0;
|
||
yh = float.Parse(uiLabel12.Text);
|
||
//ushort[] fire = _modbusMaster?.ReadHoldingRegisters(1, 196, 2);
|
||
//firetime = c.UshortToFloat(fire[1], fire[0]);//点火时间
|
||
//yy = 0;
|
||
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 314, 2);
|
||
//if (yhlocation != null && yhlocation.Length >= 1)
|
||
//{
|
||
// yh = c.UshortToFloat(yhlocation[1], yhlocation[0]);//余辉
|
||
//}
|
||
bool[] fire1 = await ReadModbusCoilAsync(280, 1);
|
||
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
|
||
if (fire1 != null && fire1.Length > 0 && fire1[0])
|
||
{
|
||
iszixi = "true";//自熄
|
||
}
|
||
else if (fire2 != null && fire2.Length > 0 && fire2[0])
|
||
{
|
||
iszixi = "false";
|
||
}
|
||
else
|
||
{
|
||
iszixi = "null";
|
||
}
|
||
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 96, 2);
|
||
costtime = time[0];//总测试时长
|
||
}
|
||
}
|
||
|
||
if (uiLabel10.Text != null && uiLabel10.Text.Trim() == "5")
|
||
{
|
||
bool[] value17 = await ReadModbusCoilAsync(114, 1);
|
||
bool[] value18 = await ReadModbusCoilAsync(124, 1);
|
||
bool[] value19 = await ReadModbusCoilAsync(134, 1);
|
||
bool[] value20 = await ReadModbusCoilAsync(144, 1);
|
||
|
||
if (value17 != null && value17.Length > 0 && value17[0])
|
||
{
|
||
classify = "I4x";//分类
|
||
firetime = float.Parse(uiLabel7.Text);
|
||
yy = float.Parse(uiLabel8.Text);
|
||
yh = float.Parse(uiLabel12.Text);
|
||
//ushort[] fire = _modbusMaster?.ReadHoldingRegisters(1, 198, 2);
|
||
//firetime = c.UshortToFloat(fire[1], fire[0]);//点火时间
|
||
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 300, 4);
|
||
//if (yhlocation != null && yhlocation.Length >= 3)
|
||
//{
|
||
// yy = c.UshortToFloat(yhlocation[1], yhlocation[0]); //余焰
|
||
// yh = c.UshortToFloat(yhlocation[3], yhlocation[2]);//余辉
|
||
//}
|
||
bool[] fire1 = await ReadModbusCoilAsync(280, 1);
|
||
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
|
||
if (fire1 != null && fire1.Length > 0 && fire1[0])
|
||
{
|
||
iszixi = "true";//自熄
|
||
}
|
||
else if (fire2 != null && fire2.Length > 0 && fire2[0])
|
||
{
|
||
iszixi = "false";
|
||
}
|
||
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 98, 2);
|
||
costtime = time[0];//总测试时长
|
||
}
|
||
else if (value18 != null && value18.Length > 0 && value18[0])
|
||
{
|
||
classify = "I3x";//分类
|
||
firetime = float.Parse(uiLabel7.Text);
|
||
yy = float.Parse(uiLabel8.Text);
|
||
yh = float.Parse(uiLabel12.Text);
|
||
//ushort[] fire = _modbusMaster?.ReadHoldingRegisters(1, 198, 2);
|
||
//firetime = c.UshortToFloat(fire[1], fire[0]);//点火时间
|
||
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 308, 4);
|
||
//if (yhlocation != null && yhlocation.Length >= 3)
|
||
//{
|
||
// yy = c.UshortToFloat(yhlocation[1], yhlocation[0]); //余焰
|
||
// yh = c.UshortToFloat(yhlocation[3], yhlocation[2]);//余辉
|
||
//}
|
||
bool[] fire1 = await ReadModbusCoilAsync(280, 1);
|
||
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
|
||
if (fire1 != null && fire1.Length > 0 && fire1[0])
|
||
{
|
||
iszixi = "true";//自熄
|
||
}
|
||
else if (fire2 != null && fire2.Length > 0 && fire2[0])
|
||
{
|
||
iszixi = "false";
|
||
}
|
||
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 98, 2);
|
||
costtime = time[0];//总测试时长
|
||
}
|
||
else if (value19 != null && value19.Length > 0 && value19[0])
|
||
{
|
||
classify = "I2x";//分类
|
||
firetime = float.Parse(uiLabel7.Text);
|
||
yy = float.Parse(uiLabel8.Text);
|
||
yh = float.Parse(uiLabel12.Text);
|
||
//ushort[] fire = _modbusMaster?.ReadHoldingRegisters(1, 198, 2);
|
||
//firetime = c.UshortToFloat(fire[1], fire[0]);//点火时间
|
||
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 304, 4);
|
||
//if (yhlocation != null && yhlocation.Length >= 3)
|
||
//{
|
||
// yy = c.UshortToFloat(yhlocation[1], yhlocation[0]); //余焰
|
||
// yh = c.UshortToFloat(yhlocation[3], yhlocation[2]);//余辉
|
||
//}
|
||
bool[] fire1 = await ReadModbusCoilAsync(280, 1);
|
||
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
|
||
if (fire1 != null && fire1.Length > 0 && fire1[0])
|
||
{
|
||
iszixi = "true";//自熄
|
||
}
|
||
else if (fire2 != null && fire2.Length > 0 && fire2[0])
|
||
{
|
||
iszixi = "false";
|
||
}
|
||
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 98, 2);
|
||
costtime = time[0];//总测试时长
|
||
}
|
||
else if (value20 != null && value20.Length > 0 && value20[0])
|
||
{
|
||
classify = "I1x";//分类
|
||
|
||
firetime = float.Parse(uiLabel7.Text);
|
||
yy = 0;
|
||
yh = float.Parse(uiLabel12.Text);
|
||
|
||
//ushort[] fire = _modbusMaster?.ReadHoldingRegisters(1, 198, 2);
|
||
//firetime = c.UshortToFloat(fire[1], fire[0]);//点火时间
|
||
//yy = 0;
|
||
//ushort[] yhlocation = _modbusMaster?.ReadHoldingRegisters(1, 314, 2);
|
||
//if (yhlocation != null && yhlocation.Length >= 1)
|
||
//{
|
||
// yh = c.UshortToFloat(yhlocation[1], yhlocation[0]);//余辉
|
||
//}
|
||
bool[] fire1 = await ReadModbusCoilAsync(280, 1);
|
||
bool[] fire2 = await ReadModbusCoilAsync(281, 1);
|
||
if (fire1 != null && fire1.Length > 0 && fire1[0])
|
||
{
|
||
iszixi = "true";//自熄
|
||
}
|
||
else if (fire2 != null && fire2.Length > 0 && fire2[0])
|
||
{
|
||
iszixi = "false";
|
||
}
|
||
else
|
||
{
|
||
iszixi = "null";
|
||
}
|
||
ushort[] time = _modbusMaster?.ReadHoldingRegisters(1, 98, 2);
|
||
costtime = time[0];//总测试时长
|
||
}
|
||
}
|
||
|
||
|
||
try
|
||
{
|
||
string selectedO2Text = uiComboBox1.Text;
|
||
string id = uiLabel10.Text;
|
||
|
||
var model = new PrimaryIgnitionModel
|
||
{
|
||
Id = id,
|
||
O2 = selectedO2Text,
|
||
result = classify,
|
||
FireDate = firetime,
|
||
yuhui = yh,
|
||
yuyan = yy,
|
||
Iszixi = iszixi,
|
||
costTime = costtime,
|
||
Testtime = DateTime.Now,
|
||
|
||
sampleType = uiLabel10.Text.Contains("1") ? 1
|
||
: uiLabel10.Text.Contains("2") ? 2
|
||
: uiLabel10.Text.Contains("3") ? 3
|
||
: uiLabel10.Text.Contains("4") ? 4
|
||
: uiLabel10.Text.Contains("5") ? 5 : 0,
|
||
};
|
||
reportList.Add(model);
|
||
_isCurrentRecordAdded = true; // 标记为已添加,避免重复
|
||
await Task.Delay(100);
|
||
return model;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
Debug.WriteLine($"报表插入失败: {ex.Message}");
|
||
return new PrimaryIgnitionModel();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//_isCurrentRecordAdded = false;
|
||
return new PrimaryIgnitionModel(); ;
|
||
}
|
||
}
|
||
|
||
|
||
private async Task ReadtimeAsync()
|
||
{
|
||
try
|
||
{
|
||
|
||
string currentTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||
|
||
// 跨线程更新UI(异步方法中仍需检查Invoke,避免跨线程异常)
|
||
if (uiLabel25.InvokeRequired)
|
||
{
|
||
uiLabel25.Invoke(new Action(() =>
|
||
{
|
||
uiLabel25.Text = currentTime;
|
||
}));
|
||
}
|
||
else
|
||
{
|
||
uiLabel25.Text = currentTime;
|
||
}
|
||
|
||
// 等待1秒再更新(异步等待,不阻塞UI线程)
|
||
await Task.Delay(1000);
|
||
|
||
}
|
||
|
||
catch (Exception ex)
|
||
{
|
||
uiLabel25.Text = $"错误:{ex.Message}";
|
||
}
|
||
}
|
||
|
||
private void InitComboBoxPattern()
|
||
{
|
||
// 清空原有选项(可选,避免重复添加)
|
||
//Combox_pattern.Items.Clear();
|
||
|
||
// 定义需要添加的选项数组
|
||
string[] options = {
|
||
"环境空气 (21%)",
|
||
"富氧环境 (60%)",
|
||
"富氧环境 (98%)",
|
||
"无氧环境/灭火 (0%)"
|
||
};
|
||
uiComboBox1.Items.AddRange(options);
|
||
uiComboBox1.SelectedIndex = 0;
|
||
}
|
||
|
||
|
||
private void PrimaryIgnitionForm_FormClosed(object sender, FormClosedEventArgs e)
|
||
{
|
||
|
||
|
||
foreach (Form form in Application.OpenForms)
|
||
{
|
||
if (form.Name == "MainForm" || form.Text.Contains("主界面"))
|
||
{
|
||
form.Show();
|
||
form.Activate(); // 激活窗体
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
private void uiButton4_Click(object sender, EventArgs e)
|
||
{
|
||
ma?.BtnClickFunctionForNew(Function.ButtonType.切换型, 5);//余焰开始
|
||
}
|
||
|
||
private void uiButton5_Click(object sender, EventArgs e)
|
||
{
|
||
ma?.BtnClickFunctionForNew(Function.ButtonType.复归型, 6);//余焰结束
|
||
}
|
||
|
||
private void uiButton6_Click(object sender, EventArgs e)
|
||
{
|
||
ma?.BtnClickFunctionForNew(Function.ButtonType.复归型, 7);//实验结束
|
||
}
|
||
|
||
private void uiComboBox1_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
ushort selectedIndex = ushort.Parse(uiComboBox1.SelectedIndex.ToString());
|
||
_modbusMaster?.WriteSingleRegister(1, 10, selectedIndex);//下拉框
|
||
}
|
||
|
||
private void uiButton7_Click(object sender, EventArgs e)
|
||
{
|
||
string message = "帮助一:请目测是否有余辉:有余辉请立即点击“余辉开始”按钮,余辉时间开始计时;余辉结束,请立即点击“余辉结束”按钮,余辉时间计时结束;\n帮助二:请目测判断样品是否燃尽,如燃尽请按下“火焰未自熄”按钮,如未燃尽请按下“火焰自熄”按钮;";
|
||
|
||
Font font = new Font("Microsoft YaHei", 12, FontStyle.Regular);
|
||
|
||
// 创建一个自定义的消息框
|
||
TaskDialogPage page = new TaskDialogPage
|
||
{
|
||
Text = message,
|
||
Caption = "帮助",
|
||
SizeToContent = true
|
||
};
|
||
|
||
TaskDialog.ShowDialog(this, page);
|
||
}
|
||
|
||
private void uiButton1_Click(object sender, EventArgs e)
|
||
{
|
||
ma?.BtnClickFunctionForNew(Function.ButtonType.复归型, 50);//开始
|
||
_isReported = false;
|
||
}
|
||
|
||
private void uiButton2_Click(object sender, EventArgs e)
|
||
{
|
||
ma?.BtnClickFunctionForNew(Function.ButtonType.复归型, 55);//手动停止
|
||
}
|
||
|
||
private void uiButton3_Click(object sender, EventArgs e)
|
||
{
|
||
ma?.BtnClickFunctionForNew(Function.ButtonType.切换型, 99);//灭火
|
||
}
|
||
|
||
private void PrimaryIgnitionForm_FormClosing(object sender, FormClosingEventArgs e)
|
||
{
|
||
|
||
if (_readtimer != null)
|
||
{
|
||
_readtimer.Stop();
|
||
_readtimer.Dispose();
|
||
ModbusResourceManager.Instance?.Dispose();
|
||
}
|
||
}
|
||
|
||
|
||
private void InitComboBox2Pattern()
|
||
{
|
||
// 清空原有选项(可选,避免重复添加)
|
||
//Combox_pattern.Items.Clear();
|
||
|
||
// 定义需要添加的选项数组
|
||
string[] options = {
|
||
"样品1",
|
||
"样品2",
|
||
"样品3",
|
||
"样品4",
|
||
"样品5"
|
||
};
|
||
uiComboBox2.Items.AddRange(options);
|
||
|
||
}
|
||
|
||
private void uiComboBox2_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
string value = uiComboBox2.SelectedItem.ToString();
|
||
|
||
switch (value)
|
||
{
|
||
case "样品1":
|
||
{
|
||
var data = reportList?.OrderByDescending(s => s.Testtime).FirstOrDefault(x => x.sampleType == 1);
|
||
uiLabel21.Text = data?.O2.ToString() ?? string.Empty;
|
||
uiLabel19.Text = data?.result.ToString() ?? string.Empty;
|
||
uiLabel31.Text = data?.FireDate.ToString() ?? string.Empty;
|
||
uiLabel27.Text = data?.yuyan.ToString() ?? string.Empty;
|
||
uiLabel29.Text = data?.yuhui.ToString() ?? string.Empty;
|
||
uiLabel18.Text = data?.Iszixi.ToString() ?? string.Empty;
|
||
uiLabel34.Text = data?.costTime.ToString() ?? string.Empty;
|
||
uiLabel42.Text = data?.Testtime.ToString() ?? string.Empty;
|
||
break;
|
||
}
|
||
case "样品2":
|
||
{
|
||
var data = reportList?.OrderByDescending(s => s.Testtime).FirstOrDefault(x => x.sampleType == 2);
|
||
uiLabel21.Text = data?.O2.ToString() ?? string.Empty;
|
||
uiLabel19.Text = data?.result.ToString() ?? string.Empty;
|
||
uiLabel31.Text = data?.FireDate.ToString() ?? string.Empty;
|
||
uiLabel27.Text = data?.yuyan.ToString() ?? string.Empty;
|
||
uiLabel29.Text = data?.yuhui.ToString() ?? string.Empty;
|
||
uiLabel18.Text = data?.Iszixi.ToString() ?? string.Empty;
|
||
uiLabel34.Text = data?.costTime.ToString() ?? string.Empty;
|
||
uiLabel42.Text = data?.Testtime.ToString() ?? string.Empty;
|
||
break;
|
||
}
|
||
case "样品3":
|
||
{
|
||
var data = reportList?.OrderByDescending(s => s.Testtime).FirstOrDefault(x => x.sampleType == 3);
|
||
uiLabel21.Text = data?.O2.ToString() ?? string.Empty;
|
||
uiLabel19.Text = data?.result.ToString() ?? string.Empty;
|
||
uiLabel31.Text = data?.FireDate.ToString() ?? string.Empty;
|
||
uiLabel27.Text = data?.yuyan.ToString() ?? string.Empty;
|
||
uiLabel29.Text = data?.yuhui.ToString() ?? string.Empty;
|
||
uiLabel18.Text = data?.Iszixi.ToString() ?? string.Empty;
|
||
uiLabel34.Text = data?.costTime.ToString() ?? string.Empty;
|
||
uiLabel42.Text = data?.Testtime.ToString() ?? string.Empty;
|
||
break;
|
||
}
|
||
case "样品4":
|
||
{
|
||
var data = reportList?.OrderByDescending(s => s.Testtime).FirstOrDefault(x => x.sampleType == 4);
|
||
uiLabel21.Text = data?.O2.ToString() ?? string.Empty;
|
||
uiLabel19.Text = data?.result.ToString() ?? string.Empty;
|
||
uiLabel31.Text = data?.FireDate.ToString() ?? string.Empty;
|
||
uiLabel27.Text = data?.yuyan.ToString() ?? string.Empty;
|
||
uiLabel29.Text = data?.yuhui.ToString() ?? string.Empty;
|
||
uiLabel18.Text = data?.Iszixi.ToString() ?? string.Empty;
|
||
uiLabel34.Text = data?.costTime.ToString() ?? string.Empty;
|
||
uiLabel42.Text = data?.Testtime.ToString() ?? string.Empty;
|
||
break;
|
||
}
|
||
case "样品5":
|
||
{
|
||
var data = reportList?.OrderByDescending(s => s.Testtime).FirstOrDefault(x => x.sampleType == 5);
|
||
uiLabel21.Text = data?.O2.ToString() ?? string.Empty;
|
||
uiLabel19.Text = data?.result.ToString() ?? string.Empty;
|
||
uiLabel31.Text = data?.FireDate.ToString() ?? string.Empty;
|
||
uiLabel27.Text = data?.yuyan.ToString() ?? string.Empty;
|
||
uiLabel29.Text = data?.yuhui.ToString() ?? string.Empty;
|
||
uiLabel18.Text = data?.Iszixi.ToString() ?? string.Empty;
|
||
uiLabel34.Text = data?.costTime.ToString() ?? string.Empty;
|
||
uiLabel42.Text = data?.Testtime.ToString() ?? string.Empty;
|
||
break;
|
||
}
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
private void uiButton8_Click(object sender, EventArgs e)
|
||
{
|
||
//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);//未自熄
|
||
}
|
||
|
||
private void uiButton12_Click(object sender, EventArgs e)
|
||
{
|
||
ma?.BtnClickFunctionForNew(Function.ButtonType.切换型, 270);//自熄
|
||
}
|
||
|
||
private void uiButton13_Click(object sender, EventArgs e)
|
||
{
|
||
this.Close();//返回主页面
|
||
}
|
||
|
||
private void uiButton10_Click_1(object sender, EventArgs e)
|
||
{
|
||
ma?.BtnClickFunctionForNew(Function.ButtonType.复归型, 54, 1);//清除
|
||
}
|
||
|
||
private void SwitchToForm(Func<Form> formCreator)
|
||
{
|
||
using (Form form = formCreator())
|
||
{
|
||
this.Hide();
|
||
form.ShowDialog();
|
||
this.Show();
|
||
this.Activate();
|
||
}
|
||
}
|
||
|
||
private void uiButton9_Click(object sender, EventArgs e)
|
||
{
|
||
ma?.BtnClickFunctionForNew(Function.ButtonType.切换型, 101);//混氧开关
|
||
}
|
||
|
||
private void uiButton14_Click(object sender, EventArgs e)
|
||
{
|
||
ma?.BtnClickFunctionForNew(Function.ButtonType.切换型, 11);//灯开关
|
||
}
|
||
}
|
||
}
|