| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- using EaseDapper;
- using SHJX.Service.Control.Extends;
- using static Org.BouncyCastle.Math.EC.ECCurve;
- using System.Windows.Threading;
-
- namespace SHJX.Service.Control.Pipeline.Nodes.MoveNodes
- {
- public class TongsLoosen : INode
- {
- #region Fields
- private static readonly ILogger logger = LogFactory.BuildLogger(typeof(TongsGrab));
- private static IDataManager _dataManager;
- private static TaskExtend _taskExtend;
- private static ReadConfigUtil _config;
- #endregion
- public TongsLoosen(IDataManager dataManager, TaskExtend taskExtend, ReadConfigUtil config)
- {
- Name = nameof(TongsGrab);
- _config = config;
- _dataManager = dataManager;
- _taskExtend = taskExtend;
- }
- public override INode Invoke()
- {
- bool writeResponse = true;
- if (_config.TongsFeedBack)
- {
- var judgeCount = 0;
- Policy.HandleResult<bool>(Arg => Arg.Equals(false)).Retry(3, (resultArg, retryCount) =>
- {
- #region 松开
- writeResponse = EquipmentNames.Tongs.RegisterClose();
- #endregion
- Thread.Sleep(500);
- #region 抓取
- writeResponse = writeResponse && EquipmentNames.Tongs.RegisterOpen();
- #endregion
- judgeCount = retryCount;
- }).Execute(() =>
- {
- Thread.Sleep(500);
- char[] readRes = EquipmentNames.Tongs.MotorRead(); //这里需要读取
- bool judgeRes = readRes[4].Equals('0');
- #region 任务取消,加入取消缓存
- if (judgeCount.Equals(3) && !judgeRes)
- {
- ExcuteNextStep();
- }
- #endregion
- writeResponse = judgeRes;
- return judgeRes;
- });
- if (!writeResponse)
- {
- logger.LogDebug($"任务取消后,不进行后续操作!!!");
- return null;
- }
- }
- EquipmentNames.Tongs.RegisterClose();
- Thread.Sleep(200);
- return this;
- }
- private void ExcuteNextStep()
- {
- EquipmentNames.Tongs.RegisterClose();
- bool seekhome = EquipmentNames.AxisZ.MotorGoBack();
- if (seekhome)
- {
- CurrentTask.Status = TaskState.Finished;
- _dataManager.Update(CurrentTask);
- logger.LogDebug("任务被取消,后续步骤不再执行!");
- }
- if (CurrentTask.To.In("D1", "L1"))
- {
- EquipmentArea releaseArea = _dataManager.Query<EquipmentArea>().Where(item => item.PointName.Equals(CurrentTask.To)).First();
- if (releaseArea is not null)
- {
- releaseArea.Enable = true;
- _dataManager.Update(releaseArea);
- logger.LogDebug($"任务取消后,{releaseArea.PointName}被释放!");
- }
- }
- RouteCache cache = _dataManager.Query<RouteCache>().Where(item => item.Source.Equals(CurrentTask.Source)).First();
- if (cache is not null)
- {
- _dataManager.Delete(cache);
- logger.LogDebug($"任务取消后,{CurrentTask.Source}缓存被删除!");
- }
- var rows = _dataManager.Update<StateMachine>().Invoke(it => it.Status.Set(0))(it => it.Name.Equals(StateMachineName.MOTOR_LOCK));
- if (rows > 0)
- {
- logger.LogDebug($"任务取消后,{StateMachineName.MOTOR_LOCK}状态被解锁!");
- }
- ThreadPool.QueueUserWorkItem(delegate
- {
- SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext(System.Windows.Application.Current.Dispatcher));
- SynchronizationContext.Current?.Post(pl =>
- {
- _config.UpdateTaskRunning(false);
- Messager<string>.Send("ChangePauseIconSendMesg");
- UMessageBox.SingleBtnInfo("任务暂停\n当前抓取位置异常,未检测到杯子\n请检查相应位置是否正确或联系售后工程师!");
- }, null);
- });
- }
- }
- }
|