using System; using Aitex.Core.RT.Log; using Aitex.Core.Util; namespace Aitex.Core.RT.IOCore.Interlock.DataProvider; public abstract class DataPollProviderBase : IInterlockLimitDataProvider { #region Variables private readonly R_TRIG _rTrigPollFailed = new(); #endregion #region Constructors /// /// 实例化数据拉取器 /// /// protected DataPollProviderBase(string dataPath) { DataPath = dataPath; } #endregion #region Properties /// /// /// public string Name => DataPath; /// /// /// public string Description => DataPath; /// /// 返回当前数据拉取器需要拉取的数据路径。 /// /// 注意路径中不要包含Module名称。 /// /// protected string DataPath { get; } #endregion #region Methods /// /// 需由派生类实现的获取数据的方法。 /// /// protected abstract object HandleGetValue(); /// /// 获取数据。 /// /// public object GetValue() { try { var value = HandleGetValue(); _rTrigPollFailed.CLK = false; return value; } catch (Exception ex) { _rTrigPollFailed.CLK = true; if (_rTrigPollFailed.Q) { LOG.Error($"DataPollProvider poll data {DataPath} failed, {ex.Message}"); } return null; } } public override string ToString() { return Name; } #endregion }