IOE84.cs 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Xml;
  7. using Aitex.Core.Common.DeviceData;
  8. using Aitex.Core.RT.DataCenter;
  9. using Aitex.Core.RT.Device;
  10. using Aitex.Core.RT.Event;
  11. using Aitex.Core.RT.IOCore;
  12. using Aitex.Core.RT.Log;
  13. using Aitex.Core.RT.OperationCenter;
  14. using Aitex.Core.RT.SCCore;
  15. using Aitex.Core.Util;
  16. using FACore.E87FA;
  17. using FurnaceRT.Equipments.LPs;
  18. using FurnaceRT.Equipments.Systems;
  19. using MECF.Framework.Common.Equipment;
  20. using MECF.Framework.Common.SubstrateTrackings;
  21. using MECF.Framework.FA.Core.E87FA;
  22. namespace FurnaceRT.Devices
  23. {
  24. public enum SignalType
  25. {
  26. Acitvie,
  27. Passive,
  28. }
  29. public enum SignalID
  30. {
  31. LightCurtain,
  32. CS_0,
  33. CS_1,
  34. AM_AVBL,
  35. VALID,
  36. TR_REQ,
  37. BUSY,
  38. COMPT,
  39. CONT,
  40. L_REQ,
  41. U_REQ,
  42. HO_AVBL,
  43. READY,
  44. ES
  45. }
  46. public class Signal
  47. {
  48. public bool Value
  49. {
  50. get
  51. {
  52. if (_di != null)
  53. return _di.Value;
  54. if (_do != null)
  55. return _do.Value;
  56. return false;
  57. }
  58. }
  59. private SignalID _id;
  60. private RD_TRIG _trig = new RD_TRIG();
  61. private DIAccessor _di = null;
  62. private DOAccessor _do = null;
  63. public event Action<SignalID, bool> OnChanged;
  64. public Signal(SignalID id, DIAccessor diAccessor, DOAccessor doAccessor)
  65. {
  66. _id = id;
  67. _di = diAccessor;
  68. _do = doAccessor;
  69. }
  70. public void Monitor()
  71. {
  72. if (_di != null)
  73. _trig.CLK = _di.Value;
  74. if (_do != null)
  75. _trig.CLK = _do.Value;
  76. if (_trig.R)
  77. {
  78. if (OnChanged != null)
  79. OnChanged(_id, true);
  80. }
  81. if (_trig.M)
  82. {
  83. if (OnChanged != null)
  84. OnChanged(_id, false);
  85. }
  86. }
  87. public void Reset()
  88. {
  89. _trig.RST = true;
  90. }
  91. }
  92. public class E84Passiver : BaseDevice, IDevice
  93. {
  94. public enum E84State
  95. {
  96. Normal,
  97. LD_TP1_Timeout,
  98. LD_TP2_Timeout,
  99. LD_TP3_Timeout,
  100. LD_TP4_Timeout,
  101. LD_TP5_Timeout,
  102. LD_TP6_Timeout,
  103. ULD_TP1_Timeout,
  104. ULD_TP2_Timeout,
  105. ULD_TP3_Timeout,
  106. ULD_TP4_Timeout,
  107. ULD_TP5_Timeout,
  108. ULD_TP6_Timeout,
  109. Error,
  110. }
  111. public enum Timeout
  112. {
  113. TP1,
  114. TP2,
  115. TP3,
  116. TP4,
  117. TP5,
  118. }
  119. public bool LightCurtainBroken { get { return !DiLightCurtain; } } //interlock
  120. public AccessMode Mode { get; set; }
  121. public LPTransferState TransferState { get; set; }
  122. public LPReservationState LPReserved { get; set; }
  123. public IFALoadPort Provider { get; set; }
  124. public bool DiLightCurtain { get; set; }
  125. public bool DiValid { get { return _diValid != null ? _diValid.Value : false; } }
  126. public bool DiCS0 { get { return _diCS0 != null ? _diCS0.Value : false; } }
  127. public bool DiCS1 { get { return _diCS1 != null ? _diCS1.Value : false; } }
  128. public bool DiTrReq { get { return _diTrReq != null ? _diTrReq.Value : false; } }
  129. public bool DiBusy { get { return _diBusy != null ? _diBusy.Value : false; } }
  130. public bool DiCompt { get { return _diCompt != null ? _diCompt.Value : false; } }
  131. public bool DiCont { get { return _diCont != null ? _diCont.Value : false; } }
  132. public bool DiAmAvbl { get { return _diAmAvbl != null ? _diAmAvbl.Value : false; } }
  133. public bool DoLoadReq { get { return _doLoadReq != null ? _doLoadReq.Value : false; } }
  134. public bool DoUnloadReq { get { return _doUnloadReq != null ? _doUnloadReq.Value : false; } }
  135. public bool DoReady { get { return _doReady != null ? _doReady.Value : false; } }
  136. public bool DoHOAvbl { get { return _doHOAvbl != null ? _doHOAvbl.Value : false; } }
  137. public bool DoES { get { return _doES != null ? _doES.Value : false; } }
  138. public string EventE84LoadTransactionStart => $"E84{Module}LoadTransactionStart";
  139. public string EventE84UnloadTransactionStart => $"E84{Module}UnloadTransactionStart";
  140. public string EventE84LoadTransactionComplete => $"E84{Module}LoadTransactionComplete";
  141. public string EventE84UnloadTransactionComplete => $"E84{Module}UnloadTransactionComplete";
  142. public string EventE84LoadTransactionRestart => $"E84{Module}LoadTransactionRestart";
  143. public string EventE84UnloadTransactionRestart => $"E84{Module}UnloadTransactionRestart";
  144. public string EventE84ChangeAccessModeToAuto => $"E84{Module}ChangeAccessModeToAuto";
  145. public string EventE84ChangeAccessModeToManual => $"E84{Module}ChangeAccessModeToManual";
  146. public static string EventE84TP1Timeout = "E84TP1Timeout";
  147. public static string EventE84TP2Timeout = "E84TP2Timeout";
  148. public static string EventE84TP3Timeout = "E84TP3Timeout";
  149. public static string EventE84TP4Timeout = "E84TP4Timeout";
  150. public static string EventE84TP5Timeout = "E84TP5Timeout";
  151. public static string EventE84TP6Timeout = "E84TP6Timeout";
  152. public bool IsFoupPresent
  153. {
  154. get
  155. {
  156. //if (SC.GetValue<bool>("System.IsSimulatorMode"))
  157. // return CarrierManager.Instance.HasCarrier(Module);
  158. if (_diPresent1 != null && _diPresent2 != null && _diPresent3 != null && _diSeat != null)
  159. return _diPresent1.Value && _diPresent2.Value && _diPresent3.Value && _diSeat.Value;
  160. return false;
  161. }
  162. }
  163. //Active equipment signal
  164. private DIAccessor _diLightCurtain;
  165. private DIAccessor _diValid;
  166. private DIAccessor _diCS0;
  167. private DIAccessor _diCS1;
  168. private DIAccessor _diAmAvbl;
  169. private DIAccessor _diTrReq;
  170. private DIAccessor _diBusy;
  171. private DIAccessor _diCompt;
  172. private DIAccessor _diCont;
  173. private DIAccessor _diPresent1;
  174. private DIAccessor _diPresent2;
  175. private DIAccessor _diPresent3;
  176. private DIAccessor _diSeat;
  177. //Passive
  178. private DOAccessor _doLoadReq;
  179. private DOAccessor _doUnloadReq;
  180. private DOAccessor _doReady;
  181. private DOAccessor _doHOAvbl;
  182. private DOAccessor _doES;
  183. private DeviceTimer _timer = new DeviceTimer();
  184. private DeviceTimer _timer_TP1 = new DeviceTimer();
  185. private DeviceTimer _timer_TP2 = new DeviceTimer();
  186. private DeviceTimer _timer_TP3 = new DeviceTimer();
  187. private DeviceTimer _timer_TP4 = new DeviceTimer();
  188. private DeviceTimer _timer_TP5 = new DeviceTimer();
  189. private DeviceTimer _timer_TP6 = new DeviceTimer();
  190. private R_TRIG _trigReset = new R_TRIG();
  191. private List<Signal> _signals = new List<Signal>();
  192. //timeout
  193. private SCConfigItem _scTimeoutTP1;
  194. private SCConfigItem _scTimeoutTP2;
  195. private SCConfigItem _scTimeoutTP3;
  196. private SCConfigItem _scTimeoutTP4;
  197. private SCConfigItem _scTimeoutTP5;
  198. private SCConfigItem _scTimeoutTP6;
  199. private SCConfigItem _scTimeoutTP7;
  200. private SCConfigItem _scTimeoutTP8;
  201. //private int reqOnTimeout = 2; //L_REQ|U_REQ_ON ON ---> TR REQ ON
  202. //private int readyOnTimeout = 2; //READY ON ---> BUSY ON
  203. //private int busyOnTimeout = 2; //BUSYON -- CARRIAGE DETECT|CARRIAGE REMOVE
  204. //private int reqOffTimeout = 2; //L_REQ|U_REQ off --->BUSY off
  205. //private int readyOffTimeout = 2; //Ready off --->Valid off
  206. private E84State _state;
  207. private string _lastSignalValue = "";
  208. //private Timeout _tp;
  209. /// <summary>
  210. /// This constructor uses DeviceModel's node to define IOs
  211. /// </summary>
  212. /// <param name="module"></param>
  213. /// <param name="node"></param>
  214. /// <param name="ioModule"></param>
  215. public E84Passiver(string module, XmlElement node, string ioModule = "")
  216. {
  217. base.Module = node.GetAttribute("module");
  218. base.Name = node.GetAttribute("id");
  219. base.Display = node.GetAttribute("display");
  220. base.DeviceID = node.GetAttribute("schematicId");
  221. _diLightCurtain = ParseDiNode("LightCurtain", node, ioModule);
  222. _signals.Add(new Signal(SignalID.LightCurtain, _diLightCurtain, null));
  223. //Indicates that the signal transition is active and selected
  224. //ON: valid; OFF: not valid
  225. _diValid = ParseDiNode("VALID", node, ioModule);
  226. _signals.Add(new Signal(SignalID.VALID, _diValid, null));
  227. //Carrier stage 0
  228. //ON: Use the load port for carrier handoff; vice versa
  229. _diCS0 = ParseDiNode("CS_0", node, ioModule);
  230. _signals.Add(new Signal(SignalID.CS_0, _diCS0, null));
  231. //Carrier stage 1
  232. //ON: Use the load port for carrier handoff; vice versa
  233. _diCS1 = ParseDiNode("CS_1", node, ioModule);
  234. _signals.Add(new Signal(SignalID.CS_1, _diCS1, null));
  235. //Transfer Arm Available
  236. //ON: Handoff is available; OFF: Handoff is unavailable with any error
  237. _diAmAvbl = ParseDiNode("AM_AVBL", node, ioModule);
  238. _signals.Add(new Signal(SignalID.AM_AVBL, _diAmAvbl, null));
  239. //Transfer Request
  240. //ON: Request Handoff; vice versa
  241. _diTrReq = ParseDiNode("TR_REQ", node, ioModule);
  242. _signals.Add(new Signal(SignalID.TR_REQ, _diTrReq, null));
  243. //BUSY for transfer
  244. //ON: Handoff is in progress; vice versa
  245. _diBusy = ParseDiNode("BUSY", node, ioModule);
  246. _signals.Add(new Signal(SignalID.BUSY, _diBusy, null));
  247. //Complete Transfer
  248. //ON:The handoff is completed; vice versa
  249. _diCompt = ParseDiNode("COMPT", node, ioModule);
  250. _signals.Add(new Signal(SignalID.COMPT, _diCompt, null));
  251. //Continuous Handoff
  252. //ON: Continuous Handoff; vice versa
  253. _diCont = ParseDiNode("CONT", node, ioModule);
  254. _signals.Add(new Signal(SignalID.CONT, _diCont, null));
  255. _diPresent1 = ParseDiNode("Present1", node, ioModule);
  256. _diPresent2 = ParseDiNode("Present2", node, ioModule);
  257. _diPresent3 = ParseDiNode("Present3", node, ioModule);
  258. _diSeat = ParseDiNode("Seat", node, ioModule);
  259. //Load Request
  260. //ON: The load port is assigned to load a carrier; vice versa
  261. //CS_0 && VALID && !CarrierLoaded
  262. _doLoadReq = ParseDoNode("L_REQ", node, ioModule);
  263. _signals.Add(new Signal(SignalID.L_REQ, null, _doLoadReq));
  264. //Unload Request
  265. //ON: The load port is assigned to unload a carrier; vice versa
  266. //CS_0 && VALID && !CarrierUnloaded
  267. _doUnloadReq = ParseDoNode("U_REQ", node, ioModule);
  268. _signals.Add(new Signal(SignalID.U_REQ, null, _doUnloadReq));
  269. //READY for transfer(after accepted the transfer request set ON, turned OFF when COMPT ON)
  270. //ON: Ready for handoff; vice versa
  271. _doReady = ParseDoNode("READY", node, ioModule);
  272. _signals.Add(new Signal(SignalID.READY, null, _doReady));
  273. //Indicates the passive equipment is not available for the handoff.
  274. //ON: Handoff is available; OFF: vice versa but with error
  275. //ON when normal; OFF when : Maintenance mode / Error State
  276. _doHOAvbl = ParseDoNode("HO_AVBL", node, ioModule);
  277. _signals.Add(new Signal(SignalID.HO_AVBL, null, _doHOAvbl));
  278. //Emergency stop
  279. _doES = ParseDoNode("ES", node, ioModule);
  280. _signals.Add(new Signal(SignalID.ES, null, _doES));
  281. foreach (var signal in _signals)
  282. {
  283. signal.OnChanged += OnSignalChange;
  284. }
  285. _scTimeoutTP1 = SC.GetConfigItem("FA.E84.TP1");
  286. _scTimeoutTP2 = SC.GetConfigItem("FA.E84.TP2");
  287. _scTimeoutTP3 = SC.GetConfigItem("FA.E84.TP3");
  288. _scTimeoutTP4 = SC.GetConfigItem("FA.E84.TP4");
  289. _scTimeoutTP5 = SC.GetConfigItem("FA.E84.TP5");
  290. _scTimeoutTP6 = SC.GetConfigItem("FA.E84.TP6");
  291. _scTimeoutTP7 = SC.GetConfigItem("FA.E84.TP7");
  292. _scTimeoutTP8 = SC.GetConfigItem("FA.E84.TP8");
  293. OP.Subscribe($"{Module}.E84Place", (cmd, param) =>
  294. {
  295. if (!AutoLoad(out var reason))
  296. {
  297. EV.PostWarningLog(Module, $"{Name} can not Place, {reason}");
  298. return false;
  299. }
  300. return true;
  301. });
  302. OP.Subscribe($"{Module}.E84Pick", (cmd, param) =>
  303. {
  304. if (!AutoUnLoad(out var reason))
  305. {
  306. EV.PostWarningLog(Module, $"{Name} can not Pick, {reason}");
  307. return false;
  308. }
  309. return true;
  310. });
  311. OP.Subscribe($"{Module}.E84Retry", (cmd, param) =>
  312. {
  313. if (!E84Retry(out var reason))
  314. {
  315. EV.PostWarningLog(Module, $"{Name} can not retry E84 transaction, {reason}");
  316. return false;
  317. }
  318. return true;
  319. });
  320. OP.Subscribe($"{Module}.E84Complete", (cmd, param) =>
  321. {
  322. if (!E84Complete(out var reason))
  323. {
  324. EV.PostWarningLog(Module, $"{Name} can not complete E84 transaction, {reason}");
  325. return false;
  326. }
  327. return true;
  328. });
  329. DATA.Subscribe($"{Module}.E84State", () => _state.ToString());
  330. //DATA.Subscribe($"{Module}.TransferState", () => TransferState.ToString());
  331. //DATA.Subscribe($"{Module}.AccessMode", () => Mode.ToString());
  332. DATA.Subscribe($"{Module}_E84STATE", () => (ushort)_state);
  333. //DATA.Subscribe($"{Module}_TRANSFER_STATE", () => (ushort)TransferState);
  334. //DATA.Subscribe($"{Module}_ACCESS_MODE", () => (ushort)Mode);
  335. DATA.Subscribe($"{Module}.LightCurtain", () => (_diLightCurtain != null ? _diLightCurtain.Value : true));
  336. DATA.Subscribe($"{Module}.Valid", () => _diValid.Value);
  337. DATA.Subscribe($"{Module}.TransferRequest", () => _diTrReq.Value);
  338. DATA.Subscribe($"{Module}.Busy", () => _diBusy.Value);
  339. DATA.Subscribe($"{Module}.TransferComplete", () => _diCompt.Value);
  340. DATA.Subscribe($"{Module}.CS0", () => _diCS0.Value);
  341. DATA.Subscribe($"{Module}.CS1", () => _diCS1.Value);
  342. DATA.Subscribe($"{Module}.CONT", () => _diCont.Value);
  343. DATA.Subscribe($"{Module}.LoadRequest", () => _doLoadReq.Value);
  344. DATA.Subscribe($"{Module}.UnloadRequest", () => _doUnloadReq.Value);
  345. DATA.Subscribe($"{Module}.ReadyToTransfer", () => _doReady.Value);
  346. DATA.Subscribe($"{Module}.HandoffAvailable", () => _doHOAvbl.Value);
  347. DATA.Subscribe($"{Module}.ES", () => _doES.Value);
  348. int index = (int)(ModuleName)(Enum.Parse(typeof(ModuleName), Module)) - 1;
  349. EV.Subscribe(new EventItem(60061 + 10 * index, "Event", AlarmTP1timeout, $"{Module} Occurred TP1 Timeout", EventLevel.Alarm, Aitex.Core.RT.Event.EventType.HostNotification));
  350. EV.Subscribe(new EventItem(60062 + 10 * index, "Event", AlarmTP2timeout, $"{Module} Occurred TP2 Timeout", EventLevel.Alarm, Aitex.Core.RT.Event.EventType.HostNotification));
  351. EV.Subscribe(new EventItem(60063 + 10 * index, "Event", AlarmTP3timeout, $"{Module} Occurred TP3 Timeout", EventLevel.Alarm, Aitex.Core.RT.Event.EventType.HostNotification));
  352. EV.Subscribe(new EventItem(60064 + 10 * index, "Event", AlarmTP4timeout, $"{Module} Occurred TP4 Timeout", EventLevel.Alarm, Aitex.Core.RT.Event.EventType.HostNotification));
  353. EV.Subscribe(new EventItem(60065 + 10 * index, "Event", AlarmTP5timeout, $"{Module} Occurred TP5 Timeout", EventLevel.Alarm, Aitex.Core.RT.Event.EventType.HostNotification));
  354. EV.Subscribe(new EventItem("Event", EventE84LoadTransactionStart, $"{Module} Load Transaction Start", EventLevel.Information, Aitex.Core.RT.Event.EventType.EventUI_Notify));
  355. EV.Subscribe(new EventItem("Event", EventE84UnloadTransactionStart, $"{Module} Unload Transaction Start", EventLevel.Information, Aitex.Core.RT.Event.EventType.EventUI_Notify));
  356. EV.Subscribe(new EventItem("Event", EventE84LoadTransactionComplete, $"{Module} Load Transaction Complete", EventLevel.Information, Aitex.Core.RT.Event.EventType.EventUI_Notify));
  357. EV.Subscribe(new EventItem("Event", EventE84UnloadTransactionComplete, $"{Module} Unload Transaction Complete", EventLevel.Information, Aitex.Core.RT.Event.EventType.EventUI_Notify));
  358. EV.Subscribe(new EventItem("Event", EventE84LoadTransactionRestart, $"{Module} Load Transaction Restart", EventLevel.Information, Aitex.Core.RT.Event.EventType.EventUI_Notify));
  359. EV.Subscribe(new EventItem("Event", EventE84UnloadTransactionRestart, $"{Module} Unload Transaction Restart", EventLevel.Information, Aitex.Core.RT.Event.EventType.EventUI_Notify));
  360. EV.Subscribe(new EventItem("Event", EventE84ChangeAccessModeToAuto, $"{Module} Change Access Mode To Auto", EventLevel.Information, Aitex.Core.RT.Event.EventType.EventUI_Notify));
  361. EV.Subscribe(new EventItem("Event", EventE84ChangeAccessModeToManual, $"{Module} Change Access Mode To Manual", EventLevel.Information, Aitex.Core.RT.Event.EventType.EventUI_Notify));
  362. _thread = new PeriodicJob(10, OnTimer, $"{Module}.{Name} MonitorE84Handler", true);
  363. }
  364. private string AlarmTP1timeout { get => $"{Module}TP1Timeout"; }
  365. private string AlarmTP2timeout { get => $"{Module}TP2Timeout"; }
  366. private string AlarmTP3timeout { get => $"{Module}TP3Timeout"; }
  367. private string AlarmTP4timeout { get => $"{Module}TP4Timeout"; }
  368. private string AlarmTP5timeout { get => $"{Module}TP5Timeout"; }
  369. /// <summary>
  370. /// This constructor gets IO signals using GetIO
  371. /// </summary>
  372. /// <param name="module"></param>
  373. /// <param name="name"></param>
  374. /// <param name="display"></param>
  375. /// <param name="deviceId"></param>
  376. public E84Passiver(string module, string name, string display, string deviceId)
  377. {
  378. Module = module;
  379. Name = name;
  380. Display = display;
  381. DeviceID = deviceId;
  382. _diLightCurtain = IO.DI[$"DI_{module}_LightCurtain"];
  383. _signals.Add(new Signal(SignalID.LightCurtain, _diLightCurtain, null));
  384. //Indicates that the signal transition is active and selected
  385. //ON: valid; OFF: not valid
  386. _diValid = IO.DI[$"DI_{module}_VALID"];
  387. _signals.Add(new Signal(SignalID.VALID, _diValid, null));
  388. //Carrier stage 0
  389. //ON: Use the load port for carrier handoff; vice versa
  390. _diCS0 = IO.DI[$"DI_{module}_CS_0"];
  391. _signals.Add(new Signal(SignalID.CS_0, _diCS0, null));
  392. //Carrier stage 1
  393. //ON: Use the load port for carrier handoff; vice versa
  394. _diCS1 = IO.DI[$"DI_{module}_CS_1"] ?? IO.DI[$"DI_{module}_CS_0"];
  395. _signals.Add(new Signal(SignalID.CS_1, _diCS1, null));
  396. //Transfer Arm Available
  397. //ON: Handoff is available; OFF: Handoff is unavailable with any error
  398. _diAmAvbl = IO.DI[$"DI_{module}_AM_AVBL"];
  399. _signals.Add(new Signal(SignalID.AM_AVBL, _diAmAvbl, null));
  400. //Transfer Request
  401. //ON: Request Handoff; vice versa
  402. _diTrReq = IO.DI[$"DI_{module}_TR_REQ"];
  403. _signals.Add(new Signal(SignalID.TR_REQ, _diTrReq, null));
  404. //BUSY for transfer
  405. //ON: Handoff is in progress; vice versa
  406. _diBusy = IO.DI[$"DI_{module}_BUSY"];
  407. _signals.Add(new Signal(SignalID.BUSY, _diBusy, null));
  408. //Complete Transfer
  409. //ON:The handoff is completed; vice versa
  410. _diCompt = IO.DI[$"DI_{module}_COMPT"];
  411. _signals.Add(new Signal(SignalID.COMPT, _diCompt, null));
  412. //Continuous Handoff
  413. //ON: Continuous Handoff; vice versa
  414. _diCont = IO.DI[$"DI_{module}_CONT"];
  415. _signals.Add(new Signal(SignalID.CONT, _diCont, null));
  416. //Load Request
  417. //ON: The load port is assigned to load a carrier; vice versa
  418. //CS_0 && VALID && !CarrierLoaded
  419. _doLoadReq = IO.DO[$"DI_{module}_L_REQ"];
  420. _signals.Add(new Signal(SignalID.L_REQ, null, _doLoadReq));
  421. //Unload Request
  422. //ON: The load port is assigned to unload a carrier; vice versa
  423. //CS_0 && VALID && !CarrierUnloaded
  424. _doUnloadReq = IO.DO[$"DI_{module}_U_REQ"];
  425. _signals.Add(new Signal(SignalID.U_REQ, null, _doUnloadReq));
  426. //READY for transfer(after accepted the transfer request set ON, turned OFF when COMPT ON)
  427. //ON: Ready for handoff; vice versa
  428. _doReady = IO.DO[$"DI_{module}_READY"];
  429. _signals.Add(new Signal(SignalID.READY, null, _doReady));
  430. //Indicates the passive equipment is not available for the handoff.
  431. //ON: Handoff is available; OFF: vice versa but with error
  432. //ON when normal; OFF when : Maintenance mode / Error State
  433. _doHOAvbl = IO.DO[$"DI_{module}_HO_AVBL"];
  434. _signals.Add(new Signal(SignalID.HO_AVBL, null, _doHOAvbl));
  435. //Emergency stop
  436. _doES = IO.DO[$"DI_{module}_ES"];
  437. _signals.Add(new Signal(SignalID.ES, null, _doES));
  438. foreach (var signal in _signals)
  439. {
  440. signal.OnChanged += OnSignalChange;
  441. }
  442. _scTimeoutTP1 = SC.GetConfigItem("FA.E84.TP1");
  443. _scTimeoutTP2 = SC.GetConfigItem("FA.E84.TP2");
  444. _scTimeoutTP3 = SC.GetConfigItem("FA.E84.TP3");
  445. _scTimeoutTP4 = SC.GetConfigItem("FA.E84.TP4");
  446. _scTimeoutTP5 = SC.GetConfigItem("FA.E84.TP5");
  447. _scTimeoutTP6 = SC.GetConfigItem("FA.E84.TP6");
  448. _scTimeoutTP7 = SC.GetConfigItem("FA.E84.TP7");
  449. _scTimeoutTP8 = SC.GetConfigItem("FA.E84.TP8");
  450. OP.Subscribe($"{Module}.E84Place", (cmd, param) =>
  451. {
  452. if (!AutoLoad(out var reason))
  453. {
  454. EV.PostWarningLog(Module, $"{Name} can not Place, {reason}");
  455. return false;
  456. }
  457. return true;
  458. });
  459. OP.Subscribe($"{Module}.E84Pick", (cmd, param) =>
  460. {
  461. if (!AutoUnLoad(out var reason))
  462. {
  463. EV.PostWarningLog(Module, $"{Name} can not Pick, {reason}");
  464. return false;
  465. }
  466. return true;
  467. });
  468. OP.Subscribe($"{Module}.E84Retry", (cmd, param) =>
  469. {
  470. if (!E84Retry(out var reason))
  471. {
  472. EV.PostWarningLog(Module, $"{Name} can not retry E84 transaction, {reason}");
  473. return false;
  474. }
  475. return true;
  476. });
  477. OP.Subscribe($"{Module}.E84Complete", (cmd, param) =>
  478. {
  479. if (!E84Complete(out var reason))
  480. {
  481. EV.PostWarningLog(Module, $"{Name} can not complete E84 transaction, {reason}");
  482. return false;
  483. }
  484. return true;
  485. });
  486. DATA.Subscribe($"{Module}.E84State", () => _state.ToString());
  487. //DATA.Subscribe($"{Module}.TransferState", () => TransferState.ToString());
  488. // DATA.Subscribe($"{Module}.AccessMode", () => Mode.ToString());
  489. DATA.Subscribe($"{Module}.LightCurtain", () => _diLightCurtain.Value);
  490. DATA.Subscribe($"{Module}.Valid", () => _diValid.Value);
  491. DATA.Subscribe($"{Module}.TransferRequest", () => _diTrReq.Value);
  492. DATA.Subscribe($"{Module}.Busy", () => _diBusy.Value);
  493. DATA.Subscribe($"{Module}.TransferComplete", () => _diCompt.Value);
  494. DATA.Subscribe($"{Module}.CS0", () => _diCS0.Value);
  495. DATA.Subscribe($"{Module}.CS1", () => _diCS1.Value);
  496. DATA.Subscribe($"{Module}.CONT", () => _diCont.Value);
  497. DATA.Subscribe($"{Module}.LoadRequest", () => _doLoadReq.Value);
  498. DATA.Subscribe($"{Module}.UnloadRequest", () => _doUnloadReq.Value);
  499. DATA.Subscribe($"{Module}.ReadyToTransfer", () => _doReady.Value);
  500. DATA.Subscribe($"{Module}.HandoffAvailable", () => _doHOAvbl.Value);
  501. DATA.Subscribe($"{Module}.ES", () => _doES.Value);
  502. int index = (int)(ModuleName)(Enum.Parse(typeof(ModuleName), Module)) - 1;
  503. EV.Subscribe(new EventItem(60061 + 10 * index, "Event", AlarmTP1timeout, $"{Module} Occurred TP1 Timeout", EventLevel.Alarm, Aitex.Core.RT.Event.EventType.HostNotification));
  504. EV.Subscribe(new EventItem(60062 + 10 * index, "Event", AlarmTP2timeout, $"{Module} Occurred TP2 Timeout", EventLevel.Alarm, Aitex.Core.RT.Event.EventType.HostNotification));
  505. EV.Subscribe(new EventItem(60063 + 10 * index, "Event", AlarmTP3timeout, $"{Module} Occurred TP3 Timeout", EventLevel.Alarm, Aitex.Core.RT.Event.EventType.HostNotification));
  506. EV.Subscribe(new EventItem(60064 + 10 * index, "Event", AlarmTP4timeout, $"{Module} Occurred TP4 Timeout", EventLevel.Alarm, Aitex.Core.RT.Event.EventType.HostNotification));
  507. EV.Subscribe(new EventItem(60065 + 10 * index, "Event", AlarmTP5timeout, $"{Module} Occurred TP5 Timeout", EventLevel.Alarm, Aitex.Core.RT.Event.EventType.HostNotification));
  508. _thread = new PeriodicJob(10, OnTimer, $"{Module}.{Name} MonitorE84Handler", true);
  509. }
  510. private PeriodicJob _thread;
  511. public bool Stop(out string reason)
  512. {
  513. reason = String.Empty;
  514. ResetSignal();
  515. return false;
  516. }
  517. public bool AutoLoad(out string reason)
  518. {
  519. //reason = String.Empty;
  520. //if (Mode != LPAccessMode.AUTO)
  521. //{
  522. // if (!SetAMHS(out reason))
  523. // {
  524. // return false;
  525. // }
  526. //}
  527. //if (Provider.ReadyForLoad())
  528. //{
  529. // TransferState = LPTransferState.READY_TO_LOAD;
  530. // return true;
  531. //}
  532. reason = "Not Ready For Auto Load";
  533. return false;
  534. }
  535. public bool AutoUnLoad(out string reason)
  536. {
  537. //reason = String.Empty;
  538. //if (Mode != LPAccessMode.AUTO)
  539. //{
  540. // if (!SetAMHS(out reason))
  541. // {
  542. // return false;
  543. // }
  544. //}
  545. //if (Provider.ReadyForUnload())
  546. //{
  547. // TransferState = LPTransferState.READY_TO_UNLOAD;
  548. // return true;
  549. //}
  550. reason = "Not Ready For Auto Load";
  551. return false;
  552. }
  553. public bool SetAMHS(out string reason)
  554. {
  555. reason = "";
  556. Provider.SetAccessMode(true, out reason);
  557. return true;
  558. }
  559. public bool SetManual(out string reason)
  560. {
  561. reason = "";
  562. Provider.SetAccessMode(false, out reason);
  563. return true;
  564. }
  565. public bool E84Retry(out string reason)
  566. {
  567. reason = "";
  568. var dvid = new SerializableDictionary<string, object>();
  569. int portID = 0;
  570. dvid["PORT_ID"] = int.TryParse(Module.Replace("LP", ""), out portID) ? portID : portID;
  571. ResetSignal();
  572. //Provider.E84Retry();
  573. return true;
  574. }
  575. public bool E84Complete(out string reason)
  576. {
  577. reason = "";
  578. var dvid = new SerializableDictionary<string, object>();
  579. int portID = 0;
  580. dvid["PORT_ID"] = int.TryParse(Module.Replace("LP", ""), out portID) ? portID : portID;
  581. switch (_state)
  582. {
  583. case E84State.Error:
  584. ResetSignal();
  585. break;
  586. case E84State.LD_TP1_Timeout:
  587. if (IsFoupPresent)
  588. {
  589. EV.Notify(EventE84LoadTransactionComplete, dvid);
  590. ResetSignal();
  591. }
  592. else
  593. {
  594. reason = "Foup not detected";
  595. return false;
  596. }
  597. break;
  598. case E84State.LD_TP2_Timeout:
  599. if (IsFoupPresent)
  600. {
  601. EV.Notify(EventE84LoadTransactionComplete, dvid);
  602. ResetSignal();
  603. }
  604. else
  605. {
  606. reason = "Foup not detected";
  607. return false;
  608. }
  609. break;
  610. case E84State.LD_TP3_Timeout:
  611. if (IsFoupPresent)
  612. {
  613. EV.Notify(EventE84LoadTransactionComplete, dvid);
  614. ResetSignal();
  615. }
  616. else
  617. {
  618. reason = "Foup not detected";
  619. return false;
  620. }
  621. break;
  622. case E84State.LD_TP4_Timeout:
  623. if (IsFoupPresent)
  624. {
  625. EV.Notify(EventE84LoadTransactionComplete, dvid);
  626. ResetSignal();
  627. }
  628. else
  629. {
  630. reason = "Foup not detected";
  631. return false;
  632. }
  633. break;
  634. case E84State.LD_TP5_Timeout:
  635. ResetSignal();
  636. break;
  637. case E84State.ULD_TP1_Timeout:
  638. if (!IsFoupPresent)
  639. {
  640. EV.Notify(EventE84UnloadTransactionComplete, dvid);
  641. ResetSignal();
  642. }
  643. else
  644. {
  645. reason = "Foup detected";
  646. return false;
  647. }
  648. break;
  649. case E84State.ULD_TP2_Timeout:
  650. if (!IsFoupPresent)
  651. {
  652. EV.Notify(EventE84UnloadTransactionComplete, dvid);
  653. ResetSignal();
  654. }
  655. else
  656. {
  657. reason = "Foup detected";
  658. return false;
  659. }
  660. break;
  661. case E84State.ULD_TP3_Timeout:
  662. if (!IsFoupPresent)
  663. {
  664. EV.Notify(EventE84UnloadTransactionComplete, dvid);
  665. ResetSignal();
  666. }
  667. else
  668. {
  669. reason = "Foup detected";
  670. return false;
  671. }
  672. break;
  673. case E84State.ULD_TP4_Timeout:
  674. if (!IsFoupPresent)
  675. {
  676. EV.Notify(EventE84UnloadTransactionComplete, dvid);
  677. ResetSignal();
  678. }
  679. else
  680. {
  681. reason = "Foup detected";
  682. return false;
  683. }
  684. break;
  685. case E84State.ULD_TP5_Timeout:
  686. ResetSignal();
  687. break;
  688. default:
  689. ResetSignal();
  690. break;
  691. }
  692. return true;
  693. }
  694. public bool Initialize()
  695. {
  696. ResetSignal();
  697. return true;
  698. }
  699. private bool InvokeReset(string arg1, object[] arg2)
  700. {
  701. //string reason;
  702. EV.PostInfoLog(Module, $"E84 reset {Module}.{Name}");
  703. ResetSignal();
  704. return true;
  705. }
  706. public void Terminate()
  707. {
  708. ResetSignal();
  709. }
  710. private void ResetSignal()
  711. {
  712. _doLoadReq.SetValue(false, out _);
  713. _doUnloadReq.SetValue(false, out _);
  714. _doReady.SetValue(false, out _);
  715. _doHOAvbl.SetValue(false, out _);
  716. _doES.SetValue(false, out _);
  717. _timer_TP1.Stop();
  718. _timer_TP2.Stop();
  719. _timer_TP3.Stop();
  720. _timer_TP4.Stop();
  721. _timer_TP5.Stop();
  722. _state = E84State.Normal;
  723. foreach (var signal in _signals)
  724. {
  725. signal.Reset();
  726. }
  727. }
  728. private LPTransferState preTranState;
  729. private bool OnTimer()
  730. {
  731. try
  732. {
  733. foreach (var signal in _signals)
  734. {
  735. signal.Monitor();
  736. }
  737. RecordSignalChange();
  738. if (Provider == null)
  739. return true;
  740. TransferState = (LPTransferState)Provider.GetTransferState();
  741. Mode = (AccessMode)Provider.GetAccessMode();
  742. LPReserved = (LPReservationState)Provider.GetReservedState();
  743. if (_diLightCurtain != null)
  744. {
  745. DiLightCurtain = _diLightCurtain.Value;
  746. if (SC.ContainsItem("Fa.E84.BypassLightCurtain") && SC.GetValue<bool>("Fa.E84.BypassLightCurtain"))
  747. DiLightCurtain = true;
  748. }
  749. else DiLightCurtain = true;
  750. if (LightCurtainBroken || TransferState == LPTransferState.OUT_OF_SERVICE || Mode != AccessMode.Auto)
  751. {
  752. _doHOAvbl.SetValue(false, out _);
  753. _doLoadReq.SetValue(false, out _);
  754. _doUnloadReq.SetValue(false, out _);
  755. _doReady.SetValue(false, out _);
  756. _doES.SetValue(false, out _);
  757. _timer_TP1.Stop();
  758. _timer_TP2.Stop();
  759. _timer_TP3.Stop();
  760. _timer_TP4.Stop();
  761. _timer_TP5.Stop();
  762. _timer_TP6.Stop();
  763. preTranState = TransferState;
  764. return true;
  765. }
  766. if (_state != E84State.Normal)
  767. return true;
  768. _doHOAvbl.SetValue(true, out _);
  769. _doES.SetValue(true, out _);
  770. var dvid = new SerializableDictionary<string, object>();
  771. int portID = 0;
  772. dvid["PORT_ID"] = int.TryParse(Module.Replace("LP", ""), out portID) ? portID : portID;
  773. if (TransferState == LPTransferState.READY_TO_LOAD && !IsFoupPresent)
  774. {
  775. preTranState = TransferState;
  776. if (DiCS0 && DiValid && !_doLoadReq.Value)
  777. {
  778. _doLoadReq.SetValue(true, out _);
  779. }
  780. if (DiCS0 && DiValid && _doLoadReq.Value && !DiTrReq)
  781. {
  782. if (_timer_TP1.IsIdle()) _timer_TP1.Start(_scTimeoutTP1.IntValue * 1000);
  783. }
  784. if (DiCS0 && DiValid && _doLoadReq.Value && DiTrReq && !_doReady.Value)
  785. {
  786. _timer_TP1.Stop();
  787. _doReady.SetValue(true, out _);
  788. if (Provider != null) Provider.OnE84HandoffStart(true, out _);
  789. EV.Notify(EventE84LoadTransactionStart, dvid);
  790. }
  791. }
  792. if (TransferState == LPTransferState.TRANSFER_BLOCKED && preTranState == LPTransferState.READY_TO_LOAD) //Load Sequence
  793. {
  794. if (DiCS0 && DiValid && _doLoadReq.Value && DiTrReq && _doReady.Value && !DiBusy)
  795. {
  796. if (_timer_TP2.IsIdle()) _timer_TP2.Start(_scTimeoutTP2.IntValue * 1000);
  797. }
  798. if (DiCS0 && DiValid && _doLoadReq.Value && DiTrReq && _doReady.Value && DiBusy)
  799. {
  800. _timer_TP2.Stop();
  801. if (!IsFoupPresent)
  802. {
  803. if (_timer_TP3.IsIdle()) _timer_TP3.Start(_scTimeoutTP3.IntValue * 1000);
  804. }
  805. else
  806. {
  807. _timer_TP3.Stop();
  808. _doLoadReq.SetValue(false, out _);
  809. }
  810. }
  811. if (DiCS0 && DiValid && !_doLoadReq.Value && DiTrReq && _doReady.Value && DiBusy)
  812. {
  813. if (_timer_TP4.IsIdle()) _timer_TP4.Start(_scTimeoutTP4.IntValue * 1000);
  814. }
  815. if (DiCS0 && DiValid && !_doLoadReq.Value && _doReady.Value && !DiBusy)
  816. {
  817. _timer_TP4.Stop();
  818. }
  819. if (DiCS0 && DiValid && !_doLoadReq.Value && _doReady.Value && DiCompt)
  820. {
  821. _doReady.SetValue(false, out _);
  822. _timer_TP4.Stop();
  823. if (_timer_TP5.IsIdle()) _timer_TP5.Start(_scTimeoutTP5.IntValue * 1000);
  824. }
  825. if (!DiCS0 && !_doLoadReq.Value && !_doUnloadReq.Value && !DiTrReq && !_doReady.Value && !DiBusy && !DiCompt)
  826. {
  827. _timer_TP5.Stop();
  828. EV.Notify(EventE84LoadTransactionComplete, dvid);
  829. preTranState = LPTransferState.TRANSFER_BLOCKED;
  830. var lpmodule = Singleton<EquipmentManager>.Instance.Modules[ModuleHelper.Converter(Module)] as LoadPortModule;
  831. if (IsFoupPresent)
  832. lpmodule.Invoke("ReadID");
  833. //if (Provider != null) Provider.OnE84HandoffComplete(true,out _);
  834. }
  835. }
  836. if (TransferState == LPTransferState.READY_TO_UNLOAD)
  837. {
  838. preTranState = TransferState;
  839. if (DiCS0 && DiValid && !_doUnloadReq.Value)
  840. {
  841. _doUnloadReq.SetValue(true, out _);
  842. //Provider.LPTSTrans();
  843. //EV.Notify(EventE84UnloadTransactionStart, dvid);
  844. }
  845. if (DiCS0 && DiValid && _doUnloadReq.Value && !DiTrReq)
  846. {
  847. if (_timer_TP1.IsIdle()) _timer_TP1.Start(_scTimeoutTP1.IntValue * 1000);
  848. }
  849. if (DiCS0 && DiValid && _doUnloadReq.Value && DiTrReq && !_doReady.Value)
  850. {
  851. _timer_TP1.Stop();
  852. _doReady.SetValue(true, out _);
  853. EV.Notify(EventE84UnloadTransactionStart, dvid);
  854. if (Provider != null) Provider.OnE84HandoffStart(false, out _);
  855. }
  856. }
  857. if (TransferState == LPTransferState.TRANSFER_BLOCKED && preTranState == LPTransferState.READY_TO_UNLOAD) //Unload Sequence
  858. {
  859. if (DiCS0 && DiValid && _doUnloadReq.Value && DiTrReq && _doReady.Value && !DiBusy)
  860. {
  861. if (_timer_TP2.IsIdle()) _timer_TP2.Start(_scTimeoutTP1.IntValue * 1000);
  862. }
  863. if (DiCS0 && DiValid && _doUnloadReq.Value && DiTrReq && _doReady.Value && DiBusy)
  864. {
  865. _timer_TP2.Stop();
  866. if (IsFoupPresent)
  867. {
  868. if (_timer_TP3.IsIdle()) _timer_TP3.Start(_scTimeoutTP3.IntValue * 1000);
  869. }
  870. else
  871. {
  872. _timer_TP3.Stop();
  873. _doUnloadReq.SetValue(false, out _);
  874. }
  875. }
  876. if (DiCS0 && DiValid && !_doUnloadReq.Value && DiTrReq && _doReady.Value && DiBusy)
  877. {
  878. if (_timer_TP4.IsIdle()) _timer_TP4.Start(_scTimeoutTP4.IntValue * 1000);
  879. }
  880. if (DiCS0 && DiValid && DiTrReq && _doReady.Value && !DiBusy)
  881. {
  882. _timer_TP4.Stop();
  883. }
  884. if (DiCS0 && DiValid && !_doUnloadReq.Value && _doReady.Value && DiCompt)
  885. {
  886. _doReady.SetValue(false, out _);
  887. _timer_TP4.Stop();
  888. if (_timer_TP5.IsIdle()) _timer_TP5.Start(_scTimeoutTP5.IntValue * 1000);
  889. }
  890. if (!DiValid && !_doUnloadReq.Value && !DiTrReq && !_doReady.Value && !DiBusy && !DiCompt)
  891. {
  892. _timer_TP5.Stop();
  893. EV.Notify(EventE84UnloadTransactionComplete, dvid);
  894. preTranState = LPTransferState.TRANSFER_BLOCKED;
  895. if (Provider != null) Provider.OnE84HandoffComplete(false, out _);
  896. }
  897. }
  898. if (_timer_TP1.IsTimeout())
  899. {
  900. if (preTranState == LPTransferState.READY_TO_LOAD)
  901. {
  902. _doLoadReq.SetValue(false, out _);
  903. _doUnloadReq.SetValue(false, out _);
  904. _doReady.SetValue(false, out _);
  905. _doHOAvbl.SetValue(false, out _);
  906. //EV.Notify(EventE84TP1Timeout, dvid);
  907. _state = E84State.LD_TP1_Timeout;
  908. _timer_TP1.Stop();
  909. if (Provider != null) Provider.E84Error(_state.ToString());
  910. }
  911. if (preTranState == LPTransferState.READY_TO_UNLOAD)
  912. {
  913. _doLoadReq.SetValue(false, out _);
  914. _doUnloadReq.SetValue(false, out _);
  915. _doReady.SetValue(false, out _);
  916. _doHOAvbl.SetValue(false, out _);
  917. //EV.Notify(EventE84TP1Timeout, dvid);
  918. _state = E84State.ULD_TP1_Timeout;
  919. if (Provider != null) Provider.E84Error(_state.ToString());
  920. }
  921. _timer_TP1.Stop();
  922. EV.Notify(AlarmTP1timeout);
  923. }
  924. if (_timer_TP2.IsTimeout())
  925. {
  926. if (preTranState == LPTransferState.READY_TO_LOAD)
  927. {
  928. _doLoadReq.SetValue(false, out _);
  929. _doUnloadReq.SetValue(false, out _);
  930. _doReady.SetValue(false, out _);
  931. _doHOAvbl.SetValue(false, out _);
  932. //EV.Notify(EventE84TP2Timeout, dvid);
  933. _state = E84State.LD_TP2_Timeout;
  934. if (Provider != null) Provider.E84Error(_state.ToString());
  935. }
  936. if (preTranState == LPTransferState.READY_TO_UNLOAD)
  937. {
  938. _doLoadReq.SetValue(false, out _);
  939. _doUnloadReq.SetValue(false, out _);
  940. _doReady.SetValue(false, out _);
  941. _doHOAvbl.SetValue(false, out _);
  942. //EV.Notify(EventE84TP2Timeout, dvid);
  943. _state = E84State.ULD_TP2_Timeout;
  944. if (Provider != null) Provider.E84Error(_state.ToString());
  945. }
  946. _timer_TP2.Stop();
  947. EV.Notify(AlarmTP2timeout);
  948. }
  949. if (_timer_TP3.IsTimeout())
  950. {
  951. if (preTranState == LPTransferState.READY_TO_LOAD)
  952. {
  953. _doLoadReq.SetValue(false, out _);
  954. _doUnloadReq.SetValue(false, out _);
  955. _doReady.SetValue(false, out _);
  956. _doHOAvbl.SetValue(false, out _);
  957. //EV.Notify(EventE84TP3Timeout, dvid);
  958. _state = E84State.LD_TP3_Timeout;
  959. if (Provider != null) Provider.E84Error(_state.ToString());
  960. }
  961. if (preTranState == LPTransferState.READY_TO_UNLOAD)
  962. {
  963. _doLoadReq.SetValue(false, out _);
  964. _doUnloadReq.SetValue(false, out _);
  965. _doReady.SetValue(false, out _);
  966. _doHOAvbl.SetValue(false, out _);
  967. //EV.Notify(EventE84TP3Timeout, dvid);
  968. _state = E84State.ULD_TP3_Timeout;
  969. if (Provider != null) Provider.E84Error(_state.ToString());
  970. }
  971. _timer_TP3.Stop();
  972. EV.Notify(AlarmTP3timeout);
  973. }
  974. if (_timer_TP4.IsTimeout())
  975. {
  976. if (preTranState == LPTransferState.READY_TO_LOAD)
  977. {
  978. _doLoadReq.SetValue(false, out _);
  979. _doUnloadReq.SetValue(false, out _);
  980. _doReady.SetValue(false, out _);
  981. _doHOAvbl.SetValue(false, out _);
  982. //EV.Notify(EventE84TP4Timeout, dvid);
  983. _state = E84State.LD_TP4_Timeout;
  984. if (Provider != null) Provider.E84Error(_state.ToString());
  985. }
  986. if (preTranState == LPTransferState.READY_TO_UNLOAD)
  987. {
  988. _doLoadReq.SetValue(false, out _);
  989. _doUnloadReq.SetValue(false, out _);
  990. _doReady.SetValue(false, out _);
  991. _doHOAvbl.SetValue(false, out _);
  992. //EV.Notify(EventE84TP4Timeout, dvid);
  993. _state = E84State.ULD_TP4_Timeout;
  994. if (Provider != null) Provider.E84Error(_state.ToString());
  995. }
  996. _timer_TP4.Stop();
  997. EV.Notify(AlarmTP4timeout);
  998. }
  999. if (_timer_TP5.IsTimeout())
  1000. {
  1001. if (preTranState == LPTransferState.READY_TO_LOAD)
  1002. {
  1003. _doLoadReq.SetValue(false, out _);
  1004. _doUnloadReq.SetValue(false, out _);
  1005. _doReady.SetValue(false, out _);
  1006. _doHOAvbl.SetValue(false, out _);
  1007. //EV.Notify(EventE84TP5Timeout, dvid);
  1008. _state = E84State.LD_TP5_Timeout;
  1009. if (Provider != null) Provider.E84Error(_state.ToString());
  1010. }
  1011. if (preTranState == LPTransferState.READY_TO_UNLOAD)
  1012. {
  1013. _doLoadReq.SetValue(false, out _);
  1014. _doUnloadReq.SetValue(false, out _);
  1015. _doReady.SetValue(false, out _);
  1016. _doHOAvbl.SetValue(false, out _);
  1017. //EV.Notify(EventE84TP5Timeout, dvid);
  1018. _state = E84State.ULD_TP5_Timeout;
  1019. if (Provider != null) Provider.E84Error(_state.ToString());
  1020. }
  1021. _timer_TP5.Stop();
  1022. EV.Notify(AlarmTP5timeout);
  1023. }
  1024. }
  1025. catch (Exception ex)
  1026. {
  1027. LOG.Write(ex);
  1028. }
  1029. return true;
  1030. }
  1031. public void Reset()
  1032. {
  1033. //_doLoadReq.SetValue(false, out _);
  1034. //_doUnloadReq.SetValue(false, out _);
  1035. //_doReady.SetValue(false, out _);
  1036. //_doHOAvbl.SetValue(false, out _);
  1037. //_doES.SetValue(false, out _);
  1038. //_state = E84State.Normal;
  1039. //foreach (var signal in _signals)
  1040. //{
  1041. // signal.Reset();
  1042. //}
  1043. }
  1044. private void RecordSignalChange()
  1045. {
  1046. string tempSignal = $"{Name} E84 signal change to following,Active: Valid:{_diValid.Value}," +
  1047. $"CS0:{_diCS0.Value},TransferRequest:{_diTrReq.Value},Busy:{_diBusy.Value},Complete:{_diCompt.Value}," +
  1048. $"Passive:LoadRequest:{_doLoadReq.Value},UnloadRequest:{_doUnloadReq.Value},Ready:{_doReady.Value}," +
  1049. $"HoAvl:{_doHOAvbl.Value},ES:{_doES.Value},LightCurtain:" +
  1050. $"{(_diLightCurtain == null ? "None" : _diLightCurtain.Value.ToString())}," +
  1051. $"Present Sensor1:{(_diPresent1 == null ? "None" : _diPresent1.Value.ToString())}," +
  1052. $"Present Sensor2:{(_diPresent2 == null ? "None" : _diPresent2.Value.ToString())}," +
  1053. $"Present Sensor3:{(_diPresent3 == null ? "None" : _diPresent3.Value.ToString())}," +
  1054. $"Seat Sensor:{(_diSeat == null ? "None" : _diSeat.Value.ToString())},";
  1055. if (tempSignal != _lastSignalValue)
  1056. {
  1057. _lastSignalValue = tempSignal;
  1058. LOG.Write(_lastSignalValue);
  1059. }
  1060. }
  1061. private void autoRecovery()
  1062. {
  1063. var dvid = new SerializableDictionary<string, object>();
  1064. int portID = 0;
  1065. dvid["PORT_ID"] = int.TryParse(Module.Replace("LP", ""), out portID) ? portID : portID;
  1066. switch (_state)
  1067. {
  1068. case E84State.Error:
  1069. break;
  1070. case E84State.LD_TP1_Timeout:
  1071. if (IsFoupPresent) EV.Notify(EventE84LoadTransactionComplete, dvid);
  1072. else EV.Notify(EventE84LoadTransactionRestart, dvid);
  1073. ResetSignal();
  1074. break;
  1075. case E84State.LD_TP2_Timeout:
  1076. if (IsFoupPresent) EV.Notify(EventE84LoadTransactionComplete, dvid);
  1077. else EV.Notify(EventE84LoadTransactionRestart, dvid);
  1078. ResetSignal();
  1079. break;
  1080. case E84State.LD_TP3_Timeout:
  1081. if (IsFoupPresent) EV.Notify(EventE84LoadTransactionComplete, dvid);
  1082. else EV.Notify(EventE84LoadTransactionRestart, dvid);
  1083. ResetSignal();
  1084. break;
  1085. case E84State.LD_TP4_Timeout:
  1086. if (IsFoupPresent) EV.Notify(EventE84LoadTransactionComplete, dvid);
  1087. else EV.Notify(EventE84LoadTransactionRestart, dvid);
  1088. ResetSignal();
  1089. break;
  1090. case E84State.LD_TP5_Timeout:
  1091. if (!IsFoupPresent) EV.Notify(EventE84LoadTransactionComplete, dvid);
  1092. else EV.Notify(EventE84LoadTransactionRestart, dvid);
  1093. ResetSignal();
  1094. break;
  1095. case E84State.ULD_TP1_Timeout:
  1096. if (!IsFoupPresent) EV.Notify(EventE84UnloadTransactionComplete, dvid);
  1097. else EV.Notify(EventE84UnloadTransactionRestart, dvid);
  1098. ResetSignal();
  1099. break;
  1100. case E84State.ULD_TP2_Timeout:
  1101. if (!IsFoupPresent) EV.Notify(EventE84UnloadTransactionComplete, dvid);
  1102. else EV.Notify(EventE84UnloadTransactionRestart, dvid);
  1103. ResetSignal();
  1104. break;
  1105. case E84State.ULD_TP3_Timeout:
  1106. if (!IsFoupPresent) EV.Notify(EventE84UnloadTransactionComplete, dvid);
  1107. else EV.Notify(EventE84UnloadTransactionRestart, dvid);
  1108. ResetSignal();
  1109. break;
  1110. case E84State.ULD_TP4_Timeout:
  1111. if (!IsFoupPresent) EV.Notify(EventE84UnloadTransactionComplete, dvid);
  1112. else EV.Notify(EventE84UnloadTransactionRestart, dvid);
  1113. ResetSignal();
  1114. break;
  1115. case E84State.ULD_TP5_Timeout:
  1116. if (!IsFoupPresent) EV.Notify(EventE84UnloadTransactionComplete, dvid);
  1117. else EV.Notify(EventE84UnloadTransactionRestart, dvid);
  1118. ResetSignal();
  1119. break;
  1120. default: break;
  1121. }
  1122. ResetSignal();
  1123. }
  1124. private void OnSignalChange(SignalID signal, bool value)
  1125. {
  1126. }
  1127. public void Monitor()
  1128. {
  1129. }
  1130. }
  1131. }