TCPersistentManager.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using Aitex.Common.Util;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.Util;
  4. using MECF.Framework.Common.Device.ResistivityProbe;
  5. using MECF.Framework.Common.Device.TemperatureController;
  6. using MECF.Framework.Common.Persistent.Dryer;
  7. using MECF.Framework.Common.Persistent.SRD;
  8. using MECF.Framework.Common.ToolLayout;
  9. using MECF.Framework.Common.Utilities;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.IO;
  13. using System.IO.Ports;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. namespace MECF.Framework.Common.Persistent.Temperature
  18. {
  19. public class TCPersistentManager : Singleton<TCPersistentManager>
  20. {
  21. #region 内部变量
  22. private Dictionary<string, TCPersistentValue> _persistentValueDic = new Dictionary<string, TCPersistentValue>();
  23. private Dictionary<string, string> _persistentValuePathDic = new Dictionary<string, string>();
  24. #endregion
  25. /// <summary>
  26. /// 初始化
  27. /// </summary>
  28. public void Initialize()
  29. {
  30. List<string> installedModules = TemperatureItemManager.Instance.InstalledModules;
  31. try
  32. {
  33. string xmlPath = PathManager.GetCfgDir() + "Devices\\SMCCfg.xml";
  34. TemperatureConfig cfg = CustomXmlSerializer.Deserialize<TemperatureConfig>(new FileInfo(xmlPath));
  35. if (cfg != null)
  36. {
  37. foreach (TemperatureDeviceConfig config in cfg.TemperatureDeviceConfigs)
  38. {
  39. if (installedModules!=null&&installedModules.Contains(config.Name))
  40. {
  41. foreach (TemperatureDevice item in config.TemperatureDevices)
  42. {
  43. string module = item.Name;
  44. string foldStr = PathManager.GetCfgDir() + $"Persistent\\TC";
  45. if (!Directory.Exists(foldStr))
  46. {
  47. Directory.CreateDirectory(foldStr);
  48. }
  49. string str = $"{foldStr}\\{module}Persistent.xml";
  50. _persistentValuePathDic[module] = str;
  51. if (File.Exists(str))
  52. {
  53. TCPersistentValue tcPersistentValue = CustomXmlSerializer.Deserialize<TCPersistentValue>(new FileInfo(str));
  54. if (tcPersistentValue != null)
  55. {
  56. _persistentValueDic[module] = tcPersistentValue;
  57. }
  58. }
  59. else
  60. {
  61. TCPersistentValue persistentValue = new TCPersistentValue();
  62. persistentValue.Name = module;
  63. persistentValue.SetPoint = 10;
  64. persistentValue.SetPointLowLimit = 0;
  65. persistentValue.SetPointHighLimit = 50;
  66. _persistentValueDic[module] = persistentValue;
  67. UpdateModulePersistentValue(module);
  68. }
  69. }
  70. }
  71. }
  72. }
  73. }
  74. catch (Exception ex)
  75. {
  76. LOG.WriteLog(eEvent.ERR_TEMPERATURE, "System", "Load TCPersistent xml exception");
  77. }
  78. }
  79. /// <summary>
  80. /// 更新数值
  81. /// </summary>
  82. /// <param name="module"></param>
  83. public void UpdateModulePersistentValue(string module)
  84. {
  85. if (_persistentValueDic.ContainsKey(module))
  86. {
  87. try
  88. {
  89. CustomXmlSerializer.Serialize(_persistentValueDic[module], _persistentValuePathDic[module]);
  90. }
  91. catch (Exception ex)
  92. {
  93. LOG.WriteLog(eEvent.ERR_TEMPERATURE, module, "Save TC Persistent xml file excepetion");
  94. }
  95. }
  96. else
  97. {
  98. LOG.WriteLog(eEvent.ERR_TEMPERATURE, module, "Update TC Persistent xml file excepetion");
  99. }
  100. }
  101. /// <summary>
  102. /// 获取TCPersistent数值
  103. /// </summary>
  104. /// <returns></returns>
  105. public TCPersistentValue GetTCPersistentValue(string module)
  106. {
  107. TCPersistentValue value = new TCPersistentValue();
  108. if (_persistentValueDic.ContainsKey(module) == false)
  109. {
  110. LOG.WriteLog(eEvent.ERR_TEMPERATURE, "System", $"{module} persistentValue is not exist");
  111. }
  112. else
  113. {
  114. value = _persistentValueDic[module];
  115. }
  116. return value;
  117. }
  118. /// <summary>
  119. /// 更新设置值和高\低limit值
  120. /// </summary>
  121. /// <returns></returns>
  122. public void UpdateTemperatureValue(string module, double setPoint, double setPointLowLimit,double setPointHighLimit)
  123. {
  124. _persistentValueDic[module].SetPoint = setPoint;
  125. _persistentValueDic[module].SetPointLowLimit = setPointLowLimit;
  126. _persistentValueDic[module].SetPointHighLimit = setPointHighLimit;
  127. try
  128. {
  129. CustomXmlSerializer.Serialize(_persistentValueDic[module], _persistentValuePathDic[module]);
  130. }
  131. catch (Exception ex)
  132. {
  133. LOG.WriteLog(eEvent.ERR_TEMPERATURE, "System", "Update TCPersistent xml file excepetion");
  134. }
  135. }
  136. }
  137. }