using System; using System.Collections.Generic; using System.ComponentModel.Design.Serialization; using System.Globalization; using System.Linq; using System.Text; namespace Aitex.Core.RT.IOCore { /* * * */ class InterlockAction { private List _limits = new List(); private DOAccessor _do; private bool _actionValue; private string _tip; private Dictionary _cultureTip = new Dictionary(); public string ActionName => _do != null ? _do.Name : ""; public InterlockAction(DOAccessor doItem, bool value, string tip, Dictionary cultureTip, List limits) { _do = doItem; _actionValue = value; _tip = tip; _cultureTip = cultureTip; _limits = limits; } public bool IsSame(string doName, bool value) { return (doName == _do.Name) && (_actionValue == value); } public bool Reverse(out string reason) { reason = string.Empty; if (_do.Value != _actionValue) return false; if (_do.SetValue(!_actionValue, out reason)) { reason = string.Format("Force setting DO-{0}({1}) = [{2}]", _do.IoTableIndex, _do.Name, (!_actionValue) ? "ON" : "OFF"); } return true; } public bool CanDo(out string reason) { reason = string.Empty; bool result = true; foreach (var interlockLimit in _limits) { string info; if (!interlockLimit.CanDo(out info)) { if (reason.Length > 0) reason += "\n"; else { reason = string.Format("Interlock triggered, DO-{0}({1}) can not be [{2}], {3} \n", _do.IoTableIndex, _do.Name, _actionValue ? "ON" : "OFF", _tip); } reason += info; result = false; } } return result; } } }