InterlockLimit.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using System.Collections.Generic;
  2. using Aitex.Core.Util;
  3. using DocumentFormat.OpenXml.Spreadsheet;
  4. namespace Aitex.Core.RT.IOCore
  5. {
  6. /*
  7. *
  8. <Action do="DO_MFC1_valve__" value="true" tip="" tip.zh-CN="" tip.en-US="">
  9. <Limit di="DI_Chamber_door_sw" value="true" tip="" tip.zh-CN="" tip.en-US="" />
  10. </Action>
  11. *
  12. */
  13. public abstract class InterlockLimit
  14. {
  15. public string Name
  16. {
  17. get { return _name; }
  18. }
  19. public abstract bool CurrentValue { get; }
  20. public abstract string LimitReason { get; }
  21. public bool LimitValue
  22. {
  23. get { return _limitValue; }
  24. }
  25. public string Tip
  26. {
  27. get
  28. {
  29. return _tip;
  30. }
  31. }
  32. private string _name;
  33. private bool _limitValue;
  34. private string _tip;
  35. private Dictionary<string, string> _cultureTip = new Dictionary<string, string>();
  36. R_TRIG _trigger = new R_TRIG();
  37. public InterlockLimit(string name, bool value, string tip, Dictionary<string, string> cultureTip)
  38. {
  39. _name = name;
  40. _limitValue = value;
  41. _tip = tip;
  42. _cultureTip = cultureTip;
  43. }
  44. public bool IsSame(string name, bool value)
  45. {
  46. return (name == _name) && (_limitValue == value);
  47. }
  48. public bool IsSame(InterlockLimit limit)
  49. {
  50. return (limit.Name == _name) && (_limitValue == limit.LimitValue);
  51. }
  52. public bool IsTriggered()
  53. {
  54. _trigger.CLK = CurrentValue != _limitValue;
  55. return _trigger.Q;
  56. }
  57. public bool CanDo(out string reason)
  58. {
  59. reason = string.Empty;
  60. if (CurrentValue == _limitValue)
  61. return true;
  62. reason = LimitReason;
  63. return false;
  64. }
  65. }
  66. internal class DiLimit:InterlockLimit
  67. {
  68. private DIAccessor _di;
  69. public DiLimit(DIAccessor diItem, bool value, string tip, Dictionary<string, string> cultureTip)
  70. :base(diItem.Name, value, tip, cultureTip)
  71. {
  72. _di = diItem;
  73. }
  74. public override bool CurrentValue
  75. {
  76. get { return _di.Value; }
  77. }
  78. public override string LimitReason
  79. {
  80. get
  81. {
  82. return string.Format("DI-{0}({1}) = [{2}],{3}", _di.IoTableIndex, _di.Name, _di.Value ? "ON" : "OFF", Tip);
  83. }
  84. }
  85. }
  86. internal class DoLimit : InterlockLimit
  87. {
  88. private DOAccessor _do;
  89. public DoLimit(DOAccessor doItem, bool value, string tip, Dictionary<string, string> cultureTip)
  90. : base(doItem.Name, value, tip, cultureTip)
  91. {
  92. _do = doItem;
  93. }
  94. public override bool CurrentValue
  95. {
  96. get { return _do.Value; }
  97. }
  98. public override string LimitReason
  99. {
  100. get
  101. {
  102. return string.Format("DO-{0}({1}) = [{2}],{3}", _do.IoTableIndex, _do.Name, _do.Value ? "ON" : "OFF", Tip);
  103. }
  104. }
  105. }
  106. public class CustomLimitBase : InterlockLimit
  107. {
  108. public CustomLimitBase(string name, bool limitValue, string tip, Dictionary<string, string> cultureTip) : base(name, limitValue, tip, cultureTip)
  109. {
  110. }
  111. public override bool CurrentValue { get; }
  112. public override string LimitReason { get; }
  113. }
  114. }