徐孝锋 8 luni în urmă
părinte
comite
1138d498a8
2 a modificat fișierele cu 27 adăugiri și 18 ștergeri
  1. 23 14
      TeamAAS-VM/Core/Management.cs
  2. 4 4
      TeamAAS-VM/Core/PLCs/OPCuaClientPLC.cs

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

@@ -1,4 +1,5 @@
-using Cognex.VisionPro;
+using Basler.Pylon;
+using Cognex.VisionPro;
 using Cognex.VisionPro.ToolBlock;
 using CSScripting;
 using MathNet.Numerics.Distributions;
@@ -1008,14 +1009,14 @@ namespace TeamAAS_VP.Core
                     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.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)
@@ -1046,6 +1047,10 @@ namespace TeamAAS_VP.Core
                 if (plc == null || !plc.IsConnected) return;
                 // 获取当前产品
                 var currentProduct = _productService.GetCurrentProduct();
+                if (currentProduct==null)
+                {
+                    return;
+                }
 
                 // 触发下相机拍照
                 if (addressConfig.In_DowmCameraExe.Address.Contains(tuple.nodeId))
@@ -1057,6 +1062,7 @@ namespace TeamAAS_VP.Core
                             SendTaskMessage($"触发下相机拍照...", MessageLevel.Debug);
                             //相机的编号
                             Int16 cameraIndex = plc.ReadNode<Int16>(addressConfig.In_DowmCameraNum.Address);
+                            SendTaskMessage($"编号:{cameraIndex}", MessageLevel.Info);
 
                             // 获取流程
                             var process = _productService.GetCurrentProductProcedureModelById(currentProduct.FixedUpCamera1ProcedureId);
@@ -1135,6 +1141,7 @@ namespace TeamAAS_VP.Core
                             SendTaskMessage($"触发上相机锁附/组装拍照...", MessageLevel.Debug);
                             //相机的编号
                             Int16 cameraIndex = plc.ReadNode<Int16>(addressConfig.In_UpCameraPutNum.Address);
+                            SendTaskMessage($"编号:{cameraIndex}", MessageLevel.Info);
 
                             // 获取流程
                             var process = _productService.GetCurrentProductProcedureModelById(currentProduct.MoveDownCameraLockPhotoProcedureId);
@@ -1273,8 +1280,8 @@ namespace TeamAAS_VP.Core
                         {
                             SendTaskMessage($"收到开始锁付信号...", MessageLevel.Debug);
                             //位置编号
-                            //Int16 positionIndex = plc.ReadNode<Int16>(addressConfig.In_ProductNum.Address);
-
+                            Int16 positionIndex = plc.ReadNode<Int16>(addressConfig.In_ProductNum.Address);
+                            SendTaskMessage($"编号:{positionIndex}", MessageLevel.Info);
                         }
                         else
                         {
@@ -1293,6 +1300,7 @@ namespace TeamAAS_VP.Core
                             SendTaskMessage($"收到停止锁付信号...", MessageLevel.Debug);
                             //位置编号
                             Int16 positionIndex = plc.ReadNode<Int16>(addressConfig.In_ProductNum.Address);
+                            SendTaskMessage($"编号:{positionIndex}", MessageLevel.Info);
                             //获取当前锁付点
                             var screwPoint = currentProduct.ScrewPoints.FirstOrDefault(p=>p.Number== positionIndex);
                             //获取当前的机器人点位
@@ -1364,12 +1372,13 @@ namespace TeamAAS_VP.Core
 
                                 for (int i = 0; i < currentProduct.ScrewPoints.Count; i++)
                                 {
-                                    var localPoint = new PointF(currentProduct.ScrewCameraPoints[i].X_Position, currentProduct.ScrewCameraPoints[i].Y_Position);
+                                    var localPoint = new PointF(currentProduct.ScrewPoints[i].X_Position, currentProduct.ScrewPoints[i].Y_Position);
                                     var worldPoint= local.ToOldCoord(localPoint.X, localPoint.Y);
-                                    var point = currentProduct.ScrewCameraPoints[i].Clone();
+                                    var point = currentProduct.ScrewPoints[i].Clone();
                                     point.X_Position = (float)worldPoint[0];
                                     point.Y_Position = (float)worldPoint[1];
-                                    await point.WriteToPlcAddress(addressConfig.Out_ScrewCamera, plc);
+                                    SendTaskMessage($"点:{i},{point.X_Position:F3},{point.Y_Position:F4}", MessageLevel.Info);
+                                    await point.WriteToPlcAddress(addressConfig.Out_Screw, plc);
                                 }
                                 await plc.WriteNodeAsync(addressConfig.Out_WorkNum.Address, (Int16)currentProduct.ScrewPoints.Count);
                             }

+ 4 - 4
TeamAAS-VM/Core/PLCs/OPCuaClientPLC.cs

@@ -216,7 +216,7 @@ namespace TeamAAS_VP.Core.PLCs
             {
                 readNodeId = NodeHeader + nodeId;
             }
-            return OpcUaClient.ReadNode<T>(NodeHeader + nodeId);
+            return OpcUaClient.ReadNode<T>(readNodeId);
         }
 
         /// <summary>
@@ -232,7 +232,7 @@ namespace TeamAAS_VP.Core.PLCs
             {
                 readNodeId = NodeHeader + nodeId;
             }
-            return await OpcUaClient.ReadNodeAsync<T>(NodeHeader + nodeId);
+            return await OpcUaClient.ReadNodeAsync<T>(readNodeId);
         }
 
         /// <summary>
@@ -310,7 +310,7 @@ namespace TeamAAS_VP.Core.PLCs
         /// <param name="dataChangeHandler"></param>
         public void SubscribeNodes(string key, List<string> nodeIds, Action<(string key,string nodeId,object value)> dataChangeHandler)
         {
-            OpcUaClient.AddSubscription("InputOutput", nodeIds.Select(s =>
+            OpcUaClient.AddSubscription(key, nodeIds.Select(s =>
             {
                 if (s.StartsWith(NodeHeader))
                 {
@@ -333,7 +333,7 @@ namespace TeamAAS_VP.Core.PLCs
                     nodeId= nodeId.Substring(NodeHeader.Length);
                 }
                 // 触发数据变化事件
-                dataChangeHandler?.Invoke((key, nodeId, notification.Value.WrappedValue.Value));
+                dataChangeHandler?.Invoke((key1, nodeId, notification.Value.WrappedValue.Value));
             });
         }
         #region OPC事件