InterlockAction.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 string ActionName => _do != null ? _do.Name : "";
  24. public InterlockAction(DOAccessor doItem, bool value, string tip, Dictionary<string, string> cultureTip, List<InterlockLimit> limits)
  25. {
  26. _do = doItem;
  27. _actionValue = value;
  28. _tip = tip;
  29. _cultureTip = cultureTip;
  30. _limits = limits;
  31. }
  32. public bool IsSame(string doName, bool value)
  33. {
  34. return (doName == _do.Name) && (_actionValue == value);
  35. }
  36. public bool Reverse(out string reason)
  37. {
  38. reason = string.Empty;
  39. if (_do.Value != _actionValue)
  40. return false;
  41. if (_do.SetValue(!_actionValue, out reason))
  42. {
  43. reason = string.Format("Force setting DO-{0}({1}) = [{2}]", _do.IoTableIndex, _do.Name, (!_actionValue) ? "ON" : "OFF");
  44. }
  45. return true;
  46. }
  47. public bool CanDo(out string reason)
  48. {
  49. reason = string.Empty;
  50. bool result = true;
  51. foreach (var interlockLimit in _limits)
  52. {
  53. string info;
  54. if (!interlockLimit.CanDo(out info))
  55. {
  56. if (reason.Length > 0)
  57. reason += "\n";
  58. else
  59. {
  60. reason = string.Format("Interlock triggered, DO-{0}({1}) can not be [{2}], {3} \n", _do.IoTableIndex, _do.Name, _actionValue ? "ON" : "OFF",
  61. _tip);
  62. }
  63. reason += info;
  64. result = false;
  65. }
  66. }
  67. return result;
  68. }
  69. }
  70. }