领胜LDS 键盘AOI检测项目
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);
@@ -526,7 +530,7 @@
        /// <returns></returns>
        public double GetPosition(int axisNum)
        {
            lock (moveLock)
            //lock (moveLock)
            {
                double position = 0;
                double pPos = 0;
@@ -646,7 +650,9 @@
                if (CurrentState != EnumHelper.DeviceState.DSOpen)
                {
                    LogAsync(DateTime.Now, "非正常状态异常", "轴" + optionPara.AxisIndex + "试图在非正常状态运动");
                    throw new ProcessException("轴" + optionPara.AxisIndex + "试图在非正常状态运动", null);
                    return false;
                    //throw new ProcessException("轴" + optionPara.AxisIndex + "试图在非正常状态运动", null);
                }
                LogAsync(DateTime.Now, "轴" + optionPara.AxisIndex + "开始运动", "目标坐标:" + optionPara.Destination);
@@ -725,8 +731,11 @@
                if (CurrentState != EnumHelper.DeviceState.DSOpen)
                {
                    LogAsync(DateTime.Now, "非正常状态异常", "轴" + optionPara.AxisIndex + "试图在非正常状态运动");
                    throw new ProcessException("轴" + optionPara.AxisIndex + "试图在非正常状态运动", null);
                    return false;
                    //throw new ProcessException("轴" + optionPara.AxisIndex + "试图在非正常状态运动", 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)
@@ -891,6 +908,8 @@
        {
            try
            {
                Thread.CurrentThread.Priority = ThreadPriority.AboveNormal;
                var goHomePara = IConfig.AxisSettings.FirstOrDefault(u => u.AxisIndex == movingOption.AxisIndex).GoHomePara;
                bool homeDirection = goHomePara.IsHomeDirPositive;
                bool isRightLimitReached = false;
@@ -914,6 +933,8 @@
                    PositionReset(movingOption.AxisIndex, 1);
                    ClearStatus(movingOption.AxisIndex, 1);
                    //LogAsync(DateTime.Now, $"{Name}位置置零", "");
                    if (goHomePara.IsCaptureMode)
                    {
                        //搜索距离 阶段1
@@ -922,7 +943,7 @@
                    }
                    // 设置点位模式目标位置,即原点搜索距离
                    sRtn = GTSCardAPI.GT_SetPos((short)IConfig.CardNum, (short)movingOption.AxisIndex, homeDirection ? 99999999 : -99999999);
                    sRtn = GTSCardAPI.GT_SetPos((short)IConfig.CardNum, (short)movingOption.AxisIndex, homeDirection ? 999999999 : -999999999);
                    // 启动运动
                    sRtn = GTSCardAPI.GT_Update((short)IConfig.CardNum, 1 << (movingOption.AxisIndex - 1));
@@ -940,7 +961,7 @@
                    do
                    {
                        Thread.Sleep(checkInterval * 2);
                        Thread.Sleep(checkInterval);
                        if (goHomePara.IsCaptureMode)
                        {
@@ -950,11 +971,11 @@
                        else
                        {
                            GTSCardAPI.GT_GetDi((short)IConfig.CardNum, GTSCardAPI.MC_HOME, out int pValue);
                            capture = (short)((pValue & (1 << (movingOption.AxisIndex - 1))) == 0 ? 1 : 0);
                            //LogAsync(DateTime.Now, $"原点状态{pValue},轴{movingOption.AxisIndex}原点{capture}", "");
                        }
                        isStop = IsStop((short)movingOption.AxisIndex);
                        repeatTime -= checkInterval * 2;
                        repeatTime -= checkInterval;
                    } while (!(isStop || capture == 1 || repeatTime <= 0));
                    if (repeatTime <= 0)
@@ -965,25 +986,40 @@
                    var axisStatus = AxisStatusList.FirstOrDefault(u => u.AxisIndex == movingOption.AxisIndex);
                    //if (isStop)
                    //{
                    //    LogAsync(DateTime.Now, $"轴{movingOption.AxisIndex}复位中停止", $"Capture状态{capture}");
                    //}
                    if (isStop && capture != 1)
                    {
                        if (((axisStatus.AxisStatus & 0x20) != 0) || ((axisStatus.AxisStatus & 0x40) != 0))
                        {
                            //movingOption.GoHomePara.HomeDir = (short)(movingOption.GoHomePara.HomeDir == 1 ? -1 : 1);
                            capture = 0;
                            //正限位
                            if ((axisStatus.AxisStatus & 0x20) != 0 && !goHomePara.IsCaptureDirPositive)
                            if ((axisStatus.AxisStatus & 0x20) != 0)
                            {
                                isRightLimitReached = true;
                                homeDirection = false;
                                if (!goHomePara.IsCaptureDirPositive)
                                {
                                    isRightLimitReached = true;
                                }
                            }
                            //负限位
                            if ((axisStatus.AxisStatus & 0x40) != 0 && goHomePara.IsCaptureDirPositive)
                            if ((axisStatus.AxisStatus & 0x40) != 0)
                            {
                                isRightLimitReached = true;
                                homeDirection = true;
                                if (goHomePara.IsCaptureDirPositive)
                                {
                                    isRightLimitReached = true;
                                }
                            }
                            homeDirection = !homeDirection;
                            LogAsync(DateTime.Now, $"轴{movingOption.AxisIndex}极限位置换向", "");
                        }
                        ClearStatus(movingOption.AxisIndex, 1);
@@ -1018,17 +1054,25 @@
                            repeatTime--;
                        } while (!isStop && repeatTime > 0);
                        PositionReset(movingOption.AxisIndex, 1);
                        LogAsync(DateTime.Now, $"轴{movingOption.AxisIndex}复位完成,位置清零", "");
                        return (sRtn == (short)GTSRetCode.GRCRunOK) && isStop;
                    }
                } while (!(capture == 1 && isRightLimitReached));
                return false;
            }
            catch (Exception ex)
            {
                LogAsync(DateTime.Now, $"{Name}回原点异常", ex.GetExceptionMessage());
                AllMoveStop(true);
                OnExceptionOccured?.Invoke(DateTime.Now, ex);
                return false;
            }
            finally
            {
            }
        }
@@ -1099,7 +1143,7 @@
        /// <returns></returns>
        public override int GetAxisStatus(int axisNum)
        {
            lock (moveLock)
            //lock (moveLock)
            {
                int sts = 0;
                uint pclock = 0;
@@ -1122,7 +1166,7 @@
        /// <returns></returns>
        public override bool PositionReset(int startAxisIndex, int count)
        {
            lock (moveLock)
            //lock (moveLock)
            {
                var rtn = GTSCardAPI.GT_ZeroPos((short)IConfig.CardNum, (short)startAxisIndex, (short)count);
                return rtn == (short)GTSRetCode.GRCRunOK;
@@ -1209,7 +1253,9 @@
                            }
                        });
                        _positionWait.SpinOnce();
                        Task.Delay(100).Wait();
                        //_positionWait.SpinOnce();
                    }
                    catch (Exception ex)
                    {
@@ -1246,7 +1292,8 @@
                            }
                        });
                        _statusWait.SpinOnce();
                        Thread.Sleep(10);
                        //Task.Delay(10).Wait();
                    }
                    catch (Exception ex)
                    {