Browse Source

Merge branch 'KB-Mylar' of http://49.235.130.76/XXF_1122/DaisyNPILine into KB-Mylar

yaoxiaohan 7 months ago
parent
commit
c199788ed6

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

@@ -1125,7 +1125,7 @@ namespace TeamAAS_VP.Core
         Int16 _LastPickINC = 0;
         Int16[] _LastMesCheck = new Int16[10];
         DateTime[] _LastMesCheckTime = new DateTime[10];
-
+        Dictionary<string, string> mes_cc = new Dictionary<string, string>();
         /// <summary>
         /// PLC命令触发时
         /// </summary>
@@ -1731,14 +1731,20 @@ namespace TeamAAS_VP.Core
 
                             // 执行视觉任务
                             var _cts = new CancellationTokenSource();
-                            var visionResult = await _remoteCommandService.ExecutePhotoGetSinglePoint(process, null, null, _cts.Token, cameraIndex, null);
+                            var visionResult = await _remoteCommandService.ExecutePhotoGetDistance(process, null, null, _cts.Token, cameraIndex, null);
                             if (visionResult.IsSucceed)
                             {
+                                if (visionResult.distance.Split(',')[0] == "1")
+                                {
+                                    mes_cc.Clear();
+                                }
+                                mes_cc.Add(visionResult.distance.Split(',')[0], visionResult.distance.Split(',')[1]);
                                 await plc.WriteNodeAsync(addressConfig.Out_UPCameracheckStatus.Address, (Int16)1);
                                 SendTaskMessage($"点位{cameraIndex}检测OK", MessageLevel.Debug);
                             }
                             else
                             {
+                                mes_cc.Add("0","0");
                                 await plc.WriteNodeAsync(addressConfig.Out_UPCameracheckStatus.Address, (Int16)2);
                                 SendTaskMessage($"点位{cameraIndex}检测NG", MessageLevel.Error);
                             }
@@ -2008,6 +2014,7 @@ namespace TeamAAS_VP.Core
                                     return;
                                 }
                                 var code = plc.ReadNode<string>(string.Format(addressConfig.In_Code.Address, i));
+                                string comp = "";
                                 if (state == 1)
                                 {
                                     //这里缺少从MES获取产品配方的内容,需要补充
@@ -2016,7 +2023,7 @@ namespace TeamAAS_VP.Core
 
                                     LogHelper.WriteLogMes($"【mes开始QUERY】");
                                     SendTaskMessage($"mes开始QUERY", MessageLevel.Info);
-                                    (bool isSuccess, string response) = await _mesService.StationGetAsync(code, "", 2);
+                                    (bool isSuccess, string response) = await _mesService.StationGetAsync(code, comp, 2);
                                     if (i == 0)
                                     {
                                         SendTaskMessage($"收到当前过站检查请求(当站是否生产)...", MessageLevel.Debug);
@@ -2117,7 +2124,10 @@ namespace TeamAAS_VP.Core
 
                                     LogHelper.WriteLogMes($"【mes开始ADD】");
                                     SendTaskMessage($"mes开始ADD", MessageLevel.Info);
-                                    (bool isSuccess, string response) = await _mesService.SubmitGetAsync(code, "", resultIndex == 1 ? true : false, _LastMesCheckTime[i], DateTime.UtcNow);
+                                    string assypress= "";string cc = "";
+                                    cc = string.Join(",", mes_cc.OrderBy(kv => kv.Key, StringComparer.Ordinal).Select(kv => kv.Value));
+                                    assypress = assemblyRecord.AssemblyPressure.ToString();
+                                    (bool isSuccess, string response) = await _mesService.SubmitGetAsync(code, comp, cc,assypress, resultIndex == 1 ? true : false, _LastMesCheckTime[i], DateTime.UtcNow);
                                     if (isSuccess)
                                     {
                                         LogHelper.WriteLogMes($"上传mes成功");

+ 2 - 2
TeamAAS-VM/Interfaces/IMesService.cs

@@ -63,7 +63,7 @@ namespace TeamAAS_VP.Interfaces
         /// - 若 <paramref name="start_time"/> 晚于 <paramref name="stop_time"/>,实现应记录并视情况返回失败或抛出异常。
         /// - 实现应尊重 <paramref name="cancellationToken"/>,并在取消时尽早中止请求。
         /// </remarks>
-        Task<(bool IsSuccess, string Response)> SubmitGetAsync(string sn, string comp, bool isSuccess, DateTime start_time, DateTime stop_time, CancellationToken cancellationToken = default);
+        Task<(bool IsSuccess, string Response)> SubmitGetAsync(string sn, string comp, string cc, string assypress, bool isSuccess, DateTime start_time, DateTime stop_time, CancellationToken cancellationToken = default);
 
         /// <summary>
         /// 使用配置的提交(Submit)URL 发起 GET 请求,提交过站结果及时间信息,并使用指定的超时时间(秒)。
@@ -82,6 +82,6 @@ namespace TeamAAS_VP.Interfaces
         /// - 此重载用于在不传入 <see cref="CancellationToken"/> 的场景中指定超时时间。
         /// - 实现应确保对时间参数与布尔参数进行适当的 URL 编码或格式化。
         /// </remarks>
-        Task<(bool IsSuccess, string Response)> SubmitGetAsync(string sn, string comp, bool isSuccess, DateTime start_time, DateTime stop_time, double timeoutInSeconds);
+        Task<(bool IsSuccess, string Response)> SubmitGetAsync(string sn, string comp, string cc, string assypress, bool isSuccess, DateTime start_time, DateTime stop_time, double timeoutInSeconds);
     }
 }

+ 7 - 1
TeamAAS-VM/Interfaces/IRemoteCommandService.cs

@@ -202,7 +202,7 @@ namespace TeamAAS_VP.Interfaces
         /// </summary>
         /// <param name="cancellationToken"></param>
         /// <returns></returns>
-        Task<bool> IsRobotInDebugModeAsync(int robotNumber,CancellationToken cancellationToken);
+        Task<bool> IsRobotInDebugModeAsync(int robotNumber, CancellationToken cancellationToken);
 
         /// <summary>
         /// 执行视觉任务
@@ -344,5 +344,11 @@ namespace TeamAAS_VP.Interfaces
         /// <param name="procedure">流程模型</param>
         /// <returns></returns>
         Task TurnOffLightAfterPhoto(ProcedureModel procedure);
+
+        /// <summary>
+        /// 获取复检结果
+        /// </summary>
+        Task<(bool IsSucceed, string distance)> ExecutePhotoGetDistance(ProcedureModel procedure, Dictionary<string, string> InputTerminal, double[] robotCoord, CancellationToken cancellationToken, int positionIndex, string remark);
+
     }
 }

+ 7 - 7
TeamAAS-VM/Services/MesService.cs

@@ -99,11 +99,11 @@ namespace TeamAAS_VP.Services
             string url = "";
             if (device.F == "PTL")
             {
-                url = $"{device.MesUrl}?c=QUERY_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&comp={device.comp}:{comp}&p=unit_process_check,model";
+                url = $"{device.MesUrl}?c=QUERY_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&comp={device.comp}:{comp}&p=unit_process_check,message,model";
             }
             else
             {
-                url = $"{device.MesUrl}?c=QUERY_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&p=unit_process_check,model";
+                url = $"{device.MesUrl}?c=QUERY_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&p=unit_process_check,message,model";
             }
 
             LogHelper.WriteLogMes($"【询问URL】{url}");
@@ -179,7 +179,7 @@ namespace TeamAAS_VP.Services
         /// - 捕获 <see cref="OperationCanceledException"/> 返回 "Canceled",捕获其它异常则返回异常消息。
         /// - 若实例已被释放则抛出 <see cref="ObjectDisposedException"/>。
         /// </remarks>
-        public async Task<(bool IsSuccess, string Response)> SubmitGetAsync(string sn, string comp, bool isSuccess, DateTime start_time, DateTime stop_time, CancellationToken cancellationToken = default)
+        public async Task<(bool IsSuccess, string Response)> SubmitGetAsync(string sn, string comp, string cc,string assypress,bool isSuccess, DateTime start_time, DateTime stop_time, CancellationToken cancellationToken = default)
         {
             // 如果已经释放,则抛出异常,防止在已释放资源上继续操作。
             if (_disposed) throw new ObjectDisposedException(nameof(MesService));
@@ -204,12 +204,12 @@ namespace TeamAAS_VP.Services
             if (device.F == "PTL")
             {
                 url = $"{device.MesUrl}?c=ADD_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&f=PTL&comp={device.comp}:{comp}" +
-                    $"&result={res}&start_time={start_time.ToString("yyyy-MM-dd HH:mm:ss")}&stop_time={stop_time.ToString("yyyy-MM-dd HH:mm:ss")}";
+                    $"&cc={cc}&assy_pressure={assypress}&result={res}&start_time={start_time.ToString("yyyy-MM-dd HH:mm:ss")}&stop_time={stop_time.ToString("yyyy-MM-dd HH:mm:ss")}";
             }
             else
             {
                 url = $"{device.MesUrl}?c=ADD_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&f=PQC" +
-                    $"&result={res}&start_time={start_time.ToString("yyyy-MM-dd HH:mm:ss")}&stop_time={stop_time.ToString("yyyy-MM-dd HH:mm:ss")}";
+                    $"&cc={cc}&assy_pressure={assypress}&result={res}&start_time={start_time.ToString("yyyy-MM-dd HH:mm:ss")}&stop_time={stop_time.ToString("yyyy-MM-dd HH:mm:ss")}";
             }
             LogHelper.WriteLogMes($"【上传URL】{url}");
             SendTaskMessage($"【上传URL】{url}", MessageLevel.Info);
@@ -258,11 +258,11 @@ namespace TeamAAS_VP.Services
         /// <param name="stop_time">结束时间。</param>
         /// <param name="timeoutInSeconds">请求超时,单位为秒。</param>
         /// <returns>与 <see cref="SubmitGetAsync(string, bool, DateTime, DateTime, CancellationToken)"/> 相同的返回语义。</returns>
-        public async Task<(bool IsSuccess, string Response)> SubmitGetAsync(string sn, string comp, bool isSuccess, DateTime start_time, DateTime stop_time, double timeoutInSeconds)
+        public async Task<(bool IsSuccess, string Response)> SubmitGetAsync(string sn, string comp, string cc, string assypress, bool isSuccess, DateTime start_time, DateTime stop_time, double timeoutInSeconds)
         {
             using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(timeoutInSeconds)))
             {
-                return await SubmitGetAsync(sn, comp, isSuccess, start_time, stop_time, cts.Token);
+                return await SubmitGetAsync(sn, comp, cc, assypress, isSuccess, start_time, stop_time, cts.Token);
             }
         }
 

+ 63 - 0
TeamAAS-VM/Services/RemoteCommandService.cs

@@ -1758,6 +1758,69 @@ namespace TeamAAS_VP.Services
 
             }
         }
+        /// <summary>
+        /// 获取复检结果
+        /// </summary>
+        /// <param name="procedure"></param>
+        /// <param name="InputTerminal"></param>
+        /// <param name="robotCoord"></param>
+        /// <param name="cancellationToken"></param>
+        /// <param name="positionIndex"></param>
+        /// <param name="remark"></param>
+        /// <returns></returns>
+        public async Task<(bool IsSucceed, string distance)> ExecutePhotoGetDistance(ProcedureModel procedure, Dictionary<string, string> InputTerminal, double[] robotCoord, CancellationToken cancellationToken, int positionIndex, string remark)
+        {
+            DateTime nowtime = DateTime.Now;
+            await SetLightBeforePhoto(procedure);
+            try
+            {
+                //拍照失败时,需要多次拍照
+                for (int i = 0; i < procedure.FeederFailLimit; i++)
+                {
+                    SendTaskMessage(Lang.开始执行视觉流程.Replace("{0}", $"{i + 1}").Replace("{1}", procedure.Name), MessageLevel.Info);
+
+                    // 1. 执行相机拍照并运行视觉工具
+                    bool visionSucceed = ExecutePhoto(procedure, InputTerminal, out CogToolBlockTerminalCollection outputCollection);
+                    if (!visionSucceed)
+                    {
+                        SendTaskMessage(Lang.视觉任务执行失败, MessageLevel.Error);
+                        continue;
+                    }
+
+                    if (!outputCollection.Contains("Found"))
+                    {
+                        SendTaskMessage(Lang.未找到视觉输出结果, MessageLevel.Error);
+                        return (false, "");
+                    }
+
+                    // 2. 获取视觉输出结果
+                    bool Found = (bool)(outputCollection["Found"].Value);
+                    if (!Found)
+                    {
+                        SendTaskMessage(Lang.拍照NG, MessageLevel.Debug);
+                        continue;
+                    }
+
+                    SendTaskMessage(Lang.拍照OK, MessageLevel.Debug);
+
+                    LogHelper.WriteLogInfo("开始获取视觉输出结果");
+                    string dis = (string)(outputCollection["CC"].Value);
+                    return (true, dis);
+                }
+                SendTaskMessage(Lang.多次拍照失败, MessageLevel.Alarm);
+                return (false, "");
+            }
+            catch (Exception ex)
+            {
+                LogHelper.WriteLogError("执行相机取图并获取单点位时出错!", ex);
+                return (false, "");
+            }
+            finally
+            {
+                await TurnOffLightAfterPhoto(procedure);
+
+            }
+        }
 
         /// <summary>
         /// 记录拍照结果数据至数据库