public void ReloveReceivedData(string dtuid, byte[] bytes) { string dtunum = dtuid; int sensortype = bytes[TypeOfDataOfFrame]; string moduleId = BitConverter.ToInt16(bytes, ModuleNumOfFrame).ToString(); int channelid = bytes[ChannelIdOfFrame]; short wavelengthIndex = 0; IList <SensorInfo> sensorlist = new List <SensorInfo>(); foreach (SensorInfo sensor in DeceiveInfoDic.GetDeceiveInfoDic().DeceiveInfos[dtunum][sensortype][moduleId]) { if (sensor.DaiChannelNumber == channelid && short.Parse(sensor.UniqueSign) == wavelengthIndex) { sensorlist.Add(sensor); } } if (sensorlist.Count == 1) { int sensorid = sensorlist[0].SensorId; int safetype = sensorlist[0].SafetyFactorTypeId; int count = bytes[10]; int index = bytes[11]; int floatcount = (bytes.Length - 31) / 4; var values = new List <float>(); for (int i = 0; i < floatcount; i++) { float value = BitConverter.ToSingle(bytes, DataValueOfFrame + (4 * i)); values.Add(value); } } //光栅光纤数据 }
public void ReloveReceivedData(string dtuid, byte[] bytes) { string dtunum = dtuid; int sensortype = bytes[TypeOfDataOfFrame]; string moduleId = BitConverter.ToInt16(bytes, ModuleNumOfFrame).ToString(); int channelid = bytes[ChannelIdOfFrame]; // IList<SensorInfo> sensorlist = new List<SensorInfo>(); IList <SensorInfo> sensorlist = DeceiveInfoDic.GetDeceiveInfoDic().GeSensorInfosByChannel(dtuid, sensortype, moduleId, channelid); if (sensorlist.Count > 0) { DateTime time = DateTime.MinValue; StringBuilder str = new StringBuilder(); for (int si = 0; si < sensorlist.Count; si++) { int project = BitConverter.ToInt16(bytes, ProjectCodeOfFrame); int sensorid = sensorlist[si].SensorId; int safetype = sensorlist[si].SafetyFactorTypeId; var bll = new Bll(); string tableName = bll.GetTableName(safetype); int structureId = BitConverter.ToInt32(bytes, Structure); long ticks = BitConverter.ToInt64(bytes, AcqTimeOfFrame); time = new DateTime(ticks); int floatcount = (bytes.Length - 31) / 4; var values = new float[floatcount]; for (int i = 0; i < floatcount; i++) { float value = BitConverter.ToSingle(bytes, DataValueOfFrame + (4 * i)); values[i] = value; } str.Append(sensorid).Append(","); str.Append(time.ToString("yyyy-MM-dd HH:mm:ss.fff")).Append(","); float[] original; float[] calcu; if (sensortype == 15) { original = new float[values.Length - 2]; calcu = new float[2]; } else { original = new float[values.Length - 1]; calcu = new float[1]; } int j = original.Length; for (int i = 0; i < values.Length; i++) { if (i < j) { original[i] = values[i]; str.Append(values[i]).Append(","); } else { calcu[i - j] = values[i]; str.Append(values[i]).Append(","); } } bll.InsertOrigalData(sensorid, time, original); } try { if (!DeceiveInfoDic.GetDeceiveInfoDic().LastAcqTime.ContainsKey(dtuid)) { DeceiveInfoDic.GetDeceiveInfoDic().LastAcqTime.TryAdd(dtuid, time); } else { Log.Debug("比较"); if (DeceiveInfoDic.GetDeceiveInfoDic().LastAcqTime[dtuid] < time) { var msg = MakeMsgToDataCalc.MakeMsgToRequestDataCalc( Convert.ToInt32(dtuid), DeceiveInfoDic.GetDeceiveInfoDic().LastAcqTime[dtuid]); Log.DebugFormat("通知计算进程计算 MSG_ID={0},DTU={1},TIME={2}", msg.Id, dtuid, DeceiveInfoDic.GetDeceiveInfoDic().LastAcqTime[dtuid]); DeceiveInfoDic.GetDeceiveInfoDic().LastAcqTime[dtuid] = time; } } Log.Debug(str.ToString()); } catch (Exception ex) { StringBuilder msg = new StringBuilder(); str.Append(ex.Message + "::").Append(string.Format("[{0},{1},{2}]", dtuid, moduleId, channelid)).Append(">>").Append(ValueHelper.ByteToHexStr(bytes)); Log.ErrorFormat(msg.ToString()); } } else { StringBuilder str = new StringBuilder(); str.Append("未找到该传感器:").Append(string.Format("[{0},{1},{2}]", dtuid, moduleId, channelid)).Append(">>").Append(ValueHelper.ByteToHexStr(bytes)); Log.ErrorFormat(str.ToString()); } }
public void ReloveReceivedData(string dtuid, byte[] bytes) { int sensortype = bytes[TypeOfDataOfFrame]; string moduleId = BitConverter.ToInt16(bytes, ModuleNumOfFrame).ToString(); int channelid = bytes[ChannelIdOfFrame]; IList <SensorInfo> sensorlist = DeceiveInfoDic.GetDeceiveInfoDic().GeSensorInfosByChannel(dtuid, sensortype, moduleId, channelid); if (sensorlist.Count == 1) { int sensorid = sensorlist[0].SensorId; int safetype = sensorlist[0].SafetyFactorTypeId; int count = bytes[10]; int index = bytes[11]; double fre = BitConverter.ToSingle(bytes, 12); // ValueHelper.GetFloat(bytes, 12);//计算时间? int structureId = BitConverter.ToInt32(bytes, Structure); long ticks = BitConverter.ToInt64(bytes, AcqTimeOfFrame); var time = new DateTime(ticks); int floatcount = (bytes.Length - 33) / 4; double[] data = new double[floatcount]; for (int i = 0; i < floatcount; i++) { data[i] = BitConverter.ToSingle(bytes, DataValueOfFrame + (4 * i)); //ValueHelper.GetFloat(bytes, DataValueOfFrame + (4 * i)); } var fileParam = new FileParamStruct(); fileParam.diSampleFreq = fre; fileParam.diTestPointNum = moduleId + "_" + channelid; StringBuilder filename = new StringBuilder(); filename.Append(fileParam.diTestPointNum).Append("_").Append(time.ToString("yyyyMMddHHmmssfff")); if (bytes[16] == 1) { filename.Append("_TRI"); } try { //Directory.CreateDirectory(path); DirectoryInfo dir = new DirectoryInfo(path); if (!dir.Exists) { dir.Create(); } string filePath = path + filename; CreateParamsFile(filePath + ".sdb", fileParam); CreateDataFile(filePath + ".odb", data); } catch (Exception ex) { Log.FatalFormat(ex.Message); } if (index == count - 1) { string filePath = path + filename; MakeMsgToDataCalc.MakeMsgToRequestDataCalc(sensorid, filePath, time); } } else { Log.Error("不能确定唯一传感器:" + ValueHelper.ByteToHexStr(bytes)); } }