EfemSimulator.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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 Venus_Core;
  9. namespace Venus_Simulator.Devices
  10. {
  11. class EfemSimulatorServer : SocketDeviceSimulator
  12. {
  13. private const string CMD_PATTERN = "^MOV|^SET|^GET";
  14. private const string SCMD = @"(?<=\:)(.*?)(?=\/)";
  15. private const string SFOUP = @"(?<=P)(\d{1})(?=[\;\/])";
  16. private const string ACK = "ACK";
  17. private string[] _slotMap = new string[25];
  18. private PeriodicJob _HwThread;
  19. private bool _bCommReady;
  20. private bool _isDoorOpen;
  21. private bool _isPlaced;
  22. public int WaferSize = 3;
  23. public string SlotMap
  24. {
  25. get { return string.Join("", _slotMap); }
  26. }
  27. public bool _isVacuumError { get; set; }
  28. public bool _isAirError { get; set; }
  29. public bool _isFlowError { get; set; }
  30. public bool _isLeak { get; set; }
  31. public bool _isMaintain { get; set; }
  32. public bool _isWaferPresent { get; set; }
  33. public bool _isMaintainDoorOpen { get; private set; }
  34. public bool _isProtrude1 { get; set; }
  35. public bool _isProtrude2 { get; set; }
  36. public bool _isProtrude3 { get; set; }
  37. public EfemSimulatorServer() : base(13001, -1, "\r", ' ')
  38. {
  39. for (int i = 0; i < _slotMap.Length; i++)
  40. _slotMap[i] = "0";
  41. _HwThread = new PeriodicJob(5000, OnSendEvent, "EfemHardware", true);
  42. }
  43. private bool OnSendEvent()
  44. {
  45. if (!_bCommReady)
  46. {
  47. OnWriteMessage("INF:READY/COMM;");
  48. }
  49. return true;
  50. }
  51. protected override void ProcessUnsplitMessage(string str)
  52. {
  53. if (!_bCommReady && str.Contains("ACK:READY/COMM"))
  54. {
  55. _bCommReady = true;
  56. }
  57. if (!Regex.IsMatch(str, CMD_PATTERN))
  58. return;
  59. // 发送ACK 表示收到
  60. string ack = Regex.Replace(str, CMD_PATTERN, ACK);
  61. OnWriteMessage(ack);
  62. // 处理INF
  63. OnWork(ack);
  64. }
  65. internal void SetCassetteDoor(bool doorOpen)
  66. {
  67. if (doorOpen != _isDoorOpen)
  68. {
  69. _isDoorOpen = doorOpen;
  70. SendSystemData();
  71. }
  72. }
  73. internal void SetMaintain(bool maintain)
  74. {
  75. if (maintain != _isMaintain)
  76. {
  77. _isMaintain = maintain;
  78. SendSystemData();
  79. }
  80. }
  81. internal void SetProtrude1(bool protrude)
  82. {
  83. if (protrude != _isProtrude1)
  84. {
  85. _isProtrude1 = protrude;
  86. SendLP1Data();
  87. }
  88. }
  89. internal void SetProtrude2(bool protrude)
  90. {
  91. if (protrude != _isProtrude2)
  92. {
  93. _isProtrude2 = protrude;
  94. SendLP2Data();
  95. }
  96. }
  97. internal void SetProtrude3(bool protrude)
  98. {
  99. if (protrude != _isProtrude3)
  100. {
  101. _isProtrude3 = protrude;
  102. SendLP3Data();
  103. }
  104. }
  105. private void OnWork(string strACK)
  106. {
  107. // match basic
  108. Match m1 = Regex.Match(strACK, SCMD);
  109. // get mock delay time
  110. string sBasic = m1.Groups[1].Value;
  111. if (string.IsNullOrEmpty(sBasic))
  112. return;
  113. EfemOperation op = EfemConstant.ToOperation(sBasic);
  114. ushort millionSec = this.SimuOperationTime(op);
  115. // delay
  116. //await Task.Delay(millionSec);
  117. Thread.Sleep(millionSec);
  118. // build the INF string
  119. string strINF = string.Empty;
  120. switch (EfemConstant.ToOperation(sBasic))
  121. {
  122. case EfemOperation.GetWaferInfo:
  123. strINF = strACK.Replace(ACK, "INF");
  124. strINF = strINF.TrimEnd(';');
  125. strINF += "/1111111111111110001111111;";
  126. break;
  127. case EfemOperation.Home:
  128. string s1 = "EVT:SIGSTAT/P1/00000381/00000000;\rEVT:SIGSTAT/P2/00000381/00000000;\rEVT:SIGSTAT/P3/00000381/00000000;\rEVT:SIGSTAT/System/0000FFF7/00000004;\r";
  129. strINF = s1 + strACK.Replace(ACK, "INF");
  130. SendSystemData();
  131. SendLP1Data();
  132. SendLP2Data();
  133. SendLP3Data();
  134. OnWriteMessage(strACK.Replace(ACK, "INF"));
  135. return;
  136. case EfemOperation.Map:
  137. case EfemOperation.Load:
  138. Match m2 = Regex.Match(strACK, SFOUP);
  139. if (m2.Success)
  140. {
  141. string map = string.Join("", _slotMap);
  142. string s2 = $"EVT:MAPDT/P{m2.Groups[1].Value}/{map};\r";
  143. strINF = s2 + strACK.Replace(ACK, "INF");
  144. }
  145. break;
  146. case EfemOperation.StateTrack:
  147. strINF = "INF:STATE/TRACK/000;";
  148. break;
  149. case EfemOperation.CarrierId:
  150. strINF = strACK.Replace(ACK, "INF");
  151. strINF = strINF.TrimEnd(';');
  152. strINF += $"/{new Random().Next(10000000, 99999999)};";
  153. break;
  154. case EfemOperation.Align:
  155. case EfemOperation.Pick:
  156. case EfemOperation.Place:
  157. case EfemOperation.Orgsh:
  158. case EfemOperation.Light:
  159. case EfemOperation.SigStatus:
  160. default:
  161. strINF = strACK.Replace(ACK, "INF");
  162. break;
  163. }
  164. //EVT: SIGSTAT / SYSTEM / 00007FFF / 08000004;
  165. //OnWriteMessage("EVT:SIGSTAT/SYSTEM/00007FFF/08000004;\r");
  166. //OnWriteMessage("EVT:SIGSTAT/SYSTEM/00007FFF/08000006;\r");
  167. //OnWriteMessage("EVT:SIGSTAT/SYSTEM/00007FFF/08000002;\r");
  168. OnWriteMessage(strINF);
  169. }
  170. private void SendLP1Data()
  171. {
  172. uint data = GetLP1Data1();
  173. string msg = $"EVT:SIGSTAT/P1/{data:X8}/00000000;";
  174. OnWriteMessage(msg);
  175. }
  176. private void SendLP2Data()
  177. {
  178. uint data = GetLP2Data1();
  179. string msg = $"EVT:SIGSTAT/P2/{data:X8}/00000000;";
  180. OnWriteMessage(msg);
  181. }
  182. private void SendLP3Data()
  183. {
  184. uint data = GetLP3Data1();
  185. string msg = $"EVT:SIGSTAT/P3/{data:X8}/00000000;";
  186. OnWriteMessage(msg);
  187. }
  188. private void SendSystemData()
  189. {
  190. uint data = GetSystemData1();
  191. string msg = $"EVT:SIGSTAT/System/{data:X8}/00000000;";
  192. OnWriteMessage(msg);
  193. }
  194. private ushort SimuOperationTime(EfemOperation op)
  195. {
  196. ushort sec = 0;
  197. switch (op)
  198. {
  199. case EfemOperation.Map:
  200. case EfemOperation.GetWaferInfo:
  201. case EfemOperation.Align:
  202. sec = 2500;
  203. break;
  204. case EfemOperation.Pick:
  205. case EfemOperation.Place:
  206. case EfemOperation.Orgsh:
  207. sec = 2500;
  208. break;
  209. case EfemOperation.Light:
  210. case EfemOperation.SigStatus:
  211. sec = 200;
  212. break;
  213. default:
  214. sec = 100;
  215. break;
  216. }
  217. return sec;
  218. }
  219. public void PlaceCarrier1()
  220. {
  221. _isPlaced = true;
  222. SendLP1Data();
  223. }
  224. public void RemoveCarrier1()
  225. {
  226. _isPlaced = false;
  227. SendLP1Data();
  228. }
  229. public void PlaceCarrier2()
  230. {
  231. _isPlaced = true;
  232. SendLP2Data();
  233. }
  234. public void RemoveCarrier2()
  235. {
  236. _isPlaced = false;
  237. SendLP2Data();
  238. }
  239. public void PlaceCarrier3()
  240. {
  241. _isPlaced = true;
  242. SendLP3Data();
  243. }
  244. public void RemoveCarrier3()
  245. {
  246. _isPlaced = false;
  247. SendLP3Data();
  248. }
  249. public void ClearWafer()
  250. {
  251. for (int i = 0; i < _slotMap.Length; i++)
  252. {
  253. _slotMap[i] = "0";
  254. }
  255. }
  256. public void SetAllWafer()
  257. {
  258. for (int i = 0; i < _slotMap.Length; i++)
  259. {
  260. _slotMap[i] = "1";
  261. }
  262. }
  263. public void SetUpWafer()
  264. {
  265. for (int i = 0; i < _slotMap.Length; i++)
  266. {
  267. _slotMap[i] = i > 15 ? "1" : "0";
  268. }
  269. }
  270. public void SetLowWafer()
  271. {
  272. for (int i = 0; i < _slotMap.Length; i++)
  273. {
  274. _slotMap[i] = i < 10 ? "1" : "0";
  275. }
  276. }
  277. public void RandomWafer()
  278. {
  279. Random _rd = new Random();
  280. for (int i = 0; i < _slotMap.Length; i++)
  281. {
  282. //_slotMap[i] = (i % 9).ToString();
  283. _slotMap[i]= _rd.Next(0, 10) < 6 ? "0" : "1";
  284. }
  285. }
  286. private uint GetLP1Data1()
  287. {
  288. uint data1 = 0x0u;
  289. data1 |= (_isPlaced ? 0x00000001u : 0x0);
  290. data1 |= (!_isPlaced ? 0x00000002u : 0x0);
  291. switch (WaferSize)
  292. {
  293. case 3:
  294. //data1 |= 0x00000040u;
  295. data1 |= 0x00000080u;
  296. data1 |= 0x00000100u;
  297. break;
  298. case 4:
  299. data1 |= 0x00000040u;
  300. //data1 |= 0x00000080u;
  301. data1 |= 0x00000100u;
  302. break;
  303. case 6:
  304. data1 |= 0x00000040u;
  305. data1 |= 0x00000080u;
  306. //data1 |= 0x00000100u;
  307. break;
  308. }
  309. data1 |= (!_isProtrude1) ? 0x00000200u : 0x0;
  310. return data1;
  311. }
  312. private uint GetLP2Data1()
  313. {
  314. uint data1 = 0x0u;
  315. data1 |= (_isPlaced ? 0x00000001u : 0x0);
  316. data1 |= (!_isPlaced ? 0x00000002u : 0x0);
  317. switch (WaferSize)
  318. {
  319. case 3:
  320. //data1 |= 0x00000040u;
  321. data1 |= 0x00000080u;
  322. data1 |= 0x00000100u;
  323. break;
  324. case 4:
  325. data1 |= 0x00000040u;
  326. //data1 |= 0x00000080u;
  327. data1 |= 0x00000100u;
  328. break;
  329. case 6:
  330. data1 |= 0x00000040u;
  331. data1 |= 0x00000080u;
  332. //data1 |= 0x00000100u;
  333. break;
  334. }
  335. data1 |= (!_isProtrude2) ? 0x00000200u : 0x0;
  336. return data1;
  337. }
  338. private uint GetLP3Data1()
  339. {
  340. uint data1 = 0x0u;
  341. data1 |= (_isPlaced ? 0x00000001u : 0x0);
  342. data1 |= (!_isPlaced ? 0x00000002u : 0x0);
  343. switch (WaferSize)
  344. {
  345. case 3:
  346. //data1 |= 0x00000040u;
  347. data1 |= 0x00000080u;
  348. data1 |= 0x00000100u;
  349. break;
  350. case 4:
  351. data1 |= 0x00000040u;
  352. //data1 |= 0x00000080u;
  353. data1 |= 0x00000100u;
  354. break;
  355. case 6:
  356. data1 |= 0x00000040u;
  357. data1 |= 0x00000080u;
  358. //data1 |= 0x00000100u;
  359. break;
  360. }
  361. data1 |= (!_isProtrude3) ? 0x00000200u : 0x0;
  362. return data1;
  363. }
  364. private uint GetSystemData1()
  365. {
  366. uint data1 = 0x0u;
  367. //0:
  368. data1 |= (!_isVacuumError ? 0x00000001u : 0x0);
  369. //3:
  370. data1 |= (!_isAirError ? 0x00000004u : 0x0);
  371. //4 Flow gauge Sensor Warning
  372. data1 |= (_isFlowError ? 0x00000010u : 0x0);
  373. //5 Leakage Sensor Warning
  374. data1 |= (_isLeak ? 0x00000020u : 0x0);
  375. //6:Door switch Door close
  376. data1 |= (!_isMaintainDoorOpen ? 0x00000040u : 0x0);
  377. //7 Drive power Normal
  378. data1 |= 0x00000080u;
  379. //8 Differential pressure sensor setting 1 Normal
  380. data1 |= 0x00000100u;
  381. //9 Differential pressure sensor setting 1 Normal
  382. data1 |= 0x00000200u;
  383. //10 Ionizer alarm Normal
  384. data1 |= 0x00000400u;
  385. //11 FFU alarm Normal
  386. data1 |= 0x00000800u;
  387. //12 Area sensor(Reserved) Not blocked
  388. data1 |= 0x00001000u;
  389. //13 Mode switch RUN
  390. data1 |= (!_isMaintain ? 0x00002000u : 0x0);
  391. //14 Robot Wafer Present No presence
  392. data1 |= (!_isWaferPresent ? 0x00004000u : 0x0);
  393. //15 Cassette Door Door Closed
  394. data1 |= (!_isDoorOpen ? 0x00008000u : 0x0);
  395. return 65535;
  396. }
  397. }
  398. }