Explorar el Código

支持PLC多站点MES交互及过站检查扩展

本次提交将PLC相关地址配置改为支持多站点(0~9),包括In_MesCheck、Out_MesStatus、In_Code等,地址格式由固定索引改为可格式化字符串。过站检查逻辑扩展为循环处理所有站点的信号,并分别写入对应站点的MES状态。产品编码读取方式也调整为按站点读取。整体提升了系统对多站点MES交互和数据处理的支持能力。
孝锋 徐 hace 8 meses
padre
commit
efcb7b21e1
Se han modificado 2 ficheros con 49 adiciones y 33 borrados
  1. 46 30
      TeamAAS-VM/Core/Management.cs
  2. 3 3
      TeamAAS-VM/Models/PLC/PlcAddressConfig.cs

+ 46 - 30
TeamAAS-VM/Core/Management.cs

@@ -962,11 +962,14 @@ namespace TeamAAS_VP.Core
                 addressConfig.In_FixedCameracheckExe.Address,
                 addressConfig.In_WorkStart.Address,
                 addressConfig.In_WorkDone.Address,
-                addressConfig.In_MesCheck.Address,
                 addressConfig.In_RequestPosition.Address,
                 addressConfig.In_ScrewTeachExe.Address,
                 addressConfig.In_PickINC.Address,
             };
+            for (int i = 0; i < 10; i++)
+            {
+                monitorNodeIds.Add(string.Format(addressConfig.In_MesCheck.Address, i));
+            }
 
             //订阅PLC地址变化
             plc.SubscribeNodes("AutoSensor", monitorNodeIds, PlcCommandTrigger);
@@ -1069,13 +1072,14 @@ namespace TeamAAS_VP.Core
                 }
 
                 //获取产品编码
-                _productService.CurrentProductCode = plc.ReadNode<string>(addressConfig.In_Code.Address);
+                _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);
 
                 // 触发下相机拍照
@@ -1784,33 +1788,6 @@ namespace TeamAAS_VP.Core
                         }
                     }
                 }
-                // 过站检查
-                else if (addressConfig.In_MesCheck.Address.Contains(tuple.nodeId))
-                {
-                    if (tuple.value is Int16 state)
-                    {
-                        if (state == 1)
-                        {
-                            SendTaskMessage($"收到过站检查请求(当站是否生产)...", MessageLevel.Debug);
-
-                            //产品发生改变并且供料器发生了变化时,需要通知PLC进行取料更改
-                            await plc.WriteNodeAsync(addressConfig.Out_ScrewFeederIsChanged.Address, (Int16)1); //不发生改变
-
-                            await plc.WriteNodeAsync(addressConfig.Out_MesStatus.Address, (Int16)1);
-                        }
-                        // 上传本站数据
-                        else if (state == 2)
-                        {
-                            SendTaskMessage($"收到上传本站数据请求...", MessageLevel.Debug);
-                            await plc.WriteNodeAsync(addressConfig.Out_MesStatus.Address, (Int16)3);
-                        }
-                        else
-                        {
-                            SendTaskMessage($"过站检查信号:state={state},处理为默认状态", MessageLevel.Alarm);
-                            await plc.WriteNodeAsync(addressConfig.Out_MesStatus.Address, (Int16)0);
-                        }
-                    }
-                }
                 // 螺丝供料器螺丝递减
                 else if (addressConfig.In_PickINC.Address.Contains(tuple.nodeId))
                 {
@@ -1824,7 +1801,46 @@ namespace TeamAAS_VP.Core
 
                     }
                 }
-            }
+                // 过站检查
+                else
+                {
+                    for (int i = 0; i < 10; i++)
+                    {
+                        if (string.Format(addressConfig.In_MesCheck.Address, i).Contains(tuple.nodeId))
+                        {
+                            if (tuple.value is Int16 state)
+                            {
+                                if (state == 1)
+                                {
+                                    if (i == 0)
+                                    {
+                                        SendTaskMessage($"收到当前站过站检查请求(当站是否生产)...", MessageLevel.Debug);
+                                    }
+                                    else
+                                    {
+                                        SendTaskMessage($"收到 {i} 过站检查请求(当站是否生产)...", MessageLevel.Debug);
+                                    }
+
+                                    //产品发生改变并且供料器发生了变化时,需要通知PLC进行取料更改
+                                    await plc.WriteNodeAsync(addressConfig.Out_ScrewFeederIsChanged.Address, (Int16)1); //不发生改变
+
+                                    await plc.WriteNodeAsync(string.Format(addressConfig.Out_MesStatus.Address, i), (Int16)1);
+                                }
+                                // 上传本站数据
+                                else if (state == 2)
+                                {
+                                    SendTaskMessage($"收到上传{i}站数据请求...", MessageLevel.Debug);
+                                    await plc.WriteNodeAsync(string.Format(addressConfig.Out_MesStatus.Address, i), (Int16)3);
+                                }
+                                else
+                                {
+                                    SendTaskMessage($"{i}过站检查信号:state={state},处理为默认状态", MessageLevel.Alarm);
+                                    await plc.WriteNodeAsync(string.Format(addressConfig.Out_MesStatus.Address, i), (Int16)0);
+                                }
+                            }
+                        }
+                    }
+                }
             catch (Exception ex)
             {
                 SendTaskMessage(ex.Message, MessageLevel.Error);

+ 3 - 3
TeamAAS-VM/Models/PLC/PlcAddressConfig.cs

@@ -661,7 +661,7 @@ namespace TeamAAS_VP.Models.PLC
             Out_CameraDone.Description = "相机坐标拟合完成";
 
             Out_MesStatus = Ensure(Out_MesStatus);
-            Out_MesStatus.Address = "ns=4;s=DB_Communication|FromPC.MesStatus[0]";
+            Out_MesStatus.Address = "ns=4;s=DB_Communication|FromPC.MesStatus[{0}]";
             Out_MesStatus.DataType = "int16";
             Out_MesStatus.Description = "过站信息 =1 允许工作 =2 本站放行 =3 数据上传完成";
 
@@ -800,12 +800,12 @@ namespace TeamAAS_VP.Models.PLC
 
             // 4. In_* 默认(假定从 PLC 读到 PC,使用 ToPC 前缀)
             In_Code = Ensure(In_Code);
-            In_Code.Address = "ns=4;s=DB_Communication|ToPC.Mes[0].Code";
+            In_Code.Address = "ns=4;s=DB_Communication|ToPC.Mes[{0}].Code";
             In_Code.DataType = "string";
             In_Code.Description = "产品编码";
 
             In_MesCheck = Ensure(In_MesCheck);
-            In_MesCheck.Address = "ns=4;s=DB_Communication|ToPC.Mes[0].Check";
+            In_MesCheck.Address = "ns=4;s=DB_Communication|ToPC.Mes[{0}].Check";
             In_MesCheck.DataType = "int16";
             In_MesCheck.Description = "Mes交互 =1 获取过站信息当站是否生产,=2 上传本站数据";