Browse Source

添加零件码传给PLC及,从PLC获取零件码功能

徐孝锋 6 months ago
parent
commit
7bd5566422

+ 27 - 7
TeamAAS-VM/Core/Management.cs

@@ -1,5 +1,6 @@
 using Cognex.VisionPro.ToolBlock;
 using MathNet.Numerics.LinearAlgebra;
+using NPOI.SS.Formula.Functions;
 using OpenCvSharp;
 using Prism.Events;
 using Prism.Ioc;
@@ -1188,13 +1189,13 @@ namespace TeamAAS_VP.Core
                     return;
                 }
 
-                ////获取产品编码
-                //_productService.CurrentProductCode = plc.ReadNode<string>(string.Format(addressConfig.In_Code.Address, 0));
-                ////如果产品编码为空,则以当前的时间戳作为编码
-                //if (string.IsNullOrEmpty(_productService.CurrentProductCode))
-                //{
-                //    _productService.CurrentProductCode = DateTime.Now.ToString("yyyyMMddHHmmssfff");
-                //}
+                //获取产品编码
+                _productService.CurrentProductCode = plc.ReadNode<string>(string.Format(addressConfig.In_Code.Address, 0));
+                //如果产品编码为空,则以当前的时间戳作为编码
+                if (string.IsNullOrEmpty(_productService.CurrentProductCode))
+                {
+                    _productService.CurrentProductCode = DateTime.Now.ToString("yyyyMMddHHmmssfff");
+                }
 
 
                 bool isDryMode = plc.ReadNode<bool>(addressConfig.In_DryMode.Address);
@@ -2185,6 +2186,11 @@ namespace TeamAAS_VP.Core
                             if (visionResults[0].IsSucceed && visionResults[1].IsSucceed && visionResults[2].IsSucceed && visionResults[3].IsSucceed)
                             {
                                 SendTaskMessage($"固定相机检测OK", MessageLevel.Debug);
+                                SendTaskMessage($"流程1结果:{visionResults[0].distance}", MessageLevel.Debug);
+                                SendTaskMessage($"流程2结果:{visionResults[1].distance}", MessageLevel.Debug);
+                                SendTaskMessage($"流程3结果:{visionResults[2].distance}", MessageLevel.Debug);
+                                SendTaskMessage($"流程4结果:{visionResults[3].distance}", MessageLevel.Debug);
+
                                 gapString = $"1-{visionResults[0].distance.Split(',')[1]},2-{visionResults[1].distance.Split(',')[1]},3-{visionResults[2].distance.Split(',')[1]},4-{visionResults[3].distance.Split(',')[1]}";
                                 await plc.WriteNodeAsync(addressConfig.Out_FixedCameracheckStatus.Address, (Int16)1);
                                 return;
@@ -2374,6 +2380,7 @@ namespace TeamAAS_VP.Core
                                 PartSN = outputCollection["QR"].Value as string;
                                 if (!string.IsNullOrEmpty(PartSN))
                                 {
+                                    await plc.WriteNodeAsync(addressConfig.Out_PartCode.Address, PartSN);
                                     SendTaskMessage($"二维码扫码成功:{PartSN}", MessageLevel.Info);
                                     await plc.WriteNodeAsync(addressConfig.Out_QrCodePhotoResault.Address, (Int16)1);
                                 }
@@ -2541,6 +2548,14 @@ namespace TeamAAS_VP.Core
                                                     SendTaskMessage($"工单信息:{wo[i]}", MessageLevel.Info);
                                                 }
                                             }
+                                            else
+                                            {
+                                                ProductMainSN[i] = DateTime.Now.ToString();
+                                                if (i == 0)
+                                                {
+                                                    _productService.CurrentProductCode = ProductMainSN[i];
+                                                }
+                                            }
 
                                             LogHelper.WriteLogMes($"询问mes成功");
                                             SendTaskMessage($"询问mes成功:{response}", MessageLevel.Debug);
@@ -2577,6 +2592,10 @@ namespace TeamAAS_VP.Core
                                         CTtime = ct;
                                     }
 
+                                    //从PLC获取零件编号
+                                    PartSN = plc.ReadNode<string>(addressConfig.In_PartCode.Address);
+                                    comp = PartSN;
+
                                     //读取产品结果
                                     Int16 resultIndex = plc.ReadNode<Int16>(string.Format(addressConfig.In_Result.Address, i));
                                     resultIndex = 1;
@@ -2949,6 +2968,7 @@ namespace TeamAAS_VP.Core
             catch (Exception ex)
             {
                 SendTaskMessage(ex.Message, MessageLevel.Error);
+                LogHelper.WriteLogError("PLC命令执行时出错!", ex);
             }
         }
 

+ 29 - 0
TeamAAS-VM/Models/PLC/PlcAddressConfig.cs

@@ -347,6 +347,16 @@ namespace TeamAAS_VP.Models.PLC
             get { return _Out_ScrewFeederIsChanged; }
             set { SetProperty(ref _Out_ScrewFeederIsChanged, value); }
         }
+
+        private PlcAddress _Out_PartCode;
+        /// <summary>
+        /// 零件的扫码编号写入到PLC
+        /// </summary>
+        public PlcAddress Out_PartCode
+        {
+            get { return _Out_PartCode; }
+            set { SetProperty(ref _Out_PartCode, value); }
+        }
         #endregion
 
         #region 从PLC读取的地址
@@ -681,6 +691,15 @@ namespace TeamAAS_VP.Models.PLC
             set { SetProperty(ref _Down_WetOut_Num_max, value); }
         }
 
+        private PlcAddress _In_PartCode;
+        /// <summary>
+        /// 从PLC中读取当前产品上传对应的零件号
+        /// </summary>
+        public PlcAddress In_PartCode
+        {
+            get { return _In_PartCode; }
+            set { SetProperty(ref _In_PartCode, value); }
+        }
         #endregion
 
         public PlcAddressConfig()
@@ -1188,6 +1207,16 @@ namespace TeamAAS_VP.Models.PLC
             Down_WetOut_Num_max.DataType = "float";
             Down_WetOut_Num_max.Description = "后保压压力最大值";
 
+            Out_PartCode = Ensure(Out_PartCode);
+            Out_PartCode.Address = "ns=4;s=DB_Communication|FromPC_code[0]";
+            Out_PartCode.DataType = "string";
+            Out_PartCode.Description = "零件的扫码编号写入到PLC";
+
+            In_PartCode = Ensure(In_PartCode);
+            In_PartCode.Address = "ns=4;s=DB_Communication|ToPC_code[0]";
+            In_PartCode.DataType = "string";
+            In_PartCode.Description = "从PLC中读取当前产品上传对应的零件号";
+
             // 说明:若项目中 PlcAddress 的实际属性名或类型与此不同(例如使用枚举、不同字段名),
             // 请根据实际类型调整赋值。本方法主要提供合理的默认字符串地址、数据类型及描述,便于后续从配置覆盖。
         }

+ 4 - 0
TeamAAS-VM/ViewModels/SettingViewModel.cs

@@ -483,6 +483,10 @@ namespace TeamAAS_VP.ViewModels
         private DelegateCommand _SaveDeviceInfoCommand;
         public DelegateCommand SaveDeviceInfoCommand => _SaveDeviceInfoCommand ?? (_SaveDeviceInfoCommand = new DelegateCommand(ExecuteSaveDeviceInfoCommand));
 
+        private DelegateCommand _SelectSaveImagePathCommand;
+        public DelegateCommand SelectSaveImagePathCommand =>
+            _SelectSaveImagePathCommand ?? (_SelectSaveImagePathCommand = new DelegateCommand(ExecuteSelectSaveImagePathCommand));
+
         private DelegateCommand<object> _LightModelChangedCommand;
         public DelegateCommand<object> LightModelChangedCommand =>
             _LightModelChangedCommand ?? (_LightModelChangedCommand = new DelegateCommand<object>(ExecuteLightModelChangedCommand));