| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 | 
							- using Aitex.Core.RT.Device;
 
- using Aitex.Core.RT.Event;
 
- using Aitex.Core.RT.Routine;
 
- using Aitex.Core.RT.SCCore;
 
- using Aitex.Sorter.Common;
 
- 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.Diagnostics;
 
- using System.Linq;
 
- using System.Text;
 
- using System.Threading.Tasks;
 
- using FurnaceRT.Equipments.Systems;
 
- namespace FurnaceRT.Equipments.LPs
 
- {
 
-     public class LoadPortAutoUnload : ModuleRoutine, IRoutine
 
-     {
 
-         enum RoutineStep
 
-         {
 
-             Unload,
 
-             BuzzerOn,
 
-             BuzzerOff,
 
-             CheckAccessSwitch1,
 
-             CheckAccessSwitch2,
 
-         }
 
-         private LoadPortModule _lpModule;
 
-         private int _timeout = 0;
 
-         private int _accessSwitchTimeout = 0;
 
-         private int _carrierInOrOutDelayTime = 0;
 
-         private bool _buzzerOn;
 
-         private bool _accessSwitchPressedBeforeCarrierOut;
 
-         private bool _accessSwitchPressedAfterCarrierOut;
 
-         private bool _isBypassAccessSwitchPressedTimeout;
 
-         private RoutineStep _routineStep;
 
-         public LoadPortAutoUnload(LoadPortModule lpModule)
 
-         {
 
-             _lpModule = lpModule;
 
-             Module = lpModule.Module;
 
-             Name = "Unload";
 
-         }
 
-         public void Init(bool isHasAlarm)
 
-         {
 
-             _isHasAlarm = isHasAlarm;
 
-         }
 
-         public Result Start(params object[] objs)
 
-         {
 
-             if (!_isHasAlarm)
 
-             {
 
-                 Reset();
 
-             }
 
-             else
 
-             {
 
-                 List<int> stepLst = new List<int>(Steps.ToArray());
 
-                 stepLst.Remove((int)_routineStep);
 
-                 Steps = new Stack<int>(stepLst);
 
-                 _isHasAlarm = false;
 
-                 ResetState();
 
-             }
 
-             _timeout = SC.GetValue<int>($"LoadPort.{Module}.MotionTimeout");
 
-             if (_lpModule.IsClamp)
 
-             {
 
-                 EV.PostInfoLog(Module, $"{Module} already at clamp position");
 
-                 return Result.DONE;
 
-             }
 
-             _buzzerOn = SC.GetValue<bool>("LoadPort.BuzzerSetting.BuzzerOnWhenUnloading");
 
-             _accessSwitchPressedBeforeCarrierOut = SC.GetValue<bool>("LoadPort.LoadPortSwitch.AccessSwitchPressedBeforeCarrierOut");
 
-             _accessSwitchPressedAfterCarrierOut = SC.GetValue<bool>("LoadPort.LoadPortSwitch.AccessSwitchPressedAfterCarrierOut");
 
-             _isBypassAccessSwitchPressedTimeout = SC.GetStringValue("LoadPort.LoadPortSwitch.OperationSwitchPressedAfterCarrierOut") == "Continue";
 
-             _accessSwitchTimeout = SC.GetValue<int>("LoadPort.LoadPortSwitch.AccessSwitchTimeout");
 
-             _carrierInOrOutDelayTime = SC.GetValue<int>("LoadPort.LoadPortSwitch.CarrierInOrOutDelayTime");
 
-             _lpModule.UnloadFailAlarm.RetryMessage = (int)LoadPortModule.MSG.AutoUnloadRetry;
 
-             _lpModule.UnloadTimeoutAlarm.RetryMessage = (int)LoadPortModule.MSG.AutoUnloadRetry;
 
-             var para = new List<object> { true };
 
-             _lpModule.UnloadFailAlarm.RetryMessageParas = para.ToArray();
 
-             _lpModule.UnloadTimeoutAlarm.RetryMessageParas = para.ToArray();
 
-             Notify($"{Module} unload start");
 
-             return Result.RUN;
 
-         }
 
-         public void Abort()
 
-         {
 
-             _lpModule.Stop();
 
-         }
 
-         public override Result Monitor()
 
-         {
 
-             try
 
-             {
 
-                 //_accessSwitchPressedBeforeCarrierOut
 
-                 //等待Access Switch按键按下
 
-                 if (_accessSwitchPressedBeforeCarrierOut)
 
-                     CheckAccessSwitch((int)RoutineStep.CheckAccessSwitch1, _accessSwitchTimeout);
 
-                 else
 
-                     Delay((int)RoutineStep.CheckAccessSwitch1, _carrierInOrOutDelayTime);
 
-                 Unload((int)RoutineStep.Unload, _timeout);
 
-                 if(_buzzerOn)                
 
-                     BuzzerOn((int)RoutineStep.BuzzerOn, true);
 
-                 //_accessSwitchPressedAfterCarrierOut
 
-                 //等待Access Switch按键按下
 
-                 if (_accessSwitchPressedAfterCarrierOut)
 
-                     CheckAccessSwitch((int)RoutineStep.CheckAccessSwitch2, _accessSwitchTimeout);
 
-                 if (_buzzerOn)
 
-                     BuzzerOn((int)RoutineStep.BuzzerOff, false);
 
-             }
 
-             catch (RoutineBreakException)
 
-             {
 
-                 return Result.RUN;
 
-             }
 
-             catch (RoutineFaildException ex)
 
-             {
 
-                 return Result.FAIL;
 
-             }
 
-             Notify($"{Name} finished");
 
-             return Result.DONE;
 
-         }
 
-         private void CheckAccessSwitch(int id, int timeout)
 
-         {
 
-             Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
 
-             {
 
-                 Notify($"{Module} check access switch");
 
-                 return true;
 
-             }, () =>
 
-             {
 
-                 return _lpModule.IsClamp;
 
-             }, timeout * 1000);
 
-             if (ret.Item1)
 
-             {
 
-                 if (ret.Item2 == Result.FAIL)
 
-                 {
 
-                     throw (new RoutineFaildException());
 
-                 }
 
-                 else if (ret.Item2 == Result.TIMEOUT) //timeout
 
-                 {
 
-                     if(_isBypassAccessSwitchPressedTimeout)
 
-                     {
 
-                         throw (new RoutineBreakException());
 
-                     }
 
-                     else
 
-                     {
 
-                         _lpModule.UnloadTimeoutAlarm.Set($"unload timeout, can not complete in {timeout} seconds");
 
-                         throw (new RoutineFaildException());
 
-                     }
 
-                 }
 
-                 else
 
-                     throw (new RoutineBreakException());
 
-             }
 
-         }
 
-         private void Unload(int id, int timeout)
 
-         {
 
-             _routineStep = (RoutineStep)Enum.Parse(typeof(RoutineStep), id.ToString());
 
-             Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
 
-             {
 
-                 Notify($"{Module} unload");
 
-                 if (!_lpModule.UnloadLoadPort(out string reason))
 
-                 {
 
-                     _lpModule.UnloadFailAlarm.Set(reason);
 
-                     return false;
 
-                 }
 
-                 return true;
 
-             }, () =>
 
-             {
 
-                 return  _lpModule.IsClamp;
 
-             }, timeout * 1000);
 
-             if (ret.Item1)
 
-             {
 
-                 if (ret.Item2 == Result.FAIL)
 
-                 {
 
-                     throw (new RoutineFaildException());
 
-                 }
 
-                 else if (ret.Item2 == Result.TIMEOUT) //timeout
 
-                 {
 
-                     _lpModule.UnloadTimeoutAlarm.Set($"unload timeout, can not complete in {timeout} seconds");
 
-                     throw (new RoutineFaildException());
 
-                 }
 
-                 else
 
-                     throw (new RoutineBreakException());
 
-             }
 
-         }
 
-         private void BuzzerOn(int id, bool isOn)
 
-         {
 
-             Tuple<bool, Result> ret = Execute(id, () =>
 
-             {
 
-                 Notify($"Buzzer {(isOn ? "on" : "off")}");
 
-                 DEVICE.GetDevice<FurnaceSignalTower>($"{ModuleName.System}.{ModuleName.SignalTower}").IsAutoSetLight = !isOn;
 
-                 DEVICE.GetDevice<FurnaceSignalTower>($"{ModuleName.System}.{ModuleName.SignalTower}").SetLight(LightType.Buzzer1, isOn ? TowerLightStatus.On : TowerLightStatus.Off);
 
-                 return true;
 
-             });
 
-             if (ret.Item1)
 
-             {
 
-                 if (ret.Item2 == Result.FAIL)
 
-                 {
 
-                     throw new RoutineFaildException();
 
-                 }
 
-                 else
 
-                     throw new RoutineBreakException();
 
-             }
 
-         }
 
-     }
 
- }
 
 
  |