| | |
| | | bool _isResetting = false; |
| | | |
| | | /// <summary> |
| | | /// 是否暂停中 |
| | | /// </summary> |
| | | bool _isPause = false; |
| | | |
| | | /// <summary> |
| | | /// 运动轴立即暂停 |
| | | /// </summary> |
| | | Dictionary<int, ManualResetEvent> axisImmediatePauseHandleDict = new Dictionary<int, ManualResetEvent>(); |
| | | |
| | | Dictionary<int, CancellationTokenSource> axisMoveCancelDict = new Dictionary<int, CancellationTokenSource>(); |
| | | //Dictionary<int, CancellationTokenSource> axisMoveCancelDict = new Dictionary<int, CancellationTokenSource>(); |
| | | |
| | | public void SetResetFlag(bool isReset) |
| | | { |
| | |
| | | { |
| | | InitialMotionCard(); |
| | | axisImmediatePauseHandleDict = IConfig.AxisSettings.FindAll(a => a.IsAxisEnabled).ToDictionary(a => a.AxisIndex, a => new ManualResetEvent(true)); |
| | | axisMoveCancelDict = IConfig.AxisSettings.FindAll(a => a.IsAxisEnabled).ToDictionary(a => a.AxisIndex, a => new CancellationTokenSource()); |
| | | //axisMoveCancelDict = IConfig.AxisSettings.FindAll(a => a.IsAxisEnabled).ToDictionary(a => a.AxisIndex, a => new CancellationTokenSource()); |
| | | |
| | | axisMoveCancelDict.Values.ToList().ForEach(c => |
| | | { |
| | | c = new CancellationTokenSource(); |
| | | }); |
| | | //axisMoveCancelDict.Values.ToList().ForEach(c => |
| | | //{ |
| | | // c = new CancellationTokenSource(); |
| | | //}); |
| | | } |
| | | |
| | | protected override void Pause() |
| | |
| | | { |
| | | axisImmediatePauseHandleDict[axisIndex].Reset(); |
| | | |
| | | axisMoveCancelDict[axisIndex].Cancel(); |
| | | //axisMoveCancelDict[axisIndex].Cancel(); |
| | | |
| | | await MoveStop(axisIndex, 0); |
| | | await MoveStop(axisIndex, 0);//所有轴都暂停 |
| | | }); |
| | | } |
| | | } |
| | |
| | | |
| | | immediatePauseAxis.ForEach(axisIndex => |
| | | { |
| | | axisMoveCancelDict[axisIndex] = new CancellationTokenSource(); |
| | | //axisMoveCancelDict[axisIndex] = new CancellationTokenSource(); |
| | | |
| | | axisImmediatePauseHandleDict[axisIndex].Set(); |
| | | }); |
| | |
| | | public override async Task<bool> SingleAxisMoving(MovingOption optionPara) |
| | | { |
| | | return await Task.Run(() => |
| | | { |
| | | { |
| | | axisImmediatePauseHandleDict[optionPara.AxisIndex].WaitOne(); |
| | | bool isSuccessAndStop = false; |
| | | try |
| | | { |
| | | 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(); |
| | | |
| | |
| | | short ret = 0; |
| | | bool isSuccessSetAxisParam = false; |
| | | int timeout = optionPara.MovingTimeout; |
| | | while (CurrentState == DeviceState.DSOpen) |
| | | while (CurrentState == DeviceState.DSOpen&&!_isPause) |
| | | { |
| | | //设置 运动参数 |
| | | isSuccessSetAxisParam = SetAxisParam(optionPara); |
| | |
| | | |
| | | bool isStop = false; |
| | | repeatTime = 1000; |
| | | do |
| | | while (!isStop && repeatTime > 0) |
| | | { |
| | | isStop = IsStop((short)optionPara.AxisIndex); |
| | | Thread.Sleep(50); |
| | | repeatTime--; |
| | | } while (!isStop && repeatTime > 0); |
| | | } |
| | | |
| | | return (ret == (short)GTSRetCode.GRCRunOK) && isStop; |
| | | } |
| | |
| | | { |
| | | try |
| | | { |
| | | GTSCardAPI.GT_ZeroPos((short)IConfig.CardNum, (short)movingOption.AxisIndex, 1); |
| | | PositionReset(movingOption.AxisIndex, 1); |
| | | GTSCardAPI.THomePrm thomeprm; |
| | | GTSCardAPI.THomeStatus homests; |
| | | short rtn = GTSCardAPI.GT_GetHomePrm((short)IConfig.CardNum, (short)movingOption.AxisIndex, out thomeprm); |
| | |
| | | if (isStop && homests.error == 0) |
| | | { |
| | | Thread.Sleep(200); |
| | | GTSCardAPI.GT_ZeroPos((short)IConfig.CardNum, (short)movingOption.AxisIndex, 1); |
| | | PositionReset(movingOption.AxisIndex, 1); |
| | | } |
| | | repeatTime--; |
| | | } while (!isStop && repeatTime > 0); |
| | |
| | | return rtn == (short)GTSRetCode.GRCRunOK; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 位置回零 |
| | | /// </summary> |
| | | /// <param name="startAxisIndex"></param> |
| | | /// <param name="count"></param> |
| | | /// <returns></returns> |
| | | public override bool PositionReset(int startAxisIndex, int count) |
| | | { |
| | | var rtn = GTSCardAPI.GT_ZeroPos((short)IConfig.CardNum, (short)startAxisIndex, (short)count); |
| | | return rtn == (short)GTSRetCode.GRCRunOK; |
| | | lock (moveLock) |
| | | { |
| | | var rtn = GTSCardAPI.GT_ZeroPos((short)IConfig.CardNum, (short)startAxisIndex, (short)count); |
| | | return rtn == (short)GTSRetCode.GRCRunOK; |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | |
| | | { |
| | | var rst = GTSCardAPI.GT_AxisOn((short)IConfig.CardNum, (short)axisSetting.AxisIndex); |
| | | } |
| | | // 位置请零 |
| | | GTSCardAPI.GT_ZeroPos((short)IConfig.CardNum, 1, (short)axisSettings.Count); |
| | | // 所有位置请零 |
| | | PositionReset(1, axisSettings.Count); |
| | | // 正极限报警 |
| | | if ((axis_sts & 0x20) != 0) |
| | | { |