123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Xml;
- using System.Xml.Serialization;
- using Aitex.Core.Common.DeviceData;
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Device.Unit;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.IOCore;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.OperationCenter;
- using Aitex.Core.Util;
- using MECF.Framework.Common.Device.Bases;
- using MECF.Framework.Common.Equipment;
- using Venus_Core;
- namespace Venus_RT.Devices
- {
- //public enum LightType
- //{
- // Red,
- // Yellow,
- // Green,
- // White,
- // Blue,
- // Buzzer1,
- // Buzzer2
- //}
- public enum LightState
- {
- Off,
- On,
- Blink,
- }
- public class STEvents
- {
- [XmlElement(ElementName = "STEvent")]
- public List<STEvent> Events;
- }
- public class STEvent
- {
- [XmlAttribute(AttributeName = "name")]
- public string Name { get; set; }
- [XmlAttribute]
- public string Red { get; set; }
- [XmlAttribute]
- public string Yellow { get; set; }
- [XmlAttribute]
- public string Green { get; set; }
- [XmlAttribute]
- public string Blue { get; set; }
- [XmlAttribute]
- public string White { get; set; }
- [XmlAttribute]
- public string Buzzer1 { get; set; }
- [XmlAttribute]
- public string Buzzer2 { get; set; }
- }
- public class IoSignalTower : BaseDevice, IDevice
- {
- //device
- private IoSignalLight _red = null;
- private IoSignalLight _yellow = null;
- private IoSignalLight _green = null;
- private IoSignalLight _blue = null;
- private IoSignalLight _white = null;
- private IoSignalLight _buzzer1 = null;
- private IoSignalLight _buzzer2 = null;
- private PMState state;
- public bool HostControl { get; set; }
- private bool _buzzerSwitchOff = false;
- private bool _buzzerAndRed = false;
- private RfPowerBase _Generator;
- public DeviceTimer _timerBuzzerBlinking = new DeviceTimer();
- public AITSignalTowerData DeviceData
- {
- get
- {
- AITSignalTowerData data = new AITSignalTowerData()
- {
- DeviceName = Name,
- DeviceSchematicId = DeviceID,
- DisplayName = Display,
- IsGreenLightOn = _green != null && _green.Value,
- IsRedLightOn = _red != null && _red.Value,
- IsYellowLightOn = _yellow != null && _yellow.Value,
- IsWhiteLightOn = _white != null && _white.Value,
- IsBlueLightOn = _blue != null && _blue.Value,
- IsBuzzerOn = (_buzzer1 != null && _buzzer1.Value) || (_buzzer2 != null && _buzzer2.Value),
- };
- return data;
- }
- }
- private object _locker = new object();
- private Dictionary<string, Dictionary<IoSignalLight, TowerLightStatus>> _config =
- new Dictionary<string, Dictionary<IoSignalLight, TowerLightStatus>>();
- private Dictionary<IoSignalLight, TowerLightStatus> _cmdSetPoint = new Dictionary<IoSignalLight, TowerLightStatus>();
- public IoSignalTower(string module, XmlElement node, string ioModule = "")
- {
- base.Module = module;
- base.Name = node.GetAttribute("id");
- base.Display = node.GetAttribute("display");
- base.DeviceID = node.GetAttribute("schematicId");
- DOAccessor doRed = ParseDoNode("doRed", node, ioModule);
- if (doRed != null)
- {
- _red = new IoSignalLight(module, "SignalLightRed", "Red Light", "SignalLightRed", doRed);
- }
- DOAccessor doYellow = ParseDoNode("doYellow", node, ioModule);
- if (doYellow != null)
- {
- _yellow = new IoSignalLight(module, "SignalLightYellow", "Yellow Light", "SignalLightYellow", doYellow);
- }
- DOAccessor doGreen = ParseDoNode("doGreen", node, ioModule);
- if (doGreen != null)
- {
- _green = new IoSignalLight(module, "SignalLightGreen", "Green Light", "SignalLightGreen", doGreen);
- }
- DOAccessor doBlue = ParseDoNode("doBlue", node, ioModule);
- if (doBlue != null)
- {
- _blue = new IoSignalLight(module, "SignalLightBlue", "Blue Light", "SignalLightBlue", doBlue);
- }
- DOAccessor doWhite = ParseDoNode("doWhite", node, ioModule);
- if (doWhite != null)
- {
- _white = new IoSignalLight(module, "SignalLightWhite", "White Light", "SignalLightWhite", doWhite);
- }
- DOAccessor doBuzzer1 = ParseDoNode("doBuzzer1", node, ioModule);
- if (doBuzzer1 != null)
- {
- _buzzer1 = new IoSignalLight(module, "SignalLightBuzzer1", "Buzzer Light 1", "SignalLightBuzzer1", doBuzzer1);
- }
- DOAccessor doBuzzer2 = ParseDoNode("doBuzzer2", node, ioModule);
- if (doBuzzer2 != null)
- {
- _buzzer2 = new IoSignalLight(module, "SignalLightBuzzer2", "Buzzer Light 2", "SignalLightBuzzer2", doBuzzer2);
- }
- }
- public bool Initialize()
- {
- OP.Subscribe($"{Module}.{Name}.{AITSignalTowerOperation.SwitchOffBuzzer}", SwitchOffBuzzer);
- OP.Subscribe($"{Module}.{Name}.{AITSignalTowerOperation.SwitchOnBuzzerAndRed}", SwitchOnBuzzerAndRed);
- DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData);
- DATA.Subscribe($"{Module}.{Name}.IsRedLightOn", () => _red != null && _red.Value);
- DATA.Subscribe($"{Module}.{Name}.IsYellowLightOn", () => _yellow != null && _yellow.Value);
- DATA.Subscribe($"{Module}.{Name}.IsGreenLightOn", () => _green != null && _green.Value);
- DATA.Subscribe($"{Module}.{Name}.IsBlueLightOn", () => _blue != null && _blue.Value);
- DATA.Subscribe($"{Module}.{Name}.IsBuzzerOn", () => (_buzzer1 != null && _buzzer1.Value) || (_buzzer2 != null && _buzzer2.Value));
- return true;
- }
- public void SetLight(LightType lightType, LightState state, int blinkInterval = 500)
- {
- IoSignalLight light = null;
- switch (lightType)
- {
- case LightType.RED:
- light = _red;
- break;
- case LightType.GREEN:
- light = _green;
- break;
- case LightType.YELLOW:
- light = _yellow;
- break;
- case LightType.WHITE:
- light = _white;
- break;
- case LightType.BLUE:
- light = _blue;
- break;
- case LightType.BUZZER1:
- light = _buzzer1;
- break;
- //case LightType.buzz:
- // light = _buzzer2;
- // break;
- }
- if (light == null)
- {
- LOG.Write(eEvent.ERR_SIGNAL_TOWER_UNDEFINE, ModuleName.System, light.ToString());
- return;
- }
- switch (state)
- {
- case LightState.On:
- _cmdSetPoint[light] = TowerLightStatus.On;
- light.StateSetPoint = TowerLightStatus.On;
- break;
- case LightState.Off:
- _cmdSetPoint[light] = TowerLightStatus.Off;
- light.StateSetPoint = TowerLightStatus.Off;
- break;
- case LightState.Blink:
- _cmdSetPoint[light] = TowerLightStatus.Blinking;
- light.Interval = blinkInterval;
- light.StateSetPoint = TowerLightStatus.Blinking;
- break;
- }
- }
- public bool CustomSignalTower(string configPathFile)
- {
- try
- {
- STEvents config = CustomXmlSerializer.Deserialize<STEvents>(new FileInfo(configPathFile));
- lock (_locker)
- {
- foreach (STEvent e in config.Events)
- {
- if (!_config.ContainsKey(e.Name))
- {
- _config[e.Name] = new Dictionary<IoSignalLight, TowerLightStatus>();
- }
- if (_red != null)
- _config[e.Name][_red] = ParseLight(e.Red);
- if (_yellow != null)
- _config[e.Name][_yellow] = ParseLight(e.Yellow);
- if (_green != null)
- _config[e.Name][_green] = ParseLight(e.Green);
- if (_blue != null)
- _config[e.Name][_blue] = ParseLight(e.Blue);
- if (_white != null)
- _config[e.Name][_white] = ParseLight(e.White);
- if (_buzzer1 != null)
- _config[e.Name][_buzzer1] = ParseLight(e.Buzzer1);
- }
- }
- }
- catch (Exception e)
- {
- LOG.Write(eEvent.ERR_SIGNAL_TOWER_INVALID_CFG, ModuleName.System, e.Message);
- return false;
- }
- return true;
- }
- //响3声,通知工艺正常结束
- public void BuzzerBlinking(double time)
- {
- _timerBuzzerBlinking.Start(time);
- }
- public bool SwitchOnBuzzerAndRed(string cmd, object[] objs)
- {
- return _buzzerAndRed = true;
- }
- public void Monitor()
- {
- if (DATA.Poll(Module, StateData.PMState.ToString()) != null)
- state = (PMState)DATA.Poll(Module, StateData.PMState.ToString());
- List<IoValve> valves = DEVICE.GetDevice<IoValve>();
- //if (DEVICE.GetDevice<IoRf>() != null)
- //{
- // _Generator = DEVICE.GetDevice<IoRf>($"{Module}.{VenusDevice.Rf}");
- //}
- //else
- if (DEVICE.GetDevice<AdTecGenerator>() != null)
- {
- _Generator = DEVICE.GetDevice<AdTecGenerator>($"{Module}.{VenusDevice.Rf}");
- }
- else
- {
- _Generator = null;
- }
- //pumping valve开,vent purge valve开,Gas valve开,RF开,只要有其中之一处于开的状态,就是绿灯
- if (state == PMState.Error || _buzzerAndRed)
- {
- SetLight(LightType.GREEN, LightState.Off);
- SetLight(LightType.RED, LightState.On);
- SetLight(LightType.YELLOW, LightState.Off);
- SetLight(LightType.BUZZER1, _buzzerSwitchOff ? LightState.Off : LightState.On);
- }
- else if ((_Generator != null && _Generator.IsPowerOn) || valves.Exists(v => v.Status))
- {
- SetLight(LightType.GREEN, LightState.On);
- SetLight(LightType.RED, LightState.Off);
- SetLight(LightType.YELLOW, LightState.Off);
- SetLight(LightType.BUZZER1, LightState.Off);
- }
- else if (state == PMState.PreProcess || state == PMState.Processing || state == PMState.PostProcess)
- {
- SetLight(LightType.GREEN, LightState.On);
- SetLight(LightType.RED, LightState.Off);
- SetLight(LightType.YELLOW, LightState.Off);
- SetLight(LightType.BUZZER1, LightState.Off);
- }
- else
- {
- SetLight(LightType.GREEN, LightState.Off);
- SetLight(LightType.RED, LightState.Off);
- SetLight(LightType.YELLOW, LightState.On);
- SetLight(LightType.BUZZER1, LightState.Off);
- }
- if (!_timerBuzzerBlinking.IsIdle() && !_timerBuzzerBlinking.IsTimeout())
- SetLight(LightType.BUZZER1, LightState.Blink);
- MonitorLight(_red);
- MonitorLight(_blue);
- MonitorLight(_yellow);
- MonitorLight(_green);
- MonitorLight(_white);
- MonitorLight(_buzzer1);
- MonitorLight(_buzzer2);
- }
- public void Reset()
- {
- ResetLight(_red);
- ResetLight(_blue);
- ResetLight(_yellow);
- ResetLight(_green);
- ResetLight(_white);
- ResetLight(_buzzer1);
- ResetLight(_buzzer2);
- _buzzerAndRed = false;
- _buzzerSwitchOff = false;
- }
- public bool SwitchOffBuzzer(string cmd, object[] objs)
- {
- if (cmd == $"{ Module}.{ Name}.{ AITSignalTowerOperation.SwitchOffBuzzer}" && _buzzer1 != null && _buzzer1.StateSetPoint != TowerLightStatus.Off)
- {
- _buzzerSwitchOff = true;
- }
- return true;
- }
- private void SetLight(IoSignalLight light, Dictionary<IoSignalLight, TowerLightStatus> state)
- {
- if (light != null)
- {
- light.StateSetPoint = state[light];
- }
- }
- private void ResetLight(IoSignalLight light)
- {
- if (light != null)
- {
- light.Reset();
- }
- }
- private void MonitorLight(IoSignalLight light)
- {
- if (light != null)
- {
- light.Monitor();
- }
- }
- public void Terminate()
- {
- }
- private TowerLightStatus MergeCondition(TowerLightStatus newValue, TowerLightStatus oldValue)
- {
- if (newValue == TowerLightStatus.Blinking || oldValue == TowerLightStatus.Blinking)
- return TowerLightStatus.Blinking;
- if (newValue == TowerLightStatus.On || oldValue == TowerLightStatus.On)
- return TowerLightStatus.On;
- return TowerLightStatus.Off;
- }
- private TowerLightStatus ParseLight(string light)
- {
- if (string.IsNullOrEmpty(light))
- return TowerLightStatus.Off;
- TowerLightStatus result = TowerLightStatus.Unknown;
- light = light.Trim().ToLower();
- switch (light)
- {
- case "on":
- result = TowerLightStatus.On;
- break;
- case "off":
- result = TowerLightStatus.Off;
- break;
- case "blinking":
- result = TowerLightStatus.Blinking;
- break;
- default:
- LOG.Write(eEvent.ERR_SIGNAL_TOWER_INVALID_CFG, ModuleName.System, light);
- break;
- }
- return result;
- }
- }
- }
|