Ejemplo n.º 1
0
        /// <summary>
        /// 更新模块状态缓存
        /// </summary>
        /// <param name="sensorData">模块数据</param>
        private void updateCurModuleStateDic(SensorData sensorData)
        {
            ConcurrentDictionary <string, List <Param> > moduleDicCacheOk;

            log = LogFactory.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.FullName + ":" + MethodBase.GetCurrentMethod().Name);
            var fault = sensorData.Fault;
            //消除异常错误
            //将数据按机台分组
            //发来的数据是 机台 -----> 参数,而我的数据结构是 机台 ------->模块------>参数
            //所以要遍历多次
            var d = from s in sensorData.CollectedData group s by s.MachineID into t select t;

            try {
                //遍历机台
                foreach (var realParamList in d)
                {
                    //获取机台 Id
                    var machineId = realParamList.Key.Value;
                    //从缓存中找到机台
                    if (curModuleStateDic.TryGetValue(machineId, out moduleDicCacheOk))
                    {
                        //遍历实时参数
                        foreach (var realParam in realParamList)
                        {
                            //遍历缓存模块
                            foreach (var module in moduleDicCacheOk)
                            {
                                //遍历缓存参数
                                foreach (var param in module.Value)
                                {
                                    //  realParam.ParameterCodeID = 2;
                                    //找到缓存中的参数对象
                                    if (param.ParamCodeID == realParam.ParameterCodeID.ToString())
                                    {
                                        //参数正常,更新缓存值
                                        param.FaultValue = "1";
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                //添加异常错误
                ConcurrentDictionary <string, List <Param> > moduleDicCacheError;
                //有异常情况
                if (fault != null)
                {
                    var faultMachId = fault.MachineID;
                    //找该机台的出错到缓存
                    if (curModuleStateDic.TryGetValue(faultMachId.Value, out moduleDicCacheError))
                    {
                        //出错的模块
                        var          faultSerialNum = fault.SerialNum;
                        List <Param> faultParamList;
                        //找到出错的模块
                        if (moduleDicCacheError.TryGetValue(faultSerialNum, out faultParamList))
                        {
                            var faultState = fault.State.Split('-');
                            //不满足出错格式则不做任何处理
                            if (faultState.Length != 3)
                            {
                                log.Debug("更新错误缓存的错误状态值长度出错 " + faultState.Length);
                            }
                            else
                            {
                                //取出出错的状态码
                                var faultCode  = faultState[1];
                                var faultValue = faultState[2];
                                //遍历模块下面的参数
                                foreach (var faultParam in faultParamList)
                                {
                                    //找到出错的参数
                                    if (faultParam.ParamCode == faultCode)
                                    {
                                        //更新出错参数的错误值
                                        faultParam.FaultValue = faultValue;
                                        break;
                                    }
                                }
                                log.Debug("更新错误缓存中没有该参数 " + faultCode);
                            }
                        }
                        else
                        {
                            log.Debug("更新错误缓存中没有该模块 " + faultSerialNum);
                        }
                    }
                    else
                    {
                        log.Debug("更新错误缓存中没有该机台 " + faultMachId);
                    }
                }
            } catch (Exception e) {
                log.Error("更新错误状态失败", e);
            }
        }
Ejemplo n.º 2
0
        private void TestUpdateSensorData(SensorData sensorData)
        {
            //将接受的数据封装成需要的数据
            var retData = sensorDataBiz.GetSensorData(sensorData);
            //按机台分组,即接受到的数据所包含的机台
            var groupData = (from d in sensorData.CollectedData group d by d.MachineID into g select g);

            //取出机台收到的参数
            foreach (var data in groupData)
            {
                var    machineId  = data.Key.Value;
                string curMeters  = "";
                string curAxisNum = "";


                //更新字典缓存
                updateDicCache(machineId, sensorData, out curMeters, out curAxisNum,
                               //轴号变动则通知前端浏览器清空数据
                               //相当于在线重新进行初始化数据
                               () => {
                    //TODO
                });

                VM_MachineProperty pty;
                //获取到该机台的属性
                if (curMachPtyDic.TryGetValue(machineId, out pty))
                {
                    //更新参数
                    pty.CurrentMeters = curMeters;
                    pty.AxisNum       = curAxisNum;
                    //最大最小线径
                    try {
                        var maxOd = (from d in data where d.ParameterCodeID == (int)SPEC_PARAM_CODE.OUTTER_OD select d).Max(d => decimal.Parse(d.CollectedValue));
                        var minOd = (from d in data where d.ParameterCodeID == (int)SPEC_PARAM_CODE.OUTTER_OD select d).Min(d => decimal.Parse(d.CollectedValue));
                        if (pty.ODMax.Value < maxOd)
                        {
                            pty.ODMax = maxOd;
                        }
                        if (pty.ODMin > minOd)
                        {
                            pty.ODMin = minOd;
                        }
                    } catch {
                    }
                }



                //拥有相同机台的前端连接
                var sameMachConnectionIds = new List <string>();
                if (clientsDic.TryGetValue(machineId, out sameMachConnectionIds))
                {
                    //挨个推送机台的实时数据
                    ConcurrentDictionary <string, List <Param> > moduleStateTab;
                    curModuleStateDic.TryGetValue(machineId, out moduleStateTab);
                    foreach (var conenctionId in sameMachConnectionIds)
                    {
                        //更新曲线参数
                        context.Clients.Client(conenctionId).
                        updateSensorData(
                            //数据
                            retData,
                            //当前米数
                            curMeters,
                            //该机台的错误表
                            moduleStateTab);

                        //更新机台属性
                        context.Clients.Client(conenctionId).updateMachinePty(pty);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void UpdateSensorData(DataDisplay.StructData dpData)
        {
            var sensorData = new SensorData();

            List <T_CollectedDataParameters> colData = new List <T_CollectedDataParameters>();
            List <T_CodeUsing> code = new List <T_CodeUsing>();

            try {
                if (!string.IsNullOrEmpty(dpData.datamain))
                {
                    dpData.datamain = dpData.datamain.Replace(":abc123", ":\"\"").Replace("\"abc123\"", "\"\"");
                    code            = JsonConvert.DeserializeObject <List <T_CodeUsing> >(dpData.datamain);
                }
                if (!string.IsNullOrEmpty(dpData.datadetail))
                {
                    dpData.datadetail = dpData.datadetail.Replace(":abc123", ":\"\"").Replace("\"abc123\"", "\"\"");
                    colData           = JsonConvert.DeserializeObject <List <T_CollectedDataParameters> >(dpData.datadetail);
                }
                if (!string.IsNullOrEmpty(dpData.faultdata))
                {
                    sensorData.Fault = JsonConvert.DeserializeObject <T_FaultModule>(dpData.faultdata);
                }
                sensorData.CodeUsing     = code;
                sensorData.CollectedData = colData;
                updateCurModuleStateDic(sensorData);
            } catch (Exception e) {
                Debug.Write(e.ToString());
                return;
            }
            mapParamCode(sensorData);
            #region 来自于中心服务器测试数据
            ////++testMeters;
            //Random random = new Random();
            //timer = new Timer(testTimerHub,null,random.Next(1000,5000),0);
            //List<T_CollectedDataParameters> colData = new List<T_CollectedDataParameters> {
            //    //现场温度
            //    new T_CollectedDataParameters {
            //        CollectedTime =DateTime.UtcNow,
            //        CollectedValue =  random.Next(-20,100).ToString(),
            //        ParameterCodeID = 3,
            //        MachineID = 22
            //    },
            //    //六段温度
            //  new T_CollectedDataParameters {
            //        CollectedTime = DateTime.Now.AddMilliseconds(500),
            //        CollectedValue =  random.Next(1,3).ToString(),
            //        ParameterCodeID = (int) SPEC_PARAM_CODE.INNER_OD,
            //        MachineID = 22
            //    },
            // new T_CollectedDataParameters {
            //        CollectedTime = DateTime.Now.AddMilliseconds(500),
            //        CollectedValue =  random.Next(2,5).ToString(),
            //        ParameterCodeID = (int)SPEC_PARAM_CODE.OUTTER_OD,
            //        MachineID = 22
            //    },
            // new T_CollectedDataParameters {
            //        CollectedTime = DateTime.Now.AddMilliseconds(500),
            //        CollectedValue =  random.Next(-20,100).ToString(),
            //        ParameterCodeID = 16,
            //        MachineID = 22
            //    },
            // new T_CollectedDataParameters {
            //        CollectedTime = DateTime.Now.AddMilliseconds(500),
            //        CollectedValue =  random.Next(-20,100).ToString(),
            //        ParameterCodeID = 18,
            //        MachineID = 22
            //    },
            // new T_CollectedDataParameters {
            //        CollectedTime = DateTime.Now.AddMilliseconds(500),
            //        CollectedValue =  random.Next(-20,100).ToString(),
            //        ParameterCodeID = 20,
            //        MachineID = 22
            //    },
            // new T_CollectedDataParameters {
            //        CollectedTime = DateTime.Now.AddMilliseconds(500),
            //        CollectedValue =  random.Next(-20,100).ToString(),
            //        ParameterCodeID = 22,
            //        MachineID = 22
            //    },};
            ////收到米数
            //if(testMetersTrigger % 5 == 0) {
            //    ++testMeters;
            //    //colData.Add(new T_CollectedDataParameters {
            //    //    CollectedTime = DateTime.Now.AddMilliseconds(500),
            //    //    CollectedValue = testMeters.ToString(),
            //    //    ParameterCodeID = (int)SPEC_PARAM_CODE.METERS_COUNT,
            //    //    MachineID = 22
            //    //});
            //}
            //List<T_CodeUsing> code = new List<T_CodeUsing>();
            ////模拟每100米更换一次轴号
            //if(testMeters % 2 == 0) {
            //    //code.Add(new T_CodeUsing {
            //    //    Axis_No = "CPXXtestxxxxyyy",
            //    //    GeneratorTime = DateTime.Now,
            //    //    MachineID = 22,
            //    //    CodeNumber = "12456464650"

            //    //});
            //}

            //反序列化的数据
            //sensorData.CodeUsing = code;
            //sensorData.CollectedData = colData;
            #endregion

            //将接受的数据封装成需要的数据
            var retData = sensorDataBiz.GetSensorData(sensorData);
            //按机台分组,即接受到的数据所包含的机台
            var groupData = (from d in sensorData.CollectedData group d by d.MachineID into g select g);
            //取出机台收到的参数
            foreach (var data in groupData)
            {
                var    machineId  = data.Key.Value;
                string curMeters  = "";
                string curAxisNum = "";


                //更新字典缓存
                updateDicCache(machineId, sensorData, out curMeters, out curAxisNum,
                               //轴号变动则通知前端浏览器清空数据
                               //相当于在线重新进行初始化数据
                               () => {
                    //TODO
                });

                VM_MachineProperty pty = new VM_MachineProperty();
                //获取到该机台的属性
                if (curMachPtyDic.TryGetValue(machineId, out pty))
                {
                    //更新参数
                    pty.CurrentMeters = curMeters;
                    pty.AxisNum       = curAxisNum;
                    //最大最小线径
                    try {
                        var maxOd = (from d in data where d.ParameterCodeID == (int)SPEC_PARAM_CODE.OUTTER_OD select d).Max(d => decimal.Parse(d.CollectedValue));
                        var minOd = (from d in data where d.ParameterCodeID == (int)SPEC_PARAM_CODE.OUTTER_OD select d).Min(d => decimal.Parse(d.CollectedValue));
                        if (pty.ODMax.Value < maxOd)
                        {
                            pty.ODMax = maxOd;
                        }
                        if (pty.ODMin > minOd)
                        {
                            pty.ODMin = minOd;
                        }
                    } catch (Exception e) {
                    }
                }



                //拥有相同机台的前端连接
                var sameMachConnectionIds = new List <string>();
                if (clientsDic.TryGetValue(machineId, out sameMachConnectionIds))
                {
                    //挨个推送机台的实时数据
                    ConcurrentDictionary <string, List <Param> > moduleStateTab;
                    curModuleStateDic.TryGetValue(machineId, out moduleStateTab);
                    foreach (var conenctionId in sameMachConnectionIds)
                    {
                        //更新曲线参数
                        context.Clients.Client(conenctionId).
                        updateSensorData(
                            //数据
                            retData,
                            //当前米数
                            curMeters,
                            //该机台的错误表
                            moduleStateTab);

                        //更新机台属性
                        context.Clients.Client(conenctionId).updateMachinePty(pty);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public void testTimerHub(object state)
        {
            ins++;

            var sensorData = new SensorData();

            sensorData.CollectedData = new List <T_CollectedDataParameters>();

            Random random = new Random();

            foreach (var machineItem in curMachPtyDic)
            {
                //OD值
                sensorData.CollectedData.Add(new T_CollectedDataParameters {
                    MachineID       = machineItem.Key,
                    CollectedTime   = DateTime.Now,
                    CollectedValue  = (random.NextDouble() * 8 + 15).ToString(),
                    ParameterCodeID = 2
                });
                sensorData.CollectedData.Add(new T_CollectedDataParameters {
                    MachineID       = machineItem.Key,
                    CollectedTime   = DateTime.Now,
                    CollectedValue  = (random.NextDouble() * 8 + 10).ToString(),
                    ParameterCodeID = 41
                });
                if (ins >= 5)
                {
                    ins = 0;
                    //一段温度显示值
                    sensorData.CollectedData.Add(new T_CollectedDataParameters {
                        MachineID       = machineItem.Key,
                        CollectedTime   = DateTime.Now,
                        CollectedValue  = (random.NextDouble() * 20 + 185).ToString(),
                        ParameterCodeID = 12
                    });
                    //二段温度显示值
                    sensorData.CollectedData.Add(new T_CollectedDataParameters {
                        MachineID       = machineItem.Key,
                        CollectedTime   = DateTime.Now,
                        CollectedValue  = (random.NextDouble() * 20 + 185).ToString(),
                        ParameterCodeID = 14
                    });
                    //三段温度显示值
                    sensorData.CollectedData.Add(new T_CollectedDataParameters {
                        MachineID       = machineItem.Key,
                        CollectedTime   = DateTime.Now,
                        CollectedValue  = (random.NextDouble() * 20 + 185).ToString(),
                        ParameterCodeID = 16
                    });
                    //四段温度显示值
                    sensorData.CollectedData.Add(new T_CollectedDataParameters {
                        MachineID       = machineItem.Key,
                        CollectedTime   = DateTime.Now,
                        CollectedValue  = (random.NextDouble() * 20 + 185).ToString(),
                        ParameterCodeID = 18
                    });
                }
            }

            sensorData.CodeUsing = new List <T_CodeUsing>();
            TestUpdateSensorData(sensorData);
        }