EfemSimulator.cs 13 KB

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