123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- 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 DocumentFormat.OpenXml.Wordprocessing;
- 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 LoadPortAutoLoad : ModuleRoutine, IRoutine
- {
- enum RoutineStep
- {
- Load,
- BuzzerOn,
- BuzzerOff,
- CheckAccessSwitch1,
- CheckAccessSwitch2,
- }
- private LoadPortModule _lpModule;
- private int _timeout = 0;
- private int _accessSwitchTimeout = 0;
- private int _carrierInOrOutDelayTime = 0;
- private bool _buzzerOn;
- private bool _accessSwitchPressedBeforeCarrierIn;
- private bool _accessSwitchPressedAfterCarrierIn;
- private bool _isBypassAccessSwitchPressedTimeout;
- private RoutineStep _routineStep;
- public LoadPortAutoLoad(LoadPortModule lpModule)
- {
- _lpModule = lpModule;
- Module = lpModule.Module;
- Name = "Load";
- }
- 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.IsReleased)
- {
- EV.PostInfoLog(Module, $"{Module} already at release position");
- return Result.DONE;
- }
- _lpModule.LoadFailAlarm.RetryMessage = (int)LoadPortModule.MSG.AutoLoadRetry;
- _lpModule.LoadTimeoutAlarm.RetryMessage = (int)LoadPortModule.MSG.AutoLoadRetry;
- var para = new List<object> { true };
- _lpModule.LoadFailAlarm.RetryMessageParas = para.ToArray();
- _lpModule.LoadTimeoutAlarm.RetryMessageParas = para.ToArray();
- _buzzerOn = SC.GetValue<bool>("LoadPort.BuzzerSetting.BuzzerOnWhenUnloading");
- _accessSwitchPressedBeforeCarrierIn = SC.GetValue<bool>("LoadPort.LoadPortSwitch.AccessSwitchPressedBeforeCarrierIn");
- _accessSwitchPressedAfterCarrierIn = SC.GetValue<bool>("LoadPort.LoadPortSwitch.AccessSwitchPressedAfterCarrierIn");
- _isBypassAccessSwitchPressedTimeout = SC.GetStringValue("LoadPort.LoadPortSwitch.OperationSwitchPressedAfterCarrierOut") == "Continue";
- _accessSwitchTimeout = SC.GetValue<int>("LoadPort.LoadPortSwitch.AccessSwitchTimeout");
- _carrierInOrOutDelayTime = SC.GetValue<int>("LoadPort.LoadPortSwitch.CarrierInOrOutDelayTime");
- Notify($"{Module} unload start");
- return Result.RUN;
- }
- public void Abort()
- {
- _lpModule.Stop();
- }
- public override Result Monitor()
- {
- try
- {
- //_accessSwitchPressedBeforeCarrierIn
- //等待Access Switch按键按下
- if (_accessSwitchPressedBeforeCarrierIn)
- CheckAccessSwitch((int)RoutineStep.CheckAccessSwitch1, _accessSwitchTimeout);
- else
- Delay((int)RoutineStep.CheckAccessSwitch1, _carrierInOrOutDelayTime);
- Load((int)RoutineStep.Load, _timeout);
- if(_buzzerOn)
- BuzzerOn((int)RoutineStep.BuzzerOn, true);
- //_accessSwitchPressedAfterCarrierIn
- //等待Access Switch按键按下
- if (_accessSwitchPressedAfterCarrierIn)
- 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 Load(int id, int timeout)
- {
- _routineStep = (RoutineStep)Enum.Parse(typeof(RoutineStep), id.ToString());
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"{Module} load");
- if (!_lpModule.LoadLoadPort(out string reason))
- {
- _lpModule.LoadFailAlarm.Set(reason);
- return false;
- }
- return true;
- }, () =>
- {
- return _lpModule.IsReleased;
- }, timeout * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- _lpModule.LoadTimeoutAlarm.Set($"load 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();
- }
- }
- }
- }
|