123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- 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<DryerAutoOff>
- {
- #region 内部变量
- private Timer _timer;
- /// <summary>
- /// auto shut off时间
- /// </summary>
- private int _autoShutoffTimeoutSeconds = 1800;
- private Stopwatch _stopWatch = new Stopwatch();
- /// <summary>
- /// 是否启动
- /// </summary>
- private bool _isStart = false;
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- 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);
- }
- /// <summary>
- /// 定时器执行
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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();
- }
- /// <summary>
- /// 自动关闭
- /// </summary>
- /// <param name="moduleName"></param>
- private void AutoPowerOff(ModuleName moduleName)
- {
- if (ModuleHelper.IsInstalled(moduleName))
- {
- DryerDevice dryerDevice = DEVICE.GetDevice<DryerDevice>(moduleName.ToString());
- if (dryerDevice != null)
- {
- dryerDevice.PowerControlOff();
- }
- }
- }
- /// <summary>
- /// 检验是否在HighOn
- /// </summary>
- /// <param name="moduleName"></param>
- /// <returns></returns>
- private bool CheckDyerIsHigh(ModuleName moduleName)
- {
- if (ModuleHelper.IsInstalled(moduleName))
- {
- DryerDevice dryerDevice = DEVICE.GetDevice<DryerDevice>(moduleName.ToString());
- if (dryerDevice != null)
- {
- return dryerDevice.CommonData.BlowerHigh;
- }
- }
- return false;
- }
- /// <summary>
- /// 启动
- /// </summary>
- public void Start()
- {
- _autoShutoffTimeoutSeconds = SC.GetValue<int>("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;
- }
- }
- /// <summary>
- /// 停止
- /// </summary>
- public void Stop()
- {
- if (_isStart)
- {
- LOG.WriteLog(eEvent.INFO_DRYER, "Dryer", "stop auto power off");
- _timer.Stop();
- _isStart = false;
- }
- if (_stopWatch.IsRunning)
- {
- _stopWatch.Stop();
- }
- }
- }
- }
|