123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.Routine;
- using CyberX8_Core;
- using CyberX8_RT.Devices.EFEM;
- using CyberX8_RT.Modules.Rinse;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.Routine;
- using MECF.Framework.Common.Utilities;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace CyberX8_RT.Modules.EFEM
- {
- public class CycleRobotCycleRoutine : ModuleRoutineBase, IRoutine
- {
- private enum CycleRobotCycleStep
- {
- LoopStart,
- LoopRunRobotCycle,
- LoopRunRobotCycleWait,
- LoopEnd,
- End
- }
- /// <summary>
- /// Cycle次数
- /// </summary>
- private int _cycleTimes;
- /// <summary>
- /// 当前处于第几次Cycle
- /// </summary>
- private int _currentCycle;
- private object[] param;
- private RobotCycleRoutine _robotCycleRoutine;
- public CycleRobotCycleRoutine(EfemBase efem) : base(ModuleName.EfemRobot)
- {
- _robotCycleRoutine = new RobotCycleRoutine(efem);
- }
- public RState Start(params object[] objs)
- {
- param = objs;
- _currentCycle = 1;//初始化当前Cycle次数
- if (objs.Length >= 6)
- {
- _cycleTimes = (int)objs[4];
- if (_cycleTimes < 1)
- {
- LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Input Robot Cycle Times{_cycleTimes} error");
- return RState.Failed;
- }
- }
- return Runner.Start(Module, "Start CycleRobotCycleRoutine");
- }
- public RState Monitor()
- {
- Runner.LoopStart(CycleRobotCycleStep.LoopStart, "Loop StartCycleRobotCycleRoutine", _cycleTimes, NullFun, _delay_1ms)
- .LoopRun(CycleRobotCycleStep.LoopRunRobotCycle, () => _robotCycleRoutine.Start(param) == RState.Running,_delay_1ms)
- .LoopRunWithStopStatus(CycleRobotCycleStep.LoopRunRobotCycleWait, () => { return CommonFunction.CheckRoutineEndState(_robotCycleRoutine); },
- () => CheckRoutineStopStatus(_robotCycleRoutine, "CycleRobotCycleRoutine failed"))
- .LoopEnd(CycleRobotCycleStep.LoopEnd, UpdateCycleCount, _delay_1ms)
- .End(CycleRobotCycleStep.End, AchievedCycleCount, _delay_1ms);
- return Runner.Status;
- }
- private bool CheckRoutineStopStatus(IRoutine routine, string error)
- {
- bool result = CommonFunction.CheckRoutineStopState(routine);
- if (result)
- {
- Stop($"{error}");
- }
- return result;
- }
-
- /// <summary>
- /// Abort
- /// </summary>
- public void Abort()
- {
- Runner.Stop("CycleRobotCycleRoutine Abort");
- }
- /// <summary>
- /// 统计完成的Cycle次数
- /// </summary>
- /// <returns></returns>
- private bool UpdateCycleCount()
- {
- _currentCycle += 1;
- return true;
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- private bool AchievedCycleCount()
- {
- _currentCycle -= 1;
- return true;
- }
- /// <summary>
- /// 获取当前Cycle次数
- /// </summary>
- /// <returns></returns>
- public int GetCurrentCycle()
- {
- return _currentCycle;
- }
- }
- }
|