| | |
| | | /// 运动轴立即暂停 |
| | | /// </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>(); |
| | | |
| | |
| | | { |
| | | foreach (var preCheck in operationSet.PreCheckIOCollection) |
| | | { |
| | | int timeout = operationSet.PreCheckIOTimeout; |
| | | _pauseHandle.Wait(); |
| | | |
| | | IOValue? ioData = null; |
| | | if (CurrentState == DeviceState.DSOpen) |
| | | { |
| | | int timeout = operationSet.PreCheckIOTimeout; |
| | | |
| | | while (CurrentState == DeviceState.DSOpen) |
| | | { |
| | | Thread.Sleep(10); |
| | |
| | | if (preCheck.CheckValue == ioData || (operationSet.PreCheckIOTimeout > 0 && timeout < 0)) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | // 2.板卡运动 |
| | | if (CurrentState == DeviceState.DSOpen) |
| | | { |
| | | _pauseHandle.Wait(); |
| | | |
| | | if (CurrentState == DeviceState.DSOpen) |
| | | { |
| | | responseMessage = MoveToPoint(new MotionOperationCollection() { MovingOps = operationSet.MovingOps }); |
| | | if (!responseMessage.Result) |
| | | { |
| | | return responseMessage; |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | // 3.IO输出 不需要超时 |
| | | if (CurrentState == DeviceState.DSOpen) |
| | | { |
| | | |
| | | foreach (var ioOutput in operationSet.IOOutputCollection) |
| | | { |
| | | _pauseHandle.Wait(); |
| | | |
| | | if (CurrentState == DeviceState.DSOpen) |
| | | { |
| | | WriteOutput((short)ioOutput.IOItem.IONum, ioOutput.CheckValue); |
| | | |
| | |
| | | // 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 |
| | |
| | | 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); |
| | |
| | | { |
| | | return Task.Run(() => |
| | | { |
| | | axisImmediatePauseHandleDict[optionPara.AxisIndex].WaitOne(); |
| | | bool isSuccessAndStop = false; |
| | | do |
| | | { |
| | | axisImmediatePauseHandleDict[optionPara.AxisIndex].WaitOne(); |
| | | |
| | | if (!axisPauseResumeFlag[optionPara.AxisIndex]) |
| | | return true; |
| | | |
| | | 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(); |
| | | |
| | | // _position = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff},{optionPara.AxisIndex},{motionType},{GetPosition(optionPara.AxisIndex)},{GetPrfPosition(optionPara.AxisIndex)},{optionPara.Destination},"; |
| | | |
| | | switch (optionPara.MoveMode) |
| | | { |
| | |
| | | { |
| | | isSuccessAndStop = P2PMoveAbs(optionPara); |
| | | } |
| | | else |
| | | { |
| | | isSuccessAndStop = P2PMoveRel(optionPara); |
| | | } |
| | | //else |
| | | //{ |
| | | // isSuccessAndStop = P2PMoveRel(optionPara); |
| | | //} |
| | | |
| | | } |
| | | break; |
| | |
| | | } |
| | | 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()); |
| | | } |
| | | } while (axisImmediatePauseFlag[optionPara.AxisIndex]); |
| | | return isSuccessAndStop; |
| | | }); |
| | | } |
| | |
| | | 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); |