IoCoolBuffer.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. using System;
  2. using System.Xml;
  3. using Aitex.Core.Common;
  4. using Aitex.Core.Common.DeviceData;
  5. using Aitex.Core.RT.DataCenter;
  6. using Aitex.Core.RT.Event;
  7. using Aitex.Core.RT.IOCore;
  8. using Aitex.Core.RT.Log;
  9. using Aitex.Core.RT.OperationCenter;
  10. using Aitex.Core.RT.SCCore;
  11. using Aitex.Core.Util;
  12. using MECF.Framework.Common.Equipment;
  13. using MECF.Framework.Common.SubstrateTrackings;
  14. namespace Aitex.Core.RT.Device.Unit
  15. {
  16. public class IoCoolBuffer : BaseDevice, IDevice
  17. {
  18. enum DeviceState
  19. {
  20. Idle,
  21. Homing,
  22. MovingUp,
  23. MovingDown,
  24. Error,
  25. }
  26. public enum LiftState
  27. {
  28. Unknown = 0,
  29. Down = 1,
  30. Up = 2,
  31. Error = 3,
  32. }
  33. private DIAccessor _diLiftUp;
  34. private DIAccessor _diLiftDown;
  35. private DIAccessor _di3InchExtend;
  36. private DIAccessor _di3InchRetract;
  37. private DIAccessor _di4InchExtend;
  38. private DIAccessor _di4InchRetract;
  39. private DOAccessor _doLiftUp;
  40. private DOAccessor _doLiftDown;
  41. private DOAccessor _do3InchExtend;
  42. private DOAccessor _do3InchRetract;
  43. private DOAccessor _do4InchExtend;
  44. private DOAccessor _do4InchRetract;
  45. private DeviceState _state = DeviceState.Idle;
  46. private DeviceTimer _timer = new DeviceTimer();
  47. private WaferSize _size = WaferSize.WS0;
  48. private SCConfigItem _scLiftUpTimeout;
  49. private SCConfigItem _scLiftDownTimeout;
  50. public bool Busy
  51. {
  52. get
  53. {
  54. return _state != DeviceState.Idle;
  55. }
  56. }
  57. public bool Moving
  58. {
  59. get
  60. {
  61. return _state != DeviceState.Idle && _state != DeviceState.Error;
  62. }
  63. }
  64. public bool Error
  65. {
  66. get
  67. {
  68. return _state == DeviceState.Error;
  69. }
  70. }
  71. //public bool IsUp
  72. //{
  73. // get
  74. // {
  75. // return _diLiftUp.Value && !_diLiftDown.Value;
  76. // }
  77. //}
  78. //public bool IsDown
  79. //{
  80. // get
  81. // {
  82. // return !_diLiftUp.Value && _diLiftDown.Value;
  83. // }
  84. //}
  85. public LiftState Feedback3Inch
  86. {
  87. get
  88. {
  89. if (_di3InchExtend.Value && !_di3InchRetract.Value)
  90. return LiftState.Up;
  91. if (!_di3InchExtend.Value && _di3InchRetract.Value)
  92. return LiftState.Down;
  93. return LiftState.Unknown;
  94. }
  95. }
  96. public LiftState Feedback4Inch
  97. {
  98. get
  99. {
  100. //if (_di4InchExtend.Value && _di4InchRetract.Value)
  101. // return LiftState.Error;
  102. if (_di4InchExtend.Value && !_di4InchRetract.Value)
  103. return LiftState.Up;
  104. if (!_di4InchExtend.Value && _di4InchRetract.Value)
  105. return LiftState.Down;
  106. //if (!_di4InchExtend.Value && !_di4InchRetract.Value)
  107. return LiftState.Unknown;
  108. }
  109. }
  110. public LiftState FeedbackLift
  111. {
  112. get
  113. {
  114. //if (_diLiftUp.Value && _diLiftDown.Value)
  115. // return LiftState.Error;
  116. if (_diLiftUp.Value && !_diLiftDown.Value)
  117. return LiftState.Up;
  118. if (!_diLiftUp.Value && _diLiftDown.Value)
  119. return LiftState.Down;
  120. //if (!_di3InchExtend.Value && !_di3InchRetract.Value)
  121. return LiftState.Unknown;
  122. }
  123. }
  124. public LiftState SetPoint3Inch
  125. {
  126. get
  127. {
  128. //if (_do3InchExtend.Value && _do3InchRetract.Value)
  129. // return LiftState.Error;
  130. if (_do3InchExtend.Value && !_do3InchRetract.Value)
  131. return LiftState.Up;
  132. if (!_do3InchExtend.Value && _do3InchRetract.Value)
  133. return LiftState.Down;
  134. //if (!_do3InchExtend.Value && !_do3InchRetract.Value)
  135. return LiftState.Unknown;
  136. }
  137. }
  138. public LiftState SetPoint4Inch
  139. {
  140. get
  141. {
  142. //if (_do4InchExtend.Value && _do4InchRetract.Value)
  143. // return LiftState.Error;
  144. if (_do4InchExtend.Value && !_do4InchRetract.Value)
  145. return LiftState.Up;
  146. if (!_do4InchExtend.Value && _do4InchRetract.Value)
  147. return LiftState.Down;
  148. //if (!_do4InchExtend.Value && !_do4InchRetract.Value)
  149. return LiftState.Unknown;
  150. }
  151. }
  152. public LiftState SetPointLift
  153. {
  154. get
  155. {
  156. //if (_doLiftUp.Value && _doLiftDown.Value)
  157. // return LiftState.Error;
  158. if (_doLiftUp.Value && !_doLiftDown.Value)
  159. return LiftState.Up;
  160. if (!_doLiftUp.Value && _doLiftDown.Value)
  161. return LiftState.Down;
  162. //if (!_do3InchExtend.Value && !_do3InchRetract.Value)
  163. return LiftState.Unknown;
  164. }
  165. }
  166. public IoCoolBuffer(string module, XmlElement node, string ioModule = "")
  167. {
  168. base.Module = string.IsNullOrEmpty(node.GetAttribute("module")) ? module : node.GetAttribute("module");
  169. base.Name = node.GetAttribute("id");
  170. base.Display = node.GetAttribute("display");
  171. base.DeviceID = node.GetAttribute("schematicId");
  172. _diLiftUp = ParseDiNode("diLiftUp", node, ioModule);
  173. _diLiftDown = ParseDiNode("diLiftDown", node, ioModule);
  174. _di3InchExtend = ParseDiNode("diAligner1Extend", node, ioModule);
  175. _di3InchRetract = ParseDiNode("diAligner1Retract", node, ioModule);
  176. _di4InchExtend = ParseDiNode("diAligner2Extend", node, ioModule);
  177. _di4InchRetract = ParseDiNode("diAligner2Retract", node, ioModule);
  178. _doLiftUp = ParseDoNode("doLiftUp", node, ioModule);
  179. _doLiftDown = ParseDoNode("doLiftDown", node, ioModule);
  180. _do3InchExtend = ParseDoNode("doAligner1Extend", node, ioModule);
  181. _do3InchRetract = ParseDoNode("doAligner1Retract", node, ioModule);
  182. _do4InchExtend = ParseDoNode("doAligner2Extend", node, ioModule);
  183. _do4InchRetract = ParseDoNode("doAligner2Retract", node, ioModule);
  184. _scLiftUpTimeout = ParseScNode("scUpTimeout", node);
  185. _scLiftDownTimeout = ParseScNode("scDownTimeout", node);
  186. }
  187. public bool Initialize()
  188. {
  189. _state = DeviceState.Idle;
  190. WaferManager.Instance.SubscribeLocation(Module, 1);
  191. DATA.Subscribe($"{Module}.{Name}.Feedback3Inch", () => Feedback3Inch.ToString());
  192. DATA.Subscribe($"{Module}.{Name}.Feedback4Inch", () => Feedback4Inch.ToString());
  193. DATA.Subscribe($"{Module}.{Name}.FeedbackLift", () => FeedbackLift.ToString());
  194. DATA.Subscribe($"{Module}.{Name}.SetPoint3Inch", () => SetPoint3Inch.ToString());
  195. DATA.Subscribe($"{Module}.{Name}.SetPoint4Inch", () => SetPoint4Inch.ToString());
  196. DATA.Subscribe($"{Module}.{Name}.SetPointLift", () => SetPointLift.ToString());
  197. DATA.Subscribe($"{Module}.{Name}.Status", () => _state.ToString());
  198. DATA.Subscribe($"{Module}.{Name}.WaferSizeByWafer", () => WaferManager.Instance.GetWafer(ModuleHelper.Converter(Module), 0).Size.ToString());
  199. DATA.Subscribe($"{Module}.{Name}.WaferSizeBySetPoint", () => _size.ToString());
  200. OP.Subscribe($"{Module}.{Name}.MoveUp3", (string reason, object[] param) =>
  201. {
  202. reason = "";
  203. return Move(WaferSize.WS3, true, out reason);
  204. });
  205. OP.Subscribe($"{Module}.{Name}.MoveUp4", (string reason, object[] param) =>
  206. {
  207. reason = "";
  208. return Move(WaferSize.WS4, true, out reason);
  209. });
  210. OP.Subscribe($"{Module}.{Name}.MoveUpLift", (string reason, object[] param) =>
  211. {
  212. reason = "";
  213. return Move(WaferSize.WS6, true, out reason);
  214. });
  215. OP.Subscribe($"{Module}.{Name}.MoveDown3", (string reason, object[] param) =>
  216. {
  217. reason = "";
  218. return Move(WaferSize.WS3, false, out reason);
  219. });
  220. OP.Subscribe($"{Module}.{Name}.MoveDown4", (string reason, object[] param) =>
  221. {
  222. reason = "";
  223. return Move(WaferSize.WS4, false, out reason);
  224. });
  225. OP.Subscribe($"{Module}.{Name}.MoveDownLift", (string reason, object[] param) =>
  226. {
  227. reason = "";
  228. return Move(WaferSize.WS6, false, out reason);
  229. });
  230. return true;
  231. }
  232. public void Monitor()
  233. {
  234. switch (_state)
  235. {
  236. case DeviceState.MovingUp:
  237. if (CheckPinUp() /*&& Check3InchDown() && Check4InchDown()*/)
  238. {
  239. _state = DeviceState.Idle;
  240. }
  241. else
  242. {
  243. if (_timer.IsTimeout())
  244. {
  245. EV.PostAlarmLog(Module, $"{Module} {Name} Can not move up in {_scLiftUpTimeout.IntValue} seconds");
  246. _state = DeviceState.Error;
  247. }
  248. else
  249. {
  250. if (CheckPinUp())
  251. {
  252. //Set3InchDown(out _);
  253. //Set4InchDown(out _);
  254. }
  255. }
  256. }
  257. break;
  258. case DeviceState.MovingDown:
  259. bool guided = CheckGuided(_size);
  260. if (CheckPinDown() && guided)
  261. {
  262. _state = DeviceState.Idle;
  263. }
  264. else
  265. {
  266. if (_timer.IsTimeout())
  267. {
  268. EV.PostAlarmLog(Module, $"{Module} {Name} Can not move down in {_scLiftUpTimeout.IntValue} seconds");
  269. _state = DeviceState.Error;
  270. }
  271. else
  272. {
  273. if (guided)
  274. {
  275. SetPinDown(out _);
  276. }
  277. }
  278. }
  279. break;
  280. case DeviceState.Homing:
  281. if(Check3InchDown() && Check4InchDown() && CheckPinDown())
  282. _state = DeviceState.Idle;
  283. break;
  284. default:
  285. break;
  286. }
  287. }
  288. public void Terminate()
  289. {
  290. }
  291. public bool Home(out string reason)
  292. {
  293. ModuleName _module;
  294. if (!Enum.TryParse<ModuleName>(Module, out _module))
  295. {
  296. reason = $"{Module} isn't exist";
  297. return false;
  298. }
  299. if (_state != DeviceState.Error && _state != DeviceState.Idle)
  300. {
  301. reason = $"{Module} is in {_state} state.";
  302. return false;
  303. }
  304. WaferInfo info = WaferManager.Instance.GetWafer(_module, 0);
  305. _do3InchExtend.SetValue(false, out reason);
  306. _do4InchExtend.SetValue(false, out reason);
  307. _doLiftUp.SetValue(false, out reason);
  308. _do3InchRetract.SetValue(true, out reason);
  309. _do4InchRetract.SetValue(true, out reason);
  310. _doLiftDown.SetValue(true, out reason);
  311. _state = DeviceState.Homing;
  312. return true;
  313. }
  314. public bool Move(WaferSize size, bool up, out string reason)
  315. {
  316. _size = size;
  317. if (up)
  318. return MoveUp(out reason);
  319. return MoveDown(out reason);
  320. }
  321. public bool Check3InchUp() { return Feedback3Inch == LiftState.Up; }
  322. public bool Check3InchDown() { return Feedback3Inch == LiftState.Down; }
  323. public bool Check4InchUp() { return Feedback4Inch == LiftState.Up; }
  324. public bool Check4InchDown() { return Feedback4Inch == LiftState.Down; }
  325. public bool CheckPinUp() { return FeedbackLift == LiftState.Up; }
  326. public bool CheckPinDown() { return FeedbackLift == LiftState.Down; }
  327. private bool Set3InchUp(out string reason)
  328. {
  329. if (SetPoint3Inch != LiftState.Up)
  330. EV.PostInfoLog(Module, $"{Module} move 3 inch up");
  331. return _do3InchExtend.SetValue(true, out reason) && _do3InchRetract.SetValue(false, out reason);
  332. }
  333. private bool Set3InchDown(out string reason)
  334. {
  335. if (SetPoint3Inch != LiftState.Down)
  336. EV.PostInfoLog(Module, $"{Module} move 3 inch down");
  337. return _do3InchExtend.SetValue(false, out reason) && _do3InchRetract.SetValue(true, out reason);
  338. }
  339. private bool Set4InchUp(out string reason)
  340. {
  341. if (SetPoint4Inch != LiftState.Up)
  342. EV.PostInfoLog(Module, $"{Module} move 4 inch up");
  343. return _do4InchExtend.SetValue(true, out reason) && _do4InchRetract.SetValue(false, out reason);
  344. }
  345. private bool Set4InchDown(out string reason)
  346. {
  347. if (SetPoint4Inch != LiftState.Down)
  348. EV.PostInfoLog(Module, $"{Module} move 4 inch down");
  349. return _do4InchExtend.SetValue(false, out reason) && _do4InchRetract.SetValue(true, out reason);
  350. }
  351. private bool SetPinUp(out string reason)
  352. {
  353. if (SetPointLift != LiftState.Up)
  354. EV.PostInfoLog(Module, $"{Module} move pin up");
  355. return _doLiftUp.SetValue(true, out reason) && _doLiftDown.SetValue(false, out reason);
  356. }
  357. private bool SetPinDown(out string reason)
  358. {
  359. if (SetPointLift != LiftState.Down)
  360. EV.PostInfoLog(Module, $"{Module} move pin down");
  361. return _doLiftUp.SetValue(false, out reason) && _doLiftDown.SetValue(true, out reason);
  362. }
  363. public bool CheckMovedUp()
  364. {
  365. // return CheckPinUp() && Check3InchDown() && Check4InchDown();
  366. return CheckPinUp();
  367. }
  368. public bool CheckMovedDown()
  369. {
  370. return CheckPinDown() && CheckGuided(_size);
  371. }
  372. private bool CheckGuided(WaferSize size)
  373. {
  374. bool guided = false;
  375. switch (_size)
  376. {
  377. case WaferSize.WS0:
  378. case WaferSize.WS8:
  379. case WaferSize.WS6:
  380. {
  381. guided = Check3InchDown() && Check4InchDown();
  382. }
  383. break;
  384. case WaferSize.WS3:
  385. {
  386. guided = Check3InchUp() && Check4InchDown();
  387. }
  388. break;
  389. case WaferSize.WS4:
  390. {
  391. guided = Check3InchDown() && Check4InchUp();
  392. }
  393. break;
  394. }
  395. return guided;
  396. }
  397. private bool MoveUp(out string reason)
  398. {
  399. reason = string.Empty;
  400. bool ret = true;
  401. switch (_size)
  402. {
  403. case WaferSize.WS0:
  404. case WaferSize.WS8:
  405. case WaferSize.WS6:
  406. {
  407. if (!Set3InchDown(out reason) || !Set4InchDown(out reason) || !SetPinUp(out reason))
  408. {
  409. ret = false;
  410. }
  411. }
  412. break;
  413. case WaferSize.WS3:
  414. {
  415. if (!Set3InchUp(out reason) || !Set4InchDown(out reason) || !SetPinUp(out reason))
  416. {
  417. ret = false;
  418. }
  419. }
  420. break;
  421. case WaferSize.WS4:
  422. {
  423. if (!Set3InchDown(out reason) || !Set4InchUp(out reason) || !SetPinUp(out reason))
  424. {
  425. ret = false;
  426. }
  427. }
  428. break;
  429. }
  430. if (!ret)
  431. return false;
  432. _timer.Start(_scLiftUpTimeout.IntValue * 1000);
  433. _state = DeviceState.MovingUp;
  434. return true;
  435. }
  436. private bool MoveDown(out string reason)
  437. {
  438. reason = string.Empty;
  439. bool ret = true;
  440. switch (_size)
  441. {
  442. case WaferSize.WS0:
  443. case WaferSize.WS8:
  444. case WaferSize.WS6:
  445. {
  446. if (!Set3InchDown(out reason) || !Set4InchDown(out reason))
  447. {
  448. ret = false;
  449. }
  450. }
  451. break;
  452. case WaferSize.WS3:
  453. {
  454. if (!Set3InchUp(out reason) || Set4InchDown(out reason))
  455. {
  456. ret = false;
  457. }
  458. }
  459. break;
  460. case WaferSize.WS4:
  461. {
  462. if (!Set4InchUp(out reason)|| !Set3InchDown(out reason))
  463. {
  464. ret = false;
  465. }
  466. }
  467. break;
  468. }
  469. if (!ret)
  470. return false;
  471. _timer.Start(_scLiftDownTimeout.IntValue * 1000);
  472. _state = DeviceState.MovingDown;
  473. return true;
  474. }
  475. public void Reset()
  476. {
  477. }
  478. }
  479. }