using Aitex.Core.RT.DataCenter; using Aitex.Core.RT.Device; using Aitex.Core.RT.Log; using Aitex.Core.RT.SCCore; using Aitex.Core.Util; using MECF.Framework.Common.Equipment; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Timers; namespace CyberX8_RT.Devices.Dryer { public class DryerAutoOff : Singleton { #region 内部变量 private Timer _timer; /// /// auto shut off时间 /// private int _autoShutoffTimeoutSeconds = 1800; private Stopwatch _stopWatch = new Stopwatch(); /// /// 是否启动 /// private bool _isStart = false; #endregion /// /// 构造函数 /// public DryerAutoOff() { _timer = new Timer(); _timer.Elapsed += Timer_Elapsed; DATA.Subscribe("Dryer.CountDownSecond", () => _stopWatch.IsRunning ? (int)Math.Ceiling((_timer.Interval - _stopWatch.ElapsedMilliseconds) / 1000) : 0, SubscriptionAttribute.FLAG.IgnoreSaveDB); } /// /// 定时器执行 /// /// /// private void Timer_Elapsed(object sender, ElapsedEventArgs e) { if (CheckDyerIsHigh(ModuleName.Dryer1)) { LOG.WriteLog(eEvent.INFO_AXIS, "Dyer", "Dryer1 is in High on"); Stop(); return; } if (CheckDyerIsHigh(ModuleName.Dryer2)) { LOG.WriteLog(eEvent.INFO_AXIS, "Dyer", "Dryer2 is in High on"); Stop(); return; } if (CheckDyerIsHigh(ModuleName.Dryer3)) { LOG.WriteLog(eEvent.INFO_AXIS, "Dyer", "Dryer3 is in High on"); Stop(); return; } AutoPowerOff(ModuleName.Dryer1); AutoPowerOff(ModuleName.Dryer2); AutoPowerOff(ModuleName.Dryer3); LOG.WriteLog(eEvent.INFO_DRYER, "Dryer", "Auto power off all dryers"); Stop(); } /// /// 自动关闭 /// /// private void AutoPowerOff(ModuleName moduleName) { if (ModuleHelper.IsInstalled(moduleName)) { DryerDevice dryerDevice = DEVICE.GetDevice(moduleName.ToString()); if (dryerDevice != null) { dryerDevice.PowerControlOff(); } } } /// /// 检验是否在HighOn /// /// /// private bool CheckDyerIsHigh(ModuleName moduleName) { if (ModuleHelper.IsInstalled(moduleName)) { DryerDevice dryerDevice = DEVICE.GetDevice(moduleName.ToString()); if (dryerDevice != null) { return dryerDevice.CommonData.BlowerHigh; } } return false; } /// /// 启动 /// public void Start() { _autoShutoffTimeoutSeconds = SC.GetValue("Dryer.AutoShutoffTimeoutSeconds"); if (CheckDyerIsHigh(ModuleName.Dryer1)) { LOG.WriteLog(eEvent.INFO_AXIS, "Dyer", "Dryer1 is in High on"); return; } if (CheckDyerIsHigh(ModuleName.Dryer2)) { LOG.WriteLog(eEvent.INFO_AXIS, "Dyer", "Dryer2 is in High on"); return; } if (CheckDyerIsHigh(ModuleName.Dryer3)) { LOG.WriteLog(eEvent.INFO_AXIS, "Dyer", "Dryer3 is in High on"); return; } if (_autoShutoffTimeoutSeconds!=_timer.Interval) { _timer.Stop(); _timer.Interval = _autoShutoffTimeoutSeconds*1000; } if (!_isStart) { _stopWatch.Restart(); LOG.WriteLog(eEvent.INFO_DRYER, "Dryer", "start auto power off"); _timer.Start(); _isStart = true; } } /// /// 停止 /// public void Stop() { if (_isStart) { LOG.WriteLog(eEvent.INFO_DRYER, "Dryer", "stop auto power off"); _timer.Stop(); _isStart = false; } if (_stopWatch.IsRunning) { _stopWatch.Stop(); } } } }