| | |
| | | /// </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; |
| | | if (config is MotionCardOperationConfigBase motionCardOperationConfig) |
| | | { |
| | | _pauseHandle.WaitOne(); |
| | | foreach (var operationSet in motionCardOperationConfig.OperationCollection) |
| | | { |
| | | 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; |
| | | if (opConfig is MotionOperationCollection gtsOperationCollection) |
| | | { |
| | | _pauseHandle.WaitOne(); |
| | | List<Task<bool>> taskList = new List<Task<bool>>(); |
| | | foreach (var movingOp in gtsOperationCollection.MovingOps) |
| | | { |
| | |
| | | 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(); |
| | | |
| | |
| | | { |
| | | try |
| | | { |
| | | axisImmediatePauseHandleDict[optionPara.AxisIndex].WaitOne(); |
| | | |
| | | if (_isResetting) |
| | | { |
| | | LogAsync(DateTime.Now, "复位过程异常", "轴" + optionPara.AxisIndex + "试图在复位过程中运动"); |