123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using Aitex.Core.Common.DeviceData;
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Device.Unit;
- using Aitex.Core.Util;
- using Aitex.Platform;
- using Aitex.Triton160.Common;
- namespace Aitex.Triton160.RT.Device
- {
- public enum LightType
- {
- RED, GREEN, YELLOW, BUZZER
- }
- public enum LightStatus
- {
- OFF, ON, BLINK
- }
- public class IoSignalTower : BaseDevice, IDevice
- {
- //device
- private IoSignalLight red = null;
- private IoSignalLight yellow = null;
- private IoSignalLight green = null;
- private IoSignalLight alarmBuzzer = null;
- private bool _buzzerCleared = false;
- /// <summary>
- /// 用于生成闪烁信号
- /// </summary>
- private bool binking = false;
- /// <summary>
- /// 闪烁定时器 (500ms)
- /// </summary>
- private DeviceTimer timer = new DeviceTimer();
- /// <summary>
- /// 信号灯状态定义
- /// </summary>
- public TowerLightStatus Red { get; private set; }
- public TowerLightStatus Yellow { get; private set; }
- public TowerLightStatus Green { get; private set; }
- public TowerLightStatus Buzzer_Alarm { get; private set; }
- public bool IsGreenOn => green.Value;
- public bool IsYellowOn => yellow.Value;
- public bool IsRedOn => red.Value;
- public bool IsBuzzerOn = false;
- public DeviceTimer _timerBuzzerBlinking = new DeviceTimer();
- public IoSignalTower(string module, string name, string display, string deviceID) :
- base(module, name, display, deviceID)
- {
- }
- public bool Initialize()
- {
- red = DeviceModel.SignalTowerRedLight;
- yellow = DeviceModel.SignalTowerYellowLight;
- green = DeviceModel.SignalTowerGreenLight;
- alarmBuzzer = DeviceModel.SignalTowerBuzzer;
- Debug.Assert(red != null && yellow != null && green != null && alarmBuzzer != null);
- DATA.Subscribe(string.Format("Device.{0}.{1}", ModuleName.System, Name), () =>
- {
- AITSignalTowerData data = new AITSignalTowerData()
- {
- DeviceName = Name,
- DeviceSchematicId = DeviceID,
- DisplayName = Display,
- IsBlueLightOn = false,
- IsGreenLightOn = IsGreenOn,
- IsRedLightOn = IsRedOn,
- IsYellowLightOn = IsYellowOn,
- };
- return data;
- }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DEVICE.Register(string.Format("{0}.{1}", Name, AITSignalTowerOperation.SwitchOffBuzzer), (out string reason, int time, object[] param) =>
- {
- reason = "";
- PMState state = (PMState)DATA.Poll(ModuleNameString.System, StateData.PMState.ToString());
- _buzzerCleared = state == PMState.Error;
- alarmBuzzer.Value = false;
- return true;
- });
- return true;
- }
- public void Terminate()
- {
- }
- /// <summary>
- /// 控制各种灯
- /// </summary>
- /// <param name="light"></param>
- /// <param name="st"></param>
- public void SetLight(LightType light, LightStatus st)
- {
- switch (light)
- {
- case LightType.RED:
- red.Value = st == LightStatus.ON ? true : false;
- break;
- case LightType.GREEN:
- green.Value = st == LightStatus.ON ? true : false;
- break;
- case LightType.YELLOW:
- yellow.Value = st == LightStatus.ON ? true : false;
- break;
- case LightType.BUZZER:
- // TODO, buzzer暂时还用老的BuzzerBlinking [4/30/2020 TerryLu]
- break;
- default:
- break;
- }
- }
- //响3声,通知工艺正常结束
- public void BuzzerBlinking(double time)
- {
- IsBuzzerOn = true;
- _timerBuzzerBlinking.Start(time);
- }
- public void BuzzerStop()
- {
- IsBuzzerOn = false;
- _timerBuzzerBlinking.Stop();
- }
- public void Monitor()
- {
- Buzzer_Alarm = TowerLightStatus.Off;
- if (timer.IsIdle())
- timer.Start(500);
- if (timer.IsTimeout())
- {
- timer.Start(500);
- binking = !binking;
- }
- PMState state = (PMState)DATA.Poll(ModuleNameString.System, StateData.PMState.ToString());
- List<IoValve> valves = DEVICE.GetDevice<IoValve>();
- //pumping valve开,vent purge valve开,Gas valve开,RF开,只要有其中之一处于开的状态,就是绿灯
- if (state == PMState.Error)
- {
- Green = TowerLightStatus.Off;
- Red = TowerLightStatus.On;
- Yellow = TowerLightStatus.Off;
- Buzzer_Alarm = _buzzerCleared ? TowerLightStatus.Off : TowerLightStatus.On;
- }
- else if (DeviceModel.Rf.IsRfOn || valves.Exists(v => v.Status))
- {
- Green = TowerLightStatus.On;
- Red = TowerLightStatus.Off;
- Yellow = TowerLightStatus.Off;
- Buzzer_Alarm = TowerLightStatus.Off;
- }
- else
- {
- Green = TowerLightStatus.Off;
- Red = TowerLightStatus.Off;
- Yellow = TowerLightStatus.On;
- }
- if (!_timerBuzzerBlinking.IsIdle() && !_timerBuzzerBlinking.IsTimeout())
- {
- Buzzer_Alarm = IsBuzzerOn ? TowerLightStatus.On : TowerLightStatus.Off;
- }
- else
- {
- Buzzer_Alarm = TowerLightStatus.Off;
- IsBuzzerOn = false;
- }
- //update tower light status
- switch (Red)
- {
- case TowerLightStatus.On:
- red.Value = true;
- break;
- case TowerLightStatus.Off:
- red.Value = false;
- break;
- case TowerLightStatus.Blinking:
- red.Value = binking;
- break;
- }
- switch (Yellow)
- {
- case TowerLightStatus.On:
- yellow.Value = true;
- break;
- case TowerLightStatus.Off:
- yellow.Value = false;
- break;
- case TowerLightStatus.Blinking:
- yellow.Value = binking;
- break;
- }
- switch (Green)
- {
- case TowerLightStatus.On:
- green.Value = true;
- break;
- case TowerLightStatus.Off:
- green.Value = false;
- break;
- case TowerLightStatus.Blinking:
- green.Value = binking;
- break;
- }
- switch (Buzzer_Alarm)
- {
- case TowerLightStatus.On:
- alarmBuzzer.Value = true;
- break;
- case TowerLightStatus.Off:
- alarmBuzzer.Value = false;
- break;
- case TowerLightStatus.Blinking:
- alarmBuzzer.Value = binking;
- break;
- }
- //System.Diagnostics.Trace.WriteLine(DateTime.Now.Minute.ToString() + ":"+DateTime.Now.Second+"."+DateTime.Now.Millisecond+ "," + (alarmBuzzer.Value ? "1" : "0"));
- }
- /// <summary>
- /// 关闭所有灯和蜂鸣器
- /// </summary>
- public void Reset()
- {
- red.Value = false;
- yellow.Value = false;
- green.Value = false;
- alarmBuzzer.Value = false;
- _buzzerCleared = false;
- }
- }
- }
|