| | |
| | | /// 运动轴立即暂停 |
| | | /// </summary> |
| | | Dictionary<int, ManualResetEvent> axisImmediatePauseHandleDict = new Dictionary<int, ManualResetEvent>(); |
| | | Dictionary<int, bool> axisImmediatePauseFlag = new Dictionary<int, bool>(); |
| | | Dictionary<int, bool> axisPauseResumeFlag = new Dictionary<int, bool>(); |
| | | |
| | | //Dictionary<int, CancellationTokenSource> axisMoveCancelDict = new Dictionary<int, CancellationTokenSource>(); |
| | | |
| | |
| | | { |
| | | AllAxisOn(); |
| | | |
| | | MonitorPosition(); |
| | | MonitorAxisStatus(); |
| | | |
| | | base.Start(); |
| | | } |
| | | |
| | |
| | | { |
| | | foreach (var preCheck in operationSet.PreCheckIOCollection) |
| | | { |
| | | int timeout = operationSet.PreCheckIOTimeout; |
| | | _pauseHandle.Wait(); |
| | | |
| | | IOValue? ioData = null; |
| | | while (CurrentState == DeviceState.DSOpen) |
| | | if (CurrentState == DeviceState.DSOpen) |
| | | { |
| | | Thread.Sleep(10); |
| | | ioData = MonitorValues.FirstOrDefault(u => u.IONum == preCheck.IOItem.IONum && u.IOType == preCheck.IOItem.IOType)?.Value;//IO 是开、关 从MonitorValues 获取 |
| | | timeout -= 10; |
| | | if (preCheck.CheckValue == ioData || (operationSet.PreCheckIOTimeout > 0 && timeout < 0)) |
| | | int timeout = operationSet.PreCheckIOTimeout; |
| | | |
| | | while (CurrentState == DeviceState.DSOpen) |
| | | { |
| | | break; |
| | | Thread.Sleep(10); |
| | | ioData = MonitorValues.FirstOrDefault(u => u.IONum == preCheck.IOItem.IONum && u.IOType == preCheck.IOItem.IOType)?.Value;//IO 是开、关 从MonitorValues 获取 |
| | | timeout -= 10; |
| | | if (preCheck.CheckValue == ioData || (operationSet.PreCheckIOTimeout > 0 && timeout < 0)) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | // 2.板卡运动 |
| | | if (CurrentState == DeviceState.DSOpen) |
| | | { |
| | | responseMessage = MoveToPoint(new MotionOperationCollection() { MovingOps = operationSet.MovingOps }); |
| | | if (!responseMessage.Result) |
| | | _pauseHandle.Wait(); |
| | | |
| | | if (CurrentState == DeviceState.DSOpen) |
| | | { |
| | | return responseMessage; |
| | | responseMessage = MoveToPoint(new MotionOperationCollection() { MovingOps = operationSet.MovingOps }); |
| | | if (!responseMessage.Result) |
| | | { |
| | | return responseMessage; |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | // 3.IO输出 不需要超时 |
| | | if (CurrentState == DeviceState.DSOpen) |
| | | { |
| | | |
| | | foreach (var ioOutput in operationSet.IOOutputCollection) |
| | | { |
| | | WriteOutput((short)ioOutput.IOItem.IONum, ioOutput.CheckValue); |
| | | _pauseHandle.Wait(); |
| | | |
| | | //var ioData = MonitorValues.FirstOrDefault(u => u.IONum == ioOutput.IOItem.IONum && u.IOType == ioOutput.IOItem.IOType)?.Value;//IO 是开、关 从MonitorValues 获取 |
| | | if (CurrentState == DeviceState.DSOpen) |
| | | { |
| | | WriteOutput((short)ioOutput.IOItem.IONum, ioOutput.CheckValue); |
| | | |
| | | //if (ioOutput.CheckValue != ioData) |
| | | //{ |
| | | // responseMessage.Result = false; |
| | | // responseMessage.Message = $"IO输出不通过,配置:{ioOutput.GetDisplayText()},当前值:{ioData}"; |
| | | // return responseMessage; |
| | | //} |
| | | //var ioData = MonitorValues.FirstOrDefault(u => u.IONum == ioOutput.IOItem.IONum && u.IOType == ioOutput.IOItem.IOType)?.Value;//IO 是开、关 从MonitorValues 获取 |
| | | |
| | | //if (ioOutput.CheckValue != ioData) |
| | | //{ |
| | | // responseMessage.Result = false; |
| | | // responseMessage.Message = $"IO输出不通过,配置:{ioOutput.GetDisplayText()},当前值:{ioData}"; |
| | | // return responseMessage; |
| | | //} |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | #endregion |
| | | |
| | | #region ImmediatePause |
| | | ManualResetEventSlim _pauseHandle = new ManualResetEventSlim(true); |
| | | |
| | | /// <summary> |
| | | /// 启动立即暂停 |
| | | /// </summary> |
| | |
| | | if (!_isResetting) |
| | | { |
| | | var immediatePauseAxis = IConfig.AxisSettings.FindAll(a => a.IsAxisEnabled && a.IsImmediatePause).Select(u => u.AxisIndex).ToList(); |
| | | |
| | | _pauseHandle.Reset(); |
| | | immediatePauseAxis.ForEach(async axisIndex => |
| | | { |
| | | axisImmediatePauseHandleDict[axisIndex].Reset(); |
| | | |
| | | //axisMoveCancelDict[axisIndex].Cancel(); |
| | | axisImmediatePauseFlag[axisIndex] = true; |
| | | |
| | | await MoveStop(axisIndex, 0);//所有轴都暂停 |
| | | }); |
| | |
| | | /// <summary> |
| | | /// 恢复立即暂停 |
| | | /// </summary> |
| | | public override void ResetImmediatePause() |
| | | public override void ResetImmediatePause(bool isResumeMoving) |
| | | { |
| | | var immediatePauseAxis = IConfig.AxisSettings.FindAll(a => a.IsAxisEnabled && a.IsImmediatePause).Select(u => u.AxisIndex).ToList(); |
| | | |
| | | _pauseHandle.Set(); |
| | | immediatePauseAxis.ForEach(axisIndex => |
| | | { |
| | | //axisMoveCancelDict[axisIndex] = new CancellationTokenSource(); |
| | | |
| | | axisImmediatePauseFlag[axisIndex] = false; |
| | | axisImmediatePauseHandleDict[axisIndex].Set(); |
| | | if (isResumeMoving) |
| | | { |
| | | axisPauseResumeFlag[axisIndex] = true; |
| | | } |
| | | else |
| | | { |
| | | axisPauseResumeFlag[axisIndex] = false; |
| | | } |
| | | }); |
| | | } |
| | | #endregion |
| | |
| | | throw new ProcessException("板卡载入配置文件异常,错误码:" + res); |
| | | } |
| | | } |
| | | |
| | | |
| | | public override bool AllAxisOn() |
| | | { |
| | |
| | | ResponseMessage responseMessage = new ResponseMessage(); |
| | | if (opConfig is MotionOperationCollection gtsOperationCollection) |
| | | { |
| | | //List<Task<bool>> taskList = new List<Task<bool>>(); |
| | | //foreach (var movingOp in gtsOperationCollection.MovingOps) |
| | | //{ |
| | | // var task = SingleAxisMoving(movingOp); |
| | | // taskList.Add(task); |
| | | // task.Start(); |
| | | //} |
| | | //Task.WaitAll(taskList.ToArray()); |
| | | //responseMessage.Result = taskList.All(u => u.GetAwaiter().GetResult()); |
| | | |
| | | List<bool> resultList = new List<bool>(); |
| | | Parallel.ForEach(gtsOperationCollection.MovingOps, movingOp => |
| | | { |
| | | axisImmediatePauseFlag[movingOp.AxisIndex] = false; |
| | | axisPauseResumeFlag[movingOp.AxisIndex] = true; |
| | | resultList.Add(SingleAxisMoving(movingOp).Result); |
| | | }); |
| | | responseMessage.Result = resultList.All(u => u == true); |
| | | if (!responseMessage.Result) |
| | | { |
| | | responseMessage.Message = $"点位运动异常"; |
| | | responseMessage.Message = $"点位运动异常,运动结果:{string.Join(" ", resultList.Select(u => u ? "1" : "0"))}"; |
| | | } |
| | | } |
| | | return responseMessage; |
| | |
| | | /// <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) |
| | | { |
| | |
| | | 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); |
| | |
| | | public override Task<bool> SingleAxisMoving(MovingOption optionPara) |
| | | { |
| | | return Task.Run(() => |
| | | { |
| | | axisImmediatePauseHandleDict[optionPara.AxisIndex].WaitOne(); |
| | | bool isSuccessAndStop = false; |
| | | try |
| | | { |
| | | if (IConfig.AxisSettings.FirstOrDefault(a => a.AxisIndex == optionPara.AxisIndex)?.IsAxisEnabled ?? false) |
| | | { |
| | | // string _position = ""; |
| | | string motionType = optionPara.MoveMode == EnumHelper.MotionMode.Normal ? (optionPara.IsAbsolute ? "Abs" : "Rel") : optionPara.MoveMode.ToString(); |
| | | { |
| | | bool isSuccessAndStop = false; |
| | | do |
| | | { |
| | | axisImmediatePauseHandleDict[optionPara.AxisIndex].WaitOne(); |
| | | |
| | | // _position = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff},{optionPara.AxisIndex},{motionType},{GetPosition(optionPara.AxisIndex)},{GetPrfPosition(optionPara.AxisIndex)},{optionPara.Destination},"; |
| | | if (axisPauseResumeFlag.ContainsKey(optionPara.AxisIndex) && !axisPauseResumeFlag[optionPara.AxisIndex]) |
| | | return true; |
| | | |
| | | switch (optionPara.MoveMode) |
| | | { |
| | | case MotionMode.Normal: |
| | | { |
| | | if (_isResetting) |
| | | { |
| | | LogAsync(DateTime.Now, "复位中启动运动异常", optionPara.AxisIndex + "启动运动异常"); |
| | | return false; |
| | | } |
| | | try |
| | | { |
| | | if (IConfig.AxisSettings.FirstOrDefault(a => a.AxisIndex == optionPara.AxisIndex)?.IsAxisEnabled ?? false) |
| | | { |
| | | string motionType = optionPara.MoveMode == EnumHelper.MotionMode.Normal ? (optionPara.IsAbsolute ? "Abs" : "Rel") : optionPara.MoveMode.ToString(); |
| | | |
| | | if (optionPara.IsAbsolute) |
| | | { |
| | | isSuccessAndStop = P2PMoveAbs(optionPara); |
| | | } |
| | | else |
| | | { |
| | | isSuccessAndStop = P2PMoveRel(optionPara); |
| | | } |
| | | switch (optionPara.MoveMode) |
| | | { |
| | | case MotionMode.Normal: |
| | | { |
| | | if (_isResetting) |
| | | { |
| | | LogAsync(DateTime.Now, "复位中启动运动异常", optionPara.AxisIndex + "启动运动异常"); |
| | | return false; |
| | | } |
| | | |
| | | } |
| | | break; |
| | | case MotionMode.FindOri: |
| | | { |
| | | //isSuccessAndStop = GoHome(optionPara); |
| | | isSuccessAndStop = P2PGoHome(optionPara); |
| | | } |
| | | break; |
| | | case MotionMode.Jog: |
| | | { |
| | | isSuccessAndStop = JogMove(optionPara); |
| | | } |
| | | break; |
| | | } |
| | | //_position += $"{GetPosition(optionPara.AxisIndex)},"; |
| | | //_position += $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}"; |
| | | //LogAsync(DateTime.Now, "", _position); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | isSuccessAndStop = false; |
| | | LogAsync(DateTime.Now, $"轴{optionPara.AxisIndex}运动异常", ex.GetExceptionMessage()); |
| | | } |
| | | return isSuccessAndStop; |
| | | }); |
| | | if (optionPara.IsAbsolute) |
| | | { |
| | | isSuccessAndStop = P2PMoveAbs(optionPara); |
| | | } |
| | | //else |
| | | //{ |
| | | // isSuccessAndStop = P2PMoveRel(optionPara); |
| | | //} |
| | | |
| | | } |
| | | break; |
| | | case MotionMode.FindOri: |
| | | { |
| | | //isSuccessAndStop = GoHome(optionPara); |
| | | isSuccessAndStop = P2PGoHome(optionPara); |
| | | } |
| | | break; |
| | | case MotionMode.Jog: |
| | | { |
| | | isSuccessAndStop = JogMove(optionPara); |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | isSuccessAndStop = false; |
| | | LogAsync(DateTime.Now, $"轴{optionPara.AxisIndex}运动异常", ex.GetExceptionMessage()); |
| | | } |
| | | } while (axisImmediatePauseFlag.ContainsKey(optionPara.AxisIndex) && axisImmediatePauseFlag[optionPara.AxisIndex]); |
| | | return isSuccessAndStop; |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// <returns></returns> |
| | | public double GetPosition(int axisNum) |
| | | { |
| | | lock (moveLock) |
| | | //lock (moveLock) |
| | | { |
| | | double position = 0; |
| | | double pPos = 0; |
| | |
| | | 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); |
| | |
| | | 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; |
| | |
| | | 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) |
| | | { |
| | |
| | | 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) |
| | |
| | | { |
| | | try |
| | | { |
| | | StartCapture: |
| | | Thread.CurrentThread.Priority = ThreadPriority.AboveNormal; |
| | | |
| | | PositionReset(movingOption.AxisIndex, 1); |
| | | ClearStatus(movingOption.AxisIndex, 1); |
| | | var goHomePara = IConfig.AxisSettings.FirstOrDefault(u => u.AxisIndex == movingOption.AxisIndex).GoHomePara; |
| | | bool homeDirection = goHomePara.IsHomeDirPositive; |
| | | bool isRightLimitReached = false; |
| | | short capture = 0; |
| | | |
| | | GTSCardAPI.TTrapPrm trapPrm; |
| | | bool isStop = false; |
| | | //搜索距离 阶段1 |
| | | // 启动Home捕获 |
| | | short sRtn = GTSCardAPI.GT_SetCaptureMode((short)IConfig.CardNum, (short)movingOption.AxisIndex, GTSCardAPI.CAPTURE_HOME); |
| | | |
| | | // 切换到点位运动模式 |
| | | sRtn = GTSCardAPI.GT_PrfTrap((short)IConfig.CardNum, (short)movingOption.AxisIndex); |
| | | short sRtn = GTSCardAPI.GT_PrfTrap((short)IConfig.CardNum, (short)movingOption.AxisIndex); |
| | | // 读取点位模式运动参数 |
| | | sRtn = GTSCardAPI.GT_GetTrapPrm((short)IConfig.CardNum, (short)movingOption.AxisIndex, out trapPrm); |
| | | trapPrm.acc = movingOption.VelocityPara.Acc; |
| | |
| | | // 设置点位模式运动参数 |
| | | 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.HomeVelocity); |
| | | |
| | | // 设置点位模式目标位置,即原点搜索距离 |
| | | sRtn = GTSCardAPI.GT_SetPos((short)IConfig.CardNum, (short)movingOption.AxisIndex, movingOption.GoHomePara.HomeDir == 1 ? 99999999 : -99999999); |
| | | // 启动运动 |
| | | sRtn = GTSCardAPI.GT_Update((short)IConfig.CardNum, 1 << (movingOption.AxisIndex - 1)); |
| | | |
| | | int repeatTime = 1000; |
| | | short capture; |
| | | int pos; |
| | | uint clk;//时钟参数 |
| | | do |
| | | { |
| | | Thread.Sleep(20); |
| | | // 读取捕获状态 |
| | | GTSCardAPI.GT_GetCaptureStatus((short)IConfig.CardNum, (short)movingOption.AxisIndex, out capture, out pos, 1, out clk); |
| | | isStop = IsStop((short)movingOption.AxisIndex); |
| | | repeatTime--; |
| | | } while (!(isStop || capture == 1 || repeatTime <= 0)); |
| | | PositionReset(movingOption.AxisIndex, 1); |
| | | ClearStatus(movingOption.AxisIndex, 1); |
| | | |
| | | if (repeatTime <= 0) |
| | | { |
| | | MoveStop((short)movingOption.AxisIndex, 0); |
| | | throw new ProcessException($"运动轴{movingOption.AxisIndex} ,回原点超时异常"); |
| | | } |
| | | //LogAsync(DateTime.Now, $"{Name}位置置零", ""); |
| | | |
| | | if (isStop && capture != 1) |
| | | { |
| | | ClearStatus((short)movingOption.AxisIndex, 1); |
| | | if (goHomePara.IsCaptureMode) |
| | | { |
| | | //搜索距离 阶段1 |
| | | // 启动Home捕获 |
| | | sRtn = GTSCardAPI.GT_SetCaptureMode((short)IConfig.CardNum, (short)movingOption.AxisIndex, GTSCardAPI.CAPTURE_HOME); |
| | | } |
| | | |
| | | // 设置点位模式目标位置,即原点搜索距离 |
| | | sRtn = GTSCardAPI.GT_SetPos((short)IConfig.CardNum, (short)movingOption.AxisIndex, homeDirection ? 999999999 : -999999999); |
| | | // 启动运动 |
| | | sRtn = GTSCardAPI.GT_Update((short)IConfig.CardNum, 1 << (movingOption.AxisIndex - 1)); |
| | | |
| | | int repeatTime = goHomePara.GoHomeTimeOut * 1000; |
| | | |
| | | bool isStop = false; |
| | | int pos = 0; |
| | | uint clk;//时钟参数 |
| | | |
| | | int checkInterval = IConfig.MonitorInterval; |
| | | if (IConfig.MonitorInterval <= 0) |
| | | { |
| | | checkInterval = 10; |
| | | } |
| | | |
| | | do |
| | | { |
| | | Thread.Sleep(checkInterval); |
| | | |
| | | if (goHomePara.IsCaptureMode) |
| | | { |
| | | // 读取捕获状态 |
| | | GTSCardAPI.GT_GetCaptureStatus((short)IConfig.CardNum, (short)movingOption.AxisIndex, out capture, out pos, 1, out clk); |
| | | } |
| | | 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; |
| | | } while (!(isStop || capture == 1 || repeatTime <= 0)); |
| | | |
| | | if (repeatTime <= 0) |
| | | { |
| | | MoveStop((short)movingOption.AxisIndex, 0); |
| | | throw new ProcessException($"运动轴{movingOption.AxisIndex} ,回原点超时异常"); |
| | | } |
| | | |
| | | var axisStatus = AxisStatusList.FirstOrDefault(u => u.AxisIndex == movingOption.AxisIndex); |
| | | |
| | | if (((axisStatus.AxisStatus & 0x20) != 0) || ((axisStatus.AxisStatus & 0x40) != 0)) |
| | | //if (isStop) |
| | | //{ |
| | | // LogAsync(DateTime.Now, $"轴{movingOption.AxisIndex}复位中停止", $"Capture状态{capture}"); |
| | | //} |
| | | |
| | | if (isStop && capture != 1) |
| | | { |
| | | movingOption.GoHomePara.HomeDir = (short)(movingOption.GoHomePara.HomeDir == 1 ? -1 : 1); |
| | | goto StartCapture; |
| | | if (((axisStatus.AxisStatus & 0x20) != 0) || ((axisStatus.AxisStatus & 0x40) != 0)) |
| | | { |
| | | capture = 0; |
| | | |
| | | //正限位 |
| | | if ((axisStatus.AxisStatus & 0x20) != 0 && !goHomePara.IsCaptureDirPositive) |
| | | { |
| | | isRightLimitReached = true; |
| | | } |
| | | |
| | | //负限位 |
| | | if ((axisStatus.AxisStatus & 0x40) != 0 && goHomePara.IsCaptureDirPositive) |
| | | { |
| | | isRightLimitReached = true; |
| | | } |
| | | |
| | | homeDirection = !homeDirection; |
| | | |
| | | LogAsync(DateTime.Now, $"轴{movingOption.AxisIndex}极限位置换向", ""); |
| | | } |
| | | |
| | | ClearStatus(movingOption.AxisIndex, 1); |
| | | } |
| | | |
| | | throw new ProcessException($"运动轴{movingOption.AxisIndex} ,回原点超时异常"); |
| | | } |
| | | |
| | | if (capture == 1) |
| | | { |
| | | //先stop |
| | | MoveStop((short)movingOption.AxisIndex, 0); |
| | | ClearStatus((short)movingOption.AxisIndex, 1); |
| | | //已经捕获到Home才可以回零 阶段2 |
| | | // 运动到"捕获位置+偏移量" |
| | | sRtn = GTSCardAPI.GT_SetPos((short)IConfig.CardNum, (short)movingOption.AxisIndex, pos + movingOption.GoHomePara.HomeOffset); |
| | | // 在运动状态下更新目标位置 |
| | | sRtn = GTSCardAPI.GT_Update((short)IConfig.CardNum, 1 << (movingOption.AxisIndex - 1)); |
| | | isStop = false; |
| | | |
| | | repeatTime = 1000; |
| | | do |
| | | if (capture == 1) |
| | | { |
| | | Thread.Sleep(20); |
| | | isStop = IsStop((short)movingOption.AxisIndex); |
| | | repeatTime--; |
| | | } while (!isStop && repeatTime > 0); |
| | | PositionReset(movingOption.AxisIndex, 1); |
| | | return (sRtn == (short)GTSRetCode.GRCRunOK) && isStop; |
| | | } |
| | | if (!isRightLimitReached) |
| | | { |
| | | capture = 0; |
| | | ClearStatus(movingOption.AxisIndex, 1); |
| | | //GTSCardAPI.GT_SetCaptureMode((short)IConfig.CardNum, (short)movingOption.AxisIndex, GTSCardAPI.CAPTURE_HOME); |
| | | continue; |
| | | } |
| | | |
| | | //先stop |
| | | MoveStop((short)movingOption.AxisIndex, 0); |
| | | ClearStatus((short)movingOption.AxisIndex, 1); |
| | | |
| | | //已经捕获到Home才可以回零 阶段2 |
| | | // 运动到"捕获位置+偏移量" |
| | | 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; |
| | | |
| | | repeatTime = 1000; |
| | | do |
| | | { |
| | | Thread.Sleep(20); |
| | | isStop = IsStop((short)movingOption.AxisIndex); |
| | | 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 |
| | | { |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | /// <returns></returns> |
| | | public override int GetAxisStatus(int axisNum) |
| | | { |
| | | lock (moveLock) |
| | | //lock (moveLock) |
| | | { |
| | | int sts = 0; |
| | | uint pclock = 0; |
| | |
| | | /// <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; |
| | |
| | | |
| | | return axisMovingStatusesList; |
| | | } |
| | | |
| | | |
| | | public List<IOItem> GetMonitorValues() |
| | | { |
| | |
| | | return result; |
| | | } |
| | | |
| | | SpinWait _positionWait = new SpinWait(); |
| | | private async void MonitorPosition() |
| | | { |
| | | await Task.Run(() => |
| | | { |
| | | while (CurrentState != EnumHelper.DeviceState.DSClose && CurrentState != EnumHelper.DeviceState.DSExcept && CurrentState != EnumHelper.DeviceState.DSUninit) |
| | | { |
| | | try |
| | | { |
| | | if (!IConfig.IsEnableMonitor) |
| | | return; |
| | | |
| | | AxisStatusList.ForEach(a => |
| | | { |
| | | int curPosition = (int)GetPrfPosition(a.AxisIndex); |
| | | |
| | | if (a.CurPosition != curPosition) |
| | | { |
| | | a.CurPosition = curPosition; |
| | | AxisPositionChanged(a.AxisIndex, curPosition); |
| | | } |
| | | }); |
| | | |
| | | Task.Delay(100).Wait(); |
| | | |
| | | //_positionWait.SpinOnce(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | if (CurrentState == DeviceState.DSOpen) |
| | | { |
| | | LogAsync(DateTime.Now, $"{this.Name}监听轴信息异常", ex.GetExceptionMessage()); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | SpinWait _statusWait = new SpinWait(); |
| | | private async void MonitorAxisStatus() |
| | | { |
| | | await Task.Run(() => |
| | | { |
| | | while (CurrentState != EnumHelper.DeviceState.DSClose && CurrentState != EnumHelper.DeviceState.DSExcept && CurrentState != EnumHelper.DeviceState.DSUninit) |
| | | { |
| | | try |
| | | { |
| | | if (!IConfig.IsEnableMonitor) |
| | | return; |
| | | |
| | | AxisStatusList.ForEach(a => |
| | | { |
| | | int curStatus = GetAxisStatus(a.AxisIndex); |
| | | |
| | | if (a.AxisStatus != curStatus) |
| | | { |
| | | int temp = a.AxisStatus; |
| | | a.AxisStatus = curStatus; |
| | | AxisStatusChanged(a.AxisIndex, temp, curStatus); |
| | | } |
| | | }); |
| | | |
| | | Thread.Sleep(10); |
| | | //Task.Delay(10).Wait(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | if (CurrentState == DeviceState.DSOpen) |
| | | { |
| | | LogAsync(DateTime.Now, $"{this.Name}监听轴信息异常", ex.GetExceptionMessage()); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | public async override void Monitor() |
| | | { |
| | | await Task.Run(() => |
| | |
| | | return; |
| | | |
| | | var newValues = GetMonitorValues(); |
| | | var newAxisMovingStatus = GetAxisMovingStatus(); |
| | | //var newAxisMovingStatus = GetAxisMovingStatus(); |
| | | |
| | | if (newValues == null || newValues.Count == 0 || newAxisMovingStatus == null || newAxisMovingStatus.Count == 0) |
| | | if (newValues == null || newValues.Count == 0) |
| | | continue; |
| | | |
| | | //Stopwatch sw = new Stopwatch(); |
| | |
| | | MonitorCheckAndInvoke(tempNew, tempOld); |
| | | } |
| | | |
| | | if (AxisStatusList.Count == newAxisMovingStatus.Count) |
| | | { |
| | | var tempNew = new List<AxisMovingStatus>(newAxisMovingStatus);//clone |
| | | var tempOld = new List<AxisMovingStatus>(AxisStatusList); |
| | | AxisStatusCheck(tempNew, tempOld); |
| | | } |
| | | //if (AxisStatusList.Count == newAxisMovingStatus.Count) |
| | | //{ |
| | | // var tempNew = new List<AxisMovingStatus>(newAxisMovingStatus);//clone |
| | | // var tempOld = new List<AxisMovingStatus>(AxisStatusList); |
| | | // AxisStatusCheck(tempNew, tempOld); |
| | | //} |
| | | |
| | | AxisStatusList = new List<AxisMovingStatus>(newAxisMovingStatus); |
| | | //AxisStatusList = new List<AxisMovingStatus>(newAxisMovingStatus); |
| | | MonitorValues = new List<IOItem>(newValues); |
| | | //sw.Stop(); |
| | | |
| | |
| | | int axis_sts; |
| | | var axisSettings = IConfig.AxisSettings.FindAll(u => u.IsAxisEnabled); |
| | | ClearStatus(1, axisSettings.Count); |
| | | |
| | | if (AxisStatusList.Count == 0) |
| | | { |
| | | Thread.Sleep(10); |
| | | } |
| | | |
| | | foreach (var axisSetting in axisSettings) |
| | | { |
| | | //axis_sts = GetAxisStatus((short)axisSetting.AxisIndex); |
| | | axis_sts = AxisStatusList.FirstOrDefault(u => u.AxisIndex == axisSetting.AxisIndex).AxisStatus; |
| | | axis_sts = AxisStatusList.FirstOrDefault(u => u.AxisIndex == axisSetting.AxisIndex)?.AxisStatus ?? 0; |
| | | if ((axis_sts & 0x200) == 0) |
| | | { |
| | | var rst = GTSCardAPI.GT_AxisOn((short)IConfig.CardNum, (short)axisSetting.AxisIndex); |