using System.Collections.Generic; using System.Text; namespace Aitex.Core.RT.IOCore; public class InterlockDaemonAction { #region Variables private readonly List _limits; private readonly DOAccessor _do; private readonly bool _targetValue; private readonly string _tip; private Dictionary _cultureTip; #endregion #region Constructors public InterlockDaemonAction(DOAccessor doItem, bool value, string tip, Dictionary cultureTip, List limits) { _do = doItem; _targetValue = value; _tip = tip; _cultureTip = cultureTip; _limits = limits; } #endregion #region Properties /// /// 当前动作的名称。 /// public string ActionName => (_do != null) ? _do.Name : ""; #endregion #region Methods /// /// 比较当前动作是否和指定DO的指定输出状态相同。 /// /// /// /// public bool IsSame(string doName, bool value) { return doName == _do.Name && _targetValue == value; } /// /// 扫描当前动作的条件,并设置相关DO的输出状态。 /// public bool DaemonMonitor(out string reason) { reason = ""; var info = new StringBuilder(); foreach (var limit in _limits) { if (!limit.CanDo(out _)) return false; info.AppendLine($"\t{limit}"); } // 到这里表示所有的Condition均满足条件 // 如果DO输出已经满足要求,则直接退出 if (_do.Value == _targetValue) return false; // 设置DO输出 if (_do.SetValue(_targetValue, out reason)) reason = info.ToString().TrimEnd('\r', '\n'); info.Insert(0, $"Interlock Force set DO-{_do.IoTableIndex}({_do.Name}) = [{((_targetValue) ? "ON" : "OFF")}]\r\n"); return true; } public override string ToString() { return $"{ActionName}, Action={_targetValue}, Condition Count={_limits.Count}"; } #endregion }