SoftDIGenerator.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Aitex.Core.Util;
  6. namespace Aitex.Core.RT.IOCore
  7. {
  8. /// <summary>
  9. /// 源DI 一段时间无变化,设置
  10. /// </summary>
  11. public class HoldDIMonitor
  12. {
  13. private DIAccessor diSource = null;
  14. private DIAccessor diDest = null;
  15. private DeviceTimer timer = new DeviceTimer();
  16. private bool last;
  17. private int period;
  18. private bool initValue;
  19. public HoldDIMonitor(string source, string dest, int period, bool value)
  20. {
  21. diSource = IO.DI[source];
  22. diDest = IO.DI[dest];
  23. this.period = period;
  24. initValue = value;
  25. }
  26. public void Gernerate()
  27. {
  28. if (last != diSource.Value)
  29. {
  30. timer.Start(period);
  31. }
  32. last = diSource.Value;
  33. diDest.RawData = initValue ? timer.IsTimeout() : !timer.IsTimeout();
  34. }
  35. }
  36. }