EfemServerModule.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. using System.Threading;
  5. using Aitex.Core.RT.Device;
  6. using Aitex.Core.RT.Log;
  7. using Aitex.Core.Util;
  8. using Aitex.Sorter.Common;
  9. using MECF.Framework.Common.Equipment;
  10. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.BufferStations;
  11. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  12. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  13. namespace Aitex.Sorter.RT.EFEMs.Servers
  14. {
  15. public interface IData
  16. {
  17. bool Error { get; }
  18. bool IsLinkOk { get; }
  19. bool Busy { get; }
  20. bool Disabled { get; set; }
  21. bool Initialized { get; set; }
  22. bool OriginSearched { get; set; }
  23. bool InUsed { get; set; }
  24. }
  25. public interface IFunction
  26. {
  27. bool Init(out string reason);
  28. bool Home(out string reason);
  29. }
  30. public interface IServerModule : IData, IFunction
  31. {
  32. }
  33. public class SystemServerModule : IServerModule
  34. {
  35. public string Name { get; set; }
  36. public bool Busy { get { return Singleton<EfemEntity>.Instance.EfemDevice.IsRunning; } }
  37. public bool Moving { get; set; }
  38. public bool Error
  39. {
  40. get { return Singleton<EfemEntity>.Instance.EfemDevice.IsError;}
  41. }
  42. public bool IsLinkOk
  43. {
  44. get { return Singleton<EfemEntity>.Instance.IsCommunicationOk; }
  45. }
  46. public bool Disabled { get; set; }
  47. public bool Initialized { get; set; }
  48. public bool OriginSearched { get; set; }
  49. public bool InUsed { get; set; }
  50. private Dictionary<EfemEventType, EfemEventValue> _dicEventStatus = new Dictionary<EfemEventType, EfemEventValue>();
  51. public SystemServerModule(string name)
  52. {
  53. Name = name;
  54. foreach (var value in Enum.GetValues(typeof(EfemEventType)))
  55. {
  56. _dicEventStatus[(EfemEventType)value] = EfemEventValue.ON;
  57. }
  58. }
  59. public bool Init(out string reason)
  60. {
  61. reason = string.Empty;
  62. if(!Singleton<EfemEntity>.Instance.EfemDevice.Init(ModuleName.System))
  63. {
  64. reason = "BUSY";
  65. return false;
  66. }
  67. Thread.Sleep(100);//can not remove
  68. Initialized = true;
  69. return true;
  70. }
  71. public bool Home(out string reason)
  72. {
  73. reason = string.Empty;
  74. if (!Singleton<EfemEntity>.Instance.EfemDevice.Home(ModuleName.System))
  75. {
  76. reason = "BUSY";
  77. return false;
  78. }
  79. Initialized = true;
  80. return true;
  81. }
  82. public bool MapWafer(string device, out string reason)
  83. {
  84. reason = string.Empty;
  85. if (!Singleton<EfemEntity>.Instance.EfemDevice.MapWafer(device))
  86. {
  87. reason = "BUSY";
  88. return false;
  89. }
  90. return true;
  91. }
  92. public bool SetEvent(EfemEventType type, EfemEventValue value)
  93. {
  94. _dicEventStatus[type] = value;
  95. return true;
  96. }
  97. public bool IsEventEnabled(EfemEventType type)
  98. {
  99. return _dicEventStatus[type] == EfemEventValue.ON;
  100. }
  101. public bool Hold()
  102. {
  103. return true;
  104. }
  105. public bool Resume()
  106. {
  107. return true;
  108. }
  109. public bool Abort()
  110. {
  111. return true;
  112. }
  113. public bool Stop()
  114. {
  115. return true;
  116. }
  117. public bool ClearError()
  118. {
  119. if (!Singleton<EfemEntity>.Instance.EfemDevice.ClearError())
  120. {
  121. LOG.Write("call routermanager reset failed.");
  122. return false;
  123. }
  124. return true;
  125. }
  126. public string GetLastError()
  127. {
  128. return string.Empty;
  129. }
  130. }
  131. public class AlignerServerModule : IServerModule
  132. {
  133. public bool IsLinkOk
  134. {
  135. get { return _aligner != null && _aligner.Communication; }
  136. }
  137. public bool Busy
  138. {
  139. get { return _aligner.Busy; }
  140. }
  141. public bool Moving
  142. {
  143. get { return _aligner.Moving; }
  144. }
  145. public bool Error
  146. {
  147. get { return _aligner.Error; }
  148. }
  149. public string Name { get; set; }
  150. public bool Disabled { get; set; }
  151. public bool Initialized { get; set; }
  152. public bool OriginSearched { get; set; }
  153. public bool InUsed { get; set; }
  154. private double _angle = 0;
  155. public bool IsGripped
  156. {
  157. get
  158. {
  159. return _aligner.StateWaferHold;
  160. }
  161. }
  162. public Aligner GetDevice()
  163. {
  164. return _aligner;
  165. }
  166. protected Aligner _aligner = null;
  167. public AlignerServerModule(string name)
  168. {
  169. _aligner = DEVICE.GetDevice<Aligner>(DeviceName.Aligner);
  170. }
  171. public bool Init(out string reason)
  172. {
  173. return _aligner.Init(out reason);
  174. }
  175. public bool Home(out string reason)
  176. {
  177. return _aligner.Home(out reason);
  178. }
  179. public bool Align(out string reason)
  180. {
  181. return _aligner.Align(_angle, out reason);
  182. }
  183. public bool Grip(out string reason)
  184. {
  185. return _aligner.Grip(Hand.Blade1, out reason);
  186. }
  187. public bool Release(out string reason)
  188. {
  189. return _aligner.Release(Hand.Blade1, out reason);
  190. }
  191. public bool SetAlign(string target,out string reason)
  192. {
  193. reason = string.Empty;
  194. if (target.StartsWith("P1"))
  195. {
  196. _angle = 0;
  197. }
  198. else if (target.StartsWith("P2"))
  199. {
  200. _angle = 0;
  201. }
  202. else if (target.StartsWith("P3"))
  203. {
  204. _angle = 0;
  205. }
  206. else if (target.StartsWith("P4"))
  207. {
  208. _angle = 0;
  209. }
  210. else if (target.StartsWith("LLA"))
  211. {
  212. _angle = 0;
  213. }
  214. else if (target.StartsWith("LLB"))
  215. {
  216. _angle = 0;
  217. }
  218. else
  219. {
  220. target = target.Replace("D", "");//D***.**, ***.** is angle. (0 to 360.00°)
  221. if (!double.TryParse(target, out _angle))
  222. {
  223. return false;
  224. }
  225. }
  226. return true;
  227. }
  228. }
  229. public class RobotServerModule : IServerModule
  230. {
  231. public bool IsLinkOk
  232. {
  233. get { return Singleton<EfemEntity>.Instance.EfemDevice.CheckIsInitialized(ModuleName.Robot); }
  234. }
  235. public bool Busy
  236. {
  237. get { return Singleton<EfemEntity>.Instance.EfemDevice.CheckIsBusy(ModuleName.Robot); }
  238. }
  239. public bool Error
  240. {
  241. get { return Singleton<EfemEntity>.Instance.EfemDevice.CheckIsError(ModuleName.Robot); }
  242. }
  243. public bool Disabled { get; set; }
  244. public bool Initialized { get; set; }
  245. public bool OriginSearched { get; set; }
  246. public bool InUsed { get; set; }
  247. public RobotServerModule(string name)
  248. {
  249. }
  250. public bool Init(out string reason)
  251. {
  252. if (!Singleton<EfemEntity>.Instance.EfemDevice.Init(ModuleName.Robot))
  253. {
  254. reason = "BUSY";
  255. return false;
  256. }
  257. reason = string.Empty;
  258. return true;
  259. }
  260. public bool Home(out string reason)
  261. {
  262. if (!Singleton<EfemEntity>.Instance.EfemDevice.Home(ModuleName.Robot))
  263. {
  264. reason = "BUSY";
  265. return false;
  266. }
  267. reason = string.Empty;
  268. return true;
  269. }
  270. }
  271. public class LoadPortServerModule : IServerModule
  272. {
  273. public bool IsLinkOk
  274. {
  275. get
  276. {
  277. return Singleton<EfemEntity>.Instance.EfemDevice.CheckLinkOk(_module)
  278. && Singleton<EfemEntity>.Instance.EfemDevice.CheckIsInitialized(_module);
  279. }
  280. }
  281. public bool Busy
  282. {
  283. get { return Singleton<EfemEntity>.Instance.EfemDevice.CheckIsBusy(_module); }
  284. }
  285. public bool Error
  286. {
  287. get { return Singleton<EfemEntity>.Instance.EfemDevice.CheckIsError(_module); }
  288. }
  289. public bool Disabled { get; set; }
  290. public bool Initialized { get; set; }
  291. public bool OriginSearched { get; set; }
  292. public bool InUsed { get; set; }
  293. public bool IsStateIdle
  294. {
  295. get
  296. {
  297. return Singleton<EfemEntity>.Instance.EfemDevice.CheckIsIdle(_module);
  298. }
  299. }
  300. public string SlotMap => Singleton<EfemEntity>.Instance.EfemDevice.GetSlotMap(_module);
  301. private ModuleName _module;
  302. public LoadPortServerModule(ModuleName module)
  303. {
  304. _module = module;
  305. }
  306. public bool Init(out string reason)
  307. {
  308. reason = string.Empty;
  309. return Singleton<EfemEntity>.Instance.EfemDevice.Init(_module);
  310. }
  311. public bool Home(out string reason)
  312. {
  313. reason = string.Empty;
  314. return Singleton<EfemEntity>.Instance.EfemDevice.Home(_module);
  315. }
  316. public bool Lock(out string reason)
  317. {
  318. reason = string.Empty;
  319. return Singleton<EfemEntity>.Instance.EfemDevice.Lock(_module);
  320. }
  321. public bool Unlock(out string reason)
  322. {
  323. reason = string.Empty;
  324. return Singleton<EfemEntity>.Instance.EfemDevice.Unlock(_module);
  325. }
  326. public bool Dock(out string reason)
  327. {
  328. reason = string.Empty;
  329. return Singleton<EfemEntity>.Instance.EfemDevice.Dock(_module);
  330. }
  331. public bool Undock(out string reason)
  332. {
  333. reason = string.Empty;
  334. return Singleton<EfemEntity>.Instance.EfemDevice.Undock(_module);
  335. }
  336. public bool OpenDoor(out string reason)
  337. {
  338. reason = string.Empty;
  339. return Singleton<EfemEntity>.Instance.EfemDevice.OpenDoor(_module);
  340. }
  341. public bool CloseDoor(out string reason)
  342. {
  343. reason = string.Empty;
  344. return Singleton<EfemEntity>.Instance.EfemDevice.CloseDoor(_module);
  345. }
  346. public bool Open(out string reason)
  347. {
  348. reason = string.Empty;
  349. Singleton<EfemEntity>.Instance.EfemDevice.Open(_module);
  350. return true;
  351. }
  352. public bool Close(out string reason)
  353. {
  354. reason = string.Empty;
  355. return Singleton<EfemEntity>.Instance.EfemDevice.Close(_module);
  356. }
  357. public bool Map(out string reason)
  358. {
  359. reason = string.Empty;
  360. Singleton<EfemEntity>.Instance.EfemDevice.Map(_module);
  361. return true;
  362. }
  363. }
  364. public class BufferServerModule : IServerModule
  365. {
  366. public bool IsLinkOk
  367. {
  368. get { return _buffer != null; }
  369. }
  370. public bool Busy
  371. {
  372. get { return false; }
  373. }
  374. public bool Error
  375. {
  376. get { return false; }
  377. }
  378. public bool Disabled { get; set; }
  379. public bool Initialized { get; set; }
  380. public bool OriginSearched { get; set; }
  381. public bool InUsed { get; set; }
  382. public string Name { get; set; }
  383. public BufferStation GetDevice()
  384. {
  385. return _buffer;
  386. }
  387. protected BufferStation _buffer = null;
  388. public BufferServerModule(string name)
  389. {
  390. Name = name;
  391. _buffer = DEVICE.GetDevice<BufferStation>(name);
  392. }
  393. public bool Init(out string reason)
  394. {
  395. reason = string.Empty;
  396. return true;
  397. }
  398. public bool Home(out string reason)
  399. {
  400. reason = string.Empty;
  401. return true;
  402. }
  403. }
  404. public class EfemServerModule : Singleton<EfemServerModule>
  405. {
  406. private SystemServerModule _system = null;
  407. private AlignerServerModule _aligner = null;
  408. private RobotServerModule _robot = null;
  409. private LoadPortServerModule _loadportA = null;
  410. private LoadPortServerModule _loadportB = null;
  411. private LoadPortServerModule _loadportC = null;
  412. private LoadPortServerModule _loadportD = null;
  413. private LoadPortServerModule _loadportE = null;
  414. private LoadPortServerModule _loadportF = null;
  415. private LoadPortServerModule _loadportG = null;
  416. private LoadPortServerModule _loadportH = null;
  417. private LoadPortServerModule _loadportI = null;
  418. private LoadPortServerModule _loadportJ = null;
  419. private BufferServerModule _coolbuffer1 = null;
  420. private BufferServerModule _coolbuffer2 = null;
  421. private BufferServerModule _buffer1 = null;
  422. private BufferServerModule _buffer2 = null;
  423. private BufferServerModule _buffer3 = null;
  424. private BufferServerModule _buffer4 = null;
  425. public EfemServerModule()
  426. {
  427. _system = new SystemServerModule(DeviceName.System);
  428. _aligner = new AlignerServerModule(DeviceName.Aligner);
  429. _robot = new RobotServerModule(DeviceName.Robot);
  430. _loadportA = new LoadPortServerModule(ModuleName.LP1);
  431. _loadportB = new LoadPortServerModule(ModuleName.LP2);
  432. _loadportC = new LoadPortServerModule(ModuleName.LP3);
  433. _loadportD = new LoadPortServerModule(ModuleName.LP4);
  434. _loadportE = new LoadPortServerModule(ModuleName.LP5);
  435. _loadportF = new LoadPortServerModule(ModuleName.LP6);
  436. _loadportG = new LoadPortServerModule(ModuleName.LP7);
  437. _loadportH = new LoadPortServerModule(ModuleName.LP8);
  438. _loadportI = new LoadPortServerModule(ModuleName.LP9);
  439. _loadportJ = new LoadPortServerModule(ModuleName.LP10);
  440. _coolbuffer1 = new BufferServerModule(DeviceName.CoolingBuffer1);
  441. _coolbuffer2 = new BufferServerModule(DeviceName.CoolingBuffer2);
  442. _buffer1 = new BufferServerModule(DeviceName.Buffer1);
  443. _buffer2 = new BufferServerModule(DeviceName.Buffer2);
  444. _buffer3 = new BufferServerModule(DeviceName.Buffer3);
  445. _buffer4 = new BufferServerModule(DeviceName.Buffer4);
  446. }
  447. public IServerModule GetModule(string name)
  448. {
  449. if (ModuleHelper.IsLoadPort((ModuleName)Enum.Parse(typeof(ModuleName),name)))
  450. {
  451. string pattern = "[1-9]\\d*";
  452. Regex rgx = new Regex(pattern);
  453. var match = int.Parse(rgx.Match(name).ToString());
  454. if (match > DeviceDefineManager.Instance.GetValue<int>("LoadPortQuantity"))
  455. {
  456. return null;
  457. }
  458. }
  459. switch (name)
  460. {
  461. case DeviceName.System:
  462. return _system;
  463. case DeviceName.Aligner:
  464. return _aligner;
  465. case DeviceName.Robot:
  466. return _robot;
  467. case DeviceName.LP1:
  468. return _loadportA;
  469. case DeviceName.LP2:
  470. return _loadportB;
  471. case DeviceName.LP3:
  472. return _loadportC;
  473. case DeviceName.LP4:
  474. return _loadportD;
  475. case DeviceName.LP5:
  476. return _loadportE;
  477. case DeviceName.LP6:
  478. return _loadportF;
  479. case DeviceName.LP7:
  480. return _loadportG;
  481. case DeviceName.LP8:
  482. return _loadportH;
  483. case DeviceName.LP9:
  484. return _loadportI;
  485. case DeviceName.LP10:
  486. return _loadportJ;
  487. case DeviceName.CoolingBuffer1:
  488. return _coolbuffer1;
  489. case DeviceName.CoolingBuffer2:
  490. return _coolbuffer2;
  491. case DeviceName.Buffer1:
  492. return _buffer1;
  493. case DeviceName.Buffer2:
  494. return _buffer2;
  495. case DeviceName.Buffer3:
  496. return _buffer3;
  497. case DeviceName.Buffer4:
  498. return _buffer4;
  499. }
  500. return null;
  501. }
  502. }
  503. }