ServerModule.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. using Aitex.Core.RT.Device;
  5. using Aitex.Core.RT.Event;
  6. using Aitex.Core.Util;
  7. using Aitex.Sorter.Common;
  8. using Efem.Protocol;
  9. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  10. using EFEM.RT.Modules;
  11. using MECF.Framework.Common.Equipment;
  12. using MECF.Framework.Common.OperationCenter;
  13. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  14. using System.Threading;
  15. using Aitex.Core.RT.Device.Unit;
  16. using Aitex.Core.Common;
  17. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase;
  18. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase;
  19. using Aitex.Core.RT.SCCore;
  20. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.BufferStations;
  21. using Aitex.Core.RT.OperationCenter;
  22. namespace EFEM.RT.Tasks
  23. {
  24. public interface IData
  25. {
  26. bool Error { get; }
  27. bool IsLinkOk { get; }
  28. bool Busy { get; }
  29. //bool Moving { get; }
  30. bool Disabled { get; set; }
  31. bool Initialized { get; set; }
  32. bool OriginSearched { get; set; }
  33. bool InUsed { get; set; }
  34. }
  35. public interface IFunction
  36. {
  37. bool Reset(out string reason);
  38. bool Init(out string reason);
  39. bool Home(out string reason);
  40. }
  41. public interface IServerModule : IData, IFunction
  42. {
  43. string Name { get; set; }
  44. }
  45. public class SystemServerModule : IServerModule
  46. {
  47. //public bool Communication { get { return Singleton<EfemManager>.Instance.IsConnected; } set { } }
  48. public string Name { get; set; }
  49. public bool Busy { get { return Singleton<RouteManager>.Instance.IsRunning; } }
  50. public bool Moving { get; set; }
  51. public bool Error
  52. {
  53. get { return Singleton<RouteManager>.Instance.IsError;}
  54. }
  55. public bool IsLinkOk
  56. {
  57. get { return Singleton<EfemEntity>.Instance.IsCommunicationOk; }
  58. }
  59. public bool Disabled { get; set; }
  60. public bool Initialized { get; set; }
  61. public bool OriginSearched { get; set; }
  62. public bool InUsed { get; set; }
  63. private Dictionary<EfemEventType, EfemEventValue> _dicEventStatus = new Dictionary<EfemEventType, EfemEventValue>();
  64. public SystemServerModule(string name)
  65. {
  66. Name = name;
  67. foreach (var value in Enum.GetValues(typeof(EfemEventType)))
  68. {
  69. _dicEventStatus[(EfemEventType) value] = EfemEventValue.ON;
  70. }
  71. }
  72. public bool Reset(out string reason)
  73. {
  74. reason = string.Empty;
  75. if (!Singleton<RouteManager>.Instance.CheckToPostMsg(RouteManager.MSG.RESET))
  76. {
  77. reason = "BUSY";
  78. return false;
  79. }
  80. Thread.Sleep(100);//can not remove
  81. //Initialized = true;
  82. return true;
  83. }
  84. public bool Init(out string reason)
  85. {
  86. reason = string.Empty;
  87. if(!Singleton<RouteManager>.Instance.CheckToPostMsg(RouteManager.MSG.HOME))
  88. {
  89. reason = "BUSY";
  90. return false;
  91. }
  92. Thread.Sleep(100);//can not remove
  93. Initialized = true;
  94. return true;
  95. }
  96. public bool Home(out string reason)
  97. {
  98. reason = string.Empty;
  99. if (!Singleton<RouteManager>.Instance.CheckToPostMsg(RouteManager.MSG.HOME))
  100. {
  101. reason = "BUSY";
  102. return false;
  103. }
  104. Initialized = true;
  105. return true;
  106. }
  107. public bool MapWafer(string device, out string reason)
  108. {
  109. reason = string.Empty;
  110. if (!Singleton<RouteManager>.Instance.CheckToPostMsg(RouteManager.MSG.MapWafer, device))
  111. {
  112. reason = "BUSY";
  113. return false;
  114. }
  115. return true;
  116. }
  117. public bool SetEvent(EfemEventType type, EfemEventValue value)
  118. {
  119. _dicEventStatus[type] = value;
  120. return true;
  121. }
  122. public bool IsEventEnabled(EfemEventType type)
  123. {
  124. return _dicEventStatus[type] == EfemEventValue.ON;
  125. }
  126. public bool Hold()
  127. {
  128. return true;
  129. }
  130. public bool Resume()
  131. {
  132. return true;
  133. }
  134. public bool Abort()
  135. {
  136. return true;
  137. }
  138. public bool Stop()
  139. {
  140. return true;
  141. }
  142. public bool ClearError()
  143. {
  144. //InvokeClient.Instance.Service.DoOperation("System.Reset");
  145. //Singleton<EventManager>.Instance.ClearAlarmEvent();
  146. if (Singleton<RouteManager>.Instance.IsError||(DEVICE.GetDevice<LoadPortBaseDevice>(ModuleName.LP1.ToString()) != null && DEVICE.GetDevice<LoadPortBaseDevice>(ModuleName.LP1.ToString()).State == DeviceState.Error)||(DEVICE.GetDevice<LoadPortBaseDevice>(ModuleName.LP2.ToString()) != null && DEVICE.GetDevice<LoadPortBaseDevice>(ModuleName.LP2.ToString()).State == DeviceState.Error))
  147. {
  148. // Singleton<RouteManager>.Instance.Invoke("Reset");
  149. //OP.DoOperation("System.Reset");
  150. //Thread.Sleep(1000);
  151. Singleton<RouteManager>.Instance.ClearEventLogEnable = true;
  152. //Singleton<EventManager>.Instance.ClearAlarmEvent();
  153. }
  154. return true;
  155. }
  156. public string GetLastError()
  157. {
  158. return string.Empty;
  159. }
  160. }
  161. public class AlignerServerModule : IServerModule
  162. {
  163. public bool IsLinkOk
  164. {
  165. get { return _aligner!=null && _aligner.Communication; }
  166. }
  167. public bool Busy
  168. {
  169. get { return _aligner.Busy; }
  170. }
  171. public bool Moving
  172. {
  173. get { return _aligner.Moving; }
  174. }
  175. public bool Error
  176. {
  177. get { return _aligner.Error; }
  178. }
  179. public string Name { get; set; }
  180. public bool Disabled { get; set; }
  181. public bool Initialized { get; set; }
  182. public bool OriginSearched { get; set; }
  183. public bool InUsed { get; set; }
  184. private double _angle = 0;
  185. public Aligner GetDevice()
  186. {
  187. return _aligner;
  188. }
  189. protected Aligner _aligner = null;
  190. public AlignerServerModule(string name)
  191. {
  192. Name = name;
  193. _aligner = DEVICE.GetDevice<Aligner>(DeviceName.Aligner);
  194. }
  195. public bool Init(out string reason)
  196. {
  197. return _aligner.Init(out reason);
  198. }
  199. public bool Home(out string reason)
  200. {
  201. return _aligner.Home(out reason);
  202. }
  203. public bool Align(out string reason)
  204. {
  205. return _aligner.Align(_angle, out reason);
  206. }
  207. public bool SetAlign(string target,out string reason)
  208. {
  209. reason = string.Empty;
  210. if (target.StartsWith("P1"))
  211. {
  212. _angle = 0;
  213. }
  214. else if (target.StartsWith("P2"))
  215. {
  216. _angle = 0;
  217. }
  218. else if (target.StartsWith("P3"))
  219. {
  220. _angle = 0;
  221. }
  222. else if (target.StartsWith("P4"))
  223. {
  224. _angle = 0;
  225. }
  226. else if (target.StartsWith("LLA"))
  227. {
  228. _angle = 0;
  229. }
  230. else if (target.StartsWith("LLB"))
  231. {
  232. _angle = 0;
  233. }
  234. else
  235. {
  236. target = target.Replace("D", "");//D***.**, ***.** is angle. (0 to 360.00°)
  237. if (!double.TryParse(target, out _angle))
  238. {
  239. return false;
  240. }
  241. }
  242. return true;
  243. }
  244. bool IFunction.Reset(out string reason)
  245. {
  246. reason = string.Empty;
  247. return true;
  248. }
  249. }
  250. public class RobotServerModule : IServerModule
  251. {
  252. public bool IsLinkOk
  253. {
  254. get { return _robot != null; }
  255. }
  256. public bool Busy
  257. {
  258. get { return _robot.IsBusy; }
  259. }
  260. //public bool Moving
  261. //{
  262. // get { return _robot.Moving; }
  263. //}
  264. public bool Error
  265. {
  266. get { return _robot.IsError; }
  267. }
  268. public bool Disabled { get; set; }
  269. public bool Initialized { get; set; }
  270. public bool OriginSearched { get; set; }
  271. public bool InUsed { get; set; }
  272. public string Name { get; set; }
  273. public RobotBaseDevice GetDevice()
  274. {
  275. return _robot;
  276. }
  277. protected RobotBaseDevice _robot = null;
  278. public RobotServerModule(string name)
  279. {
  280. Name = name;
  281. _robot = DEVICE.GetDevice<RobotBaseDevice>(DeviceName.Robot);
  282. }
  283. public bool Reset(out string reason)
  284. {
  285. reason = null;
  286. return _robot.RobotReset();
  287. }
  288. public bool Init(out string reason)
  289. {
  290. reason = null;
  291. return _robot.Init(null);
  292. }
  293. public bool Home(out string reason)
  294. {
  295. reason = null;
  296. return _robot.Home(null);
  297. }
  298. }
  299. public class LoadPortServerModule : IServerModule
  300. {
  301. public bool IsLinkOk
  302. {
  303. get { return _loadport!=null; }
  304. }
  305. public bool Busy
  306. {
  307. get { return _loadport.IsBusy; }
  308. }
  309. //public bool Moving
  310. //{
  311. // get { return _loadport.IsMoving; }
  312. //}
  313. public bool Error
  314. {
  315. get { return _loadport.IsError; }
  316. }
  317. public FoupDockState DockState
  318. {
  319. get { return _loadport.DockState; }
  320. }
  321. public bool Disabled { get; set; }
  322. public bool Initialized { get; set; }
  323. public bool OriginSearched { get; set; }
  324. public bool InUsed { get; set; }
  325. public string Name { get; set; }
  326. public string SlotMap => _loadport.SlotMap;
  327. public LoadPortBaseDevice GetDevice()
  328. {
  329. return _loadport;
  330. }
  331. protected LoadPortBaseDevice _loadport = null;
  332. public LoadPortServerModule(string name)
  333. {
  334. Name = name;
  335. _loadport = DEVICE.GetDevice<LoadPortBaseDevice>(name);
  336. }
  337. public bool Reset(out string reason)
  338. {
  339. return _loadport.LoadportReset(out reason);
  340. }
  341. public bool Init(out string reason)
  342. {
  343. return _loadport.Home(out reason);
  344. }
  345. public bool Home(out string reason)
  346. {
  347. return _loadport.Home(out reason);
  348. }
  349. public bool Lock(out string reason)
  350. {
  351. return _loadport.Clamp(out reason);
  352. }
  353. public bool Unlock(out string reason)
  354. {
  355. return _loadport.Unclamp(out reason);
  356. }
  357. public bool Dock(out string reason)
  358. {
  359. return _loadport.Dock(out reason);
  360. }
  361. public bool Undock(out string reason)
  362. {
  363. return _loadport.Undock(out reason);
  364. }
  365. public bool OpenDoor(out string reason)
  366. {
  367. return _loadport.OpenDoor(out reason);
  368. }
  369. public bool CloseDoor(out string reason)
  370. {
  371. return _loadport.CloseDoor(out reason);
  372. }
  373. public bool Open(out string reason)
  374. {
  375. return _loadport.Load(out reason);
  376. }
  377. public bool Read(out string reason)
  378. {
  379. reason = null;
  380. return _loadport.ReadCarrierID(0,16);
  381. }
  382. public bool Read()
  383. {
  384. return _loadport.ReadCarrierID();
  385. }
  386. public bool Read(string type,out string reason)
  387. {
  388. reason = null;
  389. string filename = "LCDFILE.TXT";
  390. if (type == "LID") filename = "LCDFILE.TXT";
  391. if(type == "CID") filename = "CARRIER.TXT";
  392. return _loadport.ReadCarrierID(new object[]{ filename });
  393. }
  394. public bool Write(string cid)
  395. {
  396. return _loadport.WriteCarrierID(cid, 0, 16, "", out _);
  397. }
  398. public bool Write(string cid,out string reason)
  399. {
  400. reason = null;
  401. return SC.GetValue<Boolean>("System.OnlyLotId") ? _loadport.WriteCarrierIDByIndex(cid, 0, 16 ,0) : _loadport.WriteCarrierID(cid, 0,16);
  402. }
  403. public bool Close(out string reason)
  404. {
  405. return _loadport.Unload(out reason);
  406. }
  407. public bool QueryWaferMap(out string reason)
  408. {
  409. return _loadport.QueryWaferMap(out reason);
  410. }
  411. }
  412. public class BufferServerModule : IServerModule
  413. {
  414. public bool IsLinkOk
  415. {
  416. get { return _buffer!=null; }
  417. }
  418. public bool Busy
  419. {
  420. get { return _buffer.Busy; }
  421. }
  422. //public bool Moving
  423. //{
  424. // get { return _buffer.Moving; }
  425. //}
  426. public bool Error
  427. {
  428. get { return _buffer.Error; }
  429. }
  430. public bool Disabled { get; set; }
  431. public bool Initialized { get; set; }
  432. public bool OriginSearched { get; set; }
  433. public bool InUsed { get; set; }
  434. public string Name { get; set; }
  435. public IoCoolingBuffer GetDevice()
  436. {
  437. return _buffer;
  438. }
  439. protected IoCoolingBuffer _buffer = null;
  440. public BufferServerModule(string name)
  441. {
  442. Name = name;
  443. _buffer = DEVICE.GetDevice<IoCoolingBuffer>(name);
  444. }
  445. public bool Init(out string reason)
  446. {
  447. return _buffer.Home(out reason);
  448. }
  449. public bool Home(out string reason)
  450. {
  451. return _buffer.Home(out reason);
  452. }
  453. public bool LiftUp(WaferSize size,out string reason)
  454. {
  455. return _buffer.Move(size, true ,out reason);
  456. }
  457. public bool LiftDown(WaferSize size, out string reason)
  458. {
  459. return _buffer.Move(size, false, out reason);
  460. }
  461. public bool Align(WaferSize size, out string reason)
  462. {
  463. return _buffer.Move(size, false, out reason);
  464. }
  465. public bool Reset(out string reason)
  466. {
  467. reason = string.Empty;
  468. return true;
  469. }
  470. }
  471. public class BufferStationServerModule : IServerModule
  472. {
  473. public bool IsLinkOk
  474. {
  475. get { return _buffer != null; }
  476. }
  477. public bool Busy
  478. {
  479. get { return false; }
  480. }
  481. public bool Error
  482. {
  483. get { return false; }
  484. }
  485. public bool Disabled { get; set; }
  486. public bool Initialized { get; set; }
  487. public bool OriginSearched { get; set; }
  488. public bool InUsed { get; set; }
  489. public string Name { get; set; }
  490. public BufferStation GetDevice()
  491. {
  492. return _buffer;
  493. }
  494. protected BufferStation _buffer = null;
  495. public BufferStationServerModule(string name)
  496. {
  497. OriginSearched = true;
  498. Initialized = true;
  499. Name = name;
  500. _buffer = DEVICE.GetDevice<BufferStation>(name);
  501. }
  502. public bool Init(out string reason)
  503. {
  504. reason = string.Empty;
  505. return true;
  506. }
  507. public bool Home(out string reason)
  508. {
  509. reason = string.Empty;
  510. return true;
  511. }
  512. public bool Reset(out string reason)
  513. {
  514. reason = string.Empty;
  515. return true;
  516. }
  517. }
  518. public class EntityFactory
  519. {
  520. private SystemServerModule _system = null;
  521. private AlignerServerModule _aligner = null;
  522. private RobotServerModule _robot = null;
  523. private LoadPortServerModule _loadportA = null;
  524. private LoadPortServerModule _loadportB = null;
  525. private LoadPortServerModule _loadportC = null;
  526. private LoadPortServerModule _loadportD = null;
  527. private LoadPortServerModule _loadportE = null;
  528. private LoadPortServerModule _loadportF = null;
  529. private LoadPortServerModule _loadportG = null;
  530. private LoadPortServerModule _loadportH = null;
  531. private LoadPortServerModule _loadportI = null;
  532. private LoadPortServerModule _loadportJ = null;
  533. private BufferServerModule _buffer1 = null;
  534. private BufferServerModule _buffer2 = null;
  535. private BufferServerModule _aligner1 = null;
  536. private BufferServerModule _aligner2 = null;
  537. private BufferStationServerModule _bufferStation1 = null;
  538. private BufferStationServerModule _bufferStation2 = null;
  539. public EntityFactory()
  540. {
  541. _system = new SystemServerModule(DeviceName.System);
  542. _aligner = new AlignerServerModule(DeviceName.Aligner);
  543. _robot = new RobotServerModule(DeviceName.Robot);
  544. _loadportA = new LoadPortServerModule(DeviceName.LP1);
  545. _loadportB = new LoadPortServerModule(DeviceName.LP2);
  546. _loadportC = new LoadPortServerModule(DeviceName.LP3);
  547. _loadportD = new LoadPortServerModule(DeviceName.LP4);
  548. _loadportE = new LoadPortServerModule(DeviceName.LP5);
  549. _loadportF = new LoadPortServerModule(DeviceName.LP6);
  550. _loadportG = new LoadPortServerModule(DeviceName.LP7);
  551. _loadportH = new LoadPortServerModule(DeviceName.LP8);
  552. _loadportI = new LoadPortServerModule(DeviceName.LP9);
  553. _loadportJ = new LoadPortServerModule(DeviceName.LP10);
  554. _aligner1 = new BufferServerModule(DeviceName.Aligner1);
  555. _aligner2 = new BufferServerModule(DeviceName.Aligner2);
  556. _buffer1 = new BufferServerModule(DeviceName.CoolingBuffer1);
  557. _buffer2 = new BufferServerModule(DeviceName.CoolingBuffer2);
  558. _bufferStation1= new BufferStationServerModule(DeviceName.Buffer1);
  559. _bufferStation2 = new BufferStationServerModule(DeviceName.Buffer2);
  560. }
  561. public IServerModule GetEntity(string name)
  562. {
  563. if (string.IsNullOrEmpty(name))
  564. return null;
  565. if (ModuleHelper.IsLoadPort((ModuleName)Enum.Parse(typeof(ModuleName),name)))
  566. {
  567. string pattern = "[1-9]\\d*";
  568. Regex rgx = new Regex(pattern);
  569. var match = int.Parse(rgx.Match(name).ToString());
  570. if (match > DeviceDefineManager.Instance.GetValue<int>("LoadPortQuantity"))
  571. {
  572. return null;
  573. }
  574. }
  575. switch (name)
  576. {
  577. case DeviceName.System:
  578. return _system;
  579. case DeviceName.Aligner:
  580. return _aligner;
  581. case DeviceName.Robot:
  582. return _robot;
  583. case DeviceName.LP1:
  584. return _loadportA;
  585. case DeviceName.LP2:
  586. return _loadportB;
  587. case DeviceName.LP3:
  588. return _loadportC;
  589. case DeviceName.LP4:
  590. return _loadportD;
  591. case DeviceName.LP5:
  592. return _loadportE;
  593. case DeviceName.LP6:
  594. return _loadportF;
  595. case DeviceName.LP7:
  596. return _loadportG;
  597. case DeviceName.LP8:
  598. return _loadportH;
  599. case DeviceName.LP9:
  600. return _loadportI;
  601. case DeviceName.LP10:
  602. return _loadportJ;
  603. case DeviceName.Aligner1:
  604. return _aligner1;
  605. case DeviceName.Aligner2:
  606. return _aligner2;
  607. case DeviceName.Aligner3:
  608. return _aligner1;
  609. case DeviceName.Aligner4:
  610. return _aligner2;
  611. case DeviceName.CoolingBuffer1:
  612. return _buffer1;
  613. case DeviceName.CoolingBuffer2:
  614. return _buffer2;
  615. case DeviceName.Buffer1:
  616. return _bufferStation1;
  617. case DeviceName.Buffer2:
  618. return _bufferStation2;
  619. }
  620. return null;
  621. }
  622. }
  623. }