IoE84.cs 50 KB

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