Эх сурвалжийг харах

Merge branch 'master' of http://49.235.130.76/XXF_1122/DaisyNPILine

徐孝锋 8 сар өмнө
parent
commit
81d44ac2e2

+ 44 - 4
TeamAAS-VM/Core/Cameras/OptCamera.cs

@@ -1,5 +1,6 @@
 using Cognex.VisionPro;
 using Microsoft.Win32;
+using NPOI.POIFS.Crypt.Dsig;
 using NPOI.SS.Formula.Eval;
 using SciCamera.Net;
 using System;
@@ -121,7 +122,7 @@ namespace TeamAAS_VP.Core.Cameras
 
                 if (devTlType == SciCam.SciCamTLType.SciCam_TLType_Gige)
                 {
-                    
+
                     SciCam.SCI_DEVICE_GIGE_INFO gigeDevInfo = (SciCam.SCI_DEVICE_GIGE_INFO)SciCam.ByteToStruct(device.info.gigeInfo, typeof(SciCam.SCI_DEVICE_GIGE_INFO));
                     uint ip1 = gigeDevInfo.ip;
                     int nIp1 = (int)(ip1 & 0x000000ff);
@@ -337,7 +338,7 @@ namespace TeamAAS_VP.Core.Cameras
                         throw new Exception("没有发现相机");
                     }
                 }
-                SciCam.SCI_DEVICE_INFO sCI_DEVICE_INFO= CameraInfo;
+                SciCam.SCI_DEVICE_INFO sCI_DEVICE_INFO = CameraInfo;
                 nReVal = mvCameraAcq.CreateDevice(ref sCI_DEVICE_INFO);
                 if (nReVal != SciCam.SCI_CAMERA_OK)
                 {
@@ -348,12 +349,22 @@ namespace TeamAAS_VP.Core.Cameras
                 nReVal = mvCameraAcq.OpenDevice();
                 // ch:设置触发模式为off | en:Set trigger mode as off
                 nReVal = mvCameraAcq.SetEnumValueByStringEx(SciCam.SciCamDeviceXmlType.SciCam_DeviceXml_Camera, "TriggerMode", "Off");
+                nReVal = mvCameraAcq.SetEnumValueByString("TriggerSource", "Software");
+                // ch:注册事件回调 | en:Register event callback
+                //nReVal = mvCameraAcq.RegisterPayloadCallBack(new SciCam.fnOnPayloadDelegate(ImageCallBack), IntPtr.Zero, true);
+                // ch:设置采集策略 | en:Set Grab Strategy
+                nReVal = mvCameraAcq.SetGrabStrategy(SciCam.SciCamGrabStrategy.SciCam_GrabStrategy_Latest);
+                if (nReVal != SciCam.SCI_CAMERA_OK)
+                {
+                    Console.WriteLine("Register Event CallBack fail! nRet {0}", nReVal);
+                }
                 if (!IsConnected)
                 {
                     CameraConnectChangedEvent?.Invoke(ID, true);
                 }
+                mvCameraAcq.SetGrabTimeout(2000);
                 IsConnected = mvCameraAcq.IsDeviceOpen();
-                if (IsConnected) 
+                if (IsConnected)
                 {
                     mvCameraAcq.StartGrabbing();
                 }
@@ -415,7 +426,14 @@ namespace TeamAAS_VP.Core.Cameras
                         {
                             OpenDevice();
                         }
+                        //if (!mvCameraAcq.IsGrabbing())
+                        //{
+                        //    mvCameraAcq.StartGrabbing();
+                        //}
                         //nReVal = mvCameraAcq.StartGrabbing();
+                        //mvCameraAcq.ClearPayloadBuffer();
+                        // ch:发送软触发命令 | en:Send Trigger Software command
+                        //nReVal = mvCameraAcq.SetCommandValueEx(SciCam.SciCamDeviceXmlType.SciCam_DeviceXml_Camera, "TriggerSoftware");
                         nReVal = mvCameraAcq.Grab(ref payload);
                         if (nReVal == SciCam.SCI_CAMERA_OK)
                         {
@@ -423,11 +441,12 @@ namespace TeamAAS_VP.Core.Cameras
                             mvCameraAcq.FreePayload(payload);
                             //nReVal = mvCameraAcq.StopGrabbing();
                             TotalTime = sw.Elapsed;
+                            ErrorMessage = $"{i + 1}";
                             return Image;
                         }
                         else
                         {
-                            nReVal = mvCameraAcq.FreePayload(payload);
+                            //nReVal = mvCameraAcq.FreePayload(payload);
                             //nReVal = mvCameraAcq.StopGrabbing();
                             //_operationSemaphore.Release();
                             CloseDevice();
@@ -456,6 +475,27 @@ namespace TeamAAS_VP.Core.Cameras
             }
         }
 
+        // ch:采集回调接口 | en:Grab Callback interface     
+        void ImageCallBack(IntPtr payload, IntPtr tag)
+        {
+            if (payload == IntPtr.Zero) return;
+            uint nReVal = SciCam.SCI_CAMERA_OK;
+
+            SciCam.SCI_CAM_PAYLOAD_ATTRIBUTE attribute = new SciCam.SCI_CAM_PAYLOAD_ATTRIBUTE();
+            nReVal = SciCam.PayloadGetAttribute(payload, ref attribute);
+            if (nReVal != SciCam.SCI_CAMERA_OK || !attribute.isComplete)
+            {
+                Console.WriteLine("Failed to get image attributes or frame is incomplete! nRet:{0}", nReVal);
+            }
+            else
+            {
+                Image = GetConvertedInfo(payload);
+                ImageCallbackEvent?.Invoke(Image, TotalTime, ErrorMessage);
+                //Console.WriteLine("Get One Frame: Width[{0}], Height[{1}], nFrameNum[{2}]",
+                //attribute.imgAttr.width, attribute.imgAttr.height, attribute.frameID);
+            }
+        }
+
         /// <summary>
         /// 开始采集图像
         /// </summary>

+ 47 - 29
TeamAAS-VM/Core/Management.cs

@@ -1107,12 +1107,15 @@ namespace TeamAAS_VP.Core
                 addressConfig.In_FixedCameracheckExe.Address,
                 addressConfig.In_WorkStart.Address,
                 addressConfig.In_WorkDone.Address,
-                addressConfig.In_MesCheck.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);
         }
@@ -1628,33 +1631,7 @@ 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))
                 {
@@ -1683,6 +1660,47 @@ 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)
             {

+ 21 - 20
TeamAAS-VM/Core/Robots/XYZU_Robot.cs

@@ -587,7 +587,7 @@ namespace TeamAAS_VP.Core.Robots
                     }
 
                     // 判断是否至少有一个轴在最近 Timeout 时间内发生过变化(即认为还在运动)
-                    bool anyAxisMovedRecently = actNodes.Any(node => (now - lastChange[node]).TotalMilliseconds <= 1000);
+                    bool anyAxisMovedRecently = actNodes.Any(node => (now - lastChange[node]).TotalMilliseconds <= 500);
 
                     // 如果没有任何轴在最近 Timeout 时间内发生变化,则认为出现停滞异常
                     if (!anyAxisMovedRecently && actNodes.Length > 0)
@@ -602,13 +602,14 @@ namespace TeamAAS_VP.Core.Robots
                     if (isFinished)
                     {
                         StopMove();
-                        if (isError)
-                        {
-                            LogHelper.WriteLogInfo($"机器人执行移动时发生错误,位置:X={position.X},Y={position.Y},Z={position.Z},U={position.U}");
-                            return false;
-                        }
                         return true;
                     }
+                    if (isError)
+                    {
+                        StopMove();
+                        LogHelper.WriteLogInfo($"机器人执行移动时发生错误,位置:X={position.X},Y={position.Y},Z={position.Z},U={position.U}");
+                        return false;
+                    }
 
                     // 检查整体超时(防止一直有抖动导致 anyAxisMovedRecently 一直为 true)
                     if (sw.ElapsedMilliseconds > 60000) // 保守超时,一分钟,可根据需求调整
@@ -667,10 +668,10 @@ namespace TeamAAS_VP.Core.Robots
                 {
                     keyValues.Add(axis.Command.ManuPositionNode, false);
                 }
-                if (!string.IsNullOrWhiteSpace(axis.Command.StopNode))
-                {
-                    keyValues.Add(axis.Command.StopNode, true);
-                }
+                //if (!string.IsNullOrWhiteSpace(axis.Command.StopNode))
+                //{
+                //    keyValues.Add(axis.Command.StopNode, true);
+                //}
             }
             bool result = Plc.WriteNodes(keyValues);
 
@@ -678,16 +679,16 @@ namespace TeamAAS_VP.Core.Robots
             //Task.Run(async () =>
             //{
             //    await Task.Delay(100);
-            Thread.Sleep(50);
-            Dictionary<string, object> resetValues = new Dictionary<string, object>();
-            foreach (var axis in Axes)
-            {
-                if (!string.IsNullOrWhiteSpace(axis.Command.StopNode))
-                {
-                    resetValues.Add(axis.Command.StopNode, false);
-                }
-            }
-            Plc.WriteNodes(resetValues);
+            //Thread.Sleep(50);
+            //Dictionary<string, object> resetValues = new Dictionary<string, object>();
+            //foreach (var axis in Axes)
+            //{
+            //    if (!string.IsNullOrWhiteSpace(axis.Command.StopNode))
+            //    {
+            //        resetValues.Add(axis.Command.StopNode, false);
+            //    }
+            //}
+            //Plc.WriteNodes(resetValues);
             //});
             return result;
         }

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

@@ -653,7 +653,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 数据上传完成";
 
@@ -790,12 +790,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 上传本站数据";
 

+ 2 - 2
TeamAAS-VM/Properties/AssemblyInfo.cs

@@ -51,5 +51,5 @@ using System.Windows;
 //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
 //通过使用 "*",如下所示:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.2.0.2")]
-[assembly: AssemblyFileVersion("1.2.0.2")]
+[assembly: AssemblyVersion("1.2.0.4")]
+[assembly: AssemblyFileVersion("1.2.0.4")]