终端一体化运控平台
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

74 líneas
1.8 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Collections.Concurrent;
  5. namespace BPASmartClient.Helper
  6. {
  7. /// <summary>
  8. /// 延时上升沿触发
  9. /// </summary>
  10. public class DelayRTrig
  11. {
  12. private volatile static ConcurrentDictionary<string, DelayRTrig> _Instance;
  13. public static DelayRTrig GetInstance(string name)
  14. {
  15. if (_Instance == null) _Instance = new ConcurrentDictionary<string, DelayRTrig>();
  16. if (!_Instance.ContainsKey(name)) _Instance.TryAdd(name, new DelayRTrig());
  17. return _Instance[name];
  18. }
  19. private DelayRTrig() { }
  20. /// <summary>
  21. /// 计时条件
  22. /// </summary>
  23. //public bool IN { get; set; }
  24. /// <summary>
  25. /// 当前时间
  26. /// </summary>
  27. public long ET { get; private set; } = 0;
  28. private bool flag1;
  29. public bool Q { get; private set; }
  30. private bool IN1
  31. {
  32. set
  33. {
  34. Q = value && !flag1;
  35. flag1 = value;
  36. }
  37. }
  38. private bool flag;
  39. DateTime startTime = new DateTime();
  40. /// <summary>
  41. /// 开始计时(时间单位/秒)
  42. /// </summary>
  43. /// <param name="PT">计时时间(单位 秒)</param>
  44. /// <returns></returns>
  45. public bool Start(bool IN, int PT)
  46. {
  47. if (IN)
  48. {
  49. if (!flag)
  50. {
  51. startTime = DateTime.Now;
  52. flag = true;
  53. }
  54. if (ET < PT) ET = Convert.ToInt64(DateTime.Now.Subtract(startTime).TotalSeconds);
  55. }
  56. else
  57. {
  58. ET = 0;
  59. flag = false;
  60. }
  61. IN1 = ET >= PT;
  62. return Q;
  63. }
  64. }
  65. }