IoEfemE84.cs 41 KB

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