EfemSimulator.cs 11 KB

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