using Aitex.Core.RT.DataCenter; using Aitex.Core.RT.Device; using Aitex.Core.RT.IOCore; using Aitex.Core.RT.Log; using Aitex.Core.RT.OperationCenter; using Aitex.Core.Util; using MECF.Framework.Common.CommonData.DeviceData; using System; using System.Xml; using Venus_Core; namespace Venus_RT.Devices.IODevices { public class IoHighTemperatureHeater : BaseDevice, IDevice { private readonly DIAccessor _diPowerOnFeedback; private readonly DOAccessor _doPowerOn; private readonly AIAccessor _aiTemperatureFeedback; private readonly AOAccessor _aoTemperatureSetPoint; private readonly DIAccessor _diGoPosition1Feedback; private readonly DOAccessor _doGoPosition1On; private readonly DIAccessor _diGoPosition2Feedback; private readonly DOAccessor _doGoPosition2On; private readonly DIAccessor _diGoPosition3Feedback; private readonly DOAccessor _doGoPosition3On; private readonly DIAccessor _diGoOriginFeedback; private readonly DOAccessor _doGoOriginOn; private readonly DeviceTimer _originTimer = new DeviceTimer(); private readonly DeviceTimer _position1Timer = new DeviceTimer(); private readonly DeviceTimer _position2Timer = new DeviceTimer(); private readonly DeviceTimer _position3Timer = new DeviceTimer(); private int _goPositionTime = 5 * 1000; private AITHighTemperatureHeaterData DeviceData { get { return new AITHighTemperatureHeaterData { Module = Module, DeviceName = Name, DisplayName = Display, HighTemperatureHeaterPosition = CurrentPosition.ToString(), HighTemperatureHeaterIson = HighTemperatureHeaterIsOn, HighTemperatureHeaterTemperature = HighTemperatureHighHeaterTemperature }; } } public HighTemperatureHeaterPosition CurrentPosition { get { if (_diGoOriginFeedback.Value == true && _diGoPosition1Feedback.Value == false && _diGoPosition2Feedback.Value == false && _diGoPosition3Feedback.Value == false) { return HighTemperatureHeaterPosition.Origin; } else if (_diGoOriginFeedback.Value == false && _diGoPosition1Feedback.Value == true && _diGoPosition2Feedback.Value == false && _diGoPosition3Feedback.Value == false) { return HighTemperatureHeaterPosition.Position1; } else if (_diGoOriginFeedback.Value == false && _diGoPosition1Feedback.Value == false && _diGoPosition2Feedback.Value == true && _diGoPosition3Feedback.Value == false) { return HighTemperatureHeaterPosition.Position2; } else if (_diGoOriginFeedback.Value == false && _diGoPosition1Feedback.Value == false && _diGoPosition2Feedback.Value == false && _diGoPosition3Feedback.Value == true) { return HighTemperatureHeaterPosition.Position3; } else { return HighTemperatureHeaterPosition.Error; } } } public bool HighTemperatureHeaterIsOn { get { if (_diPowerOnFeedback.Value == true && _doPowerOn.Value == true) { return true; } else { return false; } } set { _doPowerOn.Value = value; } } public float HighTemperatureHighHeaterTemperature { get { if (_aiTemperatureFeedback == null) return -1; return _GetRealFloat(_aiTemperatureFeedback); } set { _SetRealFloat(_aoTemperatureSetPoint, value); } } public IoHighTemperatureHeater(string module, XmlElement node, string ioModule = "") { base.Module = module; base.Name = node.GetAttribute("id"); base.Display = node.GetAttribute("display"); base.DeviceID = node.GetAttribute("schematicId"); _diPowerOnFeedback = ParseDiNode("diPowerOnFeedback", node, ioModule); _doPowerOn = ParseDoNode("doPowerOn", node, ioModule); _aiTemperatureFeedback = ParseAiNode("aiTemperatureFeedback", node, ioModule); _aoTemperatureSetPoint = ParseAoNode("aoTemperatureSetPoint", node, ioModule); _diGoPosition1Feedback = ParseDiNode("diGoPosition1Feedback", node, ioModule); _doGoPosition1On = ParseDoNode("doGoPosition1On", node, ioModule); _diGoPosition2Feedback = ParseDiNode("diGoPosition2Feedback", node, ioModule); _doGoPosition2On = ParseDoNode("doGoPosition2On", node, ioModule); _diGoPosition3Feedback = ParseDiNode("diGoPosition3Feedback", node, ioModule); _doGoPosition3On = ParseDoNode("doGoPosition3On", node, ioModule); _diGoOriginFeedback = ParseDiNode("diGoOriginFeedback", node, ioModule); _doGoOriginOn = ParseDoNode("doGoOriginOn", node, ioModule); } public bool GotoPosition(HighTemperatureHeaterPosition highTemperatureHeaterPosition) { if (CurrentPosition == highTemperatureHeaterPosition) { return true; } switch (highTemperatureHeaterPosition) { case HighTemperatureHeaterPosition.Origin: _doGoOriginOn.Value = true; _originTimer.Start(_goPositionTime); break; case HighTemperatureHeaterPosition.Position1: _doGoPosition1On.Value = true; _position1Timer.Start(_goPositionTime); break; case HighTemperatureHeaterPosition.Position2: _doGoPosition2On.Value = true; _position2Timer.Start(_goPositionTime); break; case HighTemperatureHeaterPosition.Position3: _doGoPosition3On.Value = true; _position3Timer.Start(_goPositionTime); break; } return true; } public bool Initialize() { OP.Subscribe($"{Module}.{Name}.GotoPosition", (cmd, args) => { var currentPosition = (HighTemperatureHeaterPosition)Enum.Parse(typeof(HighTemperatureHeaterPosition), args[0].ToString()); GotoPosition(currentPosition); return true; }); OP.Subscribe($"{Module}.{Name}.SwitchHighTemperatureHeater", (cmd, args) => { HighTemperatureHeaterIsOn = Convert.ToBoolean(args[0].ToString()); return true; }); OP.Subscribe($"{Module}.{Name}.SetHighTemperatureHeaterTemperature", (cmd, args) => { HighTemperatureHighHeaterTemperature = Convert.ToSingle( args[0]); return true; }); DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData, SubscriptionAttribute.FLAG.IgnoreSaveDB); return true; } public void Stop() { } public void Terminate() { } public void Monitor() { if (_originTimer.IsTimeout()) { _originTimer.Stop(); if (_diGoOriginFeedback.Value == false) { LOG.Write(eEvent.ERR_DEVICE_INFO, Module, $"{Name} {_goPositionTime/1000} s 内未到原点"); } } else if (_originTimer.IsIdle()==false) { if (_diGoOriginFeedback.Value == true) { LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{Name} 到 原点"); _doGoOriginOn.Value = false; _originTimer.Stop(); } } if (_position1Timer.IsTimeout()) { _position1Timer.Stop(); if (_diGoPosition1Feedback.Value == false) { LOG.Write(eEvent.ERR_DEVICE_INFO, Module, $"{Name} {_goPositionTime/1000} s 内未到Position1"); } } else if (_position1Timer.IsIdle() == false) { if (_diGoPosition1Feedback.Value == true) { LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{Name} 到 Position1"); _doGoPosition1On.Value = false; _position1Timer.Stop(); } } if (_position2Timer.IsTimeout()) { _position2Timer.Stop(); if (_diGoPosition2Feedback.Value == false) { LOG.Write(eEvent.ERR_DEVICE_INFO, Module, $"{Name} {_goPositionTime/1000} s 内未到Position2"); } } else if (_position2Timer.IsIdle() == false) { if (_diGoPosition2Feedback.Value == true) { LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{Name} 到 Position2"); _doGoPosition2On.Value = false; _position2Timer.Stop(); } } if (_position3Timer.IsTimeout()) { _position3Timer.Stop(); if (_diGoPosition3Feedback.Value == false) { LOG.Write(eEvent.ERR_DEVICE_INFO, Module, $"{Name} {_goPositionTime/1000} s 内未到Position3"); } } else if (_position3Timer.IsIdle() == false) { if (_diGoPosition3Feedback.Value == true) { LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{Name} 到 Position3"); _doGoPosition3On.Value = false; _position3Timer.Stop(); } } } public void Reset() { } } }