Recipe.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Xml;
  6. using Aitex.Core.RT.Log;
  7. using Aitex.Common.Util;
  8. namespace Aitex.Triton160.RT.Routine.Process
  9. {
  10. /// <summary>
  11. /// Recipe head
  12. /// </summary>
  13. public class RecipeHead
  14. {
  15. public string RecipeVariation { get; set; }
  16. public string CreationTime { get; set; }
  17. public string LastRevisionTime { get; set; }
  18. public string CreatedBy { get; set; }
  19. public string LastModifiedBy { get; set; }
  20. public string PressureMode { get; set; }
  21. public string Description { get; set; }
  22. public string Barcode { get; set; }
  23. public string BasePressure
  24. {
  25. get;
  26. set;
  27. }
  28. public string PumpDownLimit
  29. {
  30. get;
  31. set;
  32. }
  33. public string ElectrodeTemp
  34. {
  35. get;
  36. set;
  37. }
  38. public string PurgeActive
  39. {
  40. get;
  41. set;
  42. }
  43. public string MatchPositionC1
  44. {
  45. get;
  46. set;
  47. }
  48. public string MatchPositionC2
  49. {
  50. get;
  51. set;
  52. }
  53. }
  54. public class RecipeStep
  55. {
  56. public string StepName;
  57. public double StepTime;
  58. public bool IsJumpStep;
  59. public bool IsLoopStartStep;
  60. public bool IsLoopEndStep;
  61. public int LoopCount;
  62. public string EndBy;
  63. //public double EndByValue;
  64. public Dictionary<string, string> RecipeCommands = new Dictionary<string, string>();
  65. }
  66. public class Recipe
  67. {
  68. /// <summary>
  69. /// 当前Recipe Run 记录对应的Guid
  70. /// 每个Recipe Run 都对应有一个唯一的Guid
  71. /// </summary>
  72. public static Guid CurrentRecipeRunGuid;
  73. /// <summary>
  74. /// 解析工艺程序文件
  75. /// </summary>
  76. /// <param name="recipeName">工艺程序名</param>
  77. /// <param name="xmlRecipeData">xml格式的工艺数据内容</param>
  78. /// <param name="recipeData">返回解析的工艺数据变量</param>
  79. /// <returns>True:解析成功 | False:解析失败</returns>
  80. public static bool Parse(string recipe, out RecipeHead recipeHead, out List<RecipeStep> recipeData)
  81. {
  82. recipeHead = new RecipeHead();
  83. recipeData = new List<RecipeStep>();
  84. try
  85. {
  86. //获取工艺程序文件中允许的命令字符串列表
  87. //目的:如果工艺程序文件中含有规定之外的命令,则被禁止执行
  88. HashSet<string> recipeAllowedCommands = new HashSet<string>();
  89. XmlDocument rcpFormatDoc = new XmlDocument();
  90. string recipeSchema = PathManager.GetCfgDir() + "RecipeFormat.xml";
  91. rcpFormatDoc.Load(recipeSchema);
  92. XmlNodeList rcpItemNodeList = rcpFormatDoc.SelectNodes("/Aitex/TableRecipeFormat/Catalog/Group/Step");
  93. foreach (XmlElement item in rcpItemNodeList)
  94. recipeAllowedCommands.Add(item.Attributes["ControlName"].Value);
  95. //获取工艺程序文件中所有步的内容
  96. XmlDocument rcpDataDoc = new XmlDocument();
  97. rcpDataDoc.LoadXml(recipe);
  98. recipeHead.PressureMode = rcpDataDoc.DocumentElement.HasAttribute("PressureMode") ? rcpDataDoc.DocumentElement.Attributes["PressureMode"].Value : "";
  99. recipeHead.BasePressure = rcpDataDoc.DocumentElement.HasAttribute("BasePressure") ? rcpDataDoc.DocumentElement.Attributes["BasePressure"].Value : "";
  100. recipeHead.PumpDownLimit = rcpDataDoc.DocumentElement.HasAttribute("PumpDownLimit") ? rcpDataDoc.DocumentElement.Attributes["PumpDownLimit"].Value : "";
  101. recipeHead.ElectrodeTemp = rcpDataDoc.DocumentElement.HasAttribute("ElectrodeTemp") ? rcpDataDoc.DocumentElement.Attributes["ElectrodeTemp"].Value : "";
  102. recipeHead.PurgeActive = rcpDataDoc.DocumentElement.HasAttribute("PurgeActive") ? rcpDataDoc.DocumentElement.Attributes["PurgeActive"].Value : "";
  103. recipeHead.MatchPositionC1 = rcpDataDoc.DocumentElement.HasAttribute("MatchPositionC1") ? rcpDataDoc.DocumentElement.Attributes["MatchPositionC1"].Value : "";
  104. recipeHead.MatchPositionC2 = rcpDataDoc.DocumentElement.HasAttribute("MatchPositionC2") ? rcpDataDoc.DocumentElement.Attributes["MatchPositionC2"].Value : "";
  105. recipeHead.Barcode = rcpDataDoc.DocumentElement.HasAttribute("Barcode") ? rcpDataDoc.DocumentElement.Attributes["Barcode"].Value : "";
  106. XmlNodeList stepNodeList = rcpDataDoc.SelectNodes("/TableRecipeData/Step");
  107. for (int i = 0; i < stepNodeList.Count; i++)
  108. {
  109. var recipeStep = new RecipeStep();
  110. recipeData.Add(recipeStep);
  111. XmlElement stepNode = stepNodeList[i] as XmlElement;
  112. Dictionary<string, string> dic = new Dictionary<string, string>();
  113. //遍历Step节点
  114. foreach (XmlAttribute att in stepNode.Attributes)
  115. {
  116. if (recipeAllowedCommands.Contains(att.Name))
  117. {
  118. dic.Add(att.Name, att.Value);
  119. }
  120. }
  121. //遍历Step子节点中所有的attribute属性节点
  122. foreach (XmlElement subStepNode in stepNode.ChildNodes)
  123. {
  124. foreach (XmlAttribute att in subStepNode.Attributes)
  125. {
  126. if (recipeAllowedCommands.Contains(att.Name))
  127. {
  128. dic.Add(att.Name, att.Value);
  129. }
  130. }
  131. //遍历Step子节点的子节点中所有的attribute属性节点
  132. foreach (XmlElement subsubStepNode in subStepNode.ChildNodes)
  133. {
  134. foreach (XmlAttribute att in subsubStepNode.Attributes)
  135. {
  136. if (recipeAllowedCommands.Contains(att.Name))
  137. {
  138. dic.Add(att.Name, att.Value);
  139. }
  140. }
  141. }
  142. }
  143. recipeStep.IsJumpStep = true;//!Convert.ToBoolean(dic["Ramp"]);
  144. recipeStep.StepName = dic["Name"];
  145. recipeStep.StepTime = TimeSpan.Parse(dic["Time"]).TotalSeconds;
  146. string loopStr = dic["Loop"];
  147. recipeStep.IsLoopStartStep = System.Text.RegularExpressions.Regex.Match(loopStr, @"Loop\x20\d+\s*$").Success;
  148. recipeStep.IsLoopEndStep = System.Text.RegularExpressions.Regex.Match(loopStr, @"Loop End$").Success;
  149. if (recipeStep.IsLoopStartStep)
  150. recipeStep.LoopCount = Convert.ToInt32(loopStr.Replace("Loop", string.Empty));
  151. else
  152. recipeStep.LoopCount = 0;
  153. //recipeStep.EndByValue = Convert.ToDouble(dic["EndValue"]);
  154. recipeStep.EndBy = dic["EndBy"];
  155. if (recipeStep.EndBy == "EndByRfTime")
  156. {
  157. recipeStep.StepTime = TimeSpan.Parse(dic["Rf.SetPowerOnTime"]).TotalSeconds;
  158. if (recipeStep.StepTime <= 0)
  159. {
  160. LOG.Error("recipe 没有定义RF Power on的时间");
  161. return false;
  162. }
  163. }
  164. int rfPower = (int)Convert.ToDouble(dic["Rf.SetPower"]);
  165. dic.Add("Rf.SetPowerOnOff", rfPower >0 ? "true" : "false");
  166. //dic.Remove("Ramp");
  167. dic.Remove("StepNo");
  168. dic.Remove("Name");
  169. dic.Remove("Loop");
  170. dic.Remove("Time");
  171. dic.Remove("EndBy");
  172. //dic.Remove("EndValue");
  173. dic.Remove("Rf.SetPowerOnTime");
  174. foreach (string key in dic.Keys)
  175. recipeStep.RecipeCommands.Add(key, dic[key]);
  176. }
  177. }
  178. catch (Exception ex)
  179. {
  180. LOG.Write(ex);
  181. return false;
  182. }
  183. return true;
  184. }
  185. }
  186. }