EfemDevice.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Collections.Specialized;
  5. using System.Linq;
  6. using System.Xml;
  7. using Aitex.Core.Common;
  8. using Aitex.Core.RT.DataCenter;
  9. using Aitex.Core.RT.Device;
  10. using Aitex.Core.RT.Event;
  11. using Aitex.Core.RT.SCCore;
  12. using Aitex.Core.Util;
  13. using Aitex.Sorter.Common;
  14. using MECF.Framework.Common.Equipment;
  15. using MECF.Framework.Common.SubstrateTrackings;
  16. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  17. using Virgo_DCommon;
  18. using Virgo_DRT.Devices;
  19. using Virgo_DRT.Devices.YASKAWA;
  20. using Virgo_DRT.Modules;
  21. using System.Diagnostics;
  22. using Aitex.Core.Common.DeviceData;
  23. namespace Virgo_DRT.Device
  24. {
  25. class EfemCommunicationBase
  26. {
  27. protected readonly AsyncSocket _socket = new AsyncSocket("");
  28. protected EfemCommunicationBase(string sIP)
  29. {
  30. string ip_address = sIP;
  31. if (SC.GetValue<bool>("System.IsSimulatorMode"))
  32. {
  33. ip_address = "127.0.0.1:13001";
  34. }
  35. _socket.Connect(ip_address);
  36. _socket.OnDataChanged += Hardware_OnDataChanged;
  37. _socket.OnErrorHappened += Hardware_OnErrorHappened;
  38. //if (!_socket.IsConnected)
  39. //{
  40. // EV.PostAlarmLog(ModuleName.EFEM.ToString(), "Cannot connect to EFEM");
  41. //}
  42. }
  43. private void Hardware_OnDataChanged(string message)
  44. {
  45. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.RecHwMsg, message);
  46. }
  47. private void Hardware_OnErrorHappened(ErrorEventArgs args)
  48. {
  49. }
  50. public virtual void SendTo(string str) { }
  51. public virtual void SendTo(IEfemMessage yas_msg) { }
  52. }
  53. class EfemBase : BaseDevice, IDevice
  54. {
  55. // Fields
  56. //
  57. protected volatile LinkedList<ActionBase> _actions = new LinkedList<ActionBase>();
  58. protected EfemCommunicationBase _comm;
  59. protected IMessageHandler _msgHandler;
  60. public virtual ILoadport this[ModuleName mod]
  61. {
  62. get { throw new ApplicationException(); }
  63. }
  64. // Properties
  65. //
  66. public new ModuleName Module { get; set; }
  67. public OnlineFlag OnlineFlag { get; set; }
  68. public bool CommunicationConnected { get; protected set; }
  69. public DeviceState Status { get; set; }
  70. public bool HasActions => _actions.Any(x => x.Status == ActionStatus.Pending);
  71. public EfemCommunicationBase Comm => _comm;
  72. public IMessageHandler MsgHandler => _msgHandler;
  73. // Constructor
  74. //
  75. protected EfemBase(XmlElement xmlNode = null)
  76. {
  77. }
  78. public bool Initialize()
  79. {
  80. return true;
  81. }
  82. public void Monitor()
  83. {
  84. throw new NotImplementedException();
  85. }
  86. public void Terminate()
  87. {
  88. throw new NotImplementedException();
  89. }
  90. public void Reset()
  91. {
  92. throw new NotImplementedException();
  93. }
  94. // Methods
  95. //
  96. public void ExecuteAction()
  97. {
  98. if (!_actions.Any())
  99. {
  100. Debug.WriteLine("No Action in the EFEM Queue");
  101. return;
  102. }
  103. if (_actions.All(x => x.Status != ActionStatus.Pending))
  104. {
  105. Debug.Print("NO pending Action in EFEM Queue");
  106. return;
  107. }
  108. var nextAction = _actions.First(a => a.Status == ActionStatus.Pending);
  109. if (nextAction != null)
  110. {
  111. Debug.WriteLine($"{nextAction.GetType()} 开始执行");
  112. nextAction.Execute();
  113. }
  114. }
  115. public void ClearActions() { _actions?.Clear(); }
  116. public void AddAction(ActionBase cmd)
  117. {
  118. _actions.AddLast(cmd);
  119. }
  120. public void UpdateStatus(ushort Id, ActionStatus st)
  121. {
  122. var cur = _actions.First(x => x.ID == Id);
  123. if (null == cur)
  124. throw new ApplicationException($"NO {Id} action in the queue");
  125. cur.Status = st;
  126. if (st == ActionStatus.Completed)
  127. {
  128. cur.OnPostWork();
  129. }
  130. }
  131. public virtual void ReceiveMessage(string sRec) { throw new NotImplementedException(); }
  132. public void SetOnline(bool online)
  133. {
  134. this.OnlineFlag = online ? OnlineFlag.Online : OnlineFlag.Offline;
  135. }
  136. public virtual void SetOnline(ModuleName mod, bool online) { }
  137. public virtual void SetBusy(ModuleName mod, bool online) { }
  138. }
  139. }
  140. namespace Virgo_DRT.Device.YASKAWA
  141. {
  142. sealed class MessageHandler : IMessageHandler
  143. {
  144. // Fields
  145. //
  146. private readonly IList<EfemMessage> _msgQueue = new List<EfemMessage>();
  147. private readonly EfemBase _efem;
  148. // Properties
  149. //
  150. public bool IsCompleted
  151. {
  152. get
  153. {
  154. if (_msgQueue.Count <= 0) return false;
  155. return EfemMessage.MsgHead.INF == _msgQueue[_msgQueue.Count - 1].Head;
  156. }
  157. }
  158. public event EventHandler<EfemActionArgs> CommandUpdated;
  159. public event EventHandler<EfemEventArgs> EventUpdated;
  160. public event EventHandler<EfemErrorArgs> ErrorOccurred;
  161. // Constructor
  162. //
  163. public MessageHandler(EfemBase device)
  164. {
  165. _efem = device;
  166. }
  167. public void Send(IEfemMessage msg)
  168. {
  169. _efem.Comm.SendTo(msg);
  170. _msgQueue.Add(msg as EfemMessage);
  171. }
  172. public void ReceiveMessage(string sRec)
  173. {
  174. string[] msgs = sRec.Split('\r');
  175. foreach (var msg in msgs)
  176. {
  177. if (string.IsNullOrWhiteSpace(msg)) continue;
  178. EfemMessage rec_msg = msg.ToMessage();
  179. switch (rec_msg.Head)
  180. {
  181. case EfemMessage.MsgHead.ACK:
  182. _msgQueue.Add(rec_msg);
  183. OnCommandUpdated(new EfemActionArgs
  184. {
  185. Module = rec_msg.Port,
  186. CommandType = rec_msg.Operation,
  187. Status = ActionStatus.RecACK
  188. });
  189. break;
  190. case EfemMessage.MsgHead.INF:
  191. OnCommandUpdated(new EfemActionArgs
  192. {
  193. Module = rec_msg.Port,
  194. CommandType = rec_msg.Operation,
  195. Status = ActionStatus.RecINF
  196. });
  197. // 收到INF之后发送ACK确认
  198. string strACK = rec_msg.RawString.Replace("INF", "ACK");
  199. _efem.Comm.SendTo(strACK);
  200. EfemMessage ack_msg = strACK.ToMessage();
  201. ack_msg.Direct = MsgDirection.To;
  202. _msgQueue.Add(ack_msg);
  203. OnCommandUpdated(new EfemActionArgs
  204. {
  205. Module = rec_msg.Port,
  206. CommandType = rec_msg.Operation,
  207. Status = ActionStatus.Completed,
  208. Data = rec_msg.Data.Count > 0 ? rec_msg.Data.First() : string.Empty
  209. });
  210. break;
  211. case EfemMessage.MsgHead.EVT:
  212. OnEventUpdated(new EfemEventArgs
  213. {
  214. EvtStr = rec_msg.ToParamString(),
  215. Module = rec_msg.Port,
  216. CommandType = rec_msg.Operation,
  217. DataList = rec_msg.Data
  218. });
  219. break;
  220. case EfemMessage.MsgHead.NAK:
  221. OnErrorOccurred(new EfemErrorArgs
  222. {
  223. Factor = rec_msg.Factor,
  224. Description = Constant.FactorString[rec_msg.Factor]
  225. });
  226. break;
  227. case EfemMessage.MsgHead.CAN:
  228. OnErrorOccurred(new EfemErrorArgs
  229. {
  230. Factor = rec_msg.Factor,
  231. Description = Constant.FactorString[rec_msg.Factor],
  232. Message = rec_msg.Data[0]
  233. });
  234. break;
  235. case EfemMessage.MsgHead.ABS:
  236. OnErrorOccurred(new EfemErrorArgs
  237. {
  238. Factor = rec_msg.Factor,
  239. Description = $"{rec_msg.Data[0]}, {rec_msg.Data[1]}"
  240. });
  241. break;
  242. }
  243. }
  244. }
  245. private void OnCommandUpdated(EfemActionArgs args)
  246. {
  247. CommandUpdated?.Invoke(this, args);
  248. }
  249. private void OnEventUpdated(EfemEventArgs args)
  250. {
  251. EventUpdated?.Invoke(this, args);
  252. }
  253. private void OnErrorOccurred(EfemErrorArgs args)
  254. {
  255. ErrorOccurred?.Invoke(this, args);
  256. }
  257. }
  258. sealed class EfemComm : EfemCommunicationBase
  259. {
  260. public EfemComm() : base(SC.GetStringValue("EFEM.IPAddress"))
  261. {
  262. }
  263. public override void SendTo(string str) { _socket.Write(str + '\r'); }
  264. public override void SendTo(IEfemMessage msg)
  265. {
  266. if (msg is EfemMessage yas_msg)
  267. {
  268. //string str = EfemParser.Instance.TranslateBack(yas_msg);
  269. string str = yas_msg.ToString();
  270. if (string.IsNullOrEmpty(str))
  271. throw new ApplicationException("Yaskawa message translation error");
  272. yas_msg.RawString = str;
  273. SendTo(str);
  274. }
  275. }
  276. }
  277. /// <summary>
  278. /// EFEM object class
  279. /// </summary>
  280. sealed class Efem : EfemBase, IEfem
  281. {
  282. //---------------------------------Fields----------------------------------------
  283. //
  284. private readonly JetPM[] _pm = new JetPM[2];
  285. private readonly Loadport[] _LPMs = new Loadport[2];
  286. private readonly SignalTower _signalT = new SignalTower();
  287. //private readonly CoolingStage[] _aligner = new CoolingStage[2];
  288. private string _robotMoveAction;
  289. private LidState _CassetteDoor;
  290. private LidState _SideDoor;
  291. private F_TRIG _bSysVacPressure1 = new F_TRIG();
  292. private F_TRIG _bSysCompressedAirPressure = new F_TRIG();
  293. private R_TRIG _bFlowGaugeSensor = new R_TRIG();
  294. private R_TRIG _bLeakageSensor = new R_TRIG();
  295. private F_TRIG _bDiffPressureSensorSetting1 = new F_TRIG();
  296. private F_TRIG _bDiffPressureSensorSetting2 = new F_TRIG();
  297. private F_TRIG _bIonizerAlarm = new F_TRIG();
  298. private F_TRIG _bFFuAlarm = new F_TRIG();
  299. private F_TRIG _bAreaSensor = new F_TRIG();
  300. private F_TRIG _bModeSwitch = new F_TRIG();
  301. private RD_TRIG _bCassetteDoorTrig = new RD_TRIG();
  302. private RD_TRIG _bSideDoorTrig = new RD_TRIG();
  303. public override ILoadport this[ModuleName mod]
  304. {
  305. get
  306. {
  307. if (!ModuleHelper.IsLoadPort(mod))
  308. throw new ApplicationException($"{mod} is NOT Loadport");
  309. return _LPMs[mod - ModuleName.LP1];
  310. }
  311. }
  312. //---------------------------------Properties------------------------------------
  313. //
  314. public LidState CassetteDoor
  315. {
  316. get => _CassetteDoor;
  317. set
  318. {
  319. _CassetteDoor = value;
  320. _bCassetteDoorTrig.CLK = _CassetteDoor == LidState.Close;
  321. if (_bCassetteDoorTrig.T)
  322. {
  323. EV.PostWarningLog(Module.ToString(), "前门被打开");
  324. }
  325. if (_bCassetteDoorTrig.R)
  326. {
  327. EV.PostInfoLog(Module.ToString(), "前门被关闭");
  328. }
  329. }
  330. }
  331. public LidState DoorSwitch
  332. {
  333. get => _SideDoor;
  334. set
  335. {
  336. _SideDoor = value;
  337. _bSideDoorTrig.CLK = _SideDoor == LidState.Close;
  338. if (_bSideDoorTrig.T)
  339. {
  340. EV.PostWarningLog(Module.ToString(), "侧门被打开");
  341. }
  342. if (_bSideDoorTrig.R)
  343. {
  344. EV.PostInfoLog(Module.ToString(), "侧门被关闭");
  345. }
  346. }
  347. }
  348. // Constructor
  349. //
  350. public Efem()
  351. {
  352. Module = ModuleName.EfemRobot;
  353. _pm[0] = DEVICE.GetDevice<JetPM>(ModuleName.PMA.ToString());
  354. _pm[1] = DEVICE.GetDevice<JetPM>(ModuleName.PMB.ToString());
  355. _comm = new EfemComm();
  356. _LPMs[0] = new Loadport(ModuleName.LP1, this);
  357. _LPMs[1] = new Loadport(ModuleName.LP2, this);
  358. _msgHandler = new MessageHandler(this);
  359. _msgHandler.CommandUpdated += MsgOnCommandUpdated;
  360. _msgHandler.EventUpdated += MsgOnEventUpdated;
  361. _msgHandler.ErrorOccurred += MsgOnErrorOccurred;
  362. CarrierManager.Instance.SubscribeLocation(ModuleName.LP1.ToString(), 1);
  363. CarrierManager.Instance.SubscribeLocation(ModuleName.LP2.ToString(), 1);
  364. WaferManager.Instance.SubscribeLocation(ModuleName.EfemRobot, 1);
  365. WaferManager.Instance.SubscribeLocation(ModuleName.Aligner1, 1);
  366. WaferManager.Instance.SubscribeLocation(ModuleName.Aligner2, 1);
  367. WaferManager.Instance.SubscribeLocation(ModuleName.LP1, 25);
  368. WaferManager.Instance.SubscribeLocation(ModuleName.LP2, 25);
  369. DATA.Subscribe("EfemRobot.RobotMoveAction", () => _robotMoveAction);
  370. DATA.Subscribe("LP1.WaferSize", () => _LPMs[0].WaferSize.ToString());
  371. DATA.Subscribe("LP1.CassetteState", () => _LPMs[0].HasCassette ? LoadportCassetteState.Normal : LoadportCassetteState.Absent);
  372. DATA.Subscribe("LP2.WaferSize", () => _LPMs[1].WaferSize.ToString());
  373. DATA.Subscribe("LP2.CassetteState", () => _LPMs[1].HasCassette ? LoadportCassetteState.Normal : LoadportCassetteState.Absent);
  374. DATA.Subscribe("Aligner1.WaferSize", () => WaferManager.Instance.GetWafer(ModuleName.Aligner1, 0).Size.ToString());
  375. DATA.Subscribe("Aligner2.WaferSize", () => WaferManager.Instance.GetWafer(ModuleName.Aligner2, 0).Size.ToString());
  376. DATA.Subscribe("EfemRobot.WaferSize", () => WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 0).Size.ToString());
  377. DATA.Subscribe("EFEM.CassetteDoor", () => CassetteDoor);
  378. _bCassetteDoorTrig.CLK = true;
  379. _bSideDoorTrig.CLK = true;
  380. }
  381. // Methods
  382. //
  383. public void HomeAll()
  384. {
  385. AddAction(new HomeAllAction(this, ModuleName.EFEM));
  386. AddAction(new OrgshAction(this, ModuleName.EFEM));
  387. }
  388. public void Home(ModuleName mod)
  389. {
  390. AddAction(new HomeModuleAction(this, mod));
  391. }
  392. public void ClearError()
  393. {
  394. AddAction(new ClearErrorAction(this));
  395. }
  396. public void AbortRobot()
  397. {
  398. AddAction(new AbortAction(this));
  399. }
  400. public void Pick(MoveParam mp)
  401. {
  402. if (ModuleHelper.IsPm(mp.SrcModule))
  403. {
  404. JetPM pM = GetPM(mp.SrcModule);
  405. if (pM.IsSlitDoorClosed)
  406. {
  407. EV.PostAlarmLog(pM.Module.ToString(), "Slit 门必须打开");
  408. return;
  409. }
  410. AddAction(new PinAction(mp.SrcModule, pM, MovementPosition.Up, false));
  411. AddAction(new ExtendAction(this, new ExtendParam { Module = mp.SrcModule, Pos = ExtendPos.GB }));
  412. _robotMoveAction = string.Format($"{mp.SrcModule}.Picking");
  413. AddAction(new PinAction(mp.SrcModule, pM, MovementPosition.Down, true));
  414. AddAction(new ExtendAction(this, new ExtendParam { Module = mp.SrcModule, Pos = ExtendPos.G4 }));
  415. }
  416. else
  417. {
  418. _robotMoveAction = string.Format($"{mp.SrcModule}.Picking");
  419. AddAction(new PickAction(this, mp));
  420. }
  421. }
  422. public void Place(MoveParam mp)
  423. {
  424. if (ModuleHelper.IsPm(mp.DestModule))
  425. {
  426. JetPM pM = GetPM(mp.DestModule);
  427. if (pM.IsSlitDoorClosed)
  428. {
  429. EV.PostAlarmLog(pM.Module.ToString(), "Slit 门必须打开");
  430. return;
  431. }
  432. AddAction(new ExtendAction(this, new ExtendParam { Module = mp.DestModule, Pos = ExtendPos.PB }));
  433. _robotMoveAction = string.Format($"{mp.DestModule}.Placing");
  434. AddAction(new PinAction(mp.DestModule, pM, MovementPosition.Up, true));
  435. AddAction(new ExtendAction(this, new ExtendParam { Module = mp.DestModule, Pos = ExtendPos.P4 }));
  436. AddAction(new PinAction(mp.DestModule, pM, MovementPosition.Down, false));
  437. }
  438. else
  439. {
  440. _robotMoveAction = string.Format($"{mp.DestModule}.Placing");
  441. AddAction(new PlaceAction(this, mp));
  442. }
  443. }
  444. public void Extend(ExtendParam ep)
  445. {
  446. AddAction(new ExtendAction(this, ep));
  447. }
  448. public void Retract(ExtendParam ep)
  449. {
  450. AddAction(new ExtendAction(this, ep));
  451. }
  452. public void Map(ModuleName mod)
  453. {
  454. _LPMs[mod - ModuleName.LP1].Map();
  455. }
  456. public void SetPinUp(ModuleName mod)
  457. {
  458. AddAction(new LiftAction(this, mod));
  459. }
  460. public void Align(ModuleName mod, float delayTime, WaferSize size)
  461. {
  462. AddAction(new AlignAction(this, mod, size));
  463. }
  464. public void SetLamp(LightType light, LightStatus status)
  465. {
  466. //AddAction(new LedAction(this, light, status));
  467. }
  468. public void TurnOffAllLamps()
  469. {
  470. //AddAction(new LedAction(this, LightType.RED, LightStatus.OFF));
  471. //AddAction(new LedAction(this, LightType.YELLOW, LightStatus.OFF));
  472. //AddAction(new LedAction(this, LightType.GREEN, LightStatus.OFF));
  473. //AddAction(new LedAction(this, LightType.BUZZER1, LightStatus.OFF));
  474. }
  475. public override void ReceiveMessage(string sRec)
  476. {
  477. _msgHandler.ReceiveMessage(sRec);
  478. }
  479. public override void SetOnline(ModuleName mod, bool online)
  480. {
  481. this[mod].SetOnline(online);
  482. }
  483. public override void SetBusy(ModuleName mod, bool busy)
  484. {
  485. this[mod].Status = DeviceState.Busy;
  486. }
  487. //--------------------------------Constructor------------------------------------
  488. //
  489. private JetPM GetPM(ModuleName mod)
  490. {
  491. if (!ModuleHelper.IsPm(mod))
  492. throw new ArgumentException("Module argument error");
  493. return _pm[mod - ModuleName.PMA];
  494. }
  495. //----------------------------------Private Method-------------------------------
  496. //
  497. private void MsgOnEventUpdated(object sender, EventArgs e)
  498. {
  499. if (!(e is EfemEventArgs))
  500. return;
  501. EfemEventArgs eArg = e as EfemEventArgs;
  502. switch (eArg.CommandType)
  503. {
  504. case EfemOperation.SigStatus:
  505. // EVT:SIGSTAT/Parameter/DATA1/DATA2;
  506. string sParam = eArg.DataList[0]; // "SYSTEM" or "Pn"
  507. // DATA1 & DATA2
  508. int nData1 = Convert.ToInt32(eArg.DataList[1], 16);
  509. int nData2 = Convert.ToInt32(eArg.DataList[2], 16);
  510. BitArray baData1 = new BitArray(new int[] { nData1});
  511. BitArray baData2 = new BitArray(new int[] { nData2});
  512. if (0 == string.Compare(sParam, Constant.SYS, true))
  513. {
  514. // EVT:SIGSTAT/System/00000000/00000004;
  515. // DATA1
  516. _bSysVacPressure1.CLK = baData1[0]; // bit 0
  517. _bSysCompressedAirPressure.CLK = baData1[2]; // bit 2
  518. _bFlowGaugeSensor.CLK = baData1[4]; // bit 4
  519. _bLeakageSensor.CLK = baData1[5]; // bit 5
  520. this.DoorSwitch = baData1[6] ? LidState.Close : LidState.Open; // bit 6
  521. //bDrivePower = baData1[7]; // bit 7
  522. _bDiffPressureSensorSetting1.CLK = baData1[8]; // bit 8
  523. _bDiffPressureSensorSetting2.CLK = baData1[9]; // bit 9
  524. _bIonizerAlarm.CLK = baData1[10]; // bit 10
  525. _bFFuAlarm.CLK = baData1[11]; // bit 11
  526. _bAreaSensor.CLK = baData1[12]; // bit 12
  527. _bModeSwitch.CLK = baData1[13]; // bit 13
  528. this.CassetteDoor = baData1[15] ? LidState.Close : LidState.Open; // bit 15
  529. if (_bSysVacPressure1.Q)
  530. EV.PostWarningLog(Module.ToString(), "真空报错");
  531. if (_bSysCompressedAirPressure.Q)
  532. EV.PostWarningLog(Module.ToString(), "压缩空气报错");
  533. // DATA2
  534. _signalT.ChangeLightStatus(LightType.RED, baData2[0] ? LightStatus.ON : baData2[5] ? LightStatus.BLINK : LightStatus.OFF);
  535. _signalT.ChangeLightStatus(LightType.GREEN, baData2[1] ? LightStatus.ON : baData2[6] ? LightStatus.BLINK : LightStatus.OFF);
  536. _signalT.ChangeLightStatus(LightType.YELLOW, baData2[2] ? LightStatus.ON : baData2[7] ? LightStatus.BLINK : LightStatus.OFF);
  537. _signalT.ChangeLightStatus(LightType.BLUE, baData2[3] ? LightStatus.ON : baData2[8] ? LightStatus.BLINK : LightStatus.OFF);
  538. _signalT.ChangeLightStatus(LightType.WHITE, baData2[4] ? LightStatus.ON : baData2[9] ? LightStatus.BLINK : LightStatus.OFF);
  539. _signalT.ChangeLightStatus(LightType.BUZZER1, baData2[10] ? LightStatus.ON : LightStatus.OFF);
  540. /* EFEM 程序中目前没有实现
  541. _RobotErr.CLK = baData2[27]; // bit 27
  542. bool bArmNotExtendLLA = baData2[30]; // bit 30
  543. bool bArmNotExtendLLB = baData2[31]; // bit 31
  544. */
  545. } // system event
  546. else
  547. {
  548. _LPMs[eArg.Module - ModuleName.LP1].HandleEvent(eArg);
  549. } // FOUP EVENT
  550. break;
  551. case EfemOperation.GetWaferInfo:
  552. _LPMs[eArg.Module - ModuleName.LP1].HandleEvent(eArg);
  553. break;
  554. default:
  555. break;
  556. }
  557. }
  558. private void MsgOnCommandUpdated(object sender, EventArgs e)
  559. {
  560. EfemActionArgs arg = e as EfemActionArgs;
  561. if (arg == null) throw new ArgumentNullException("Argument is Null");
  562. if (arg.CommandType == EfemOperation.Ready)
  563. {
  564. this.CommunicationConnected = true;
  565. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.CommReady);
  566. return;
  567. }
  568. EfemActionBase action = null;
  569. foreach (var item in _actions)
  570. {
  571. if (item is EfemActionBase a1)
  572. {
  573. if (a1.Type == arg.CommandType && item.Status != ActionStatus.Completed)
  574. {
  575. action = a1;
  576. break;
  577. }
  578. }
  579. }
  580. if (action == null)
  581. {
  582. EV.PostAlarmLog(arg.Module.ToString(), $"NO activated {arg.CommandType} in the queue");
  583. throw new ApplicationException($"NO activated {arg.CommandType} in the queue");
  584. }
  585. // 更新 action 状态
  586. action.Status = arg.Status;
  587. if (arg.Status == ActionStatus.Completed)
  588. {
  589. ModuleName mod = action.Module;
  590. // Map 命令比较特别, module 是LPX但是用robot做mapping
  591. if (mod == ModuleName.EFEM || mod == ModuleName.EfemRobot || ModuleHelper.IsAligner(mod) || arg.CommandType == EfemOperation.Map)
  592. {
  593. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.ActionDone, arg.CommandType);
  594. }
  595. else if (ModuleHelper.IsLoadPort(mod))
  596. {
  597. Singleton<RouteManager>.Instance.EFEM.NotifyLP(mod, LoadportEntity.MSG.ActionDone);
  598. }
  599. _robotMoveAction = string.Format($"System.None");
  600. action.OnPostWork(arg.Data);
  601. }
  602. }
  603. private void MsgOnErrorOccurred(object sender, EventArgs e)
  604. {
  605. if (e is EfemErrorArgs errArg)
  606. {
  607. this.Status = DeviceState.Error;
  608. if (this._actions.Count > 0) this._actions.RemoveLast();
  609. EV.PostAlarmLog(Module.ToString(), $"{errArg.Description}, [{errArg.Message}], [{errArg.Factor}]");
  610. }
  611. }
  612. }
  613. /// <summary>
  614. /// Load port object class
  615. /// </summary>
  616. sealed class Loadport : ILoadport
  617. {
  618. private readonly EfemBase _efem;
  619. //---------------------------------Properties------------------------------------
  620. //
  621. public OnlineFlag OnlineFlag { get; set; }
  622. public ModuleName Module { get; set; }
  623. public DeviceState Status { get; set; }
  624. public WaferSize WaferSize { get; set; }
  625. public WaferStatus[] WaferInfo { get; set; }
  626. public bool HasCassette { get; set; }
  627. public bool Protrusion { get; set; }
  628. public bool IsMapped { get; set; }
  629. // Constructor
  630. //
  631. public Loadport(ModuleName mod, EfemBase efem)
  632. {
  633. Module = mod;
  634. _efem = efem;
  635. }
  636. // Methods
  637. //
  638. public void Home()
  639. {
  640. _efem.AddAction(new HomeAllAction(_efem, Module));
  641. }
  642. public void Map()
  643. {
  644. _efem.AddAction(new MapAction(_efem, Module));
  645. }
  646. public void HandleEvent(EfemEventArgs eArg)
  647. {
  648. switch (eArg.CommandType)
  649. {
  650. case EfemOperation.GetWaferInfo:
  651. string sWaferInfo = eArg.DataList[0];
  652. for (byte index = 0; index < sWaferInfo.Length; index++)
  653. {
  654. WaferStatus st = (WaferStatus)int.Parse(sWaferInfo.Substring(index, 1));
  655. WaferManager.Instance.CreateWafer(this.Module, index, st);
  656. WaferManager.Instance.UpdateWaferSize(this.Module, index, WaferSize);
  657. if (st == WaferStatus.Normal)
  658. {
  659. EV.PostInfoLog(this.Module.ToString(), $"Found Wafer on Slot {index+1} {WaferSize}");
  660. }
  661. }
  662. this.IsMapped = true;
  663. break;
  664. case EfemOperation.SigStatus:
  665. // EVT: SIGSTAT/P2/00000381/00000000;
  666. string sParam = eArg.DataList[0];
  667. ModuleName mod = sParam.ToModule();
  668. if (!ModuleHelper.IsLoadPort(mod))
  669. return;
  670. // DATA1 & DATA2
  671. int nData1 = Convert.ToInt32(eArg.DataList[1], 16);
  672. int nData2 = Convert.ToInt32(eArg.DataList[2], 16);
  673. BitArray baData1 = new BitArray(new int[] { nData1 });
  674. BitArray baData2 = new BitArray(new int[] { nData2 });
  675. // wafer size
  676. this.WaferSize = !baData1[6] ? WaferSize.WS3 :
  677. !baData1[7] ? WaferSize.WS4 :
  678. !baData1[8] ? WaferSize.WS6 : WaferSize.WS0;
  679. // placement & present
  680. bool bPlacement = baData1[0]; // bit 0
  681. bool bPresence = !baData1[1]; // bit 1
  682. bool bArrived = bPlacement && bPresence;
  683. if (HasCassette)
  684. {
  685. if (!bArrived)
  686. {
  687. this.HasCassette = false;
  688. this.IsMapped = false;
  689. EV.PostInfoLog(mod.ToString(), "Cassette 拿走");
  690. WaferManager.Instance.DeleteWafer(this.Module, 0, 25);
  691. }
  692. }
  693. else
  694. {
  695. if (bArrived)
  696. {
  697. this.HasCassette = true;
  698. EV.PostInfoLog(mod.ToString(), $"Cassette {WaferSize} 放好");
  699. }
  700. }
  701. this.Protrusion = !baData1[9];
  702. if (Protrusion)
  703. {
  704. EV.PostWarningLog(Module.ToString(), "发现 wafer 突出");
  705. }
  706. // DATA2, loadport上面的LED 灯, 暂时不需要用到
  707. break;
  708. default:
  709. break;
  710. }
  711. }
  712. public void SetOnline(bool online)
  713. {
  714. OnlineFlag = online ? OnlineFlag.Online : OnlineFlag.Offline;
  715. }
  716. }
  717. sealed class SignalTower
  718. {
  719. // Fields
  720. //
  721. private readonly Dictionary<LightType, LightStatus> _lights = new Dictionary<LightType, LightStatus>(5);
  722. public SignalTower()
  723. {
  724. _lights.Add(LightType.RED, LightStatus.OFF);
  725. _lights.Add(LightType.YELLOW, LightStatus.OFF);
  726. _lights.Add(LightType.BLUE, LightStatus.OFF);
  727. _lights.Add(LightType.GREEN, LightStatus.OFF);
  728. _lights.Add(LightType.WHITE, LightStatus.OFF);
  729. _lights.Add(LightType.BUZZER1, LightStatus.OFF);
  730. DATA.Subscribe($"{ModuleName.EFEM}.SignalTower", () =>
  731. {
  732. return new AITSignalTowerData
  733. {
  734. IsGreenLightOn = _lights[LightType.GREEN] == LightStatus.ON,
  735. IsRedLightOn = _lights[LightType.RED] == LightStatus.ON,
  736. IsYellowLightOn = _lights[LightType.YELLOW] == LightStatus.ON,
  737. IsWhiteLightOn = _lights[LightType.WHITE] == LightStatus.ON,
  738. IsBlueLightOn = _lights[LightType.BLUE] == LightStatus.ON,
  739. IsBuzzerOn = _lights[LightType.BUZZER1] == LightStatus.ON,
  740. };
  741. });
  742. }
  743. // Methods
  744. //
  745. public void ChangeLightStatus(LightType light, LightStatus st)
  746. {
  747. if (!_lights.ContainsKey(light))
  748. throw new ApplicationException($"NO {light} configured");
  749. _lights[light] = st;
  750. }
  751. }
  752. }