wanghan il y a 7 mois
Parent
commit
a5fbdcf8ed

+ 12 - 4
TeamAAS-VM/Core/Management.cs

@@ -1341,7 +1341,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)
                             {
                                 //披头偏差
@@ -1408,7 +1410,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)
                             {
                                 //披头偏差
@@ -1515,7 +1519,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)
                             {
                                 //是拍一个锁一个还是拍两个点锁所有
@@ -1584,7 +1590,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)
                             {
                                 await plc.WriteNodeAsync(addressConfig.Out_UPCameracheckStatus.Address, (Int16)1);

+ 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; }
+		}
+
+	}
+}

+ 10 - 0
TeamAAS-VM/Models/ShowRender.cs

@@ -117,5 +117,15 @@ namespace TeamAAS_VP.Models
             get { return _IsCompress; }
             set { SetProperty(ref _IsCompress, value); }
         }
+
+        private ImageParameters _ImgPara;
+        /// <summary>
+        /// 图片保存附加参数
+        /// </summary>
+        public ImageParameters ImgPara
+        {
+            get { return _ImgPara; }
+            set { SetProperty(ref _ImgPara, value); }
+        }
     }
 }

+ 14 - 11
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
             {
@@ -1529,6 +1531,7 @@ namespace TeamAAS_VP.Services
                         SaveImagePathModel = procedure.SaveImagePathModel,
                         SavePath = procedure.SavePath,
                         IsCompress = procedure.IsCompress,
+                        ImgPara = imgPara,
                     });
                     SendTaskMessage($"{procedure.CameraName},{procedure.CameraId}", MessageLevel.Info);
                     return true;
@@ -1768,7 +1771,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 +1783,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" />

+ 2 - 2
TeamAAS-VM/Views/Home/ShowVisionRender.xaml.cs

@@ -83,7 +83,7 @@ namespace TeamAAS_VP.Views.Home
                             ((Cognex.VisionPro.CogRecordDisplay)item.Value.Child).Record = render.Record;
                         if (render.IsSaveImage)
                         {
-                            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);
+                            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;
                     }
@@ -843,7 +843,7 @@ namespace TeamAAS_VP.Views.Home
         /// <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)
+        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))