| | |
| | | } |
| | | } |
| | | |
| | | static Dictionary<int, object> axisMoveLockDict = new Dictionary<int, object>(); |
| | | |
| | | /// <summary> |
| | | /// 轴运动开始时的检测,true:有冲突 不可继续执行 false:无冲突,可继续执行 |
| | | /// </summary> |
| | | public event OnAxisStartToCheckDelegate OnAxisStartToCheckConfliction; |
| | | /// <summary> |
| | | /// 暂停(线程同步事件) |
| | | /// </summary> |
| | | Dictionary<int, ManualResetEvent> axisImmediatePauseHandleDict = new Dictionary<int, ManualResetEvent>(); |
| | | Dictionary<int, CancellationTokenSource> axisMoveCancelDict = new Dictionary<int, CancellationTokenSource>(); |
| | | /// <summary> |
| | | /// 运行过程中的线程等待 |
| | | /// </summary> |
| | | private Dictionary<int, ManualResetEvent> runningEventDic = new Dictionary<int, ManualResetEvent>(); |
| | | private Dictionary<int, AutoResetEvent> axisMovingHandleDict = new Dictionary<int, AutoResetEvent>(); |
| | | private ConcurrentDictionary<int, int> axisDestination = new ConcurrentDictionary<int, int>(); |
| | | |
| | | private ObservableCollection<int> _commandAxisList = new ObservableCollection<int>(); |
| | | public Action<bool> CommandAxisCountChangedAction = null; |
| | | private Dictionary<int, VelocityPara> velIndexDict = new Dictionary<int, VelocityPara>(); |
| | | ManualResetEvent _pauseHandle = new ManualResetEvent(true); |
| | | |
| | | static object moveLock = new object(); |
| | | /// <summary> |
| | | /// 是否复位标志 |
| | |
| | | { |
| | | InitialMotionCard(); |
| | | } |
| | | |
| | | |
| | | protected override void Pause() |
| | | { |
| | |
| | | { |
| | | bool resultOK = false; |
| | | var gtsOperationConfig = opConfig as GTSCardOperationConfig; |
| | | List<Task<bool>> taskList = new List<Task<bool>>(); |
| | | //TaskFactory factory = new TaskFactory(TaskCreationOptions.LongRunning, TaskContinuationOptions.None); |
| | | // 如果是多个轴的运动 等每个轴运动结束 |
| | | foreach (var movingOp in gtsOperationConfig.MovingOps) |
| | | { |
| | | resultOK = SingleAxisMoving(movingOp); |
| | | //var task = factory.StartNew<bool>((op) => |
| | | //{ |
| | | // return SingleAxisMoving(op as MovingOption); |
| | | //}, movingOp); |
| | | var task = SingleAxisMoving(movingOp); |
| | | taskList.Add(task); |
| | | } |
| | | Task.WaitAll(taskList.ToArray()); |
| | | resultOK = taskList.All(u => u.GetAwaiter().GetResult()); |
| | | |
| | | return resultOK; |
| | | } |
| | | |
| | |
| | | /// 单个轴 点位到点位运动 |
| | | /// </summary> |
| | | /// <param name="optionPara">运动参数对象</param> |
| | | public bool SingleAxisMoving(MovingOption optionPara) |
| | | public async Task<bool> SingleAxisMoving(MovingOption optionPara) |
| | | { |
| | | bool isSuccessAndStop = false; |
| | | if (IConfig.AxisSettings.FirstOrDefault(a => a.AxisIndex == optionPara.AxisIndex)?.IsAxisEnabled ?? false) |
| | | return await Task.Run(() => |
| | | { |
| | | string _position = ""; |
| | | string motionType = optionPara.MoveMode == EnumHelper.MotorMoveMode.Normal ? (optionPara.IsAbsolute ? "Abs" : "Rel") : optionPara.MoveMode.ToString(); |
| | | |
| | | _position = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")},{optionPara.AxisIndex},{motionType},{GetPosition(optionPara.AxisIndex).ToString()},{GetPrfPosition(optionPara.AxisIndex).ToString()},{optionPara.Destination},"; |
| | | |
| | | switch (optionPara.MoveMode) |
| | | bool isSuccessAndStop = false; |
| | | if (IConfig.AxisSettings.FirstOrDefault(a => a.AxisIndex == optionPara.AxisIndex)?.IsAxisEnabled ?? false) |
| | | { |
| | | case MotorMoveMode.Normal: |
| | | { |
| | | if (_isResetting) |
| | | string _position = ""; |
| | | string motionType = optionPara.MoveMode == EnumHelper.MotorMoveMode.Normal ? (optionPara.IsAbsolute ? "Abs" : "Rel") : optionPara.MoveMode.ToString(); |
| | | |
| | | _position = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")},{optionPara.AxisIndex},{motionType},{GetPosition(optionPara.AxisIndex).ToString()},{GetPrfPosition(optionPara.AxisIndex).ToString()},{optionPara.Destination},"; |
| | | |
| | | switch (optionPara.MoveMode) |
| | | { |
| | | case MotorMoveMode.Normal: |
| | | { |
| | | LogAsync(DateTime.Now, "复位中启动运动异常", optionPara.AxisIndex + "启动运动异常"); |
| | | return false; |
| | | } |
| | | //设置 运动参数 |
| | | var isSuccess = SetAxisParam(optionPara); |
| | | if (isSuccess) |
| | | { |
| | | if (optionPara.IsAbsolute) |
| | | if (_isResetting) |
| | | { |
| | | isSuccessAndStop = MoveAbs(optionPara); |
| | | LogAsync(DateTime.Now, "复位中启动运动异常", optionPara.AxisIndex + "启动运动异常"); |
| | | return false; |
| | | } |
| | | else |
| | | //设置 运动参数 |
| | | var isSuccess = SetAxisParam(optionPara); |
| | | if (isSuccess) |
| | | { |
| | | isSuccessAndStop = MoveRel(optionPara); |
| | | if (optionPara.IsAbsolute) |
| | | { |
| | | isSuccessAndStop = MoveAbs(optionPara); |
| | | } |
| | | else |
| | | { |
| | | isSuccessAndStop = MoveRel(optionPara); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case MotorMoveMode.FindOri: |
| | | { |
| | | isSuccessAndStop = GoHome(optionPara); |
| | | } |
| | | break; |
| | | break; |
| | | case MotorMoveMode.FindOri: |
| | | { |
| | | isSuccessAndStop = GoHome(optionPara); |
| | | } |
| | | break; |
| | | } |
| | | _position += $"{GetPosition(optionPara.AxisIndex)},"; |
| | | _position += $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}"; |
| | | LogAsync(DateTime.Now, "", _position); |
| | | } |
| | | _position += $"{GetPosition(optionPara.AxisIndex)},"; |
| | | _position += $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}"; |
| | | LogAsync(DateTime.Now, "", _position); |
| | | } |
| | | return isSuccessAndStop; |
| | | return isSuccessAndStop; |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |