DryerAutoOff.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. using Aitex.Core.RT.DataCenter;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Log;
  4. using Aitex.Core.RT.SCCore;
  5. using Aitex.Core.Util;
  6. using MECF.Framework.Common.Equipment;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Diagnostics;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Timers;
  14. namespace CyberX8_RT.Devices.Dryer
  15. {
  16. public class DryerAutoOff : Singleton<DryerAutoOff>
  17. {
  18. #region 内部变量
  19. private Timer _timer;
  20. /// <summary>
  21. /// auto shut off时间
  22. /// </summary>
  23. private int _autoShutoffTimeoutSeconds = 1800;
  24. private Stopwatch _stopWatch = new Stopwatch();
  25. /// <summary>
  26. /// 是否启动
  27. /// </summary>
  28. private bool _isStart = false;
  29. #endregion
  30. /// <summary>
  31. /// 构造函数
  32. /// </summary>
  33. public DryerAutoOff()
  34. {
  35. _timer = new Timer();
  36. _timer.Elapsed += Timer_Elapsed;
  37. DATA.Subscribe("Dryer.CountDownSecond", () => _stopWatch.IsRunning ? (int)Math.Ceiling((_timer.Interval - _stopWatch.ElapsedMilliseconds) / 1000) : 0, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  38. }
  39. /// <summary>
  40. /// 定时器执行
  41. /// </summary>
  42. /// <param name="sender"></param>
  43. /// <param name="e"></param>
  44. private void Timer_Elapsed(object sender, ElapsedEventArgs e)
  45. {
  46. if (CheckDyerIsHigh(ModuleName.Dryer1))
  47. {
  48. LOG.WriteLog(eEvent.INFO_AXIS, "Dyer", "Dryer1 is in High on");
  49. Stop();
  50. return;
  51. }
  52. if (CheckDyerIsHigh(ModuleName.Dryer2))
  53. {
  54. LOG.WriteLog(eEvent.INFO_AXIS, "Dyer", "Dryer2 is in High on");
  55. Stop();
  56. return;
  57. }
  58. if (CheckDyerIsHigh(ModuleName.Dryer3))
  59. {
  60. LOG.WriteLog(eEvent.INFO_AXIS, "Dyer", "Dryer3 is in High on");
  61. Stop();
  62. return;
  63. }
  64. AutoPowerOff(ModuleName.Dryer1);
  65. AutoPowerOff(ModuleName.Dryer2);
  66. AutoPowerOff(ModuleName.Dryer3);
  67. LOG.WriteLog(eEvent.INFO_DRYER, "Dryer", "Auto power off all dryers");
  68. Stop();
  69. }
  70. /// <summary>
  71. /// 自动关闭
  72. /// </summary>
  73. /// <param name="moduleName"></param>
  74. private void AutoPowerOff(ModuleName moduleName)
  75. {
  76. if (ModuleHelper.IsInstalled(moduleName))
  77. {
  78. DryerDevice dryerDevice = DEVICE.GetDevice<DryerDevice>(moduleName.ToString());
  79. if (dryerDevice != null)
  80. {
  81. dryerDevice.PowerControlOff();
  82. }
  83. }
  84. }
  85. /// <summary>
  86. /// 检验是否在HighOn
  87. /// </summary>
  88. /// <param name="moduleName"></param>
  89. /// <returns></returns>
  90. private bool CheckDyerIsHigh(ModuleName moduleName)
  91. {
  92. if (ModuleHelper.IsInstalled(moduleName))
  93. {
  94. DryerDevice dryerDevice = DEVICE.GetDevice<DryerDevice>(moduleName.ToString());
  95. if (dryerDevice != null)
  96. {
  97. return dryerDevice.CommonData.BlowerHigh;
  98. }
  99. }
  100. return false;
  101. }
  102. /// <summary>
  103. /// 启动
  104. /// </summary>
  105. public void Start()
  106. {
  107. _autoShutoffTimeoutSeconds = SC.GetValue<int>("Dryer.AutoShutoffTimeoutSeconds");
  108. if (CheckDyerIsHigh(ModuleName.Dryer1))
  109. {
  110. LOG.WriteLog(eEvent.INFO_AXIS, "Dyer", "Dryer1 is in High on");
  111. return;
  112. }
  113. if (CheckDyerIsHigh(ModuleName.Dryer2))
  114. {
  115. LOG.WriteLog(eEvent.INFO_AXIS, "Dyer", "Dryer2 is in High on");
  116. return;
  117. }
  118. if (CheckDyerIsHigh(ModuleName.Dryer3))
  119. {
  120. LOG.WriteLog(eEvent.INFO_AXIS, "Dyer", "Dryer3 is in High on");
  121. return;
  122. }
  123. if (_autoShutoffTimeoutSeconds!=_timer.Interval)
  124. {
  125. _timer.Stop();
  126. _timer.Interval = _autoShutoffTimeoutSeconds*1000;
  127. }
  128. if (!_isStart)
  129. {
  130. _stopWatch.Restart();
  131. LOG.WriteLog(eEvent.INFO_DRYER, "Dryer", "start auto power off");
  132. _timer.Start();
  133. _isStart = true;
  134. }
  135. }
  136. /// <summary>
  137. /// 停止
  138. /// </summary>
  139. public void Stop()
  140. {
  141. if (_isStart)
  142. {
  143. LOG.WriteLog(eEvent.INFO_DRYER, "Dryer", "stop auto power off");
  144. _timer.Stop();
  145. _isStart = false;
  146. }
  147. if (_stopWatch.IsRunning)
  148. {
  149. _stopWatch.Stop();
  150. }
  151. }
  152. }
  153. }