From 773369500892dcb5347e4a0059f8089960073030 Mon Sep 17 00:00:00 2001
From: xcd <834800634@qq.com>
Date: 星期三, 15 七月 2020 22:08:34 +0800
Subject: [PATCH] 板卡回原点配置迁移到初始配置轴配置中 板卡回原点配置区分运动方向和捕捉方向,限制捕捉原点方向

---
 src/Bro.Device.GTSCard/GTSCardDriver.cs         |   41 ++++++++++++++++----
 src/Bro.M071.Process/M071Process.cs             |   12 ++++--
 src/Bro.Common.Model/Model/MotionCardRelated.cs |   49 ++++++++++++++++--------
 3 files changed, 73 insertions(+), 29 deletions(-)

diff --git a/src/Bro.Common.Model/Model/MotionCardRelated.cs b/src/Bro.Common.Model/Model/MotionCardRelated.cs
index 1037012..8d9ce6b 100644
--- a/src/Bro.Common.Model/Model/MotionCardRelated.cs
+++ b/src/Bro.Common.Model/Model/MotionCardRelated.cs
@@ -86,6 +86,13 @@
         //[Description("IsUseWarning锛氭槸鍚﹀惎鐢ㄦ姤璀�")]
         //public bool IsUseWarning { get; set; } = false;
 
+        [Category("鍘熺偣閰嶇疆")]
+        [DisplayName("鍥炲師鐐瑰弬鏁�")]
+        [Description("鍥炲師鐐瑰弬鏁�")]
+        [TypeConverter(typeof(ComplexObjectConvert))]
+        [Editor(typeof(PropertyObjectEditor), typeof(UITypeEditor))]
+        public GoHomePara GoHomePara { get; set; } = new GoHomePara();
+
         [Category("鏆傚仠閰嶇疆")]
         [DisplayName("鏄惁鍚敤绔嬪嵆鏆傚仠")]
         [Description("IsImmediatePause锛氭槸鍚﹀惎鐢ㄧ珛鍗虫殏鍋�")]
@@ -154,25 +161,19 @@
         [Category("鍥炲師鐐瑰弬鏁�")]
         [DisplayName("鍥炲師鐐规柟寮�")]
         [Description("HomeMode锛氬洖鍘熺偣鏂瑰紡 锛圚OME_MODE_LIMIT = 10; HOME_MODE_LIMIT_HOME = 11; HOME_MODE_LIMIT_INDEX = 12; HOME_MODE_LIMIT_HOME_INDEX = 13;HOME_MODE_HOME = 20;HOME_MODE_HOME_INDEX = 22;HOME_MODE_INDEX = 30;")]
-        public short HomeMode { get; set; } = 11;
-
-        [Category("鍥炲師鐐瑰弬鏁�")]
-        [DisplayName("鍥炲師鐐规柟鍚�")]
-        [Description("HomeDir锛�1 姝e悜锛�-1 璐熷悜")]
-        public short HomeDir { get; set; } = 1;
+        public short HomeMode { get; set; } = 11; 
 
         [Category("鍥炲師鐐瑰弬鏁�")]
         [DisplayName("杈圭紭")]
         [Description("edge锛氳竟缂�")]
         public short Edge { get; set; } = 0;
 
-        [Category("鍥炲師鐐瑰弬鏁�")]
+        [Category("鍥炲師鐐归�熷害")]
         [DisplayName("鍥炲師鐐规渶浣庨�熷害")]
         [Description("LowVelocity锛氶�熷害,涓�0鏃惰〃绀轰笉淇敼褰撳墠璁剧疆")]
         public double LowVelocity { get; set; } = 50;
 
-
-        [Category("鍥炲師鐐瑰弬鏁�")]
+        [Category("鍥炲師鐐归�熷害")]
         [DisplayName("鍥炲師鐐规渶楂橀�熷害")]
         [Description("HighVelocity锛氶�熷害,涓�0鏃惰〃绀轰笉淇敼褰撳墠璁剧疆")]
         public double HighVelocity { get; set; } = 50;
@@ -182,16 +183,30 @@
         //[Description("SearchHomeDistance锛氭悳绱㈣窛绂�")]
         //public int SearchHomeDistance { get; set; } = 9999999;
 
-        [Category("鍥炲師鐐瑰弬鏁�")]
+        [Category("鍥炲師鐐瑰亸绉�")]
         [DisplayName("鍋忕Щ璺濈")]
         [Description("HomeOffset锛氬亸绉昏窛绂�")]
         public int HomeOffset { get; set; } = 0;
 
-        [Category("鍥炲師鐐瑰弬鏁�")]
+        [Category("鍥炲師鐐瑰亸绉�")]
         [DisplayName("璺宠繃姝ラ暱")]
         [Description("EscapeStep锛氳烦杩囨闀�")]
         public int EscapeStep { get; set; } = 1000;
 
+        [Category("鍥炲師鐐规柟鍚�")]
+        [DisplayName("璧峰杩愬姩鏂瑰悜")]
+        [Description("鍥炲師鐐规椂锛岃酱鐨勫垵濮嬭繍鍔ㄦ柟鍚戯細true 姝e悜锛宖alse 璐熷悜")]
+        public bool IsHomeDirPositive { get; set; } = true;
+
+        [Category("鍥炲師鐐规柟鍚�")]
+        [DisplayName("鍘熺偣鎹曟崏鏂瑰悜")]
+        [Description("鎹曟崏鍘熺偣鏃讹紝杞寸殑杩愬姩鏂瑰悜锛歵rue 姝e悜锛宖alse 璐熷悜")]
+        public bool IsCaptureDirPositive { get; set; } = true;
+
+        [Category("鍥炲師鐐硅秴鏃�")]
+        [DisplayName("鍥炲師鐐硅秴鏃�")]
+        [Description("鍥炲師鐐硅秴鏃讹紝鍗曚綅绉�")]
+        public int GoHomeTimeOut { get; set; } = 60;
     }
 
     /// <summary>
@@ -352,12 +367,12 @@
         //}
 
         //private GoHomePara goHomePara = new GoHomePara();
-        [Category("杩愬姩閰嶇疆")]
-        [DisplayName("鍥炲師鐐瑰弬鏁�")]
-        [Description("GoHomePara锛氶�熷害鍙傛暟")]
-        [TypeConverter(typeof(ComplexObjectConvert))]
-        [Editor(typeof(PropertyObjectEditor), typeof(UITypeEditor))]
-        public GoHomePara GoHomePara { get; set; } = new GoHomePara();
+        //[Category("杩愬姩閰嶇疆")]
+        //[DisplayName("鍥炲師鐐瑰弬鏁�")]
+        //[Description("GoHomePara锛氶�熷害鍙傛暟")]
+        //[TypeConverter(typeof(ComplexObjectConvert))]
+        //[Editor(typeof(PropertyObjectEditor), typeof(UITypeEditor))]
+        //public GoHomePara GoHomePara { get; set; } = new GoHomePara();
         //{
         //    get => goHomePara;
         //    set
diff --git a/src/Bro.Device.GTSCard/GTSCardDriver.cs b/src/Bro.Device.GTSCard/GTSCardDriver.cs
index 2385a82..d87e661 100644
--- a/src/Bro.Device.GTSCard/GTSCardDriver.cs
+++ b/src/Bro.Device.GTSCard/GTSCardDriver.cs
@@ -888,7 +888,11 @@
         {
             try
             {
-                StartCapture:
+                var goHomePara = IConfig.AxisSettings.FirstOrDefault(u => u.AxisIndex == movingOption.AxisIndex).GoHomePara;
+                bool homeDirection = goHomePara.IsHomeDirPositive;
+                bool isRightLimitReached = false;
+
+            StartCapture:
 
                 PositionReset(movingOption.AxisIndex, 1);
                 ClearStatus(movingOption.AxisIndex, 1);
@@ -907,24 +911,24 @@
                 // 璁剧疆鐐逛綅妯″紡杩愬姩鍙傛暟
                 sRtn = GTSCardAPI.GT_SetTrapPrm((short)IConfig.CardNum, (short)movingOption.AxisIndex, ref trapPrm);
                 // 璁剧疆鐐逛綅妯″紡鐩爣閫熷害锛屽嵆鍥炲師鐐归�熷害
-                sRtn = GTSCardAPI.GT_SetVel((short)IConfig.CardNum, (short)movingOption.AxisIndex, movingOption.GoHomePara.HighVelocity);
+                sRtn = GTSCardAPI.GT_SetVel((short)IConfig.CardNum, (short)movingOption.AxisIndex, goHomePara.HighVelocity);
 
                 // 璁剧疆鐐逛綅妯″紡鐩爣浣嶇疆锛屽嵆鍘熺偣鎼滅储璺濈
-                sRtn = GTSCardAPI.GT_SetPos((short)IConfig.CardNum, (short)movingOption.AxisIndex, movingOption.GoHomePara.HomeDir == 1 ? 99999999 : -99999999);
+                sRtn = GTSCardAPI.GT_SetPos((short)IConfig.CardNum, (short)movingOption.AxisIndex, homeDirection ? 99999999 : -99999999);
                 // 鍚姩杩愬姩
                 sRtn = GTSCardAPI.GT_Update((short)IConfig.CardNum, 1 << (movingOption.AxisIndex - 1));
 
-                int repeatTime = 1000;
+                int repeatTime = goHomePara.GoHomeTimeOut * 1000;
                 short capture;
                 int pos;
                 uint clk;//鏃堕挓鍙傛暟
                 do
                 {
-                    Thread.Sleep(20);
+                    Thread.Sleep(IConfig.MonitorInterval);
                     // 璇诲彇鎹曡幏鐘舵��
                     GTSCardAPI.GT_GetCaptureStatus((short)IConfig.CardNum, (short)movingOption.AxisIndex, out capture, out pos, 1, out clk);
                     isStop = IsStop((short)movingOption.AxisIndex);
-                    repeatTime--;
+                    repeatTime -= IConfig.MonitorInterval;
                 } while (!(isStop || capture == 1 || repeatTime <= 0));
 
                 if (repeatTime <= 0)
@@ -941,7 +945,22 @@
 
                     if (((axisStatus.AxisStatus & 0x20) != 0) || ((axisStatus.AxisStatus & 0x40) != 0))
                     {
-                        movingOption.GoHomePara.HomeDir = (short)(movingOption.GoHomePara.HomeDir == 1 ? -1 : 1);
+                        //movingOption.GoHomePara.HomeDir = (short)(movingOption.GoHomePara.HomeDir == 1 ? -1 : 1);
+
+                        //姝i檺浣�
+                        if ((axisStatus.AxisStatus & 0x20) != 0 && !goHomePara.IsCaptureDirPositive)
+                        {
+                            isRightLimitReached = true;
+                        }
+
+
+                        //璐熼檺浣�
+                        if ((axisStatus.AxisStatus & 0x40) != 0 && goHomePara.IsCaptureDirPositive)
+                        {
+                            isRightLimitReached = true;
+                        }
+
+                        homeDirection = !homeDirection;
                         goto StartCapture;
                     }
 
@@ -950,12 +969,18 @@
 
                 if (capture == 1)
                 {
+                    if (!isRightLimitReached)
+                    {
+                        capture = 0;
+                        goto StartCapture;
+                    }
+
                     //鍏坰top
                     MoveStop((short)movingOption.AxisIndex, 0);
                     ClearStatus((short)movingOption.AxisIndex, 1);
                     //宸茬粡鎹曡幏鍒癏ome鎵嶅彲浠ュ洖闆� 闃舵2
                     // 杩愬姩鍒�"鎹曡幏浣嶇疆+鍋忕Щ閲�"
-                    sRtn = GTSCardAPI.GT_SetPos((short)IConfig.CardNum, (short)movingOption.AxisIndex, pos + movingOption.GoHomePara.HomeOffset);
+                    sRtn = GTSCardAPI.GT_SetPos((short)IConfig.CardNum, (short)movingOption.AxisIndex, pos + goHomePara.HomeOffset);
                     // 鍦ㄨ繍鍔ㄧ姸鎬佷笅鏇存柊鐩爣浣嶇疆
                     sRtn = GTSCardAPI.GT_Update((short)IConfig.CardNum, 1 << (movingOption.AxisIndex - 1));
                     isStop = false;
diff --git a/src/Bro.M071.Process/M071Process.cs b/src/Bro.M071.Process/M071Process.cs
index cf6b12d..325cccc 100644
--- a/src/Bro.M071.Process/M071Process.cs
+++ b/src/Bro.M071.Process/M071Process.cs
@@ -272,7 +272,7 @@
                           return;
                       }
 
-                      RunImageHandle(camera, s.CameraOp.OpConfig, set, s.Id, s.Name, pMeasure.Measurements);
+                      RunImageHandle(s.CameraOp.OpConfig, set, s.Id, s.Name, pMeasure.Measurements);
                   });
 
             BarCode = "";
@@ -1027,7 +1027,7 @@
         }
         #endregion
 
-        private async void RunImageHandle(CameraBase camera, IOperationConfig opConfig, IImageSet imgSet, string snapshotId, string snapshotName, List<MeasurementUnit> measureList)
+        private async void RunImageHandle(IOperationConfig opConfig, IImageSet imgSet, string snapshotId, string snapshotName, List<MeasurementUnit> measureList)
         {
             await Task.Run(() =>
              {
@@ -1095,7 +1095,10 @@
                      HOperatorSet.SelectObj(images, out HObject image, i);
 
                      string fileName = Path.Combine(dir, $"{i}.tif");
-                     image.ConvertHObjectToHImage().WriteImage("tiff", 0, fileName);
+                     using (HImage temp = image.ConvertHObjectToHImage())
+                     {
+                         temp.WriteImage("tiff", 0, fileName);
+                     }
 
                      keys.Where(u => u.ImageSeq == i).ToList().ForEach(k =>
                          {
@@ -1113,6 +1116,7 @@
                                  _halconToolDict[keyToolKey].InputImageDic["INPUT_Image"] = image;
                                  _halconToolDict[keyToolKey].InputTupleDic["INPUT_Resolution_X"] = scanParam.Resolution_X / 1000000.0;
                                  _halconToolDict[keyToolKey].InputTupleDic["INPUT_Resolution_Z"] = scanParam.Resolution_Z / 1000000.0;
+                                 _halconToolDict[keyToolKey].InputTupleDic["INPUT_ImageId"] = $"{k.AliasName}_{DateTime.Now.ToString("HHmmssfff")}.tif";
                                  if (!_halconToolDict[keyToolKey].RunProcedure(out string error))
                                  {
                                      LogAsync(DateTime.Now, $"{k.AliasName}妫�娴嬬畻娉曞紓甯革紝{error}", "");
@@ -1144,7 +1148,7 @@
                              });
                          });
 
-                     //image.Dispose();
+                     image.Dispose();
                  }
                  //);
 

--
Gitblit v1.8.0