InterlockLimit.cs 3.6 KB

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