|
|
@@ -1,5 +1,6 @@
|
|
|
using Cognex.VisionPro;
|
|
|
using CSScripting;
|
|
|
+//using ICSharpCode.SharpZipLib.Zip;
|
|
|
using Prism.Events;
|
|
|
using Prism.Ioc;
|
|
|
using Prism.Mvvm;
|
|
|
@@ -9,6 +10,7 @@ using System.Collections.Generic;
|
|
|
using System.Collections.ObjectModel;
|
|
|
using System.Drawing;
|
|
|
using System.IO;
|
|
|
+using System.IO.Compression;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading;
|
|
|
@@ -55,7 +57,14 @@ namespace TeamAAS_VP.Core
|
|
|
/// 产品主sn
|
|
|
/// </summary>
|
|
|
string ProductMainSN = "";
|
|
|
+ /// <summary>
|
|
|
+ /// 工单信息
|
|
|
+ /// </summary>
|
|
|
string wo = "";
|
|
|
+ string model_num = "";//产品model_num
|
|
|
+ string color = "";//产品color
|
|
|
+ string ppid = "";//产品ppid
|
|
|
+ string revision = "";//产品revision
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
@@ -203,6 +212,13 @@ namespace TeamAAS_VP.Core
|
|
|
|
|
|
public Dictionary<string, object> BackupObject { get; set; } = new Dictionary<string, object>();
|
|
|
|
|
|
+
|
|
|
+ private ObservableCollection<ProductModel> _ProductList;
|
|
|
+ public ObservableCollection<ProductModel> ProductList
|
|
|
+ {
|
|
|
+ get { return _ProductList; }
|
|
|
+ set { SetProperty(ref _ProductList, value); }
|
|
|
+ }
|
|
|
#endregion
|
|
|
|
|
|
#region 命令
|
|
|
@@ -1408,6 +1424,7 @@ namespace TeamAAS_VP.Core
|
|
|
Int16 _LastPickINC = 0;
|
|
|
DateTime[] _LastMesCheckTime = new DateTime[10];
|
|
|
List<Task<(bool IsSucceed, bool[] Result, string Message)>> _PrcTaskList = new List<Task<(bool IsSucceed, bool[] Result, string Message)>>();
|
|
|
+ List<Task<(bool IsSucceed, ICogImage[] Images, string Message, int cameraIndex, Guid procedureId)>> _ImageTaskList = new List<Task<(bool IsSucceed, ICogImage[] Images, string Message, int cameraIndex, Guid procedureId)>>();
|
|
|
|
|
|
private readonly object _stateLock = new object();
|
|
|
|
|
|
@@ -1623,20 +1640,71 @@ namespace TeamAAS_VP.Core
|
|
|
if (response != "MES功能未启用!")
|
|
|
{
|
|
|
string[] items = response.Split('\n');
|
|
|
- if (items[3].Contains("sn="))
|
|
|
+ string snItem = items.FirstOrDefault(f => f.Contains("sn="));
|
|
|
+ if (snItem != null)
|
|
|
{
|
|
|
- ProductMainSN = items[3].Replace("sn=", "");
|
|
|
+ ProductMainSN = snItem.Replace("sn=", "").Trim();
|
|
|
_productService.CurrentProductCode = ProductMainSN;
|
|
|
+ SendTaskMessage($"产品主sn:{ProductMainSN}", MessageLevel.Info);
|
|
|
}
|
|
|
- SendTaskMessage($"产品主sn:{ProductMainSN}", MessageLevel.Info);
|
|
|
- if (items[5].Contains("wo="))
|
|
|
+ string woItem = items.FirstOrDefault(f => f.Contains("wo="));
|
|
|
+ if (snItem != null)
|
|
|
{
|
|
|
- wo = items[5].Replace("wo=", "");
|
|
|
+ wo = snItem.Replace("wo=", "").Trim();
|
|
|
+ SendTaskMessage($"产品wo:{wo}", MessageLevel.Info);
|
|
|
}
|
|
|
- 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 = colorItem.Replace("ppid=", "").Trim();
|
|
|
+ SendTaskMessage($"ppid:{ppid}", MessageLevel.Info);
|
|
|
+ }
|
|
|
+ string revisionItem = items.FirstOrDefault(f => f.Contains("revision="));
|
|
|
+ if (revisionItem != null)
|
|
|
+ {
|
|
|
+ revision = colorItem.Replace("revision=", "").Trim();
|
|
|
+ SendTaskMessage($"revision:{revision}", MessageLevel.Info);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
LogHelper.WriteLogMes($"【mes结束QUERY】");
|
|
|
SendTaskMessage($"mes结束QUERY", MessageLevel.Info);
|
|
|
+ var q = await _systemDatabaseService.QueryProductFromMesAsync(model_num, color);
|
|
|
+ if (!string.IsNullOrEmpty(q))
|
|
|
+ {
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ //切换产品
|
|
|
+ _productService.LoadProduct(productId);
|
|
|
+ _productService.SetCurrentProduct(productId);
|
|
|
+ await WritePositionToPlcAsync();
|
|
|
+ SendTaskMessage($"切换产品成功", MessageLevel.Debug);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)1);
|
|
|
return;
|
|
|
}
|
|
|
@@ -1689,9 +1757,10 @@ namespace TeamAAS_VP.Core
|
|
|
if (response != "MES功能未启用!")
|
|
|
{
|
|
|
string[] item = response.Split('\n');
|
|
|
- if (item[2].Contains("sn="))
|
|
|
+ string snItem = item.FirstOrDefault(f => f.Contains("sn="));
|
|
|
+ if (snItem != null)
|
|
|
{
|
|
|
- ProductMainSN_Temp = item[2].Replace("sn=", "");
|
|
|
+ ProductMainSN_Temp = snItem.Replace("sn=", "").Trim();
|
|
|
SendTaskMessage($"sn:{ProductMainSN_Temp}", MessageLevel.Info);
|
|
|
}
|
|
|
}
|
|
|
@@ -1708,21 +1777,72 @@ namespace TeamAAS_VP.Core
|
|
|
if (response2 != "MES功能未启用!")
|
|
|
{
|
|
|
string[] item = response2.Split('\n');
|
|
|
- if (item[3].Contains("sn="))
|
|
|
+
|
|
|
+ string snItem = item.FirstOrDefault(f => f.Contains("sn="));
|
|
|
+ if (snItem != null)
|
|
|
{
|
|
|
- ProductMainSN = item[3].Replace("sn=", "");
|
|
|
+ ProductMainSN = snItem.Replace("sn=", "").Trim();
|
|
|
_productService.CurrentProductCode = ProductMainSN;
|
|
|
- SendTaskMessage($"产品主sn:{ProductMainSN}", MessageLevel.Info);
|
|
|
+ SendTaskMessage($"产品主sn:{ProductMainSN}", MessageLevel.Info);
|
|
|
+ }
|
|
|
+ string woItem = item.FirstOrDefault(f => f.Contains("wo="));
|
|
|
+ if (snItem != null)
|
|
|
+ {
|
|
|
+ wo = snItem.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);
|
|
|
}
|
|
|
- if (item[5].Contains("wo="))
|
|
|
+ string colorItem = item.FirstOrDefault(f => f.Contains("color="));
|
|
|
+ if (colorItem != null)
|
|
|
{
|
|
|
- wo = item[5].Replace("wo=", "");
|
|
|
- SendTaskMessage($"产品主wo:{wo}", MessageLevel.Info);
|
|
|
+ color = colorItem.Replace("color=", "").Trim();
|
|
|
+ SendTaskMessage($"color:{color}", MessageLevel.Info);
|
|
|
+ }
|
|
|
+ string ppidItem = item.FirstOrDefault(f => f.Contains("ppid="));
|
|
|
+ if (ppidItem != null)
|
|
|
+ {
|
|
|
+ ppid = colorItem.Replace("ppid=", "").Trim();
|
|
|
+ SendTaskMessage($"ppid:{ppid}", MessageLevel.Info);
|
|
|
+ }
|
|
|
+ string revisionItem = item.FirstOrDefault(f => f.Contains("revision="));
|
|
|
+ if (revisionItem != null)
|
|
|
+ {
|
|
|
+ revision = colorItem.Replace("revision=", "").Trim();
|
|
|
+ SendTaskMessage($"revision:{revision}", MessageLevel.Info);
|
|
|
}
|
|
|
}
|
|
|
LogHelper.WriteLogMes($"第二次询问mes成功");
|
|
|
SendTaskMessage($"第二次询问mes成功:{response2}", MessageLevel.Debug);
|
|
|
|
|
|
+ var q = await _systemDatabaseService.QueryProductFromMesAsync(model_num, color);
|
|
|
+ if (!string.IsNullOrEmpty(q))
|
|
|
+ {
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ //切换产品
|
|
|
+ _productService.LoadProduct(productId);
|
|
|
+ _productService.SetCurrentProduct(productId);
|
|
|
+ await WritePositionToPlcAsync();
|
|
|
+ SendTaskMessage($"切换产品成功", MessageLevel.Debug);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)1);
|
|
|
}
|
|
|
else
|
|
|
@@ -1837,9 +1957,11 @@ namespace TeamAAS_VP.Core
|
|
|
if (response != "MES功能未启用!")
|
|
|
{
|
|
|
string[] item = response.Split('\n');
|
|
|
- if (item[2].Contains("sn="))
|
|
|
+
|
|
|
+ string snItem = item.FirstOrDefault(f => f.Contains("sn="));
|
|
|
+ if (snItem != null)
|
|
|
{
|
|
|
- ProductMainSN_Temp = item[2].Replace("sn=", "");
|
|
|
+ ProductMainSN_Temp = snItem.Replace("sn=", "").Trim();
|
|
|
SendTaskMessage($"sn:{ProductMainSN_Temp}", MessageLevel.Info);
|
|
|
}
|
|
|
}
|
|
|
@@ -1856,21 +1978,72 @@ namespace TeamAAS_VP.Core
|
|
|
if (response2 != "MES功能未启用!")
|
|
|
{
|
|
|
string[] item = response2.Split('\n');
|
|
|
- if (item[3].Contains("sn="))
|
|
|
+
|
|
|
+
|
|
|
+ string snItem = item.FirstOrDefault(f => f.Contains("sn="));
|
|
|
+ if (snItem != null)
|
|
|
{
|
|
|
- ProductMainSN = item[3].Replace("sn=", "");
|
|
|
+ ProductMainSN = snItem.Replace("sn=", "").Trim();
|
|
|
_productService.CurrentProductCode = ProductMainSN;
|
|
|
- SendTaskMessage($"产品主sn:{ProductMainSN}", MessageLevel.Info);
|
|
|
+ SendTaskMessage($"产品主sn:{ProductMainSN}", MessageLevel.Info);
|
|
|
+ }
|
|
|
+ string woItem = item.FirstOrDefault(f => f.Contains("wo="));
|
|
|
+ if (snItem != null)
|
|
|
+ {
|
|
|
+ wo = snItem.Replace("wo=", "").Trim();
|
|
|
+ SendTaskMessage($"产品wo:{wo}", MessageLevel.Info);
|
|
|
}
|
|
|
- if (item[5].Contains("wo="))
|
|
|
+ string modelItem = item.FirstOrDefault(f => f.Contains("model_num="));
|
|
|
+ if (modelItem != null)
|
|
|
{
|
|
|
- wo = item[5].Replace("wo=", "");
|
|
|
- SendTaskMessage($"产品主wo:{wo}", MessageLevel.Info);
|
|
|
+ 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 = colorItem.Replace("ppid=", "").Trim();
|
|
|
+ SendTaskMessage($"ppid:{ppid}", MessageLevel.Info);
|
|
|
+ }
|
|
|
+ string revisionItem = item.FirstOrDefault(f => f.Contains("revision="));
|
|
|
+ if (revisionItem != null)
|
|
|
+ {
|
|
|
+ revision = colorItem.Replace("revision=", "").Trim();
|
|
|
+ SendTaskMessage($"revision:{revision}", MessageLevel.Info);
|
|
|
}
|
|
|
}
|
|
|
LogHelper.WriteLogMes($"第二次询问mes成功");
|
|
|
SendTaskMessage($"第二次询问mes成功:{response2}", MessageLevel.Debug);
|
|
|
|
|
|
+ var q = await _systemDatabaseService.QueryProductFromMesAsync(model_num, color);
|
|
|
+ if (!string.IsNullOrEmpty(q))
|
|
|
+ {
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ //切换产品
|
|
|
+ _productService.LoadProduct(productId);
|
|
|
+ _productService.SetCurrentProduct(productId);
|
|
|
+ await WritePositionToPlcAsync();
|
|
|
+ SendTaskMessage($"切换产品成功", MessageLevel.Debug);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)1);
|
|
|
}
|
|
|
else
|
|
|
@@ -1958,20 +2131,71 @@ namespace TeamAAS_VP.Core
|
|
|
if (response != "MES功能未启用!")
|
|
|
{
|
|
|
string[] items = response.Split('\n');
|
|
|
- if (items[3].Contains("sn="))
|
|
|
+
|
|
|
+ string snItem = items.FirstOrDefault(f => f.Contains("sn="));
|
|
|
+ if (snItem != null)
|
|
|
{
|
|
|
- ProductMainSN = items[3].Replace("sn=", "");
|
|
|
+ ProductMainSN = snItem.Replace("sn=", "").Trim();
|
|
|
_productService.CurrentProductCode = ProductMainSN;
|
|
|
+ SendTaskMessage($"产品主sn:{ProductMainSN}", MessageLevel.Info);
|
|
|
}
|
|
|
- SendTaskMessage($"产品主sn:{ProductMainSN}", MessageLevel.Info);
|
|
|
- if (items[5].Contains("wo="))
|
|
|
+ string woItem = items.FirstOrDefault(f => f.Contains("wo="));
|
|
|
+ if (snItem != null)
|
|
|
{
|
|
|
- wo = items[5].Replace("wo=", "");
|
|
|
+ wo = snItem.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 = colorItem.Replace("ppid=", "").Trim();
|
|
|
+ SendTaskMessage($"ppid:{ppid}", MessageLevel.Info);
|
|
|
+ }
|
|
|
+ string revisionItem = items.FirstOrDefault(f => f.Contains("revision="));
|
|
|
+ if (revisionItem != null)
|
|
|
+ {
|
|
|
+ revision = colorItem.Replace("revision=", "").Trim();
|
|
|
+ SendTaskMessage($"revision:{revision}", MessageLevel.Info);
|
|
|
}
|
|
|
- SendTaskMessage($"产品wo:{wo}", MessageLevel.Info);
|
|
|
}
|
|
|
LogHelper.WriteLogMes($"【mes结束QUERY】");
|
|
|
SendTaskMessage($"mes结束QUERY", MessageLevel.Info);
|
|
|
+
|
|
|
+ var q = await _systemDatabaseService.QueryProductFromMesAsync(model_num, color);
|
|
|
+ if (!string.IsNullOrEmpty(q))
|
|
|
+ {
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ //切换产品
|
|
|
+ _productService.LoadProduct(productId);
|
|
|
+ _productService.SetCurrentProduct(productId);
|
|
|
+ await WritePositionToPlcAsync();
|
|
|
+ SendTaskMessage($"切换产品成功", MessageLevel.Debug);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)1);
|
|
|
return;
|
|
|
}
|
|
|
@@ -1992,27 +2216,33 @@ namespace TeamAAS_VP.Core
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
+ _ImageTaskList.Clear();
|
|
|
foreach (var prcId in procIds)
|
|
|
{
|
|
|
- if (Is3D(prcId))
|
|
|
- {
|
|
|
- _PrcTaskList.Add(ExecuteProcedureAsync(cameraIndex, prcId));
|
|
|
- }
|
|
|
- else
|
|
|
+ _ImageTaskList.Add(GrabImageEx(cameraIndex, prcId));
|
|
|
+ }
|
|
|
+ if (cameraIndex != currentProduct.PhotoCountStop)
|
|
|
+ {
|
|
|
+ //直接放行,执行下一个检测点
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)1);
|
|
|
+ }
|
|
|
+ if (_ImageTaskList.Count > 0)//如果2D取图有队列
|
|
|
+ {
|
|
|
+ var ImageTaskResults = await Task.WhenAll(_ImageTaskList);
|
|
|
+ foreach (var item in ImageTaskResults)
|
|
|
{
|
|
|
- //2d相机时,需要先等待图像采集完成
|
|
|
- var imageData = await GrabImage(cameraIndex, prcId);
|
|
|
- if (imageData.IsSucceed)
|
|
|
+ if (item.IsSucceed)
|
|
|
{
|
|
|
- _PrcTaskList.Add(ExecuteProcedureAsync(cameraIndex, prcId, imageData.imges));
|
|
|
+ _PrcTaskList.Add(ExecuteProcedureAsync(item.cameraIndex, item.procedureId, item.Images));
|
|
|
+ //_PrcTaskList.Add(ExecuteProcedureAsync(cameraIndex, prcId, imageData.imges));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- SendTaskMessage($"图像采集失败!{cameraIndex}: {prcId}", MessageLevel.Alarm);
|
|
|
+ SendTaskMessage($"图像采集失败!{item.cameraIndex}: {item.procedureId}", MessageLevel.Alarm);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
//如果最后一个拍照点,则需要等待前面所有的拍照处理完成
|
|
|
if (cameraIndex == currentProduct.PhotoCountStop)
|
|
|
{
|
|
|
@@ -2026,6 +2256,7 @@ namespace TeamAAS_VP.Core
|
|
|
if (!item.IsSucceed || item.Result == null)
|
|
|
{
|
|
|
resultFlog = false;
|
|
|
+ break;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -2052,13 +2283,7 @@ namespace TeamAAS_VP.Core
|
|
|
SendTaskMessage($"检测执行失败", MessageLevel.Alarm);
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)2);
|
|
|
}
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //直接放行,执行下一个检测点
|
|
|
- //SendTaskMessage($"流程执行成功", MessageLevel.Info);
|
|
|
- await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)1);
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -2148,9 +2373,61 @@ namespace TeamAAS_VP.Core
|
|
|
wo = woItem.Replace("wo=", "").Trim();
|
|
|
SendTaskMessage($"工单信息:{wo[i]}", 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 = colorItem.Replace("ppid=", "").Trim();
|
|
|
+ SendTaskMessage($"ppid:{ppid}", MessageLevel.Info);
|
|
|
+ }
|
|
|
+ string revisionItem = item.FirstOrDefault(f => f.Contains("revision="));
|
|
|
+ if (revisionItem != null)
|
|
|
+ {
|
|
|
+ revision = colorItem.Replace("revision=", "").Trim();
|
|
|
+ SendTaskMessage($"revision:{revision}", MessageLevel.Info);
|
|
|
+ }
|
|
|
ShowMes_Query = true;
|
|
|
//产品发生改变并且供料器发生了变化时,需要通知PLC进行取料更改
|
|
|
|
|
|
+ //切换产品
|
|
|
+ if (i == 0)//i=0时才会切换产品
|
|
|
+ {
|
|
|
+ var q = await _systemDatabaseService.QueryProductFromMesAsync(model_num, color);
|
|
|
+ if (!string.IsNullOrEmpty(q))
|
|
|
+ {
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ //切换产品
|
|
|
+ _productService.LoadProduct(productId);
|
|
|
+ _productService.SetCurrentProduct(productId);
|
|
|
+ await WritePositionToPlcAsync();
|
|
|
+ SendTaskMessage($"切换产品成功", MessageLevel.Debug);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
await plc.WriteNodeAsync(string.Format(addressConfig.Out_MesStatus.Address, i), (Int16)1);
|
|
|
|
|
|
LogHelper.WriteLogMes($"【mes结束QUERY】");
|
|
|
@@ -2216,8 +2493,9 @@ namespace TeamAAS_VP.Core
|
|
|
StringBuilder submitData = new StringBuilder();
|
|
|
foreach (var item in lockResultsAll)
|
|
|
{
|
|
|
- submitData.Append($"{item.PhotoName}-{item.ResultData}");
|
|
|
+ submitData.Append($"{item.PhotoName}={item.ResultData}&");
|
|
|
}
|
|
|
+
|
|
|
ShowMes_Result = resultIndex == 1 ? true : false;
|
|
|
//(bool isSuccess, string response) = await _mesService.SubmitGetAsync(ProductMainSN, "", MesData.Replace("--", "-"), resultIndex == 1 ? true : false, _LastMesCheckTime[i], DateTime.UtcNow);
|
|
|
(bool isSuccess, string response) = await _mesService.SubmitGetAsync(ProductMainSN, "", submitData.ToString(), resultIndex == 1 ? true : false, _LastMesCheckTime[i], serverTimeResult.Now);
|
|
|
@@ -2244,17 +2522,17 @@ namespace TeamAAS_VP.Core
|
|
|
{
|
|
|
DFC.Add(new DataFormCtq
|
|
|
{
|
|
|
- PPID = ProductMainSN,
|
|
|
+ PPID = ppid,
|
|
|
PROCESS_NAME = stationConfig.DataInfo.PROCESS_NAME,
|
|
|
- PROCESS_START_TIME = _LastMesCheckTime[i].ToString(),
|
|
|
+ PROCESS_START_TIME = _LastMesCheckTime[i].ToString("o"),
|
|
|
CTQ_NAME = item.PhotoName,
|
|
|
CTQ_VALUE = item.ResultData.Replace(",", ";"),
|
|
|
CTQ_LSL = item.DownLimit,
|
|
|
CTQ_USL = item.UpLimit,
|
|
|
- PROCESS_END_TIME = serverTimeResult.Now.ToString(),
|
|
|
+ PROCESS_END_TIME = serverTimeResult.Now.ToString("o"),
|
|
|
SUPPLIER_NAME = stationConfig.DataInfo.SUPPLIER_NAME,
|
|
|
COMMODITY_TYPE = stationConfig.DataInfo.COMMODITY_TYPE,
|
|
|
- REVISION = stationConfig.DataInfo.REVISION,
|
|
|
+ REVISION = revision,
|
|
|
WO = wo,
|
|
|
MFG_LOT = stationConfig.DataInfo.MFG_LOT,
|
|
|
MFG_ASSY_LINE = stationConfig.DataInfo.MFG_ASSY_LINE,
|
|
|
@@ -2262,7 +2540,7 @@ namespace TeamAAS_VP.Core
|
|
|
PROCESS_MACHINE_ID = stationConfig.DataInfo.PROCESS_MACHINE_ID,
|
|
|
CTQ_UNIT_OF_MEASURE = "mm",
|
|
|
ERROR_MESSAGE = item.PhotoPassed == "OK" ? "" : $"{item.PhotoName} OOS",
|
|
|
- PD_ATTR_01= "xxxxxxxx1",
|
|
|
+ PD_ATTR_01= ProductMainSN,
|
|
|
PD_ATTR_02 = item.MidLimit,
|
|
|
PD_ATTR_03 = "",
|
|
|
PD_ATTR_04 = "",
|
|
|
@@ -2274,6 +2552,39 @@ namespace TeamAAS_VP.Core
|
|
|
if (recordResult)
|
|
|
{
|
|
|
SendTaskMessage($"{i}:{stationConfig.DeviceName}产品记录保存成功", MessageLevel.Debug);
|
|
|
+ //上传数据
|
|
|
+ try
|
|
|
+ {
|
|
|
+ DateTime dt = DateTime.Now;
|
|
|
+ string filename = $"{ProductMainSN}_{dt.ToString("yyyyMMddHHmmss")}";
|
|
|
+ var device = _configService.GetDeviceInfo();
|
|
|
+ (bool isSuc, string resp) = await _mesService.SendFtpFileAsync(ProductMainSN, filename);
|
|
|
+ if (isSuc)
|
|
|
+ {
|
|
|
+ LogHelper.WriteLogMes($"上传数据成功");
|
|
|
+ SendTaskMessage($"上传数据成功", MessageLevel.Debug);
|
|
|
+ string filePath = $"D:\\Image\\Recored\\{dt.ToString("yyyy-MM")}\\{dt.ToString("MM-dd")}\\{currentProduct.Name}\\{ProductMainSN[i]}";
|
|
|
+ //复制csv
|
|
|
+ string source_csv = $"{stationConfig.SaveCsvPath}\\{dt.ToString("yyyy-MM")}\\{i}_{stationConfig.DeviceName}_{dt.ToString("yyyy-MM-dd")}.csv";
|
|
|
+ string target_csv = Path.Combine(filePath, Path.GetFileName(source_csv)); ;
|
|
|
+ File.Copy(source_csv, target_csv, true);
|
|
|
+ //复制log
|
|
|
+ string source_log = $"..\\Log\\LogInfo\\{dt.ToString("yyyy-MM")}\\{dt.ToString("yyyy-MM-dd")}.txt";
|
|
|
+ string target_log = Path.Combine(filePath, Path.GetFileName(source_log));
|
|
|
+ File.Copy(source_log, target_log, true);
|
|
|
+ CompressionImage(filePath, filename, device.Station, device.FixtureId);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ LogHelper.WriteLogMes($"上传数据失败");
|
|
|
+ SendTaskMessage($"上传数据失败", MessageLevel.Error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ SendTaskMessage($"上传数据时出错:{ex.Message}", MessageLevel.Error);
|
|
|
+ LogHelper.WriteLogError($"上传数据时出错", ex);
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -2560,65 +2871,99 @@ namespace TeamAAS_VP.Core
|
|
|
//}
|
|
|
|
|
|
string[] strpoints1 = visionResult.Items[i].Split(',');
|
|
|
- lockResult1.PhotoName = strpoints1[0];
|
|
|
string[] body1 = strpoints1[1].Split(";");
|
|
|
- string body2 = null;
|
|
|
-
|
|
|
- if (body1.Length == 8)
|
|
|
- {
|
|
|
- body2 = $"{body1[0]},{body1[2]},{body1[4]},{body1[6]}";
|
|
|
- }
|
|
|
- else
|
|
|
+ if (body1.Length > 1)
|
|
|
{
|
|
|
- body2 = strpoints1[1];
|
|
|
- }
|
|
|
- lockResult1.ResultData = body2;
|
|
|
- lockResult1.PhotoCode = ProductMainSN;
|
|
|
- var globalParam = currentProduct.GlobalParamListCollection.FirstOrDefault(p => p.Name == strpoints1[0]);
|
|
|
- if (globalParam != null)
|
|
|
- {
|
|
|
- lockResult1.UpLimit = globalParam.Param1;
|
|
|
- lockResult1.DownLimit = globalParam.Param2;
|
|
|
- lockResult1.MidLimit = globalParam.Param5;
|
|
|
- string ResData = strpoints1[1];
|
|
|
- if (ResData.Contains("NA"))
|
|
|
- {
|
|
|
- ResData = "-1000";
|
|
|
- }
|
|
|
- string[] body = ResData.Split(";");
|
|
|
- bool resultflog = true;
|
|
|
- foreach (var item in body)
|
|
|
+ for (int j = 1; j <= body1.Length; j++)
|
|
|
{
|
|
|
- if (Convert.ToDouble(item) >= Convert.ToDouble(globalParam.Param2) && Convert.ToDouble(item) <= Convert.ToDouble(globalParam.Param1))
|
|
|
+ lockResult1.PhotoName = strpoints1[0] + j.ToString();
|
|
|
+ lockResult1.ResultData = body1[j - 1];
|
|
|
+ lockResult1.PhotoCode = ProductMainSN;
|
|
|
+ var globalParam = currentProduct.GlobalParamListCollection.FirstOrDefault(p => p.Name == strpoints1[0]);
|
|
|
+ if (globalParam != null)
|
|
|
{
|
|
|
+ lockResult1.UpLimit = globalParam.Param1;
|
|
|
+ lockResult1.DownLimit = globalParam.Param2;
|
|
|
+ lockResult1.MidLimit = globalParam.Param5;
|
|
|
+ string ResData = strpoints1[1];
|
|
|
+ if (ResData.Contains("NA"))
|
|
|
+ {
|
|
|
+ ResData = "-1000";
|
|
|
+ }
|
|
|
+
|
|
|
+ bool resultflog = true;
|
|
|
+ if (Convert.ToDouble(lockResult1.ResultData) >= Convert.ToDouble(globalParam.Param2) && Convert.ToDouble(lockResult1.ResultData) <= Convert.ToDouble(globalParam.Param1))
|
|
|
+ {
|
|
|
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ resultflog = false;
|
|
|
+ }
|
|
|
+ if (resultflog)
|
|
|
+ {
|
|
|
+ lockResult1.PhotoPassed = "OK";
|
|
|
+ results.Add(true);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ lockResult1.PhotoPassed = "NG";
|
|
|
+ results.Add(false);
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
+ lock (_stateLock)
|
|
|
{
|
|
|
- resultflog = false;
|
|
|
+ lockResultsAll.Add(lockResult1);
|
|
|
}
|
|
|
}
|
|
|
- if (resultflog)
|
|
|
- {
|
|
|
- lockResult1.PhotoPassed = "OK";
|
|
|
- results.Add(true);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- lockResult1.PhotoPassed = "NG";
|
|
|
- results.Add(false);
|
|
|
- }
|
|
|
}
|
|
|
-
|
|
|
- lock (_stateLock)
|
|
|
+ else
|
|
|
{
|
|
|
- lockResultsAll.Add(lockResult1);
|
|
|
+ lockResult1.PhotoName = strpoints1[0];
|
|
|
+ lockResult1.ResultData = strpoints1[1];
|
|
|
+ lockResult1.PhotoCode = ProductMainSN;
|
|
|
+ var globalParam = currentProduct.GlobalParamListCollection.FirstOrDefault(p => p.Name == strpoints1[0]);
|
|
|
+ if (globalParam != null)
|
|
|
+ {
|
|
|
+ lockResult1.UpLimit = globalParam.Param1;
|
|
|
+ lockResult1.DownLimit = globalParam.Param2;
|
|
|
+ lockResult1.MidLimit = globalParam.Param5;
|
|
|
+ string ResData = strpoints1[1];
|
|
|
+ if (ResData.Contains("NA"))
|
|
|
+ {
|
|
|
+ ResData = "-1000";
|
|
|
+ }
|
|
|
+
|
|
|
+ bool resultflog = true;
|
|
|
+ if (Convert.ToDouble(lockResult1.ResultData) >= Convert.ToDouble(globalParam.Param2) && Convert.ToDouble(lockResult1.ResultData) <= Convert.ToDouble(globalParam.Param1))
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ resultflog = false;
|
|
|
+ }
|
|
|
+ if (resultflog)
|
|
|
+ {
|
|
|
+ lockResult1.PhotoPassed = "OK";
|
|
|
+ results.Add(true);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ lockResult1.PhotoPassed = "NG";
|
|
|
+ results.Add(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ lock (_stateLock)
|
|
|
+ {
|
|
|
+ lockResultsAll.Add(lockResult1);
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- App.Current.Dispatcher.Invoke(() =>
|
|
|
- {
|
|
|
- _eventAggregator.GetEvent<LockFinishNotification>().Publish(lockResult1);
|
|
|
- });
|
|
|
+
|
|
|
+ App.Current.Dispatcher.Invoke(() =>
|
|
|
+ {
|
|
|
+ _eventAggregator.GetEvent<LockFinishNotification>().Publish(lockResult1);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
////排序
|
|
|
@@ -3084,5 +3429,111 @@ namespace TeamAAS_VP.Core
|
|
|
SendTaskMessage(Lang.扫码枪接收信息时出错 + ex.Message, MessageLevel.Error);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 2D相机先采集图像
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="procedureId"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private async Task<(bool IsSucceed, ICogImage[] imges, string Message, int pointIndex, Guid procedureId)> GrabImageEx(int pointIndex, Guid procedureId)
|
|
|
+ {
|
|
|
+ // 获取当前产品
|
|
|
+ var currentProduct = _productService.GetCurrentProduct();
|
|
|
+ if (currentProduct == null)
|
|
|
+ {
|
|
|
+ return (false, null, "当前产品为空,未加载产品!", pointIndex, procedureId);
|
|
|
+ }
|
|
|
+
|
|
|
+ var cameraProcedures = currentProduct.CameraProcedures;
|
|
|
+ if (cameraProcedures == null || cameraProcedures.Count == 0)
|
|
|
+ {
|
|
|
+ SendTaskMessage($"当前产品未配置 CameraProcedures,无法执行视觉流程", MessageLevel.Alarm);
|
|
|
+ return (false, null, $"当前产品未配置 CameraProcedures,无法执行视觉流程", pointIndex, procedureId);
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ ProcedureModel selectedProcedure = null;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ foreach (var cp in cameraProcedures)
|
|
|
+ {
|
|
|
+ if (cp?.ProcedureModels == null) continue;
|
|
|
+ selectedProcedure = cp.ProcedureModels.FirstOrDefault(pm => pm.Id == procedureId);
|
|
|
+
|
|
|
+ if (selectedProcedure != null) break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ LogHelper.WriteLogError("查找 AOI 点位对应视觉流程时出错", ex);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (selectedProcedure == null)
|
|
|
+ {
|
|
|
+ SendTaskMessage($"未找到 AOI 点位对应的视觉流程,Point#{pointIndex} ProcedureId={pointIndex}", MessageLevel.Alarm);
|
|
|
+ return (false, null, $"未找到 AOI 点位对应的视觉流程,Point#{pointIndex} ProcedureId={procedureId}", pointIndex, procedureId);
|
|
|
+ }
|
|
|
+
|
|
|
+ SendTaskMessage($"开始执行 AOI 流程 (Point#{pointIndex}) 流程Id={pointIndex}", MessageLevel.Debug);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var sysConfig = _configService.GetSystemConfiguration();
|
|
|
+ if (selectedProcedure.Id == currentProduct.FixedDownCameraProcedureId && sysConfig.TurnOnAllLightUse == true)
|
|
|
+ {
|
|
|
+ await _remoteCommandService.SetLightBeforePhoto(selectedProcedure);
|
|
|
+ }
|
|
|
+ //1. 执行拍照
|
|
|
+ var res = await _remoteCommandService.ExecuteGrabImageAsync(selectedProcedure);
|
|
|
+ return (res.IsSucceed, res.Image, res.Msg, pointIndex, procedureId);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ LogHelper.WriteLogError("执行 AOI 视觉图像采集时出错", ex);
|
|
|
+ SendTaskMessage($"执行 AOI 视觉图像采集时出错: {ex.Message}", MessageLevel.Alarm);
|
|
|
+ }
|
|
|
+
|
|
|
+ return (false, null, $"图像采集失败", pointIndex, procedureId);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ LogHelper.WriteLogError("处理固定相机检测拍照时出错", ex);
|
|
|
+ return (false, null, $"处理固定相机检测拍照时出错", pointIndex, procedureId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ #region 压缩图片文件夹
|
|
|
+ /// <summary>
|
|
|
+ /// 压缩文件
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="sourcePath">原路径</param>
|
|
|
+ /// <param name="zipname">压缩后文件的名称</param>
|
|
|
+ /// <param name="station">mes中的station</param>
|
|
|
+ /// <param name="fixid">mes中的fixtureID</param>
|
|
|
+ public async void CompressionImage(string sourcePath, string zipname, string station, string fixid)
|
|
|
+ {
|
|
|
+ string zipPath = "";
|
|
|
+ try
|
|
|
+ {
|
|
|
+ SendTaskMessage($"开始压缩文件", MessageLevel.Info);
|
|
|
+ await Task.Run(() =>
|
|
|
+ {
|
|
|
+ zipPath = $"Z:\\{station}\\{fixid}\\{DateTime.Now.ToString("yyyyMMdd")}\\{zipname}.zip";//生成的zip文件路径
|
|
|
+ string path = $"Z:\\{station}\\{fixid}\\{DateTime.Now.ToString("yyyyMMdd")}";
|
|
|
+ if (!Directory.Exists(path))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(path);
|
|
|
+ }
|
|
|
+
|
|
|
+ ZipFile.CreateFromDirectory(sourcePath, zipPath);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ LogHelper.WriteLogError($"压缩文件时出错", ex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
}
|
|
|
}
|