using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; using Aitex.Core.RT.Device; using Aitex.Core.RT.Log; using Aitex.Core.Util; using MECF.Framework.Common.Device.Bases; using MECF.Framework.Common.Equipment; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Efems; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Efems.Rorzes; namespace FutureEfemLib.SignalTowers { class RorzeSingalLight : SignalLightBase { public LightType Type { get; set; } public IEfemController EfemController { get; set; } private F_TRIG _trigError = new F_TRIG(); private bool _isInit; private TowerLightStatus _preState = TowerLightStatus.Unknown; public RorzeSingalLight(string module, string name) : base(module, name) { _isInit = true; } protected override void SetOn() { SetLight(TowerLightStatus.On); } protected override void SetOff() { SetLight(TowerLightStatus.Off); } protected override void SetBlinking(bool token) { SetLight(TowerLightStatus.Blinking); } private void SetLight(TowerLightStatus setpoint) { try { if (setpoint != _preState || _isInit) { _trigError.CLK = EfemController.SetSignalLight(Type, setpoint, out string reason); if (_trigError.Q) { //EV.PostWarningLog(Module, $"Set {Type} signal light {setpoint} error, {reason}"); } if (_trigError.M) { _isInit = false; _preState = setpoint; } } } catch (Exception ex) { LOG.Write(ex); } } public void ResetData() { _isInit = true; } public override void Reset() { _trigError.RST = true; base.Reset(); } } public class FutureSignalTower : SignalTowerBase, IEfemSignalTowerCallback { private string _efemName; private IRorzeEfemController _efem; private List _lstLight = new List(); public FutureSignalTower(string module, XmlElement node, string ioModule) : base("", "") { var attrModule = node.GetAttribute("module"); base.Module = string.IsNullOrEmpty(attrModule) ? module : attrModule; base.Name = node.GetAttribute("id"); base.Display = node.GetAttribute("display"); base.DeviceID = node.GetAttribute("schematicId"); _efemName = node.GetAttribute("efem"); } public FutureSignalTower(string module, string name, string efemName) : base("", "") { base.Module = module; base.Name = name; _efemName = efemName; } public override bool Initialize() { base.Initialize(); if (_efem == null && !string.IsNullOrEmpty(_efemName)) { _efem = DEVICE.GetDevice(_efemName); _efem.SetSignalTowerCallback(ModuleHelper.Converter(Module), this); } CustomSignalTower(); return true; } //重新连接EFEM之后,需要重置灯塔 public void ResetData() { foreach (var rorzeSingalLight in _lstLight) { rorzeSingalLight.ResetData(); } } public override SignalLightBase CreateLight(LightType type) { var light = new RorzeSingalLight(ModuleName.System.ToString(), $"SignalLight{type}") { Type = type, EfemController = _efem }; _lstLight.Add(light); return light; } } }