Exemplo n.º 1
0
 /// <summary>
 /// 添加设备信息
 /// </summary>
 /// <param name="result63ReadBase"></param>
 public void AddDeviceData(Result63ReadBase result63ReadBase)
 {
     if (_deviceCache.ContainsKey(result63ReadBase.Num))
     {
         _deviceCache.Remove(result63ReadBase.Num);
     }
     _deviceCache.Add(result63ReadBase.Num, result63ReadBase);
 }
Exemplo n.º 2
0
 /// <summary>
 /// 获取单个设备缓存
 /// </summary>
 /// <param name="num"></param>
 /// <returns></returns>
 public Result63ReadBase GetDeviceData(int num)
 {
     if (_deviceCache.ContainsKey(num))
     {
         Result63ReadBase obj = _deviceCache[num];
         return(obj);
     }
     return(null);
 }
Exemplo n.º 3
0
        /// <summary>
        /// 根据返回结果 转化JSON
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public override string BuildResultDataJson(byte[] data, EnumDeviceType enumDeviceType)
        {
            string str = "无此类型设备";

            Result63ReadBase result63ReadBase = null;

            if (enumDeviceType == EnumDeviceType.电表)
            {
                Result63ReadAmmeter res = new Result63ReadAmmeter(DeviceNum, data);
                result63ReadBase = res;
                //PLCDeviceCacheObject.Instance[res.Num.ToString()] = res;
                str = JsonConvert.SerializeObject(res);
            }
            else if (enumDeviceType == EnumDeviceType.水表)
            {
                Result63ReadWatermeter res = new Result63ReadWatermeter(DeviceNum, data);
                //PLCDeviceCacheObject.Instance[res.Num.ToString()] = res;
                result63ReadBase = res;
                str = JsonConvert.SerializeObject(res);
            }
            else if (enumDeviceType == EnumDeviceType.阀门)
            {
                Result63ReadValve res = new Result63ReadValve(DeviceNum, data);
                //PLCDeviceCacheObject.Instance[res.Num.ToString()] = res;
                result63ReadBase = res;
                str = JsonConvert.SerializeObject(res);
            }
            else if (enumDeviceType == EnumDeviceType.温度)
            {
                Result63ReadTemperature res = new Result63ReadTemperature(DeviceNum, data);
                //PLCDeviceCacheObject.Instance[res.Num.ToString()] = res;
                result63ReadBase = res;
                str = JsonConvert.SerializeObject(res);
            }
            else if (enumDeviceType == EnumDeviceType.湿度)
            {
                Result63ReadHumidity res = new Result63ReadHumidity(DeviceNum, data);
                //PLCDeviceCacheObject.Instance[res.Num.ToString()] = res;
                result63ReadBase = res;
                str = JsonConvert.SerializeObject(res);
            }
            else if (enumDeviceType == EnumDeviceType.灯控)
            {
                Result63ReadLight res = new Result63ReadLight(DeviceNum, data);
                //PLCDeviceCacheObject.Instance[res.Num.ToString()] = res;
                result63ReadBase = res;
                str = JsonConvert.SerializeObject(res);
            }
            else if (enumDeviceType == EnumDeviceType.光感度)
            {
                Result63ReadOptical res = new Result63ReadOptical(DeviceNum, data);
                //PLCDeviceCacheObject.Instance[res.Num.ToString()] = res;
                result63ReadBase = res;
                str = JsonConvert.SerializeObject(res);
            }
            else if (enumDeviceType == EnumDeviceType.水浸)
            {
                Result63ReadWater res = new Result63ReadWater(DeviceNum, data);
                //PLCDeviceCacheObject.Instance[res.Num.ToString()] = res;
                result63ReadBase = res;
                str = JsonConvert.SerializeObject(res);
            }

            if (result63ReadBase != null)
            {
                PLCDeviceCacheObject.Instance.AddDeviceData(result63ReadBase);
            }



            return(str);
        }