From 8a3ab64a65da226636743be07c4bee63f50da25d Mon Sep 17 00:00:00 2001
From: patrick.xu <patrick.xu@broconcentric.com>
Date: 星期六, 06 三月 2021 11:35:20 +0800
Subject: [PATCH] 1. 解决软件异常崩溃问题

---
 src/Bro.Device.GTSCard/GTSCardDriver.cs |   66 ++++++++++++++++++++++----------
 1 files changed, 45 insertions(+), 21 deletions(-)

diff --git a/src/Bro.Device.GTSCard/GTSCardDriver.cs b/src/Bro.Device.GTSCard/GTSCardDriver.cs
index dbea577..a1c7aa6 100644
--- a/src/Bro.Device.GTSCard/GTSCardDriver.cs
+++ b/src/Bro.Device.GTSCard/GTSCardDriver.cs
@@ -312,7 +312,6 @@
             }
         }
 
-
         public override bool AllAxisOn()
         {
             List<Task<bool>> taskList = new List<Task<bool>>(); ;
@@ -387,7 +386,7 @@
                 responseMessage.Result = resultList.All(u => u == true);
                 if (!responseMessage.Result)
                 {
-                    responseMessage.Message = $"鐐逛綅杩愬姩寮傚父";
+                    responseMessage.Message = $"鐐逛綅杩愬姩寮傚父,杩愬姩缁撴灉锛歿string.Join(" ", resultList.Select(u => u ? "1" : "0"))}";
                 }
             }
             return responseMessage;
@@ -400,24 +399,28 @@
         /// <returns></returns>
         private bool SetAxisParam(MovingOption optionPara)
         {
-            List<short> resultCode = new List<short>() { 0 };
+            List<short> resultCode = new List<short>();
             GTSCardAPI.TTrapPrm trapprm = new GTSCardAPI.TTrapPrm();
             short axisIndex = short.Parse(optionPara.AxisIndexStr);
             resultCode.Add(GTSCardAPI.GT_PrfTrap((short)IConfig.CardNum, axisIndex));
-            resultCode.Add(GTSCardAPI.GT_GetTrapPrm((short)IConfig.CardNum, axisIndex, out trapprm));
-            trapprm.smoothTime = 1;
 
-            if (optionPara.VelocityPara.Acc != 0)
+            if (optionPara.VelocityPara.Acc != 0 || optionPara.VelocityPara.Dec != 0)
             {
-                trapprm.acc = optionPara.VelocityPara.Acc;
-            }
+                resultCode.Add(GTSCardAPI.GT_GetTrapPrm((short)IConfig.CardNum, axisIndex, out trapprm));
+                trapprm.smoothTime = 1;
 
-            if (optionPara.VelocityPara.Dec != 0)
-            {
-                trapprm.dec = optionPara.VelocityPara.Dec;
-            }
+                if (optionPara.VelocityPara.Acc != 0)
+                {
+                    trapprm.acc = optionPara.VelocityPara.Acc;
+                }
 
-            resultCode.Add(GTSCardAPI.GT_SetTrapPrm((short)IConfig.CardNum, axisIndex, ref trapprm));
+                if (optionPara.VelocityPara.Dec != 0)
+                {
+                    trapprm.dec = optionPara.VelocityPara.Dec;
+                }
+
+                resultCode.Add(GTSCardAPI.GT_SetTrapPrm((short)IConfig.CardNum, axisIndex, ref trapprm));
+            }
 
             if (optionPara.VelocityPara.Velocity != 0)
             {
@@ -427,9 +430,10 @@
             var resultOK = resultCode.All(u => u == (short)GTSRetCode.GRCRunOK);
             if (!resultOK)
             {
-                throw new ProcessException("杞�" + optionPara.AxisIndex + "璁剧疆鍙傛暟寮傚父锛岄敊璇爜锛�" + string.Join(",", resultCode));
+                //throw new ProcessException("杞�" + optionPara.AxisIndex + "璁剧疆鍙傛暟寮傚父锛岄敊璇爜锛�" + string.Join(",", resultCode));
+                LogAsync(DateTime.Now, $"杞磠optionPara.AxisIndex}璁剧疆鍙傛暟寮傚父锛岄敊璇爜锛歿string.Join(",", resultCode)}", "");
             }
-            return resultOK;
+            return true;
         }
 
         TaskFactory taskFactory = new TaskFactory(TaskCreationOptions.LongRunning, TaskContinuationOptions.LongRunning);
@@ -646,7 +650,9 @@
                 if (CurrentState != EnumHelper.DeviceState.DSOpen)
                 {
                     LogAsync(DateTime.Now, "闈炴甯哥姸鎬佸紓甯�", "杞�" + optionPara.AxisIndex + "璇曞浘鍦ㄩ潪姝e父鐘舵�佽繍鍔�");
-                    throw new ProcessException("杞�" + optionPara.AxisIndex + "璇曞浘鍦ㄩ潪姝e父鐘舵�佽繍鍔�", null);
+
+                    return false;
+                    //throw new ProcessException("杞�" + optionPara.AxisIndex + "璇曞浘鍦ㄩ潪姝e父鐘舵�佽繍鍔�", null);
                 }
 
                 LogAsync(DateTime.Now, "杞�" + optionPara.AxisIndex + "寮�濮嬭繍鍔�", "鐩爣鍧愭爣锛�" + optionPara.Destination);
@@ -725,8 +731,11 @@
                 if (CurrentState != EnumHelper.DeviceState.DSOpen)
                 {
                     LogAsync(DateTime.Now, "闈炴甯哥姸鎬佸紓甯�", "杞�" + optionPara.AxisIndex + "璇曞浘鍦ㄩ潪姝e父鐘舵�佽繍鍔�");
-                    throw new ProcessException("杞�" + optionPara.AxisIndex + "璇曞浘鍦ㄩ潪姝e父鐘舵�佽繍鍔�", null);
+
+                    return false;
+                    //throw new ProcessException("杞�" + optionPara.AxisIndex + "璇曞浘鍦ㄩ潪姝e父鐘舵�佽繍鍔�", null);
                 }
+
                 LogAsync(DateTime.Now, "杞�" + optionPara.AxisIndex + "寮�濮嬭繍鍔�", "鐩爣鍧愭爣锛�" + optionPara.Destination);
                 short ret = 0;
                 bool isSuccessSetAxisParam = false;
@@ -760,7 +769,14 @@
                     repeatTime--;
                 }
 
-                return (ret == (short)GTSRetCode.GRCRunOK) && isStop;
+                if (repeatTime <= 0)
+                {
+                    LogAsync(DateTime.Now, "杞�" + optionPara.AxisIndex + "APS_absolute_move鏈仠姝�", "");
+                    return false;
+                }
+
+                //return (ret == (short)GTSRetCode.GRCRunOK) && isStop;
+                return true;
             }
             catch (Exception ex)
             {
@@ -783,7 +799,8 @@
                 bool isStop = false;
                 if (option == 1)
                 {
-                    StateChange(EnumHelper.DeviceState.DSExcept);
+                    //StateChange(EnumHelper.DeviceState.DSExcept);
+                    LogAsync(DateTime.Now, "鎬ュ仠鍋滄", "");
                 }
                 var ret = GTSCardAPI.GT_Stop((short)IConfig.CardNum, 1 << (axisNum - 1), option);
                 if (ret != (short)GTSRetCode.GRCRunOK)
@@ -1045,6 +1062,10 @@
                 OnExceptionOccured?.Invoke(DateTime.Now, ex);
                 return false;
             }
+            finally
+            { 
+            
+            }
         }
 
         /// <summary>
@@ -1224,7 +1245,9 @@
                             }
                         });
 
-                        _positionWait.SpinOnce();
+                        Task.Delay(100).Wait();
+
+                        //_positionWait.SpinOnce();
                     }
                     catch (Exception ex)
                     {
@@ -1261,7 +1284,8 @@
                             }
                         });
 
-                        _statusWait.SpinOnce();
+                        Thread.Sleep(10);
+                        //Task.Delay(10).Wait();
                     }
                     catch (Exception ex)
                     {

--
Gitblit v1.8.0