修改
This commit is contained in:
@ -271,7 +271,7 @@ namespace DHSoftware
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
//refreshTimer.Start();
|
||||
//refreshTimer.Start();
|
||||
//初始化数据
|
||||
InitData();
|
||||
//绑定事件
|
||||
@ -428,7 +428,7 @@ namespace DHSoftware
|
||||
|
||||
currentState = value;
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -543,11 +543,7 @@ namespace DHSoftware
|
||||
dgvProductNums.DataSource = ProductSummaries;
|
||||
|
||||
|
||||
dgvCamreaNums.AutoGenerateColumns = false;
|
||||
|
||||
dgvCamreaNums.DefaultCellStyle.Font = new Font("Tahoma", 12, FontStyle.Regular, GraphicsUnit.World);
|
||||
|
||||
dgvCamreaNums.DataSource = null;
|
||||
dgvCamreaNums.Columns.Clear();
|
||||
|
||||
// 添加 CCD 列
|
||||
@ -556,6 +552,14 @@ namespace DHSoftware
|
||||
HeaderText = "CCD",
|
||||
DataPropertyName = "CameraName"
|
||||
});
|
||||
// 添加 触发数 列
|
||||
var TiggerCountColumn = new DataGridViewTextBoxColumn
|
||||
{
|
||||
HeaderText = "触发数",
|
||||
DataPropertyName = "TiggerCount"
|
||||
};
|
||||
|
||||
dgvCamreaNums.Columns.Add(TiggerCountColumn);
|
||||
|
||||
// 添加 合格 列
|
||||
var okColumn = new DataGridViewTextBoxColumn
|
||||
@ -563,7 +567,7 @@ namespace DHSoftware
|
||||
HeaderText = "合格",
|
||||
DataPropertyName = "OKCount"
|
||||
};
|
||||
okColumn.DefaultCellStyle.ForeColor = Color.LightGreen; // 设置背景为绿色
|
||||
okColumn.DefaultCellStyle.ForeColor = Color.Green; // 设置背景为绿色
|
||||
dgvCamreaNums.Columns.Add(okColumn);
|
||||
|
||||
// 添加 不合格 列
|
||||
@ -589,7 +593,7 @@ namespace DHSoftware
|
||||
HeaderText = "良率",
|
||||
DataPropertyName = "YieldStr"
|
||||
});
|
||||
|
||||
dgvCamreaNums.AutoGenerateColumns = false;
|
||||
dgvCamreaNums.DataSource = new BindingList<CameraSummary>(CameraSummaries);
|
||||
}
|
||||
#endregion
|
||||
@ -673,22 +677,22 @@ namespace DHSoftware
|
||||
if (cameraBase.CamType == EnumCamType.度申Do3think)
|
||||
{
|
||||
|
||||
|
||||
Do3ThinkCamera cam =new Do3ThinkCamera();
|
||||
|
||||
Do3ThinkCamera cam = new Do3ThinkCamera();
|
||||
cam.IsSavePicEnabled = cameraBase.IsSavePicEnabled;
|
||||
cam.CameraName = cameraBase.CameraName;
|
||||
cam.CameraIP = cameraBase.CameraIP;
|
||||
cam.IsEnabled = cameraBase.IsEnabled;
|
||||
cam.ImageSaveDirectory = Path.Combine("D://Projects", cameraBase.CameraName);
|
||||
Cameras.Add(cam);
|
||||
if(cameraBase.IsEnabled)
|
||||
if (cameraBase.IsEnabled)
|
||||
{
|
||||
cam.OnLog -= _visionEngine_OnLog;
|
||||
cam.OnLog += _visionEngine_OnLog;
|
||||
cam.CameraConnect();
|
||||
cam.OnHImageOutput += OnCameraHImageOutput;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if (cameraBase.CamType == EnumCamType.海康hik)
|
||||
{
|
||||
@ -745,7 +749,7 @@ namespace DHSoftware
|
||||
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;
|
||||
detectionConfig.ShowLocation.Y = (i + 1) / 5 + 1;
|
||||
@ -780,7 +784,7 @@ namespace DHSoftware
|
||||
//
|
||||
_visionEngine = new SimboVisionDriver();
|
||||
_visionEngine.DetectionConfigs = DetectionConfigs;
|
||||
_visionEngine.LoggerHelper .LogPath = "D://PROJECTS//Logs//";
|
||||
_visionEngine.LoggerHelper.LogPath = "D://PROJECTS//Logs//";
|
||||
_visionEngine.LoggerHelper.LogPrefix = "Vision";
|
||||
_visionEngine.OnLog += _visionEngine_OnLog;
|
||||
//初始化模型 加载模型
|
||||
@ -799,8 +803,9 @@ namespace DHSoftware
|
||||
}
|
||||
private void LogDisplay(LogMsg msg)
|
||||
{
|
||||
|
||||
frmLog?.LogDisplay(msg);
|
||||
|
||||
//frmLog?.LogDisplay(msg);
|
||||
frmLog?.AddLog(msg);
|
||||
}
|
||||
public LoggerHelper LoggerHelper { get; set; } = new LoggerHelper();
|
||||
public virtual void LogAsync(LogMsg msg)
|
||||
@ -819,13 +824,13 @@ namespace DHSoftware
|
||||
OnLog?.Invoke(msg);
|
||||
//if (IConfig?.IsLogEnabled ?? true)
|
||||
//{
|
||||
LoggerHelper.LogAsync(msg);
|
||||
LoggerHelper.LogAsync(msg);
|
||||
//}
|
||||
}
|
||||
public virtual void LogAsync(DateTime dt, LogLevel logLevel, string msg)
|
||||
{
|
||||
LogAsync(new LogMsg(dt, logLevel, msg));
|
||||
|
||||
|
||||
}
|
||||
System.Windows.Forms.Timer _refreshUITimer = new System.Windows.Forms.Timer();
|
||||
private void BindEventHandler()
|
||||
@ -855,7 +860,7 @@ namespace DHSoftware
|
||||
{
|
||||
DH.RBAC.RBACWindow.Instance.Show();
|
||||
|
||||
|
||||
|
||||
}
|
||||
private void _refreshUITimer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
@ -865,12 +870,12 @@ namespace DHSoftware
|
||||
{
|
||||
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(); // 宕机时间
|
||||
// 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();
|
||||
// lblOEE_OK.Text = ProcessControl.ProductNum_OK.ToString();
|
||||
}
|
||||
|
||||
_refreshUITimer.Enabled = true;
|
||||
@ -890,7 +895,7 @@ namespace DHSoftware
|
||||
{
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
|
||||
|
||||
dgvProductNums.DataSource = new BindingList<ProductSummary>(ProductSummaries);
|
||||
|
||||
//if (dgvProductNums.Rows.Count > 0)
|
||||
@ -903,7 +908,7 @@ namespace DHSoftware
|
||||
//}
|
||||
|
||||
//lblOEE_Rate.Text = ProcessControl.OEE.ToString("f2") + " %";
|
||||
lblUPH.Text = UPH.ToString();
|
||||
lblUPH.Text = UPM.ToString();
|
||||
}));
|
||||
}
|
||||
|
||||
@ -1101,7 +1106,7 @@ namespace DHSoftware
|
||||
}
|
||||
segmented1.SelectIndex = -1;
|
||||
}
|
||||
|
||||
public string BatchNO { get; set; }
|
||||
public bool CurrentMachine = false;
|
||||
public volatile int ProductNum_Total = 0;
|
||||
public volatile int ProductNum_OK = 0;
|
||||
@ -1114,7 +1119,12 @@ namespace DHSoftware
|
||||
private Dictionary<string, HDevEngineTool> HalconToolDict = new Dictionary<string, HDevEngineTool>();
|
||||
public List<RecongnitionLabel> RecongnitionLabelList { get; set; } = new List<RecongnitionLabel>();
|
||||
public DateTime ProcessstartTime;
|
||||
private void PrepareBatchNO()
|
||||
{
|
||||
BatchNO = string.IsNullOrEmpty(BatchNO) ? SystemModel.CurrentScheme + "-" + DateTime.Now.ToString("yyyyMMddHHmmss") : BatchNO;
|
||||
// DataSavePath = string.IsNullOrEmpty(DataSavePath) ? Path.Combine(X018PLCConfig.ImgDirectory, DateTime.Now.ToString("yyyyMMdd"), BatchNO) : DataSavePath;
|
||||
|
||||
}
|
||||
private void HandleStartButton()
|
||||
{
|
||||
InitialCameraSumsView();
|
||||
@ -1127,11 +1137,16 @@ namespace DHSoftware
|
||||
|
||||
private void StartProcess()
|
||||
{
|
||||
BatchNO = textBoxBatchNO.Text;
|
||||
textBoxBatchNO.ReadOnly = true;
|
||||
btnCreateBatchNO.Enabled = false;
|
||||
PrepareBatchNO();//生成批次号
|
||||
ProcessstartTime = DateTime.Now;
|
||||
lblStartTime.Text = ProcessstartTime.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
//计数清零
|
||||
PieceCount = 0;
|
||||
|
||||
|
||||
//CameraSummaries.Clear();
|
||||
|
||||
if (PLC?.Enable == true)
|
||||
{
|
||||
@ -1230,7 +1245,7 @@ namespace DHSoftware
|
||||
|
||||
// ProductBaseCount = _MGSCameraList.Count;
|
||||
|
||||
|
||||
|
||||
|
||||
//流程执行时PLC
|
||||
PLC.StartProcess();
|
||||
@ -1275,7 +1290,7 @@ namespace DHSoftware
|
||||
LogAsync(DateTime.Now, LogLevel.Action, $">> 轴{axisIndex}新产品{pieceNumber}加入队列{index}----板卡计数{PieceCount}");
|
||||
|
||||
}
|
||||
|
||||
|
||||
DateTime dtNow = DateTime.Now;
|
||||
UpdateCT(null, (float)(dtNow - _ctTime).TotalSeconds);
|
||||
_ctTime = dtNow;
|
||||
@ -1333,7 +1348,7 @@ namespace DHSoftware
|
||||
}
|
||||
else
|
||||
{
|
||||
Thread.Sleep(20);
|
||||
Thread.Sleep(20);
|
||||
//await Task.Delay(20);
|
||||
}
|
||||
retryTimes--;
|
||||
@ -1351,7 +1366,7 @@ namespace DHSoftware
|
||||
|
||||
//LogAsync(DateTime.Now, LogLevel.Error, $"{camera.Name} 未找到产品,编号:{productNumber},队列{index}数量:{tmpDic.Count},列表:{pnStr}");
|
||||
imageSet.Dispose();
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1360,10 +1375,10 @@ namespace DHSoftware
|
||||
if (!_cameraRelatedDetectionDict.ContainsKey(camera.CameraName))
|
||||
{
|
||||
imageSet.Dispose();
|
||||
|
||||
|
||||
|
||||
LogAsync(DateTime.Now, LogLevel.Warning, $"{camera.CameraName} 找到产品{productNumber},但是没有推理1");
|
||||
|
||||
|
||||
LogAsync(DateTime.Now, LogLevel.Warning, $"{camera.CameraName} 找到产品{productNumber},但是没有推理1");
|
||||
|
||||
return;
|
||||
}
|
||||
@ -1377,19 +1392,35 @@ namespace DHSoftware
|
||||
{
|
||||
string detectionId = detectionDict[i];
|
||||
var tmpImgSet = camera.CopyImageSet(imageSet as MatSet);
|
||||
//imageSet
|
||||
// using (Mat inferenceImage = localImageSet.Clone()) // 仅在此处克隆,确保推理过程中 Mat 有独立副本
|
||||
//imageSet
|
||||
// using (Mat inferenceImage = localImageSet.Clone()) // 仅在此处克隆,确保推理过程中 Mat 有独立副本
|
||||
|
||||
DetectStationResult temp1 = _visionEngine.RunInference(tmpImgSet, detectionId);
|
||||
|
||||
resultStates.Add(temp1.ResultState);
|
||||
|
||||
product.ResultCollection.Add(temp1);
|
||||
|
||||
if (temp1 != null)
|
||||
{
|
||||
DetectStationResult temp1 = _visionEngine.RunInference(tmpImgSet, detectionId);
|
||||
UpdateResultTigger(dt, temp1.DetectName, (int)productNumber);
|
||||
//if (tmpModuleData.CamIDs.Count == 1)
|
||||
//{
|
||||
// UpdateResultoverride(dt, temp1.DetectName, resultStates, totalTime, _cameraRelatedDetectionDict.Keys.Count);
|
||||
//}
|
||||
//else //合图的合成一列
|
||||
//{
|
||||
// UpdateResultoverride(dt, temp1.DetectName, resultStates, totalTime, _cameraRelatedDetectionDict.Keys.Count);
|
||||
//}
|
||||
if (product.ResultCollection.Count != 0)
|
||||
UpdateResultoverride(dt, temp1.DetectName, resultStates, totalTime, _cameraRelatedDetectionDict.Keys.Count);
|
||||
|
||||
resultStates.Add(temp1.ResultState);
|
||||
|
||||
product.ResultCollection.Add(temp1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
stopwatch.Stop();
|
||||
if (product.ResultCollection.Count != 0)
|
||||
UpdateResultoverride(dt, camera, resultStates, totalTime, _cameraRelatedDetectionDict.Keys.Count);
|
||||
|
||||
|
||||
product.InferenceOne();
|
||||
|
||||
@ -1399,7 +1430,7 @@ namespace DHSoftware
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
#region 6. 统计产品结果
|
||||
|
||||
product.ProductResult = product.ResultCollection.Any(u => u.ResultState != ResultState.OK)
|
||||
@ -1424,7 +1455,7 @@ namespace DHSoftware
|
||||
PLC.Blowing(productNumber, 2);
|
||||
LogAsync(DateTime.Now, LogLevel.Action, $"产品{product.PieceNumber}PLC,NG吹气");
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion 6. 统计产品结果
|
||||
|
||||
@ -1448,12 +1479,12 @@ namespace DHSoftware
|
||||
$"当前队列产品数量:{tmpDic.Count}";
|
||||
this.BeginInvoke(new MethodInvoker(delegate ()
|
||||
{
|
||||
// int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
|
||||
// int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
|
||||
|
||||
// richTextBox1.AppendText(logStr);
|
||||
// richTextBox1.AppendText(logStr);
|
||||
|
||||
// 设置回原来的滚动位置
|
||||
// richTextBox1.SelectionStart = richTextBox1.TextLength;
|
||||
// richTextBox1.SelectionStart = richTextBox1.TextLength;
|
||||
//richTextBox1.ScrollToCaret();
|
||||
}));
|
||||
}
|
||||
@ -1468,15 +1499,15 @@ namespace DHSoftware
|
||||
{
|
||||
//int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
|
||||
|
||||
// richTextBox1.AppendText(logStr);
|
||||
// richTextBox1.AppendText(logStr);
|
||||
|
||||
// 设置回原来的滚动位置
|
||||
// richTextBox1.SelectionStart = richTextBox1.TextLength;
|
||||
// richTextBox1.SelectionStart = richTextBox1.TextLength;
|
||||
//richTextBox1.ScrollToCaret();
|
||||
}));
|
||||
//重新生成实例 销毁之前的实例
|
||||
var saveData = temp.GetProductData();
|
||||
|
||||
|
||||
}
|
||||
catch (Exception) { }
|
||||
finally
|
||||
@ -1505,14 +1536,49 @@ namespace DHSoftware
|
||||
ProductNum_OK++;
|
||||
}
|
||||
}
|
||||
public async Task UpdateResultoverride(DateTime dt, CameraBase objData, List<ResultState> resultStr, double total, int _cameraDictCount)
|
||||
public async Task UpdateResultTigger(DateTime dt, string objData, int _cameraDictCount)
|
||||
{
|
||||
// CurrentState = RunState.Running;
|
||||
CurrentState = RunState.Running;
|
||||
|
||||
|
||||
|
||||
// 根据相机名称找到对应的信息(假设有一个字典或其他集合保存相机相关信息)
|
||||
var cameraName = objData?.CameraName; // 假设 CameraBase 有 Name 属性
|
||||
var cameraName = objData; // 假设 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);
|
||||
}
|
||||
|
||||
|
||||
summary.TiggerCount = _cameraDictCount;
|
||||
}
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
OnUpdateCamResult?.Invoke(dt, objData, "");
|
||||
});
|
||||
}
|
||||
public async Task UpdateResultoverride(DateTime dt, string objData, List<ResultState> resultStr, double total, int _cameraDictCount)
|
||||
{
|
||||
// CurrentState = RunState.Running;
|
||||
|
||||
|
||||
|
||||
// 根据相机名称找到对应的信息(假设有一个字典或其他集合保存相机相关信息)
|
||||
var cameraName = objData; // 假设 CameraBase 有 Name 属性
|
||||
if (string.IsNullOrEmpty(cameraName))
|
||||
{
|
||||
throw new ArgumentException("相机名称不能为空");
|
||||
@ -1612,15 +1678,18 @@ namespace DHSoftware
|
||||
|
||||
private void HandleStopButton()
|
||||
{
|
||||
// Cameras.Clear();
|
||||
// Dectection.Clear();
|
||||
textBoxBatchNO.ReadOnly = false;
|
||||
btnCreateBatchNO.Enabled = true;
|
||||
|
||||
// Cameras.Clear();
|
||||
// Dectection.Clear();
|
||||
// Add the code for the "停止" button click here
|
||||
PLC.TurnStart(false);
|
||||
CurrentMachine = true;
|
||||
//sLDMotion.Stop();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void CalculateOEE()
|
||||
{
|
||||
@ -1635,7 +1704,7 @@ namespace DHSoftware
|
||||
UPM = (int)UPH / 60;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//TimeSpan timeSpan = DateTime.Now - ProcessstartTime;
|
||||
|
||||
//UPH = (int)(ProductNum_Total / timeSpan.TotalHours) + 100;
|
||||
@ -1669,18 +1738,9 @@ namespace DHSoftware
|
||||
LoginWindow.Instance.Show();
|
||||
}
|
||||
|
||||
private void splitter1_SplitterMoved(object sender, SplitterEventArgs e)
|
||||
private void btnCreateBatchNO_Click(object sender, EventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
private void richTextBox1_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void splitContainer2_Panel1_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
|
||||
textBoxBatchNO.Text = SystemModel.CurrentScheme + "-" + DateTime.Now.ToString("yyyyMMddHHmmss");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user