KWD 7 месяцев назад
Родитель
Сommit
c802360b0e

+ 9 - 3
TeamAAS-VM/Core/Management.cs

@@ -1343,7 +1343,9 @@ namespace TeamAAS_VP.Core
 
                             // 执行视觉任务
                             var _cts = new CancellationTokenSource();
-                            var visionResult = await _remoteCommandService.ExecutePhotoGetSinglePoint(process, null, null, _cts.Token, cameraIndex, null);
+                            ImageParameters imgPara = new ImageParameters();
+                            imgPara.SNCode = productSn;
+                            var visionResult = await _remoteCommandService.ExecutePhotoGetSinglePoint(process, null, null, _cts.Token, cameraIndex, null, imgPara);
                             if (visionResult.IsSucceed)
                             {
                                 //披头偏差
@@ -1410,7 +1412,9 @@ namespace TeamAAS_VP.Core
 
                             // 执行视觉任务
                             var _cts = new CancellationTokenSource();
-                            var visionResult = await _remoteCommandService.ExecutePhotoGetSinglePoint(process, null, null, _cts.Token, cameraIndex, null);
+                            ImageParameters imgPara = new ImageParameters();
+                            imgPara.SNCode = productSn;
+                            var visionResult = await _remoteCommandService.ExecutePhotoGetSinglePoint(process, null, null, _cts.Token, cameraIndex, null, imgPara);
                             if (visionResult.IsSucceed)
                             {
                                 //披头偏差
@@ -1517,7 +1521,9 @@ namespace TeamAAS_VP.Core
 
                             // 执行视觉任务
                             var _cts = new CancellationTokenSource();
-                            var visionResult = await _remoteCommandService.ExecutePhotoGetSinglePoint(process, null, new double[] { currentPosition.X, currentPosition.Y, currentPosition.U }, _cts.Token, cameraIndex, null);
+                            ImageParameters imgPara = new ImageParameters();
+                            imgPara.SNCode = productSn;
+                            var visionResult = await _remoteCommandService.ExecutePhotoGetSinglePoint(process, null, new double[] { currentPosition.X, currentPosition.Y, currentPosition.U }, _cts.Token, cameraIndex, null, imgPara);
                             if (visionResult.IsSucceed)
                             {
                                 //是拍一个锁一个还是拍两个点锁所有

+ 5 - 5
TeamAAS-VM/Interfaces/IRemoteCommandService.cs

@@ -211,7 +211,7 @@ namespace TeamAAS_VP.Interfaces
         /// <param name="items">是否先振动</param>
         /// <param name="cancellationToken"></param>
         /// <returns></returns>
-        Task<(bool IsSucceed, string[] Response)> ExecuteVisionTaskAsync(ProcedureModel procedure, string[] items, CancellationToken cancellationToken);
+        Task<(bool IsSucceed, string[] Response)> ExecuteVisionTaskAsync(ProcedureModel procedure, string[] items, CancellationToken cancellationToken, ImageParameters imgPara);
 
         /// <summary>
         /// 执行Feeder视觉引导任务
@@ -221,7 +221,7 @@ namespace TeamAAS_VP.Interfaces
         /// <param name="items"></param>
         /// <param name="cancellationToken"></param>
         /// <returns></returns>
-        Task<(bool IsSucceed, string[] Response)> ExecuteFeederVisionTaskAsync(IVoiceCoilMotorFeeder feeder, ProcedureModel procedure, string[] items, CancellationToken cancellationToken);
+        Task<(bool IsSucceed, string[] Response)> ExecuteFeederVisionTaskAsync(IVoiceCoilMotorFeeder feeder, ProcedureModel procedure, string[] items, CancellationToken cancellationToken, ImageParameters imgPara);
 
         /// <summary>
         /// 执行普通视觉任务
@@ -230,7 +230,7 @@ namespace TeamAAS_VP.Interfaces
         /// <param name="items"></param>
         /// <param name="cancellationToken"></param>
         /// <returns></returns>
-        Task<(bool IsSucceed, string Response)> ExecuteNormalVisionTaskAsync(ProcedureModel procedure, string[] items, CancellationToken cancellationToken);
+        Task<(bool IsSucceed, string Response)> ExecuteNormalVisionTaskAsync(ProcedureModel procedure, string[] items, CancellationToken cancellationToken, ImageParameters imgPara);
 
         /// <summary>
         /// 执行相机拍照
@@ -239,7 +239,7 @@ namespace TeamAAS_VP.Interfaces
         /// <param name="InputTerminal"></param>
         /// <param name="outputCollection"></param>
         /// <returns></returns>
-        bool ExecutePhoto(ProcedureModel procedure, Dictionary<string, string> InputTerminal, out CogToolBlockTerminalCollection outputCollection);
+        bool ExecutePhoto(ProcedureModel procedure, Dictionary<string, string> InputTerminal, out CogToolBlockTerminalCollection outputCollection, ImageParameters imgPara);
         /// <summary>
         /// 执行拍照二维码流程运行
         /// </summary>
@@ -258,7 +258,7 @@ namespace TeamAAS_VP.Interfaces
         /// <param name="positionIndex"></param>
         /// <param name="remark"></param>
         /// <returns></returns>
-        Task<(bool IsSucceed, double X, double Y, double U)> ExecutePhotoGetSinglePoint(ProcedureModel procedure, Dictionary<string, string> InputTerminal, double[] robotCoord, CancellationToken cancellationToken, int positionIndex, string remark);
+        Task<(bool IsSucceed, double X, double Y, double U)> ExecutePhotoGetSinglePoint(ProcedureModel procedure, Dictionary<string, string> InputTerminal, double[] robotCoord, CancellationToken cancellationToken, int positionIndex, string remark, ImageParameters imgPara);
 
         /// <summary>
         /// 执行相机拍照获取单个点位结果,并且返回图像和图形

+ 22 - 0
TeamAAS-VM/Models/ImageParameters.cs

@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TeamAAS_VP.Models
+{
+    public class ImageParameters
+    {
+		private string _SNCode;
+		/// <summary>
+		/// SN
+		/// </summary>
+        public string SNCode
+		{
+			get { return _SNCode; }
+			set { _SNCode = value; }
+		}
+
+	}
+}

+ 7 - 16
TeamAAS-VM/Models/ShowRender.cs

@@ -111,23 +111,14 @@ namespace TeamAAS_VP.Models
             set { SetProperty(ref _IsCompress, value); }
         }
 
-        private ProductModel _CurrentProduct;
-
-        public ProductModel CurrentProduct
-        {
-            get { return _CurrentProduct; }
-            set { _CurrentProduct = value; }
-        }
-
-
-        private string _ProceductName;
-
-        public string ProceductName
+        private ImageParameters _ImgPara;
+        /// <summary>
+        /// 图片保存附加参数
+        /// </summary>
+        public ImageParameters ImgPara
         {
-            get { return _ProceductName; }
-            set { _ProceductName = value; }
+            get { return _ImgPara; }
+            set { SetProperty(ref _ImgPara, value); }
         }
-
-
     }
 }

+ 14 - 12
TeamAAS-VM/Services/RemoteCommandService.cs

@@ -551,7 +551,9 @@ namespace TeamAAS_VP.Services
 
                     var visionResult = await TrackExecutionAsync(async ct =>
                     {
-                        var r = await ExecuteVisionTaskAsync(procedure, commandParams, ct);
+                        ImageParameters imgPara = new ImageParameters();
+                        imgPara.SNCode = "SN";
+                        var r = await ExecuteVisionTaskAsync(procedure, commandParams, ct, imgPara);
                         return Tuple.Create(r.IsSucceed, r.Response);
                     }, isVision: true, cancellationToken);
                     if (visionResult.Item1)
@@ -1053,7 +1055,7 @@ namespace TeamAAS_VP.Services
         /// - 否则根据 procedure.FeederId 调用 Feeder 引导的视觉任务或普通视觉任务
         /// 返回是否成功以及字符串数组形式的响应(用于发送多条结果)。
         /// </summary>
-        public async Task<(bool IsSucceed, string[] Response)> ExecuteVisionTaskAsync(ProcedureModel procedure, string[] items, CancellationToken cancellationToken)
+        public async Task<(bool IsSucceed, string[] Response)> ExecuteVisionTaskAsync(ProcedureModel procedure, string[] items, CancellationToken cancellationToken, ImageParameters imgPara)
         {
             var currentProduct = _productService.GetCurrentProduct();
             string scriptFilePath = FilePath.ProductsPath + "//" + currentProduct.Name + "//" + procedure.CameraName + "//" + procedure.Name + ".cs";
@@ -1092,11 +1094,11 @@ namespace TeamAAS_VP.Services
                 if (procedure.FeederId != Guid.Empty)
                 {
                     Feeder = _feederService.GetFeeder(procedure.FeederId);
-                    return await ExecuteFeederVisionTaskAsync(Feeder, procedure, items, cancellationToken);
+                    return await ExecuteFeederVisionTaskAsync(Feeder, procedure, items, cancellationToken, imgPara);
                 }
                 else
                 {
-                    var result = await ExecuteNormalVisionTaskAsync(procedure, items, cancellationToken);
+                    var result = await ExecuteNormalVisionTaskAsync(procedure, items, cancellationToken, imgPara);
                     return (result.IsSucceed, new string[] { result.Response });
                 }
             }
@@ -1130,7 +1132,7 @@ namespace TeamAAS_VP.Services
         /// - 多次尝试拍照并运行视觉工具,直到成功或达到失败次数上限
         /// - 返回布尔成功标记及字符串数组形式的响应项
         /// </summary>
-        public async Task<(bool IsSucceed, string[] Response)> ExecuteFeederVisionTaskAsync(IVoiceCoilMotorFeeder feeder, ProcedureModel procedure, string[] items, CancellationToken cancellationToken)
+        public async Task<(bool IsSucceed, string[] Response)> ExecuteFeederVisionTaskAsync(IVoiceCoilMotorFeeder feeder, ProcedureModel procedure, string[] items, CancellationToken cancellationToken, ImageParameters imgPara)
         {
             // 如果输入的items中是否包含Vibration和NoVibration,这两个分别对应是否先振动和是否先拍照
             bool doVibrateFirst = items != null && items.Contains("VibrateFirst");
@@ -1185,7 +1187,7 @@ namespace TeamAAS_VP.Services
                 SendTaskMessage(Lang.开始执行视觉流程.Replace("{0}", $"{i + 1}").Replace("{1}", procedure.Name), MessageLevel.Info);
 
                 // 1. 执行相机拍照并运行视觉工具
-                bool visionSucceed = ExecutePhoto(procedure, InputTerminal, out CogToolBlockTerminalCollection outputCollection);
+                bool visionSucceed = ExecutePhoto(procedure, InputTerminal, out CogToolBlockTerminalCollection outputCollection, imgPara);
                 if (!visionSucceed)
                 {
                     SendTaskMessage(Lang.视觉任务执行失败, MessageLevel.Error);
@@ -1337,7 +1339,7 @@ namespace TeamAAS_VP.Services
         /// <summary>
         /// 执行非 Feeder 引导的普通视觉任务,返回单字符串响应。
         /// </summary>
-        public async Task<(bool IsSucceed, string Response)> ExecuteNormalVisionTaskAsync(ProcedureModel procedure, string[] items, CancellationToken cancellationToken)
+        public async Task<(bool IsSucceed, string Response)> ExecuteNormalVisionTaskAsync(ProcedureModel procedure, string[] items, CancellationToken cancellationToken, ImageParameters imgPara)
         {
             // 开始执行前的时间点
             DateTime startTime = DateTime.Now;
@@ -1374,7 +1376,7 @@ namespace TeamAAS_VP.Services
                     }
                     // 1. 执行相机拍照并运行视觉工具
                     LogHelper.WriteLogInfo(Lang.开始执行相机拍照并运行视觉工具);
-                    bool visionSucceed = ExecutePhoto(procedure, InputTerminal, out CogToolBlockTerminalCollection outputCollection);
+                    bool visionSucceed = ExecutePhoto(procedure, InputTerminal, out CogToolBlockTerminalCollection outputCollection, imgPara);
                     if (!visionSucceed)
                     {
                         SendTaskMessage(Lang.视觉任务执行失败, MessageLevel.Error);
@@ -1452,7 +1454,7 @@ namespace TeamAAS_VP.Services
         /// 执行相机拍照并运行 ToolBlock,返回是否成功并通过 out 参数返回 Outputs。
         /// 该方法会发布 RenderUpdateNotification 以更新 UI。
         /// </summary>
-        public bool ExecutePhoto(ProcedureModel procedure, Dictionary<string, string> InputTerminal, out CogToolBlockTerminalCollection outputCollection)
+        public bool ExecutePhoto(ProcedureModel procedure, Dictionary<string, string> InputTerminal, out CogToolBlockTerminalCollection outputCollection, ImageParameters imgPara)
         {
             try
             {
@@ -1528,7 +1530,7 @@ namespace TeamAAS_VP.Services
                         SaveImagePathModel = procedure.SaveImagePathModel,
                         SavePath = procedure.SavePath,
                         IsCompress = procedure.IsCompress,
-                        ProceductName = procedure.Name
+                        ImgPara = imgPara,
                     });
                     SendTaskMessage($"{procedure.CameraName},{procedure.CameraId}", MessageLevel.Info);
                     return true;
@@ -1768,7 +1770,7 @@ namespace TeamAAS_VP.Services
         /// <param name="positionIndex"></param>
         /// <param name="remark"></param>
         /// <returns></returns>
-        public async Task<(bool IsSucceed, double X, double Y, double U)> ExecutePhotoGetSinglePoint(ProcedureModel procedure, Dictionary<string, string> InputTerminal, double[] robotCoord, CancellationToken cancellationToken, int positionIndex, string remark)
+        public async Task<(bool IsSucceed, double X, double Y, double U)> ExecutePhotoGetSinglePoint(ProcedureModel procedure, Dictionary<string, string> InputTerminal, double[] robotCoord, CancellationToken cancellationToken, int positionIndex, string remark, ImageParameters imgPara)
         {
             DateTime nowtime = DateTime.Now;
             await SetLightBeforePhoto(procedure);
@@ -1780,7 +1782,7 @@ namespace TeamAAS_VP.Services
                     SendTaskMessage(Lang.开始执行视觉流程.Replace("{0}", $"{i + 1}").Replace("{1}", procedure.Name), MessageLevel.Info);
 
                     // 1. 执行相机拍照并运行视觉工具
-                    bool visionSucceed = ExecutePhoto(procedure, InputTerminal, out CogToolBlockTerminalCollection outputCollection);
+                    bool visionSucceed = ExecutePhoto(procedure, InputTerminal, out CogToolBlockTerminalCollection outputCollection, imgPara);
                     if (!visionSucceed)
                     {
                         SendTaskMessage(Lang.视觉任务执行失败, MessageLevel.Error);

+ 1 - 0
TeamAAS-VM/TeamAAS-VP.csproj

@@ -540,6 +540,7 @@
     <Compile Include="Models\DeviceInfo.cs" />
     <Compile Include="Models\Feeder\ScrewFeederInfo.cs" />
     <Compile Include="Models\HeadChangeRecord.cs" />
+    <Compile Include="Models\ImageParameters.cs" />
     <Compile Include="Models\NozzleChangeRecord.cs" />
     <Compile Include="Models\NumberStatistics.cs" />
     <Compile Include="Models\Torque\PickDynamicTestResult.cs" />

+ 61 - 22
TeamAAS-VM/Views/Home/ShowVisionRender.xaml.cs

@@ -82,26 +82,64 @@ namespace TeamAAS_VP.Views.Home
                 {
                     if (item.Value?.Child is CogRecordDisplay disp)
                     {
-                        // 通过 Tag(产品名) 匹配当前需要更新的窗口
-                        if (disp.Tag != null && disp.Tag.ToString() == render.ProceductName)
+                        ((Cognex.VisionPro.CogRecordDisplay)item.Value.Child).Record = null;
+                        ((Cognex.VisionPro.CogRecordDisplay)item.Value.Child).Image = render.Image;
+                        ((Cognex.VisionPro.CogRecordDisplay)item.Value.Child).StaticGraphics.Clear();
+                        if (render.Graphic!=null)
+                            ((Cognex.VisionPro.CogRecordDisplay)item.Value.Child).StaticGraphics.AddList(render.Graphic, "");
+
+                        if (render.Record != null)
+                            ((Cognex.VisionPro.CogRecordDisplay)item.Value.Child).Record = render.Record;
+                        if (render.IsSaveImage)
                         {
-                            disp.Record = null;
-                            disp.Image = render.Image;
-
-                            disp.StaticGraphics.Clear();
-                            if (render.Graphic != null)
-                                disp.StaticGraphics.AddList(render.Graphic, "");
-
+                            SaveImage(render.SaveImageModel, render.SaveImagePathModel, render.SavePath, render.Image, (Bitmap)((Cognex.VisionPro.CogRecordDisplay)item.Value.Child).CreateContentBitmap(Cognex.VisionPro.Display.CogDisplayContentBitmapConstants.Custom), render.Result, render.IsCompress, render.ImgPara);
+                        }
+                        break;
+                    }
+                }
+                /*
+                foreach (var item in gridRender.Children)
+                {
+                    if (item is WindowsFormsHost && ((WindowsFormsHost)item).Child is Cognex.VisionPro.CogRecordDisplay)
+                    {
+                        if (((Cognex.VisionPro.CogRecordDisplay)((WindowsFormsHost)item).Child).Tag != null && ((Cognex.VisionPro.CogRecordDisplay)((WindowsFormsHost)item).Child).Tag.ToString() == render.CameraName)
+                        {
+                            ((Cognex.VisionPro.CogRecordDisplay)((WindowsFormsHost)item).Child).Image = render.Image;
+                            ((Cognex.VisionPro.CogRecordDisplay)((WindowsFormsHost)item).Child).StaticGraphics.Clear();
+                            ((Cognex.VisionPro.CogRecordDisplay)((WindowsFormsHost)item).Child).StaticGraphics.AddList(render.Graphic, "");
                             if (render.Record != null)
-                                disp.Record = render.Record;
-
-                            // ======================= 【关键优化】保存图像走安全入口 =======================
-                            RequestSaveImage(render, disp);
-
+                                ((Cognex.VisionPro.CogRecordDisplay)((WindowsFormsHost)item).Child).Record = render.Record;
+                            if (render.IsSaveImage)
+                            {
+                                SaveImage(render.SaveImageModel, render.SaveImagePathModel, render.SavePath, render.Image, (Bitmap)((Cognex.VisionPro.CogRecordDisplay)((WindowsFormsHost)item).Child).CreateContentBitmap(Cognex.VisionPro.Display.CogDisplayContentBitmapConstants.Custom), render.Result, render.IsCompress);
+                            }
                             break;
                         }
                     }
-                }
+                    else if (item is Grid)
+                    {
+                        foreach (var item1 in ((Grid)item).Children)
+                        {
+                            if (item1 is WindowsFormsHost && ((WindowsFormsHost)item1).Child is Cognex.VisionPro.CogRecordDisplay)
+                            {
+                                if (((Cognex.VisionPro.CogRecordDisplay)((WindowsFormsHost)item1).Child).Tag != null && ((Cognex.VisionPro.CogRecordDisplay)((WindowsFormsHost)item1).Child).Tag.ToString() == render.CameraName)
+                                {
+                                    ((Cognex.VisionPro.CogRecordDisplay)((WindowsFormsHost)item1).Child).Image = render.Image;
+                                    ((Cognex.VisionPro.CogRecordDisplay)((WindowsFormsHost)item1).Child).StaticGraphics.Clear();
+                                    ((Cognex.VisionPro.CogRecordDisplay)((WindowsFormsHost)item1).Child).StaticGraphics.AddList(render.Graphic, "");
+                                    if (render.Record != null)
+                                        ((Cognex.VisionPro.CogRecordDisplay)((WindowsFormsHost)item).Child).Record = render.Record;
+                                    if (render.IsSaveImage)
+                                    {
+                                        SaveImage(render.SaveImageModel, render.SaveImagePathModel, render.SavePath, render.Image, (Bitmap)((Cognex.VisionPro.CogRecordDisplay)((WindowsFormsHost)item).Child).CreateContentBitmap(Cognex.VisionPro.Display.CogDisplayContentBitmapConstants.Custom), render.Result, render.IsCompress);
+                                    }
+                                    break;
+                                }
+                            }
+                        }
+                        break;
+                    }
+                }*/
             }));
         }
 
@@ -349,13 +387,14 @@ namespace TeamAAS_VP.Views.Home
         /// <summary>
         /// 保存图像(保持你原有逻辑不变,补充 Dispose 兜底,防止压缩分支不释放导致闪退)
         /// </summary>
-        private void SaveImage(ProcedureSaveImageModel saveImageModel,
-                               ProcedureSaveImagePathModel saveImagePathModel,
-                               string path,
-                               ICogImage image,
-                               Bitmap reimage,
-                               bool result,
-                               bool isCompress)
+        /// <param name="saveImageModel">要保存图像的模式</param>
+        /// <param name="saveImagePathModel">图像保存路径类型</param>
+        /// <param name="path">保存图像的文件夹路径</param>
+        /// <param name="image">原图像</param>
+        /// <param name="reimage">渲染图像</param>
+        /// <param name="result">拍照结果</param>
+        /// <param name="isCompress">是否压缩</param>
+        private void SaveImage(ProcedureSaveImageModel saveImageModel, ProcedureSaveImagePathModel saveImagePathModel, string path, ICogImage image, Bitmap reimage, bool result, bool isCompress, ImageParameters imgPara)
         {
             if (string.IsNullOrEmpty(path) || string.IsNullOrWhiteSpace(path) || !Path.IsPathRooted(path))
             {