ToleranceChecker.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 time)
  55. {
  56. if (!_started || (value >= min && value <= max))
  57. {
  58. _started = true;
  59. _timer.Start(time * 1000);
  60. }
  61. _trigger.CLK = _timer.IsTimeout();
  62. }
  63. public void MonitorBool(bool value, double time)
  64. {
  65. if (!_started || (value))
  66. {
  67. _started = true;
  68. _timer.Start(time * 1000);
  69. }
  70. _trigger.CLK = _timer.IsTimeout();
  71. }
  72. }
  73. }