SunWayEfemSimulator.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. using Aitex.Core.UI.Control;
  6. using MECF.Framework.Simulator.Core.Driver;
  7. using Aitex.Core.Util;
  8. using CyberX8_Core;
  9. using Aitex.Core.RT.DataCenter;
  10. using System.Linq;
  11. namespace CyberX8_Simulator.Devices
  12. {
  13. public class SunWayEfemSimulator : SocketDeviceSimulator
  14. {
  15. private const string SCMD = @"(?<=\:)(.*?)(?=\/)";
  16. private const string SFOUP = @"(?<=P)(\d{1})(?=[\;\/])";
  17. private const string ACK = "ACK";
  18. private readonly char[] delimiters = { ':', '/', '>', '|', ';' };
  19. private string[] _slotMap = new string[25];
  20. private string[] _slotDummy = new string[25];
  21. private PeriodicJob _HwThread;
  22. private bool _bCommReady;
  23. private bool _isDoorOpen;
  24. private bool _isLp1Placed;
  25. private bool _isLp2Placed;
  26. private bool _isLp3Placed;
  27. private bool _isLp1Clamped;
  28. private bool _isLp2Clamped;
  29. private bool _isLp3Clamped;
  30. private bool _isLP1Docked;
  31. private bool _isLP2Docked;
  32. private bool _isLP3Docked;
  33. public int WaferSize = 200;
  34. private int _speed = 20;
  35. private string _carrier1ID = "12345678";
  36. private string _carrier2ID = "12345678";
  37. private string _carrier3ID = "12345678";
  38. public string SlotMap
  39. {
  40. get { return string.Join("", _slotMap); }
  41. }
  42. public bool _isVacuumError { get; set; }
  43. public bool _isAirError { get; set; }
  44. public bool _isFlowError { get; set; }
  45. public bool _isLeak { get; set; }
  46. public bool _isMaintain { get; set; }
  47. public bool _isWaferPresent { get; set; }
  48. public bool _isMaintainDoorOpen { get; private set; }
  49. public bool _isProtrude1 { get; set; }
  50. public bool _isProtrude2 { get; set; }
  51. public bool _isVAC { get; set; }
  52. public bool _isAIR { get; set; }
  53. private bool _isDoorOpen1;
  54. public bool IsDoorOpen1 { get { return _isDoorOpen1; } set { _isDoorOpen1 = value; SendLP1Data(); } }
  55. private bool _isDoorOpen2;
  56. public bool IsDoorOpen2 { get { return _isDoorOpen2; } set { _isDoorOpen2 = value;SendLP2Data(); } }
  57. private bool _isDoorOpen3;
  58. public bool IsDoorOpen3
  59. {
  60. get { return _isDoorOpen3; }
  61. set { _isDoorOpen3 = value; SendLP3Data(); }
  62. }
  63. public SunWayEfemSimulator() : base(13001, -1, "\r", ' ')
  64. {
  65. for (int i = 0; i < _slotMap.Length; i++)
  66. _slotMap[i] = "0";
  67. for(int i=0; i < _slotDummy.Length; i++)
  68. {
  69. _slotDummy[i]="0";
  70. }
  71. _HwThread = new PeriodicJob(5000, OnSendEvent, "EfemHardware", true);
  72. }
  73. private bool OnSendEvent()
  74. {
  75. if (IsConnected)
  76. {
  77. }
  78. return true;
  79. }
  80. protected override void ProcessUnsplitMessage(string str)
  81. {
  82. string ack = "";
  83. if (str.StartsWith("RQ LOAD")) //查询手指是否带片
  84. {
  85. ack = "LOAD A OFF\n_RDY";
  86. }
  87. else if(str.StartsWith("RSR")) //返回扫片结果
  88. {
  89. string[] strings = str.Split(' ').ToArray();
  90. int stationNumber = int.Parse(strings[1]);
  91. if (stationNumber >= 50 && stationNumber <= 58) //LP
  92. {
  93. string lpwafer = "";
  94. foreach(var item in _slotMap)
  95. {
  96. lpwafer += $" {item}";
  97. }
  98. ack = "MAP" + lpwafer;
  99. }
  100. else if (stationNumber >= 59 && stationNumber <= 64) //dummy
  101. {
  102. string dummywafer = "";
  103. foreach (var item in _slotDummy)
  104. {
  105. dummywafer += $" {item}";
  106. }
  107. ack = "MAP" + dummywafer;
  108. }
  109. }
  110. else //默认回复
  111. {
  112. ack = str + "\n_RDY"; ;
  113. }
  114. OnWriteMessage(ack);
  115. // 处理INF
  116. //OnWork(str);
  117. }
  118. internal void SetCassetteDoor(bool doorOpen)
  119. {
  120. _isMaintainDoorOpen = doorOpen;
  121. uint data = doorOpen ? (uint)0b0111111111000001110 : (uint)0b0111111111000001111;
  122. string msg = $"EVT:SIGSTAT/System/{data:X8}/00000000;";
  123. OnWriteMessage(msg);
  124. }
  125. internal void SetMaintain(bool maintain)
  126. {
  127. _isMaintain = maintain;
  128. uint data = maintain ? (uint)0b0111111111000011111 : (uint)0b0111111111000001111;
  129. string msg = $"EVT:SIGSTAT/System/{data:X8}/00000000;";
  130. OnWriteMessage(msg);
  131. }
  132. internal void SetProtrude1(bool protrude)
  133. {
  134. _isProtrude1 = protrude;
  135. uint data = protrude? (uint)0b0111111111000101111: (uint)0b0111111111000001111;
  136. string msg = $"EVT:SIGSTAT/System/{data:X8}/00000000;";
  137. OnWriteMessage(msg);
  138. }
  139. internal void SetProtrude2(bool protrude)
  140. {
  141. _isProtrude2 = protrude;
  142. uint data = protrude ? (uint)0b0111111111001001111 : (uint)0b0111111111000001111;
  143. string msg = $"EVT:SIGSTAT/System/{data:X8}/00000000;";
  144. OnWriteMessage(msg);
  145. }
  146. internal void SetVAC(bool VAC)
  147. {
  148. _isVAC = VAC;
  149. uint data = VAC ? (uint)0b0111111111000001101 : (uint)0b0111111111000001111;
  150. string msg = $"EVT:SIGSTAT/System/{data:X8}/00000000;";
  151. OnWriteMessage(msg);
  152. }
  153. internal void SetAIR(bool AIR)
  154. {
  155. _isAIR = AIR;
  156. uint data = AIR ? (uint)0b0111111111000001011 : (uint)0b0111111111000001111;
  157. string msg = $"EVT:SIGSTAT/System/{data:X8}/00000000;";
  158. OnWriteMessage(msg);
  159. }
  160. private void OnWork(string strACK)
  161. {
  162. // match basic
  163. Match m1 = Regex.Match(strACK, SCMD);
  164. // get mock delay time
  165. string sBasic = m1.Groups[1].Value;
  166. if (string.IsNullOrEmpty(sBasic))
  167. return;
  168. EfemOperation op = EfemConstant.ToOperation(sBasic);
  169. ushort millionSec = this.SimuOperationTime(op);
  170. // delay
  171. //await Task.Delay(millionSec);
  172. Thread.Sleep(millionSec);
  173. // build the INF string
  174. string strINF = string.Empty;
  175. switch (EfemConstant.ToOperation(strACK))
  176. {
  177. case EfemOperation.GetWaferInfo:
  178. strINF = strACK.Replace(ACK, "INF");
  179. strINF = strINF.TrimEnd(';');
  180. string map1 = string.Join("", _slotMap);
  181. strINF += $"/{map1};";
  182. break;
  183. case EfemOperation.Home:
  184. int data1 = 0b011111111010100000;
  185. string s1 = $"EVT:SIGSTAT/LP1/00000000/00000003;\rEVT:SIGSTAT/LP2/0000000/00000003;\rEVT:SIGSTAT/LP3/000000/00000003;\rEVT:SIGSTAT/System/{data1}/00000;\r";
  186. strINF = s1 + strACK.Replace(ACK, "INF");
  187. SendSystemData();
  188. SendLP1Data();
  189. SendLP2Data();
  190. SendLP3Data();
  191. SendAlignData();
  192. OnWriteMessage(strACK.Replace(ACK, "INF"));
  193. return;
  194. case EfemOperation.Map:
  195. if(strACK.Contains("BF"))
  196. {
  197. string map = string.Join("", _slotDummy);
  198. string strEVT = strACK.Replace(ACK,"EVT");
  199. strEVT = strEVT.Replace("WAFSH","MAPDT");
  200. strEVT = strEVT.TrimEnd(';');
  201. string str = $"{strEVT}/{map};";
  202. OnWriteMessage(str);
  203. }
  204. else if (strACK.Contains("LP"))
  205. {
  206. string map = string.Join("", _slotMap);
  207. string strEVT = strACK.Replace(ACK, "EVT");
  208. strEVT = strEVT.Replace("WAFSH", "MAPDT");
  209. strEVT = strEVT.TrimEnd(';');
  210. string str = $"{strEVT}/{map};";
  211. OnWriteMessage(str);
  212. }
  213. strINF = strACK.Replace(ACK, "INF");
  214. break;
  215. case EfemOperation.Load:
  216. strINF = strACK.Replace(ACK, "INF");
  217. break;
  218. case EfemOperation.StateTrack:
  219. strINF = "INF:STATE/TRACK/NONE/NONE;";
  220. break;
  221. case EfemOperation.CarrierId:
  222. break;
  223. case EfemOperation.Size:
  224. break;
  225. case EfemOperation.Dock:
  226. Match mDock = Regex.Match(strACK, SFOUP);
  227. if (mDock.Success)
  228. {
  229. UpdateLocked(mDock.Groups[1].Value, true);
  230. }
  231. strINF = strACK.Replace(ACK, "INF");
  232. break;
  233. case EfemOperation.Undock:
  234. Match mUnDock = Regex.Match(strACK, SFOUP);
  235. if (mUnDock.Success)
  236. {
  237. UpdateLocked(mUnDock.Groups[1].Value, false);
  238. }
  239. strINF = strACK.Replace(ACK, "INF");
  240. break;
  241. case EfemOperation.Clamp:
  242. Match mClamp= Regex.Match(strACK, SFOUP);
  243. if (mClamp.Success)
  244. {
  245. UpdateClamped(mClamp.Groups[1].Value, true);
  246. }
  247. strINF = strACK.Replace(ACK, "INF");
  248. break;
  249. case EfemOperation.Unclamp:
  250. Match mUnClamp = Regex.Match(strACK, SFOUP);
  251. if (mUnClamp.Success)
  252. {
  253. UpdateClamped(mUnClamp.Groups[1].Value, false);
  254. }
  255. strINF = strACK.Replace(ACK, "INF");
  256. break;
  257. case EfemOperation.Speed:
  258. break;
  259. case EfemOperation.Align:
  260. case EfemOperation.Pick:
  261. case EfemOperation.Place:
  262. case EfemOperation.Orgsh:
  263. case EfemOperation.Light:
  264. case EfemOperation.SigStatus:
  265. default:
  266. strINF = strACK.Replace(ACK, "INF");
  267. break;
  268. }
  269. OnWriteMessage(strINF);
  270. }
  271. private void UpdateLocked(string lpNumber,bool locked)
  272. {
  273. if (lpNumber== "1")
  274. {
  275. _isLP1Docked = locked;
  276. SendLP1Data();
  277. }
  278. else if (lpNumber == "2")
  279. {
  280. _isLP2Docked = locked;
  281. SendLP2Data();
  282. }
  283. else if (lpNumber == "3")
  284. {
  285. _isLP3Docked = locked;
  286. SendLP3Data();
  287. }
  288. }
  289. private void UpdateClamped(string lpNumber, bool clamped)
  290. {
  291. if (lpNumber == "1")
  292. {
  293. _isLp1Clamped = clamped;
  294. SendLP1Data();
  295. }
  296. else if (lpNumber == "2")
  297. {
  298. _isLp2Clamped = clamped;
  299. SendLP2Data();
  300. }
  301. else if (lpNumber == "3")
  302. {
  303. _isLp3Clamped = clamped;
  304. SendLP3Data();
  305. }
  306. }
  307. private void SendLP1Data()
  308. {
  309. uint data = GetLP1Data1();
  310. string msg = $"EVT:SIGSTAT/LP1/{data:X8}/0000;";
  311. OnWriteMessage(msg);
  312. }
  313. private void SendLP2Data()
  314. {
  315. uint data = GetLP2Data1();
  316. string msg = $"EVT:SIGSTAT/LP2/{data:X8}/0000;";
  317. OnWriteMessage(msg);
  318. }
  319. private void SendLP3Data()
  320. {
  321. uint data = GetLP3Data1();
  322. string msg = $"EVT:SIGSTAT/LP3/{data:X8}/0000;";
  323. OnWriteMessage(msg);
  324. }
  325. private void SendAlignData()
  326. {
  327. string msg = $"EVT:ALIGN/ALN1/0;";
  328. OnWriteMessage(msg);
  329. }
  330. private void SendDummyMapData(string dummy)
  331. {
  332. string s2 = $"EVT:MAPDT/{dummy}/{_slotDummy};\r";
  333. OnWriteMessage(s2);
  334. }
  335. private void SendSystemData()
  336. {
  337. uint data = 0b0111111111000001111;
  338. string msg = $"EVT:SIGSTAT/System/{data:X8}/00000000;";
  339. OnWriteMessage(msg);
  340. }
  341. private ushort SimuOperationTime(EfemOperation op)
  342. {
  343. ushort sec = 0;
  344. switch (op)
  345. {
  346. case EfemOperation.Map:
  347. case EfemOperation.GetWaferInfo:
  348. case EfemOperation.Align:
  349. sec = 2200;
  350. break;
  351. case EfemOperation.Pick:
  352. case EfemOperation.Place:
  353. case EfemOperation.Orgsh:
  354. sec = 2200;
  355. break;
  356. case EfemOperation.Light:
  357. case EfemOperation.SigStatus:
  358. sec = 0;
  359. break;
  360. default:
  361. sec = 100;
  362. break;
  363. }
  364. return sec;
  365. }
  366. public void PlaceCarrier1()
  367. {
  368. _isLp1Placed = true;
  369. SendLP1Data();
  370. }
  371. public void RemoveCarrier1()
  372. {
  373. _isLp1Placed = false;
  374. SendLP1Data();
  375. }
  376. public void PlaceCarrier2()
  377. {
  378. _isLp2Placed = true;
  379. SendLP2Data();
  380. }
  381. public void RemoveCarrier2()
  382. {
  383. _isLp2Placed = false;
  384. SendLP2Data();
  385. }
  386. public void PlaceCarrier3()
  387. {
  388. _isLp3Placed = true;
  389. SendLP3Data();
  390. }
  391. public void RemoveCarrier3()
  392. {
  393. _isLp3Placed = false;
  394. SendLP3Data();
  395. }
  396. public void ClearWafer()
  397. {
  398. for (int i = 0; i < _slotMap.Length; i++)
  399. {
  400. _slotMap[i] = "0";
  401. }
  402. for (int i = 0; i < _slotDummy.Length; i++)
  403. {
  404. _slotDummy[i] = "0";
  405. }
  406. }
  407. public void SetAllWafer()
  408. {
  409. for (int i = 0; i < _slotMap.Length; i++)
  410. {
  411. _slotMap[i] = "1";
  412. }
  413. }
  414. public void RandomWafer()
  415. {
  416. Random _rd = new Random();
  417. for (int i = 0; i < _slotMap.Length; i++)
  418. {
  419. //_slotMap[i] = (i % 9).ToString();
  420. _slotMap[i]= _rd.Next(0, 10) < 6 ? "0" : "1";
  421. }
  422. }
  423. public void RandomDummyWafer()
  424. {
  425. Random _rdDummy = new Random();
  426. for (int i = 0; i < _slotDummy.Length; i++)
  427. {
  428. _slotDummy[i] = _rdDummy.Next(0, 10) < 6 ? "0" : "1";
  429. }
  430. }
  431. private uint GetLP1Data1()
  432. {
  433. uint data1 = 0x0u;
  434. data1 |= (_isLp1Placed ? 0x00000001u : 0x0);
  435. data1 |= (_isLp1Clamped ? 0x00000002u : 0x0);
  436. data1 |= (_isLP1Docked ? 0x00000004u : 0x0);
  437. data1 |= (_isDoorOpen1 ? 0x00000020u : 0x0);
  438. return data1;
  439. }
  440. private uint GetLP2Data1()
  441. {
  442. uint data1 = 0x0u;
  443. data1 |= (_isLp2Placed ? 0x00000001u : 0x0);
  444. data1 |= (_isLp2Clamped ? 0x00000002u : 0x0);
  445. data1 |= (_isLP2Docked ? 0x00000004u : 0x0);
  446. data1 |= (_isDoorOpen2 ? 0x00000020u : 0x0);
  447. return data1;
  448. }
  449. private uint GetLP3Data1()
  450. {
  451. uint data1 = 0x0u;
  452. data1 |= (_isLp3Placed ? 0x00000001u : 0x0);
  453. data1 |= (_isLp3Clamped ? 0x00000002u : 0x0);
  454. data1 |= (_isLP3Docked ? 0x00000004u : 0x0);
  455. data1 |= (_isDoorOpen3 ? 0x00000020u : 0x0);
  456. return data1;
  457. }
  458. }
  459. }