test 331
This commit is contained in:
1 parent
2b56f8e7d3
commit
60cafc4f8c
6 files changed
+384
-91
No files matched your search
@@ -172,6 +172,9 @@
|
||||
<Compile Include="form\Angleaddress_Manage.Designer.cs">
|
||||
<DependentUpon>Angleaddress_Manage.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="form\LoadingForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="form\ScanForm_DZ.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
||||
Generated
+50
-20
@@ -96,6 +96,8 @@ namespace WindowsFormsApp1
|
||||
this.底部注释4 = new System.Windows.Forms.Label();
|
||||
this.底部注释5 = new System.Windows.Forms.Label();
|
||||
this.timer1 = new System.Windows.Forms.Timer(this.components);
|
||||
this.材料 = new System.Windows.Forms.Label();
|
||||
this.材料值 = new System.Windows.Forms.Label();
|
||||
this.plcStatusGroupBox.SuspendLayout();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
this.tableLayoutPanel1.SuspendLayout();
|
||||
@@ -172,21 +174,21 @@ namespace WindowsFormsApp1
|
||||
// 修改密码ToolStripMenuItem
|
||||
//
|
||||
this.修改密码ToolStripMenuItem.Name = "修改密码ToolStripMenuItem";
|
||||
this.修改密码ToolStripMenuItem.Size = new System.Drawing.Size(359, 50);
|
||||
this.修改密码ToolStripMenuItem.Size = new System.Drawing.Size(283, 50);
|
||||
this.修改密码ToolStripMenuItem.Text = "修改密码";
|
||||
this.修改密码ToolStripMenuItem.Click += new System.EventHandler(this.修改密码ToolStripMenuItem_Click);
|
||||
//
|
||||
// 切换用户ToolStripMenuItem
|
||||
//
|
||||
this.切换用户ToolStripMenuItem.Name = "切换用户ToolStripMenuItem";
|
||||
this.切换用户ToolStripMenuItem.Size = new System.Drawing.Size(359, 50);
|
||||
this.切换用户ToolStripMenuItem.Size = new System.Drawing.Size(283, 50);
|
||||
this.切换用户ToolStripMenuItem.Text = "切换用户";
|
||||
this.切换用户ToolStripMenuItem.Click += new System.EventHandler(this.切换用户ToolStripMenuItem_Click);
|
||||
//
|
||||
// 用户管理ToolStripMenuItem1
|
||||
//
|
||||
this.用户管理ToolStripMenuItem1.Name = "用户管理ToolStripMenuItem1";
|
||||
this.用户管理ToolStripMenuItem1.Size = new System.Drawing.Size(359, 50);
|
||||
this.用户管理ToolStripMenuItem1.Size = new System.Drawing.Size(283, 50);
|
||||
this.用户管理ToolStripMenuItem1.Text = "用户管理";
|
||||
this.用户管理ToolStripMenuItem1.Click += new System.EventHandler(this.用户管理ToolStripMenuItem1_Click);
|
||||
//
|
||||
@@ -494,18 +496,21 @@ namespace WindowsFormsApp1
|
||||
this.tableLayoutPanel5.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 21.75624F));
|
||||
this.tableLayoutPanel5.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 67.06608F));
|
||||
this.tableLayoutPanel5.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 11.17768F));
|
||||
this.tableLayoutPanel5.Controls.Add(this.材料值, 1, 1);
|
||||
this.tableLayoutPanel5.Controls.Add(this.材料, 0, 1);
|
||||
this.tableLayoutPanel5.Controls.Add(this.LOT号显示, 0, 0);
|
||||
this.tableLayoutPanel5.Controls.Add(this.LOT号, 1, 0);
|
||||
this.tableLayoutPanel5.Controls.Add(this.胶水上下线, 2, 0);
|
||||
this.tableLayoutPanel5.Controls.Add(this.剩余寿命, 2, 1);
|
||||
this.tableLayoutPanel5.Controls.Add(this.MES提示, 0, 1);
|
||||
this.tableLayoutPanel5.Controls.Add(this.Tray盘二维码, 1, 1);
|
||||
this.tableLayoutPanel5.Controls.Add(this.MES提示, 0, 2);
|
||||
this.tableLayoutPanel5.Controls.Add(this.Tray盘二维码, 1, 2);
|
||||
this.tableLayoutPanel5.Controls.Add(this.剩余寿命, 2, 2);
|
||||
this.tableLayoutPanel5.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.tableLayoutPanel5.Location = new System.Drawing.Point(3, 41);
|
||||
this.tableLayoutPanel5.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.tableLayoutPanel5.Name = "tableLayoutPanel5";
|
||||
this.tableLayoutPanel5.RowCount = 2;
|
||||
this.tableLayoutPanel5.RowCount = 3;
|
||||
this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
|
||||
this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 50F));
|
||||
this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
|
||||
this.tableLayoutPanel5.Size = new System.Drawing.Size(1390, 256);
|
||||
this.tableLayoutPanel5.TabIndex = 0;
|
||||
@@ -515,7 +520,7 @@ namespace WindowsFormsApp1
|
||||
this.LOT号显示.Anchor = System.Windows.Forms.AnchorStyles.None;
|
||||
this.LOT号显示.AutoSize = true;
|
||||
this.LOT号显示.Font = new System.Drawing.Font("宋体", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.LOT号显示.Location = new System.Drawing.Point(93, 40);
|
||||
this.LOT号显示.Location = new System.Drawing.Point(93, 27);
|
||||
this.LOT号显示.Name = "LOT号显示";
|
||||
this.LOT号显示.Size = new System.Drawing.Size(116, 48);
|
||||
this.LOT号显示.TabIndex = 2;
|
||||
@@ -526,7 +531,7 @@ namespace WindowsFormsApp1
|
||||
this.LOT号.Anchor = System.Windows.Forms.AnchorStyles.None;
|
||||
this.LOT号.AutoSize = true;
|
||||
this.LOT号.Font = new System.Drawing.Font("宋体", 21.85714F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.LOT号.Location = new System.Drawing.Point(767, 34);
|
||||
this.LOT号.Location = new System.Drawing.Point(767, 22);
|
||||
this.LOT号.Name = "LOT号";
|
||||
this.LOT号.Size = new System.Drawing.Size(0, 59);
|
||||
this.LOT号.TabIndex = 0;
|
||||
@@ -537,28 +542,30 @@ namespace WindowsFormsApp1
|
||||
this.胶水上下线.Location = new System.Drawing.Point(1236, 5);
|
||||
this.胶水上下线.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.胶水上下线.Name = "胶水上下线";
|
||||
this.胶水上下线.Size = new System.Drawing.Size(150, 118);
|
||||
this.tableLayoutPanel5.SetRowSpan(this.胶水上下线, 2);
|
||||
this.胶水上下线.Size = new System.Drawing.Size(150, 144);
|
||||
this.胶水上下线.TabIndex = 3;
|
||||
this.胶水上下线.Text = "胶水寿命";
|
||||
this.胶水上下线.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// 剩余寿命
|
||||
//
|
||||
this.剩余寿命.Anchor = System.Windows.Forms.AnchorStyles.None;
|
||||
this.剩余寿命.AutoSize = true;
|
||||
this.剩余寿命.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.剩余寿命.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.剩余寿命.Location = new System.Drawing.Point(1239, 175);
|
||||
this.剩余寿命.Location = new System.Drawing.Point(1236, 154);
|
||||
this.剩余寿命.Name = "剩余寿命";
|
||||
this.剩余寿命.Size = new System.Drawing.Size(143, 33);
|
||||
this.剩余寿命.Size = new System.Drawing.Size(150, 101);
|
||||
this.剩余寿命.TabIndex = 5;
|
||||
this.剩余寿命.Text = "剩余寿命";
|
||||
this.剩余寿命.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// MES提示
|
||||
//
|
||||
this.MES提示.Anchor = System.Windows.Forms.AnchorStyles.None;
|
||||
this.MES提示.AutoSize = true;
|
||||
this.MES提示.Font = new System.Drawing.Font("宋体", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.MES提示.Location = new System.Drawing.Point(45, 167);
|
||||
this.MES提示.Location = new System.Drawing.Point(45, 180);
|
||||
this.MES提示.Name = "MES提示";
|
||||
this.MES提示.Size = new System.Drawing.Size(212, 48);
|
||||
this.MES提示.TabIndex = 4;
|
||||
@@ -569,7 +576,7 @@ namespace WindowsFormsApp1
|
||||
this.Tray盘二维码.Anchor = System.Windows.Forms.AnchorStyles.None;
|
||||
this.Tray盘二维码.AutoSize = true;
|
||||
this.Tray盘二维码.Font = new System.Drawing.Font("宋体", 21.85714F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.Tray盘二维码.Location = new System.Drawing.Point(767, 162);
|
||||
this.Tray盘二维码.Location = new System.Drawing.Point(767, 175);
|
||||
this.Tray盘二维码.Name = "Tray盘二维码";
|
||||
this.Tray盘二维码.Size = new System.Drawing.Size(0, 59);
|
||||
this.Tray盘二维码.TabIndex = 2;
|
||||
@@ -677,7 +684,7 @@ namespace WindowsFormsApp1
|
||||
this.当前时间.Name = "当前时间";
|
||||
this.当前时间.Size = new System.Drawing.Size(248, 75);
|
||||
this.当前时间.TabIndex = 11;
|
||||
this.当前时间.Text = "当前时间:";
|
||||
this.当前时间.Text = "当前状态:";
|
||||
this.当前时间.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// 操作人员ID
|
||||
@@ -840,9 +847,31 @@ namespace WindowsFormsApp1
|
||||
//
|
||||
// timer1
|
||||
//
|
||||
this.timer1.Enabled = true;
|
||||
this.timer1.Interval = 1000;
|
||||
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
|
||||
//this.timer1.Enabled = true;
|
||||
//this.timer1.Interval = 1000;
|
||||
//this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
|
||||
//
|
||||
// 材料
|
||||
//
|
||||
this.材料.Anchor = System.Windows.Forms.AnchorStyles.None;
|
||||
this.材料.AutoSize = true;
|
||||
this.材料.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.材料.Location = new System.Drawing.Point(96, 111);
|
||||
this.材料.Name = "材料";
|
||||
this.材料.Size = new System.Drawing.Size(111, 33);
|
||||
this.材料.TabIndex = 6;
|
||||
this.材料.Text = "材料:";
|
||||
//
|
||||
// 材料值
|
||||
//
|
||||
this.材料值.AutoSize = true;
|
||||
this.材料值.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.材料值.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.材料值.Location = new System.Drawing.Point(306, 103);
|
||||
this.材料值.Name = "材料值";
|
||||
this.材料值.Size = new System.Drawing.Size(923, 50);
|
||||
this.材料值.TabIndex = 7;
|
||||
this.材料值.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
@@ -947,7 +976,8 @@ namespace WindowsFormsApp1
|
||||
private System.Windows.Forms.ToolStripMenuItem 图片展示ToolStripMenuItem;
|
||||
private System.Windows.Forms.GroupBox plcStatusGroupBox;
|
||||
private System.Windows.Forms.TableLayoutPanel plcStatusTableLayout;
|
||||
|
||||
private System.Windows.Forms.Label 材料;
|
||||
private System.Windows.Forms.Label 材料值;
|
||||
}
|
||||
}
|
||||
|
||||
+202
-52
@@ -39,6 +39,10 @@ namespace WindowsFormsApp1
|
||||
private Dictionary<int, System.Windows.Forms.Label> plcStatusLabels = new Dictionary<int, System.Windows.Forms.Label>();
|
||||
private Dictionary<int, System.Windows.Forms.Panel> plcStatusIndicators = new Dictionary<int, System.Windows.Forms.Panel>();
|
||||
|
||||
// 在MainForm类的成员变量部分添加一个定时器
|
||||
private System.Windows.Forms.Timer statusReportTimer = new System.Windows.Forms.Timer();
|
||||
private ApiClient statusApiClient = new ApiClient(); // 专用于状态上报的API客户端
|
||||
|
||||
public MainForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -46,6 +50,10 @@ namespace WindowsFormsApp1
|
||||
this.FormClosed += MainForm_FormClosed;
|
||||
|
||||
CheckForIllegalCrossThreadCalls = false;
|
||||
|
||||
// 初始化状态上报定时器
|
||||
statusReportTimer.Interval = 15000; // 15秒
|
||||
//statusReportTimer.Tick += StatusReportTimer_Tick;
|
||||
}
|
||||
|
||||
private void Form1_Load(object sender, EventArgs e)
|
||||
@@ -141,22 +149,32 @@ namespace WindowsFormsApp1
|
||||
continue;
|
||||
}
|
||||
|
||||
if(Plc.id == 1)
|
||||
{
|
||||
LOT号.Text = PlcData.Read_MaterialCode0;
|
||||
Tray盘二维码.Text = PlcData.Read_MaterialCode1;
|
||||
材料值.Text = PlcData.Read_MaterialCode2;
|
||||
}
|
||||
|
||||
|
||||
当前时间.Text = $"PLC状态:{plcstatus.GetName(typeof(plcstatus),PlcData.Read_Status)}";
|
||||
|
||||
DateTime Plc_Time = DateTime.Now;
|
||||
|
||||
//PLC链接状态.Text = "PLC链接状态:OK";
|
||||
//PLC链接状态.BackColor = SystemColors.Control;
|
||||
//PLC通讯时间.Text = "PLC通讯时间:" + Plc_Time.ToString("MM-dd HH:mm:ss");
|
||||
// 更新对应PLC的状态指示器为绿色
|
||||
|
||||
//LogExecute.logNet.WriteError($"{Plc.plcname}");
|
||||
|
||||
UpdatePlcStatus(Plc.id, true);
|
||||
|
||||
#endregion
|
||||
|
||||
ApiClient apiClient = new ApiClient();
|
||||
otherdata otherdata = new otherdata();
|
||||
Init.SN = PlcData.Read_MaterialCode0;
|
||||
//Init.SN = PlcData.Read_MaterialCode0;
|
||||
#region 机台状态及报警
|
||||
//机台状态
|
||||
//机台状态.Text = "机台状态:" + Enum.GetName(typeof(plcstatus), Init.Plcstatus);
|
||||
@@ -165,7 +183,7 @@ namespace WindowsFormsApp1
|
||||
{
|
||||
DateTime oldPlcstatus_LastTime = Init.Plcstatus_LastTime;
|
||||
//状态+报警
|
||||
if (oldstatus != PlcData.Read_Status || (Plc_Time - oldPlcstatus_LastTime).TotalSeconds >= 15)
|
||||
if (oldstatus != PlcData.Read_Status)
|
||||
{
|
||||
//反馈状态
|
||||
Init.Plcstatus = PlcData.Read_Status;
|
||||
@@ -298,10 +316,44 @@ namespace WindowsFormsApp1
|
||||
if (nowflow.dzscan)
|
||||
{
|
||||
//扫码
|
||||
ScanForm_DZ scanForm = new ScanForm_DZ();
|
||||
DialogResult scan_result = scanForm.ShowDialog();
|
||||
ChangeBarcode();
|
||||
var stationid = Init.t_Line.lineremark2;
|
||||
// ccd扫码
|
||||
if ("Assy1".Contains(stationid))
|
||||
{
|
||||
SQLiteHelper<t_keyvalue> sQLiteHelper_key = new db.SQLiteHelper<t_keyvalue>();
|
||||
var key_sqlresult = sQLiteHelper_key.QueryAll();
|
||||
|
||||
var result1 = apiClient.CallFunctionByName("SN_FeedingCheck", PlcData, new otherdata() { JS_SN = PlcData.Read_MaterialCode2 });
|
||||
if (result1.Success && result1.Mesresult == mesresult.PASS)
|
||||
{
|
||||
//继续调用接口
|
||||
var result2 = apiClient.CallFunctionByName("Link_Comp", PlcData, new otherdata() { JS_SN = PlcData.Read_MaterialCode2 });
|
||||
if (result2.Success && result2.Mesresult == mesresult.PASS)
|
||||
{
|
||||
// 写数据到 主页的barcode 数据库改,缓存改
|
||||
var txt = Init.t_Keyvalues.FirstOrDefault(a => a.key == "Barcode1");
|
||||
txt.value = PlcData.Read_MaterialCode2;
|
||||
|
||||
var code = key_sqlresult.Data.First(x => x.key == txt.key);
|
||||
code.value = PlcData.Read_MaterialCode2;
|
||||
sQLiteHelper_key.Update(code);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogExecute.logNet.WriteError($"{PlcData.Read_MaterialCode2}绑定NG");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogExecute.logNet.WriteError($"{PlcData.Read_MaterialCode2}核对NG");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ScanForm_DZ scanForm = new ScanForm_DZ();
|
||||
DialogResult scan_result = scanForm.ShowDialog();
|
||||
}
|
||||
ChangeBarcode();
|
||||
var writeresult = siemensHelp.WriteAddress(plcaddress, PlcData);
|
||||
if (!writeresult.Success)
|
||||
{
|
||||
@@ -521,7 +573,7 @@ namespace WindowsFormsApp1
|
||||
|
||||
#region 开始及结束处理按钮
|
||||
|
||||
private void 开始处理_Click(object sender, EventArgs e)
|
||||
private async void 开始处理_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (开始处理.Text == "开始处理")
|
||||
{
|
||||
@@ -690,31 +742,26 @@ namespace WindowsFormsApp1
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var thread in Init.threadHelps)
|
||||
// 禁用按钮,防止重复点击
|
||||
开始处理.Enabled = false;
|
||||
|
||||
// 显示 Loading 窗体
|
||||
LoadingForm loadingForm = new LoadingForm("正在停止处理...");
|
||||
loadingForm.Show();
|
||||
|
||||
try
|
||||
{
|
||||
if (thread.Thread.IsAlive)
|
||||
{
|
||||
// 请求取消线程
|
||||
thread.cancellationTokenSource1?.Cancel();
|
||||
thread.Thread.Join(); // 等待线程完成
|
||||
}
|
||||
thread.isrunning1 = false;
|
||||
}
|
||||
// 异步清理资源
|
||||
await Task.Run(() => CleanupResources());
|
||||
|
||||
if (Init.ScanPort != null && Init.ScanPort.IsOpen)
|
||||
// 恢复界面
|
||||
FormRecover();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Init.ScanPort?.Close();
|
||||
loadingForm.Close();
|
||||
开始处理.Enabled = true;
|
||||
}
|
||||
|
||||
if (Init.AirtightPort != null && Init.AirtightPort.IsOpen)
|
||||
{
|
||||
Init.AirtightPort?.Close();
|
||||
}
|
||||
|
||||
//Thread.Sleep(500);
|
||||
FormRecover();
|
||||
|
||||
LogExecute.logNet.WriteInfo($"用户{Init.t_User.username},停止处理!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -722,14 +769,95 @@ namespace WindowsFormsApp1
|
||||
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
|
||||
{
|
||||
// 如果已经执行过清理,则直接返回
|
||||
if (_isCleanupDone)
|
||||
return;
|
||||
//if (_isCleanupDone)
|
||||
// return;
|
||||
|
||||
//try
|
||||
//{
|
||||
// _isCleanupDone = true; // 标记清理操作已执行
|
||||
// // 给日志系统一点时间完成写入
|
||||
// System.Threading.Thread.Sleep(100);
|
||||
// // 停止所有线程
|
||||
// if (Init.threadHelps != null)
|
||||
// {
|
||||
// foreach (var thread in Init.threadHelps)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// if (thread.Thread != null && thread.Thread.IsAlive)
|
||||
// {
|
||||
// thread.cancellationTokenSource1?.Cancel();
|
||||
// }
|
||||
// }
|
||||
// catch { /* 忽略异常 */ }
|
||||
// }
|
||||
// }
|
||||
|
||||
// // 安全关闭串口
|
||||
// try
|
||||
// {
|
||||
// if (Init.ScanPort != null && Init.ScanPort.IsOpen)
|
||||
// {
|
||||
// Init.ScanPort.Close();
|
||||
// Init.ScanPort = null;
|
||||
// }
|
||||
// }
|
||||
// catch { /* 忽略异常 */ }
|
||||
|
||||
// try
|
||||
// {
|
||||
// if (Init.AirtightPort != null && Init.AirtightPort.IsOpen)
|
||||
// {
|
||||
// Init.AirtightPort.Close();
|
||||
// Init.AirtightPort = null;
|
||||
// }
|
||||
// }
|
||||
// catch { /* 忽略异常 */ }
|
||||
//}
|
||||
//catch { /* 忽略所有异常 */ }
|
||||
}
|
||||
|
||||
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
// 设置窗体正在关闭标志
|
||||
_isFormClosing = true;
|
||||
|
||||
// 如果当前正在处理中,则进行清理
|
||||
if (开始处理.Text == "停止处理" && !_isCleanupDone)
|
||||
{
|
||||
e.Cancel = true; // 取消关闭
|
||||
|
||||
// 显示 Loading 窗体
|
||||
LoadingForm loadingForm = new LoadingForm("正在关闭程序...");
|
||||
loadingForm.Show();
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
_isCleanupDone = true;
|
||||
CleanupResources();
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.Invoke((Action)(() =>
|
||||
{
|
||||
loadingForm.Close();
|
||||
this.Close(); // 重新触发关闭
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 添加一个清理资源的私有方法
|
||||
private void CleanupResources()
|
||||
{
|
||||
try
|
||||
{
|
||||
_isCleanupDone = true; // 标记清理操作已执行
|
||||
// 给日志系统一点时间完成写入
|
||||
System.Threading.Thread.Sleep(100);
|
||||
// 停止状态上报定时器
|
||||
statusReportTimer.Stop();
|
||||
|
||||
// 停止所有线程
|
||||
if (Init.threadHelps != null)
|
||||
{
|
||||
@@ -740,7 +868,9 @@ namespace WindowsFormsApp1
|
||||
if (thread.Thread != null && thread.Thread.IsAlive)
|
||||
{
|
||||
thread.cancellationTokenSource1?.Cancel();
|
||||
thread.Thread.Join(); // 等待线程完成
|
||||
}
|
||||
thread.isrunning1 = false;
|
||||
}
|
||||
catch { /* 忽略异常 */ }
|
||||
}
|
||||
@@ -766,29 +896,15 @@ namespace WindowsFormsApp1
|
||||
}
|
||||
}
|
||||
catch { /* 忽略异常 */ }
|
||||
|
||||
// 记录日志
|
||||
LogExecute.logNet.WriteInfo($"用户{Init.t_User.username},停止处理!");
|
||||
// 给日志系统一点时间完成写入
|
||||
System.Threading.Thread.Sleep(100);
|
||||
}
|
||||
catch { /* 忽略所有异常 */ }
|
||||
}
|
||||
|
||||
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
// 设置窗体正在关闭标志
|
||||
_isFormClosing = true;
|
||||
|
||||
// 如果当前正在处理中,则记录日志
|
||||
if (开始处理.Text == "停止处理")
|
||||
{
|
||||
try
|
||||
{
|
||||
LogExecute.logNet.WriteInfo($"用户{Init.t_User.username},程序关闭时自动停止处理!");
|
||||
// 给日志系统一点时间完成写入
|
||||
System.Threading.Thread.Sleep(100);
|
||||
}
|
||||
catch { /* 忽略异常 */ }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region 页面按钮-跳转
|
||||
private void 扭力角度扭矩设置ToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
@@ -1117,7 +1233,7 @@ namespace WindowsFormsApp1
|
||||
|
||||
// 设置事件结果
|
||||
resultLabel.Text = $"{(result == mesresult.PASS ? "PASS" : "FAIL")}";
|
||||
resultLabel.ForeColor = result == mesresult.PASS ? Color.Green : Color.Red;
|
||||
resultLabel.BackColor = result == mesresult.PASS ? Color.Green : Color.Red;
|
||||
resultLabel.Visible = true;
|
||||
|
||||
// 设置事件时间
|
||||
@@ -1285,6 +1401,40 @@ namespace WindowsFormsApp1
|
||||
}
|
||||
#endregion
|
||||
|
||||
// 添加状态上报定时器的事件处理方法
|
||||
private void StatusReportTimer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 如果没有PLC数据或者状态为0,则不上报
|
||||
if (Init.Plcstatus == 0)
|
||||
return;
|
||||
|
||||
otherdata statusOtherData = new otherdata();
|
||||
statusOtherData.Plc_Status = Init.Plcstatus;
|
||||
|
||||
var statusResult = statusApiClient.CallFunctionByName("Status", null, statusOtherData);
|
||||
if (statusResult.Success)
|
||||
{
|
||||
MES_MsgfORM("Status", statusResult, statusResult.Requesttime);
|
||||
|
||||
// 更新最后上报时间
|
||||
Init.Plcstatus_LastTime = DateTime.Now;
|
||||
|
||||
LogExecute.logNet.WriteDebug($"定时上报机台状态成功: {Init.Plcstatus}");
|
||||
}
|
||||
else
|
||||
{
|
||||
//MES链接状态.Text = "MES链接状态:NG";
|
||||
//MES链接状态.BackColor = Color.Red;
|
||||
LogExecute.logNet.WriteError($"定时上报机台状态失败: MES通讯异常!");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogExecute.logNet.WriteError($"定时上报机台状态异常: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ namespace WindowsFormsApp1
|
||||
public ImageDisplayForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
SetCurrentName("123");
|
||||
SetCurrentName("test");
|
||||
|
||||
// 初始化自动更新定时器
|
||||
autoUpdateTimer = new Timer();
|
||||
@@ -153,19 +153,31 @@ namespace WindowsFormsApp1
|
||||
// 标记位置
|
||||
if (originalImage != null)
|
||||
{
|
||||
DrawMark(pos.x, pos.y);
|
||||
isBlinking = true;
|
||||
isBlinking = true; // 设置为 true 后不再切换
|
||||
currentRadius = MIN_RADIUS; // 重置半径
|
||||
blinkTimer.Start();
|
||||
DrawMark(pos.x, pos.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 记录错误但不显示消息框,避免频繁弹窗
|
||||
Console.WriteLine($"查询坐标失败:{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private float breathScale = 1.0f; // 添加这个字段到类的顶部
|
||||
private const float MIN_SCALE = 0.6f;
|
||||
private const float MAX_SCALE = 1.4f;
|
||||
private bool scaleIncreasing = true;
|
||||
|
||||
// 修改半径相关的常量
|
||||
private float currentRadius = 20f; // 增大初始半径
|
||||
private const float MIN_RADIUS = 20f; // 最小半径
|
||||
private const float MAX_RADIUS = 50f; // 增大最大半径
|
||||
private bool isExpanding = true;
|
||||
private const float RADIUS_CHANGE_SPEED = 2f;
|
||||
|
||||
private void DrawMark(int x, int y)
|
||||
{
|
||||
markedImage = new Bitmap(originalImage);
|
||||
@@ -173,14 +185,37 @@ namespace WindowsFormsApp1
|
||||
{
|
||||
if (isBlinking)
|
||||
{
|
||||
// 绘制放大加粗的红色感叹号
|
||||
using (Brush brush = new SolidBrush(Color.Red))
|
||||
using (Pen pen = new Pen(Color.Red, 4)) // 加粗线条
|
||||
// 设置高质量绘图模式
|
||||
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
|
||||
|
||||
// 只绘制白色圆
|
||||
using (Brush whiteBrush = new SolidBrush(Color.Yellow))
|
||||
{
|
||||
// 放大的感叹号圆点
|
||||
g.FillEllipse(brush, x - 6, y + 8, 12, 12);
|
||||
// 放大的感叹号竖线
|
||||
g.DrawLine(pen, x, y - 20, x, y);
|
||||
g.FillEllipse(whiteBrush,
|
||||
x - currentRadius,
|
||||
y - currentRadius,
|
||||
currentRadius * 2,
|
||||
currentRadius * 2);
|
||||
}
|
||||
|
||||
// 更新半径
|
||||
if (isExpanding)
|
||||
{
|
||||
currentRadius += RADIUS_CHANGE_SPEED;
|
||||
if (currentRadius >= MAX_RADIUS)
|
||||
{
|
||||
currentRadius = MAX_RADIUS;
|
||||
isExpanding = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
currentRadius -= RADIUS_CHANGE_SPEED;
|
||||
if (currentRadius <= MIN_RADIUS)
|
||||
{
|
||||
currentRadius = MIN_RADIUS;
|
||||
isExpanding = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -189,7 +224,7 @@ namespace WindowsFormsApp1
|
||||
|
||||
private void BlinkTimer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
isBlinking = !isBlinking;
|
||||
// 移除 isBlinking 切换,保持为 true
|
||||
if (!int.TryParse(txtX.Text, out int x) || !int.TryParse(txtY.Text, out int y))
|
||||
return;
|
||||
DrawMark(x, y);
|
||||
@@ -490,8 +525,7 @@ namespace WindowsFormsApp1
|
||||
this.pictureBox.Click += new System.EventHandler(this.PictureBox_Click);
|
||||
//
|
||||
// blinkTimer
|
||||
//
|
||||
this.blinkTimer.Interval = 500;
|
||||
this.blinkTimer.Interval = 50; // 修改为50毫秒
|
||||
this.blinkTimer.Tick += new System.EventHandler(this.BlinkTimer_Tick);
|
||||
//
|
||||
// ImageDisplayForm
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using WindowsFormsApp1.db;
|
||||
using WindowsFormsApp1.mod;
|
||||
|
||||
namespace WindowsFormsApp1
|
||||
{
|
||||
public partial class LoadingForm : Form
|
||||
{
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// LoadingForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(300, 100);
|
||||
this.Name = "LoadingForm";
|
||||
this.Text = "LoadingForm";
|
||||
this.ResumeLayout(false);
|
||||
}
|
||||
|
||||
public LoadingForm(string message = "正在处理中...")
|
||||
{
|
||||
InitializeComponent();
|
||||
this.StartPosition = FormStartPosition.CenterScreen;
|
||||
this.FormBorderStyle = FormBorderStyle.None;
|
||||
this.Size = new Size(300, 100);
|
||||
this.BackColor = Color.White;
|
||||
this.TopMost = true; // 设置窗体始终显示在最顶层
|
||||
this.ShowInTaskbar = false; // 不在任务栏显示
|
||||
|
||||
Label loadingLabel = new Label();
|
||||
loadingLabel.Text = message;
|
||||
loadingLabel.AutoSize = false;
|
||||
loadingLabel.Size = new Size(280, 30);
|
||||
loadingLabel.TextAlign = ContentAlignment.MiddleCenter;
|
||||
loadingLabel.Location = new Point((this.Width - loadingLabel.Width) / 2,
|
||||
(this.Height - loadingLabel.Height) / 2);
|
||||
this.Controls.Add(loadingLabel);
|
||||
}
|
||||
|
||||
protected override CreateParams CreateParams
|
||||
{
|
||||
get
|
||||
{
|
||||
CreateParams cp = base.CreateParams;
|
||||
cp.ClassStyle |= 0x20000; // CS_DROPSHADOW
|
||||
return cp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,7 +87,7 @@ namespace WindowsFormsApp1.server
|
||||
headers.Add("泄漏量");
|
||||
break;
|
||||
case "potting":
|
||||
case "thermalaste":
|
||||
case "thermapaste":
|
||||
headers.Add("胶重");
|
||||
break;
|
||||
case "vacuum":
|
||||
@@ -155,7 +155,7 @@ namespace WindowsFormsApp1.server
|
||||
// 回写对应PLC
|
||||
if (statusCode > 0)
|
||||
PlcData.Write_Status = (short)statusCode;
|
||||
if (eventName == "SN_Release")
|
||||
if (eventName == "SN_Release" || eventName == "SN_CheckIn")
|
||||
PlcData.Write_stSN = res.SN.Value;
|
||||
if (eventName == "SN_FeedingCheck")
|
||||
{
|
||||
@@ -208,9 +208,9 @@ namespace WindowsFormsApp1.server
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogExecute.logNet.WriteError($"{eventName} 接口请求失败: {ex.Message}");
|
||||
return ApiFormResult.Sucess(mesresult.PASS, true, "PASS", PlcData, DateTime.Now);
|
||||
//return ApiFormResult.Sucess(mesresult.PASS, true, "PASS", PlcData, DateTime.Now);
|
||||
|
||||
//throw new Exception(ex.Message);
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData, DateTime.Now);
|
||||
}
|
||||
@@ -280,6 +280,7 @@ namespace WindowsFormsApp1.server
|
||||
/// <returns></returns>
|
||||
public ApiFormResult SN_FeedingCheck(string url, plcdata PlcData, otherdata OtherData)
|
||||
{
|
||||
OtherData.JS_SN = PlcData.Read_MaterialCode2;
|
||||
//判断是否为胶水站,是查询materialscan中上线的胶水码
|
||||
var station = Init.t_Line.lineremark2.ToLower();
|
||||
switch (station)
|
||||
@@ -333,6 +334,8 @@ namespace WindowsFormsApp1.server
|
||||
/// <returns></returns>
|
||||
public ApiFormResult Link_Comp(string url, plcdata PlcData, otherdata OtherData)
|
||||
{
|
||||
|
||||
OtherData.JS_SN = PlcData.Read_MaterialCode2;
|
||||
// 组装 request json
|
||||
var request = new
|
||||
{
|
||||
@@ -832,7 +835,7 @@ namespace WindowsFormsApp1.server
|
||||
{
|
||||
dcInfo = new DCInfoItem();
|
||||
dcInfo.Item = stationid == "CCD" ? "CCD" : $"{Init.t_Line.lineremark2}_CCD";
|
||||
dcInfo.Value = PlcData.Read_UploadData0.ToString();
|
||||
dcInfo.Value = logresult;
|
||||
dcInfo.Result = result;
|
||||
sninfo.DC_INFO.Add(dcInfo);
|
||||
if (!"Assy2,Assy3".Contains(stationid))
|
||||
@@ -1128,6 +1131,7 @@ namespace WindowsFormsApp1.server
|
||||
public const int Fail = 1001;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region checkout class
|
||||
// 根对象类
|
||||
|
||||
Reference in new issue
Block a user