IoTurnOver.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. using System.Xml;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Event;
  4. using Aitex.Core.RT.IOCore;
  5. using Aitex.Core.RT.Log;
  6. using Aitex.Core.RT.OperationCenter;
  7. using Aitex.Core.RT.SCCore;
  8. using Aitex.Core.Util;
  9. using MECF.Framework.Common.Equipment;
  10. using MECF.Framework.Common.SubstrateTrackings;
  11. namespace Aitex.Core.RT.Device.Unit
  12. {
  13. /// <summary>
  14. ///
  15. /// </summary>
  16. public class IoTurnOver : BaseDevice, IDevice
  17. {
  18. private readonly DIAccessor _di0Degree;
  19. private readonly DIAccessor _di180Degree;
  20. private readonly DIAccessor _diAlarm;
  21. private readonly DIAccessor _diBusy;
  22. private readonly DIAccessor _diGrip;
  23. private readonly DIAccessor _diOrigin;
  24. private readonly DIAccessor _diPlacement;
  25. private readonly DIAccessor _diPressureError;
  26. private readonly DIAccessor _diUngrip;
  27. private readonly DOAccessor _doGrip;
  28. private readonly DOAccessor _doM0;
  29. private readonly DOAccessor _doM1;
  30. private readonly DOAccessor _doOrigin;
  31. private readonly DOAccessor _doResetError;
  32. private readonly DOAccessor _doStop;
  33. private readonly DOAccessor _doUngrip;
  34. //private bool _cmdLoop;
  35. //private int _interval;
  36. private DeviceTimer _loopTimeout = new DeviceTimer();
  37. private readonly DeviceTimer _loopTimer = new DeviceTimer();
  38. private readonly SCConfigItem _scLoopInterval;
  39. //private SCConfigItem _scLoopTimeout;
  40. private TurnOverState _state = TurnOverState.Idle;
  41. public TurnOverState State => _state;
  42. private R_TRIG _trigCloseError = new R_TRIG();
  43. private R_TRIG _trigOpenError = new R_TRIG();
  44. private R_TRIG _trigReset = new R_TRIG();
  45. private R_TRIG _trigSetPointDone = new R_TRIG();
  46. public const string EventWaferTurnOverStart = "WAFER_TURN_OVER_START";
  47. public const string EventWaferTurnOverEnd = "WAFER_TURN_OVER_COMPLETE";
  48. // DI_TurnOverPlacement
  49. // DI_TurnOverGrip
  50. // DI_TurnOverUngrip
  51. // DI_TurnOverBusy
  52. // DI_TurnOverPressureError
  53. //
  54. // DI_TurnOverAlarm
  55. // DI_TurnOverOrigin
  56. // DI_TurnOver0Degree
  57. // DI_TurnOver180Degree
  58. //
  59. // DO_TurnOverGrip
  60. // DO_TurnOverUngrip
  61. // DO_TurnOverM0
  62. // DO_TurnOverM1
  63. // DO_TurnOverStop
  64. //
  65. // DO_TurnOverOrigin
  66. // DO_TurnOverResetError
  67. public IoTurnOver(string module, XmlElement node, string ioModule = "")
  68. {
  69. Module = node.GetAttribute("module");
  70. Name = node.GetAttribute("id");
  71. Display = node.GetAttribute("display");
  72. DeviceID = node.GetAttribute("schematicId");
  73. _diPlacement = ParseDiNode("DI_TurnOverPlacement", node, ioModule);
  74. _diGrip = ParseDiNode("DI_TurnOverGrip", node, ioModule);
  75. _diUngrip = ParseDiNode("DI_TurnOverUngrip", node, ioModule);
  76. _diBusy = ParseDiNode("DI_TurnOverBusy", node, ioModule);
  77. _diPressureError = ParseDiNode("DI_TurnOverPressureError", node, ioModule);
  78. _diAlarm = ParseDiNode("DI_TurnOverAlarm", node, ioModule);
  79. _diOrigin = ParseDiNode("DI_TurnOverOrigin", node, ioModule);
  80. _di0Degree = ParseDiNode("DI_TurnOver0Degree", node, ioModule);
  81. _di180Degree = ParseDiNode("DI_TurnOver180Degree", node, ioModule);
  82. _doGrip = ParseDoNode("DO_TurnOverGrip", node, ioModule);
  83. _doUngrip = ParseDoNode("DO_TurnOverUngrip", node, ioModule);
  84. _doM0 = ParseDoNode("DO_TurnOverM0", node, ioModule);
  85. _doM1 = ParseDoNode("DO_TurnOverM1", node, ioModule);
  86. _doStop = ParseDoNode("DO_TurnOverStop", node, ioModule);
  87. _doOrigin = ParseDoNode("DO_TurnOverOrigin", node, ioModule);
  88. _doResetError = ParseDoNode("DO_TurnOverResetError", node, ioModule);
  89. _scLoopInterval = SC.GetConfigItem("Turnover.IntervalTimeLimit");
  90. }
  91. public int TimelimitAction
  92. {
  93. get
  94. {
  95. if (SC.ContainsItem($"Turnover.TimeLimitTurnoverAction"))
  96. return SC.GetValue<int>($"Turnover.TimeLimitTurnoverAction");
  97. return 60;
  98. }
  99. }
  100. public bool IsHomed => _diOrigin.Value;
  101. public bool IsPlacement
  102. {
  103. get
  104. {
  105. if(_diPlacement !=null) return !_diPlacement.Value;
  106. return WaferManager.Instance.CheckHasWafer(ModuleName.TurnOverStation, 0);
  107. }
  108. }
  109. public bool IsAlarm => !_diAlarm.Value;
  110. public bool IsPressureError => _diPressureError ==null? false: !_diPressureError.Value;
  111. public bool IsBusy => _diBusy.Value || _state != TurnOverState.Idle;
  112. public bool IsIdle => !_diBusy.Value && _state == TurnOverState.Idle;
  113. public bool IsGrip => _diGrip.Value && !_diUngrip.Value;
  114. public bool IsUnGrip => _diUngrip.Value && !_diGrip.Value;
  115. public bool Is0Degree => _di0Degree.Value &&!_di180Degree.Value;
  116. public bool Is180Degree => _di180Degree.Value&&!_di0Degree.Value;
  117. public bool IsEnableWaferTransfer => Is0Degree && !IsBusy && IsUnGrip && !IsAlarm &&
  118. IsPlacement;
  119. public bool Initialize()
  120. {
  121. DATA.Subscribe($"{Module}.{Name}.State", () => _state.ToString());
  122. DATA.Subscribe($"{Module}.{Name}.IsHomed", () => IsHomed);
  123. DATA.Subscribe($"{Module}.{Name}.IsBusy", () => IsBusy);
  124. DATA.Subscribe($"{Module}.{Name}.IsGrip", () => IsGrip);
  125. DATA.Subscribe($"{Module}.{Name}.IsUnGrip", () => IsUnGrip);
  126. DATA.Subscribe($"{Module}.{Name}.Is0Degree", () => Is0Degree);
  127. DATA.Subscribe($"{Module}.{Name}.Is180Degree", () => Is180Degree);
  128. DATA.Subscribe($"{Module}.{Name}.IsPlacement", () => IsPlacement);
  129. DATA.Subscribe($"{Module}.{Name}.IsAlarm", () => IsAlarm);
  130. DATA.Subscribe($"{Module}.{Name}.IsPressureError", () => IsPressureError);
  131. DATA.Subscribe($"{Module}.{Name}.GripCmd", () => _doGrip.Value);
  132. DATA.Subscribe($"{Module}.{Name}.TurnTo0Cmd", () => _doM0.Value);
  133. DATA.Subscribe($"{Module}.{Name}.TurnTo180Cmd", () => _doM1.Value);
  134. DATA.Subscribe($"{Module}.{Name}.HomeCmd", () => _doOrigin.Value);
  135. DATA.Subscribe($"{Module}.{Name}.ResetCmd", () => _doResetError.Value);
  136. DATA.Subscribe($"{Module}.{Name}.StopCmd", () => _doStop==null?false: _doStop.Value);
  137. DATA.Subscribe($"{Module}.{Name}.UnGripCmd", () => _doUngrip.Value);
  138. EV.Subscribe(new EventItem("Event", EventWaferTurnOverStart, "Start Turn Over"));
  139. EV.Subscribe(new EventItem("Event", EventWaferTurnOverEnd, "Turn Over End"));
  140. //System.TurnoverStation.
  141. OP.Subscribe($"{Module}.{Name}.ResetError", (cmd, param) =>
  142. {
  143. if (!ResetError(out var reason))
  144. {
  145. EV.PostWarningLog(Module, $"{Name} can not reset error, {reason}");
  146. return false;
  147. }
  148. return true;
  149. });
  150. OP.Subscribe($"{Module}.{Name}.Home", (cmd, param) =>
  151. {
  152. if (!Home(out var reason))
  153. {
  154. EV.PostWarningLog(Module, $"{Name} can not home, {reason}");
  155. return false;
  156. }
  157. return true;
  158. });
  159. OP.Subscribe($"{Module}.{Name}.Grip", (cmd, param) =>
  160. {
  161. if (!Grip(out var reason))
  162. {
  163. EV.PostWarningLog(Module, $"{Name} can not grip, {reason}");
  164. return false;
  165. }
  166. return true;
  167. });
  168. OP.Subscribe($"{Module}.{Name}.Ungrip", (cmd, param) =>
  169. {
  170. if (!UnGrip(out var reason))
  171. {
  172. EV.PostWarningLog(Module, $"{Name} can not ungrip, {reason}");
  173. return false;
  174. }
  175. return true;
  176. });
  177. OP.Subscribe($"{Module}.{Name}.TurnTo0", (cmd, param) =>
  178. {
  179. if (!TurnTo0(out var reason))
  180. {
  181. EV.PostWarningLog(Module, $"{Name} can not turn to 0 degree, {reason}");
  182. return false;
  183. }
  184. return true;
  185. });
  186. OP.Subscribe($"{Module}.{Name}.TurnTo180", (cmd, param) =>
  187. {
  188. if (!TurnTo180(out var reason))
  189. {
  190. EV.PostWarningLog(Module, $"{Name} can not turn to 180 degree, {reason}");
  191. return false;
  192. }
  193. return true;
  194. });
  195. OP.Subscribe($"{Module}.{Name}.Stop", (cmd, param) =>
  196. {
  197. if (!Stop(out var reason))
  198. {
  199. EV.PostWarningLog(Module, $"{Name} can not turn to 180 degree, {reason}");
  200. return false;
  201. }
  202. return true;
  203. });
  204. return true;
  205. }
  206. public void Terminate()
  207. {
  208. }
  209. public void Monitor()
  210. {
  211. if (IsAlarm || IsPressureError)
  212. {
  213. _state = TurnOverState.Error;
  214. _doGrip.SetValue(false, out _);
  215. _doM0.SetValue(false, out _);
  216. _doM1.SetValue(false, out _);
  217. _doOrigin.SetValue(false, out _);
  218. if(_doStop !=null)
  219. _doStop.SetValue(false, out _);
  220. _doUngrip.SetValue(false, out _);
  221. return;
  222. }
  223. switch (_state)
  224. {
  225. case TurnOverState.OnHoming:
  226. _doM0.SetValue(false, out _);
  227. _doM1.SetValue(false, out _);
  228. _doOrigin.SetValue(true, out _);
  229. if (IsHomed)// && _di0Degree.Value)
  230. {
  231. if (!_doOrigin.SetValue(false, out var reason))
  232. LOG.Error($"{Module} reset DO failed, {reason}");
  233. _state = TurnOverState.Idle;
  234. }
  235. else if (_loopTimer.IsTimeout())
  236. {
  237. if (!_doOrigin.SetValue(false, out var reason))
  238. LOG.Error($"{Module} reset DO failed, {reason}");
  239. EV.PostAlarmLog(Module, $"{Module} {Name} Can not Home in {_scLoopInterval.IntValue} seconds");
  240. _state = TurnOverState.Error;
  241. }
  242. break;
  243. case TurnOverState.OnGripping:
  244. if (IsGrip)
  245. {
  246. //if (!_doGrip.SetValue(false, out var reason)) LOG.Error($"{Module} reset DO failed, {reason}");
  247. _state = TurnOverState.Idle;
  248. }
  249. else if (_loopTimer.IsTimeout())
  250. {
  251. //if (!_doOrigin.SetValue(false, out var reason))
  252. // LOG.Error($"{Module} reset DO failed, {reason}");
  253. EV.PostAlarmLog(Module, $"{Module} {Name} Can not Grip in {_scLoopInterval.IntValue} seconds");
  254. _state = TurnOverState.Error;
  255. }
  256. break;
  257. case TurnOverState.OnUnGripping:
  258. if (IsUnGrip)
  259. {
  260. //if (!_doUngrip.SetValue(false, out var reason))
  261. // LOG.Error($"{Module} reset DO failed, {reason}");
  262. _state = TurnOverState.Idle;
  263. }
  264. else if (_loopTimer.IsTimeout())
  265. {
  266. //if (!_doUngrip.SetValue(false, out var reason))
  267. // LOG.Error($"{Module} reset DO failed, {reason}");
  268. EV.PostAlarmLog(Module,
  269. $"{Module} {Name} Can not UnGrip in {_scLoopInterval.IntValue} seconds");
  270. _state = TurnOverState.Error;
  271. }
  272. break;
  273. case TurnOverState.OnTurningTo0:
  274. if (_doM1.Value == true) _doM1.SetValue(false, out _);
  275. if (_doM0.Value == false) _doM0.SetValue(true, out _);
  276. if (Is0Degree && !_diBusy.Value)
  277. { if (!_doM0.SetValue(false, out var reason)) LOG.Error($"{Module} reset DO failed, {reason}");
  278. _state = TurnOverState.Idle;
  279. }
  280. else if (_loopTimer.IsTimeout())
  281. {
  282. ////if (!_doM0.SetValue(false, out var reason))
  283. // LOG.Error($"{Module} reset DO failed, {reason}");
  284. EV.PostAlarmLog(Module,
  285. $"{Module} {Name} Can not Turn to 0 in {_scLoopInterval.IntValue} seconds");
  286. _state = TurnOverState.Error;
  287. }
  288. break;
  289. case TurnOverState.OnTurningTo180:
  290. if(_doM1.Value == false) _doM1.SetValue(true, out _);
  291. if (_doM0.Value == true) _doM0.SetValue(false, out _);
  292. if (Is180Degree &&!_diBusy.Value)
  293. {
  294. if (!_doM1.SetValue(false, out var reason)) LOG.Error($"{Module} reset DO failed, {reason}");
  295. _state = TurnOverState.Idle;
  296. var wafer = WaferManager.Instance.GetWafer(ModuleName.TurnOverStation, 0);
  297. if (!wafer.IsEmpty)
  298. {
  299. var dvid = new SerializableDictionary<string, string>()
  300. {
  301. {"LOT_ID", wafer.LotId},
  302. {"WAFER_ID", wafer.WaferID},
  303. {"ARRIVE_POS_NAME", "TRN1"},
  304. };
  305. EV.Notify(EventWaferTurnOverEnd, dvid);
  306. }
  307. }
  308. else if (_loopTimer.IsTimeout())
  309. {
  310. //if (!_doM1.SetValue(false, out var reason)) LOG.Error($"{Module} reset DO failed, {reason}");
  311. EV.PostAlarmLog(Module,
  312. $"{Module} {Name} Can not Turn to 180 in {_scLoopInterval.IntValue} seconds");
  313. _state = TurnOverState.Error;
  314. }
  315. break;
  316. case TurnOverState.OnErrorCleaning:
  317. if (!IsAlarm)
  318. {
  319. if (!_doResetError.SetValue(false, out var reason))
  320. LOG.Error($"{Module} reset DO failed, {reason}");
  321. _state = TurnOverState.Idle;
  322. }
  323. break;
  324. case TurnOverState.Stopping:
  325. if (!IsBusy)
  326. {
  327. if (_doStop != null)
  328. {
  329. if (!_doStop.SetValue(false, out var reason))
  330. LOG.Error($"{Module} reset DO failed, {reason}");
  331. }
  332. _state = TurnOverState.Stop;
  333. }
  334. break;
  335. default:
  336. //if (!_diBusy.Value && !_doStop.Value) _state = DeviceState.Idle;
  337. break;
  338. }
  339. }
  340. public void Reset()
  341. {
  342. //_doGrip.SetValue(false, out _);
  343. //_doM0.SetValue(false, out _);
  344. //_doM1.SetValue(false, out _);
  345. //_doOrigin.SetValue(false, out _);
  346. //if(_doStop!=null)
  347. // _doStop.SetValue(false, out _);
  348. //_doUngrip.SetValue(false, out _);
  349. //ResetError(out _);
  350. }
  351. public bool Home(out string reason)
  352. {
  353. reason = string.Empty;
  354. EV.PostInfoLog(Module, $"{Module}.{Name} Home");
  355. //if (IsPressureError)
  356. //{
  357. // reason = "Turn over station pressure error";
  358. // return false;
  359. //}
  360. _doM0.SetValue(false, out _);
  361. _doM1.SetValue(false, out _);
  362. _doOrigin.SetValue(true, out _);
  363. _state = TurnOverState.OnHoming;
  364. _loopTimer.Start(_scLoopInterval.IntValue * 1000);
  365. return true;
  366. }
  367. public bool Grip(out string reason)
  368. {
  369. reason = string.Empty;
  370. EV.PostInfoLog(Module, $"{Module}.{Name} Grip");
  371. if (IsPressureError)
  372. {
  373. reason = "Turn over station pressure error";
  374. EV.PostAlarmLog(Module, $"{Module}.{Name} pressure error.");
  375. return false;
  376. }
  377. //if (_doGrip.Value)
  378. //{
  379. // reason = "Gripping, can't do again";
  380. // EV.PostAlarmLog(Module, $"{Module}.{Name} {reason}.");
  381. // return false;
  382. //}
  383. _doUngrip.SetValue(false, out _);
  384. _doGrip.SetValue(true, out _);
  385. _state = TurnOverState.OnGripping;
  386. _loopTimer.Start(_scLoopInterval.IntValue * 1000);
  387. return true;
  388. }
  389. public bool UnGrip(out string reason)
  390. {
  391. reason = string.Empty;
  392. EV.PostInfoLog(Module, $"{Module}.{Name} UnGrip");
  393. if (IsPressureError)
  394. {
  395. reason = "Turn over station pressure error";
  396. return false;
  397. }
  398. //if (_doUngrip.Value)
  399. //{
  400. // reason = "UnGripping, can't do again";
  401. // return false;
  402. //}
  403. _doGrip.SetValue(false, out _);
  404. _doUngrip.SetValue(true, out _);
  405. _state = TurnOverState.OnUnGripping;
  406. _loopTimer.Start(_scLoopInterval.IntValue * 1000);
  407. return true;
  408. }
  409. public bool TurnTo0(out string reason)
  410. {
  411. reason = string.Empty;
  412. EV.PostInfoLog(Module, $"{Module}.{Name} Turn to 0");
  413. //if (IsPressureError)
  414. //{
  415. // reason = "Turn over station pressure error";
  416. // return false;
  417. //}
  418. //if (_doM0.Value)
  419. //{
  420. // reason = "Turning, can't do again";
  421. // return false;
  422. //}
  423. _state = TurnOverState.OnTurningTo0;
  424. //if (_doM1.Value == true) _doM1.SetValue(false, out _);
  425. //if (_doM0.Value == false) _doM0.SetValue(true, out _);
  426. _loopTimer.Start(_scLoopInterval.IntValue * 1000);
  427. return true;
  428. }
  429. public bool TurnTo180(out string reason)
  430. {
  431. reason = string.Empty;
  432. EV.PostInfoLog(Module, $"{Module}.{Name} Turn to 180");
  433. //if (IsPressureError)
  434. //{
  435. // reason = "Turn over station pressure error";
  436. // return false;
  437. //}
  438. //if (_doM1.Value)
  439. //{
  440. // reason = "Turning, can't do again";
  441. // return false;
  442. //}
  443. _state = TurnOverState.OnTurningTo180;
  444. //if (_doM0.Value == true) _doM0.SetValue(false, out _);
  445. //if (_doM1.Value == false) _doM1.SetValue(true, out _);
  446. _loopTimer.Start(_scLoopInterval.IntValue * 1000);
  447. var wafer = WaferManager.Instance.GetWafer(ModuleName.TurnOverStation,0);
  448. if (!wafer.IsEmpty)
  449. {
  450. var dvid = new SerializableDictionary<string, string>()
  451. {
  452. {"LOT_ID", wafer.LotId},
  453. {"WAFER_ID", wafer.WaferID},
  454. {"ARRIVE_POS_NAME", "TRN1"}
  455. };
  456. EV.Notify(EventWaferTurnOverStart, dvid);
  457. }
  458. return true;
  459. }
  460. public bool Stop(out string reason)
  461. {
  462. reason = string.Empty;
  463. EV.PostInfoLog(Module, $"{Module}.{Name} Stop");
  464. if (_doStop != null)
  465. {
  466. if (_doStop.Value)
  467. {
  468. reason = "Stopping, can't do again";
  469. return false;
  470. }
  471. _doStop.SetValue(true, out _);
  472. }
  473. _state = TurnOverState.Stopping;
  474. _loopTimer.Start(_scLoopInterval.IntValue * 1000);
  475. return true;
  476. }
  477. private bool ResetError(out string reason)
  478. {
  479. reason = string.Empty;
  480. //EV.PostInfoLog(Module, $"{Module}.{Name} Reset Error");
  481. if (_doResetError.Value)
  482. return true;
  483. _doResetError.SetValue(true, out _);
  484. _state = TurnOverState.OnErrorCleaning;
  485. _loopTimer.Start(_scLoopInterval.IntValue * 1000);
  486. return true;
  487. }
  488. }
  489. public enum TurnOverState
  490. {
  491. Idle,
  492. OnHoming,
  493. OnTurningTo0,
  494. OnTurningTo180,
  495. OnGripping,
  496. OnUnGripping,
  497. Error,
  498. OnErrorCleaning,
  499. Stopping,
  500. Stop
  501. }
  502. }