IoEfemE84.cs 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing.Text;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Xml;
  8. using Aitex.Core.Common.DeviceData;
  9. using Aitex.Core.RT.DataCenter;
  10. using Aitex.Core.RT.Device;
  11. using Aitex.Core.RT.Device.Unit;
  12. using Aitex.Core.RT.Event;
  13. using Aitex.Core.RT.IOCore;
  14. using Aitex.Core.RT.Log;
  15. using Aitex.Core.RT.OperationCenter;
  16. using Aitex.Core.RT.SCCore;
  17. using Aitex.Core.Util;
  18. using MECF.Framework.Common.Equipment;
  19. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  20. namespace Aitex.Core.RT.Device.Unit
  21. {
  22. public enum E84SignalType
  23. {
  24. Acitvie,
  25. Passive,
  26. }
  27. public enum E84SignalID
  28. {
  29. LightCurtain,
  30. CS_0,
  31. CS_1,
  32. AM_AVBL,
  33. VALID,
  34. TR_REQ,
  35. BUSY,
  36. COMPT,
  37. CONT,
  38. L_REQ,
  39. U_REQ,
  40. HO_AVBL,
  41. READY,
  42. ES
  43. }
  44. public class E84Signal
  45. {
  46. public bool Value
  47. {
  48. get
  49. {
  50. if (_di != null)
  51. return _di.Value;
  52. if (_do != null)
  53. return _do.Value;
  54. return false;
  55. }
  56. }
  57. private E84SignalID _id;
  58. private RD_TRIG _trig = new RD_TRIG();
  59. private DIAccessor _di = null;
  60. private DOAccessor _do = null;
  61. public event Action<E84SignalID, bool> OnChanged;
  62. public E84Signal(E84SignalID id, DIAccessor diAccessor, DOAccessor doAccessor)
  63. {
  64. _id = id;
  65. _di = diAccessor;
  66. _do = doAccessor;
  67. }
  68. public void Monitor()
  69. {
  70. if (_di != null)
  71. _trig.CLK = _di.Value;
  72. if (_do != null)
  73. _trig.CLK = _do.Value;
  74. if (_trig.R)
  75. {
  76. if (OnChanged != null)
  77. OnChanged(_id, true);
  78. }
  79. if (_trig.T)
  80. {
  81. if (OnChanged != null)
  82. OnChanged(_id, false);
  83. }
  84. }
  85. public void Reset()
  86. {
  87. _trig.RST = true;
  88. }
  89. }
  90. public class IOE84Passive : BaseDevice, IDevice, IE84CallBack
  91. {
  92. public event Action<string> OnE84HandOffStart;
  93. public event Action<string> OnE84HandOffComplete;
  94. public event Action<E84Timeout, string> OnE84HandOffTimeout;
  95. public event Action<E84SignalID, bool> OnE84ActiveSignalChange;
  96. public event Action<E84SignalID, bool> OnE84PassiveSignalChange;
  97. private List<E84Signal> _signals = new List<E84Signal>();
  98. public IOE84Passive(string module, string name, string display, string deviceId, bool IsfoupPresent,bool IsTransferReady,
  99. DIAccessor[] activesignals, DOAccessor[] passivesignals)
  100. {
  101. Module = module;
  102. Name = name;
  103. //_moduleName = (ModuleName)Enum.Parse(typeof(ModuleName), Name);
  104. Display = display;
  105. DeviceID = deviceId;
  106. _diValid = activesignals[0];
  107. _diCS0 = activesignals[1];
  108. _diTrReq = activesignals[2];
  109. _diBusy = activesignals[3];
  110. _diCompt = activesignals[4];
  111. _diCS1 = activesignals.Length >5? activesignals[5]:null;
  112. _diCont = activesignals.Length > 6 ? activesignals[6] : null;
  113. _diAmAvbl = activesignals.Length > 7 ? activesignals[7] : null;
  114. _doLoadReq = passivesignals[0];
  115. _doUnloadReq = passivesignals[1];
  116. _doReady = passivesignals[2];
  117. _doHOAvbl = passivesignals[3];
  118. _doES = passivesignals[4];
  119. _isFoupON = IsfoupPresent;
  120. _isTransferReady = IsTransferReady;
  121. SubscribeData();
  122. }
  123. private void SubscribeData()
  124. {
  125. DATA.Subscribe($"{Module}.{Name}.E84State", () => _state.ToString());
  126. DATA.Subscribe($"{Module}.{Name}.AlwaysOn", () => _diAlwaysOn==null? true:_diAlwaysOn.Value);
  127. DATA.Subscribe($"{Module}.{Name}.Valid", () => _diValid.Value);
  128. DATA.Subscribe($"{Module}.{Name}.TransferRequest", () => _diTrReq.Value);
  129. DATA.Subscribe($"{Module}.{Name}.Busy", () => _diBusy.Value);
  130. DATA.Subscribe($"{Module}.{Name}.TransferComplete", () => _diCompt.Value);
  131. DATA.Subscribe($"{Module}.{Name}.CS0", () => _diCS0.Value);
  132. DATA.Subscribe($"{Module}.{Name}.CS1", () => _diCS1 == null ? false : _diCS1.Value);
  133. DATA.Subscribe($"{Module}.{Name}.CONT", () => _diCont == null ? false : _diCont.Value);
  134. DATA.Subscribe($"{Module}.{Name}.LoadRequest", () => _doLoadReq.Value);
  135. DATA.Subscribe($"{Module}.{Name}.UnloadRequest", () => _doUnloadReq.Value);
  136. DATA.Subscribe($"{Module}.{Name}.ReadyToTransfer", () => _doReady.Value);
  137. DATA.Subscribe($"{Module}.{Name}.HandoffAvailable", () => _doHOAvbl.Value);
  138. DATA.Subscribe($"{Module}.{Name}.ES", () => _doES.Value);
  139. DATA.Subscribe($"{Module}.E84State", () => _state.ToString());
  140. DATA.Subscribe($"{Module}.Valid", () => _diValid.Value);
  141. DATA.Subscribe($"{Module}.TransferRequest", () => _diTrReq.Value);
  142. DATA.Subscribe($"{Module}.Busy", () => _diBusy.Value);
  143. DATA.Subscribe($"{Module}.TransferComplete", () => _diCompt.Value);
  144. DATA.Subscribe($"{Module}.CS0", () => _diCS0.Value);
  145. DATA.Subscribe($"{Module}.CS1", () => _diCS1 == null ? false : _diCS1.Value);
  146. DATA.Subscribe($"{Module}.CONT", () => _diCont == null ? false : _diCont.Value);
  147. DATA.Subscribe($"{Module}.LoadRequest", () => _doLoadReq.Value);
  148. DATA.Subscribe($"{Module}.UnloadRequest", () => _doUnloadReq.Value);
  149. DATA.Subscribe($"{Module}.ReadyToTransfer", () => _doReady.Value);
  150. DATA.Subscribe($"{Module}.HandoffAvailable", () => _doHOAvbl.Value);
  151. DATA.Subscribe($"{Module}.ES", () => _doES.Value);
  152. DATA.Subscribe($"{Module}.{Name}.E84Mode", () => IsAutoMode ? "Auto" : "Manual");
  153. OP.Subscribe(String.Format("{0}.{1}", Module, "SetE84Auto"), (out string reason, int time, object[] param) =>
  154. {
  155. SetHoAutoControl(true);
  156. reason = "";
  157. return true;
  158. });
  159. OP.Subscribe(String.Format("{0}.{1}", Module, "SetE84Manual"), (out string reason, int time, object[] param) =>
  160. {
  161. SetHoAutoControl(false);
  162. reason = "";
  163. return true;
  164. });
  165. OP.Subscribe(String.Format("{0}.{1}", Module, "TransReq"), (out string reason, int time, object[] param) =>
  166. {
  167. if (param[0].ToString() == "Load" && _isFoupON)
  168. {
  169. reason = "Can't load, foup is on";
  170. EV.PostAlarmLog(Module, "Can start E84 load, foup is On");
  171. return false;
  172. }
  173. if (param[0].ToString() == "Unload" && !_isFoupON)
  174. {
  175. reason = "Can't unload, foup is off";
  176. EV.PostAlarmLog(Module, "Can start E84 unload, foup is Off");
  177. return false;
  178. }
  179. SetHoAvailable(true);
  180. reason = "";
  181. return true;
  182. });
  183. OP.Subscribe(String.Format("{0}.{1}", Module, "TransStop"), (out string reason, int time, object[] param) =>
  184. {
  185. Stop();
  186. reason = "";
  187. return true;
  188. });
  189. _signals.Add(new E84Signal(E84SignalID.LightCurtain, _diLightCurtain, null));
  190. _signals.Add(new E84Signal(E84SignalID.VALID, _diValid, null));
  191. _signals.Add(new E84Signal(E84SignalID.CS_0, _diCS0, null));
  192. _signals.Add(new E84Signal(E84SignalID.CS_1, _diCS1, null));
  193. _signals.Add(new E84Signal(E84SignalID.AM_AVBL, _diAmAvbl, null));
  194. _signals.Add(new E84Signal(E84SignalID.TR_REQ, _diTrReq, null));
  195. _signals.Add(new E84Signal(E84SignalID.BUSY, _diBusy, null));
  196. _signals.Add(new E84Signal(E84SignalID.CONT, _diCont, null));
  197. _signals.Add(new E84Signal(E84SignalID.L_REQ, null, _doLoadReq));
  198. _signals.Add(new E84Signal(E84SignalID.U_REQ, null, _doUnloadReq));
  199. _signals.Add(new E84Signal(E84SignalID.READY, null, _doReady));
  200. _signals.Add(new E84Signal(E84SignalID.HO_AVBL, null, _doHOAvbl));
  201. _signals.Add(new E84Signal(E84SignalID.ES, null, _doES));
  202. foreach (var signal in _signals)
  203. {
  204. signal.OnChanged += OnSignalChange;
  205. }
  206. }
  207. public IOE84Passive(string module, XmlElement node, string ioModule = "")
  208. {
  209. base.Module = node.GetAttribute("module");
  210. base.Name = node.GetAttribute("id");
  211. base.Display = node.GetAttribute("display");
  212. base.DeviceID = node.GetAttribute("schematicId");
  213. ioModule = node.GetAttribute("ioModule");
  214. _diAlwaysOn = ParseDiNode("ALWAYS_ON", node, ioModule);
  215. _diLightCurtain = ParseDiNode("LightCurtain", node, ioModule);
  216. //Indicates that the signal transition is active and selected
  217. //ON: valid; OFF: not valid
  218. _diValid = ParseDiNode("VALID", node, ioModule);
  219. //Carrier stage 0
  220. //ON: Use the load port for carrier handoff; vice versa
  221. _diCS0 = ParseDiNode("CS_0", node, ioModule);
  222. //Carrier stage 1
  223. //ON: Use the load port for carrier handoff; vice versa
  224. _diCS1 = ParseDiNode("CS_1", node, ioModule);
  225. //Transfer Arm Available
  226. //ON: Handoff is available; OFF: Handoff is unavailable with any error
  227. _diAmAvbl = ParseDiNode("AM_AVBL", node, ioModule);
  228. //Transfer Request
  229. //ON: Request Handoff; vice versa
  230. _diTrReq = ParseDiNode("TR_REQ", node, ioModule);
  231. //BUSY for transfer
  232. //ON: Handoff is in progress; vice versa
  233. _diBusy = ParseDiNode("BUSY", node, ioModule);
  234. //Complete Transfer
  235. //ON:The handoff is completed; vice versa
  236. _diCompt = ParseDiNode("COMPT", node, ioModule);
  237. _signals.Add(new E84Signal(E84SignalID.COMPT, _diCompt, null));
  238. //Continuous Handoff
  239. //ON: Continuous Handoff; vice versa
  240. _diCont = ParseDiNode("CONT", node, ioModule);
  241. //Load Request
  242. //ON: The load port is assigned to load a carrier; vice versa
  243. //CS_0 && VALID && !CarrierLoaded
  244. _doLoadReq = ParseDoNode("L_REQ", node, ioModule);
  245. //Unload Request
  246. //ON: The load port is assigned to unload a carrier; vice versa
  247. //CS_0 && VALID && !CarrierUnloaded
  248. _doUnloadReq = ParseDoNode("U_REQ", node, ioModule);
  249. //READY for transfer(after accepted the transfer request set ON, turned OFF when COMPT ON)
  250. //ON: Ready for handoff; vice versa
  251. _doReady = ParseDoNode("READY", node, ioModule);
  252. //Indicates the passive equipment is not available for the handoff.
  253. //ON: Handoff is available; OFF: vice versa but with error
  254. //ON when normal; OFF when : Maintenance mode / Error State
  255. _doHOAvbl = ParseDoNode("HO_AVBL", node, ioModule);
  256. //Emergency stop
  257. _doES = ParseDoNode("ES", node, ioModule);
  258. SubscribeData();
  259. }
  260. private void OnSignalChange(E84SignalID arg1, bool arg2)
  261. {
  262. if((int)arg1 >=0 && (int)arg1<=8 && OnE84ActiveSignalChange!=null)
  263. {
  264. OnE84ActiveSignalChange(arg1, arg2);
  265. }
  266. if((int)arg1 > 8 && OnE84PassiveSignalChange!=null)
  267. OnE84PassiveSignalChange(arg1, arg2);
  268. }
  269. public enum E84State
  270. {
  271. Complete,
  272. Idle,
  273. Busy,
  274. LD_TP1_Timeout,
  275. LD_TP2_Timeout,
  276. LD_TP3_Timeout,
  277. LD_TP4_Timeout,
  278. LD_TP5_Timeout,
  279. LD_TP6_Timeout,
  280. ULD_TP1_Timeout,
  281. ULD_TP2_Timeout,
  282. ULD_TP3_Timeout,
  283. ULD_TP4_Timeout,
  284. ULD_TP5_Timeout,
  285. ULD_TP6_Timeout,
  286. Error,
  287. Stop,
  288. }
  289. public enum E84Timeout
  290. {
  291. TP1,
  292. TP2,
  293. TP3,
  294. TP4,
  295. TP5,
  296. }
  297. public enum E84ActiveSignal
  298. {
  299. Valid,
  300. CS0,
  301. CS1,
  302. TrReq,
  303. Busy,
  304. Compt,
  305. Cont,
  306. AmAvble,
  307. }
  308. public enum E84PassiveSignal
  309. {
  310. LoadReq,
  311. UnloadReq,
  312. Ready,
  313. HOAvbl,
  314. ES,
  315. }
  316. private DIAccessor _diAlwaysOn;
  317. public DIAccessor DiAlwaysOn => _diAlwaysOn;
  318. private DIAccessor _diValid;
  319. private DIAccessor _diCS0;
  320. private DIAccessor _diCS1;
  321. private DIAccessor _diTrReq;
  322. private DIAccessor _diBusy;
  323. private DIAccessor _diCompt;
  324. private DIAccessor _diCont;
  325. private DIAccessor _diAmAvbl;
  326. private DIAccessor _diLightCurtain;
  327. private DOAccessor _doLoadReq;
  328. private DOAccessor _doUnloadReq;
  329. private DOAccessor _doReady;
  330. private DOAccessor _doHOAvbl;
  331. private DOAccessor _doES;
  332. private bool _isFoupON;
  333. private bool _isTransferReady;
  334. //Active equipment signal
  335. private DeviceTimer _timer = new DeviceTimer();
  336. private DeviceTimer _timer_TP1 = new DeviceTimer();
  337. private DeviceTimer _timer_TP2 = new DeviceTimer();
  338. private DeviceTimer _timer_TP3 = new DeviceTimer();
  339. private DeviceTimer _timer_TP4 = new DeviceTimer();
  340. private DeviceTimer _timer_TP5 = new DeviceTimer();
  341. private DeviceTimer _timer_TP6 = new DeviceTimer();
  342. //private ModuleName _moduleName;
  343. //timeout
  344. private int _tp1
  345. {
  346. get
  347. {
  348. if (SC.ContainsItem("FA.E84.TP1"))
  349. return SC.GetValue<int>("FA.E84.TP1");
  350. return 2;
  351. }
  352. }
  353. private int _tp2
  354. {
  355. get
  356. {
  357. if (SC.ContainsItem("FA.E84.TP2"))
  358. return SC.GetValue<int>("FA.E84.TP2");
  359. return 2;
  360. }
  361. }
  362. private int _tp3
  363. {
  364. get
  365. {
  366. if (SC.ContainsItem("FA.E84.TP3"))
  367. return SC.GetValue<int>("FA.E84.TP3");
  368. return 60;
  369. }
  370. }
  371. private int _tp4
  372. {
  373. get
  374. {
  375. if (SC.ContainsItem("FA.E84.TP4"))
  376. return SC.GetValue<int>("FA.E84.TP4");
  377. return 60;
  378. }
  379. }
  380. private int _tp5
  381. {
  382. get
  383. {
  384. if (SC.ContainsItem("FA.E84.TP5"))
  385. return SC.GetValue<int>("FA.E84.TP5");
  386. return 2;
  387. }
  388. }
  389. private int _tp6
  390. {
  391. get
  392. {
  393. if (SC.ContainsItem("FA.E84.TP6"))
  394. return SC.GetValue<int>("FA.E84.TP6");
  395. return 2;
  396. }
  397. }
  398. private bool _isAutoMode = false;
  399. public bool IsAutoMode
  400. {
  401. get => _isAutoMode;
  402. set { _isAutoMode = value; }
  403. }
  404. private E84State _state;
  405. public E84State State { get => _state; }
  406. private LPTransferState _currentTState = LPTransferState.No_state;
  407. #region E84Interface
  408. public void SetHoAutoControl(bool value)
  409. {
  410. IsAutoMode = value;
  411. }
  412. public void SetHoAvailable(bool value)
  413. {
  414. if (value)
  415. {
  416. _state = E84State.Idle;
  417. }
  418. else
  419. _state = E84State.Complete;
  420. }
  421. public bool GetE84SignalState(E84SignalID signal)
  422. {
  423. switch(signal)
  424. {
  425. case E84SignalID.AM_AVBL:
  426. return _diAmAvbl.Value;
  427. case E84SignalID.BUSY:
  428. return _diBusy.Value;
  429. case E84SignalID.COMPT:
  430. return _diCompt.Value;
  431. case E84SignalID.CONT:
  432. return _diCont.Value;
  433. case E84SignalID.CS_0:
  434. return _diCS0.Value;
  435. case E84SignalID.CS_1:
  436. return _diCS1.Value;
  437. case E84SignalID.ES:
  438. return _doES.Value;
  439. case E84SignalID.HO_AVBL:
  440. return _doHOAvbl.Value;
  441. case E84SignalID.LightCurtain:
  442. return (_diLightCurtain == null) ? false: _diLightCurtain.Value;
  443. case E84SignalID.L_REQ:
  444. return _doLoadReq.Value;
  445. case E84SignalID.READY:
  446. return _doReady.Value;
  447. case E84SignalID.TR_REQ:
  448. return _diTrReq.Value;
  449. case E84SignalID.U_REQ:
  450. return _doUnloadReq.Value;
  451. case E84SignalID.VALID:
  452. return _diValid.Value;
  453. default:
  454. return false;
  455. }
  456. }
  457. public void SetFoupStatus(bool isfoupon)
  458. {
  459. _isFoupON = isfoupon; ;
  460. }
  461. public void SetReadyTransferStatus(bool ready)
  462. {
  463. _isTransferReady = ready;
  464. }
  465. public void SetE84SignalState(E84PassiveSignal signal, bool value)
  466. {
  467. switch(signal)
  468. {
  469. case E84PassiveSignal.ES:
  470. _doES.SetValue(value,out _);
  471. break;
  472. case E84PassiveSignal.HOAvbl:
  473. _doHOAvbl.SetValue(value, out _);
  474. break;
  475. case E84PassiveSignal.LoadReq:
  476. _doLoadReq.SetValue(value, out _);
  477. break;
  478. case E84PassiveSignal.Ready:
  479. _doReady.SetValue(value, out _);
  480. break;
  481. case E84PassiveSignal.UnloadReq:
  482. _doUnloadReq.SetValue(value, out _);
  483. break;
  484. default:
  485. break;
  486. }
  487. }
  488. #endregion
  489. public void Stop()
  490. {
  491. _doLoadReq.SetValue(false, out _);
  492. _doUnloadReq.SetValue(false, out _);
  493. _doReady.SetValue(false, out _);
  494. _doHOAvbl.SetValue(false, out _);
  495. _doES.SetValue(false, out _);
  496. _timer_TP1.Stop();
  497. _timer_TP2.Stop();
  498. _timer_TP3.Stop();
  499. _timer_TP4.Stop();
  500. _timer_TP5.Stop();
  501. _state = E84State.Stop;
  502. }
  503. public void Complete()
  504. {
  505. _doLoadReq.SetValue(false, out _);
  506. _doUnloadReq.SetValue(false, out _);
  507. _doReady.SetValue(false, out _);
  508. _doHOAvbl.SetValue(true, out _);
  509. _doES.SetValue(true, out _);
  510. _timer_TP1.Stop();
  511. _timer_TP2.Stop();
  512. _timer_TP3.Stop();
  513. _timer_TP4.Stop();
  514. _timer_TP5.Stop();
  515. _state = E84State.Complete;
  516. }
  517. public bool Initialize()
  518. {
  519. //reset();
  520. return true;
  521. }
  522. public void Terminate()
  523. {
  524. _doLoadReq.SetValue(false, out _);
  525. _doUnloadReq.SetValue(false, out _);
  526. _doReady.SetValue(false, out _);
  527. _doHOAvbl.SetValue(true, out _);
  528. _doES.SetValue(true, out _);
  529. _timer_TP1.Stop();
  530. _timer_TP2.Stop();
  531. _timer_TP3.Stop();
  532. _timer_TP4.Stop();
  533. _timer_TP5.Stop();
  534. }
  535. private void reset()
  536. {
  537. _doLoadReq.SetValue(false, out _);
  538. _doUnloadReq.SetValue(false, out _);
  539. _doReady.SetValue(false, out _);
  540. _doHOAvbl.SetValue(false, out _);
  541. _doES.SetValue(false, out _);
  542. _timer_TP1.Stop();
  543. _timer_TP2.Stop();
  544. _timer_TP3.Stop();
  545. _timer_TP4.Stop();
  546. _timer_TP5.Stop();
  547. _state = E84State.Idle;
  548. }
  549. public void Monitor()
  550. {
  551. try
  552. {
  553. foreach (var signal in _signals)
  554. {
  555. signal.Monitor();
  556. }
  557. if (IsAutoMode)
  558. {
  559. if (State == E84State.Complete)
  560. _state = E84State.Idle;
  561. }
  562. if(State == E84State.LD_TP1_Timeout || State == E84State.LD_TP2_Timeout || State == E84State.LD_TP5_Timeout
  563. ||State == E84State.ULD_TP1_Timeout || State == E84State.ULD_TP2_Timeout || State == E84State.ULD_TP5_Timeout)
  564. {
  565. if (!_diCS0.Value && !_diValid.Value)
  566. _state = E84State.Idle;
  567. }
  568. if (State == E84State.Idle)
  569. {
  570. if (_isFoupON && _isTransferReady) _currentTState = LPTransferState.READY_TO_UNLOAD;
  571. if (!_isFoupON && _isTransferReady) _currentTState = LPTransferState.READY_TO_LOAD;
  572. }
  573. if(State == E84State.Stop)
  574. {
  575. _doES.SetValue(false, out _);
  576. return;
  577. }
  578. if (State == E84State.Complete || !_isTransferReady)
  579. {
  580. _doES.SetValue(true, out _);
  581. _doHOAvbl.SetValue(true, out _);
  582. return;
  583. }
  584. if (_currentTState != LPTransferState.READY_TO_LOAD &&
  585. _currentTState != LPTransferState.READY_TO_UNLOAD)
  586. {
  587. _doLoadReq.SetValue(false, out _);
  588. _doUnloadReq.SetValue(false, out _);
  589. _doReady.SetValue(false, out _);
  590. _doHOAvbl.SetValue(true, out _);
  591. _doES.SetValue(true, out _);
  592. _timer_TP1.Stop();
  593. _timer_TP2.Stop();
  594. _timer_TP3.Stop();
  595. _timer_TP4.Stop();
  596. _timer_TP5.Stop();
  597. _timer_TP6.Stop();
  598. return;
  599. }
  600. bool divalid = _diValid.Value;
  601. bool dics0 = _diCS0.Value;
  602. bool diTrReq = _diTrReq.Value;
  603. bool diBusy = _diBusy.Value;
  604. bool dicompt = _diCompt.Value;
  605. bool doloadreq = _doLoadReq.Value;
  606. bool dounloadreq = _doUnloadReq.Value;
  607. bool doready = _doReady.Value;
  608. bool doHOavbl = _doHOAvbl.Value;
  609. bool doES = _doES.Value;
  610. if (_state != E84State.Idle && _state != E84State.Busy) return;
  611. _doES.SetValue(true,out _);
  612. if (_currentTState == LPTransferState.READY_TO_LOAD)
  613. {
  614. if (!_isFoupON)
  615. {
  616. _doHOAvbl.SetValue(true, out _);
  617. if (_state == E84State.Idle)
  618. {
  619. _doLoadReq.SetValue(false, out _);
  620. _doUnloadReq.SetValue(false, out _);
  621. _doReady.SetValue(false, out _);
  622. _doHOAvbl.SetValue(true, out _);
  623. _doES.SetValue(true, out _);
  624. if (dics0 && divalid && !doloadreq)
  625. {
  626. EV.PostInfoLog("E84", $"{Name} E84 set load request.");
  627. _doLoadReq.SetValue(true, out _);
  628. _state = E84State.Busy;
  629. if (OnE84HandOffStart != null)
  630. OnE84HandOffStart("Load");
  631. }
  632. }
  633. if (_state == E84State.Busy)
  634. {
  635. if (dics0 && divalid && doloadreq && !diTrReq)
  636. {
  637. if (_timer_TP1.IsIdle())
  638. _timer_TP1.Start(_tp1 * 1000);
  639. }
  640. if (dics0 && divalid && doloadreq && diTrReq && !doready)
  641. {
  642. EV.PostInfoLog("E84", $"{Name} E84 set ready.");
  643. _timer_TP1.Stop();
  644. _doReady.SetValue(true, out _);
  645. if (_timer_TP2.IsIdle())
  646. _timer_TP2.Start(_tp2 * 1000);
  647. }
  648. if (dics0 && divalid && doloadreq && diTrReq && doready && diBusy)
  649. {
  650. _timer_TP2.Stop();
  651. if (_timer_TP3.IsIdle())
  652. _timer_TP3.Start(_tp3 * 1000);
  653. }
  654. }
  655. }
  656. if (_isFoupON && _state == E84State.Busy)
  657. {
  658. _doLoadReq.SetValue(false,out _);
  659. _timer_TP2.Stop();
  660. _timer_TP3.Stop();
  661. if (dics0 && divalid && !doloadreq && diTrReq && doready && diBusy)
  662. {
  663. if (_timer_TP4.IsIdle())
  664. _timer_TP4.Start(_tp4 * 1000);
  665. }
  666. if (dics0 && divalid && !doloadreq && doready && !diBusy)
  667. {
  668. _timer_TP4.Stop();
  669. }
  670. if (dics0 && divalid && !doloadreq && doready && dicompt)
  671. {
  672. EV.PostInfoLog("E84", $"{Name} E84 set ready off.");
  673. _doReady.SetValue( false,out _);
  674. _timer_TP4.Stop();
  675. if (_timer_TP5.IsIdle())
  676. _timer_TP5.Start(_tp5 * 1000);
  677. }
  678. if (!dics0 && !doloadreq && !dounloadreq && !diTrReq && !doready && !diBusy && !dicompt)
  679. {
  680. EV.PostInfoLog("E84", $"{Name} E84 load transaction completed.");
  681. _timer_TP5.Stop();
  682. _doHOAvbl.SetValue(true,out _);
  683. _state = E84State.Complete;
  684. _currentTState = LPTransferState.No_state;
  685. OnE84HandOffComplete?.Invoke("Load");
  686. }
  687. }
  688. }
  689. if (_currentTState == LPTransferState.READY_TO_UNLOAD)
  690. {
  691. if (_isFoupON)
  692. {
  693. if (_state == E84State.Idle)
  694. {
  695. _doLoadReq.SetValue(false, out _);
  696. _doUnloadReq.SetValue(false, out _);
  697. _doReady.SetValue(false, out _);
  698. _doHOAvbl.SetValue(true, out _);
  699. _doES.SetValue(true, out _);
  700. }
  701. _doHOAvbl.SetValue(true,out _);
  702. if (dics0 && divalid && !dounloadreq)
  703. {
  704. EV.PostInfoLog("E84", $"{Name} E84 set unload request.");
  705. _doUnloadReq.SetValue(true,out _);
  706. _state = E84State.Busy;
  707. if (OnE84HandOffStart != null)
  708. OnE84HandOffStart("Unload");
  709. }
  710. if (dics0 && divalid && dounloadreq && !diTrReq)
  711. {
  712. if (_timer_TP1.IsIdle())
  713. _timer_TP1.Start(_tp1 * 1000);
  714. }
  715. if (dics0 && divalid && dounloadreq && diTrReq && !doready)
  716. {
  717. _timer_TP1.Stop();
  718. EV.PostInfoLog("E84", $"{Name} E84 set ready.");
  719. _doReady.SetValue(true,out _);
  720. if (_timer_TP2.IsIdle())
  721. _timer_TP2.Start(_tp2 * 1000);
  722. }
  723. if (dics0 && divalid && dounloadreq && diTrReq && doready && diBusy)
  724. {
  725. _timer_TP2.Stop();
  726. if (_timer_TP3.IsIdle())
  727. _timer_TP3.Start(_tp3 * 1000);
  728. }
  729. }
  730. if ((!_isFoupON) && _state == E84State.Busy)
  731. {
  732. _doUnloadReq.SetValue(false,out _);
  733. if (dics0 && divalid && diTrReq && doready && diBusy)
  734. {
  735. EV.PostInfoLog("E84", $"{Name} E84 set unload request off.");
  736. _timer_TP2.Stop();
  737. _timer_TP3.Stop();
  738. if (_timer_TP4.IsIdle())
  739. _timer_TP4.Start(_tp4 * 1000);
  740. }
  741. if (dics0 && divalid && !dounloadreq && doready && !diBusy)
  742. {
  743. _timer_TP4.Stop();
  744. }
  745. if (dics0 && divalid && !dounloadreq && doready && dicompt)
  746. {
  747. EV.PostInfoLog("E84", $"{Name} E84 set ready off.");
  748. _doReady.SetValue(false,out _);
  749. _timer_TP4.Stop();
  750. if (_timer_TP5.IsIdle())
  751. _timer_TP5.Start(_tp5 * 1000);
  752. }
  753. if (!divalid && !dounloadreq && !diTrReq && !doready && !diBusy && !dicompt)
  754. {
  755. _timer_TP5.Stop();
  756. EV.PostInfoLog("E84", $"{Name} E84 unload transaction completed.");
  757. _state = E84State.Complete;
  758. _currentTState = LPTransferState.No_state;
  759. OnE84HandOffComplete?.Invoke("Unload");
  760. }
  761. }
  762. }
  763. MonitorTimeout();
  764. }
  765. catch (Exception ex)
  766. {
  767. LOG.Write(ex);
  768. }
  769. }
  770. private void MonitorTimeout()
  771. {
  772. if (_timer_TP1.IsTimeout())
  773. {
  774. if (_currentTState == LPTransferState.READY_TO_LOAD)
  775. {
  776. _doLoadReq.Value = false;
  777. _doUnloadReq.Value = false;
  778. _doReady.Value = false;
  779. _doHOAvbl.Value = false;
  780. _state = E84State.LD_TP1_Timeout;
  781. if (OnE84HandOffTimeout != null)
  782. OnE84HandOffTimeout(E84Timeout.TP1, "Load");
  783. }
  784. if (_currentTState == LPTransferState.READY_TO_UNLOAD)
  785. {
  786. _doLoadReq.Value = false;
  787. _doUnloadReq.Value = false;
  788. _doReady.Value = false;
  789. _doHOAvbl.Value = false;
  790. _state = E84State.ULD_TP1_Timeout;
  791. if (OnE84HandOffTimeout != null)
  792. OnE84HandOffTimeout(E84Timeout.TP1, "Unload");
  793. }
  794. _timer_TP1.Stop();
  795. }
  796. if (_timer_TP2.IsTimeout())
  797. {
  798. if (_currentTState == LPTransferState.READY_TO_LOAD)
  799. {
  800. _doLoadReq.Value = false;
  801. _doUnloadReq.Value = false;
  802. _doReady.Value = false;
  803. _doHOAvbl.Value = false;
  804. _state = E84State.LD_TP2_Timeout;
  805. if (OnE84HandOffTimeout != null)
  806. OnE84HandOffTimeout(E84Timeout.TP2, "Load");
  807. }
  808. if (_currentTState == LPTransferState.READY_TO_UNLOAD)
  809. {
  810. _doLoadReq.Value = false;
  811. _doUnloadReq.Value = false;
  812. _doReady.Value = false;
  813. _doHOAvbl.Value = false;
  814. _state = E84State.ULD_TP2_Timeout;
  815. if (OnE84HandOffTimeout != null)
  816. OnE84HandOffTimeout( E84Timeout.TP2, "Unload");
  817. }
  818. _timer_TP2.Stop();
  819. }
  820. if (_timer_TP3.IsTimeout())
  821. {
  822. if (_currentTState == LPTransferState.READY_TO_LOAD)
  823. {
  824. _doLoadReq.Value = false;
  825. _doUnloadReq.Value = false;
  826. _doReady.Value = false;
  827. _doHOAvbl.Value = false;
  828. _state = E84State.LD_TP3_Timeout;
  829. if (OnE84HandOffTimeout != null)
  830. OnE84HandOffTimeout( E84Timeout.TP3, "Load");
  831. }
  832. if (_currentTState == LPTransferState.READY_TO_UNLOAD)
  833. {
  834. _doLoadReq.Value = false;
  835. _doUnloadReq.Value = false;
  836. _doReady.Value = false;
  837. _doHOAvbl.Value = false;
  838. _state = E84State.ULD_TP3_Timeout;
  839. if (OnE84HandOffTimeout != null)
  840. OnE84HandOffTimeout( E84Timeout.TP3, "Unload");
  841. }
  842. _timer_TP3.Stop();
  843. }
  844. if (_timer_TP4.IsTimeout())
  845. {
  846. if (_currentTState == LPTransferState.READY_TO_LOAD)
  847. {
  848. _doLoadReq.Value = false;
  849. _doUnloadReq.Value = false;
  850. _doReady.Value = false;
  851. _doHOAvbl.Value = false;
  852. _state = E84State.LD_TP4_Timeout;
  853. if (OnE84HandOffTimeout != null)
  854. OnE84HandOffTimeout( E84Timeout.TP4, "Load");
  855. }
  856. if (_currentTState == LPTransferState.READY_TO_UNLOAD)
  857. {
  858. _doLoadReq.Value = false;
  859. _doUnloadReq.Value = false;
  860. _doReady.Value = false;
  861. _doHOAvbl.Value = false;
  862. _state = E84State.ULD_TP4_Timeout;
  863. if (OnE84HandOffTimeout != null)
  864. OnE84HandOffTimeout( E84Timeout.TP4, "UUnload");
  865. }
  866. _timer_TP4.Stop();
  867. }
  868. if (_timer_TP5.IsTimeout())
  869. {
  870. if (_currentTState == LPTransferState.READY_TO_LOAD)
  871. {
  872. _doLoadReq.Value = false;
  873. _doUnloadReq.Value = false;
  874. _doReady.Value = false;
  875. _doHOAvbl.Value = false;
  876. _state = E84State.LD_TP5_Timeout;
  877. if (OnE84HandOffTimeout != null)
  878. OnE84HandOffTimeout( E84Timeout.TP5, "Load");
  879. }
  880. if (_currentTState == LPTransferState.READY_TO_UNLOAD)
  881. {
  882. _doLoadReq.Value = false;
  883. _doUnloadReq.Value = false;
  884. _doReady.Value = false;
  885. _doHOAvbl.Value = false;
  886. _state = E84State.ULD_TP5_Timeout;
  887. if (OnE84HandOffTimeout != null)
  888. OnE84HandOffTimeout( E84Timeout.TP5, "Unload");
  889. }
  890. _timer_TP5.Stop();
  891. }
  892. }
  893. public void Reset()
  894. {
  895. //if (_state == E84State.Busy) return;
  896. //if (_state == E84State.Idle) return;
  897. //_timer_TP1.Stop();
  898. //_timer_TP2.Stop();
  899. //_timer_TP3.Stop();
  900. //_timer_TP4.Stop();
  901. //_timer_TP5.Stop();
  902. //_doLoadReq.SetValue(false,out _);
  903. //_doUnloadReq.SetValue(false, out _);
  904. //_doReady.SetValue(false, out _);
  905. //_doHOAvbl.SetValue(true, out _);
  906. //_doES.SetValue(true, out _);
  907. //_state = E84State.Idle;
  908. }
  909. public void ResetE84()
  910. {
  911. if (_state == E84State.Busy) return;
  912. if (_state == E84State.Idle) return;
  913. _timer_TP1.Stop();
  914. _timer_TP2.Stop();
  915. _timer_TP3.Stop();
  916. _timer_TP4.Stop();
  917. _timer_TP5.Stop();
  918. _doLoadReq.SetValue(false, out _);
  919. _doUnloadReq.SetValue(false, out _);
  920. _doReady.SetValue(false, out _);
  921. _doHOAvbl.SetValue(true, out _);
  922. _doES.SetValue(true, out _);
  923. _state = E84State.Idle;
  924. }
  925. public E84State GetCurrentE84State()
  926. {
  927. return _state;
  928. }
  929. }
  930. }