|
|
@@ -1546,15 +1546,6 @@ namespace TeamAAS_VP.Core
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- ////获取产品编码
|
|
|
- //_productService.CurrentProductCode = currentProduct.Name;
|
|
|
- //string productCode = plc.ReadNode<string>(addressConfig.In_Code.Address);
|
|
|
- ////如果产品编码为空,则以当前的时间戳作为编码
|
|
|
- //if (string.IsNullOrEmpty(productCode))
|
|
|
- //{
|
|
|
- // productCode = DateTime.Now.ToString("yyyyMMddHHmmssfff");
|
|
|
- //}
|
|
|
-
|
|
|
// 写入3D相机长度
|
|
|
if (addressConfig.In_UPCameracheckExe.Address.Contains(tuple.nodeId))
|
|
|
{
|
|
|
@@ -1683,282 +1674,6 @@ namespace TeamAAS_VP.Core
|
|
|
catch { }
|
|
|
var sysConfig = _configService.GetSystemConfiguration();
|
|
|
|
|
|
- if (sysConfig.ScannerUse == true && cameraIndex == 1 && sysConfig.CodeUse2 == true)
|
|
|
- {
|
|
|
- ScanValue = "";
|
|
|
- _scanDoneEvent.Reset(); // 重要:先关门
|
|
|
-
|
|
|
- await Scan_Client.SendAsync("T\r\n");
|
|
|
-
|
|
|
- // 等待扫码结果,最多 3 秒
|
|
|
- bool scanOk = await Task.Run(() => _scanDoneEvent.Wait(3000));
|
|
|
-
|
|
|
- if (!scanOk || ScanValue.IsNullOrWhiteSpace())
|
|
|
- {
|
|
|
- SendTaskMessage("二维码拍照失败或超时", MessageLevel.Alarm);
|
|
|
- await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (short)3);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- code = ScanValue;
|
|
|
- SendTaskMessage($"扫码成功,SN:{code}", MessageLevel.Info);
|
|
|
- //这里缺少从MES获取产品配方的内容,需要补充
|
|
|
- _LastMesCheckTime[0] = (await _mesService.GetServerTimeAsync(code, 2)).Now;
|
|
|
- //_LastMesCheckTime[1] = DateTime.Now;
|
|
|
- LogHelper.WriteLogMes($"【mes开始QUERY】");
|
|
|
- SendTaskMessage($"mes开始QUERY", MessageLevel.Info);
|
|
|
- (bool isSuccess, string response) = await _mesService.StationGetAsync(code, "", 2);//询问mes
|
|
|
-
|
|
|
- if (isSuccess)
|
|
|
- {
|
|
|
- //产品发生改变并且供料器发生了变化时,需要通知PLC进行取料更改
|
|
|
-
|
|
|
- LogHelper.WriteLogMes($"询问mes成功");
|
|
|
- SendTaskMessage($"询问mes成功:{response}", MessageLevel.Debug);
|
|
|
- if (response != "MES功能未启用!")
|
|
|
- {
|
|
|
- string[] items = response.Split('\n');
|
|
|
- string snItem = items.FirstOrDefault(f => f.Contains("sn="));
|
|
|
- if (snItem != null)
|
|
|
- {
|
|
|
- ProductMainSN = snItem.Replace("sn=", "").Trim();
|
|
|
- _productService.CurrentProductCode = ProductMainSN;
|
|
|
- SendTaskMessage($"产品主sn:{ProductMainSN}", MessageLevel.Info);
|
|
|
- }
|
|
|
- string woItem = items.FirstOrDefault(f => f.Contains("wo="));
|
|
|
- if (woItem != null)
|
|
|
- {
|
|
|
- wo = woItem.Replace("wo=", "").Trim();
|
|
|
- SendTaskMessage($"产品wo:{wo}", MessageLevel.Info);
|
|
|
- }
|
|
|
- string modelItem = items.FirstOrDefault(f => f.Contains("model_num="));
|
|
|
- if (modelItem != null)
|
|
|
- {
|
|
|
- model_num = modelItem.Replace("model_num=", "").Trim();
|
|
|
- SendTaskMessage($"model_num:{model_num}", MessageLevel.Info);
|
|
|
- }
|
|
|
- string colorItem = items.FirstOrDefault(f => f.Contains("color="));
|
|
|
- if (colorItem != null)
|
|
|
- {
|
|
|
- color = colorItem.Replace("color=", "").Trim();
|
|
|
- SendTaskMessage($"color:{color}", MessageLevel.Info);
|
|
|
- }
|
|
|
- string ppidItem = items.FirstOrDefault(f => f.Contains("ppid="));
|
|
|
- if (ppidItem != null)
|
|
|
- {
|
|
|
- ppid = ppidItem.Replace("ppid=", "").Trim();
|
|
|
- SendTaskMessage($"ppid:{ppid}", MessageLevel.Info);
|
|
|
- }
|
|
|
- string stageItem = items.FirstOrDefault(f => f.Contains("stage="));
|
|
|
- if (stageItem != null)
|
|
|
- {
|
|
|
- stage = stageItem.Replace("stage=", "").Trim();
|
|
|
- SendTaskMessage($"stage:{stage}", MessageLevel.Info);
|
|
|
- }
|
|
|
- string kbsnitem = items.FirstOrDefault(f => f.Contains("KB="));
|
|
|
- if (kbsnitem != null)
|
|
|
- {
|
|
|
- kb_sn = kbsnitem.Replace("KB=", "").Trim();
|
|
|
- SendTaskMessage($"KB:{kb_sn}", MessageLevel.Info);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- LogHelper.WriteLogMes($"【mes结束QUERY】");
|
|
|
- SendTaskMessage($"mes结束QUERY", MessageLevel.Info);
|
|
|
- var q = await _systemDatabaseService.QueryProductFromMesAsync(model_num, color);
|
|
|
- if (!string.IsNullOrEmpty(q))
|
|
|
- {
|
|
|
- ProductWithMes productWithMes = new ProductWithMes();
|
|
|
- ProductList = new ObservableCollection<ProductModel>(_productService.GetAllProducts());
|
|
|
- Guid productId = Guid.Empty;
|
|
|
- foreach (var itt in ProductList)
|
|
|
- {
|
|
|
- if (itt.Name == q)
|
|
|
- {
|
|
|
- productId = itt.ID;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (currentProduct.ID != productId || productWithMes.ProductKBSN != kb_sn)
|
|
|
- {
|
|
|
-
|
|
|
- _productService.Clear();
|
|
|
- //切换产品
|
|
|
- _productService.LoadProduct(productId);
|
|
|
- _productService.SetCurrentProduct(productId);
|
|
|
- await WritePositionToPlcAsync();
|
|
|
- SendTaskMessage($"切换产品成功", MessageLevel.Debug);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)1);
|
|
|
- return;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //产品发生改变并且供料器发生了变化时,需要通知PLC进行取料更改
|
|
|
-
|
|
|
- await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)3);
|
|
|
-
|
|
|
- LogHelper.WriteLogMes($"询问mes失败");
|
|
|
- SendTaskMessage($"询问mes失败:{response}", MessageLevel.Error);
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (sysConfig.ScannerUse == true && cameraIndex == 1 && sysConfig.CodeUse == true)
|
|
|
- {
|
|
|
- ScanValue = "";
|
|
|
- _scanDoneEvent.Reset(); // 重要:先关门
|
|
|
-
|
|
|
- await Scan_Client.SendAsync("T\r\n");
|
|
|
-
|
|
|
- // 等待扫码结果,最多 3 秒
|
|
|
- bool scanOk = await Task.Run(() => _scanDoneEvent.Wait(3000));
|
|
|
-
|
|
|
- if (!scanOk || ScanValue.IsNullOrWhiteSpace())
|
|
|
- {
|
|
|
- SendTaskMessage("二维码拍照失败或超时", MessageLevel.Alarm);
|
|
|
- await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (short)3);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- code = ScanValue;
|
|
|
- SendTaskMessage($"扫码成功,SN:{code}", MessageLevel.Info);
|
|
|
- //这里缺少从MES获取产品配方的内容,需要补充
|
|
|
- _LastMesCheckTime[0] = (await _mesService.GetServerTimeAsync(code, 2)).Now;
|
|
|
- LogHelper.WriteLogMes($"【mes开始QUERY】");
|
|
|
- SendTaskMessage($"mes开始QUERY", MessageLevel.Info);
|
|
|
- //(bool isSuccess, string response) = await _mesService.StationGetAsync(code, "", 2);//询问mes
|
|
|
- (bool isSuccess, string response) = await _mesService.StationGetExAsync(code, "", 2);//基于电池的SN获取产品SN,询问mes
|
|
|
- if (isSuccess)
|
|
|
- {
|
|
|
- //产品发生改变并且供料器发生了变化时,需要通知PLC进行取料更改
|
|
|
-
|
|
|
-
|
|
|
- string ProductMainSN_Temp = "";
|
|
|
- LogHelper.WriteLogMes($"询问mes成功");
|
|
|
- SendTaskMessage($"询问mes成功:{response}", MessageLevel.Debug);
|
|
|
-
|
|
|
- if (response != "MES功能未启用!")
|
|
|
- {
|
|
|
- string[] item = response.Split('\n');
|
|
|
- string snItem = item.FirstOrDefault(f => f.Contains("sn="));
|
|
|
- if (snItem != null)
|
|
|
- {
|
|
|
- ProductMainSN_Temp = snItem.Replace("sn=", "").Trim();
|
|
|
- SendTaskMessage($"sn:{ProductMainSN_Temp}", MessageLevel.Info);
|
|
|
- }
|
|
|
- }
|
|
|
- LogHelper.WriteLogMes($"询问mes成功");
|
|
|
- SendTaskMessage($"询问mes成功:{response}", MessageLevel.Debug);
|
|
|
-
|
|
|
- //20260214,特别版(电池组装)
|
|
|
- (bool isSuccess2, string response2) = await _mesService.StationGetAsync(ProductMainSN_Temp, "", 2);//询问mes
|
|
|
- if (isSuccess2)
|
|
|
- {
|
|
|
- LogHelper.WriteLogMes($"询问mes成功");
|
|
|
- SendTaskMessage($"询问mes成功:{response2}", MessageLevel.Debug);
|
|
|
-
|
|
|
- if (response2 != "MES功能未启用!")
|
|
|
- {
|
|
|
- string[] item = response2.Split('\n');
|
|
|
-
|
|
|
- string snItem = item.FirstOrDefault(f => f.Contains("sn="));
|
|
|
- if (snItem != null)
|
|
|
- {
|
|
|
- ProductMainSN = snItem.Replace("sn=", "").Trim();
|
|
|
- _productService.CurrentProductCode = ProductMainSN;
|
|
|
- SendTaskMessage($"产品主sn:{ProductMainSN}", MessageLevel.Info);
|
|
|
- }
|
|
|
- string woItem = item.FirstOrDefault(f => f.Contains("wo="));
|
|
|
- if (woItem != null)
|
|
|
- {
|
|
|
- wo = woItem.Replace("wo=", "").Trim();
|
|
|
- SendTaskMessage($"产品wo:{wo}", MessageLevel.Info);
|
|
|
- }
|
|
|
- string modelItem = item.FirstOrDefault(f => f.Contains("model_num="));
|
|
|
- if (modelItem != null)
|
|
|
- {
|
|
|
- model_num = modelItem.Replace("model_num=", "").Trim();
|
|
|
- SendTaskMessage($"model_num:{model_num}", MessageLevel.Info);
|
|
|
- }
|
|
|
- string colorItem = item.FirstOrDefault(f => f.Contains("color="));
|
|
|
- if (colorItem != null)
|
|
|
- {
|
|
|
- color = colorItem.Replace("color=", "").Trim();
|
|
|
- SendTaskMessage($"color:{color}", MessageLevel.Info);
|
|
|
- }
|
|
|
- string ppidItem = item.FirstOrDefault(f => f.Contains("ppid="));
|
|
|
- if (ppidItem != null)
|
|
|
- {
|
|
|
- ppid = ppidItem.Replace("ppid=", "").Trim();
|
|
|
- SendTaskMessage($"ppid:{ppid}", MessageLevel.Info);
|
|
|
- }
|
|
|
- string stageItem = item.FirstOrDefault(f => f.Contains("stage="));
|
|
|
- if (stageItem != null)
|
|
|
- {
|
|
|
- stage = stageItem.Replace("stage=", "").Trim();
|
|
|
- SendTaskMessage($"stage:{stage}", MessageLevel.Info);
|
|
|
- }
|
|
|
- string kbsnitem = item.FirstOrDefault(f => f.Contains("KB="));
|
|
|
- if (kbsnitem != null)
|
|
|
- {
|
|
|
- kb_sn = kbsnitem.Replace("KB=", "").Trim();
|
|
|
- SendTaskMessage($"KB:{kb_sn}", MessageLevel.Info);
|
|
|
- }
|
|
|
- }
|
|
|
- LogHelper.WriteLogMes($"第二次询问mes成功");
|
|
|
- SendTaskMessage($"第二次询问mes成功:{response2}", MessageLevel.Debug);
|
|
|
-
|
|
|
- var q = await _systemDatabaseService.QueryProductFromMesAsync(model_num, color);
|
|
|
- if (!string.IsNullOrEmpty(q))
|
|
|
- {
|
|
|
- ProductWithMes productWithMes = new ProductWithMes();
|
|
|
- ProductList = new ObservableCollection<ProductModel>(_productService.GetAllProducts());
|
|
|
- Guid productId = Guid.Empty;
|
|
|
- foreach (var itt in ProductList)
|
|
|
- {
|
|
|
- if (itt.Name == q)
|
|
|
- {
|
|
|
- productId = itt.ID;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (currentProduct.ID != productId || productWithMes.ProductKBSN != kb_sn)
|
|
|
- {
|
|
|
- //切换产品
|
|
|
- _productService.LoadProduct(productId);
|
|
|
- _productService.SetCurrentProduct(productId);
|
|
|
- await WritePositionToPlcAsync();
|
|
|
- SendTaskMessage($"切换产品成功", MessageLevel.Debug);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)1);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- LogHelper.WriteLogMes($"第二次询问mes失败");
|
|
|
- SendTaskMessage($"第二次询问mes失败:{response2}", MessageLevel.Error);
|
|
|
-
|
|
|
- await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)3);
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //产品发生改变并且供料器发生了变化时,需要通知PLC进行取料更改
|
|
|
-
|
|
|
- await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)3);
|
|
|
-
|
|
|
- LogHelper.WriteLogMes($"询问mes失败");
|
|
|
- SendTaskMessage($"询问mes失败:{response}", MessageLevel.Error);
|
|
|
- }
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
if (procIds.Count == 0 && cameraIndex != currentProduct.PhotoCountStop)
|
|
|
{
|
|
|
SendTaskMessage($"Point#{cameraIndex} 未配置任何视觉流程 (CameraProcedureId1/2/3)", MessageLevel.Alarm);
|
|
|
@@ -1986,12 +1701,17 @@ namespace TeamAAS_VP.Core
|
|
|
lockResultsAll = new ConcurrentBag<LockResult>();
|
|
|
|
|
|
int count = 0;
|
|
|
+ int isscan = 0;
|
|
|
var AllProcId = new List<Guid>();
|
|
|
foreach (var item in currentProduct.AoiPoints)
|
|
|
{
|
|
|
if (item.Enable_Start_Node == 1)
|
|
|
{
|
|
|
#region 判断执行视觉模板个数
|
|
|
+ if (item.Label == "扫码")
|
|
|
+ {
|
|
|
+ isscan = -1;
|
|
|
+ }
|
|
|
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);
|
|
|
@@ -2002,8 +1722,9 @@ namespace TeamAAS_VP.Core
|
|
|
if (item.CameraProcedureId8 != Guid.Empty && !AllProcId.Contains(item.CameraProcedureId8)) AllProcId.Add(item.CameraProcedureId8);
|
|
|
#endregion
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
- count = AllProcId.Count;
|
|
|
+ count = AllProcId.Count + isscan;
|
|
|
countdown = new CountdownEvent(count);
|
|
|
SendTaskMessage($"需要执行模板数:{count}", MessageLevel.Alarm);
|
|
|
_ = App.Current.Dispatcher.BeginInvoke(new Action(() =>
|
|
|
@@ -2347,6 +2068,7 @@ namespace TeamAAS_VP.Core
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
//不能使用全局变量,不然并发的时候会被清除掉,所以局部变量
|
|
|
var _ImageTaskList = new List<Task<(bool IsSucceed, ICogImage[] Images, string Message, int cameraIndex, Guid procedureId)>>();
|
|
|
|
|
|
@@ -2417,6 +2139,8 @@ namespace TeamAAS_VP.Core
|
|
|
else
|
|
|
{
|
|
|
SendTaskMessage($"图像采集失败!{item.cameraIndex}: {item.procedureId}", MessageLevel.Alarm);
|
|
|
+ AllResult.Add(false);
|
|
|
+ ClearCountdown();
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
@@ -2447,7 +2171,7 @@ namespace TeamAAS_VP.Core
|
|
|
|
|
|
foreach (var item in AllResult)
|
|
|
{
|
|
|
- if (item)
|
|
|
+ if (!item)
|
|
|
{
|
|
|
resultFlog = false;
|
|
|
break;
|
|
|
@@ -3695,8 +3419,6 @@ namespace TeamAAS_VP.Core
|
|
|
SendTaskMessage($"执行 AOI 视觉流程异常: {ex.Message}", MessageLevel.Alarm);
|
|
|
}
|
|
|
|
|
|
- countdown.Signal(); // -1
|
|
|
-
|
|
|
//return (true, results.ToArray(), $"成功");
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
@@ -3704,6 +3426,35 @@ namespace TeamAAS_VP.Core
|
|
|
LogHelper.WriteLogError("处理固定相机检测拍照时出错", ex);
|
|
|
//return (false, null, $"处理固定相机检测拍照时出错");
|
|
|
}
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ countdown?.Signal(); // -1
|
|
|
+ }
|
|
|
+ catch (InvalidOperationException ex)
|
|
|
+ {
|
|
|
+ LogHelper.WriteLogError("AOI流程完成计数Signal失败", ex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ClearCountdown()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var currentCountdown = countdown;
|
|
|
+ if (currentCountdown == null || currentCountdown.IsSet)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ currentCountdown.Signal(currentCountdown.CurrentCount);
|
|
|
+ }
|
|
|
+ catch (InvalidOperationException ex)
|
|
|
+ {
|
|
|
+ LogHelper.WriteLogError("AOI流程计数清零失败", ex);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|