|
|
@@ -99,7 +99,10 @@ namespace TeamAAS_VP.Core
|
|
|
public string[] CsvData = new string[50];
|
|
|
public int[] ResultData = new int[200];
|
|
|
public string code = "";
|
|
|
- List<LockResult> lockResultsAll = new List<LockResult>();//一个产品的总结果
|
|
|
+ ConcurrentBag<LockResult> lockResultsAll = new ConcurrentBag<LockResult>();//一个产品的总结果
|
|
|
+ CountdownEvent countdown = new CountdownEvent(10);
|
|
|
+ ConcurrentBag<bool> AllResult = new ConcurrentBag<bool>();
|
|
|
+
|
|
|
private ObservableCollection<ShowRender> _Renders;
|
|
|
private double _CTtime;
|
|
|
public int ResultDataCount;
|
|
|
@@ -112,6 +115,8 @@ namespace TeamAAS_VP.Core
|
|
|
public ConcurrentDictionary<string, double> keyData = new ConcurrentDictionary<string, double> { };
|
|
|
//键盘单独数据
|
|
|
public ConcurrentDictionary<string, double> keyData1 = new ConcurrentDictionary<string, double> { };
|
|
|
+
|
|
|
+ public int completed = 0;
|
|
|
//键盘差值
|
|
|
public bool isValueOk;
|
|
|
|
|
|
@@ -1975,17 +1980,36 @@ namespace TeamAAS_VP.Core
|
|
|
|
|
|
if (cameraIndex == currentProduct.PhotoCount)
|
|
|
{
|
|
|
- _PrcTaskList.Clear();
|
|
|
+ //_PrcTaskList.Clear();
|
|
|
+ AllResult = new ConcurrentBag<bool>();
|
|
|
+
|
|
|
+ lockResultsAll = new ConcurrentBag<LockResult>();
|
|
|
|
|
|
- lock (_stateLock)
|
|
|
+ int count = 0;
|
|
|
+ var AllProcId = new List<Guid>();
|
|
|
+ foreach (var item in currentProduct.AoiPoints)
|
|
|
{
|
|
|
- lockResultsAll.Clear();
|
|
|
+ if (item.Enable_Start_Node == 1)
|
|
|
+ {
|
|
|
+ #region 判断执行视觉模板个数
|
|
|
+ if (item.CameraProcedureId1 != Guid.Empty && !AllProcId.Contains(item.CameraProcedureId1)) AllProcId.Add(item.CameraProcedureId1);
|
|
|
+ if (item.CameraProcedureId2 != Guid.Empty && !AllProcId.Contains(item.CameraProcedureId2)) AllProcId.Add(item.CameraProcedureId2);
|
|
|
+ if (item.CameraProcedureId3 != Guid.Empty && !AllProcId.Contains(item.CameraProcedureId3)) AllProcId.Add(item.CameraProcedureId3);
|
|
|
+ if (item.CameraProcedureId4 != Guid.Empty && !AllProcId.Contains(item.CameraProcedureId4)) AllProcId.Add(item.CameraProcedureId4);
|
|
|
+ if (item.CameraProcedureId5 != Guid.Empty && !AllProcId.Contains(item.CameraProcedureId5)) AllProcId.Add(item.CameraProcedureId5);
|
|
|
+ if (item.CameraProcedureId6 != Guid.Empty && !AllProcId.Contains(item.CameraProcedureId6)) AllProcId.Add(item.CameraProcedureId6);
|
|
|
+ if (item.CameraProcedureId7 != Guid.Empty && !AllProcId.Contains(item.CameraProcedureId7)) AllProcId.Add(item.CameraProcedureId7);
|
|
|
+ if (item.CameraProcedureId8 != Guid.Empty && !AllProcId.Contains(item.CameraProcedureId8)) AllProcId.Add(item.CameraProcedureId8);
|
|
|
+ #endregion
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- App.Current.Dispatcher.Invoke(() =>
|
|
|
+ count = AllProcId.Count;
|
|
|
+ countdown = new CountdownEvent(count);
|
|
|
+ SendTaskMessage($"需要执行模板数:{count}", MessageLevel.Alarm);
|
|
|
+ _ = App.Current.Dispatcher.BeginInvoke(new Action(() =>
|
|
|
{
|
|
|
_eventAggregator.GetEvent<LockResetNotification>().Publish();
|
|
|
- });
|
|
|
+ }));
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -2323,7 +2347,7 @@ namespace TeamAAS_VP.Core
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+ //不能使用全局变量,不然并发的时候会被清除掉,所以局部变量
|
|
|
var _ImageTaskList = new List<Task<(bool IsSucceed, ICogImage[] Images, string Message, int cameraIndex, Guid procedureId)>>();
|
|
|
|
|
|
foreach (var prcId in procIds)
|
|
|
@@ -2379,20 +2403,23 @@ namespace TeamAAS_VP.Core
|
|
|
|
|
|
if (_ImageTaskList.Count > 0)//如果2D取图有队列
|
|
|
{
|
|
|
- var ImageTaskResults = await Task.WhenAll(_ImageTaskList);
|
|
|
- foreach (var item in ImageTaskResults)
|
|
|
+ //并发
|
|
|
+ _ = Task.Run(async () =>
|
|
|
{
|
|
|
- if (item.IsSucceed)
|
|
|
- {
|
|
|
- bool Is3d = Is3D(item.procedureId);
|
|
|
- _PrcTaskList.Add(ExecuteProcedureAsync(item.cameraIndex, item.procedureId, item.Images, Is3d, currentProduct));
|
|
|
- //_PrcTaskList.Add(ExecuteProcedureAsync(cameraIndex, prcId, imageData.imges));
|
|
|
- }
|
|
|
- else
|
|
|
+ var ImageTaskResults = await Task.WhenAll(_ImageTaskList);
|
|
|
+ foreach (var item in ImageTaskResults)
|
|
|
{
|
|
|
- SendTaskMessage($"图像采集失败!{item.cameraIndex}: {item.procedureId}", MessageLevel.Alarm);
|
|
|
+ if (item.IsSucceed)
|
|
|
+ {
|
|
|
+ bool Is3d = Is3D(item.procedureId);
|
|
|
+ await ExecuteProcedureAsync(item.cameraIndex, item.procedureId, item.Images, Is3d, currentProduct);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ SendTaskMessage($"图像采集失败!{item.cameraIndex}: {item.procedureId}", MessageLevel.Alarm);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
//如果最后一个拍照点,则需要等待前面所有的拍照处理完成
|
|
|
@@ -2415,26 +2442,16 @@ namespace TeamAAS_VP.Core
|
|
|
else
|
|
|
{
|
|
|
//等待所有的图像处理流程处理完成
|
|
|
- var results = await Task.WhenAll(_PrcTaskList);
|
|
|
+ //之前版本使用的是lock机制无法进行并发操作,目前能完美进行并发且能等待所有任务完成
|
|
|
+ countdown.Wait();
|
|
|
|
|
|
- foreach (var item in results)
|
|
|
+ foreach (var item in AllResult)
|
|
|
{
|
|
|
- if (!item.IsSucceed || item.Result == null)
|
|
|
+ if (item)
|
|
|
{
|
|
|
resultFlog = false;
|
|
|
break;
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- foreach (var item_1 in item.Result)
|
|
|
- {
|
|
|
- if (!item_1)
|
|
|
- {
|
|
|
- resultFlog = false;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
//全部OK
|
|
|
@@ -2571,7 +2588,6 @@ namespace TeamAAS_VP.Core
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
//切换成自动运行模式
|
|
|
else if (addressConfig.AutoRunning.Address.Contains(tuple.nodeId))
|
|
|
{
|
|
|
@@ -2668,7 +2684,7 @@ namespace TeamAAS_VP.Core
|
|
|
{
|
|
|
code = plc.ReadNode<string>(string.Format(addressConfig.In_Code.Address, i));
|
|
|
}
|
|
|
- var homeview = _container.Resolve<HomeViewModel>();
|
|
|
+ //var homeview = _container.Resolve<HomeViewModel>();
|
|
|
if (i == 0)
|
|
|
{
|
|
|
SendTaskMessage($"收到当前过站检查请求(当站是否生产)...", MessageLevel.Debug);
|
|
|
@@ -2684,11 +2700,13 @@ namespace TeamAAS_VP.Core
|
|
|
_LastMesCheckTime[i] = (await _mesService.GetServerTimeAsync(code, 2)).Now;
|
|
|
ProductMainSN = "";
|
|
|
var stationConfig2 = _configService.GetDeviceInfo(0);
|
|
|
- if (homeview.IsNoCode == false)
|
|
|
- {
|
|
|
- var device = _configService.GetDeviceInfo(0);
|
|
|
- code = device.XnSN;
|
|
|
- }
|
|
|
+
|
|
|
+ //if (homeview.IsNoCode == false)
|
|
|
+ //{
|
|
|
+ // var device = _configService.GetDeviceInfo(0);
|
|
|
+ // code = device.XnSN;
|
|
|
+ //}
|
|
|
+
|
|
|
LogHelper.WriteLogMes($"【mes开始QUERY】");
|
|
|
SendTaskMessage($"mes开始QUERY", MessageLevel.Info);
|
|
|
ShowMes_Query = false;
|
|
|
@@ -2973,8 +2991,6 @@ namespace TeamAAS_VP.Core
|
|
|
LogHelper.WriteLogMes($"上传mes失败");
|
|
|
SendTaskMessage($"上传mes失败", MessageLevel.Error);
|
|
|
}
|
|
|
- //await plc.WriteNodeAsync(string.Format(addressConfig.Out_MesStatus.Address, i), (Int16)3);
|
|
|
-
|
|
|
|
|
|
//是否保存当前的产品记录至CSV?
|
|
|
if (stationConfig.SaveCsv)
|
|
|
@@ -3446,24 +3462,19 @@ namespace TeamAAS_VP.Core
|
|
|
/// <param name="pointIndex"></param>
|
|
|
/// <param name="procedureId"></param>
|
|
|
/// <returns></returns>
|
|
|
- private async Task<(bool IsSucceed, bool[] Result, string Message)> ExecuteProcedureAsync(int pointIndex, Guid procedureId, ICogImage[] images, bool is3dmodel, ProductModel currentProduct)
|
|
|
+ private async Task ExecuteProcedureAsync(int pointIndex, Guid procedureId, ICogImage[] images, bool is3dmodel, ProductModel currentProduct)
|
|
|
{
|
|
|
|
|
|
List<bool> results = new List<bool>();
|
|
|
|
|
|
- //Guid start = currentProduct.FixedUpCamera1ProcedureId;
|
|
|
- //Guid stop = currentProduct.FixedUpCamera2ProcedureId;
|
|
|
- //var startProcedures = _productService.GetCurrentProductProcedureModelById(start);
|
|
|
- //var stopProcedures = _productService.GetCurrentProductProcedureModelById(stop);
|
|
|
-
|
|
|
var cameraProcedures = currentProduct.CameraProcedures;
|
|
|
if (cameraProcedures == null || cameraProcedures.Count == 0)
|
|
|
{
|
|
|
SendTaskMessage($"当前产品未配置 CameraProcedures,无法执行视觉流程", MessageLevel.Alarm);
|
|
|
- return (false, null, $"当前产品未配置 CameraProcedures,无法执行视觉流程");
|
|
|
+ //return (false, null, $"当前产品未配置 CameraProcedures,无法执行视觉流程");
|
|
|
+ AllResult.Add(false);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
var ctsAll = new CancellationTokenSource();
|
|
|
|
|
|
try
|
|
|
@@ -3487,7 +3498,8 @@ namespace TeamAAS_VP.Core
|
|
|
if (selectedProcedure == null)
|
|
|
{
|
|
|
SendTaskMessage($"未找到 AOI 点位对应的视觉流程,Point#{pointIndex} ProcedureId={pointIndex}", MessageLevel.Alarm);
|
|
|
- return (false, null, $"未找到 AOI 点位对应的视觉流程,Point#{pointIndex} ProcedureId={procedureId}");
|
|
|
+ //return (false, null, $"未找到 AOI 点位对应的视觉流程,Point#{pointIndex} ProcedureId={procedureId}");
|
|
|
+ AllResult.Add(false);
|
|
|
}
|
|
|
|
|
|
SendTaskMessage($"开始执行 AOI 流程 (Point#{pointIndex}) 流程Id={pointIndex}", MessageLevel.Debug);
|
|
|
@@ -3503,18 +3515,12 @@ namespace TeamAAS_VP.Core
|
|
|
var visionResult = await _remoteCommandService.ExecutePhotoGetSinglePoint1(selectedProcedure, images, null, null, ctsAll.Token, is3dmodel);
|
|
|
if (visionResult.Count == 0)
|
|
|
{
|
|
|
- SendTaskMessage("Count值为0", MessageLevel.Alarm);
|
|
|
- return (false, null, $"未找到 AOI 点位对应的视觉流程,Point#{pointIndex} ProcedureId={procedureId}");
|
|
|
+ SendTaskMessage($"未找到 AOI 点位对应的视觉流程,Point#{pointIndex} ProcedureId={procedureId} Count值为0", MessageLevel.Alarm);
|
|
|
+ //return (false, null, $"未找到 AOI 点位对应的视觉流程,Point#{pointIndex} ProcedureId={procedureId}");
|
|
|
+ AllResult.Add(false);
|
|
|
}
|
|
|
|
|
|
//2. 结果分析
|
|
|
- //lock (_stateLock)
|
|
|
- //{
|
|
|
-
|
|
|
- //if (currentProduct.Name==startProcedures.Name)
|
|
|
- //{
|
|
|
- // lockResultsAll.Clear();
|
|
|
- //}
|
|
|
|
|
|
var stationConfig = _configService.GetDeviceInfo(0);
|
|
|
for (int i = 1; i <= visionResult.Count; i++)
|
|
|
@@ -3553,23 +3559,22 @@ namespace TeamAAS_VP.Core
|
|
|
if (Convert.ToDouble(ResData) >= Convert.ToDouble(globalParam.Param2) && Convert.ToDouble(ResData) <= Convert.ToDouble(globalParam.Param1))
|
|
|
{
|
|
|
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- SendTaskMessage($"检测项{lockResult1.PhotoName}结果{ResData}超出上下限!", MessageLevel.Error);
|
|
|
- resultflog = false;
|
|
|
- }
|
|
|
- if (resultflog)
|
|
|
- {
|
|
|
- lockResult1.PhotoPassed = "OK";
|
|
|
- results.Add(true);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- lockResult1.PhotoPassed = "NG";
|
|
|
- results.Add(false);
|
|
|
- }
|
|
|
-
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ SendTaskMessage($"检测项{lockResult1.PhotoName}结果{ResData}超出上下限!", MessageLevel.Error);
|
|
|
+ resultflog = false;
|
|
|
+ }
|
|
|
+ if (resultflog)
|
|
|
+ {
|
|
|
+ lockResult1.PhotoPassed = "OK";
|
|
|
+ AllResult.Add(true);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ lockResult1.PhotoPassed = "NG";
|
|
|
+ AllResult.Add(false);
|
|
|
+ }
|
|
|
}
|
|
|
lockResultsAll.Add(lockResult1.Copy());
|
|
|
}
|
|
|
@@ -3596,28 +3601,25 @@ namespace TeamAAS_VP.Core
|
|
|
if (Convert.ToDouble(ResData) >= Convert.ToDouble(globalParam.Param2) && Convert.ToDouble(ResData) <= Convert.ToDouble(globalParam.Param1))
|
|
|
{
|
|
|
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- SendTaskMessage($"检测项{lockResult1.PhotoName}结果{ResData}超出上下限!", MessageLevel.Error);
|
|
|
- resultflog = false;
|
|
|
- }
|
|
|
- if (resultflog)
|
|
|
- {
|
|
|
- lockResult1.PhotoPassed = "OK";
|
|
|
- results.Add(true);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- lockResult1.PhotoPassed = "NG";
|
|
|
- results.Add(false);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- lock (_stateLock)
|
|
|
- {
|
|
|
- lockResultsAll.Add(lockResult1.Copy());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ SendTaskMessage($"检测项{lockResult1.PhotoName}结果{ResData}超出上下限!", MessageLevel.Error);
|
|
|
+ resultflog = false;
|
|
|
+ }
|
|
|
+ if (resultflog)
|
|
|
+ {
|
|
|
+ lockResult1.PhotoPassed = "OK";
|
|
|
+ AllResult.Add(true);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ lockResult1.PhotoPassed = "NG";
|
|
|
+ AllResult.Add(false);
|
|
|
+ }
|
|
|
}
|
|
|
+ lockResultsAll.Add(lockResult1.Copy());
|
|
|
+
|
|
|
}
|
|
|
|
|
|
if (stationConfig.SaveCsvkeyData)
|
|
|
@@ -3685,16 +3687,7 @@ namespace TeamAAS_VP.Core
|
|
|
SendTaskMessage($"拆分视觉结果出错:{ex}", MessageLevel.Error);
|
|
|
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
- // }
|
|
|
-
|
|
|
- ////排序
|
|
|
- //lock (_stateLock)
|
|
|
- //{
|
|
|
- // var bf1 = lockResultsAll.OrderBy(p => int.Parse(p.PhotoName));
|
|
|
- // lockResultsAll = new List<LockResult>(bf1);
|
|
|
- //}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
@@ -3702,12 +3695,14 @@ namespace TeamAAS_VP.Core
|
|
|
SendTaskMessage($"执行 AOI 视觉流程异常: {ex.Message}", MessageLevel.Alarm);
|
|
|
}
|
|
|
|
|
|
- return (true, results.ToArray(), $"成功");
|
|
|
+ countdown.Signal(); // -1
|
|
|
+
|
|
|
+ //return (true, results.ToArray(), $"成功");
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
LogHelper.WriteLogError("处理固定相机检测拍照时出错", ex);
|
|
|
- return (false, null, $"处理固定相机检测拍照时出错");
|
|
|
+ //return (false, null, $"处理固定相机检测拍照时出错");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -3930,10 +3925,10 @@ namespace TeamAAS_VP.Core
|
|
|
|
|
|
private void SendTaskMessage(string msg, MessageLevel level)
|
|
|
{
|
|
|
- App.Current.Dispatcher.Invoke(() =>
|
|
|
+ _ = App.Current.Dispatcher.BeginInvoke(new Action(() =>
|
|
|
{
|
|
|
_eventAggregator.GetEvent<TaskMessageNotification>().Publish(new Models.MessageStruct() { Message = msg, level = level });
|
|
|
- });
|
|
|
+ }));
|
|
|
}
|
|
|
public bool concurrenty = true;
|
|
|
public void CurrentRunStatus()
|