EfemEntity.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Device.Unit;
  5. using Aitex.Core.RT.Fsm;
  6. using Aitex.Core.RT.OperationCenter;
  7. using Aitex.Core.RT.SCCore;
  8. using Aitex.Core.Util;
  9. using Aitex.Sorter.Common;
  10. using athosRT.Devices;
  11. using athosRT.Devices.EFEM;
  12. using athosRT.Devices.EFEM.Task;
  13. using athosRT.tool;
  14. using MECF.Framework.Common.Device.Bases;
  15. using MECF.Framework.Common.Equipment;
  16. using MECF.Framework.Common.SubstrateTrackings;
  17. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase;
  18. using System;
  19. using System.Collections.Generic;
  20. using System.Diagnostics;
  21. using System.Linq;
  22. using System.Text;
  23. using DATA = Common.DataCenter.DATA;
  24. using IoSignalTower = athosRT.Devices.IoSignalTower;
  25. using OP = Common.OP.OP;
  26. namespace athosRT.Modules.EFEMs
  27. {
  28. public class EfemEntity : Entity, IEntity, IServerCallback
  29. {
  30. private SocketServer _socket = (SocketServer)null;
  31. private string _sessionId;
  32. private List<ITaskT> _activeTaskList = new List<ITaskT>();
  33. private TaskFactory _factory = new TaskFactory();
  34. private DeviceTimer _sendReadyTimer = new DeviceTimer();
  35. private List<ModuleName> LPs;
  36. private List<string> LLs;
  37. private Dictionary<ModuleName, RD_TRIG> _trigLpPresent = new Dictionary<ModuleName, RD_TRIG>();
  38. private Dictionary<string, Tuple<uint, uint>> _sigData = new Dictionary<string, Tuple<uint, uint>>();
  39. private Dictionary<ModuleName, EfemModuleStatus> _efemModuleStatus = new Dictionary<ModuleName, EfemModuleStatus>();
  40. public string Name { get; set; }
  41. public string GetFsmState => fsm.State.ToString();
  42. public bool IsCommunicationOk { get; set; }
  43. public bool IsOnlineMode { get; private set; }
  44. private bool IsSystemHold { get; set; }
  45. public EfemEntity()
  46. {
  47. Name = "Efem";
  48. IsOnlineMode = false;
  49. LPs = new List<ModuleName>(Singleton<DeviceManager>.Instance.LpNames);
  50. foreach (ModuleName lp in LPs)
  51. _trigLpPresent[lp] = new RD_TRIG();
  52. LLs = new List<string>((IEnumerable<string>)Singleton<DeviceManager>.Instance.LLNames);
  53. int port = 13000;
  54. if (!SC.ContainsItem("System.EfemPortNumber"))
  55. LogObject.Error("EFEM", "Not define System.EfemPortNumber");
  56. else
  57. port = SC.GetValue<int>("System.EfemPortNumber");
  58. //获取端口 用于服务的发布
  59. _socket = new SocketServer((IServerCallback)this, port);
  60. fsm = (IStateMachine)new StateMachine<EfemEntity>(Name, 0, 50);
  61. BuildTransitionTable();
  62. Subscribe();
  63. }
  64. public void SetEfemData()
  65. {
  66. foreach (ModuleName installModule in GetInstallModules())
  67. _efemModuleStatus[installModule] = new EfemModuleStatus(installModule);
  68. }
  69. public IEnumerable<ModuleName> GetInstallModules() => (IEnumerable<ModuleName>)new List<ModuleName>()
  70. {
  71. ModuleName.System,
  72. ModuleName.Robot,
  73. ModuleName.Buffer1,
  74. ModuleName.LP1,
  75. ModuleName.LP2,
  76. ModuleName.LP3,
  77. ModuleName.LP4,
  78. ModuleName.LL1,
  79. ModuleName.LL2
  80. };
  81. public void SetInitialize(ModuleName module, bool initialized)
  82. {
  83. if (!_efemModuleStatus.ContainsKey(module))
  84. return;
  85. _efemModuleStatus[module].IsInitialized = initialized;
  86. }
  87. private void Subscribe()
  88. {
  89. DATA.Subscribe("Efem.IsCommunicationReady", (Func<object>)(() => (object)(fsm.State == 2)), SubscriptionAttribute.FLAG.SaveDB);
  90. DATA.Subscribe("System.IsHold", (Func<object>)(() => (object)IsSystemHold), SubscriptionAttribute.FLAG.SaveDB);
  91. DATA.Subscribe("System.IsOnlineMode", (Func<object>)(() => (object)IsOnlineMode), SubscriptionAttribute.FLAG.SaveDB);
  92. DATA.Subscribe("System.ServerStatus", (Func<object>)(() => (object)((EfemEntity.ServerState)fsm.State).ToString()), SubscriptionAttribute.FLAG.SaveDB);
  93. DATA.Subscribe($"Server.Status", () => ((ServerState)fsm.State).ToString());
  94. OP.Subscribe("Online", (Func<string, object[], bool>)((cmd, param) =>
  95. {
  96. Trace.WriteLine("执行Online");
  97. if (IsOnlineMode)
  98. return true;
  99. if (!Singleton<RouteManager1>.Instance.IsRunning)
  100. {
  101. if (CheckToPostMsg(EfemEntity.MSG.Online))
  102. {
  103. LogObject.Info("EFEM", $"Switch to Online Mode.The Address is {SC.GetStringValue("System.EfemServerLocalIp")}:{SC.GetValue<int>("System.EfemPortNumber")}.");
  104. return true;
  105. }
  106. else
  107. {
  108. LogObject.Warning("EFEM", "Cannot Switch to Online Mode.");
  109. return false;
  110. }
  111. }
  112. EV.PostWarningLog("EFEM", "Server", "System is busy, can not switch to online.");
  113. return true;
  114. }));
  115. OP.Subscribe("Offline", (Func<string, object[], bool>)((cmd, param) => {
  116. if (!IsOnlineMode)
  117. return true;
  118. if (CheckToPostMsg(EfemEntity.MSG.Offline))
  119. {
  120. LogObject.Info("EFEM", "Switch to Offline Mode.");
  121. return true;
  122. }
  123. else
  124. {
  125. LogObject.Warning("EFEM", "Cannot Switch to Offline Mode.");
  126. return true;
  127. }
  128. }));
  129. }
  130. private void BuildTransitionTable()
  131. {
  132. AnyStateTransition(MSG.Offline, FsmSetOffline, FSM_STATE.SAME);
  133. AnyStateTransition(MSG.Online, FsmSetOnline, FSM_STATE.SAME);
  134. EnterExitTransition(ServerState.Init, FsmEnterInit, new FSM_MSG?(FSM_MSG.NONE), null);
  135. Transition(ServerState.Init, MSG.Listening, null, EfemEntity.ServerState.Listening);
  136. Transition(ServerState.Init, MSG.Reset, FsmEnterInit, EfemEntity.ServerState.Init);
  137. Transition(ServerState.Listening, MSG.Error, null, EfemEntity.ServerState.Init);
  138. Transition(ServerState.Listening, MSG.NewSessionConnected, FsmNewSessionConnected, EfemEntity.ServerState.Connected);
  139. Transition(ServerState.Connected, MSG.Disconnect, FsmDisconnect, EfemEntity.ServerState.Listening);
  140. Transition(ServerState.Connected, MSG.Error, null, EfemEntity.ServerState.Init);
  141. Transition(ServerState.Connected, MSG.NewSessionConnected, FsmNewSessionConnected, EfemEntity.ServerState.Connected);
  142. Transition(ServerState.Connected, MSG.ReceiveData, FsmReceiveData, EfemEntity.ServerState.Connected);
  143. Transition(ServerState.Connected, MSG.SendData, FsmSendData, EfemEntity.ServerState.Connected);
  144. Transition(ServerState.Connected, FSM_MSG.TIMER, FsmMonitor, EfemEntity.ServerState.Connected);
  145. }
  146. ~EfemEntity() => _socket?.Stop();
  147. public bool SetSystemHold()
  148. {
  149. if (IsSystemHold)
  150. return false;
  151. IsSystemHold = true;
  152. return true;
  153. }
  154. public bool SetSystemUnHold()
  155. {
  156. if (!IsSystemHold)
  157. return true;
  158. IsSystemHold = false;
  159. return true;
  160. }
  161. public bool CheckToPostMsg(EfemEntity.MSG msg)
  162. {
  163. if (!fsm.FindTransition(fsm.State, (int)msg))
  164. {
  165. EV.PostWarningLog("EFEM", "System", string.Format("{0} is in {1} state,can not do {2}", (object)Name, (object)(EfemEntity.ServerState)fsm.State, (object)msg));
  166. return false;
  167. }
  168. PostMsg<EfemEntity.MSG>(msg);
  169. return true;
  170. }
  171. public bool CheckToPostMsg(EfemEntity.MSG msg, object param1)
  172. {
  173. if (!fsm.FindTransition(fsm.State, (int)msg))
  174. {
  175. EV.PostWarningLog("EFEM", "System", string.Format("{0} is in {1} state,can not do {2}", (object)Name, (object)(EfemEntity.ServerState)fsm.State, (object)msg));
  176. return false;
  177. }
  178. PostMsg<EfemEntity.MSG>(msg, param1);
  179. return true;
  180. }
  181. private bool FsmNewSessionConnected(object[] param)
  182. {
  183. _sessionId = (string)param[0];
  184. _activeTaskList.Clear();
  185. IsCommunicationOk = false;
  186. if (IsOnlineMode)
  187. DEVICE.GetDevice<Devices.IoSignalTower>("SignalTower").HostControl = true;
  188. return true;
  189. }
  190. private bool FsmDisconnect(object[] param) => !((string)param[0] != _sessionId);
  191. private bool FsmEnterInit(object[] param)
  192. {
  193. string server = SC.GetStringValue("System.EfemServerLocalIp");
  194. int port = SC.GetValue<int>("System.EfemPortNumber");
  195. _sendReadyTimer.Start(0.0);
  196. if (string.IsNullOrEmpty(server))
  197. server = "127.0.0.1";
  198. if (!_socket.Start(server, port))
  199. return false;
  200. PostMsg<EfemEntity.MSG>(EfemEntity.MSG.Listening);
  201. return true;
  202. }
  203. private bool FsmSendData(object[] param)
  204. {
  205. _socket.Send((string)param[0]);
  206. return true;
  207. }
  208. private bool FsmReceiveData(object[] param)
  209. {
  210. try
  211. {
  212. string cmd = (string)param[0];
  213. string[] source = cmd.Split(new char[5]
  214. {
  215. ':',
  216. '/',
  217. '>',
  218. '|',
  219. ';'
  220. }, StringSplitOptions.RemoveEmptyEntries);
  221. if (cmd.Contains("SET:CSTID"))
  222. source = new string[4]
  223. {
  224. source[0],
  225. source[1],
  226. source[2],
  227. cmd.Remove(0, 13)
  228. };
  229. EfemCommandType result1;
  230. //验证是否是EFEM协议的命令类型 SET MOV GET ACK
  231. if (!Enum.TryParse<EfemCommandType>(source[0], out result1))
  232. {
  233. LogObject.Error("EFEM", cmd + " is not a valid EFEM message format");
  234. //LOG.Write(cmd + " is not a valid EFEM message format", file: "D:\\sorter\\trunk\\Efem\\Jet\\Jet_001_2P_Jet\\EfemRT\\Servers\\EfemEntity.cs", member: nameof(FsmReceiveData), line: 398);
  235. SendMessage("NAK:" + cmd.Split(':')[1]);
  236. return true;
  237. }
  238. EfemCommand result2;
  239. //验证
  240. if (!Enum.TryParse<EfemCommand>(source[1], out result2))
  241. {
  242. LogObject.Error("EFEM", cmd + " is not a valid EFEM message format");
  243. //LOG.Write(cmd + " is not a valid EFEM message format", file: "D:\\sorter\\trunk\\Efem\\Jet\\Jet_001_2P_Jet\\EfemRT\\Servers\\EfemEntity.cs", member: nameof(FsmReceiveData), line: 405);
  244. SendMessage("NAK:" + cmd.Split(':')[1]);
  245. return true;
  246. }
  247. string str = cmd.Substring(cmd.IndexOf(':'));
  248. if (result1 == EfemCommandType.ACK)
  249. {
  250. if (!IsCommunicationOk && cmd == "ACK:READY/COMM")
  251. {
  252. IsCommunicationOk = true;
  253. return true;
  254. }
  255. foreach (ITaskT activeTask in _activeTaskList)
  256. {
  257. if (activeTask.CommandData == str && activeTask.CommandType == result1 && activeTask.CommandName == result2)
  258. activeTask.Ack(result1, result2, ((IEnumerable<string>)source).Skip<string>(2).Take<string>(source.Length).ToArray<string>());
  259. }
  260. return true;
  261. }
  262. if (_factory.UnSupport(result1, result2))
  263. {
  264. LogObject.Error("EFEM", cmd + " is not a valid EFEM message format");
  265. //LOG.Write(cmd + " is not a valid EFEM message format", file: "D:\\sorter\\trunk\\Efem\\Jet\\Jet_001_2P_Jet\\EfemRT\\Servers\\EfemEntity.cs", member: nameof(FsmReceiveData), line: 433);
  266. SendMessage("NAK:" + cmd.Split(':')[1]);
  267. return true;
  268. }
  269. ITaskT taskT = _factory.Create(result1, result2);
  270. taskT.CommandData = str;
  271. foreach (ITaskT activeTask in _activeTaskList)
  272. {
  273. if (activeTask.CommandData == str && activeTask.CommandType == result1 && activeTask.CommandName == result2)
  274. {
  275. EV.PostWarningLog("EFEM", "EFEM", "ignored " + cmd + ", already active");
  276. return true;
  277. }
  278. }
  279. string result3;
  280. string[] arr = ((IEnumerable<string>)source).Skip<string>(2).Take<string>(source.Length).ToArray<string>();
  281. if (taskT.Execute(out result3, cmd, arr))
  282. _activeTaskList.Add(taskT);
  283. SendMessage(result3);
  284. }
  285. catch (Exception ex)
  286. {
  287. LogObject.Error("EFEM", ex);
  288. //LOG.Write(ex, 2, "D:\\sorter\\trunk\\Efem\\Jet\\Jet_001_2P_Jet\\EfemRT\\Servers\\EfemEntity.cs", nameof(FsmReceiveData), 459);
  289. }
  290. return true;
  291. }
  292. private bool FsmSetOnline(object[] param)
  293. {
  294. IsOnlineMode = true;
  295. IoSignalTower device = DEVICE.GetDevice<IoSignalTower>("SignalTower");
  296. device.HostControl = true;
  297. device.Reset();
  298. return true;
  299. }
  300. private bool FsmSetOffline(object[] param)
  301. {
  302. IsOnlineMode = false;
  303. IoSignalTower device = DEVICE.GetDevice<IoSignalTower>("SignalTower");
  304. device.HostControl = false;
  305. device.Reset();
  306. return true;
  307. }
  308. public void OnConnected(string sessionId) => CheckToPostMsg(EfemEntity.MSG.NewSessionConnected, (object)sessionId);
  309. public void OnDisconnected(string sessionId) => CheckToPostMsg(EfemEntity.MSG.Disconnect, (object)sessionId);
  310. public void OnReceived(string msg) => CheckToPostMsg(EfemEntity.MSG.ReceiveData, (object)msg);
  311. public void SendMessage(string msg)
  312. {
  313. if (!IsCommunicationOk && !(msg == "INF:READY/COMM"))
  314. return;
  315. CheckToPostMsg(EfemEntity.MSG.SendData, (object)msg);
  316. }
  317. private bool FsmMonitor(object[] objs)
  318. {
  319. if (!IsCommunicationOk)
  320. {
  321. if (_sendReadyTimer.GetElapseTime() > (double)SC.GetValue<int>("Server.SendReadyInterval"))
  322. {
  323. _sendReadyTimer.Start(0.0);
  324. SendMessage("INF:READY/COMM");
  325. }
  326. return true;
  327. }
  328. MonitorRunningTask();
  329. MonitorEvent();
  330. return true;
  331. }
  332. private void MonitorRunningTask()
  333. {
  334. List<ITaskT> source = new List<ITaskT>();
  335. foreach (ITaskT activeTask in _activeTaskList)
  336. {
  337. if (!activeTask.HasInfoMessage)
  338. {
  339. source.Add(activeTask);
  340. }
  341. else
  342. {
  343. string result = string.Empty;
  344. if (activeTask.Monitor(out result).HasValue)
  345. {
  346. SendMessage(result);
  347. source.Add(activeTask);
  348. break;
  349. }
  350. }
  351. }
  352. if (!source.Any<ITaskT>())
  353. return;
  354. foreach (ITaskT taskT in source)
  355. _activeTaskList.Remove(taskT);
  356. }
  357. private void MonitorEvent() => MonitorSigStatEvent();
  358. private void MonitorSigStatEvent()
  359. {
  360. if (!((SystemServerModule)Singleton<EntityFactory>.Instance.GetEntity("System")).IsEventEnabled(EfemEventType.ALL))
  361. return;
  362. bool flag1 = ((SystemServerModule)Singleton<EntityFactory>.Instance.GetEntity("System")).IsEventEnabled(EfemEventType.PORT);
  363. bool flag2 = ((SystemServerModule)Singleton<EntityFactory>.Instance.GetEntity("System")).IsEventEnabled(EfemEventType.SYSTEM);
  364. Dictionary<string, Tuple<uint, uint>> sigStatData = GetSigStatData();
  365. if (sigStatData == null)
  366. return;
  367. foreach (KeyValuePair<string, Tuple<uint, uint>> keyValuePair in sigStatData)
  368. {
  369. if ((!keyValuePair.Key.StartsWith("P") || flag1) && (!keyValuePair.Key.StartsWith("SYS") || flag2))
  370. {
  371. ModuleName key = ProtocolName2ModuleName(keyValuePair.Key);
  372. if (_efemModuleStatus[key].IsInitialized)
  373. {
  374. if (_efemModuleStatus[key].TrigInitialized.Q)
  375. {
  376. _efemModuleStatus[key].TrigInitialized.CLK = true;
  377. _sigData.Remove(keyValuePair.Key);
  378. }
  379. else if (!_sigData.ContainsKey(keyValuePair.Key) || (int)_sigData[keyValuePair.Key].Item1 != (int)keyValuePair.Value.Item1 || (int)_sigData[keyValuePair.Key].Item2 != (int)keyValuePair.Value.Item2)
  380. {
  381. _sigData[keyValuePair.Key] = keyValuePair.Value;
  382. SendMessage(string.Format("EVT:SIGSTAT/{0}/{1:X8}/{2:X8}", (object)keyValuePair.Key, (object)_sigData[keyValuePair.Key].Item1, (object)_sigData[keyValuePair.Key].Item2));
  383. }
  384. }
  385. }
  386. }
  387. }
  388. public Dictionary<string, Tuple<uint, uint>> GetSigStatData()
  389. {
  390. Dictionary<string, Tuple<uint, uint>> sigStatData = new Dictionary<string, Tuple<uint, uint>>();
  391. ModuleName[] moduleNameArray = new ModuleName[3]
  392. {
  393. ModuleName.System,
  394. ModuleName.LP1,
  395. ModuleName.LP2
  396. };
  397. foreach (ModuleName module in moduleNameArray)
  398. sigStatData[ModuleName2ProtocolName(module)] = Tuple.Create<uint, uint>(GetSigStatData1(module), GetSigStatData2(module));
  399. return sigStatData;
  400. }
  401. private ModuleName ProtocolName2ModuleName(string protocol)
  402. {
  403. ModuleName moduleName = ModuleName.System;
  404. Dictionary<string, ModuleName> dictionary = new Dictionary<string, ModuleName>()
  405. {
  406. {
  407. "P1",
  408. ModuleName.LP1
  409. },
  410. {
  411. "P2",
  412. ModuleName.LP2
  413. },
  414. {
  415. "SYS",
  416. ModuleName.System
  417. }
  418. };
  419. if (dictionary.ContainsKey(protocol))
  420. moduleName = dictionary[protocol];
  421. return moduleName;
  422. }
  423. protected override bool Init() => true;
  424. protected override void Term()
  425. {
  426. if (_socket == null)
  427. return;
  428. _socket.Stop();
  429. }
  430. public bool Check(int msg, out string reason, params object[] args)
  431. {
  432. if (!fsm.FindTransition(fsm.State, msg))
  433. {
  434. reason = string.Format("{0} is in {1} state,can not do {2}", (object)Name, (object)(EfemEntity.ServerState)fsm.State, (object)(EfemEntity.MSG)msg);
  435. return false;
  436. }
  437. reason = "";
  438. return true;
  439. }
  440. public void Reset()
  441. {
  442. if (fsm.State != 0)
  443. return;
  444. string stringValue = SC.GetStringValue("System.EfemServerLocalIp");
  445. int port = SC.GetValue<int>("System.EfemPortNumber");
  446. _sendReadyTimer.Start(0.0);
  447. if (_socket.Start(stringValue, port))
  448. PostMsg<EfemEntity.MSG>(EfemEntity.MSG.Listening);
  449. }
  450. /// <summary>
  451. /// 此处将wafermanager中对应lp数据进行发送
  452. /// </summary>
  453. /// <param name="lp"></param>
  454. public void SendMapEvent(LoadPortBaseDevice lp)
  455. {
  456. WaferInfo[] wafers = Singleton<WaferManager>.Instance.GetWafers(ModuleHelper.Converter(lp.Name));
  457. string str1 = "";
  458. for (int index = 0; index < 25; ++index)
  459. {
  460. switch (wafers[index].Status)
  461. {
  462. case WaferStatus.Empty:
  463. str1 += "0";
  464. break;
  465. case WaferStatus.Normal:
  466. str1 += "1";
  467. break;
  468. case WaferStatus.Crossed:
  469. str1 += "3";
  470. break;
  471. case WaferStatus.Double:
  472. str1 += "7";
  473. break;
  474. case WaferStatus.Unknown:
  475. str1 += "8";
  476. break;
  477. case WaferStatus.Dummy:
  478. str1 += "4";
  479. break;
  480. }
  481. }
  482. string str2 = str1;
  483. if (lp.IsError)
  484. str2 = string.Empty;
  485. SendMessage(string.Format("EVT:MAPDT/{0}/{1}", (object)ModuleName2ProtocolName(ModuleHelper.Converter(lp.Name)), (object)str2));
  486. }
  487. public void SendSigStatEvent(ModuleName module)
  488. {
  489. uint sigStatData1 = GetSigStatData1(module);
  490. uint sigStatData2 = GetSigStatData2(module);
  491. SendMessage(string.Format("EVT:SIGSTAT/{0}/{1:X8}/{2:X8}", (object)ModuleName2ProtocolName(module), (object)sigStatData1, (object)sigStatData2));
  492. }
  493. public uint GetSigStatData1(string device)
  494. {
  495. uint sigStatData1 = 0;
  496. if (IsLoadPort(device))
  497. {
  498. LoadPortBaseDevice device1 = DEVICE.GetDevice<LoadPortBaseDevice>("L" + device);
  499. if (device1 != null)
  500. sigStatData1 |= GetLpData1(device1);
  501. E84Passiver device2 = DEVICE.GetDevice<E84Passiver>(GetE84LpName(device));
  502. if (device2 != null)
  503. sigStatData1 |= GetE84Data1(device2);
  504. }
  505. else
  506. sigStatData1 = !ModuleHelper.IsLoadLock(ModuleHelper.Converter(device)) ? GetSystemData1() : GetLlData1();
  507. return sigStatData1;
  508. }
  509. public uint GetSigStatData1(ModuleName module)
  510. {
  511. uint sigStatData1 = 0;
  512. if (ModuleHelper.IsLoadPort(module))
  513. {
  514. LoadPortBaseDevice device1 = DEVICE.GetDevice<LoadPortBaseDevice>(module.ToString());
  515. if (device1 != null)
  516. sigStatData1 |= GetLpData1(device1);
  517. E84Passiver device2 = DEVICE.GetDevice<E84Passiver>(GetE84LpName(module.ToString()));
  518. if (device2 != null)
  519. sigStatData1 |= GetE84Data1(device2);
  520. }
  521. else
  522. sigStatData1 = !ModuleHelper.IsLoadLock(module) ? GetSystemData1() : GetLlData1();
  523. return sigStatData1;
  524. }
  525. public uint GetSigStatData2(string device)
  526. {
  527. uint sigStatData2 = 0;
  528. if (IsLoadPort(device))
  529. {
  530. LoadPortBaseDevice device1 = DEVICE.GetDevice<LoadPortBaseDevice>("L" + device);
  531. if (device1 != null)
  532. sigStatData2 |= GetLpData2(device1);
  533. E84Passiver device2 = DEVICE.GetDevice<E84Passiver>(GetE84LpName(device));
  534. if (device2 != null)
  535. sigStatData2 |= GetE84Data2(device2);
  536. }
  537. else
  538. sigStatData2 = !ModuleHelper.IsLoadLock(ModuleHelper.Converter(device)) ? GetSystemData2() : GetLlData2();
  539. return sigStatData2;
  540. }
  541. public uint GetSigStatData2(ModuleName module)
  542. {
  543. uint sigStatData2 = 0;
  544. if (ModuleHelper.IsLoadPort(module))
  545. {
  546. LoadPortBaseDevice device1 = DEVICE.GetDevice<LoadPortBaseDevice>(module.ToString());
  547. if (device1 != null)
  548. sigStatData2 |= GetLpData2(device1);
  549. E84Passiver device2 = DEVICE.GetDevice<E84Passiver>(GetE84LpName(module.ToString()));
  550. if (device2 != null)
  551. sigStatData2 |= GetE84Data2(device2);
  552. }
  553. else
  554. sigStatData2 = !ModuleHelper.IsLoadLock(module) ? GetSystemData2() : GetLlData2();
  555. return sigStatData2;
  556. }
  557. private uint GetLpData1(LoadPortBaseDevice lp)
  558. {
  559. uint lpData1 = 0;
  560. if (lp != null)
  561. lpData1 = (uint)((int)lpData1 | (lp.IsPlacement ? 1 : 0) | (!lp.IsPresent ? 2 : 0)) | 64U | 128U | (!lp.IsWaferProtrude ? 512U : 0U);
  562. return lpData1;
  563. }
  564. private uint GetLpData2(LoadPortBaseDevice lp)
  565. {
  566. uint lpData2 = 0;
  567. if (lp != null)
  568. lpData2 = (uint)((int)lpData2 | (lp.IndicatiorPresence == IndicatorState.ON ? 1 : 0) | (lp.IndicatiorPlacement == IndicatorState.ON ? 2 : 0) | (lp.IndicatiorLoad == IndicatorState.ON ? 4 : 0) | (lp.IndicatiorUnload == IndicatorState.ON ? 8 : 0) | (lp.IndicatiorManualMode == IndicatorState.ON ? 16 : 0) | (lp.IndicatorAlarm == IndicatorState.ON ? 32 : 0) | (lp.IndicatiorClampUnclamp == IndicatorState.ON ? 64 : 0) | (lp.IndicatiorDockUndock == IndicatorState.ON ? 128 : 0) | (lp.IndicatiorOpAccess == IndicatorState.ON ? 256 : 0));
  569. return lpData2;
  570. }
  571. private uint GetE84Data1(E84Passiver e84Lp)
  572. {
  573. uint e84Data1 = 0;
  574. if (e84Lp != null)
  575. e84Data1 = (uint)((int)e84Data1 | (e84Lp.DiValid ? 16777216 : 0) | (e84Lp.DiCS0 ? 33554432 : 0) | (e84Lp.DiCS1 ? 67108864 : 0) | (e84Lp.DiTrReq ? 268435456 : 0) | (e84Lp.DiBusy ? 536870912 : 0) | (e84Lp.DiCompt ? 1073741824 : 0) | (e84Lp.DiCont ? int.MinValue : 0));
  576. return e84Data1;
  577. }
  578. private uint GetE84Data2(E84Passiver e84Lp)
  579. {
  580. uint e84Data2 = 0;
  581. if (e84Lp != null)
  582. e84Data2 = (uint)((int)e84Data2 | (e84Lp.DoLoadReq ? 16777216 : 0) | (e84Lp.DoUnloadReq ? 33554432 : 0) | (e84Lp.DoReady ? 134217728 : 0) | (e84Lp.DoHOAvbl ? 1073741824 : 0) | (e84Lp.DoES ? int.MinValue : 0));
  583. return e84Data2;
  584. }
  585. //private uint GetSystemData1() => (uint)(0 |
  586. // (DeviceModel.SensorVACPressureSW.Value ? 1 : 0)|
  587. // (DeviceModel.SensorIONCDAPressureSW.Value ? 2 : 0) |
  588. // (DeviceModel.SensorCDAPressureSW.Value ? 4 : 0) |
  589. // (DeviceModel.SensorWaterFlowSW.Value ? 16 : 0) |
  590. // (DeviceModel.SensorWaterLeakSW.Value ? 32 : 0) |
  591. // (DeviceModel.SensorEFEMSideDoorClosed.Value ? 64 : 0) |
  592. // (DeviceModel.SensorFFUalarm.Value ? 128 : 0) |
  593. // (DeviceModel.SensorIONAlarmSIGNAL.Value ? 1024 : 0) |
  594. // (DeviceModel.SensorFFUalarm.Value ? 2048 : 0)) | 4096U |
  595. // (!DeviceModel.SensorMaintenanceMode.Value && IsOnlineMode ? 8192U : 0U) |
  596. // 16384U | (DeviceModel.SensorGratingSensorIN1.Value ? 32768U : 0U);
  597. private uint GetSystemData1() => (uint)(0 |
  598. (DeviceModel.SensorVACPressureSW.Value ? 1 : 0) |
  599. (DeviceModel.SensorIONCDAPressureSW.Value ? 2 : 0) |
  600. (DeviceModel.SensorCDAPressureSW.Value ? 4 : 0) |
  601. 16 |
  602. 32|
  603. (!DeviceModel.SensorEFEMSideDoorClosed.Value ? 64 : 0)
  604. |128|256|512|1024 |
  605. 2048 | 4096U |
  606. (IsOnlineMode ? 8192U : 0U) |
  607. 16384U | (DeviceModel.SensorGratingSensorIN1.Value ? 32768U : 0U));
  608. private uint GetSystemData2()
  609. {
  610. uint systemData2 = 0;
  611. if (DeviceModel.SignalTower != null)
  612. {
  613. if (DeviceModel.SignalTower.Red != null)
  614. systemData2 |= DeviceModel.SignalTower.Red.StateSetPoint == TowerLightStatus.On ? 1U : 0U;
  615. if (DeviceModel.SignalTower.Green != null)
  616. systemData2 |= DeviceModel.SignalTower.Green.StateSetPoint == TowerLightStatus.On ? 2U : 0U;
  617. if (DeviceModel.SignalTower.Yellow != null)
  618. systemData2 |= DeviceModel.SignalTower.Yellow.StateSetPoint == TowerLightStatus.On ? 4U : 0U;
  619. if (DeviceModel.SignalTower.Blue != null)
  620. systemData2 |= DeviceModel.SignalTower.Blue.StateSetPoint == TowerLightStatus.On ? 8U : 0U;
  621. if (DeviceModel.SignalTower.White != null)
  622. systemData2 |= DeviceModel.SignalTower.White.StateSetPoint == TowerLightStatus.On ? 16U : 0U;
  623. if (DeviceModel.SignalTower.Red != null)
  624. systemData2 |= DeviceModel.SignalTower.Red.StateSetPoint == TowerLightStatus.Blinking ? 32U : 0U;
  625. if (DeviceModel.SignalTower.Green != null)
  626. systemData2 |= DeviceModel.SignalTower.Green.StateSetPoint == TowerLightStatus.Blinking ? 64U : 0U;
  627. if (DeviceModel.SignalTower.Yellow != null)
  628. systemData2 |= DeviceModel.SignalTower.Yellow.StateSetPoint == TowerLightStatus.Blinking ? 128U : 0U;
  629. if (DeviceModel.SignalTower.Blue != null)
  630. systemData2 |= DeviceModel.SignalTower.Blue.StateSetPoint == TowerLightStatus.Blinking ? 256U : 0U;
  631. if (DeviceModel.SignalTower.White != null)
  632. systemData2 |= DeviceModel.SignalTower.White.StateSetPoint == TowerLightStatus.Blinking ? 512U : 0U;
  633. if (DeviceModel.SignalTower.Buzzer1 != null)
  634. systemData2 |= DeviceModel.SignalTower.Buzzer1.StateSetPoint == TowerLightStatus.On ? 1024U : 0U;
  635. if (DeviceModel.SignalTower.Buzzer2 != null)
  636. systemData2 |= DeviceModel.SignalTower.Buzzer2.StateSetPoint == TowerLightStatus.On ? 2048U : 0U;
  637. }
  638. return systemData2;
  639. }
  640. private uint GetLlData1() => (uint)(0 | (LoadLockDevice.LoadLockAtmDoorState == LoadLockDoorState.Opened ? 16 : 0) | (LoadLockDevice.LoadLockVtmDoorState == LoadLockDoorState.Opened ? 32 : 0));
  641. private uint GetLlData2() => 0;
  642. private bool IsLoadPort(string device) => device == "P1" || device == "P2" || device == "P3" || device == "P4";
  643. public string GetE84LpName(string device)
  644. {
  645. string e84LpName = string.Empty;
  646. switch (device)
  647. {
  648. case "LP1":
  649. case "P1":
  650. e84LpName = "Loadport1E84";
  651. break;
  652. case "LP10":
  653. case "P10":
  654. e84LpName = "Loadport10E84";
  655. break;
  656. case "LP2":
  657. case "P2":
  658. e84LpName = "Loadport2E84";
  659. break;
  660. case "LP3":
  661. case "P3":
  662. e84LpName = "Loadport3E84";
  663. break;
  664. case "LP4":
  665. case "P4":
  666. e84LpName = "Loadport4E84";
  667. break;
  668. case "LP5":
  669. case "P5":
  670. e84LpName = "Loadport5E84";
  671. break;
  672. case "LP6":
  673. case "P6":
  674. e84LpName = "Loadport6E84";
  675. break;
  676. case "LP7":
  677. case "P7":
  678. e84LpName = "Loadport7E84";
  679. break;
  680. case "LP8":
  681. case "P8":
  682. e84LpName = "Loadport8E84";
  683. break;
  684. case "LP9":
  685. case "P9":
  686. e84LpName = "Loadport9E84";
  687. break;
  688. }
  689. return e84LpName;
  690. }
  691. private string ModuleName2ProtocolName(ModuleName module)
  692. {
  693. string str = "System";
  694. switch (module)
  695. {
  696. case ModuleName.LP1:
  697. str = "P1";
  698. break;
  699. case ModuleName.LP2:
  700. str = "P2";
  701. break;
  702. case ModuleName.LP3:
  703. str = "P3";
  704. break;
  705. case ModuleName.LP4:
  706. str = "P4";
  707. break;
  708. case ModuleName.LP5:
  709. str = "P5";
  710. break;
  711. case ModuleName.LP6:
  712. str = "P6";
  713. break;
  714. case ModuleName.LP7:
  715. str = "P7";
  716. break;
  717. case ModuleName.LP8:
  718. str = "P8";
  719. break;
  720. case ModuleName.LP9:
  721. str = "P9";
  722. break;
  723. case ModuleName.LP10:
  724. str = "P10";
  725. break;
  726. case ModuleName.LL1:
  727. str = "LLA";
  728. break;
  729. case ModuleName.LL2:
  730. str = "LLB";
  731. break;
  732. case ModuleName.LL3:
  733. str = "LLC";
  734. break;
  735. case ModuleName.LL4:
  736. str = "LLD";
  737. break;
  738. case ModuleName.LL5:
  739. str = "LLE";
  740. break;
  741. case ModuleName.LL6:
  742. str = "LLF";
  743. break;
  744. case ModuleName.LL7:
  745. str = "LLG";
  746. break;
  747. case ModuleName.LL8:
  748. str = "LLH";
  749. break;
  750. }
  751. return str;
  752. }
  753. public enum ServerState
  754. {
  755. Init,
  756. Listening,
  757. Connected,
  758. }
  759. public enum MSG
  760. {
  761. Online,
  762. Offline,
  763. NewSessionConnected,
  764. Listening,
  765. Reset,
  766. Error,
  767. Disconnect,
  768. ReceiveData,
  769. SendData,
  770. }
  771. }
  772. }