123456789101112131415161718192021222324252627282930313233343536373839404142 |
- using FreeRedis;
- using System;
- using WCS.Entity.Protocol;
- namespace WCS_Client
- {
- public static class eqpData
- {
- /// <summary>
- /// 当前最新数据
- /// </summary>
- public static DeviceDataPack deviceDataPack { get; set; } = null;
- /// <summary>
- /// 上一次更新出来的数据
- /// </summary>
- public static DeviceDataPack oldDeviceDataPack { get; set; } = null;
- private static System.Timers.Timer _timer;
- public static RedisClient Redis = null;
- public static void init(RedisClient redis)
- {
- Redis = redis;
- _timer = new System.Timers.Timer(5000);
- _timer.Elapsed += new System.Timers.ElapsedEventHandler(GetData);//到达时间的时候执行事件;
- _timer.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
- _timer.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件;
- }
- public static void GetData(object sender, EventArgs e)
- {
- try
- {
- oldDeviceDataPack = deviceDataPack;
- deviceDataPack = Redis.Get<DeviceDataPack>("DeviceDataPack");
- }
- catch (Exception ex)
- {
- }
- }
- }
- }
|