Przeglądaj źródła

增强PLC点位写入与监控,支持MES过站检查

新增WritePositionToPlcAsync方法,实现产品点位信息写入PLC。完善RegisterPlcMonitorAddress,支持In_MesCheck监控。PlcCommandTrigger改为异步,增加MES过站检查处理。产品加载、切换、参数更新时自动同步点位至PLC。优化注释与结构,提升系统稳定性与自动化水平。
孝锋 徐 8 miesięcy temu
rodzic
commit
150fe5d884

+ 109 - 16
TeamAAS-VM/Core/Management.cs

@@ -291,6 +291,7 @@ namespace TeamAAS_VP.Core
                 }
             }
             await WriteSystemParameterToPlcAsync(_configService.GetSystemConfiguration());
+            RegisterPlcMonitorAddress();
             if (sb.Length == 0)
             {
                 return (true, "");
@@ -857,7 +858,9 @@ namespace TeamAAS_VP.Core
             var res = await plc.WriteNodesAsync(nodeValues);
         }
 
-        //注册需要监控的PLC地址
+        /// <summary>
+        /// 注册需要监控的PLC地址
+        /// </summary>
         public void RegisterPlcMonitorAddress()
         {
             var addressConfig = _configService.GetPlcAddresses();
@@ -876,19 +879,79 @@ namespace TeamAAS_VP.Core
                 addressConfig.In_FixedCameracheckExe.Address,
                 addressConfig.In_WorkStart.Address,
                 addressConfig.In_WorkDone.Address,
+                addressConfig.In_MesCheck.Address,
+                addressConfig.In_RequestPosition.Address,
             };
 
             //订阅PLC地址变化
             plc.SubscribeNodes("AutoSensor", monitorNodeIds, PlcCommandTrigger);
         }
 
+        /// <summary>
+        /// 写入点位信息给PLC
+        /// </summary>
+        /// <returns></returns>
+        public async Task WritePositionToPlcAsync()
+        {
+            var addressConfig = _configService.GetPlcAddresses();
+            var plc = _plcService.GetPlcByNumber(addressConfig.PlcNo) as OpcUaClientPLC;
+            if (plc == null || !plc.IsConnected) return;
+            var current= _productService.GetCurrentProduct();
+            if (current == null) return;
+            if (current.PickCameraPoints!=null && current.PickCameraPoints.Count>0)
+            {
+                foreach (var item in current.PickCameraPoints)
+                {
+                    await item.WriteToPlcAddress(addressConfig.Out_PickCamera,plc);
+                }
+            }
+            if (current.PickPoints != null && current.PickPoints.Count > 0)
+            {
+                foreach (var item in current.PickPoints)
+                {
+                    await item.WriteToPlcAddress(addressConfig.Out_Pick, plc);
+                }
+            }
+            if (current.SecPosCameraPoints != null && current.SecPosCameraPoints.Count > 0)
+            {
+                foreach (var item in current.SecPosCameraPoints)
+                {
+                    await item.WriteToPlcAddress(addressConfig.Out_SecPosCamera, plc);
+                }
+            }
+            if (current.ScrewCameraPoints != null && current.ScrewCameraPoints.Count > 0)
+            {
+                foreach (var item in current.ScrewCameraPoints)
+                {
+                    await item.WriteToPlcAddress(addressConfig.Out_ScrewCamera, plc);
+                }
+            }
+            if (current.ScrewPoints != null && current.ScrewPoints.Count > 0)
+            {
+                foreach (var item in current.ScrewPoints)
+                {
+                    await item.WriteToPlcAddress(addressConfig.Out_Screw, plc);
+                }
+                await plc.WriteNodeAsync(addressConfig.Out_WorkNum.Address, (Int16)current.ScrewPoints.Count);
+            }
+            if (current.CheckCameraPoints != null && current.CheckCameraPoints.Count > 0)
+            {
+                foreach (var item in current.CheckCameraPoints)
+                {
+                    await item.WriteToPlcAddress(addressConfig.Out_CheckCamera, plc);
+                }
+            }
+        }
+
         /// <summary>
         /// PLC命令触发时
         /// </summary>
         /// <param name="tuple"></param>
-        private void PlcCommandTrigger((string key, string nodeId, object value) tuple)
+        private async void PlcCommandTrigger((string key, string nodeId, object value) tuple)
         {
             var addressConfig = _configService.GetPlcAddresses();
+            var plc = _plcService.GetPlcByNumber(addressConfig.PlcNo) as OpcUaClientPLC;
+            if (plc == null || !plc.IsConnected) return;
             // 触发下相机拍照
             if (tuple.nodeId.Contains(addressConfig.In_DowmCameraExe.Address))
             {
@@ -896,11 +959,11 @@ namespace TeamAAS_VP.Core
                 {
                     if (state)
                     {
-
+                        await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)1);
                     }
                     else
                     {
-
+                        await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)0);
                     }
                 }
             }
@@ -911,11 +974,11 @@ namespace TeamAAS_VP.Core
                 {
                     if (state)
                     {
-
+                        await plc.WriteNodeAsync(addressConfig.Out_UpCameraPickStatus.Address, (Int16)1);
                     }
                     else
                     {
-
+                        await plc.WriteNodeAsync(addressConfig.Out_UpCameraPickStatus.Address, (Int16)0);
                     }
                 }
             }
@@ -926,11 +989,11 @@ namespace TeamAAS_VP.Core
                 {
                     if (state)
                     {
-
+                        await plc.WriteNodeAsync(addressConfig.Out_UpCameraPutStatus.Address, (Int16)1);
                     }
                     else
                     {
-
+                        await plc.WriteNodeAsync(addressConfig.Out_UpCameraPutStatus.Address, (Int16)0);
                     }
                 }
             }
@@ -941,11 +1004,11 @@ namespace TeamAAS_VP.Core
                 {
                     if (state)
                     {
-
+                        await plc.WriteNodeAsync(addressConfig.Out_UPCameracheckStatus.Address, (Int16)1);
                     }
                     else
                     {
-
+                        await plc.WriteNodeAsync(addressConfig.Out_UPCameracheckStatus.Address, (Int16)0);
                     }
                 }
             }
@@ -956,11 +1019,11 @@ namespace TeamAAS_VP.Core
                 {
                     if (state)
                     {
-
+                        await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)1);
                     }
                     else
                     {
-
+                        await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)0);
                     }
                 }
             }
@@ -971,11 +1034,11 @@ namespace TeamAAS_VP.Core
                 {
                     if (state)
                     {
-
+                        await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPutStatus.Address, (Int16)1);
                     }
                     else
                     {
-
+                        await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPutStatus.Address, (Int16)0);
                     }
                 }
             }
@@ -986,11 +1049,11 @@ namespace TeamAAS_VP.Core
                 {
                     if (state)
                     {
-
+                        await plc.WriteNodeAsync(addressConfig.Out_FixedCameracheckStatus.Address, (Int16)1);
                     }
                     else
                     {
-
+                        await plc.WriteNodeAsync(addressConfig.Out_FixedCameracheckStatus.Address, (Int16)0);
                     }
                 }
             }
@@ -1024,6 +1087,36 @@ namespace TeamAAS_VP.Core
                     }
                 }
             }
+            // 多相机坐标合并
+            else if (tuple.nodeId.Contains(addressConfig.In_RequestPosition.Address))
+            {
+                if (tuple.value is Int16 state)
+                {
+                    if (state == 1)
+                    {
+                        await plc.WriteNodeAsync(addressConfig.Out_CameraDone.Address, (Int16)1);
+                    }
+                    else
+                    {
+                        await plc.WriteNodeAsync(addressConfig.Out_CameraDone.Address, (Int16)0);
+                    }
+                }
+            }
+            // 过站检查
+            else if (tuple.nodeId.Contains(addressConfig.In_MesCheck.Address))
+            {
+                if (tuple.value is Int16 state)
+                {
+                    if (state==1)
+                    {
+                        await plc.WriteNodeAsync(addressConfig.Out_MesStatus.Address, (Int16)1);
+                    }
+                    else
+                    {
+                        await plc.WriteNodeAsync(addressConfig.Out_MesStatus.Address, (Int16)0);
+                    }
+                }
+            }
         }
 
         #endregion

+ 1 - 0
TeamAAS-VM/ViewModels/HomeViewModel.cs

@@ -208,6 +208,7 @@ namespace TeamAAS_VP.ViewModels
                     var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
                     await _productService.LoadProductAsync(product.ID);
                     _productService.SetCurrentProduct(product.ID);
+                    await management.WritePositionToPlcAsync();
                     if (DialogHost.IsDialogOpen("RootDialog"))
                     {
                         DialogHost.Close("RootDialog");

+ 1 - 0
TeamAAS-VM/ViewModels/MainWindowViewModel.cs

@@ -375,6 +375,7 @@ namespace TeamAAS_VP.ViewModels
             {
                 await _productService.LoadProductAsync(productid);
                 _productService.SetCurrentProduct(productid);
+                await management.WritePositionToPlcAsync();
             }
             var homeviewmodel = _container.Resolve<HomeViewModel>();
             homeviewmodel.OnNavigatedTo(null);

+ 5 - 0
TeamAAS-VM/ViewModels/Product/ProductParamsViewModel.cs

@@ -111,6 +111,11 @@ namespace TeamAAS_VP.ViewModels.Product
                 //show the dialog
                 var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
                 await _productService.UpdateProductAsync(SelectProduct);
+                var current = _productService.GetCurrentProduct();
+                if (current!=null && current.IsLoad)
+                {
+                    await management.WritePositionToPlcAsync();
+                }
                 if (DialogHost.IsDialogOpen("RootDialog"))
                 {
                     DialogHost.Close("RootDialog");