修改界面

This commit is contained in:
2025-03-12 17:18:39 +08:00
parent b8c83e459d
commit a9d02a5a9d
14 changed files with 2425 additions and 636 deletions

View File

@ -282,11 +282,11 @@ namespace DHSoftware
//[Description("定义检测标签的集合例如Seg/Detection模式断裂、油污、划伤...Class模式ok、ng、上面、下面、套环、正常...")]
//[TypeConverter(typeof(CollectionCountConvert))]
//[Editor(typeof(ComplexCollectionEditor<RecongnitionLabel>), typeof(UITypeEditor))]
RecongnitionLabel recongnition=new RecongnitionLabel
RecongnitionLabel recongnition = new RecongnitionLabel
{
LabelName="youwu",
LabelDescription="油污",
LabelCategory="A_NG"
LabelName = "youwu",
LabelDescription = "油污",
LabelCategory = "A_NG"
};
RecongnitionLabel recongnition2 = new RecongnitionLabel
{
@ -314,7 +314,7 @@ namespace DHSoftware
var det6 = new DetectionConfig("相机6", MLModelType.ObjectDetection, @"D:\PROJECTS\X015\Vision\Cam6.onnx", false, "Cam6");
var det7 = new DetectionConfig("相机7", MLModelType.ObjectDetection, @"D:\PROJECTS\X015\Vision\Cam7.onnx", false, "Cam7");
var det8 = new DetectionConfig("相机8", MLModelType.ObjectDetection, @"D:\PROJECTS\X015\Vision\Cam8.onnx", false, "Cam8");
List<RelatedCamera> CameraCollects=new List<RelatedCamera>();
List<RelatedCamera> CameraCollects = new List<RelatedCamera>();
CameraCollects.Add(new RelatedCamera("Cam1"));
List<RelatedCamera> CameraCollects2 = new List<RelatedCamera>();
CameraCollects2.Add(new RelatedCamera("Cam2"));
@ -420,24 +420,32 @@ namespace DHSoftware
}
#else
Do3ThinkCamera do3ThinkCamera1 = new Do3ThinkCamera();
//Do3ThinkCamera do3ThinkCamera1 = new Do3ThinkCamera();
do3ThinkCamera1.dvpStreamFormat = dvpStreamFormat.S_RAW8;
do3ThinkCamera1.CameraName = "Cam1";
do3ThinkCamera1.CameraConnect();
do3ThinkCamera1.OnHImageOutput += OnCameraHImageOutput;
Cameras.Add(do3ThinkCamera1);
for (int i=2;i<=8;i++)
//do3ThinkCamera1.dvpStreamFormat = dvpStreamFormat.S_RAW8;
//do3ThinkCamera1.CameraName = "Cam1";
//do3ThinkCamera1.CameraConnect();
//do3ThinkCamera1.OnHImageOutput += OnCameraHImageOutput;
// Cameras.Add(do3ThinkCamera1);
for (int i = 1; i <= 8; i++)
{
Do3ThinkCamera do3ThinkCamera2 = new Do3ThinkCamera();
do3ThinkCamera2.dvpStreamFormat = dvpStreamFormat.S_RGB24;
do3ThinkCamera2.CameraName = $"Cam{i}";
Cameras.Add(do3ThinkCamera2);
do3ThinkCamera2.CameraConnect();
do3ThinkCamera2.OnHImageOutput += OnCameraHImageOutput;
Do3ThinkCamera cam = new Do3ThinkCamera();
if (i == 1)
{
cam.dvpStreamFormat = dvpStreamFormat.S_RAW8;
}
else
{
cam.dvpStreamFormat = dvpStreamFormat.S_RGB24;
}
cam.CameraName = $"Cam{i}";
Cameras.Add(cam);
cam.CameraConnect();
cam.OnHImageOutput += OnCameraHImageOutput;
}
#endif
@ -445,24 +453,24 @@ namespace DHSoftware
DetectionConfigs.ForEach(detection =>
{
detection.CameraCollects.ForEach(cam =>
{
List<string> Dets = new List<string>
{
detection.CameraCollects.ForEach(cam =>
{
List<string> Dets = new List<string>
{
detection.Id
};
if (!_cameraRelatedDetectionDict.ContainsKey(cam.CameraSourceId))
{
_cameraRelatedDetectionDict.Add(cam.CameraSourceId, Dets);
}
else
{
_cameraRelatedDetectionDict[cam.CameraSourceId].Add(detection.Id);
}
};
if (!_cameraRelatedDetectionDict.ContainsKey(cam.CameraSourceId))
{
_cameraRelatedDetectionDict.Add(cam.CameraSourceId, Dets);
}
else
{
_cameraRelatedDetectionDict[cam.CameraSourceId].Add(detection.Id);
}
}
);
}
);
});
string inferenceDevice = "CPU";
@ -474,31 +482,39 @@ namespace DHSoftware
//初始化Halcon工具
InitialHalconTools();
//深度学习模型加载
bool resultOK =InitialSimboMLEnginesAsync();
bool resultOK = InitialSimboMLEnginesAsync();
if (resultOK)
{
//初始化失败
// return;
// return;
}
//位置比较卡
sLDMotion.AxisSettings = new List<AxisSetting>();
AxisSetting axis1=new AxisSetting();
AxisSetting axis1 = new AxisSetting();
axis1.AxisIndex = 0;
axis1.AxisName = "转盘1";
axis1.IsAxisEnabled = true;
//axis1.AlarmLogic = AxisDirection.Positive;
sLDMotion.IODefinitionCollection=new List<IODefinition>();
sLDMotion.IODefinitionCollection = new List<IODefinition>();
Motion(sLDMotion.IODefinitionCollection);
sLDMotion.SnapshotSettings = new List<SnapshotSetting>();
int[] cameraPositions = { 7613, 24161, 33608, 39702, 45701 };
int[] cameraPositions = { 24161, 33608, 39702, 45701 };
for (int i = 0; i < 5; i++)
sLDMotion.SnapshotSettings.Add(new SnapshotSetting
{
IsEnabled = true,
CameraIO = sLDMotion.IODefinitionCollection.FirstOrDefault(t => t.IOType == IOType.OUTPUT && t.IOIndex == 13),
CameraPosition = 7613,
StationNumber = 0
});
for (int i = 0; i < 4; i++)
{
sLDMotion.SnapshotSettings.Add(new SnapshotSetting
{
@ -513,17 +529,20 @@ namespace DHSoftware
sLDMotion.BlowSettings = new List<BlowSetting>();
int[] BlowPositions = { 61353, 68566 };
for (int i = 0; i < 2; i++)
sLDMotion.BlowSettings.Add(new BlowSetting
{
sLDMotion.BlowSettings.Add(new BlowSetting
{
IsEnabled = true,
BlowIO = sLDMotion.IODefinitionCollection.FirstOrDefault(t => t.IOType == IOType.OUTPUT && t.IOIndex == i),
BlowPosition = BlowPositions[i],
StationNumber = 0
});
}
IsEnabled = true,
BlowIO = sLDMotion.IODefinitionCollection.FirstOrDefault(t => t.IOType == IOType.OUTPUT && t.IOIndex == 5),
BlowPosition = BlowPositions[0],
StationNumber = 0
});
sLDMotion.BlowSettings.Add(new BlowSetting
{
IsEnabled = true,
BlowIO = sLDMotion.IODefinitionCollection.FirstOrDefault(t => t.IOType == IOType.OUTPUT && t.IOIndex == 6),
BlowPosition = BlowPositions[1],
StationNumber = 0
});
//SnapshotSetting sna1 = new SnapshotSetting();
//sna1.IsEnabled = true;
@ -536,23 +555,26 @@ namespace DHSoftware
// sLDMotion.SnapshotSettings.Add(sna1);
sLDMotion.AxisSettings.Add(axis1);
sLDMotion.Init();
// sLDMotion.Start();
sLDMotion.OnNewPieces -= MainMotion_NewPieces;
sLDMotion.OnNewPieces += MainMotion_NewPieces;
// sLDMotion.Start();
//PLC.IP = "192.168.6.6";
//PLC.Port = 502;
//PLC.PLCConnect();
//PLC.OnNewPieces -= MainMotion_NewPieces;
//PLC.OnNewPieces += MainMotion_NewPieces;
ProductBaseCount = 2;
ProductBaseCount = 8;
for (int i = 0; i < ProductBaseCount * ProductListMulti; i++)
{
ConcurrentDictionary<uint, ProductData> products = new ConcurrentDictionary<uint, ProductData>();
_productLists.Add(products);
}
sLDMotion.AxisStop();
bool e=sLDMotion.CArdReset();
sLDMotion.JOGRun(10000, 100000);
startTime =DateTime.Now;
sLDMotion.AxisStop();
bool e = sLDMotion.CArdReset();
//转盘速度
sLDMotion.JOGRun(14000, 100000);
startTime = DateTime.Now;
}
public void Motion(List<IODefinition> iODefinitions)
{
@ -583,7 +605,7 @@ namespace DHSoftware
private int PieceNumberToIndex(uint pn)
{
// 物料编号,取余 集合数量
int ret = (int)(pn % (ProductBaseCount * ProductListMulti));
return ret;
}
@ -598,7 +620,7 @@ namespace DHSoftware
PieceCount++;
int index = PieceNumberToIndex(pieceNumber);
// productDatas.Add(pData);
//转盘2 的物料是不是重新覆盖之前的pDta
@ -607,8 +629,9 @@ namespace DHSoftware
ProductData pData = new ProductData("", pieceNumber, ProductBaseCount);
_productLists[index][pieceNumber] = pData;
}
string logStr = $"时间:{DateTime.Now} 轴{axisIndex}新产品{pieceNumber}加入队列{index}----入料计数{PieceCount}\n";
Task.Run(() => {
string logStr = $"时间:{DateTime.Now} 轴{axisIndex}新产品{pieceNumber}加入队列{index}----入料计数{PieceCount}\n";
Task.Run(() =>
{
this.BeginInvoke(new MethodInvoker(delegate () { richTextBox1.AppendText(logStr); }));
});
@ -622,7 +645,7 @@ namespace DHSoftware
{
await Task.Run(() =>
{
//OnUpdateCT?.Invoke(objData, ctTime);
//OnUpdateCT?.Invoke(objData, ctTime);
});
}
/// <summary>
@ -632,7 +655,7 @@ namespace DHSoftware
{
//深度学习 模型加载
var resultOK = MLLoadModel();
return resultOK;
return resultOK;
}
/// <summary>
/// 深度学习 模型加载
@ -645,56 +668,56 @@ namespace DHSoftware
{
SimboStationMLEngineList = new List<SimboStationMLEngineSet>();
// _cameraRelatedDetectionDict = IConfig.DetectionConfigs.Select(t => t.ModelPath).Distinct().ToList();
DetectionConfigs.ForEach(dc =>
DetectionConfigs.ForEach(dc =>
//_cameraRelatedDetectionDict.ForEach(dc =>
{
if (dc.IsEnabled && !string.IsNullOrWhiteSpace(dc.ModelPath))
{
if (dc.IsEnableGPU)
{
//if (IIConfig.IsLockGPU)
//{
//foreach (var validGPU in ValidGPUList2)
//{
// if (validGPU.DetectionIds.Contains(dc.Id))
// {
var engine = SingleMLLoadModel(dc, true, 0);
SimboStationMLEngineList.Add(engine);
// }
//}
//}
//else
//{
// foreach (var validGPU in ValidGPUList)
// {
// //var validGPU = ValidGPUList.FirstOrDefault(u => u.DetectionIds.Contains(dc.Id));
// if (validGPU.DetectionId == dc.Id)
// {
// var engine = SingleMLLoadModel(dc, true, validGPU.GPUNo);
// SimboStationMLEngineList.Add(engine);
// }
// }
//}
{
}
else
{
//for (int i = 0; i < IConfig.CPUNums; i++)
for (int i = 0; i <1; i++)
{
//var engine = SingleMLLoadModel(dc, false, i);
var engine = SingleMLLoadModel(dc, false, i);
SimboStationMLEngineList.Add(engine);
}
}
}
});
if (dc.IsEnabled && !string.IsNullOrWhiteSpace(dc.ModelPath))
{
if (dc.IsEnableGPU)
{
//if (IIConfig.IsLockGPU)
//{
//foreach (var validGPU in ValidGPUList2)
//{
// if (validGPU.DetectionIds.Contains(dc.Id))
// {
var engine = SingleMLLoadModel(dc, true, 0);
SimboStationMLEngineList.Add(engine);
// }
//}
//}
//else
//{
// foreach (var validGPU in ValidGPUList)
// {
// //var validGPU = ValidGPUList.FirstOrDefault(u => u.DetectionIds.Contains(dc.Id));
// if (validGPU.DetectionId == dc.Id)
// {
// var engine = SingleMLLoadModel(dc, true, validGPU.GPUNo);
// SimboStationMLEngineList.Add(engine);
// }
// }
//}
}
else
{
//for (int i = 0; i < IConfig.CPUNums; i++)
for (int i = 0; i < 1; i++)
{
//var engine = SingleMLLoadModel(dc, false, i);
var engine = SingleMLLoadModel(dc, false, i);
SimboStationMLEngineList.Add(engine);
}
}
}
});
resultOK = true;
}
catch (Exception ex)
{
// LogAsync(DateTime.Now, LogLevel.Exception, $"异常:模型并发加载异常:{ex.GetExceptionMessage()}");
// LogAsync(DateTime.Now, LogLevel.Exception, $"异常:模型并发加载异常:{ex.GetExceptionMessage()}");
resultOK = false;
}
@ -761,7 +784,7 @@ namespace DHSoftware
bool isSuccess = mLEngineSet.StationMLEngine.Load(mLInit);
if (!isSuccess)
{
// throw new ProcessException("异常:模型加载异常", null);
// throw new ProcessException("异常:模型加载异常", null);
}
//LogAsync(DateTime.Now, LogLevel.Information, $"模型加载成功是否GPU:{isGPU} CoreInx:{coreInx} - {dc.Name}" + $" {dc.ModelType.GetEnumDescription()}:{dc.ModelPath}");
}
@ -785,9 +808,9 @@ namespace DHSoftware
if (!c.IsEnabled)
return;
if(c.HalconAlgorithemPath_Pre!=null)
if (c.HalconAlgorithemPath_Pre != null)
LoadHalconTool(c.HalconAlgorithemPath_Pre);
});
}
@ -795,7 +818,7 @@ namespace DHSoftware
{
if (!HalconToolDict.ContainsKey(path))
{
string algorithemPath = path;
@ -817,7 +840,7 @@ namespace DHSoftware
/// </summary>
/// <param name="detectConfig"></param>
/// <param name="detectResult"></param>
public void PreTreated(DetectionConfig detectConfig, DetectStationResult detectResult,Mat MhImage)
public void PreTreated(DetectionConfig detectConfig, DetectStationResult detectResult, Mat MhImage)
{
try
{
@ -828,10 +851,10 @@ namespace DHSoftware
{
HObject obj = OpenCVHelper.MatToHImage(MhImage);
HImage hImage = HalconHelper.ConvertHObjectToHImage(obj);
string toolKey = detectConfig.HalconAlgorithemPath_Pre;
string toolKey = detectConfig.HalconAlgorithemPath_Pre;
if (!HalconToolDict.ContainsKey(toolKey))
{
// LogAsync(DateTime.Now, LogLevel.Exception, $"{detectConfig.Name}未获取预处理算法");
// LogAsync(DateTime.Now, LogLevel.Exception, $"{detectConfig.Name}未获取预处理算法");
return;
}
//Mean_Thre Deviation_Thre Mean_standard Deviation_standard
@ -851,11 +874,11 @@ namespace DHSoftware
if (!tool.RunProcedure(out string errorMsg, out _))
{
// detectResult.PreTreatedFlag = false;
// detectResult.PreTreatedFlag = false;
detectResult.IsPreTreatDone = false;
return;
}
@ -883,37 +906,37 @@ namespace DHSoftware
detectResult.ResultState = ResultState.DetectNG;
detectResult.IsPreTreatNG = true;
// if (detectResult.VisionImageSet.PreTreatedFlag)
{
//detectResult.VisionImageSet.MLImage = tool.GetResultObject("OUTPUT_PreTreatedImage");
//DetectionResultImage
// detectResult.VisionImageSet.DetectionResultImage = detectResult.VisionImageSet.MLImage.ConvertHImageToBitmap();
// detectResult.VisionImageSet.DetectionResultImage = detectResult.VisionImageSet.MLImage.ConvertHImageToBitmap();
}
}
else
{
// detectResult.VisionImageSet.DetectionResultImage = detectResult.VisionImageSet.MLImage.ConvertHImageToBitmap();
// detectResult.VisionImageSet.DetectionResultImage = detectResult.VisionImageSet.MLImage.ConvertHImageToBitmap();
}
}
}
catch (Exception ex)
{
}
finally
{
//detectResult.VisionImageSet.HImage?.Dispose();
//detectResult.VisionImageSet.HImage = null;
// MhImage?.Dispose();
// MhImage?.Dispose();
//MhImage = null;
}
}
/// <summary>
/// 相机回调
@ -923,6 +946,16 @@ namespace DHSoftware
/// <param name="imageSet"></param>
private void OnCameraHImageOutput(DateTime dt, CameraBase camera, Mat imageSet)
{
//if (camera.CameraName.Equals("cam1", StringComparison.OrdinalIgnoreCase))
//{
// Console.WriteLine();
//}
//if (camera.CameraName.Equals("cam2", StringComparison.OrdinalIgnoreCase))
//{
// Console.WriteLine();
//}
// 获取该相机的拍照计数
uint productNumber = (uint)camera.SnapshotCount;
@ -930,7 +963,7 @@ namespace DHSoftware
{
using (Mat localImageSet = imageSet.Clone()) // 复制 Mat 避免并发问题
{
// imageSet?.Dispose();
// imageSet?.Dispose();
// 拍照计数与物件编号一致,查找对应的产品
ProductData product = null;
//内外壁模组多个相机的处理方法
@ -939,52 +972,87 @@ namespace DHSoftware
// 找到产品存放在哪个队列里
ConcurrentDictionary<uint, ProductData> tmpDic = _productLists[index];
try
{
int retryTimes = 100;
while (product == null && retryTimes > 0)
try
{
if (tmpDic.ContainsKey(productNumber))
int retryTimes = 100;
while (product == null && retryTimes > 0)
{
product = tmpDic[productNumber];
if (tmpDic.ContainsKey(productNumber))
{
product = tmpDic[productNumber];
}
else
{
// Thread.Sleep(20);
await Task.Delay(20);
}
retryTimes--;
}
else
// 如果产品为空,则销毁图片,提示错误
if (null == product)
{
Thread.Sleep(20);
}
retryTimes--;
}
// 如果产品为空,则销毁图片,提示错误
if (null == product)
{
List<uint> pnList = tmpDic.Keys.ToList();
List<uint> pnList = tmpDic.Keys.ToList();
string pnStr = "";
if (pnList != null && pnList.Count > 0)
{
pnStr = string.Join(",", pnList);
string pnStr = "";
if (pnList != null && pnList.Count > 0)
{
pnStr = string.Join(",", pnList);
}
//LogAsync(DateTime.Now, LogLevel.Error, $"{camera.Name} 未找到产品,编号:{productNumber},队列{index}数量:{tmpDic.Count},列表:{pnStr}");
localImageSet.Dispose();
this.BeginInvoke(new MethodInvoker(delegate ()
{
int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
richTextBox1.AppendText(productNumber + "提前推出" + camera.CameraName);
// 设置回原来的滚动位置
richTextBox1.SelectionStart = richTextBox1.TextLength;
richTextBox1.ScrollToCaret();
}));
//重新生成实例 销毁之前的实例
using (StreamWriter sw = new StreamWriter("D://123log.txt", true, Encoding.UTF8))
{
sw.WriteLine(productNumber + "提前推出" + camera.CameraName);
}
return;
}
//LogAsync(DateTime.Now, LogLevel.Error, $"{camera.Name} 找到产品,编号:{productNumber},队列{index}数量:{tmpDic.Count},列表:{pnStr}");
localImageSet.Dispose();
return;
}
// LogAsync(DateTime.Now, LogLevel.Information, $"{camera.Name} 找到产品{productNumber},队列{index}数量:{tmpDic.Count}");
// LogAsync(DateTime.Now, LogLevel.Information, $"{camera.Name} 找到产品{productNumber},队列{index}数量:{tmpDic.Count}");
if (!_cameraRelatedDetectionDict.ContainsKey(camera.CameraName))
{
if (!_cameraRelatedDetectionDict.ContainsKey(camera.CameraName))
{
localImageSet.Dispose();
this.BeginInvoke(new MethodInvoker(delegate ()
{
localImageSet.Dispose();
// LogAsync(DateTime.Now, LogLevel.Warning, $"{camera.Name} 找到产品{productNumber}但是没有推理1");
int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
return;
}
richTextBox1.AppendText(productNumber+"提前推出" + camera.CameraName);
// 设置回原来的滚动位置
richTextBox1.SelectionStart = richTextBox1.TextLength;
richTextBox1.ScrollToCaret();
}));
//重新生成实例 销毁之前的实例
using (StreamWriter sw = new StreamWriter("D://123log.txt", true, Encoding.UTF8))
{
sw.WriteLine(productNumber+"提前推出" + camera.CameraName);
}
// LogAsync(DateTime.Now, LogLevel.Warning, $"{camera.Name} 找到产品{productNumber}但是没有推理1");
return;
}
double totalTime = 0.0;
List<ResultState> resultStates = new List<ResultState>();
List<string>? detectionDict = _cameraRelatedDetectionDict[camera.CameraName];
double totalTime = 0.0;
List<ResultState> resultStates = new List<ResultState>();
List<string>? detectionDict = _cameraRelatedDetectionDict[camera.CameraName];
for (int i = 0; i < detectionDict.Count; i++)
@ -1062,14 +1130,14 @@ namespace DHSoftware
req.ResizeHeight = (int)detectConfig.ModelHeight;
// req.LabelNames = detectConfig.GetLabelNames();
// req.Score = IIConfig.Score;
req.mImage = inferenceImage.Clone();
req.in_lable_path = detectConfig.in_lable_path;
req.confThreshold = detectConfig.ModelconfThreshold;
req.iouThreshold = 0.3f;
req.segmentWidth = 320;
req.out_node_name = "output0";
switch (detectConfig.ModelType)
{
case MLModelType.ImageClassification:
@ -1117,14 +1185,14 @@ namespace DHSoftware
//var result = Dectection[detectionId].RunInference(req);
//sw.Stop();
//LogAsync(DateTime.Now, LogLevel.Information, $"{camera.Name} 推理进度1.1,产品{productNumber},耗时{sw.ElapsedMilliseconds}ms");
this.BeginInvoke(new MethodInvoker(delegate ()
{
pictureBox1.Image?.Dispose(); // 释放旧图像
pictureBox1.Image = result.ResultMap;
richTextBox1.AppendText($"推理成功 {productNumber}, {result.IsSuccess} 耗时 {mlWatch.ElapsedMilliseconds}ms\n");
richTextBox1.AppendText($"推理成功 {productNumber}, {result.IsSuccess}相机名字{camera.CameraName} 耗时 {mlWatch.ElapsedMilliseconds}ms\n");
}));
req.mImage.Dispose();
req.mImage?.Dispose();
@ -1247,67 +1315,80 @@ namespace DHSoftware
}
product.InferenceOne(() =>
{
;
}, () =>
{
;
});
product.InferenceOne();
// LogAsync(DateTime.Now, LogLevel.Information, $"{camera.Name} 推理完成,产品{productNumber}");
// LogAsync(DateTime.Now, LogLevel.Information, $"{camera.Name} 推理完成,产品{productNumber}");
if (!product.InferenceFinished())
if (!product.InferenceFinished())
{
return;
}
ProductNum_Total++;
CalculateOEE();
this.BeginInvoke(new MethodInvoker(delegate ()
{
int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
richTextBox1.AppendText($"统计结果成功,{productNumber} 吹气!\n");
// 设置回原来的滚动位置
richTextBox1.SelectionStart = richTextBox1.TextLength;
richTextBox1.ScrollToCaret();
}));
#region 6.
product.ProductResult = product.ResultCollection.Any(u => u.ResultState != ResultState.OK)
? ResultState.B_NG
: ResultState.OK;
product.ProductLabelCategory = product.ProductResult.GetEnumDescription();
product.ProductLabel = product.ProductResult.GetEnumDescription();
#endregion
#region 7.
#endregion
// 出列
ProductData temp = null;
int tryTimes = 10;
while (temp == null && tryTimes > 0)
{
if (tmpDic.TryRemove(productNumber, out temp))
{
return;
break;
}
ProductNum_Total++;
CalculateOEE();
tryTimes--;
Thread.Sleep(5);
}
if (temp == null)
{
string logStr = $"{DateTime.Now}产品{productNumber}出列失败true" +
$"当前队列产品数量:{tmpDic.Count}";
this.BeginInvoke(new MethodInvoker(delegate ()
{
int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
richTextBox1.AppendText($"统计结果成功,{productNumber} 吹气!\n");
richTextBox1.AppendText(logStr);
// 设置回原来的滚动位置
richTextBox1.SelectionStart = richTextBox1.TextLength;
richTextBox1.ScrollToCaret();
}));
#region 6.
product.ProductResult = product.ResultCollection.Any(u => u.ResultState != ResultState.OK)
? ResultState.B_NG
: ResultState.OK;
product.ProductLabelCategory = product.ProductResult.GetEnumDescription();
product.ProductLabel = product.ProductResult.GetEnumDescription();
#endregion
#region 7.
#endregion
// 出列
ProductData temp = null;
int tryTimes = 10;
while (temp == null && tryTimes > 0)
}
else
{
try
{
if (tmpDic.TryRemove(productNumber, out temp))
{
break;
}
tryTimes--;
Thread.Sleep(5);
}
if (temp == null)
{
string logStr = $"{DateTime.Now}产品{productNumber}出列失败true" +
$"当前队列产品数量:{tmpDic.Count}";
string logStr = $"{DateTime.Now}产品{productNumber}出列成功true" +
$"产品结果:{temp.ProductResult.GetEnumDescription()}" +
$"当前队列产品数量:{tmpDic.Count}";
this.BeginInvoke(new MethodInvoker(delegate ()
{
@ -1319,61 +1400,42 @@ namespace DHSoftware
richTextBox1.SelectionStart = richTextBox1.TextLength;
richTextBox1.ScrollToCaret();
}));
//重新生成实例 销毁之前的实例
var saveData = temp.GetProductData();
using (StreamWriter sw = new StreamWriter("D://123log.txt", true, Encoding.UTF8))
{
sw.WriteLine(logStr);
}
}
else
catch (Exception) { }
finally
{
try
{
string logStr = $"{DateTime.Now}产品{productNumber}出列成功true" +
$"产品结果:{temp.ProductResult.GetEnumDescription()}" +
$"当前队列产品数量:{tmpDic.Count}";
this.BeginInvoke(new MethodInvoker(delegate ()
{
int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
richTextBox1.AppendText(logStr);
// 设置回原来的滚动位置
richTextBox1.SelectionStart = richTextBox1.TextLength;
richTextBox1.ScrollToCaret();
}));
//重新生成实例 销毁之前的实例
var saveData = temp.GetProductData();
using (StreamWriter sw = new StreamWriter("D://123log.txt", true, Encoding.UTF8))
{
sw.WriteLine(logStr);
}
}
catch (Exception) { }
finally
{
// temp.Dispose();
temp = null;
}
// temp.Dispose();
temp = null;
}
// UpdateCT((float)(dtNow - _ctTime).TotalSeconds);
//_ctTime = dtNow;
// });
}
catch (Exception ex)
{
//LogAsync(DateTime.Now, LogLevel.Error, $"流程检测未捕获的异常:{ex.GetExceptionMessage()}");
product?.Dispose();
}
// UpdateCT((float)(dtNow - _ctTime).TotalSeconds);
//_ctTime = dtNow;
// });
}
catch (Exception ex)
{
//LogAsync(DateTime.Now, LogLevel.Error, $"流程检测未捕获的异常:{ex.GetExceptionMessage()}");
product?.Dispose();
}
}
});
});
}
public void SetResult()
{
//// detectResult.IsPreTreatDone = detectResult.VisionImageSet.PreTreatedFlag
@ -1397,19 +1459,20 @@ namespace DHSoftware
Cameras.Clear();
Dectection.Clear();
// Add the code for the "停止" button click here
PLC.TurntableStop();
// PLC.TurntableStop();
CurrentMachine = true;
sLDMotion.Stop();
}
public int UPH=0;
public int UPH = 0;
public void CalculateOEE()
{
TimeSpan timeSpan = DateTime.Now - startTime;
UPH = (int)(ProductNum_Total / timeSpan.TotalHours) + 100;
UPH = (int)(ProductNum_Total / timeSpan.TotalHours) + 100;
//UPM = (int)UPH / 60;
this.BeginInvoke(new MethodInvoker(delegate () {
label1.Text = UPH.ToString();
this.BeginInvoke(new MethodInvoker(delegate ()
{
label1.Text = UPH.ToString();
}));