TotalReservoirDevice.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.OperationCenter;
  3. using Aitex.Core.Util;
  4. using MECF.Framework.Common.CommonData;
  5. using MECF.Framework.Common.Device.PowerSupplier;
  6. using MECF.Framework.Common.Device.Rinse;
  7. using MECF.Framework.Common.TwinCat;
  8. using CyberX8_RT.Devices.Metal;
  9. using CyberX8_RT.Devices.PowerSupplier;
  10. using CyberX8_RT.Devices.PUF;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Diagnostics.PerformanceData;
  14. using System.Linq;
  15. using System.Reflection;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. using MECF.Framework.Common.ToolLayout;
  19. using CyberX8_RT.Modules.Reservoir;
  20. using CyberX8_RT.Modules;
  21. using MECF.Framework.Common.IOCore;
  22. namespace CyberX8_RT.Devices.Reservoir
  23. {
  24. public class TotalReservoirDevice : BaseDevice, IDevice
  25. {
  26. #region 常量
  27. private const string DIREPLEN_FLOW = "DiReplenFlow";
  28. private const string COUNTER_VALUE = "CounterValue";
  29. private const string COUNTER_START = "Start";
  30. private const string COUNTER_STOP = "Stop";
  31. private const string COUNTER_RESET = "Reset";
  32. private const string EVAPORATOR_LEVEL = "EvaporatorLevel";
  33. private const string HIGH_LEVEL="HighLevel";
  34. private const string STRATUS = "Stratus";
  35. #endregion
  36. #region 内部变量
  37. /// <summary>
  38. /// Di Replen Flow
  39. /// </summary>
  40. private CounterFlowData _diReplenFlow = new CounterFlowData();
  41. /// <summary>
  42. /// High Level
  43. /// </summary>
  44. private bool _highLevel;
  45. /// <summary>
  46. /// Evaporator Level
  47. /// </summary>
  48. private bool _evaporatorLevel;
  49. /// <summary>
  50. /// Counter字典
  51. /// </summary>
  52. private Dictionary<string, CounterFlowData> _nameCounterFlowData = new Dictionary<string, CounterFlowData>();
  53. /// <summary>
  54. /// 定时器
  55. /// </summary>
  56. private PeriodicJob _period;
  57. #endregion
  58. #region 属性
  59. /// <summary>
  60. /// Di Replen Flow
  61. /// </summary>
  62. private CounterFlowData DiReplenFlow { get { return _diReplenFlow; } }
  63. /// <summary>
  64. /// High Level
  65. /// </summary>
  66. public bool HighLevel { get { return _highLevel; } }
  67. /// <summary>
  68. /// Evaporator Level
  69. /// </summary>
  70. public bool EvaporatorLevel { get { return _evaporatorLevel; } }
  71. #endregion
  72. /// <summary>
  73. /// 构造函数
  74. /// </summary>
  75. /// <param name="moduleName"></param>
  76. /// <param name="name"></param>
  77. public TotalReservoirDevice() : base("Reservoir", "Reservoir", "Reservoir", "Reservoir")
  78. {
  79. _period = new PeriodicJob(500, OnTimer, "Reservoir.OnTimer", true, true);
  80. }
  81. /// <summary>
  82. /// 初始化
  83. /// </summary>
  84. /// <returns></returns>
  85. public bool Initialize()
  86. {
  87. InitializeParameter();
  88. SubscribeValueAction();
  89. InitializeOperation();
  90. return true;
  91. }
  92. /// <summary>
  93. /// 加载参数
  94. /// </summary>
  95. private void InitializeParameter()
  96. {
  97. }
  98. /// <summary>
  99. /// 初始化操作
  100. /// </summary>
  101. private void InitializeOperation()
  102. {
  103. }
  104. /// <summary>
  105. /// 订阅变量数值发生变化
  106. /// </summary>
  107. private void SubscribeValueAction()
  108. {
  109. BeckhoffCounterSubscribeUpdateVariable(DIREPLEN_FLOW,DiReplenFlow);
  110. BeckhoffIoSubscribeUpdateVariable(EVAPORATOR_LEVEL);
  111. BeckhoffIoSubscribeUpdateVariable(HIGH_LEVEL);
  112. }
  113. /// <summary>
  114. /// 订阅Counter变量
  115. /// </summary>
  116. /// <param name="variable"></param>
  117. private void BeckhoffCounterSubscribeUpdateVariable(string variable, CounterFlowData counterFlowData)
  118. {
  119. _nameCounterFlowData[$"{Module}.{variable}"] = counterFlowData;
  120. BeckhoffCounterManager.Instance.SubscribeModuleVariable($"{Module}.{variable}", COUNTER_VALUE, UpdateCounterVariableValue);
  121. BeckhoffCounterManager.Instance.SubscribeModuleVariable($"{Module}.{variable}", COUNTER_START, UpdateCounterVariableValue);
  122. BeckhoffCounterManager.Instance.SubscribeModuleVariable($"{Module}.{variable}", COUNTER_STOP, UpdateCounterVariableValue);
  123. BeckhoffCounterManager.Instance.SubscribeModuleVariable($"{Module}.{variable}", COUNTER_RESET, UpdateCounterVariableValue);
  124. }
  125. /// <summary>
  126. /// 订阅IO变量
  127. /// </summary>
  128. /// <param name="variable"></param>
  129. private void BeckhoffIoSubscribeUpdateVariable(string variable)
  130. {
  131. IOModuleManager.Instance.SubscribeModuleVariable(Module, variable, UpdateIOVariableValue);
  132. }
  133. /// <summary>
  134. /// 更新变量数值
  135. /// </summary>
  136. /// <param name="variable"></param>
  137. /// <param name="value"></param>
  138. private void UpdateIOVariableValue(string variable, object value)
  139. {
  140. if(variable==HIGH_LEVEL)
  141. {
  142. _highLevel=(bool)value;
  143. }
  144. else if(variable==EVAPORATOR_LEVEL)
  145. {
  146. _evaporatorLevel=(bool)value;
  147. }
  148. }
  149. /// <summary>
  150. /// 更新变量数值
  151. /// </summary>
  152. /// <param name="variable"></param>
  153. /// <param name="value"></param>
  154. private void UpdateCounterVariableValue(string variable, object value)
  155. {
  156. string[] strAry = variable.Split('.');
  157. string lastVariable = strAry[strAry.Length - 1];
  158. PropertyInfo property = null;
  159. string key = variable.Replace($".{lastVariable}", "");
  160. if (_nameCounterFlowData.ContainsKey(key))
  161. {
  162. CounterFlowData counterFlowData = _nameCounterFlowData[key];
  163. property = counterFlowData.GetType().GetProperty(lastVariable);
  164. if (property != null)
  165. {
  166. property.SetValue(counterFlowData, value);
  167. }
  168. }
  169. }
  170. /// <summary>
  171. /// 定时器
  172. /// </summary>
  173. /// <returns></returns>
  174. private bool OnTimer()
  175. {
  176. List<string> reservoirs = ReservoirItemManager.Instance.InstalledModules;
  177. foreach (string module in reservoirs)
  178. {
  179. ReservoirItem reservoirItem=ReservoirItemManager.Instance.GetReservoirItem(module);
  180. ReservoirEntity reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(module);
  181. if (reservoirEntity != null)
  182. {
  183. if(reservoirItem.SubType==STRATUS)
  184. {
  185. StandardHotReservoirDevice reservoirDevice = DEVICE.GetDevice<StandardHotReservoirDevice>(module);
  186. if(reservoirDevice.IsDireplenOn)
  187. {
  188. break;
  189. }
  190. if (reservoirDevice.NeedAutoDireplen&&!reservoirDevice.IsDireplenOn)
  191. {
  192. reservoirDevice.AutoDireplen();
  193. }
  194. }
  195. else
  196. {
  197. CompactMembranReservoirDevice reservoirDevice = DEVICE.GetDevice<CompactMembranReservoirDevice>(module);
  198. if (reservoirDevice.IsDireplenOn)
  199. {
  200. break;
  201. }
  202. if(reservoirDevice.AnNeedDireplen&&!reservoirDevice.IsDireplenOn)
  203. {
  204. reservoirDevice.AutoANDiReplen();
  205. }
  206. else if(reservoirDevice.CANeedDiReplen && !reservoirDevice.IsDireplenOn)
  207. {
  208. reservoirDevice.AutoCADiReplen();
  209. }
  210. }
  211. }
  212. }
  213. return true;
  214. }
  215. public void Monitor()
  216. {
  217. }
  218. public void Reset()
  219. {
  220. }
  221. public void Terminate()
  222. {
  223. _period.Stop(false);
  224. }
  225. }
  226. }