EfemView.xaml.cs 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Input;
  10. using Aitex.Core.RT.Log;
  11. using Aitex.Core.UI.MVVM;
  12. using Aitex.Core.Util;
  13. using Aitex.Core.Utilities;
  14. using MECF.Framework.Common.Communications.Tcp.Socket.Server.APM.EventArgs;
  15. using MECF.Framework.Simulator.Core.Commons;
  16. using MECF.Framework.Simulator.Core.Driver;
  17. using MECF.Framework.Simulator.Core.LoadPorts;
  18. namespace EfemDualSimulator.Views
  19. {
  20. public partial class EfemView : UserControl
  21. {
  22. public EfemView()
  23. {
  24. InitializeComponent();
  25. this.Loaded += OnViewLoaded;
  26. }
  27. private void OnViewLoaded(object sender, RoutedEventArgs e)
  28. {
  29. if (DataContext == null)
  30. {
  31. DataContext = new EfemViewModel(13000, 0);
  32. (DataContext as TimerViewModelBase).Start();
  33. }
  34. }
  35. }
  36. class EfemViewModel : SocketDeviceViewModel
  37. {
  38. public string Title
  39. {
  40. get { return "Efem Simulator"; }
  41. }
  42. public string LP1WaferMap
  43. {
  44. get { return _sim.LP1SlotMap; }
  45. }
  46. public string LP2WaferMap
  47. {
  48. get { return _sim.LP2SlotMap; }
  49. }
  50. public string LP3WaferMap
  51. {
  52. get { return _sim.LP3SlotMap; }
  53. }
  54. public string LP1InfoPadStatus
  55. {
  56. get { return _sim.LP1InforPadState; }
  57. }
  58. public string LP2InfoPadStatus
  59. {
  60. get { return _sim.LP2InforPadState; }
  61. }
  62. public string LP3InfoPadStatus
  63. {
  64. get { return _sim.LP3InforPadState; }
  65. }
  66. [IgnorePropertyChange]
  67. public string InfoPadSet { get; set; }
  68. public ObservableCollection<WaferItem> WaferList { get; set; }
  69. public ICommand PlaceCommand { get; set; }
  70. public ICommand RemoveCommand { get; set; }
  71. public ICommand ClearCommand { get; set; }
  72. public ICommand SetAllCommand { get; set; }
  73. public ICommand RandomCommand { get; set; }
  74. public ICommand SetInfoPadCommand { get; set; }
  75. private EfemSimulator _sim;
  76. public EfemViewModel(int port, int index) : base("EfemViewModel")
  77. {
  78. PlaceCommand = new DelegateCommand<string>(Place);
  79. RemoveCommand = new DelegateCommand<string>(Remove);
  80. ClearCommand = new DelegateCommand<string>(Clear);
  81. SetAllCommand = new DelegateCommand<string>(SetAll);
  82. RandomCommand = new DelegateCommand<string>(RandomGenerateWafer);
  83. SetInfoPadCommand = new DelegateCommand<string>(SetInfoPadStatus);
  84. _sim = new EfemSimulator(port);
  85. Init(_sim);
  86. WaferList = new ObservableCollection<WaferItem>()
  87. {
  88. new WaferItem {Display = "1", Index = 2, State = 3}
  89. };
  90. if (index == 1)
  91. {
  92. _sim.SetUpWafer("LP1");
  93. _sim.SetUpWafer("LP2");
  94. _sim.SetUpWafer("LP3");
  95. }
  96. else
  97. {
  98. _sim.SetLowWafer("LP1");
  99. _sim.SetUpWafer("LP2");
  100. _sim.SetLowWafer("LP3");
  101. }
  102. }
  103. private void SetInfoPadStatus(string obj)
  104. {
  105. if (obj == "LP1")
  106. {
  107. _sim.LP1InforPadState = InfoPadSet;
  108. }
  109. if (obj == "LP2")
  110. {
  111. _sim.LP2InforPadState = InfoPadSet;
  112. }
  113. if (obj == "LP3")
  114. {
  115. _sim.LP3InforPadState = InfoPadSet;
  116. }
  117. }
  118. private void RandomGenerateWafer(string obj)
  119. {
  120. _sim.RandomWafer(obj);
  121. }
  122. private void SetAll(string obj)
  123. {
  124. _sim.SetAllWafer(obj);
  125. }
  126. private void Clear(string obj)
  127. {
  128. _sim.ClearWafer(obj);
  129. }
  130. private void Remove(string obj)
  131. {
  132. _sim.RemoveCarrier(obj);
  133. }
  134. private void Place(string obj)
  135. {
  136. _sim.PlaceCarrier(obj);
  137. }
  138. }
  139. public class EfemSimulator : SocketDeviceSimulator
  140. {
  141. public string LP1SlotMap
  142. {
  143. get { return string.Join("", _lp1slotMap); }
  144. }
  145. public string LP2SlotMap
  146. {
  147. get { return string.Join("", _lp2slotMap); }
  148. }
  149. public string LP3SlotMap
  150. {
  151. get { return string.Join("", _lp3slotMap); }
  152. }
  153. //public event Action<string> WriteDeviceEvent;
  154. private bool[] _lp1SigStateData1 = new bool[32];
  155. private bool[] _lp1SigStateData2 = new bool[32];
  156. private bool[] _lp2SigStateData1 = new bool[32];
  157. private bool[] _lp2SigStateData2 = new bool[32];
  158. private bool[] _lp3SigStateData1 = new bool[32];
  159. private bool[] _lp3SigStateData2 = new bool[32];
  160. private string[] _lp1slotMap = new string[25];
  161. private string[] _lp2slotMap = new string[25];
  162. private string[] _lp3slotMap = new string[25];
  163. private string[] _stationslotMap = new string[25];
  164. public string LP1InforPadState { get; set; } = "0";
  165. public string LP2InforPadState { get; set; } = "0";
  166. public string LP3InforPadState { get; set; } = "0";
  167. //private LpState _lp1State;
  168. //private E84State _lp1E84State;
  169. //private SystemState _systemState;
  170. //private bool _isPlaced;
  171. //private bool _isPresent;
  172. //private int _moveTime = 5000; //
  173. private PeriodicJob _HwThread;
  174. private bool _bCommReady;
  175. public EfemSimulator(int tcpPort)
  176. : base(tcpPort, -1, "\r", ' ')
  177. {
  178. for (int i = 0; i < _lp1slotMap.Length; i++)
  179. _lp1slotMap[i] = "0";
  180. for (int i = 0; i < _lp2slotMap.Length; i++)
  181. _lp2slotMap[i] = "0";
  182. for (int i = 0; i < _lp3slotMap.Length; i++)
  183. _lp3slotMap[i] = "0";
  184. for (int i = 0; i < _stationslotMap.Length; i++)
  185. _stationslotMap[i] = "0";
  186. for (int i = 0; i < _lp1SigStateData1.Length; i++)
  187. _lp1SigStateData1[i] = false;
  188. for (int i = 0; i < _lp1SigStateData2.Length; i++)
  189. _lp1SigStateData2[i] = false;
  190. for (int i = 0; i < _lp2SigStateData1.Length; i++)
  191. _lp2SigStateData1[i] = false;
  192. for (int i = 0; i < _lp2SigStateData2.Length; i++)
  193. _lp2SigStateData2[i] = false;
  194. for (int i = 0; i < _lp3SigStateData1.Length; i++)
  195. _lp3SigStateData1[i] = false;
  196. for (int i = 0; i < _lp3SigStateData2.Length; i++)
  197. _lp3SigStateData2[i] = false;
  198. _lp1SigStateData1[0] = false; //LP Placement
  199. _lp1SigStateData1[1] = false; //Pod Present
  200. _lp1SigStateData1[2] = false; //Access SW
  201. _lp1SigStateData1[3] = false; //Pod lock
  202. _lp1SigStateData1[4] = false; //Cover close
  203. _lp1SigStateData1[5] = false; // Cover lock
  204. _lp1SigStateData1[6] = false;
  205. _lp1SigStateData1[7] = false;
  206. _lp1SigStateData1[8] = false; //Info pad A
  207. _lp1SigStateData1[9] = false; //Info pad B
  208. _lp1SigStateData1[10] = false; //Info pad C
  209. _lp1SigStateData1[11] = false; //Info pad D
  210. _lp1SigStateData1[24] = false; //VALID (E84)
  211. _lp1SigStateData1[25] = false; //CS_0 (E84)
  212. _lp1SigStateData1[26] = false; //CS_1 (E84)
  213. _lp1SigStateData1[27] = false; //Valid
  214. _lp1SigStateData1[28] = false; //TR_REQ (E84)
  215. _lp1SigStateData1[29] = false; //BUSY (E84)
  216. _lp1SigStateData1[30] = false; //COMPT (E84)
  217. _lp1SigStateData1[31] = false; //CONT (E84)
  218. _lp1SigStateData2[0] = false; //PRESENCE
  219. _lp1SigStateData2[1] = false; //PLACEMENT
  220. _lp1SigStateData2[2] = false; //LOAD
  221. _lp1SigStateData2[3] = false; //UNLOAD
  222. _lp1SigStateData2[4] = false; //MANUAL MODE
  223. _lp1SigStateData2[5] = false; //ERROR
  224. _lp1SigStateData2[6] = false; //CLAMP / UNCLAMP
  225. _lp1SigStateData2[7] = false; //DOCK/UNDOCK
  226. _lp1SigStateData2[8] = false; //ACCESS SW
  227. //A000A 41010 10001 01000
  228. _lp2SigStateData1[0] = false; //LP Placement
  229. _lp2SigStateData1[1] = false; //Pod Present
  230. _lp2SigStateData1[2] = false; //Access SW
  231. _lp2SigStateData1[3] = false; //Pod lock
  232. _lp2SigStateData1[4] = false; //Cover close
  233. _lp2SigStateData1[5] = false; // Cover lock
  234. _lp2SigStateData1[6] = false;
  235. _lp2SigStateData1[7] = false;
  236. _lp2SigStateData1[8] = false; //Info pad A
  237. _lp2SigStateData1[9] = false; //Info pad B
  238. _lp2SigStateData1[10] = false; //Info pad C
  239. _lp2SigStateData1[11] = false; //Info pad D
  240. _lp2SigStateData1[24] = false; //VALID (E84)
  241. _lp2SigStateData1[25] = false; //CS_0 (E84)
  242. _lp2SigStateData1[26] = false; //CS_1 (E84)
  243. _lp2SigStateData1[27] = false; //Valid
  244. _lp2SigStateData1[28] = false; //TR_REQ (E84)
  245. _lp2SigStateData1[29] = false; //BUSY (E84)
  246. _lp2SigStateData1[30] = false; //COMPT (E84)
  247. _lp2SigStateData1[31] = false; //CONT (E84)
  248. _lp2SigStateData2[0] = false; //PRESENCE
  249. _lp2SigStateData2[1] = false; //PLACEMENT
  250. _lp2SigStateData2[2] = false; //LOAD
  251. _lp2SigStateData2[3] = false; //UNLOAD
  252. _lp2SigStateData2[4] = false; //MANUAL MODE
  253. _lp2SigStateData2[5] = false; //ERROR
  254. _lp2SigStateData2[6] = false; //CLAMP / UNCLAMP
  255. _lp2SigStateData2[7] = false; //DOCK/UNDOCK
  256. _lp2SigStateData2[8] = false; //ACCESS SW
  257. //A000A 41010 10001 01000
  258. _lp3SigStateData1[0] = false; //LP Placement
  259. _lp3SigStateData1[1] = false; //Pod Present
  260. _lp3SigStateData1[2] = false; //Access SW
  261. _lp3SigStateData1[3] = false; //Pod lock
  262. _lp3SigStateData1[4] = false; //Cover close
  263. _lp3SigStateData1[5] = false; // Cover lock
  264. _lp3SigStateData1[6] = false;
  265. _lp3SigStateData1[7] = false;
  266. _lp3SigStateData1[8] = false; //Info pad A
  267. _lp3SigStateData1[9] = false; //Info pad B
  268. _lp3SigStateData1[10] = false; //Info pad C
  269. _lp3SigStateData1[11] = false; //Info pad D
  270. _lp3SigStateData1[24] = false; //VALID (E84)
  271. _lp3SigStateData1[25] = false; //CS_0 (E84)
  272. _lp3SigStateData1[26] = false; //CS_1 (E84)
  273. _lp3SigStateData1[27] = false; //Valid
  274. _lp3SigStateData1[28] = false; //TR_REQ (E84)
  275. _lp3SigStateData1[29] = false; //BUSY (E84)
  276. _lp3SigStateData1[30] = false; //COMPT (E84)
  277. _lp3SigStateData1[31] = false; //CONT (E84)
  278. _lp3SigStateData2[0] = false; //PRESENCE
  279. _lp3SigStateData2[1] = false; //PLACEMENT
  280. _lp3SigStateData2[2] = false; //LOAD
  281. _lp3SigStateData2[3] = false; //UNLOAD
  282. _lp3SigStateData2[4] = false; //MANUAL MODE
  283. _lp3SigStateData2[5] = false; //ERROR
  284. _lp3SigStateData2[6] = false; //CLAMP / UNCLAMP
  285. _lp3SigStateData2[7] = false; //DOCK/UNDOCK
  286. _lp3SigStateData2[8] = false; //ACCESS SW
  287. BinaryDataMode = false;
  288. }
  289. //public void ChangeSlotMap(SlotMapChangedEventArgs obj)
  290. //{
  291. // string slotMap = obj.SlotMap.Replace("'", "");
  292. // for (int i = 0; i < slotMap.Length; i++)
  293. // _slotMap[i] = slotMap.Substring(i, 1);
  294. //}
  295. public override void ClientConnected(object sender, TcpClientConnectedEventArgs e)
  296. {
  297. base.ClientConnected(sender, e);
  298. Thread.Sleep(10);
  299. OnWriteMessage("INF:READY/COMM;");
  300. LOG.Info("Send message " + "INF:READY/COMM;");
  301. _HwThread = new PeriodicJob(5000, OnSendEvent, "EfemHardware", true);
  302. }
  303. private bool OnSendEvent()
  304. {
  305. if (!_bCommReady)
  306. {
  307. OnWriteMessage("INF:READY/COMM;");
  308. }
  309. return true;
  310. }
  311. protected override void ProcessUnsplitMessage(string message)
  312. {
  313. LOG.Info("Received message " + message);
  314. string[] msg = message.Split(':');
  315. if (msg.Length < 2)
  316. return;
  317. if (!_bCommReady && message.Contains("ACK:READY/COMM"))
  318. {
  319. _bCommReady = true;
  320. }
  321. string type = msg[0];
  322. string cmd = msg[1];
  323. switch (type)
  324. {
  325. case "SET":
  326. ReceiveSetCommand(cmd);
  327. break;
  328. case "MOD":
  329. ReceiveModCommand(cmd);
  330. break;
  331. case "GET":
  332. ReceiveGetCommand(cmd);
  333. break;
  334. case "FIN":
  335. ReceiveFinCommand(cmd);
  336. break;
  337. case "MOV":
  338. ReceiveMovCommand(cmd);
  339. break;
  340. case "EVT":
  341. ReceiveEvtCommand(cmd);
  342. break;
  343. case "TCH":
  344. ReceiveTchCommand(cmd);
  345. break;
  346. default:
  347. ReceiveUnknownCommand(message);
  348. break;
  349. }
  350. }
  351. private void ReceiveMovCommand(string cmd)
  352. {
  353. bool needINF = true;
  354. string[] data = cmd.Split('/');
  355. bool needSendMap = false;
  356. switch (data[0])
  357. {
  358. case "INIT":
  359. break;
  360. case "ORGSH": //back to initial
  361. if (data[1] == "ALL")
  362. {
  363. }
  364. if (data[1] == "P1")
  365. {
  366. }
  367. if (data[1] == "P2")
  368. {
  369. }
  370. break;
  371. case "ABORG": //Force back to initial
  372. break;
  373. case "UNLOCK": //FOUP clamp: Close
  374. ReceiveCommandUNLOCK(data[1]);
  375. break;
  376. case "LOCK": //FOUP clamp: open
  377. ReceiveCommandLOCK(data[1]);
  378. break;
  379. case "DOCK": //FOUP dock:
  380. ReceiveCommandDOCK(data[1]);
  381. break;
  382. case "UNDOCK": //FOUP undock
  383. ReceiveCommandUNDOCK(data[1]);
  384. break;
  385. case "OPEN": //Door open
  386. ReceiveCommandOPEN(data[1]);
  387. break;
  388. case "CLOSE": //Door Close
  389. ReceiveCommandCLOSE(data[1]);
  390. break;
  391. case "WAFSH": //Map
  392. needSendMap = true;
  393. break;
  394. case "GOTO": //Maps and loads the FOUP.
  395. break;
  396. case "CSTID":
  397. break;
  398. default:
  399. break;
  400. }
  401. SendAck(cmd);
  402. Thread.Sleep(500);
  403. if (needINF)
  404. {
  405. if (needSendMap)
  406. {
  407. Thread.Sleep(200);
  408. SendMapEvent(data[1]);
  409. }
  410. if (data[0] == "CSTID")
  411. FeedbackCarrierID(cmd);
  412. else
  413. SendInf(cmd);
  414. }
  415. }
  416. private void ReceiveCommandCLOSE(string module)
  417. {
  418. module = module.Replace(";", "").Replace("\r", "");
  419. if (module == "P1")
  420. {
  421. _lp1SigStateData1[4] = false;
  422. _lp1SigStateData1[5] = false;
  423. }
  424. if (module == "P2")
  425. {
  426. _lp2SigStateData1[4] = false;
  427. _lp2SigStateData1[5] = false;
  428. }
  429. if (module == "P3")
  430. {
  431. _lp3SigStateData1[4] = false;
  432. _lp3SigStateData1[5] = false;
  433. }
  434. }
  435. private void ReceiveCommandOPEN(string module)
  436. {
  437. module = module.Replace(";", "").Replace("\r", "");
  438. if (module == "P1")
  439. {
  440. _lp1SigStateData1[4] = true;
  441. _lp1SigStateData1[5] = true;
  442. }
  443. if (module == "P2")
  444. {
  445. _lp2SigStateData1[4] = true;
  446. _lp2SigStateData1[5] = true;
  447. }
  448. if (module == "P3")
  449. {
  450. _lp3SigStateData1[4] = true;
  451. _lp3SigStateData1[5] = true;
  452. }
  453. }
  454. private void ReceiveCommandDOCK(string module)
  455. {
  456. module = module.Replace(";", "").Replace("\r", "");
  457. if (module == "P1")
  458. _lp1SigStateData1[5] = true;
  459. if (module == "P2")
  460. _lp2SigStateData1[5] = true;
  461. if (module == "P3")
  462. _lp3SigStateData1[5] = true;
  463. }
  464. private void ReceiveCommandUNDOCK(string module)
  465. {
  466. module = module.Replace(";", "").Replace("\r", "");
  467. if (module == "P1")
  468. _lp1SigStateData1[5] = false;
  469. if (module == "P2")
  470. _lp2SigStateData1[5] = false;
  471. if (module == "P3")
  472. _lp3SigStateData1[5] = false;
  473. }
  474. private void ReceiveCommandLOCK(string module)
  475. {
  476. module = module.Replace(";", "").Replace("\r", "");
  477. if (module == "P1")
  478. _lp1SigStateData1[3] = true;
  479. if (module == "P2")
  480. _lp2SigStateData1[3] = true;
  481. if (module == "P3")
  482. _lp3SigStateData1[3] = true;
  483. }
  484. private void ReceiveCommandUNLOCK(string module)
  485. {
  486. module = module.Replace(";", "").Replace("\r", "");
  487. if (module == "P1")
  488. _lp1SigStateData1[3] = false;
  489. if (module == "P2")
  490. _lp2SigStateData1[3] = false;
  491. if (module == "P3")
  492. _lp3SigStateData1[3] = false;
  493. }
  494. private void ReceiveSetCommand(string cmd)
  495. {
  496. string[] data = cmd.Split('/');
  497. switch (data[0])
  498. {
  499. case "LED":
  500. if (data[1] == "P1")
  501. {
  502. if (data[2] == "LOAD")
  503. {
  504. if (data[3] == "ON")
  505. {
  506. _lp1SigStateData2[2] = true;
  507. }
  508. else _lp1SigStateData2[2] = false;
  509. }
  510. if (data[2] == "UNLOAD")
  511. {
  512. if (data[3] == "ON")
  513. {
  514. _lp1SigStateData2[3] = true;
  515. }
  516. else _lp1SigStateData2[3] = false;
  517. }
  518. if (data[2] == "MANUAL MODE")
  519. {
  520. if (data[3] == "ON")
  521. {
  522. _lp1SigStateData2[4] = true;
  523. }
  524. else _lp1SigStateData2[4] = false;
  525. }
  526. }
  527. if (data[1] == "P2")
  528. {
  529. if (data[2] == "LOAD")
  530. {
  531. if (data[3] == "ON")
  532. {
  533. _lp2SigStateData2[2] = true;
  534. }
  535. else _lp2SigStateData2[2] = false;
  536. }
  537. if (data[2] == "UNLOAD")
  538. {
  539. if (data[3] == "ON")
  540. {
  541. _lp2SigStateData2[3] = true;
  542. }
  543. else _lp2SigStateData2[3] = false;
  544. }
  545. if (data[2] == "MANUAL MODE")
  546. {
  547. if (data[3] == "ON")
  548. {
  549. _lp2SigStateData2[4] = true;
  550. }
  551. else _lp2SigStateData2[4] = false;
  552. }
  553. }
  554. break;
  555. case "SIZE":
  556. if (data[1] == "ARM1")
  557. robotArm1Wafersize = data[2];
  558. if (data[1] == "ARM2")
  559. robotArm2Wafersize = data[2];
  560. if (data[1] == "ALIGN1")
  561. alignerwafersize = data[2];
  562. break;
  563. }
  564. SendAck(cmd);
  565. if (cmd.Contains("FSB")) return;
  566. SendInf(cmd);
  567. }
  568. private void ReceiveModCommand(string cmd)
  569. {
  570. SendAck(cmd);
  571. }
  572. #region GET Command
  573. private void ReceiveGetCommand(string cmdGet)
  574. {
  575. string message = $"ACK:{cmdGet}";
  576. OnWriteMessage(message);
  577. string[] data = cmdGet.Split('/');
  578. switch (data[0])
  579. {
  580. case "MAPDT":
  581. FeedbackGetWaferMapDescendingOrder(cmdGet);
  582. break;
  583. case "ERROR":
  584. break;
  585. case "CLAMP":
  586. break;
  587. case "STATE":
  588. FeedbackGetStatus(cmdGet);
  589. break;
  590. case "MODE":
  591. break;
  592. case "TRANSREQ":
  593. break;
  594. case "SIGSTAT":
  595. FeedbackGetSigStatus(cmdGet);
  596. break;
  597. case "EVENT":
  598. break;
  599. case "CSTID":
  600. FeedbackCarrierID(cmdGet);
  601. break;
  602. case "SIZE":
  603. FeedbackWaferSize(cmdGet);
  604. break;
  605. case "ADPLOCK":
  606. break;
  607. case "ADPUNLOCK":
  608. break;
  609. }
  610. }
  611. private void FeedbackWaferSize(string cmdGet)
  612. {
  613. //string message = string.Format("s00ACK:{0}/{1};\r", cmd, string.Join("", _state));
  614. string[] data = cmdGet.Replace(";", "").Split('/');
  615. string message = $"INF:{cmdGet.Replace(";", "")}/{robotArm1Wafersize};";
  616. if (message.Contains("BF1") || message.Contains("BF2") || message.Contains("BF3"))
  617. message = message.Replace("300", "NONE");
  618. if (message.Contains("STATION"))
  619. message = message.Replace("300", "NONE");
  620. OnWriteMessage(message);
  621. }
  622. private string robotArm1Wafersize = "300";
  623. private string robotArm2Wafersize = "300";
  624. private string alignerwafersize = "300";
  625. private int _cid = 0;
  626. private void FeedbackCarrierID(string cmd)
  627. {
  628. _cid++;
  629. if (_cid > 1)
  630. _cid = 1;
  631. string message = $"INF:{cmd.Replace(";", "")}/{_cid};\r";
  632. OnWriteMessage(message);
  633. }
  634. private void FeedbackGetStatus(string cmd)
  635. {
  636. //string message = string.Format("s00ACK:{0}/{1};\r", cmd, string.Join("", _state));
  637. string[] data = cmd.Split('/');
  638. string reply = "";
  639. if (data[1] == "TRACK;")
  640. {
  641. reply = "00000";
  642. }
  643. if (data[1] == "VER;")
  644. {
  645. reply = "01.000(2021-03-11)";
  646. }
  647. if (data[1] == "INF1;")
  648. {
  649. reply = "0.06";
  650. }
  651. string message = $"INF:{cmd.Replace(";", "")}/{reply};\r";
  652. OnWriteMessage(message);
  653. }
  654. private void FeedbackGetSigStatus(string cmd)
  655. {
  656. string message = "";
  657. string[] data = cmd.Split('/');
  658. if (data[1] == "SYSTEM;")
  659. {
  660. message = "FFFF/FFFF";
  661. }
  662. if (data[1] == "P1;")
  663. {
  664. message = $"{ConvertBinToHexString(_lp1SigStateData1)}/{ConvertBinToHexString(_lp1SigStateData2)}";
  665. }
  666. if (data[1] == "P2;")
  667. {
  668. message = $"{ConvertBinToHexString(_lp2SigStateData1)}/{ConvertBinToHexString(_lp2SigStateData2)}";
  669. }
  670. if (data[1] == "P3;")
  671. {
  672. message = $"{ConvertBinToHexString(_lp3SigStateData1)}/{ConvertBinToHexString(_lp3SigStateData2)}";
  673. }
  674. string datamsg = $"INF:{cmd.Replace(";", "")}/{message};\r";
  675. OnWriteMessage(datamsg);
  676. }
  677. private void FeedbackGetVersion()
  678. {
  679. }
  680. private void SendMapEvent(string module)
  681. {
  682. module = module.Replace(";", "").Replace("\r", "");
  683. var sm = _lp1slotMap.Reverse();
  684. if (module.Contains("P1"))
  685. sm = _lp1slotMap.Reverse();
  686. if (module.Contains("P2"))
  687. sm = _lp2slotMap.Reverse();
  688. if (module.Contains("P3"))
  689. sm = _lp3slotMap.Reverse();
  690. if (module.Contains("STATION"))
  691. sm = _stationslotMap.Reverse();
  692. if (module.Contains("LL"))
  693. sm =new string[]{"00000000"};
  694. string message = $"EVT:MAPDT/{module}/{string.Join("", sm)};\r";
  695. OnWriteMessage(message);
  696. }
  697. //25 - 1
  698. private void FeedbackGetWaferMapDescendingOrder(string cmd)
  699. {
  700. var sm = _lp1slotMap.Reverse();
  701. if (cmd.Contains("P1"))
  702. sm = _lp1slotMap.Reverse();
  703. if (cmd.Contains("P2"))
  704. sm = _lp2slotMap.Reverse();
  705. if (cmd.Contains("P3"))
  706. sm = _lp3slotMap.Reverse();
  707. if (cmd.Contains("STATION"))
  708. sm = _stationslotMap.Reverse();
  709. if (cmd.Contains("LL"))
  710. sm = new string[] { "00000000" };
  711. string message = $"INF:{cmd.Replace(";", "")}/{string.Join("", sm)};\r";
  712. OnWriteMessage(message);
  713. }
  714. //1-25
  715. private void FeedbackGetWaferCount()
  716. {
  717. }
  718. #endregion GET Command
  719. private void ReceiveFinCommand(string cmd)
  720. {
  721. SendAck(cmd);
  722. }
  723. private void ReceiveEvtCommand(string cmd)
  724. {
  725. SendAck(cmd);
  726. }
  727. private void ReceiveTchCommand(string cmd)
  728. {
  729. SendAck(cmd);
  730. }
  731. private void ReceiveUnknownCommand(string message)
  732. {
  733. //LOG.Write("LoadPort" + _loadPortNumber + " Receive Unknown message," + message);
  734. }
  735. private void SendInf(string cmd)
  736. {
  737. Thread.Sleep(1500);
  738. //string msg = _isPlaced ? "s00INF:PODON;\r" : "s00INF:PODOF;\r";
  739. string message = Encoding.ASCII.GetString(BuildMesage($"INF:{cmd}"));
  740. OnWriteMessage("INF:" + cmd);
  741. LOG.Info("Send message " + "INF:" + cmd);
  742. }
  743. private void SendAck(string cmd)
  744. {
  745. string ack = Encoding.ASCII.GetString(BuildMesage($"ACK:{cmd}"));
  746. OnWriteMessage("ACK:" + cmd);
  747. LOG.Info("Send message " + "ACK:" + cmd);
  748. }
  749. public static byte[] BuildMesage(string data)
  750. {
  751. List<byte> ret = new List<byte>();
  752. ret.Add(0x1);
  753. List<byte> cmd = new List<byte>();
  754. foreach (char c in data)
  755. {
  756. cmd.Add((byte)c);
  757. }
  758. //cmd.Add((byte)(':')); //3A
  759. cmd.Add((byte)(';')); //3B
  760. int length = cmd.Count + 4;
  761. int checksum = length;
  762. foreach (byte bvalue in cmd)
  763. {
  764. checksum += bvalue;
  765. }
  766. byte[] byteschecksum = Encoding.ASCII.GetBytes(Convert.ToString((int)((byte)(checksum & 0xFF)), 16));
  767. byte[] blength = BitConverter.GetBytes((short)length);
  768. ret.Add(blength[1]);
  769. ret.Add(blength[0]);
  770. ret.AddRange(new byte[] { 0, 0 });
  771. ret.AddRange(cmd);
  772. ret.AddRange(byteschecksum);
  773. ret.Add(0xD);
  774. return ret.ToArray();
  775. }
  776. public void PlaceCarrier(string lp)
  777. {
  778. string message = "";
  779. if (lp == "P1")
  780. {
  781. _lp1SigStateData1[0] = true; //LP Placement
  782. _lp1SigStateData1[1] = false; //Pod Present.
  783. _lp1SigStateData1[6] = true; //wafer size 8.
  784. _lp1SigStateData1[7] = false; //wafer size 12.
  785. message = $"EVT:SIGSTAT/{lp}/{ConvertBinToHexString(_lp1SigStateData1)}" +
  786. $"/{ConvertBinToHexString(_lp1SigStateData2)}";
  787. }
  788. if (lp == "P2")
  789. {
  790. _lp2SigStateData1[0] = true; //LP Placement
  791. _lp2SigStateData1[1] = false; //Pod Present
  792. _lp2SigStateData1[6] = true; //wafer size 8.
  793. _lp2SigStateData1[7] = false; //wafer size 12.
  794. message = $"EVT:SIGSTAT/{lp}/{ConvertBinToHexString(_lp2SigStateData1)}" +
  795. $"/{ConvertBinToHexString(_lp2SigStateData2)}";
  796. }
  797. if (lp == "P3")
  798. {
  799. _lp3SigStateData1[0] = true; //LP Placement
  800. _lp3SigStateData1[1] = false; //Pod Present
  801. _lp3SigStateData1[6] = false; //wafer size 8.
  802. _lp3SigStateData1[7] = true; //wafer size 12.
  803. message = $"EVT:SIGSTAT/{lp}/{ConvertBinToHexString(_lp3SigStateData1)}" +
  804. $"/{ConvertBinToHexString(_lp3SigStateData2)}";
  805. }
  806. OnWriteMessage(message + ";\r");
  807. }
  808. private string ConvertBinToHexString(bool[] data)
  809. {
  810. uint intdata = 0;
  811. for (int i = 0; i < data.Length; i++)
  812. {
  813. intdata += data[i] ? (uint)Math.Pow(2, i) : 0;
  814. }
  815. return intdata.ToString("X8");
  816. }
  817. public void RemoveCarrier(string lp)
  818. {
  819. string message = "";
  820. if (lp == "P1")
  821. {
  822. _lp1SigStateData1[0] = false; //LP Placement
  823. _lp1SigStateData1[1] = true; //Pod Present.
  824. message = $"EVT:SIGSTAT/{lp}/{ConvertBinToHexString(_lp1SigStateData1)}" +
  825. $"/{ConvertBinToHexString(_lp1SigStateData2)}";
  826. }
  827. if (lp == "P2")
  828. {
  829. _lp2SigStateData1[0] = false; //LP Placement
  830. _lp2SigStateData1[1] = true; //Pod Present
  831. message = $"EVT:SIGSTAT/{lp}/{ConvertBinToHexString(_lp2SigStateData1)}" +
  832. $"/{ConvertBinToHexString(_lp2SigStateData2)}";
  833. }
  834. if (lp == "P3")
  835. {
  836. _lp3SigStateData1[0] = false; //LP Placement
  837. _lp3SigStateData1[1] = true; //Pod Present
  838. message = $"EVT:SIGSTAT/{lp}/{ConvertBinToHexString(_lp3SigStateData1)}" +
  839. $"/{ConvertBinToHexString(_lp3SigStateData2)}";
  840. }
  841. OnWriteMessage(message + ";\r");
  842. }
  843. public void ClearWafer(string lp)
  844. {
  845. if (lp == "LP1")
  846. {
  847. for (int i = 0; i < _lp1slotMap.Length; i++)
  848. {
  849. _lp1slotMap[i] = "0";
  850. }
  851. }
  852. if (lp == "LP2")
  853. {
  854. for (int i = 0; i < _lp2slotMap.Length; i++)
  855. {
  856. _lp2slotMap[i] = "0";
  857. }
  858. }
  859. if (lp == "LP3")
  860. {
  861. for (int i = 0; i < _lp3slotMap.Length; i++)
  862. {
  863. _lp3slotMap[i] = "0";
  864. }
  865. }
  866. }
  867. public void SetAllWafer(string lp)
  868. {
  869. if (lp == "LP1")
  870. {
  871. for (int i = 0; i < _lp1slotMap.Length; i++)
  872. {
  873. _lp1slotMap[i] = "1";
  874. }
  875. }
  876. if (lp == "LP2")
  877. {
  878. for (int i = 0; i < _lp2slotMap.Length; i++)
  879. {
  880. _lp2slotMap[i] = "1";
  881. }
  882. }
  883. if (lp == "LP3")
  884. {
  885. for (int i = 0; i < _lp3slotMap.Length; i++)
  886. {
  887. _lp3slotMap[i] = "1";
  888. }
  889. }
  890. }
  891. public void SetUpWafer(string lp)
  892. {
  893. if (lp == "LP1")
  894. {
  895. for (int i = 0; i < _lp1slotMap.Length; i++)
  896. {
  897. _lp1slotMap[i] = i > 15 ? "1" : "0";
  898. }
  899. }
  900. if (lp == "LP2")
  901. {
  902. for (int i = 0; i < _lp2slotMap.Length; i++)
  903. {
  904. _lp2slotMap[i] = i > 15 ? "1" : "0";
  905. }
  906. }
  907. if (lp == "LP3")
  908. {
  909. for (int i = 0; i < _lp3slotMap.Length; i++)
  910. {
  911. _lp3slotMap[i] = i > 15 ? "1" : "0";
  912. }
  913. }
  914. }
  915. public void SetLowWafer(string lp)
  916. {
  917. if (lp == "LP1")
  918. {
  919. for (int i = 0; i < _lp1slotMap.Length; i++)
  920. {
  921. _lp1slotMap[i] = i < 10 ? "1" : "0";
  922. }
  923. }
  924. if (lp == "LP2")
  925. {
  926. for (int i = 0; i < _lp2slotMap.Length; i++)
  927. {
  928. _lp2slotMap[i] = i < 10 ? "1" : "0";
  929. }
  930. }
  931. if (lp == "LP3")
  932. {
  933. for (int i = 0; i < _lp3slotMap.Length; i++)
  934. {
  935. _lp3slotMap[i] = i < 10 ? "1" : "0";
  936. }
  937. }
  938. }
  939. public void RandomWafer(string lp)
  940. {
  941. Random _rd = new Random();
  942. if (lp == "LP1")
  943. {
  944. for (int i = 0; i < _lp1slotMap.Length; i++)
  945. {
  946. _lp1slotMap[i] = _rd.Next(0, 10) < 6 ? "0" : "1";
  947. }
  948. }
  949. if (lp == "LP2")
  950. {
  951. for (int i = 0; i < _lp2slotMap.Length; i++)
  952. {
  953. _lp2slotMap[i] = _rd.Next(0, 10) < 6 ? "0" : "1";
  954. }
  955. }
  956. if (lp == "LP3")
  957. {
  958. for (int i = 0; i < _lp3slotMap.Length; i++)
  959. {
  960. _lp3slotMap[i] = _rd.Next(0, 10) < 6 ? "0" : "1";
  961. }
  962. }
  963. }
  964. public class LpState
  965. {
  966. public bool IsPlacement { get; set; }
  967. public bool IsPresent { get; set; }
  968. public bool IsAccessSwPressed { get; set; }
  969. public bool ClampState { get; set; }//close=1
  970. public bool DoorState { get; set; }//open=1
  971. public bool DockState { get; set; }//docked=1
  972. public bool IndicatiorPresence { get; set; }//ON=1
  973. public bool IndicatiorPlacement { get; set; }//ON=1
  974. public bool IndicatiorLoad { get; set; }//ON=1
  975. public bool IndicatiorUnload { get; set; }//ON=1
  976. public bool IndicatiorManualMode { get; set; }//ON=1
  977. public bool IndicatorAlarm { get; set; }//ON=1
  978. public bool IndicatiorClampUnclamp { get; set; }//ON=1
  979. public bool IndicatiorDockUndock { get; set; }//ON=1
  980. public bool IndicatiorOpAccess { get; set; }//ON=1
  981. }
  982. public class E84State
  983. {
  984. public bool DiValid { get; set; }//ON=1
  985. public bool DiCS0 { get; set; }//ON=1
  986. public bool DiCS1 { get; set; }//ON=1
  987. public bool DiTrReq { get; set; }//ON=1
  988. public bool DiBusy { get; set; }//ON=1
  989. public bool DiCompt { get; set; }//ON=1
  990. public bool DiCont { get; set; }//ON=1
  991. public bool DoLoadReq { get; set; }//ON=1
  992. public bool DoUnloadReq { get; set; }//ON=1
  993. public bool DoReady { get; set; }//ON=1
  994. public bool DoHOAvbl { get; set; }//ON=1
  995. public bool DoES { get; set; }//ON=1
  996. }
  997. public class SystemState
  998. {
  999. public bool VacuumsSourcePressure1 { get; set; }//Normal=1
  1000. public bool VacuumsSourcePressure2 { get; set; }//Normal=1
  1001. public bool CompressedAirPressure1 { get; set; }//Normal=1
  1002. public bool CompressedAirPressure2 { get; set; }//Normal=1
  1003. public bool DifferentialPressureSensorSetting1 { get; set; }//Normal=1
  1004. public bool DifferentialPressureSensorSetting2 { get; set; }//Normal=1
  1005. public bool FFUAlarm { get; set; }//Normal=1
  1006. public bool IonizerAlarm { get; set; }//Normal=1
  1007. public bool ModeSwitch { get; set; }//RUN=1
  1008. public bool DriverPower { get; set; }//Normal=1
  1009. public bool DoorOpenCloseStatus { get; set; }//close=1
  1010. public bool AreaSensorBarInterlock { get; set; }//Normal=1
  1011. public bool LightRed { get; set; }//ON=1
  1012. public bool LightYellow { get; set; }//ON=1
  1013. public bool LightGreen { get; set; }//ON=1
  1014. public bool LightBlue { get; set; }//ON=1
  1015. public bool LightWhite { get; set; }//ON=1
  1016. public bool FlashRed { get; set; }//Flash=1
  1017. public bool FlashYellow { get; set; }//Flash=1
  1018. public bool FlashGreen { get; set; }//Flash=1
  1019. public bool FlashBlue { get; set; }//Flash=1
  1020. public bool FlashWhite { get; set; }//Flash=1
  1021. public bool Buzzer1 { get; set; }//ON=1
  1022. public bool Buzzer2 { get; set; }//ON=1
  1023. }
  1024. }
  1025. }