InterlockAction.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.Design.Serialization;
  4. using System.Globalization;
  5. using System.Linq;
  6. using System.Text;
  7. namespace Aitex.Core.RT.IOCore
  8. {
  9. /*
  10. *
  11. <Action do="DO_MFC1_valve__" value="true" tip="" tip.zh-CN="" tip.en-US="">
  12. <Limit di="DI_Chamber_door_sw" value="true" tip="" tip.zh-CN="" tip.en-US="" />
  13. </Action>
  14. *
  15. */
  16. class InterlockAction
  17. {
  18. private List<InterlockLimit> _limits = new List<InterlockLimit>();
  19. private DOAccessor _do;
  20. private bool _actionValue;
  21. private string _tip;
  22. private Dictionary<string, string> _cultureTip = new Dictionary<string, string>();
  23. public InterlockAction(DOAccessor doItem, bool value, string tip, Dictionary<string, string> cultureTip, List<InterlockLimit> limits)
  24. {
  25. _do = doItem;
  26. _actionValue = value;
  27. _tip = tip;
  28. _cultureTip = cultureTip;
  29. _limits = limits;
  30. }
  31. public bool IsSame(string doName, bool value)
  32. {
  33. return (doName == _do.Name) && (_actionValue == value);
  34. }
  35. public bool Reverse(out string reason)
  36. {
  37. reason = string.Empty;
  38. if (_do.Value != _actionValue)
  39. return false;
  40. if (_do.SetValue(!_actionValue, out reason))
  41. {
  42. reason = string.Format("Force setting DO-{0}({1}) = [{2}]", _do.IoTableIndex, _do.Name, (!_actionValue) ? "ON" : "OFF");
  43. }
  44. return true;
  45. }
  46. public bool CanDo(out string reason)
  47. {
  48. reason = string.Empty;
  49. bool result = true;
  50. foreach (var interlockLimit in _limits)
  51. {
  52. string info;
  53. if (!interlockLimit.CanDo(out info))
  54. {
  55. if (reason.Length > 0)
  56. reason += "\n";
  57. else
  58. {
  59. reason = string.Format("Interlock triggered, DO-{0}({1}) can not be [{2}], {3} \n", _do.IoTableIndex, _do.Name, _actionValue ? "ON" : "OFF",
  60. _tip);
  61. }
  62. reason += info;
  63. result = false;
  64. }
  65. }
  66. return result;
  67. }
  68. }
  69. }