InterlockLimit.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System.Collections.Generic;
  2. using System.Runtime.InteropServices;
  3. using Aitex.Core.Util;
  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. internal class InterlockLimit
  14. {
  15. public string Name
  16. {
  17. get { return _di.Name; }
  18. }
  19. public bool Value
  20. {
  21. get { return _limitValue; }
  22. }
  23. public string Tip
  24. {
  25. get
  26. {
  27. return _tip;
  28. }
  29. }
  30. public string Module
  31. {
  32. get { return _module; }
  33. }
  34. private DIAccessor _di;
  35. private bool _limitValue;
  36. private string _tip;
  37. private string _module;
  38. private Dictionary<string, string> _cultureTip = new Dictionary<string, string>();
  39. R_TRIG _trigger = new R_TRIG();
  40. public InterlockLimit(DIAccessor diItem, bool value, string tip, Dictionary<string, string> cultureTip, string module)
  41. {
  42. _di = diItem;
  43. _limitValue = value;
  44. _tip = tip;
  45. _cultureTip = cultureTip;
  46. _module = module;
  47. }
  48. public bool IsSame(string diName, bool value)
  49. {
  50. return (diName == _di.Name) && (_limitValue == value);
  51. }
  52. public bool IsSame(InterlockLimit limit)
  53. {
  54. return (limit.Name == _di.Name) && (_limitValue == limit.Value);
  55. }
  56. public bool IsTriggered()
  57. {
  58. _trigger.CLK = _di.Value != _limitValue;
  59. return _trigger.Q;
  60. }
  61. public bool CanDo(out string reason)
  62. {
  63. reason = string.Empty;
  64. if (_di.Value == _limitValue)
  65. return true;
  66. reason = string.Format("DI-{0}({1}) = [{2}],{3}", _di.IoTableIndex, _di.Name, _di.Value ? "ON" : "OFF", _tip);
  67. return false;
  68. }
  69. }
  70. }