ExtractionMethods.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. using Aitex.Common.Util;
  2. using Aitex.Core.Common.DeviceData;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Device.Unit;
  5. using Aitex.Core.RT.Routine;
  6. using Aitex.Core.RT.SCCore;
  7. using Aitex.Core.Util;
  8. using FurnaceRT.Equipments.PMs.Devices;
  9. using FurnaceRT.Instances;
  10. using HslCommunication.Profinet.Panasonic;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using System.Xml;
  18. using System.Xml.Linq;
  19. namespace FurnaceRT.Extraction
  20. {
  21. /// <summary>
  22. /// RT模块中重复方法抽离
  23. /// </summary>
  24. public class ExtractionMethods
  25. {
  26. public static string systemSCFile = PathManager.GetCfgDir() + $"System.sccfg";
  27. public static Dictionary<string, List<string>> AllNameKeyDict = new Dictionary<string, List<string>>();
  28. public static Dictionary<string, IoValve> RecipeExecIoValve = new Dictionary<string, IoValve>() { };
  29. public static Dictionary<string, IoMFC> RecipeExecIoMFC = new Dictionary<string, IoMFC>() { };
  30. /// <summary>
  31. /// 解析DeviceModelDefine文件 指定类型节点下的ids
  32. /// </summary>
  33. /// <returns></returns>
  34. public static Dictionary<string, List<string>> GetNameKeyDict(List<string> typeNames)
  35. {
  36. Dictionary<string, List<string>> result = new Dictionary<string, List<string>>();
  37. foreach (string name in typeNames)
  38. {
  39. if (result.ContainsKey(name)) continue;
  40. result.Add(name, new List<string>());
  41. }
  42. GetXmlElement($"{SC.GetStringValue("System.SetUp.ToolType")}\\DeviceModelPM", result);
  43. GetXmlElement("DeviceModelHeater", result, true);
  44. GetXmlElement($"{SC.GetStringValue("System.SetUp.ToolType")}\\DeviceModelGasLine", result);
  45. return result;
  46. }
  47. public static void GetXmlElement(string fileName, Dictionary<string, List<string>> result, bool isSystem = false)
  48. {
  49. XmlDocument xmlDoc = new XmlDocument();
  50. var cfDirPath = PathManager.GetCfgDir();
  51. var path = cfDirPath + $"IO\\{fileName}.xml";
  52. if (!File.Exists(path)) return;
  53. xmlDoc.Load(path);
  54. XmlNode node = xmlDoc.SelectSingleNode("DeviceModelDefine");
  55. foreach (XmlNode item in node.ChildNodes)
  56. {
  57. if (item.NodeType != XmlNodeType.Element) continue;
  58. var element = item as XmlElement;
  59. var classType = element.GetAttribute("classType");
  60. if (classType == null) continue;
  61. classType = classType.Split('.').LastOrDefault();
  62. if (!result.Keys.Contains(classType)) continue;
  63. foreach (XmlNode children in item.ChildNodes)
  64. {
  65. if (children is XmlElement childElement)
  66. {
  67. if (result[classType].Contains(childElement.GetAttribute("id"))) continue;
  68. var key = isSystem ? $"System.{childElement.GetAttribute("id")}.DeviceData" : $"PM1.{childElement.GetAttribute("id")}.DeviceData";
  69. result[classType].Add(key);
  70. }
  71. }
  72. }
  73. }
  74. public static void InitRecipeIoValve()
  75. {
  76. XmlDocument xmlDoc = new XmlDocument();
  77. var cfDirPath = PathManager.GetCfgDir();
  78. var path = cfDirPath + $"GasXml\\GasViewXml.xml";
  79. if (!File.Exists(path))
  80. {
  81. return;
  82. }
  83. xmlDoc.Load(path);
  84. XmlNodeList boolConditions = xmlDoc.SelectNodes("//BoolCondition");
  85. if (boolConditions == null)
  86. return;
  87. foreach (XmlNode condition in boolConditions)
  88. {
  89. if (string.IsNullOrEmpty(condition.InnerText) || !condition.InnerText.Contains("Valve") || condition.InnerText.Contains("ILKValue"))
  90. continue;
  91. var cleanedString = new string(condition.InnerText.Where(c => !char.IsWhiteSpace(c)).ToArray());
  92. var valveName = cleanedString.Replace("return", "").Trim().Split('.')[1];
  93. if (RecipeExecIoValve.ContainsKey(valveName))
  94. continue;
  95. IDevice device = DEVICE.GetDevice<IDevice>($"PM1.{valveName}");
  96. if (device == null)
  97. continue;
  98. RecipeExecIoValve.Add(valveName, device as IoValve);
  99. }
  100. }
  101. public static void InitRecipeIoMFC()
  102. {
  103. XmlDocument xmlDoc = new XmlDocument();
  104. var cfDirPath = PathManager.GetCfgDir();
  105. var path = cfDirPath + $"GasXml\\GasViewXml.xml";
  106. if (!File.Exists(path))
  107. {
  108. return;
  109. }
  110. XDocument doc = XDocument.Load(path);
  111. // 查找Analogs节点下的所有Analog节点
  112. var analogs = doc.Descendants("Analog");
  113. foreach (var analog in analogs)
  114. {
  115. // 检查Analog节点的Enable属性是否为True
  116. if (analog.Attribute("Enable")?.Value == "True")
  117. {
  118. var topButton = analog.Element("TopButton");
  119. if (topButton != null)
  120. {
  121. var innerText = topButton.Element("InnerText");
  122. if (innerText != null)
  123. {
  124. string textContent = innerText.Attribute("Text")?.Value;
  125. var mfcName = $"MFC{textContent}";
  126. if (RecipeExecIoMFC.ContainsKey(mfcName))
  127. {
  128. continue;
  129. }
  130. IDevice device = DEVICE.GetDevice<IDevice>($"PM1.{mfcName}");
  131. if (device == null)
  132. continue;
  133. RecipeExecIoMFC.Add(mfcName, device as IoMFC);
  134. }
  135. }
  136. }
  137. }
  138. }
  139. /// <summary>
  140. /// 根据xml配置获取N2PurgeSequenceAction配置
  141. /// </summary>
  142. /// <returns></returns>
  143. public static Dictionary<string, Tuple<R_TRIG, List<Tuple<IDevice, string>>>> GetN2PurgeSequenceAction()
  144. {
  145. Dictionary<string, Tuple<R_TRIG, List<Tuple<IDevice, string>>>> result = new Dictionary<string, Tuple<R_TRIG, List<Tuple<IDevice, string>>>>();
  146. XDocument doc = XDocument.Load(ExtractionMethods.systemSCFile);
  147. var pmNode = doc.Root.Elements("configs")
  148. .Where(x => (string)x.Attribute("name") == "PM1")
  149. .FirstOrDefault();
  150. var nameGroup = pmNode.Elements("configs")
  151. .Where(x => (string)x.Attribute("name") == "N2Purge")
  152. .FirstOrDefault()
  153. .Elements("configs")
  154. .GroupBy(a => (string)a.Attribute("name"));
  155. var pM1N2PurgeNodeChildren = nameGroup.ToDictionary(a => a.Key, a => a.ToList().FirstOrDefault());
  156. foreach (var xmlItem in pM1N2PurgeNodeChildren)
  157. {
  158. var configElements = xmlItem.Value.Elements("config").ToList();
  159. var resultItem = new List<Tuple<IDevice, string>>();
  160. foreach (var valveConfig in configElements)
  161. {
  162. if (valveConfig != null &&
  163. valveConfig.Attribute("name") != null &&
  164. valveConfig.Attribute("default") != null)
  165. {
  166. string name = (string)valveConfig.Attribute("name");
  167. var defaultValue = (string)valveConfig.Attribute("default");
  168. var deviceItem = DEVICE.GetDevice<IDevice>($"PM1.{name}");
  169. if (deviceItem == null)
  170. continue;
  171. var item = Tuple.Create(deviceItem, defaultValue);
  172. resultItem.Add(item);
  173. }
  174. }
  175. result.Add(xmlItem.Key, Tuple.Create(new R_TRIG(), resultItem));
  176. }
  177. return result;
  178. }
  179. }
  180. }