SafePlcInterlockChecker.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Aitex.Core.Util;
  6. using Aitex.Core.RT.Event;
  7. using Aitex.Core.RT.Log;
  8. namespace Aitex.Core.RT.IOCore
  9. {
  10. public class SafePlcInterlockChecker
  11. {
  12. public SafePlcInterlockChecker(DOAccessor doo,DIAccessor di)
  13. {
  14. _do = doo;
  15. _di = di;
  16. _timer.Start(1000);
  17. }
  18. private DOAccessor _do = null;
  19. private DIAccessor _di = null;
  20. DeviceTimer _timer = new DeviceTimer();
  21. R_TRIG _trigInterlock = new R_TRIG();
  22. private string Module = "IO";
  23. //检查安全逻辑是否被触发动作
  24. public void Monitor()
  25. {
  26. if (_do == null || _di == null)
  27. {
  28. LOG.Warning(String.Format("SafePlcInterlockChecker do or di is null"));
  29. }
  30. else
  31. {
  32. bool setpoint = _do.Value;
  33. bool feedback = _di.Value;
  34. if (setpoint == feedback)
  35. _timer.Start(1000);
  36. _trigInterlock.CLK = (setpoint != feedback) && _timer.IsTimeout();
  37. if (_trigInterlock.Q)
  38. {
  39. //for DO and send alarm event
  40. string reason = string.Format("DO-{0}({1})被强制{2},原因是该数字量输出值不满足安全PLC的检查条件",
  41. _do.Index,
  42. _di.Name,
  43. setpoint ? "OFF" : "ON");
  44. EV.PostMessage(Module, EventEnum.SafePlcInterlock, Module, reason);
  45. _do.Value = feedback;
  46. }
  47. }
  48. }
  49. }
  50. }