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