From d007fd8d64ff33a1edb960fa33cf2312a955d933 Mon Sep 17 00:00:00 2001
From: wells.liu <wells.liu@broconcentric.com>
Date: 星期一, 06 七月 2020 14:02:46 +0800
Subject: [PATCH] 板卡底层优化

---
 src/Bro.Device.GTSCard/GTSCardDriver.cs |   96 ++++++++++++++++++++++++++++++++----------------
 1 files changed, 64 insertions(+), 32 deletions(-)

diff --git a/src/Bro.Device.GTSCard/GTSCardDriver.cs b/src/Bro.Device.GTSCard/GTSCardDriver.cs
index f2c0343..28e82b1 100644
--- a/src/Bro.Device.GTSCard/GTSCardDriver.cs
+++ b/src/Bro.Device.GTSCard/GTSCardDriver.cs
@@ -323,13 +323,13 @@
                     if (IConfig.AxisSettings.FirstOrDefault(a => a.AxisIndex == optionPara.AxisIndex)?.IsAxisEnabled ?? false)
                     {
                         string _position = "";
-                        string motionType = optionPara.MoveMode == EnumHelper.MotorMoveMode.Normal ? (optionPara.IsAbsolute ? "Abs" : "Rel") : optionPara.MoveMode.ToString();
+                        string motionType = optionPara.MoveMode == EnumHelper.MotionMode.Normal ? (optionPara.IsAbsolute ? "Abs" : "Rel") : optionPara.MoveMode.ToString();
 
                         _position = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff},{optionPara.AxisIndex},{motionType},{GetPosition(optionPara.AxisIndex)},{GetPrfPosition(optionPara.AxisIndex)},{optionPara.Destination},";
 
                         switch (optionPara.MoveMode)
                         {
-                            case MotorMoveMode.Normal:
+                            case MotionMode.Normal:
                                 {
                                     if (_isResetting)
                                     {
@@ -348,12 +348,12 @@
 
                                 }
                                 break;
-                            case MotorMoveMode.FindOri:
+                            case MotionMode.FindOri:
                                 {
                                     isSuccessAndStop = GoHome(optionPara);
                                 }
                                 break;
-                            case MotorMoveMode.Jog:
+                            case MotionMode.Jog:
                                 {
                                     isSuccessAndStop = JogMove(optionPara);
                                 }
@@ -413,6 +413,41 @@
         }
 
         /// <summary>
+        /// 鑾峰彇瑙勫垝閫熷害
+        /// </summary>
+        /// <param name="axisNum">Axis number</param>
+        /// <returns></returns>
+        public double GetPrfVelocity(int axisNum)
+        {
+            double prfVel = 0;
+            uint pclock = 0;
+            var ret = GTSCardAPI.GT_GetPrfVel((short)IConfig.CardNum, (short)axisNum, out prfVel, 1, out pclock);
+            if (ret != (short)GTSRetCode.GRCRunOK)
+            {
+                throw new Exception("杞�" + axisNum + "鑾峰彇瑙勫垝閫熷害寮傚父锛岄敊璇爜锛�" + ret);
+            }
+            prfVel = prfVel / IConfig.AxisVelocityRatio;
+            return prfVel;
+        }
+
+        /// <summary>
+        /// 鑾峰彇褰撳墠閫熷害
+        /// </summary>
+        /// <param name="axisNum">Axis number</param>
+        /// <returns></returns>
+        public double GetVelocity(int axisNum)
+        {
+            double vel = 0;
+            var ret = GTSCardAPI.GT_GetVel((short)IConfig.CardNum, (short)axisNum, out vel);
+            if (ret != (short)GTSRetCode.GRCRunOK)
+            {
+                throw new Exception("杞�" + axisNum + "鑾峰彇褰撳墠閫熷害寮傚父锛岄敊璇爜锛�" + ret);
+            }
+            vel = vel / IConfig.AxisVelocityRatio;
+            return vel;
+        }
+
+        /// <summary>
         /// Set Single Axis Do Jog Move  
         /// </summary>
         /// <param name="axisNum">AxisNo</param>
@@ -450,29 +485,6 @@
                 OnExceptionRaised?.Invoke(ex);
                 return false;
             }
-
-        }
-
-        /// <summary>
-        /// Set Single Axis Do stop Jog Move  
-        /// </summary>
-        /// <param name="axisNum">AxisNo</param>
-        /// <returns></returns>
-        public bool StopJog(int axisNum)
-        {
-            //鍋滄杩愬姩
-            MoveStop(axisNum, 0);
-            //杩愬姩寮�濮嬪悗 妫�鏌ヨ繍鍔ㄦ槸鍚﹀仠姝�
-            bool isStop = false;
-            int repeatTime = 1000;
-            do
-            {
-                isStop = IsStop((short)IConfig.CardNum, (short)axisNum);
-                Thread.Sleep(50);
-                repeatTime--;
-            } while (!isStop && repeatTime > 0);
-
-            return isStop;
         }
 
         /// <summary>
@@ -767,17 +779,17 @@
         /// </summary>
         /// <param name="index">杈撳嚭鍙�,杩斿洖1-16</param>
         /// <param name="value">false琛ㄧず杈撳嚭锛宼rue琛ㄧず鍏抽棴</param>
-        public override void WriteOutput(short cardNum, short index, IOValue value)
+        public override void WriteOutput(short index, IOValue value)
         {
             short outNum = (short)(index % 100 + 1);
             if ((int)value <= 1)
             {
-                GTSCardAPI.GT_SetDoBit(cardNum, GTSCardAPI.MC_GPO, outNum, (short)value);
+                GTSCardAPI.GT_SetDoBit((short)IConfig.CardNum, GTSCardAPI.MC_GPO, outNum, (short)value);
             }
             else
             {
                 var currentValue = (int)MonitorValues.FirstOrDefault(u => u.IONum == outNum && u.IOType == IOType.OUTPUT).Value;
-                GTSCardAPI.GT_SetDoBit(cardNum, GTSCardAPI.MC_GPO, outNum, (short)(currentValue == 1 ? 0 : 1));
+                GTSCardAPI.GT_SetDoBit((short)IConfig.CardNum, GTSCardAPI.MC_GPO, outNum, (short)(currentValue == 1 ? 0 : 1));
             }
         }
 
@@ -803,7 +815,24 @@
 
         #region IMonitor
 
-        //public List<IOItem> MonitorValues { get; set; } = new List<IOItem>();
+        public List<AxisMovingStatus> GetAxisMovingStatus()
+        {
+            List<AxisMovingStatus> axisMovingStatusesList = new List<AxisMovingStatus>();
+            foreach (var axisConfig in IConfig.AxisSettings.FindAll(u => u.IsAxisEnabled))
+            {
+                AxisMovingStatus axisMovingStatus = new AxisMovingStatus();
+                axisMovingStatus.AxisIndex = axisConfig.AxisIndex;
+                axisMovingStatus.AxisName = axisConfig.AxisName;
+                axisMovingStatus.CurPosition = Convert.ToInt32(GetPosition(axisMovingStatus.AxisIndex));
+                axisMovingStatus.Destination = Convert.ToInt32(GetPrfPosition(axisMovingStatus.AxisIndex));
+                axisMovingStatus.CurVelocity = GetVelocity(axisMovingStatus.AxisIndex);
+                axisMovingStatus.PrfVelocity = GetPrfVelocity(axisMovingStatus.AxisIndex);
+                axisMovingStatusesList.Add(axisMovingStatus);
+
+            }
+
+            return axisMovingStatusesList;
+        }
 
 
         public List<IOItem> GetMonitorValues()
@@ -849,7 +878,8 @@
                         if (!IConfig.IsEnableMonitor)
                             return;
                         var newValues = GetMonitorValues();
-                        if (newValues == null || newValues.Count == 0)
+                        var newAxisMovingStatus = GetAxisMovingStatus();
+                        if (newValues == null || newValues.Count == 0 || newAxisMovingStatus == null || newAxisMovingStatus.Count == 0)
                             continue;
 
                         Stopwatch sw = new Stopwatch();
@@ -860,6 +890,8 @@
                             var tempOld = MonitorValues.DeepSerializeClone();
                             MonitorCheckAndInvoke(tempNew, tempOld);
                         }
+
+                        AxisMovingOptionValues = new List<AxisMovingStatus>(newAxisMovingStatus);
                         MonitorValues = new List<IOItem>(newValues);
                         sw.Stop();
 

--
Gitblit v1.8.0