5 Commits

Author SHA1 Message Date
TD
8a0668ed96 解决合并冲突 2025-04-11 11:52:29 +08:00
TD
e31a890b06 修改图片保存路径 2025-04-11 11:47:29 +08:00
428896dbf8 修改保存相机原图和保存结果图命名一致 2025-04-11 11:09:55 +08:00
TD
f9d472295b 1 2025-04-11 10:42:40 +08:00
4765e0e5bd 修改统计 2025-04-10 14:08:55 +08:00
13 changed files with 920 additions and 333 deletions

View File

@ -343,7 +343,18 @@ namespace DH.Commons.Base
}
// 其他方法保持原有逻辑
public Action<DateTime, CameraBase, Mat> OnHImageOutput { get; set; }
public MatSet CopyImageSet(MatSet srcSet)
{
MatSet imageSet = new MatSet
{
Id = srcSet.Id,
_mat = srcSet._mat.Clone(),
// ImageSaveOption = srcSet.ImageSaveOption.Copy(),
ImageTime = srcSet.ImageTime
};
return imageSet;
}
public Action<DateTime, CameraBase, MatSet> OnHImageOutput { get; set; }
public virtual bool CameraConnect() { return false; }

View File

@ -509,7 +509,7 @@ namespace DH.Commons.Base
private AntList<SizeTreatParam> _sizeTreatParamList = new AntList<SizeTreatParam>();
private CustomizedPoint _showLocation = new CustomizedPoint();
private string _imageSaveDirectory="D://Images";
private string _imageSaveDirectory= "D://PROJECTS//Images//";
private bool _saveOKOriginal = false;
private bool _saveNGOriginal = false;
private bool _saveOKDetect = false;

View File

@ -305,7 +305,7 @@ namespace DH.Commons.Base
//if (InitialConfig.IsEnableLog)
//{
// LoggerHelper.LogAsync(msg);
LoggerHelper.LogAsync(msg);
//}
}

View File

@ -36,7 +36,7 @@ namespace DH.Commons.Base
public HTuple hv_ModelID;
public abstract DetectStationResult RunInference(Mat originImgSet, string detectionId = null);
public abstract DetectStationResult RunInference(MatSet originImgSet, string detectionId = null);
//public abstract void SaveDetectResultAsync(DetectStationResult detectResult);

View File

@ -12,6 +12,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AntdUI" Version="1.8.9" />

View File

@ -375,6 +375,22 @@ namespace DH.Commons.Enums
[Description("异常")]
DSExcept = 32
}
public enum RunState
{
[ColorSelect("Gold")]
[Description("空闲")]
Idle = 1,
[ColorSelect("Lime")]
[Description("运行中")]
Running = 2,
[ColorSelect("Gray")]
[Description("停止")]
Stop = 3,
[ColorSelect("Red")]
[Description("宕机")]
Down = 99,
}
public enum PriorityDirection
{
X,

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DH.Commons.Models
{
public class CameraSummary
{
public string CameraName { get; set; } // 相机名称
public int TiggerCount { get; set; } //触发数
public int OKCount { get; set; } // OK 数
public int NGCount { get; set; } // NG 数
public int TotalCount => OKCount + NGCount; // 总检测数量
public string YieldStr => $"{Yield:f2} %"; // 良率(字符串形式)
public double Yield => OKCount + NGCount > 0 ? (double)OKCount / (OKCount + NGCount) * 100 : 0;
}
public class ProductSummary
{
public int ProductAmount { get; set; }
public string ResultDesc { get; set; }
public string PercentStr { get; set; }
}
}

View File

@ -1,4 +1,5 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection.Metadata;
using System.Xml.Linq;
@ -372,7 +373,9 @@ namespace DH.Devices.Camera
};
InitialImageSet(imageSet);
OnHImageOutput?.Invoke(DateTime.Now, this, smat);
var outImgSet = CopyImageSet(imageSet);
OnHImageOutput?.Invoke(DateTime.Now, this, outImgSet);
//存图
DisplayAndSaveOriginImage(imageSet.Id,SnapshotCount);

View File

@ -368,7 +368,7 @@ namespace DH.Devices.Camera
throw new NotSupportedException($"Unsupported pixel type: {pFrameInfo.enPixelType}");
}
OnHImageOutput?.Invoke(DateTime.Now, this, cvImage);
//OnHImageOutput?.Invoke(DateTime.Now, this, cvImage);
}
catch (Exception ex)

View File

@ -41,7 +41,7 @@ namespace DH.Devices.PLC
{
try
{
LoggerHelper.LogPath = "D://";
LoggerHelper.LogPath = "D://PROJECTS//Logs//";
LoggerHelper.LogPrefix = "PLC";
TcpNet.IpAddress = IP;

View File

@ -58,7 +58,7 @@ namespace DH.Devices.Vision
//{
// LogAsync(new LogMsg(dt, LogLevel.Error, msg));
//}
public override DetectStationResult RunInference(Mat originImgSet, string detectionId = null)
public override DetectStationResult RunInference(MatSet originImgSet, string detectionId = null)
{
DetectStationResult detectResult = new DetectStationResult();
DetectionConfig detectConfig = null;
@ -78,19 +78,20 @@ namespace DH.Devices.Vision
//未能获得检测配置
return detectResult;
}
detectResult.Id = originImgSet.Id;
detectResult.DetectName = detectConfig.Name;
detectResult.ImageSaveDirectory=detectConfig.ImageSaveDirectory;
detectResult.SaveNGDetect=detectConfig.SaveNGDetect;
detectResult.SaveNGOriginal=detectConfig.SaveNGOriginal;
detectResult.SaveOKDetect=detectConfig.SaveOKDetect;
detectResult.SaveOKOriginal=detectConfig.SaveOKOriginal;
Mat OriginImage = originImgSet.Clone();
Mat OriginImage = originImgSet._mat.Clone();
detectResult.DetectionOriginImage = CopyBitmapWithLockBits(OriginImage.ToBitmap());
//detectResult.DetectionOriginImage = originImgSet.Clone().ToBitmap();
Stopwatch sw = new Stopwatch();
#region 1.
sw.Start();
using (Mat PreTMat = originImgSet.Clone())
using (Mat PreTMat = originImgSet._mat.Clone())
{
PreTreated(detectConfig, detectResult, PreTMat);
PreTreated2(detectConfig, detectResult, PreTMat);
@ -142,7 +143,7 @@ namespace DH.Devices.Vision
req.ResizeHeight = (int)detectConfig.ModelHeight;
// req.LabelNames = detectConfig.GetLabelNames();
// req.Score = IIConfig.Score;
req.mImage = originImgSet.Clone();
req.mImage = originImgSet._mat.Clone();
req.in_lable_path = detectConfig.In_lable_path;
@ -308,7 +309,7 @@ namespace DH.Devices.Vision
DisplayDetectionResult(detectResult, originImgSet.Clone(), detectionId);
DisplayDetectionResult(detectResult, originImgSet._mat.Clone(), detectionId);

View File

@ -41,34 +41,28 @@
tabsStas = new AntdUI.Tabs();
tabPage3 = new AntdUI.TabPage();
panel7 = new Panel();
panel5 = new Panel();
lblNowtime = new Label();
label8 = new Label();
lblstarttime = new Label();
label6 = new Label();
lblUPH = new Label();
label4 = new Label();
lblNum = new Label();
label2 = new Label();
pageHeader1 = new AntdUI.PageHeader();
lbInBackend = new AntdUI.Label();
labuph = new Label();
divider2 = new AntdUI.Divider();
tabMain = new AntdUI.TabPage();
panelmain = new AntdUI.Panel();
panel2 = new AntdUI.Panel();
splitter2 = new AntdUI.Splitter();
tabImgDisplay = new AntdUI.Tabs();
panel4 = new AntdUI.Panel();
splitter1 = new AntdUI.Splitter();
pnlLog = new AntdUI.Panel();
panel6 = new AntdUI.Panel();
lblNum2 = new Label();
label12 = new Label();
lblNowtime2 = new Label();
label10 = new Label();
lblstarttime2 = new Label();
label7 = new Label();
lblUPH2 = new Label();
tableLayoutstatistics = new TableLayoutPanel();
dgvCamreaNums = new DataGridView();
panelNums = new AntdUI.Panel();
tableLayoutNums = new TableLayoutPanel();
dgvProductNums = new DataGridView();
tableLayoutPanel3 = new TableLayoutPanel();
lblTotalTime = new Label();
label1 = new Label();
label12 = new Label();
lblUPH = new Label();
lblStartTime = new Label();
lblOEE_Total = new Label();
label10 = new Label();
label7 = new Label();
panel2 = new AntdUI.Panel();
panel1 = new AntdUI.Panel();
panel3 = new AntdUI.Panel();
btnDeleteProject = new AntdUI.Button();
@ -79,12 +73,22 @@
titlebar.SuspendLayout();
tabsStas.SuspendLayout();
tabPage3.SuspendLayout();
panel5.SuspendLayout();
pageHeader1.SuspendLayout();
panelmain.SuspendLayout();
panel2.SuspendLayout();
panel4.SuspendLayout();
((System.ComponentModel.ISupportInitialize)splitter2).BeginInit();
splitter2.Panel1.SuspendLayout();
splitter2.Panel2.SuspendLayout();
splitter2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)splitter1).BeginInit();
splitter1.Panel1.SuspendLayout();
splitter1.Panel2.SuspendLayout();
splitter1.SuspendLayout();
panel6.SuspendLayout();
tableLayoutstatistics.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dgvCamreaNums).BeginInit();
panelNums.SuspendLayout();
tableLayoutNums.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dgvProductNums).BeginInit();
tableLayoutPanel3.SuspendLayout();
panel1.SuspendLayout();
panel3.SuspendLayout();
SuspendLayout();
@ -133,7 +137,6 @@
// tabPage3
//
tabPage3.Controls.Add(panel7);
tabPage3.Controls.Add(panel5);
tabPage3.Location = new Point(3, 3);
tabPage3.Name = "tabPage3";
tabPage3.Size = new Size(574, 170);
@ -145,143 +148,9 @@
panel7.Dock = DockStyle.Fill;
panel7.Location = new Point(0, 0);
panel7.Name = "panel7";
panel7.Size = new Size(374, 170);
panel7.Size = new Size(574, 170);
panel7.TabIndex = 2;
//
// panel5
//
panel5.Controls.Add(lblNowtime);
panel5.Controls.Add(label8);
panel5.Controls.Add(lblstarttime);
panel5.Controls.Add(label6);
panel5.Controls.Add(lblUPH);
panel5.Controls.Add(label4);
panel5.Controls.Add(lblNum);
panel5.Controls.Add(label2);
panel5.Dock = DockStyle.Right;
panel5.Location = new Point(374, 0);
panel5.Name = "panel5";
panel5.Size = new Size(200, 170);
panel5.TabIndex = 1;
//
// lblNowtime
//
lblNowtime.AutoSize = true;
lblNowtime.Location = new Point(69, 41);
lblNowtime.Name = "lblNowtime";
lblNowtime.Size = new Size(15, 17);
lblNowtime.TabIndex = 7;
lblNowtime.Text = "0";
//
// label8
//
label8.AutoSize = true;
label8.Location = new Point(7, 41);
label8.Name = "label8";
label8.Size = new Size(56, 17);
label8.TabIndex = 6;
label8.Text = "此刻时间";
//
// lblstarttime
//
lblstarttime.AutoSize = true;
lblstarttime.Location = new Point(69, 15);
lblstarttime.Name = "lblstarttime";
lblstarttime.Size = new Size(15, 17);
lblstarttime.TabIndex = 5;
lblstarttime.Text = "0";
//
// label6
//
label6.AutoSize = true;
label6.Location = new Point(7, 15);
label6.Name = "label6";
label6.Size = new Size(56, 17);
label6.TabIndex = 4;
label6.Text = "开始时间";
//
// lblUPH
//
lblUPH.AutoSize = true;
lblUPH.Location = new Point(70, 105);
lblUPH.Name = "lblUPH";
lblUPH.Size = new Size(15, 17);
lblUPH.TabIndex = 3;
lblUPH.Text = "0";
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(7, 105);
label4.Name = "label4";
label4.Size = new Size(33, 17);
label4.TabIndex = 2;
label4.Text = "UPH";
//
// lblNum
//
lblNum.AutoSize = true;
lblNum.Location = new Point(70, 75);
lblNum.Name = "lblNum";
lblNum.Size = new Size(15, 17);
lblNum.TabIndex = 1;
lblNum.Text = "0";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(7, 75);
label2.Name = "label2";
label2.Size = new Size(32, 17);
label2.TabIndex = 0;
label2.Text = "总数";
//
// pageHeader1
//
pageHeader1.Controls.Add(lbInBackend);
pageHeader1.Controls.Add(labuph);
pageHeader1.Controls.Add(divider2);
pageHeader1.DividerShow = true;
pageHeader1.Dock = DockStyle.Bottom;
pageHeader1.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
pageHeader1.Location = new Point(0, 608);
pageHeader1.Name = "pageHeader1";
pageHeader1.Size = new Size(1024, 40);
pageHeader1.TabIndex = 7;
pageHeader1.Text = "UPH";
//
// lbInBackend
//
lbInBackend.BackColor = Color.Transparent;
lbInBackend.Dock = DockStyle.Right;
lbInBackend.ForeColor = Color.FromArgb(46, 108, 227);
lbInBackend.Location = new Point(949, 10);
lbInBackend.Name = "lbInBackend";
lbInBackend.Size = new Size(75, 30);
lbInBackend.TabIndex = 3;
lbInBackend.Tag = "sys-back";
lbInBackend.Text = "系统后台";
lbInBackend.Visible = false;
//
// labuph
//
labuph.AutoSize = true;
labuph.Location = new Point(59, 10);
labuph.Name = "labuph";
labuph.Size = new Size(64, 21);
labuph.TabIndex = 1;
labuph.Text = "100000";
//
// divider2
//
divider2.Dock = DockStyle.Top;
divider2.Location = new Point(0, 0);
divider2.Name = "divider2";
divider2.OrientationMargin = 0F;
divider2.Size = new Size(1024, 10);
divider2.TabIndex = 0;
divider2.Text = "";
//
// tabMain
//
tabMain.Location = new Point(3, 28);
@ -292,144 +161,289 @@
//
// panelmain
//
panelmain.Controls.Add(splitter2);
panelmain.Controls.Add(panel2);
panelmain.Controls.Add(panel4);
panelmain.Controls.Add(panel1);
panelmain.Dock = DockStyle.Fill;
panelmain.Location = new Point(0, 40);
panelmain.Margin = new Padding(0);
panelmain.Name = "panelmain";
panelmain.Size = new Size(1024, 568);
panelmain.Size = new Size(1024, 631);
panelmain.TabIndex = 8;
//
// panel2
// splitter2
//
panel2.Controls.Add(tabImgDisplay);
panel2.Dock = DockStyle.Fill;
panel2.Location = new Point(0, 68);
panel2.Name = "panel2";
panel2.Size = new Size(1024, 388);
panel2.TabIndex = 3;
panel2.Text = "panel2";
splitter2.Dock = DockStyle.Fill;
splitter2.Location = new Point(0, 68);
splitter2.Name = "splitter2";
splitter2.Orientation = Orientation.Horizontal;
//
// splitter2.Panel1
//
splitter2.Panel1.Controls.Add(tabImgDisplay);
//
// splitter2.Panel2
//
splitter2.Panel2.Controls.Add(splitter1);
splitter2.Size = new Size(1024, 563);
splitter2.SplitterDistance = 442;
splitter2.TabIndex = 4;
//
// tabImgDisplay
//
tabImgDisplay.Dock = DockStyle.Fill;
tabImgDisplay.Location = new Point(0, 0);
tabImgDisplay.Name = "tabImgDisplay";
tabImgDisplay.Size = new Size(1024, 388);
tabImgDisplay.Size = new Size(1024, 442);
tabImgDisplay.Style = styleCard1;
tabImgDisplay.TabIndex = 3;
tabImgDisplay.Text = "tabs1";
//
// panel4
// splitter1
//
panel4.Controls.Add(pnlLog);
panel4.Controls.Add(panel6);
panel4.Dock = DockStyle.Bottom;
panel4.Location = new Point(0, 456);
panel4.Name = "panel4";
panel4.Size = new Size(1024, 112);
panel4.TabIndex = 2;
panel4.Text = "panel4";
splitter1.Dock = DockStyle.Fill;
splitter1.Location = new Point(0, 0);
splitter1.Name = "splitter1";
//
// splitter1.Panel1
//
splitter1.Panel1.Controls.Add(pnlLog);
//
// splitter1.Panel2
//
splitter1.Panel2.Controls.Add(panel6);
splitter1.Size = new Size(1024, 117);
splitter1.SplitterDistance = 332;
splitter1.TabIndex = 3;
//
// pnlLog
//
pnlLog.Dock = DockStyle.Fill;
pnlLog.Location = new Point(0, 0);
pnlLog.Name = "pnlLog";
pnlLog.Size = new Size(719, 112);
pnlLog.Size = new Size(332, 117);
pnlLog.TabIndex = 2;
pnlLog.Text = "panel8";
//
// panel6
//
panel6.Controls.Add(lblNum2);
panel6.Controls.Add(label12);
panel6.Controls.Add(lblNowtime2);
panel6.Controls.Add(label10);
panel6.Controls.Add(lblstarttime2);
panel6.Controls.Add(label7);
panel6.Controls.Add(lblUPH2);
panel6.Controls.Add(label1);
panel6.Dock = DockStyle.Right;
panel6.Location = new Point(719, 0);
panel6.Controls.Add(tableLayoutstatistics);
panel6.Dock = DockStyle.Fill;
panel6.Location = new Point(0, 0);
panel6.Name = "panel6";
panel6.Size = new Size(305, 112);
panel6.Size = new Size(688, 117);
panel6.TabIndex = 0;
panel6.Text = "panel6";
//
// lblNum2
// tableLayoutstatistics
//
lblNum2.AutoSize = true;
lblNum2.Location = new Point(68, 92);
lblNum2.Name = "lblNum2";
lblNum2.Size = new Size(15, 17);
lblNum2.TabIndex = 7;
lblNum2.Text = "0";
tableLayoutstatistics.ColumnCount = 2;
tableLayoutstatistics.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
tableLayoutstatistics.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
tableLayoutstatistics.Controls.Add(dgvCamreaNums, 0, 0);
tableLayoutstatistics.Controls.Add(panelNums, 1, 0);
tableLayoutstatistics.Dock = DockStyle.Fill;
tableLayoutstatistics.Location = new Point(0, 0);
tableLayoutstatistics.Name = "tableLayoutstatistics";
tableLayoutstatistics.RowCount = 1;
tableLayoutstatistics.RowStyles.Add(new RowStyle(SizeType.Percent, 50F));
tableLayoutstatistics.Size = new Size(688, 117);
tableLayoutstatistics.TabIndex = 9;
//
// label12
// dgvCamreaNums
//
label12.AutoSize = true;
label12.Location = new Point(6, 92);
label12.Name = "label12";
label12.Size = new Size(44, 17);
label12.TabIndex = 6;
label12.Text = "总计数";
dgvCamreaNums.AllowUserToAddRows = false;
dgvCamreaNums.AllowUserToDeleteRows = false;
dgvCamreaNums.AllowUserToResizeColumns = false;
dgvCamreaNums.AllowUserToResizeRows = false;
dgvCamreaNums.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dgvCamreaNums.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
dgvCamreaNums.BackgroundColor = SystemColors.Control;
dgvCamreaNums.BorderStyle = BorderStyle.None;
dgvCamreaNums.CellBorderStyle = DataGridViewCellBorderStyle.SunkenHorizontal;
dgvCamreaNums.ColumnHeadersHeight = 25;
dgvCamreaNums.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
dgvCamreaNums.Dock = DockStyle.Fill;
dgvCamreaNums.Location = new Point(3, 15);
dgvCamreaNums.Margin = new Padding(3, 15, 3, 0);
dgvCamreaNums.MultiSelect = false;
dgvCamreaNums.Name = "dgvCamreaNums";
dgvCamreaNums.ReadOnly = true;
dgvCamreaNums.RowHeadersVisible = false;
dgvCamreaNums.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dgvCamreaNums.Size = new Size(338, 102);
dgvCamreaNums.TabIndex = 9;
//
// lblNowtime2
// panelNums
//
lblNowtime2.AutoSize = true;
lblNowtime2.Location = new Point(68, 68);
lblNowtime2.Name = "lblNowtime2";
lblNowtime2.Size = new Size(15, 17);
lblNowtime2.TabIndex = 5;
lblNowtime2.Text = "0";
panelNums.Controls.Add(tableLayoutNums);
panelNums.Dock = DockStyle.Fill;
panelNums.Location = new Point(347, 3);
panelNums.Name = "panelNums";
panelNums.Size = new Size(338, 111);
panelNums.TabIndex = 8;
panelNums.Text = "panel4";
//
// label10
// tableLayoutNums
//
label10.AutoSize = true;
label10.Location = new Point(6, 68);
label10.Name = "label10";
label10.Size = new Size(56, 17);
label10.TabIndex = 4;
label10.Text = "运行时间";
tableLayoutNums.ColumnCount = 1;
tableLayoutNums.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
tableLayoutNums.Controls.Add(dgvProductNums, 0, 0);
tableLayoutNums.Controls.Add(tableLayoutPanel3, 0, 1);
tableLayoutNums.Dock = DockStyle.Fill;
tableLayoutNums.Location = new Point(0, 0);
tableLayoutNums.Name = "tableLayoutNums";
tableLayoutNums.RowCount = 2;
tableLayoutNums.RowStyles.Add(new RowStyle(SizeType.Percent, 50F));
tableLayoutNums.RowStyles.Add(new RowStyle(SizeType.Percent, 50F));
tableLayoutNums.RowStyles.Add(new RowStyle(SizeType.Absolute, 20F));
tableLayoutNums.Size = new Size(338, 111);
tableLayoutNums.TabIndex = 8;
//
// lblstarttime2
// dgvProductNums
//
lblstarttime2.AutoSize = true;
lblstarttime2.Location = new Point(68, 37);
lblstarttime2.Name = "lblstarttime2";
lblstarttime2.Size = new Size(15, 17);
lblstarttime2.TabIndex = 3;
lblstarttime2.Text = "0";
dgvProductNums.AllowUserToAddRows = false;
dgvProductNums.AllowUserToDeleteRows = false;
dgvProductNums.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dgvProductNums.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
dgvProductNums.BackgroundColor = SystemColors.Control;
dgvProductNums.BorderStyle = BorderStyle.None;
dgvProductNums.CellBorderStyle = DataGridViewCellBorderStyle.SunkenHorizontal;
dgvProductNums.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.None;
dgvProductNums.ColumnHeadersHeight = 4;
dgvProductNums.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
dgvProductNums.ColumnHeadersVisible = false;
dgvProductNums.Dock = DockStyle.Fill;
dgvProductNums.Location = new Point(3, 10);
dgvProductNums.Margin = new Padding(3, 10, 3, 0);
dgvProductNums.MultiSelect = false;
dgvProductNums.Name = "dgvProductNums";
dgvProductNums.ReadOnly = true;
dgvProductNums.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.None;
dgvProductNums.RowHeadersVisible = false;
dgvProductNums.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dgvProductNums.Size = new Size(332, 45);
dgvProductNums.TabIndex = 10;
//
// label7
// tableLayoutPanel3
//
label7.AutoSize = true;
label7.Location = new Point(6, 37);
label7.Name = "label7";
label7.Size = new Size(56, 17);
label7.TabIndex = 2;
label7.Text = "开始时间";
tableLayoutPanel3.ColumnCount = 4;
tableLayoutPanel3.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
tableLayoutPanel3.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
tableLayoutPanel3.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
tableLayoutPanel3.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
tableLayoutPanel3.Controls.Add(lblTotalTime, 1, 1);
tableLayoutPanel3.Controls.Add(label1, 2, 1);
tableLayoutPanel3.Controls.Add(label12, 0, 1);
tableLayoutPanel3.Controls.Add(lblUPH, 3, 1);
tableLayoutPanel3.Controls.Add(lblStartTime, 1, 0);
tableLayoutPanel3.Controls.Add(lblOEE_Total, 3, 0);
tableLayoutPanel3.Controls.Add(label10, 0, 0);
tableLayoutPanel3.Controls.Add(label7, 2, 0);
tableLayoutPanel3.Dock = DockStyle.Fill;
tableLayoutPanel3.Location = new Point(3, 58);
tableLayoutPanel3.Name = "tableLayoutPanel3";
tableLayoutPanel3.RowCount = 2;
tableLayoutPanel3.RowStyles.Add(new RowStyle(SizeType.Percent, 50F));
tableLayoutPanel3.RowStyles.Add(new RowStyle(SizeType.Percent, 50F));
tableLayoutPanel3.Size = new Size(332, 50);
tableLayoutPanel3.TabIndex = 11;
//
// lblUPH2
// lblTotalTime
//
lblUPH2.AutoSize = true;
lblUPH2.Location = new Point(68, 11);
lblUPH2.Name = "lblUPH2";
lblUPH2.Size = new Size(15, 17);
lblUPH2.TabIndex = 1;
lblUPH2.Text = "0";
lblTotalTime.AutoSize = true;
lblTotalTime.Dock = DockStyle.Fill;
lblTotalTime.Location = new Point(86, 25);
lblTotalTime.Name = "lblTotalTime";
lblTotalTime.Size = new Size(77, 25);
lblTotalTime.TabIndex = 15;
lblTotalTime.Text = "0";
lblTotalTime.TextAlign = ContentAlignment.MiddleCenter;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(6, 11);
label1.Dock = DockStyle.Fill;
label1.Location = new Point(169, 25);
label1.Name = "label1";
label1.Size = new Size(33, 17);
label1.TabIndex = 0;
label1.Size = new Size(77, 25);
label1.TabIndex = 8;
label1.Text = "UPH";
label1.TextAlign = ContentAlignment.MiddleCenter;
//
// label12
//
label12.AutoSize = true;
label12.Dock = DockStyle.Fill;
label12.Location = new Point(3, 25);
label12.Name = "label12";
label12.Size = new Size(77, 25);
label12.TabIndex = 14;
label12.Text = "运行时间";
label12.TextAlign = ContentAlignment.MiddleCenter;
//
// lblUPH
//
lblUPH.AutoSize = true;
lblUPH.Dock = DockStyle.Fill;
lblUPH.Location = new Point(252, 25);
lblUPH.Name = "lblUPH";
lblUPH.Size = new Size(77, 25);
lblUPH.TabIndex = 9;
lblUPH.Text = "0";
lblUPH.TextAlign = ContentAlignment.MiddleCenter;
//
// lblStartTime
//
lblStartTime.AutoSize = true;
lblStartTime.Dock = DockStyle.Fill;
lblStartTime.Location = new Point(86, 0);
lblStartTime.Name = "lblStartTime";
lblStartTime.Size = new Size(77, 25);
lblStartTime.TabIndex = 11;
lblStartTime.Text = "0";
lblStartTime.TextAlign = ContentAlignment.MiddleCenter;
//
// lblOEE_Total
//
lblOEE_Total.AutoSize = true;
lblOEE_Total.Dock = DockStyle.Fill;
lblOEE_Total.Location = new Point(252, 0);
lblOEE_Total.Name = "lblOEE_Total";
lblOEE_Total.Size = new Size(77, 25);
lblOEE_Total.TabIndex = 13;
lblOEE_Total.Text = "0";
lblOEE_Total.TextAlign = ContentAlignment.MiddleCenter;
//
// label10
//
label10.AutoSize = true;
label10.Dock = DockStyle.Fill;
label10.Location = new Point(3, 0);
label10.Name = "label10";
label10.Size = new Size(77, 25);
label10.TabIndex = 12;
label10.Text = "开始时间";
label10.TextAlign = ContentAlignment.MiddleCenter;
//
// label7
//
label7.AutoSize = true;
label7.Dock = DockStyle.Fill;
label7.Location = new Point(169, 0);
label7.Name = "label7";
label7.Size = new Size(77, 25);
label7.TabIndex = 10;
label7.Text = "总计数";
label7.TextAlign = ContentAlignment.MiddleCenter;
//
// panel2
//
panel2.Location = new Point(511, 86);
panel2.Name = "panel2";
panel2.Size = new Size(814, 364);
panel2.TabIndex = 3;
panel2.Text = "panel2";
//
// panel1
//
@ -582,10 +596,9 @@
//
// MainWindow
//
ClientSize = new Size(1024, 648);
ClientSize = new Size(1024, 671);
ControlBox = false;
Controls.Add(panelmain);
Controls.Add(pageHeader1);
Controls.Add(titlebar);
Font = new Font("Microsoft YaHei UI", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
Icon = (Icon)resources.GetObject("$this.Icon");
@ -598,15 +611,23 @@
titlebar.ResumeLayout(false);
tabsStas.ResumeLayout(false);
tabPage3.ResumeLayout(false);
panel5.ResumeLayout(false);
panel5.PerformLayout();
pageHeader1.ResumeLayout(false);
pageHeader1.PerformLayout();
panelmain.ResumeLayout(false);
panel2.ResumeLayout(false);
panel4.ResumeLayout(false);
splitter2.Panel1.ResumeLayout(false);
splitter2.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)splitter2).EndInit();
splitter2.ResumeLayout(false);
splitter1.Panel1.ResumeLayout(false);
splitter1.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)splitter1).EndInit();
splitter1.ResumeLayout(false);
panel6.ResumeLayout(false);
panel6.PerformLayout();
tableLayoutstatistics.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dgvCamreaNums).EndInit();
panelNums.ResumeLayout(false);
tableLayoutNums.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dgvProductNums).EndInit();
tableLayoutPanel3.ResumeLayout(false);
tableLayoutPanel3.PerformLayout();
panel1.ResumeLayout(false);
panel3.ResumeLayout(false);
ResumeLayout(false);
@ -615,12 +636,9 @@
#endregion
private AntdUI.PageHeader titlebar;
private AntdUI.PageHeader pageHeader1;
private AntdUI.Divider divider2;
private AntdUI.Panel panelmain;
private AntdUI.Panel panel1;
private AntdUI.Segmented segmented1;
private Label labuph;
private AntdUI.Splitter splitter1;
private AntdUI.Label lbName;
@ -630,31 +648,40 @@
private AntdUI.Button btnLoadProject;
public AntdUI.Select sltProjects;
private Panel panel7;
private Panel panel5;
private Label lblNum;
private Label label2;
private Label lblNowtime;
private Label label8;
private Label lblstarttime;
private Label label6;
private Label lblUPH;
// private Panel panel5;
// private Label lblNum;
// private Label label2;
// private Label lblNowtime;
// private Label label8;
// private Label lblstarttime;
// private Label label6;
// private Label lblUPH;
private Label label4;
private AntdUI.TabPage tabPage3;
private AntdUI.TabPage tabMain;
private AntdUI.Tabs tabsStas;
private Label label1;
private AntdUI.Panel panel2;
private AntdUI.Panel panel4;
private AntdUI.Tabs tabImgDisplay;
private AntdUI.Panel panel6;
private Label lblUPH2;
private Label lblNum2;
private AntdUI.Panel pnlLog;
private AntdUI.Splitter splitter2;
private TableLayoutPanel tableLayoutstatistics;
private AntdUI.Panel panelNums;
private DataGridView dgvCamreaNums;
private TableLayoutPanel tableLayoutNums;
private Label label1;
private Label lblTotalTime;
private Label lblUPH;
private Label label12;
private Label lblNowtime2;
private Label label7;
private Label lblOEE_Total;
private Label lblStartTime;
private Label label10;
private Label lblstarttime2;
private Label label7;
private AntdUI.Panel pnlLog;
private AntdUI.Label lbInBackend;
private DataGridView dgvProductNums;
private TableLayoutPanel tableLayoutPanel3;
}
}

View File

@ -23,9 +23,11 @@ using System;
using System.CodeDom;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
@ -37,6 +39,7 @@ using static DH.Commons.Enums.EnumHelper;
using Camera = DHSoftware.Models.Camera;
using LogLevel = DH.Commons.Enums.EnumHelper.LogLevel;
using ResultState = DH.Commons.Base.ResultState;
using Timer = System.Threading.Timer;
namespace DHSoftware
{
@ -44,6 +47,13 @@ namespace DHSoftware
{
private Dictionary<string, List<string>> _cameraRelatedDetectionDict = null;
public event Action<LogMsg> OnLog;
public List<CameraSummary> CameraSummaries { get; set; } = new List<CameraSummary>();
public List<ProductSummary> ProductSummaries = new List<ProductSummary>();
static object _productSummaryLock = new object();
public event Action<DateTime, object, string> OnUpdateResult;
public event Action<DateTime, object, string> OnUpdateCamResult;
private string _loginName;
public string LoginName
@ -261,8 +271,7 @@ namespace DHSoftware
public MainWindow()
{
InitializeComponent();
//refreshTimer.Start();
//refreshTimer.Start();
//初始化数据
InitData();
//绑定事件
@ -273,6 +282,317 @@ namespace DHSoftware
//userControlFrm.Dock = DockStyle.Fill;
//tabPage2.Controls.Add(userControlFrm);
}
//#region OEE
// public event Action<RunState> OnProcessRunStateChanged;
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
public virtual void Set<T>(ref T field, T newValue, [CallerMemberName] string propName = null)
{
if (!field.Equals(newValue))
{
field = newValue;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
}
}
#endregion
#region Properties
private int uph = 0;
private int upm = 0;
private DateTime? startTime = null;
private TimeSpan runTime = new TimeSpan();
private TimeSpan idleTime = new TimeSpan();
private TimeSpan downTime = new TimeSpan();
private TimeSpan totalTime = new TimeSpan();
private int qty_OEE = 0;
private int qty_OEE_OK = 0;
private float oee = 0;
public int UPH
{
get => uph;
set => Set(ref uph, value);
}
public int UPM
{
get => upm;
set => Set(ref upm, value);
}
public DateTime? StartTime
{
get => startTime;
set => Set(ref startTime, value);
}
/// <summary>
/// 有效运行时间
/// </summary>
public TimeSpan RunTime
{
get => runTime;
set => Set(ref runTime, value);
}
/// <summary>
/// 空闲待机时间
/// </summary>
public TimeSpan IdleTime
{
get => idleTime;
set => Set(ref idleTime, value);
}
/// <summary>
/// 故障宕机时间
/// </summary>
public TimeSpan DownTime
{
get => downTime;
set => Set(ref downTime, value);
}
/// <summary>
/// 总开机时间
/// </summary>
public TimeSpan TotalTime
{
get => totalTime;
set => Set(ref totalTime, value);
}
public float OEE
{
get => oee;
set => Set(ref oee, value);
}
#endregion
#region Timer
System.Threading.Timer _runTimer = null;
System.Threading.Timer _idleTimer = null;
System.Threading.Timer _downTimer = null;
System.Threading.Timer _checkIdleTimer = null;
//System.Threading.Timer _calculateTimer = null;
private RunState? currentState = null;
public RunState? CurrentState
{
get => currentState;
set
{
if (value != null)
{
if (value.Value == RunState.Running)
{
_checkIdleTimer?.Change(10 * 1000, -1);
}
if (currentState != value.Value)
{
switch (currentState)
{
case RunState.Idle:
//AddRunEventInBuffer(DateTime.Now, RunEvent_EventType.Idle, false);
break;
case RunState.Down:
//AddRunEventInBuffer(DateTime.Now, RunEvent_EventType.Down, false);
break;
}
switch (value.Value)
{
case RunState.Stop:
_runTimer?.Change(-1, -1);
_idleTimer?.Change(-1, -1);
_downTimer?.Change(-1, -1);
break;
case RunState.Running:
_idleTimer?.Change(-1, -1);
_downTimer?.Change(-1, -1);
_runTimer?.Change(0, 1000);
break;
case RunState.Idle:
_runTimer?.Change(-1, -1);
_downTimer?.Change(-1, -1);
_idleTimer?.Change(0, 1000);
//AddRunEventInBuffer(DateTime.Now, RunEvent_EventType.Idle, true);
break;
case RunState.Down:
_idleTimer?.Change(-1, -1);
_runTimer?.Change(-1, -1);
_downTimer?.Change(0, 1000);
//AddRunEventInBuffer(DateTime.Now, RunEvent_EventType.Down, true);
break;
}
currentState = value;
}
}
}
}
private void CheckIdleTimeStart(object state)
{
if (CurrentState == RunState.Running)
{
RunTime = RunTime.Add(new TimeSpan(0, 0, 0 - 10));
IdleTime = IdleTime.Add(new TimeSpan(0, 0, 10));
CurrentState = RunState.Idle;
}
}
public void InitialOEEStatistic()
{
InitialStatisticTimers();
ResetOEETimeDistribute();
ResetProductSummaries();
}
public void ResetProductSummaries()
{
ProductSummaries = new List<ProductSummary>();
}
private void InitialStatisticTimers()
{
if (_checkIdleTimer == null)
{
_checkIdleTimer = new Timer(new TimerCallback(CheckIdleTimeStart), null, -1, -1);
}
if (_runTimer == null)
{
_runTimer = new System.Threading.Timer(RunTimerCallBack, null, -1, -1);
}
if (_idleTimer == null)
{
_idleTimer = new System.Threading.Timer(IdleTimerCallBack, null, -1, -1);
}
if (_downTimer == null)
{
_downTimer = new System.Threading.Timer(DownTimerCallBack, null, -1, -1);
}
StartTime = DateTime.Now;
DownTime = IdleTime = RunTime = new TimeSpan(0, 0, 0);
CurrentState = RunState.Running;
}
private void DownTimerCallBack(object state)
{
DownTime = DownTime.Add(new TimeSpan(0, 0, 1));
GetTotalTime();
}
private void IdleTimerCallBack(object state)
{
IdleTime = IdleTime.Add(new TimeSpan(0, 0, 1));
GetTotalTime();
}
private void RunTimerCallBack(object state)
{
RunTime = RunTime.Add(new TimeSpan(0, 0, 1));
GetTotalTime();
}
private void GetTotalTime()
{
TotalTime = RunTime + IdleTime + DownTime;
}
public void ResetOEETimeDistribute()
{
StartTime = DateTime.Now;
DownTime = IdleTime = RunTime = new TimeSpan(0, 0, 0);
ProductNum_Total = ProductNum_OK = 0;
}
public void CloseStatisticTimers()
{
CloseTimer(ref _checkIdleTimer);
CloseTimer(ref _runTimer);
CloseTimer(ref _idleTimer);
CloseTimer(ref _downTimer);
CurrentState = RunState.Stop;
}
private void CloseTimer(ref System.Threading.Timer timer)
{
timer?.Change(-1, -1);
timer?.Dispose();
timer = null;
}
#endregion
#region CameraSum
private void InitialCameraSumsView()
{
dgvProductNums.AutoGenerateColumns = false;
dgvProductNums.DefaultCellStyle.Font = new Font("Tahoma", 12, FontStyle.Regular, GraphicsUnit.World);
dgvProductNums.DataSource = null;
dgvProductNums.DataSource = ProductSummaries;
dgvCamreaNums.AutoGenerateColumns = false;
dgvCamreaNums.DefaultCellStyle.Font = new Font("Tahoma", 12, FontStyle.Regular, GraphicsUnit.World);
dgvCamreaNums.DataSource = null;
dgvCamreaNums.Columns.Clear();
// 添加 CCD 列
dgvCamreaNums.Columns.Add(new DataGridViewTextBoxColumn
{
HeaderText = "CCD",
DataPropertyName = "CameraName"
});
// 添加 合格 列
var okColumn = new DataGridViewTextBoxColumn
{
HeaderText = "合格",
DataPropertyName = "OKCount"
};
okColumn.DefaultCellStyle.ForeColor = Color.LightGreen; // 设置背景为绿色
dgvCamreaNums.Columns.Add(okColumn);
// 添加 不合格 列
var ngColumn = new DataGridViewTextBoxColumn
{
HeaderText = "不合格",
DataPropertyName = "NGCount"
};
ngColumn.DefaultCellStyle.ForeColor = Color.LightCoral; // 设置背景为红色
dgvCamreaNums.Columns.Add(ngColumn);
// 添加 总数 列
dgvCamreaNums.Columns.Add(new DataGridViewTextBoxColumn
{
HeaderText = "总数",
DataPropertyName = "TotalCount"
});
// 添加 良率 列
dgvCamreaNums.Columns.Add(new DataGridViewTextBoxColumn
{
HeaderText = "良率",
DataPropertyName = "YieldStr"
});
dgvCamreaNums.DataSource = new BindingList<CameraSummary>(CameraSummaries);
}
#endregion
/// <summary>
/// 窗体对象实例
@ -359,7 +679,7 @@ namespace DHSoftware
cam.CameraName = cameraBase.CameraName;
cam.CameraIP = cameraBase.CameraIP;
cam.IsEnabled = cameraBase.IsEnabled;
cam.ImageSaveDirectory = "D://Cam1//";
cam.ImageSaveDirectory = Path.Combine("D://Projects", cameraBase.CameraName);
Cameras.Add(cam);
if(cameraBase.IsEnabled)
{
@ -378,7 +698,7 @@ namespace DHSoftware
cam.IsEnabled = cameraBase.IsEnabled;
HKCameras.Add(cam);
// cam.CameraConnect();
cam.OnHImageOutput += OnCameraHImageOutput;
//cam.OnHImageOutput += OnCameraHImageOutput;
}
}
}
@ -424,6 +744,7 @@ namespace DHSoftware
detectionConfig.ModelHeight = detection.ModelHeight;
detectionConfig.In_lable_path = detection.In_lable_path;
detectionConfig.IsEnabled = detection.IsEnabled;
detectionConfig.ImageSaveDirectory = "D://Projects//Images";
detectionConfig.ShowLocation.X = (i + 1) % 5 + (i + 1) / 5;
// detectionConfig.ShowLocation.X = detection.ShowLocation.X;
@ -459,6 +780,8 @@ namespace DHSoftware
//
_visionEngine = new SimboVisionDriver();
_visionEngine.DetectionConfigs = DetectionConfigs;
_visionEngine.LoggerHelper .LogPath = "D://PROJECTS//Logs//";
_visionEngine.LoggerHelper.LogPrefix = "Vision";
_visionEngine.OnLog += _visionEngine_OnLog;
//初始化模型 加载模型
_visionEngine.Init();
@ -471,7 +794,7 @@ namespace DHSoftware
private void _visionEngine_OnLog(LogMsg msg)
{
OnLog?.Invoke(msg);
//OnLog?.Invoke(msg);
LogDisplay(msg);
}
private void LogDisplay(LogMsg msg)
@ -504,12 +827,13 @@ namespace DHSoftware
LogAsync(new LogMsg(dt, logLevel, msg));
}
System.Windows.Forms.Timer _refreshUITimer = new System.Windows.Forms.Timer();
private void BindEventHandler()
{
btnAddProject.Click += BtnAddProject_Click;
btnDeleteProject.Click += BtnDeleteProject_Click;
btnLoadProject.Click += BtnLoadProject_Click;
LoggerHelper.LogPath = "D://";
LoggerHelper.LogPath = "D://PROJECTS//Logs//";
LoggerHelper.LogPrefix = "Process";
OnLog -= LogDisplay;
OnLog += LogDisplay;
@ -520,6 +844,67 @@ namespace DHSoftware
private void LbInBackend_Click(object? sender, EventArgs e)
{
DH.RBAC.RBACWindow.Instance.Show();
OnUpdateCamResult -= UpdateCamResult;
OnUpdateCamResult += UpdateCamResult;
OnUpdateResult -= UpdateResult;
OnUpdateResult += UpdateResult;
Load += (s, e) =>
{
_refreshUITimer.Interval = 1000;
_refreshUITimer.Tick += _refreshUITimer_Tick;
_refreshUITimer.Enabled = true;
};
}
private void _refreshUITimer_Tick(object sender, EventArgs e)
{
_refreshUITimer.Enabled = false;
if (this != null)
{
lblStartTime.Text = StartTime == null ? "" : StartTime.Value.ToString("yyyy/MM/dd HH:mm:ss");
lblTotalTime.Text = TotalTime.ToString(); // 运行时间
// lblRunTime.Text = RunTime.ToString(); // 有效时间
// lblIdleTime.Text = ProcessControl.IdleTime.ToString(); // 空闲时间
// lblDownTime.Text = ProcessControl.DownTime.ToString(); // 宕机时间
lblOEE_Total.Text = ProductNum_Total.ToString();
// lblOEE_OK.Text = ProcessControl.ProductNum_OK.ToString();
}
_refreshUITimer.Enabled = true;
}
private void UpdateCamResult(DateTime updateTime, object objData, string customMessage)
{
this.Invoke(new Action(() =>
{
BindingList<CameraSummary> cameraSummaries = new BindingList<CameraSummary>(CameraSummaries);
dgvCamreaNums.DataSource = cameraSummaries;
}));
}
private void UpdateResult(DateTime updateTime, object objData, string result)
{
this.Invoke(new Action(() =>
{
dgvProductNums.DataSource = new BindingList<ProductSummary>(ProductSummaries);
//if (dgvProductNums.Rows.Count > 0)
//{
// dgvProductNums.Height = dgvProductNums.Rows[0].Height * dgvProductNums.Rows.Count + 15;
//}
//else
//{
// dgvProductNums.Height = 35;
//}
//lblOEE_Rate.Text = ProcessControl.OEE.ToString("f2") + " %";
lblUPH.Text = UPH.ToString();
}));
}
private void BtnDeleteProject_Click(object? sender, EventArgs e)
@ -732,6 +1117,7 @@ namespace DHSoftware
private void HandleStartButton()
{
InitialCameraSumsView();
LogAsync(DateTime.Now, LogLevel.Information, "流程启动中,请稍候...");
StartProcess();
LogAsync(DateTime.Now, LogLevel.Action, "流程启动完成!");
@ -742,7 +1128,7 @@ namespace DHSoftware
private void StartProcess()
{
ProcessstartTime = DateTime.Now;
lblstarttime2.Text = ProcessstartTime.ToString("yyyy-MM-dd HH:mm:ss");
lblStartTime.Text = ProcessstartTime.ToString("yyyy-MM-dd HH:mm:ss");
//计数清零
PieceCount = 0;
@ -848,7 +1234,7 @@ namespace DHSoftware
//流程执行时PLC
PLC.StartProcess();
InitialOEEStatistic();
@ -909,7 +1295,7 @@ namespace DHSoftware
/// <param name="dt"></param>
/// <param name="camera"></param>
/// <param name="imageSet"></param>
private void OnCameraHImageOutput(DateTime dt, CameraBase camera, Mat imageSet)
private void OnCameraHImageOutput(DateTime dt, CameraBase camera, MatSet imageSet)
{
//if (camera.CameraName.Equals("cam1", StringComparison.OrdinalIgnoreCase))
//{
@ -925,7 +1311,7 @@ namespace DHSoftware
Task.Run(async () =>
{
using (Mat localImageSet = imageSet.Clone()) // 复制 Mat 避免并发问题
//using (Mat localImageSet = imageSet._mat.Clone()) // 复制 Mat 避免并发问题
{
// imageSet?.Dispose();
// 拍照计数与物件编号一致,查找对应的产品
@ -964,16 +1350,16 @@ namespace DHSoftware
}
//LogAsync(DateTime.Now, LogLevel.Error, $"{camera.Name} 未找到产品,编号:{productNumber},队列{index}数量:{tmpDic.Count},列表:{pnStr}");
localImageSet.Dispose();
imageSet.Dispose();
return;
}
// LogAsync(DateTime.Now, LogLevel.Information, $"{camera.Name} 找到产品{productNumber},队列{index}数量:{tmpDic.Count}");
LogAsync(DateTime.Now, LogLevel.Information, $"{camera.CameraName} 找到产品{productNumber},队列{index}数量:{tmpDic.Count}");
if (!_cameraRelatedDetectionDict.ContainsKey(camera.CameraName))
{
localImageSet.Dispose();
imageSet.Dispose();
@ -990,11 +1376,11 @@ namespace DHSoftware
for (int i = 0; i < detectionDict.Count; i++)
{
string detectionId = detectionDict[i];
using (Mat inferenceImage = localImageSet.Clone()) // 仅在此处克隆,确保推理过程中 Mat 有独立副本
var tmpImgSet = camera.CopyImageSet(imageSet as MatSet);
//imageSet
// using (Mat inferenceImage = localImageSet.Clone()) // 仅在此处克隆,确保推理过程中 Mat 有独立副本
{
DetectStationResult temp1 = _visionEngine.RunInference(inferenceImage, detectionId);
DetectStationResult temp1 = _visionEngine.RunInference(tmpImgSet, detectionId);
resultStates.Add(temp1.ResultState);
@ -1002,7 +1388,9 @@ namespace DHSoftware
}
}
stopwatch.Stop();
if (product.ResultCollection.Count != 0)
UpdateResultoverride(dt, camera, resultStates, totalTime, _cameraRelatedDetectionDict.Keys.Count);
product.InferenceOne();
// LogAsync(DateTime.Now, LogLevel.Information, $"{camera.Name} 推理完成,产品{productNumber}");
@ -1011,24 +1399,32 @@ namespace DHSoftware
{
return;
}
UpdateResult(DateTime.Now, null, product.ProductResult.GetEnumDescription());
#region 6.
product.ProductResult = product.ResultCollection.Any(u => u.ResultState != ResultState.OK)
? ResultState.B_NG
: ResultState.OK;
//if (product.ProductResult == ResultState.OK)
//{
// PLC.Blowing(productNumber, 1);
//}
//else
//{
// PLC.Blowing(productNumber, 2);
//}
product.ProductLabelCategory = product.ProductResult.GetEnumDescription();
product.ProductLabel = product.ProductResult.GetEnumDescription();
UpdateResultPro(DateTime.Now, null, product.ProductResult.GetEnumDescription());
LogAsync(DateTime.Now, LogLevel.Information, $"产品{product.PieceNumber}获取结果:{product.ProductResult} {(product.IsA2B ? "IsA2B" : "")}");
if (product.ProductResult == ResultState.OK)
{
PLC.Blowing(productNumber, 1);
LogAsync(DateTime.Now, LogLevel.Action, $"产品{product.PieceNumber}PLC,OK吹气");
}
else
{
PLC.Blowing(productNumber, 2);
LogAsync(DateTime.Now, LogLevel.Action, $"产品{product.PieceNumber}PLC,NG吹气");
}
#endregion 6.
@ -1080,10 +1476,7 @@ namespace DHSoftware
}));
//重新生成实例 销毁之前的实例
var saveData = temp.GetProductData();
using (StreamWriter sw = new StreamWriter("D://123log.txt", true, Encoding.UTF8))
{
sw.WriteLine(logStr);
}
}
catch (Exception) { }
finally
@ -1105,19 +1498,116 @@ namespace DHSoftware
}
});
}
public async Task UpdateResult(DateTime dt, object objData, string resultStr)
public virtual void AddOKProduct(string resultStr)
{
// CurrentState = RunState.Running;
if (resultStr.ToLower() == "ok")
{
ProductNum_OK++;
}
}
public async Task UpdateResultoverride(DateTime dt, CameraBase objData, List<ResultState> resultStr, double total, int _cameraDictCount)
{
// CurrentState = RunState.Running;
// 根据相机名称找到对应的信息(假设有一个字典或其他集合保存相机相关信息)
var cameraName = objData?.CameraName; // 假设 CameraBase 有 Name 属性
if (string.IsNullOrEmpty(cameraName))
{
throw new ArgumentException("相机名称不能为空");
}
lock (_cameraSummaryLock)
{
// 查找或添加相机统计项
var summary = CameraSummaries.FirstOrDefault(c => c.CameraName == cameraName)
?? new CameraSummary { CameraName = cameraName };
if (!CameraSummaries.Contains(summary))
{
CameraSummaries.Add(summary);
}
if (resultStr.Any(u => u.ToString().ToLower() == "ok"))
{
summary.OKCount++;
}
else /*if (resultStr.Equals("TBD", StringComparison.OrdinalIgnoreCase))*/
{
summary.NGCount++;
}
}
await Task.Run(() =>
{
OnUpdateCamResult?.Invoke(dt, objData, "");
});
}
public async Task UpdateResultPro(DateTime dt, object objData, string resultStr)
{
CurrentState = RunState.Running;
ProductNum_Total++;
//AddOKProduct(resultStr);
AddOKProduct(resultStr);
lock (_productSummaryLock)
{
var product = ProductSummaries.FirstOrDefault(u => u.ResultDesc == resultStr);
if (product != null)
{
product.ProductAmount++;
}
else
{
product = new ProductSummary();
product.ResultDesc = resultStr;
product.ProductAmount = 1;
ProductSummaries.Add(product);
}
int totalNum = ProductSummaries.Sum(p => p.ProductAmount);
ProductSummaries.ForEach(p => p.PercentStr = ((double)p.ProductAmount * 100.0 / totalNum).ToString("f2") + " %");
}
CalculateOEE();
await Task.Run(() =>
{
OnUpdateResult?.Invoke(dt, objData, resultStr);
});
lock (_cameraSummaryLock)
{
// 查找或添加相机统计项
var summary = CameraSummaries.FirstOrDefault(c => c.CameraName == "合计")
?? new CameraSummary { CameraName = "合计" };
summary.OKCount = ProductNum_OK;
summary.NGCount = ProductNum_Total - ProductNum_OK;
if (!CameraSummaries.Contains(summary))
{
CameraSummaries.Add(summary);
}
}
await Task.Run(() =>
{
OnUpdateCamResult?.Invoke(dt, objData, "合计");
});
}
private void HandleStopButton()
@ -1130,21 +1620,33 @@ namespace DHSoftware
//sLDMotion.Stop();
}
public int UPH = 0;
public void CalculateOEE()
{
TimeSpan timeSpan = DateTime.Now - ProcessstartTime;
UPH = (int)(ProductNum_Total / timeSpan.TotalHours) + 100;
//UPM = (int)UPH / 60;
this.BeginInvoke(new MethodInvoker(delegate ()
if (TotalTime.TotalHours == 0)
{
lblNowtime2.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
lblUPH2.Text = UPH.ToString();
lblNum2.Text = ProductNum_Total.ToString();
labuph.Text = UPH.ToString();
}));
UPH = 0;
UPM = 0;
}
else
{
UPH = (int)(ProductNum_Total / RunTime.TotalHours) + 100;
UPM = (int)UPH / 60;
}
//TimeSpan timeSpan = DateTime.Now - ProcessstartTime;
//UPH = (int)(ProductNum_Total / timeSpan.TotalHours) + 100;
////UPM = (int)UPH / 60;
//this.BeginInvoke(new MethodInvoker(delegate ()
//{
// lblNowtime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
// lblUPH.Text = UPH.ToString();
// lblNum.Text = ProductNum_Total.ToString();
//}));
}
private void HandleResetButton()