Recipe.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Xml;
  4. using Aitex.Common.Util;
  5. using Aitex.Core.RT.Event;
  6. using Aitex.Core.RT.Log;
  7. using Aitex.Core.RT.SCCore;
  8. using EPInterface.Datas;
  9. namespace VirgoRT.Modules
  10. {
  11. /// <summary>
  12. /// Recipe head
  13. /// </summary>
  14. public class RecipeHead
  15. {
  16. public string RecipeVariation { get; set; }
  17. public string CreationTime { get; set; }
  18. public string LastRevisionTime { get; set; }
  19. public string CreatedBy { get; set; }
  20. public string LastModifiedBy { get; set; }
  21. public string PressureMode { get; set; }
  22. public string Description { get; set; }
  23. public string Barcode { get; set; }
  24. public string BasePressure { get; set; }
  25. public string PumpDownLimit { get; set; }
  26. //public string ElectrodeTemp { get; set; }
  27. //public string HeaterTemp { get; set; }
  28. public string PurgeActive { get; set; }
  29. public string MatchPositionC1 { get; set; }
  30. public string MatchPositionC2 { get; set; }
  31. public string SubstrateTemp { get; set; }
  32. public string PumpingPinState { get; set; }
  33. public string NotToPurgeOrVent { get; set; } //For keep vacuum after idle clean
  34. public string VentingPinState { get; set; }
  35. public string PinDownPressure { get; set; }
  36. }
  37. public class RecipeStep
  38. {
  39. public string StepName;
  40. public double StepTime;
  41. public bool IsJumpStep;
  42. public bool IsLoopStartStep;
  43. public bool IsLoopEndStep;
  44. public int LoopCount;
  45. public string EndBy;
  46. public string EndPointConfig;
  47. public bool FaultIfNoEPDTrigger;
  48. //public double EndByValue;
  49. public Dictionary<string, string> RecipeCommands = new Dictionary<string, string>();
  50. }
  51. public class Recipe
  52. {
  53. /// <summary>
  54. /// 当前Recipe Run 记录对应的Guid
  55. /// 每个Recipe Run 都对应有一个唯一的Guid
  56. /// </summary>
  57. public static Guid CurrentRecipeRunGuid;
  58. /// <summary>
  59. /// 解析工艺程序文件
  60. /// </summary>
  61. /// <param name="recipeName">工艺程序名</param>
  62. /// <param name="xmlRecipeData">xml格式的工艺数据内容</param>
  63. /// <param name="recipeData">返回解析的工艺数据变量</param>
  64. /// <returns>True:解析成功 | False:解析失败</returns>
  65. public static bool Parse(string chamberId, string recipe, out RecipeHead recipeHead, out List<RecipeStep> recipeData)
  66. {
  67. recipeHead = new RecipeHead();
  68. recipeData = new List<RecipeStep>();
  69. try
  70. {
  71. //获取工艺程序文件中允许的命令字符串列表
  72. //目的:如果工艺程序文件中含有规定之外的命令,则被禁止执行
  73. HashSet<string> recipeAllowedCommands = new HashSet<string>();
  74. XmlDocument rcpFormatDoc = new XmlDocument();
  75. string recipeSchema = PathManager.GetCfgDir() + "RecipeFormat.xml";
  76. rcpFormatDoc.Load(recipeSchema);
  77. XmlNodeList rcpItemNodeList = rcpFormatDoc.SelectNodes("/Aitex/TableRecipeFormat/Catalog/Group/Step");
  78. foreach (XmlElement item in rcpItemNodeList)
  79. recipeAllowedCommands.Add(item.Attributes["ControlName"].Value);
  80. //获取工艺程序文件中所有步的内容
  81. XmlDocument rcpDataDoc = new XmlDocument();
  82. rcpDataDoc.LoadXml(recipe);
  83. recipeHead.PressureMode = rcpDataDoc.DocumentElement.HasAttribute("PressureMode") ? rcpDataDoc.DocumentElement.Attributes["PressureMode"].Value : "";
  84. recipeHead.BasePressure = rcpDataDoc.DocumentElement.HasAttribute("BasePressure") ? rcpDataDoc.DocumentElement.Attributes["BasePressure"].Value : "";
  85. recipeHead.PumpDownLimit = rcpDataDoc.DocumentElement.HasAttribute("PumpDownLimit") ? rcpDataDoc.DocumentElement.Attributes["PumpDownLimit"].Value : "";
  86. recipeHead.PurgeActive = rcpDataDoc.DocumentElement.HasAttribute("PurgeActive") ? rcpDataDoc.DocumentElement.Attributes["PurgeActive"].Value : "";
  87. recipeHead.MatchPositionC1 = rcpDataDoc.DocumentElement.HasAttribute("MatchPositionC1") ? rcpDataDoc.DocumentElement.Attributes["MatchPositionC1"].Value : "";
  88. recipeHead.MatchPositionC2 = rcpDataDoc.DocumentElement.HasAttribute("MatchPositionC2") ? rcpDataDoc.DocumentElement.Attributes["MatchPositionC2"].Value : "";
  89. recipeHead.Barcode = rcpDataDoc.DocumentElement.HasAttribute("Barcode") ? rcpDataDoc.DocumentElement.Attributes["Barcode"].Value : "";
  90. recipeHead.SubstrateTemp = rcpDataDoc.DocumentElement.HasAttribute("SubstrateTemp") ? rcpDataDoc.DocumentElement.Attributes["SubstrateTemp"].Value : "";
  91. recipeHead.PumpingPinState = rcpDataDoc.DocumentElement.HasAttribute("PumpingPinState") ? rcpDataDoc.DocumentElement.Attributes["PumpingPinState"].Value : "Down";
  92. //For keep vacuum after idle clean
  93. recipeHead.NotToPurgeOrVent = rcpDataDoc.DocumentElement.HasAttribute("NotToPurgeOrVent") ? rcpDataDoc.DocumentElement.Attributes["NotToPurgeOrVent"].Value : "";
  94. recipeHead.VentingPinState = rcpDataDoc.DocumentElement.HasAttribute("VentingPinState") ? rcpDataDoc.DocumentElement.Attributes["VentingPinState"].Value : "Down";
  95. recipeHead.PinDownPressure = rcpDataDoc.DocumentElement.HasAttribute("PinDownPressure") ? rcpDataDoc.DocumentElement.Attributes["PinDownPressure"].Value : "1000";
  96. XmlNodeList stepNodeList = rcpDataDoc.SelectNodes("/TableRecipeData/Step");
  97. for (int i = 0; i < stepNodeList.Count; i++)
  98. {
  99. var recipeStep = new RecipeStep();
  100. recipeData.Add(recipeStep);
  101. XmlElement stepNode = stepNodeList[i] as XmlElement;
  102. Dictionary<string, string> dic = new Dictionary<string, string>();
  103. //遍历Step节点
  104. foreach (XmlAttribute att in stepNode.Attributes)
  105. {
  106. if (recipeAllowedCommands.Contains(att.Name))
  107. {
  108. dic.Add(att.Name, att.Value);
  109. }
  110. }
  111. //遍历Step子节点中所有的attribute属性节点
  112. foreach (XmlElement subStepNode in stepNode.ChildNodes)
  113. {
  114. foreach (XmlAttribute att in subStepNode.Attributes)
  115. {
  116. if (recipeAllowedCommands.Contains(att.Name))
  117. {
  118. dic.Add(att.Name, att.Value);
  119. }
  120. }
  121. //遍历Step子节点的子节点中所有的attribute属性节点
  122. foreach (XmlElement subsubStepNode in subStepNode.ChildNodes)
  123. {
  124. foreach (XmlAttribute att in subsubStepNode.Attributes)
  125. {
  126. if (recipeAllowedCommands.Contains(att.Name))
  127. {
  128. dic.Add(att.Name, att.Value);
  129. }
  130. }
  131. }
  132. }
  133. recipeStep.IsJumpStep = true;//!Convert.ToBoolean(dic["Ramp"]);
  134. recipeStep.StepName = dic["Name"];
  135. recipeStep.StepTime = double.Parse(dic["Time"]);
  136. string loopStr = dic["Loop"];
  137. recipeStep.IsLoopStartStep = System.Text.RegularExpressions.Regex.Match(loopStr, @"Loop\x20\d+\s*$").Success;
  138. recipeStep.IsLoopEndStep = System.Text.RegularExpressions.Regex.Match(loopStr, @"Loop End$").Success;
  139. if (recipeStep.IsLoopStartStep)
  140. recipeStep.LoopCount = Convert.ToInt32(loopStr.Replace("Loop", string.Empty));
  141. else
  142. recipeStep.LoopCount = 0;
  143. //recipeStep.EndByValue = Convert.ToDouble(dic["EndValue"]);
  144. recipeStep.EndBy = dic["EndBy"];
  145. if (recipeStep.EndBy == "EndByRfTime")
  146. {
  147. recipeStep.StepTime = double.Parse(dic["Rf.SetPowerOnTime"]);
  148. if (recipeStep.StepTime <= 0)
  149. {
  150. LOG.Error("recipe 没有定义RF Power on的时间");
  151. return false;
  152. }
  153. }
  154. int rfPower = (int)Convert.ToDouble(dic["Rf.SetPower"]);
  155. dic.Add("Rf.SetPowerOnOff", rfPower > 0 ? "true" : "false");
  156. if (SC.GetValue<bool>($"{chamberId}.BiasRf.EnableBiasRF"))
  157. {
  158. int rfPowerBias = (int)Convert.ToDouble(dic["BiasRf.SetPower"]);
  159. dic.Add("BiasRf.SetPowerOnOff", rfPowerBias > 0 ? "true" : "false");
  160. }
  161. else
  162. {
  163. dic.Remove("BiasRf.SetPower");
  164. dic.Remove("BiasRf.SetMatchProcessMode");
  165. dic.Remove("BiasRf.SetMatchPositionC1");
  166. dic.Remove("BiasRf.SetMatchPositionC2");
  167. }
  168. bool epdInstalled = SC.ContainsItem("System.SetUp.EPDInstalled") && SC.GetValue<bool>($"System.SetUp.EPDInstalled");
  169. if (!epdInstalled)
  170. {
  171. if (dic.ContainsKey("EPD.SetConfig"))
  172. dic.Remove("EPD.SetConfig");
  173. }
  174. else
  175. {
  176. recipeStep.EndPointConfig = dic.ContainsKey("EPD.SetConfig") ? dic["EPD.SetConfig"] : null;
  177. if (string.IsNullOrEmpty(recipeStep.EndPointConfig))
  178. {
  179. if (recipeStep.EndBy == "EndByEndPoint")
  180. {
  181. EV.PostWarningLog("System", "EndPoint is empty");
  182. return false;
  183. }
  184. recipeStep.EndPointConfig = SC.GetStringValue("System.EndPoint.EndPointDefaultValue");
  185. }
  186. else
  187. {
  188. if (!ParseEPD(recipeStep.EndPointConfig, out EPDConfig config))
  189. {
  190. EV.PostWarningLog("System", "EndPoint config is not valid");
  191. return false;
  192. }
  193. recipeStep.FaultIfNoEPDTrigger = config.FaultIfNoEPDTrigger;
  194. }
  195. }
  196. //dic.Remove("Ramp");
  197. dic.Remove("StepNo");
  198. dic.Remove("Name");
  199. dic.Remove("Loop");
  200. dic.Remove("Time");
  201. dic.Remove("EndBy");
  202. //dic.Remove("EndValue");
  203. dic.Remove("Rf.SetPowerOnTime");
  204. foreach (string key in dic.Keys)
  205. recipeStep.RecipeCommands.Add(key, dic[key]);
  206. }
  207. }
  208. catch (Exception ex)
  209. {
  210. LOG.Write(ex);
  211. return false;
  212. }
  213. return true;
  214. }
  215. private static bool ParseEPD(string config, out EPDConfig epdConfig)
  216. {
  217. epdConfig = new EPDConfig();
  218. try
  219. {
  220. epdConfig.nParameterCount = 1;
  221. string[] items = config.Split(';');
  222. foreach (var item in items)
  223. {
  224. if (string.IsNullOrEmpty(item))
  225. continue;
  226. string[] pairs = item.Split('=');
  227. if (pairs.Length != 2)
  228. continue;
  229. switch (pairs[0])
  230. {
  231. case "ExposureTime":
  232. epdConfig.Columns[0].nCCDExposureTime = int.Parse(pairs[1]);
  233. break;
  234. case "WaveLengthA":
  235. epdConfig.Columns[0].nWaveLength[0] = ushort.Parse(pairs[1]);
  236. break;
  237. case "BinningA":
  238. epdConfig.Columns[0].nBinning[0] = ushort.Parse(pairs[1]);
  239. break;
  240. case "WaveLengthB":
  241. epdConfig.Columns[0].nWaveLength[1] = ushort.Parse(pairs[1]);
  242. break;
  243. case "BinningB":
  244. epdConfig.Columns[0].nBinning[1] = ushort.Parse(pairs[1]);
  245. break;
  246. case "WaveLengthC":
  247. epdConfig.Columns[0].nWaveLength[2] = ushort.Parse(pairs[1]);
  248. break;
  249. case "BinningC":
  250. epdConfig.Columns[0].nBinning[2] = ushort.Parse(pairs[1]);
  251. break;
  252. case "WaveLengthD":
  253. epdConfig.Columns[0].nWaveLength[3] = ushort.Parse(pairs[1]);
  254. break;
  255. case "BinningD":
  256. epdConfig.Columns[0].nBinning[3] = ushort.Parse(pairs[1]);
  257. break;
  258. case "Fd":
  259. epdConfig.Columns[0].cFunc = pairs[1];
  260. break;
  261. case "PrefilterTime":
  262. epdConfig.Columns[0].nPreFilterTime = int.Parse(pairs[1]);
  263. break;
  264. case "PostfilterTime":
  265. epdConfig.Columns[0].nPostFilterTime = int.Parse(pairs[1]);
  266. break;
  267. case "AlgorithmType":
  268. epdConfig.Columns[0].algorithmType = MapType(pairs[1]);
  269. break;
  270. case "Criteria":
  271. epdConfig.Columns[0].nCriteria = float.Parse(pairs[1]);
  272. break;
  273. case "DelayTime":
  274. epdConfig.Columns[0].nDelayTime = int.Parse(pairs[1]);
  275. break;
  276. case "ValidationTime":
  277. epdConfig.Columns[0].nValidationTime = int.Parse(pairs[1]);
  278. break;
  279. case "ValidationValue":
  280. epdConfig.Columns[0].nValidationValue = int.Parse(pairs[1]);
  281. break;
  282. case "TimeWindow":
  283. epdConfig.Columns[0].nTimeWindow = int.Parse(pairs[1]);
  284. break;
  285. case "MinimalTime":
  286. epdConfig.Columns[0].nMinimalTime = int.Parse(pairs[1]);
  287. break;
  288. case "PostponeTime":
  289. epdConfig.Columns[0].nPostponeTime = int.Parse(pairs[1]);
  290. break;
  291. case "Control":
  292. epdConfig.Columns[0].bControl = Convert.ToBoolean(pairs[1]);
  293. break;
  294. case "Normalization":
  295. epdConfig.Columns[0].bNormalization = Convert.ToBoolean(pairs[1]);
  296. break;
  297. case "EnablePostponePercent":
  298. epdConfig.Columns[0].bPostponePercent = Convert.ToBoolean(pairs[1]);
  299. break;
  300. case "EnableCriterialPercent":
  301. epdConfig.Columns[0].bCriteriaPercent = Convert.ToBoolean(pairs[1]);
  302. break;
  303. case "EnableEventTrigger":
  304. epdConfig.Columns[0].bEvtTrigger = Convert.ToBoolean(pairs[1]);
  305. break;
  306. case "IsFaultIfNoTrigger":
  307. epdConfig.FaultIfNoEPDTrigger = Convert.ToBoolean(pairs[1]);
  308. break;
  309. }
  310. }
  311. return true;
  312. }
  313. catch (Exception ex)
  314. {
  315. LOG.Write(ex);
  316. EV.PostMessage("System", EventEnum.DefaultAlarm, "EPD config input not valid, ", ex.Message);
  317. return false;
  318. }
  319. }
  320. private static AlgorithmType MapType(string type)
  321. {
  322. switch (type)
  323. {
  324. case "Unknown": return AlgorithmType.ALG_NONE;
  325. case "Above_ABS_Value": return AlgorithmType.ALG_RISE_VALUE;
  326. case "Below_ABS_Value": return AlgorithmType.ALG_FALL_VALUE;
  327. case "Drop_Percent": return AlgorithmType.ALG_FALL_PERCENT;
  328. case "Up_Percent": return AlgorithmType.ALG_RISE_PERCENT;
  329. case "Range_In": return AlgorithmType.ALG_RANGE_IN;
  330. case "Gradient": return AlgorithmType.ALG_GRADIENT;
  331. case "Peek": return AlgorithmType.ALG_PEAK;
  332. case "Valley": return AlgorithmType.ALG_VALLEY;
  333. case "Min_Drop_Percent": return AlgorithmType.ALG_MIN_FALL_PERCENT;
  334. case "Min_Up_Percent": return AlgorithmType.ALG_MIN_RISE_PERCENT;
  335. case "Max_Drop_Percent": return AlgorithmType.ALG_MAX_FALL_PERCENT;
  336. case "Max_Up_Percent": return AlgorithmType.ALG_MAX_RISE_PERCENT;
  337. case "Rise_Fall": return AlgorithmType.ALG_RISE_FALL;
  338. case "Fall_Rise": return AlgorithmType.ALG_FALL_RISE;
  339. }
  340. return AlgorithmType.ALG_NONE;
  341. }
  342. }
  343. }