eqpData.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using FreeRedis;
  2. using System;
  3. using WCS.Entity.Protocol;
  4. namespace WCS_Client
  5. {
  6. public static class eqpData
  7. {
  8. /// <summary>
  9. /// 当前最新数据
  10. /// </summary>
  11. public static DeviceDataPack deviceDataPack { get; set; } = null;
  12. /// <summary>
  13. /// 上一次更新出来的数据
  14. /// </summary>
  15. public static DeviceDataPack oldDeviceDataPack { get; set; } = null;
  16. private static System.Timers.Timer _timer;
  17. public static RedisClient Redis = null;
  18. public static void init(RedisClient redis)
  19. {
  20. Redis = redis;
  21. _timer = new System.Timers.Timer(5000);
  22. _timer.Elapsed += new System.Timers.ElapsedEventHandler(GetData);//到达时间的时候执行事件;
  23. _timer.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
  24. _timer.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件;
  25. }
  26. public static void GetData(object sender, EventArgs e)
  27. {
  28. try
  29. {
  30. oldDeviceDataPack = deviceDataPack;
  31. deviceDataPack = Redis.Get<DeviceDataPack>("DeviceDataPack");
  32. }
  33. catch (Exception ex)
  34. {
  35. }
  36. }
  37. }
  38. }