ToleranceChecker.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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.Tolerance
  7. {
  8. public class ToleranceChecker
  9. {
  10. private DeviceTimer _timer = new DeviceTimer();
  11. private R_TRIG _trigger = new R_TRIG();
  12. private bool _started;
  13. public bool Trig
  14. {
  15. get
  16. {
  17. return _trigger.Q;
  18. }
  19. }
  20. public bool Result
  21. {
  22. get
  23. {
  24. return _trigger.M;
  25. }
  26. }
  27. public bool RST
  28. {
  29. set
  30. {
  31. _started = false;
  32. _trigger.RST = value;
  33. }
  34. }
  35. public ToleranceChecker()
  36. {
  37. _timer.Start(0);
  38. }
  39. public ToleranceChecker(double time)
  40. {
  41. _timer.Start(time*1000);
  42. }
  43. public void Reset(double time)
  44. {
  45. _timer.Start(time * 1000);
  46. RST = true;
  47. }
  48. /// <summary>
  49. /// </summary>
  50. /// <param name="value"></param>
  51. /// <param name="min"></param>
  52. /// <param name="max"></param>
  53. /// <param name="time">unit is second</param>
  54. public void Monitor(double value, double min, double max, double timeS)
  55. {
  56. if (!_started || (value >= min && value <= max))
  57. {
  58. _started = true;
  59. _timer.Start(timeS * 1000);
  60. }
  61. _trigger.CLK = _timer.IsTimeout();
  62. }
  63. }
  64. }