| | |
| | | /// </summary> |
| | | bool _isResetting = false; |
| | | |
| | | /// <summary> |
| | | /// 运动轴立即暂停 |
| | | /// </summary> |
| | | Dictionary<int, ManualResetEvent> axisImmediatePauseHandleDict = new Dictionary<int, ManualResetEvent>(); |
| | | |
| | | Dictionary<int, CancellationTokenSource> axisMoveCancelDict = new Dictionary<int, CancellationTokenSource>(); |
| | | |
| | | public void SetResetFlag(bool isReset) |
| | | { |
| | | _isResetting = isReset; |
| | |
| | | protected override void Init() |
| | | { |
| | | InitialMotionCard(); |
| | | axisImmediatePauseHandleDict = IConfig.AxisSettings.ToDictionary(a => a.AxisIndex, a => new ManualResetEvent(true)); |
| | | axisMoveCancelDict = IConfig.AxisSettings.ToDictionary(a => a.AxisIndex, a => new CancellationTokenSource()); |
| | | |
| | | axisMoveCancelDict.Values.ToList().ForEach(c => |
| | | { |
| | | c = new CancellationTokenSource(); |
| | | }); |
| | | } |
| | | |
| | | ManualResetEvent _pauseHandle = new ManualResetEvent(true); |
| | | protected override void Pause() |
| | | { |
| | | throw new NotImplementedException(); |
| | | |
| | | } |
| | | |
| | | protected override void Resume() |
| | | { |
| | | throw new NotImplementedException(); |
| | | |
| | | } |
| | | |
| | | protected override void Start() |
| | |
| | | public override ResponseMessage Run(IOperationConfig config) |
| | | { |
| | | ResponseMessage responseMessage = new ResponseMessage(); |
| | | var motionCardOperationConfig = config as MotionCardOperationConfigBase; |
| | | foreach (var operationSet in motionCardOperationConfig.OperationCollection) |
| | | if (config is MotionCardOperationConfigBase motionCardOperationConfig) |
| | | { |
| | | responseMessage = RunOperationSet(operationSet); |
| | | if (!responseMessage.Result) |
| | | _pauseHandle.WaitOne(); |
| | | foreach (var operationSet in motionCardOperationConfig.OperationCollection) |
| | | { |
| | | return responseMessage; |
| | | responseMessage = RunOperationSet(operationSet); |
| | | if (!responseMessage.Result) |
| | | { |
| | | return responseMessage; |
| | | } |
| | | } |
| | | } |
| | | return responseMessage; |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region ImmediatePause |
| | | /// <summary> |
| | | /// 启动立即暂停 |
| | | /// </summary> |
| | | public void SetImmediatePause() |
| | | { |
| | | if (!_isResetting) |
| | | { |
| | | var immediatePauseAxis = IConfig.AxisSettings.Where(u => u.IsImmediatePause).Select(u => u.AxisIndex).ToList(); |
| | | |
| | | immediatePauseAxis.ForEach(async axisIndex => |
| | | { |
| | | axisImmediatePauseHandleDict[axisIndex].Reset(); |
| | | |
| | | axisMoveCancelDict[axisIndex].Cancel(); |
| | | |
| | | await MoveStop(axisIndex, 0); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 恢复立即暂停 |
| | | /// </summary> |
| | | public void ResetImmediatePause() |
| | | { |
| | | var immediatePauseAxis = IConfig.AxisSettings.Where(u => u.IsImmediatePause).Select(u => u.AxisIndex).ToList(); |
| | | |
| | | immediatePauseAxis.ForEach(axisIndex => |
| | | { |
| | | axisMoveCancelDict[axisIndex] = new CancellationTokenSource(); |
| | | |
| | | axisImmediatePauseHandleDict[axisIndex].Set(); |
| | | }); |
| | | } |
| | | #endregion |
| | | |
| | | #region GTSCard |
| | | |
| | | /// <summary> |
| | |
| | | public override ResponseMessage MoveToPoint(IOperationConfig opConfig) |
| | | { |
| | | ResponseMessage responseMessage = new ResponseMessage(); |
| | | var gtsOperationCollection = opConfig as MotionOperationCollection; |
| | | List<Task<bool>> taskList = new List<Task<bool>>(); |
| | | foreach (var movingOp in gtsOperationCollection.MovingOps) |
| | | if (opConfig is MotionOperationCollection gtsOperationCollection) |
| | | { |
| | | var task = SingleAxisMoving(movingOp); |
| | | taskList.Add(task); |
| | | } |
| | | _pauseHandle.WaitOne(); |
| | | List<Task<bool>> taskList = new List<Task<bool>>(); |
| | | foreach (var movingOp in gtsOperationCollection.MovingOps) |
| | | { |
| | | var task = SingleAxisMoving(movingOp); |
| | | taskList.Add(task); |
| | | } |
| | | |
| | | Task.WaitAll(taskList.ToArray()); |
| | | responseMessage.Result = taskList.All(u => u.GetAwaiter().GetResult()); |
| | | if (!responseMessage.Result) |
| | | { |
| | | responseMessage.Message = $"点位运动异常"; |
| | | Task.WaitAll(taskList.ToArray()); |
| | | responseMessage.Result = taskList.All(u => u.GetAwaiter().GetResult()); |
| | | if (!responseMessage.Result) |
| | | { |
| | | responseMessage.Message = $"点位运动异常"; |
| | | } |
| | | } |
| | | return responseMessage; |
| | | } |
| | |
| | | { |
| | | if (IConfig.AxisSettings.FirstOrDefault(a => a.AxisIndex == optionPara.AxisIndex)?.IsAxisEnabled ?? false) |
| | | { |
| | | axisImmediatePauseHandleDict[optionPara.AxisIndex].WaitOne(); |
| | | |
| | | string _position = ""; |
| | | string motionType = optionPara.MoveMode == EnumHelper.MotionMode.Normal ? (optionPara.IsAbsolute ? "Abs" : "Rel") : optionPara.MoveMode.ToString(); |
| | | |
| | |
| | | |
| | | if (ret != (short)GTSRetCode.GRCRunOK) |
| | | { |
| | | LogAsync(DateTime.Now, "轴" + optionPara.AxisIndex + "APS_absolute_move异常", "错误码:" + ret + ";" + "重试次数:" + repeatTime); |
| | | LogAsync(DateTime.Now, "轴" + optionPara.AxisIndex + "JogMove异常", "错误码:" + ret + ";" + "重试次数:" + repeatTime); |
| | | Thread.Sleep(10); |
| | | } |
| | | repeatTime--; |
| | |
| | | repeatTime = 1000; |
| | | do |
| | | { |
| | | isStop = IsStop((short)IConfig.CardNum, (short)optionPara.AxisIndex); |
| | | isStop = IsStop((short)optionPara.AxisIndex); |
| | | Thread.Sleep(50); |
| | | repeatTime--; |
| | | } while (!isStop && repeatTime > 0); |
| | |
| | | { |
| | | try |
| | | { |
| | | axisImmediatePauseHandleDict[optionPara.AxisIndex].WaitOne(); |
| | | |
| | | if (_isResetting) |
| | | { |
| | | LogAsync(DateTime.Now, "复位过程异常", "轴" + optionPara.AxisIndex + "试图在复位过程中运动"); |
| | |
| | | repeatTime = 1000; |
| | | do |
| | | { |
| | | isStop = IsStop((short)IConfig.CardNum, (short)optionPara.AxisIndex); |
| | | isStop = IsStop((short)optionPara.AxisIndex); |
| | | Thread.Sleep(50); |
| | | repeatTime--; |
| | | } while (!isStop && repeatTime > 0); |
| | |
| | | int repeatTime = 100; |
| | | do |
| | | { |
| | | isStop = IsStop((short)IConfig.CardNum, (short)axisNum); |
| | | isStop = IsStop((short)axisNum); |
| | | Thread.Sleep(10); |
| | | repeatTime--; |
| | | } while (!isStop && repeatTime > 0); |
| | |
| | | /// <param name="cardNum">板卡号</param> |
| | | /// <param name="axisNum">轴号</param> |
| | | /// <returns></returns> |
| | | public bool IsStop(short cardNum, short axisNum) |
| | | public bool IsStop(short axisNum) |
| | | { |
| | | int sts = GetAxisStatus(axisNum); |
| | | if ((sts & 0x400) == 0) return true;//停止返回true |
| | | else return false; //运行中返回false |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 读取轴状态 |
| | | /// </summary> |
| | | /// <param name="cardNum">板卡号</param> |
| | | /// <param name="axisNum">轴号</param> |
| | | /// <returns></returns> |
| | | public int GetAxisStatus(int axisNum) |
| | | { |
| | | lock (moveLock) |
| | | { |
| | | int sts = 0; |
| | | uint pclock = 0; |
| | | GTSCardAPI.GT_GetSts(cardNum, axisNum, out sts, 1, out pclock); |
| | | if ((sts & 0x400) == 0) return true;//停止返回true |
| | | else return false; //运行中返回false |
| | | GTSCardAPI.GT_GetSts((short)IConfig.CardNum, (short)axisNum, out sts, 1, out pclock); |
| | | return sts; |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region IMonitor |
| | |
| | | axisMovingStatus.Destination = Convert.ToInt32(GetPrfPosition(axisMovingStatus.AxisIndex)); |
| | | axisMovingStatus.CurVelocity = GetVelocity(axisMovingStatus.AxisIndex); |
| | | axisMovingStatus.PrfVelocity = GetPrfVelocity(axisMovingStatus.AxisIndex); |
| | | axisMovingStatus.AxisStatus = GetAxisStatus(axisMovingStatus.AxisIndex); |
| | | |
| | | axisMovingStatusesList.Add(axisMovingStatus); |
| | | |
| | | } |
| | |
| | | public override void ResetAlarm() |
| | | { |
| | | int axis_sts; |
| | | uint clk; |
| | | var axisSettings = IConfig.AxisSettings.FindAll(u => u.IsAxisEnabled); |
| | | GTSCardAPI.GT_ClrSts((short)IConfig.CardNum, 1, (short)axisSettings.Count); |
| | | foreach (var axisSetting in axisSettings) |
| | | { |
| | | GTSCardAPI.GT_GetSts((short)IConfig.CardNum, (short)axisSetting.AxisIndex, out axis_sts, 1, out clk); |
| | | axis_sts = GetAxisStatus((short)axisSetting.AxisIndex); |
| | | if ((axis_sts & 0x200) == 0) |
| | | { |
| | | var rst = GTSCardAPI.GT_AxisOn((short)IConfig.CardNum, (short)axisSetting.AxisIndex); |