using System; using System.Xml; using Aitex.Core.Common.DeviceData; using Aitex.Core.RT.DataCenter; using Aitex.Core.RT.Device; 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 Aitex.Core.RT.SCCore; namespace VirgoRT.Devices.IODevices { class IoPumpCtrl : BaseDevice, IDevice { private DOAccessor _doPumpRun; private DOAccessor _doPumpStop; private DIAccessor _diDryPumpRunning; private DIAccessor _diPumpAlarm; private DIAccessor _diPumpRemoteStatus; private AOAccessor _aoPumpIOCTRLEnable; private bool _bAlarmReported = false; private readonly int _StartTimeout = 5000; private readonly DeviceTimer _timerStart = new DeviceTimer(); private readonly DeviceTimer _timerStop = new DeviceTimer(); public bool IsRunning => _diDryPumpRunning.Value; public bool IsError => _diPumpAlarm.Value; public IoPumpCtrl(string module, XmlElement node, string ioModule = "") { base.Module = module; base.Name = node.GetAttribute("id"); base.Display = node.GetAttribute("display"); base.DeviceID = node.GetAttribute("schematicId"); _doPumpRun = ParseDoNode("doPumpRun", node, ioModule); _doPumpStop = ParseDoNode("doPumpStop", node, ioModule); _diDryPumpRunning = ParseDiNode("diDryPumpRunning", node, ioModule); _diPumpAlarm = ParseDiNode("diPumpAlarm", node, ioModule); _diPumpRemoteStatus = ParseDiNode("diPumpRemoteStatus", node, ioModule); _aoPumpIOCTRLEnable = ParseAoNode("aoPumpIOCTRLEnable", node, ioModule); _SetRealFloat(_aoPumpIOCTRLEnable, (SC.GetValue($"{Module}.DryPump.MFG") == (int)DryPumpMFG.Kashiyama) ? 1 : 0); EV.PostInfoLog(Module, $"泵控制模式(AO26)设置为:{_aoPumpIOCTRLEnable.Value}"); } public bool Initialize() { return true; } public void Monitor() { if (SC.GetValue($"{Module}.DryPump.MFG") != (int)DryPumpMFG.Kashiyama) return; if(_diPumpAlarm.Value) { if(_bAlarmReported == false) { EV.PostAlarmLog(Module, "Kashiyama 干泵状态错误"); _bAlarmReported = true; } return; } if(_timerStart.IsTimeout()) { _timerStart.Stop(); _doPumpRun.Value = false; EV.PostAlarmLog(Module, "启动 Kashiyama 干泵超时"); } else if(!_timerStart.IsIdle()) { if (_diDryPumpRunning.Value) { _timerStart.Stop(); _doPumpRun.Value = false; } } if (_timerStop.IsTimeout() || (!_timerStop.IsIdle() && !_diDryPumpRunning.Value)) { _timerStop.Stop(); _doPumpStop.Value = false; } } public void StartPump() { if(_diPumpRemoteStatus.Value == false) { EV.PostAlarmLog(Module, "启动干泵失败, Kashiyama 干泵不是远程控制模式"); return; } if (_diPumpAlarm.Value) { EV.PostAlarmLog(Module, "启动干泵失败, Kashiyama 状态错误"); return; } LOG.Info($"[{Module}] Switch on Kashiyama Pump"); _doPumpRun.Value = true; _bAlarmReported = false; _timerStart.Start(_StartTimeout); } public void StopPump() { LOG.Info($"[{Module}] Switch off Kashiyama Pump"); _doPumpStop.Value = true; _timerStop.Start(_StartTimeout); } public void Terminate() { } public void Reset() { _bAlarmReported = false; } } }