EfemSimulator.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. using MECF.Framework.Simulator.Core.Driver;
  6. using Aitex.Core.Util;
  7. using Virgo_DCommon;
  8. namespace Virgo_DSimulator.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. public string SlotMap
  20. {
  21. get { return string.Join("", _slotMap); }
  22. }
  23. public EfemSimulatorServer() : base(13000, -1, "\r", ' ')
  24. {
  25. for (int i = 0; i < _slotMap.Length; i++)
  26. _slotMap[i] = "0";
  27. _HwThread = new PeriodicJob(5000, OnSendEvent, "EfemHardware", true);
  28. }
  29. private bool OnSendEvent()
  30. {
  31. if (!_bCommReady)
  32. {
  33. OnWriteMessage("INF:READY/COMM;");
  34. }
  35. return true;
  36. }
  37. protected override void ProcessUnsplitMessage(string str)
  38. {
  39. if (!_bCommReady && str.Contains("ACK:READY/COMM"))
  40. {
  41. _bCommReady = true;
  42. }
  43. if (!Regex.IsMatch(str, CMD_PATTERN))
  44. return;
  45. // 发送ACK 表示收到
  46. string ack = Regex.Replace(str, CMD_PATTERN, ACK);
  47. OnWriteMessage(ack);
  48. // 处理INF
  49. var a = OnWork(ack);
  50. }
  51. private async Task OnWork(string strACK)
  52. {
  53. // match basic
  54. Match m1 = Regex.Match(strACK, SCMD);
  55. // get mock delay time
  56. string sBasic = m1.Groups[1].Value;
  57. EfemOperation op = EfemConstant.ToOperation(sBasic);
  58. ushort sec = this.SimuOperationTime(op);
  59. // Sleep
  60. await Task.Run(() => Thread.Sleep(sec * 1000));
  61. // build the INF string
  62. string strINF = string.Empty;
  63. switch (EfemConstant.ToOperation(sBasic))
  64. {
  65. case EfemOperation.GetWaferInfo:
  66. strINF = strACK.Replace(ACK, "INF");
  67. strINF = strINF.TrimEnd(';');
  68. strINF += "/1111111111111110001111111;";
  69. break;
  70. case EfemOperation.Home:
  71. string s1 = "EVT:SIGSTAT/P1/00000381/00000000;\rEVT:SIGSTAT/P2/00000381/00000000;\rEVT:SIGSTAT/System/00000000/00000000;\r";
  72. strINF = s1 + strACK.Replace(ACK, "INF");
  73. break;
  74. case EfemOperation.Map:
  75. Match m2 = Regex.Match(strACK, SFOUP);
  76. if (m2.Success)
  77. {
  78. string s2 = $"EVT:MAPDT/P{m2.Groups[1].Value}/1111111100000000000000000;\r";
  79. strINF = s2 + strACK.Replace(ACK, "INF");
  80. }
  81. break;
  82. case EfemOperation.Align:
  83. case EfemOperation.Pick:
  84. case EfemOperation.Place:
  85. case EfemOperation.Orgsh:
  86. case EfemOperation.Light:
  87. case EfemOperation.SigStatus:
  88. default:
  89. strINF = strACK.Replace(ACK, "INF");
  90. break;
  91. }
  92. OnWriteMessage(strINF);
  93. }
  94. private ushort SimuOperationTime(EfemOperation op)
  95. {
  96. ushort sec = 0;
  97. switch (op)
  98. {
  99. case EfemOperation.Map:
  100. case EfemOperation.GetWaferInfo:
  101. case EfemOperation.Align:
  102. sec = 3;
  103. break;
  104. case EfemOperation.Pick:
  105. case EfemOperation.Place:
  106. case EfemOperation.Orgsh:
  107. sec = 4;
  108. break;
  109. case EfemOperation.Light:
  110. case EfemOperation.SigStatus:
  111. sec = 2;
  112. break;
  113. default:
  114. sec = 1;
  115. break;
  116. }
  117. return sec;
  118. }
  119. public void PlaceCarrier()
  120. {
  121. string msg = "EVT:SIGSTAT/P1/00000381/00000000;";
  122. OnWriteMessage(msg);
  123. //_state[6] = "1";
  124. }
  125. public void RemoveCarrier()
  126. {
  127. //_state[6] = "0";
  128. string msg = "EVT:SIGSTAT/P1/00000202/00000000;";
  129. OnWriteMessage(msg);
  130. }
  131. public void ClearWafer()
  132. {
  133. for (int i = 0; i < _slotMap.Length; i++)
  134. {
  135. _slotMap[i] = "0";
  136. }
  137. }
  138. public void SetAllWafer()
  139. {
  140. for (int i = 0; i < _slotMap.Length; i++)
  141. {
  142. _slotMap[i] = "1";
  143. }
  144. }
  145. public void SetUpWafer()
  146. {
  147. for (int i = 0; i < _slotMap.Length; i++)
  148. {
  149. _slotMap[i] = i > 15 ? "1" : "0";
  150. }
  151. }
  152. public void SetLowWafer()
  153. {
  154. for (int i = 0; i < _slotMap.Length; i++)
  155. {
  156. _slotMap[i] = i < 10 ? "1" : "0";
  157. }
  158. }
  159. public void RandomWafer()
  160. {
  161. Random _rd = new Random();
  162. for (int i = 0; i < _slotMap.Length; i++)
  163. {
  164. _slotMap[i] = _rd.Next(0, 10) < 6 ? "0" : "1";
  165. }
  166. }
  167. }
  168. }