123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Device.Unit;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.Util;
- using Aitex.Sorter.Common;
- using MECF.Framework.Common.Alarms;
- using MECF.Framework.Common.Device.Bases;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.SubstrateTrackings;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using FurnaceRT.Equipments.Systems;
- using static Aitex.Core.RT.Device.Unit.IoBoat;
- using System.Diagnostics;
- using FurnaceRT.Devices;
- namespace FurnaceRT.Equipments.Boats
- {
- public class BoatShutterCycleTest : ModuleRoutine, IRoutine
- {
- enum RoutineStep
- {
- ShutterOpen,
- ShutterClose,
- Loop,
- EndLoop,
- Delay1,
- Delay2,
- Delay3,
- }
- private float _speed;
- private float _interval;
- private BoatModule _boatModule;
- private int _timeout = 0;
- private int _shutterTimeout = 0;
- private int _count;
- public BoatShutterCycleTest(BoatModule boatModule)
- {
- _boatModule = boatModule;
- Module = boatModule.Module;
- Name = "ShutterCycleTest";
- }
- public void Init()
- {
- }
- public Result Start(params object[] objs)
- {
- Reset();
- _timeout = 6;// SC.GetValue<int>($"Boat.BoatElevatorServo.MotionTimeout");
- _count = SC.GetValue<int>($"{Module}.AutoShutter.CycleCount");
- _interval = (float)SC.GetValue<double>($"Boat.BoatElevatorServo.IntervalTime");
- _shutterTimeout = SC.GetValue<int>($"{Module}.AutoShutter.MotionTimeout");
- string reason = string.Empty;
- if (!_boatModule.CheckPrepareMove(out reason, false))
- {
- _boatModule.BoatZAxisMoveFailedForInterlock.Set(reason);
- return Result.FAIL;
- }
- Notify($"Start");
- return Result.RUN;
- }
- public void Abort()
- {
- _boatModule.ShutterDevice.Reset();
- }
- public override Result Monitor()
- {
- try
- {
- Loop((int)RoutineStep.Loop, _count);
- ShutterOpen((int)RoutineStep.ShutterOpen, true, _shutterTimeout);
- Delay((int)RoutineStep.Delay1, 2);
- Delay((int)RoutineStep.Delay2, _interval);
- ShutterOpen((int)RoutineStep.ShutterClose, false, _shutterTimeout);
- Delay((int)RoutineStep.Delay3, _interval);
- EndLoop((int)RoutineStep.EndLoop);
- }
- catch (RoutineBreakException)
- {
- return Result.RUN;
- }
- catch (RoutineFaildException ex)
- {
- return Result.FAIL;
- }
- _boatModule.ShutterDevice.Reset();
- Notify("Finished");
- return Result.DONE;
- }
- private void ShutterOpen(int id, bool isOpen, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"shutter {(isOpen ? "open" : "close")}");
- string reason;
- if (!_boatModule.ShutterDevice.SetOpen(isOpen, out reason))
- {
- _boatModule.ShutterDevice.AutoShutterMoveFailedForInterlock.Set();
- return false;
- }
- return true;
- }, () =>
- {
- return isOpen ? _boatModule.ShutterDevice.OpenCloseStatus == DeviceStatus.Open : _boatModule.ShutterDevice.OpenCloseStatus == DeviceStatus.Close;
- }, timeout * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- if (isOpen)
- {
- _boatModule.ShutterDevice.AutoShutterOpenTimeOut.Set($"can not complete in {timeout} seconds");
- }
- else
- {
- _boatModule.ShutterDevice.AutoShutterCloseTimeOut.Set($"can not complete in {timeout} seconds");
- }
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- }
- }
|