public static string GetProgramNameCaption(SensorEntity sensor, string programName) { int idParent = 0; if (Convert.ToInt32(sensor.SensorType).Equals(Convert.ToInt32(Common.Consts.SensorType.Sterilizer))) { // 灭菌 idParent = 13; } else if (Convert.ToInt32(sensor.SensorType).Equals(Convert.ToInt32(Common.Consts.SensorType.Washer))) { // 清洗 idParent = 14; } else { return(string.Empty); } SensorHelper <object> helper = new SensorHelper <object>(); AssistDataEntity entity = helper.SelectSingle <AssistDataEntity>("FParentID = " + idParent.ToString() + " and fkey = '" + programName + "'", string.Empty); if (entity == null) { return(programName); } else { return(entity.FCaption); } }
private SensorStatusDTO GetStatusData(SensorDataHeadEntity eHead) { SensorStatusDTO dtoStatus = new SensorStatusDTO(); dtoStatus.SensorCaption = mSensor.SensorName; dtoStatus.SensorStatus = mSensor.PositionMark; StatusItemDTO item = null; SensorHelper <object> helper = new SensorHelper <object>(); SensorDataLineEntity eLine = helper.SelectSingle <SensorDataLineEntity>(string.Format("SensorDataHeadID = '{0}'", eHead.SensorDataHeadID.ToString().ToUpper()), "ReceivedDate DESC"); if (eLine != null) { dtoStatus.SensorDate = eLine.SensorDate; dtoStatus.ReceivedDate = eLine.ReceivedDate; // Temperature AddValueNumberToStatus(dtoStatus, eLine.ValueNumber1, Properties.Resource.TemperatureSeries); AddValueNumberToStatus(dtoStatus, eLine.ValueNumber2, Properties.Resource.PressureSeries); AddValueNumberToStatus(dtoStatus, eLine.ValueNumber3, Properties.Resource.HumiditySeries); AddValueNumberToStatus(dtoStatus, eLine.ValueNumber4, Properties.Resource.VoltageSeries); // 确定更新时间 if (eLine.SensorDate != null && eLine.SensorDate.HasValue) { item = new StatusItemDTO(Properties.Resource.UpdatedTime, StatusItemDTO.StatusItemType.DateTimeValue, eLine.SensorDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); dtoStatus.StatusData.Add(item); } } return(dtoStatus); }
public ChartDTO GetChartData(string sdhID) { //mSyncLast = null; IsNew = true; mShowPropertyDic = GetShowPropertyData(); // 刷新状态 SensorHelper <object> helper = new SensorHelper <object>(); mSensor = helper.SelectSingle <SensorEntity>(string.Format("SensorID = '{0}'", mSensor.SensorID.ToString().ToUpper()), string.Empty); SensorDataHeadBll bllHead = new SensorDataHeadBll(); SensorDataHeadEntity eHead = bllHead.GetEntity(new Guid(sdhID)); if (eHead == null) { return(null); } else { if (eHead.IsCompressed != null && eHead.IsCompressed.HasValue && eHead.IsCompressed.Value) { // 已压缩 mIsCompressed = true; mSensorCompressedData = new SensorCompressedDataHelper(eHead); } return(GetChartDataByHead(eHead)); } }
public ChartDTO GetChartDataInc(DateTime?lastReceivedDate, bool canChangeHead) { //mSyncLast = null; IsNew = false; // 刷新状态 SensorHelper <object> helper = new SensorHelper <object>(); mSensor = helper.SelectSingle <SensorEntity>(string.Format("SensorID = '{0}'", mSensor.SensorID.ToString().ToUpper()), string.Empty); SensorDataHeadBll bllHead = new SensorDataHeadBll(); SensorDataHeadEntity eHead = bllHead.GetNewestSensorDataHeadBySensorID(Sensor.SensorID.ToString().ToUpper()); if (eHead == null) { return(null); } else { if (eHead.IsCompressed != null && eHead.IsCompressed.HasValue && eHead.IsCompressed.Value) { ChartDTO chartData = new ChartDTO(); chartData.IsAxisXCustomLabels = false; chartData.ChartTitle = GetChartTitle(); chartData.IsReset = true; return(chartData); } if (mHeadEntity != null && eHead.SensorDataHeadID == mHeadEntity.SensorDataHeadID && lastReceivedDate != null && lastReceivedDate.HasValue) { return(GetChartDataInc(eHead, lastReceivedDate.Value)); } else { if (canChangeHead) { mSensorData = null; ChartDTO dtoChart = GetChartDataByHead(eHead); dtoChart.IsReset = true; IsNew = true; return(dtoChart); } else { return(null); } } } }
public SensorStatusDTO GetStatusData() { // 刷新状态 SensorHelper <object> helper = new SensorHelper <object>(); mSensor = helper.SelectSingle <SensorEntity>(string.Format("SensorID = '{0}'", mSensor.SensorID.ToString().ToUpper()), string.Empty); SensorDataHeadBll bllHead = new SensorDataHeadBll(); SensorDataHeadEntity eHead = bllHead.GetNewestSensorDataHeadBySensorID(Sensor.SensorID.ToString().ToUpper()); if (eHead == null) { SensorStatusDTO dtoStatus = new SensorStatusDTO(); dtoStatus.SensorCaption = mSensor.SensorName; dtoStatus.SensorStatus = mSensor.PositionMark; return(dtoStatus); } if (eHead.IsCompressed != null && eHead.IsCompressed.HasValue && eHead.IsCompressed.Value) { SensorStatusDTO dtoStatus = new SensorStatusDTO(); dtoStatus.SensorCaption = mSensor.SensorName; dtoStatus.SensorStatus = mSensor.PositionMark; return(dtoStatus); } if (Convert.ToInt32(Sensor.SensorType).Equals(Convert.ToInt32(Common.Consts.SensorType.Sterilizer))) { // 灭菌 return(GetStatusData(eHead)); } else if (Convert.ToInt32(Sensor.SensorType).Equals(Convert.ToInt32(Common.Consts.SensorType.Washer))) { // 清洗 return(GetStatusData(eHead)); } else { logger.WarnFormat("未处理的设备类型([传感器:{0},设备类型:{1}])", Sensor.SensorKey, Sensor.SensorType); return(null); } }
public ChartDTO GetChartData() { mSyncLast = null; mDataDic = new Dictionary <string, DataRow[]>(); IsNew = true; mProgramData = null; mShowPropertyDic = GetShowPropertyData(); // 刷新状态 SensorHelper <object> helper = new SensorHelper <object>(); mSensor = helper.SelectSingle <SensorEntity>(string.Format("SensorID = '{0}'", mSensor.SensorID.ToString().ToUpper()), string.Empty); SensorDataHeadBll bllHead = new SensorDataHeadBll(); SensorDataHeadEntity eHead = bllHead.GetNewestSensorDataHeadBySensorID(Sensor.SensorID.ToString().ToUpper()); if (eHead == null) { ChartDTO chartData = new ChartDTO(); chartData.ChartTitle = GetChartTitle(); return(chartData); } else { if (eHead.IsCompressed != null && eHead.IsCompressed.HasValue && eHead.IsCompressed.Value) { ChartDTO chartData = new ChartDTO(); chartData.ChartTitle = GetChartTitle(); return(chartData); } //SensorDataLineBll bllLine = new SensorDataLineBll(); //mSectionList = bllLine.GetSensorDataLineByDataType(eHead.SensorDataHeadID.ToString(), Utility.GetEnumValue(DataType.Body_SectionTitle)); mProgramData = GetProgramData(eHead); return(GetChartDataByHead(eHead)); } }
public ChartDTO GetChartData() { //mSyncLast = null; IsNew = true; mShowPropertyDic = GetShowPropertyData(); // 刷新状态 SensorHelper <object> helper = new SensorHelper <object>(); mSensor = helper.SelectSingle <SensorEntity>(string.Format("SensorID = '{0}'", mSensor.SensorID.ToString().ToUpper()), string.Empty); SensorDataHeadBll bllHead = new SensorDataHeadBll(); SensorDataHeadEntity eHead = bllHead.GetNewestSensorDataHeadBySensorID(Sensor.SensorID.ToString().ToUpper()); if (eHead == null) { ChartDTO chartData = new ChartDTO(); chartData.IsAxisXCustomLabels = false; chartData.ChartTitle = GetChartTitle(); return(chartData); } else { if (eHead.IsCompressed != null && eHead.IsCompressed.HasValue && eHead.IsCompressed.Value) { ChartDTO chartData = new ChartDTO(); chartData.IsAxisXCustomLabels = false; chartData.ChartTitle = GetChartTitle(); return(chartData); } return(GetChartDataByHead(eHead)); } }
private SensorStatusDTO GetStatusData(SensorDataHeadEntity eHead) { SensorStatusDTO dtoStatus = new SensorStatusDTO(); dtoStatus.SensorCaption = mSensor.SensorName; dtoStatus.SensorStatus = mSensor.PositionMark; StatusItemDTO item = null; SensorHelper <object> helper = new SensorHelper <object>(); SensorDataLineEntity eLine = helper.SelectSingle <SensorDataLineEntity>(string.Format("SensorDataHeadID = '{0}'", eHead.SensorDataHeadID.ToString().ToUpper()), "ReceivedDate DESC"); if (eLine != null) { dtoStatus.ProgressMark = GetProgressMark(eHead, eLine); dtoStatus.ErrorData = Utility.GetSensorErrors(eHead, eLine.ReceivedDate); dtoStatus.SensorDate = eLine.SensorDate; dtoStatus.ReceivedDate = eLine.ReceivedDate; IList <SensorDataLineValueEntity> lstLineValue = helper.SelectList <SensorDataLineValueEntity>(string.Format("SensorDataLineID = '{0}'", eLine.SensorDataLineID.ToString().ToUpper()), string.Empty); if (lstLineValue != null && lstLineValue.Count > 0) { string temp = string.Empty; AddContentStringToStatus(dtoStatus, lstLineValue, SystemData.Status.ToString()); // 程序 AddContentStringToStatus(dtoStatus, lstLineValue, SystemData.ProgramNo.ToString()); AddContentStringToStatus(dtoStatus, lstLineValue, SystemData.ProgramName.ToString()); AddContentStringToStatus(dtoStatus, lstLineValue, SystemData.ProgramPhase.ToString()); AddProgramNameCaption(dtoStatus); // MeasurementSensor1 ~ MeasurementSensor7 AddContentNumberToStatus(dtoStatus, lstLineValue, SystemData.MeasurementSensor1.ToString()); AddContentNumberToStatus(dtoStatus, lstLineValue, SystemData.MeasurementSensor2.ToString()); AddContentNumberToStatus(dtoStatus, lstLineValue, SystemData.MeasurementSensor3.ToString()); AddContentNumberToStatus(dtoStatus, lstLineValue, SystemData.MeasurementSensor4.ToString()); AddContentNumberToStatus(dtoStatus, lstLineValue, SystemData.MeasurementSensor5.ToString()); AddContentNumberToStatus(dtoStatus, lstLineValue, SystemData.MeasurementSensor6.ToString()); AddContentNumberToStatus(dtoStatus, lstLineValue, SystemData.MeasurementSensor7.ToString()); // 已用时间 if (eLine.SensorDate != null && eLine.SensorDate.HasValue) { TimeSpan tsUsed = eLine.SensorDate.Value.Subtract(eHead.BeginDate.Value); item = new StatusItemDTO(Properties.Resource.ElapsedTime, StatusItemDTO.StatusItemType.DoubleValue, tsUsed.TotalMinutes.ToString("f2")); dtoStatus.StatusData.Add(item); } // 确定更新时间 if (eLine.SensorDate != null && eLine.SensorDate.HasValue) { item = new StatusItemDTO(Properties.Resource.UpdatedTime, StatusItemDTO.StatusItemType.DateTimeValue, eLine.SensorDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); dtoStatus.StatusData.Add(item); } } } return(dtoStatus); }
private void AnalyseData(IList <string> row, string strByteData) { string sysNo = ParseHelper.ParseString(row[(int)SystemData.SystemNo]); string batchNo = ParseHelper.ParseString(row[(int)SystemData.BatchNo]); DateTime timestamp = ConvertDate(row[(int)SystemData.Timestamp]); SensorHelper <object> helperSensor = new SensorHelper <object>(); SensorEntity eSensor = helperSensor.SelectSingle <SensorEntity>(string.Format("SensorGroup = '{0}' AND SensorKey = '{1}'", mSensorGroup, sysNo), string.Empty); if (eSensor == null) { logger.WarnFormat("系统中组和编号为:[{0}].[{1}]的设备没有登记。", mSensorGroup, sysNo); return; } SensorDataHeadEntity eHead = helperSensor.SelectSingle <SensorDataHeadEntity>(string.Format("SensorID = '{0}' AND DataKey = '{1}'", eSensor.SensorID.ToString().ToUpper(), batchNo), string.Empty); Enumerator.BelimedStatus status;//0-Off,1-On,2-Run,3-End try { status = (Enumerator.BelimedStatus)Enum.Parse(typeof(Enumerator.BelimedStatus), row[(int)SystemData.Status]); } catch (Exception ex) { logger.ErrorFormat("传感器状态取得失败,状态值:[{0}]", row[(int)SystemData.Status]); throw ex; } System.Threading.Monitor.Enter(Monitor.Common.Utility.SyncSqlLock); try { logger.Info("开始保存数据。"); using (TransactionScope tran = Monitor.Common.Utility.GetTransactionScope()) { switch (status) { case Enumerator.BelimedStatus.Off: eSensor.PositionMark = status.ToString(); helperSensor.Update(eSensor); break; case Enumerator.BelimedStatus.On: eSensor.PositionMark = status.ToString(); helperSensor.Update(eSensor); break; case Enumerator.BelimedStatus.Run: if (eHead == null) { // 主数据 eHead = new SensorDataHeadEntity(); eHead.SensorDataHeadID = Guid.NewGuid(); eHead.SensorID = eSensor.SensorID; eHead.DataKey = batchNo; eHead.BeginDate = timestamp; eHead.IsCompressed = false; eHead.DataVer = DataVersion.V1.ToString(); helperSensor.Create(eHead); } eSensor.PositionMark = status.ToString(); helperSensor.Update(eSensor); // 原始数据 SensorDataRawLineEntity eRawLine = new SensorDataRawLineEntity(); eRawLine.SensorDataRawLineID = Guid.NewGuid(); eRawLine.SensorDataHeadID = eHead.SensorDataHeadID; eRawLine.ReceivedDate = DateTime.Now; eRawLine.RawData = strByteData; helperSensor.Create(eRawLine); // 解析数据 SensorDataLineEntity eLine = new SensorDataLineEntity(); eLine.SensorDataLineID = Guid.NewGuid(); eLine.SensorDataHeadID = eHead.SensorDataHeadID; eLine.SensorDataRawLineID = eRawLine.SensorDataRawLineID; eLine.ReceivedDate = eRawLine.ReceivedDate; eLine.SensorDate = timestamp; if (eLine.SensorDate != null && eLine.SensorDate.HasValue && eHead.BeginDate != null && eHead.BeginDate.HasValue) { eLine.SensorTimeSpan = Convert.ToInt64(eLine.SensorDate.Value.Subtract(eHead.BeginDate.Value).TotalMilliseconds); } //eLine.AnalysedData = row.ToString(); eLine.AnalysedData = string.Join(";", row.ToArray <string>()); helperSensor.Create(eLine); SensorDataLineValueEntity eLineValue = null; for (int i = 0; i < row.Count; i++) { eLineValue = new SensorDataLineValueEntity(); eLineValue.SensorDataLineValueID = Guid.NewGuid(); eLineValue.SensorDataHeadID = eLine.SensorDataHeadID; eLineValue.SensorDataLineID = eLine.SensorDataLineID; switch (i) { case (int)SystemData.Status: string ss = ParseHelper.ParseString(row[i]); if (!string.IsNullOrEmpty(ss)) { eLineValue.ValueType = SystemData.Status.ToString(); eLineValue.ContentString = ss; helperSensor.Create(eLineValue); } break; case (int)SystemData.ErrorNo: string errorNo = ParseHelper.ParseString(row[i]); if (!string.IsNullOrEmpty(errorNo)) { eLineValue.ValueType = SystemData.ErrorNo.ToString(); eLineValue.ContentString = errorNo; helperSensor.Create(eLineValue); } break; case (int)SystemData.ProgramNo: eLineValue.ValueType = SystemData.ProgramNo.ToString(); eLineValue.ContentString = ParseHelper.ParseString(row[i]); helperSensor.Create(eLineValue); break; case (int)SystemData.ProgramName: eLineValue.ValueType = SystemData.ProgramName.ToString(); eLineValue.ContentString = ParseHelper.ParseString(row[i]); helperSensor.Create(eLineValue); break; case (int)SystemData.ProgramPhase: eLineValue.ValueType = SystemData.ProgramPhase.ToString(); eLineValue.ContentString = ParseHelper.ParseString(row[i]); helperSensor.Create(eLineValue); break; default: break; } if (Convert.ToInt32(eSensor.SensorType).Equals(Convert.ToInt32(Common.Consts.SensorType.Washer))) { switch (i) { case (int)SystemData.MeasurementSensor1: // Med eLineValue.ValueType = SystemData.MeasurementSensor1.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]); helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor2: // CT eLineValue.ValueType = SystemData.MeasurementSensor2.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]) / 10; helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor3: // CDNo eLineValue.ValueType = SystemData.MeasurementSensor3.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]); helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor4: // DosV eLineValue.ValueType = SystemData.MeasurementSensor4.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]) / 10; helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor5: // Ao eLineValue.ValueType = SystemData.MeasurementSensor5.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]); helperSensor.Create(eLineValue); break; default: break; } } else if (Convert.ToInt32(eSensor.SensorType).Equals(Convert.ToInt32(Common.Consts.SensorType.Sterilizer))) { switch (i) { case (int)SystemData.MeasurementSensor1: // T1 eLineValue.ValueType = SystemData.MeasurementSensor1.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]) / 10; helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor2: // T2 eLineValue.ValueType = SystemData.MeasurementSensor2.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]) / 10; helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor4: // P1 eLineValue.ValueType = SystemData.MeasurementSensor4.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]); helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor5: // P2 eLineValue.ValueType = SystemData.MeasurementSensor5.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]); helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor6: // P3 eLineValue.ValueType = SystemData.MeasurementSensor6.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]); helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor7: // P4 eLineValue.ValueType = SystemData.MeasurementSensor7.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]); helperSensor.Create(eLineValue); break; default: break; } } } break; case Enumerator.BelimedStatus.End: if (eHead != null) { eHead.EndDate = ConvertDate(row[(int)SystemData.Timestamp]); helperSensor.Update(eHead); eSensor.PositionMark = status.ToString(); eSensor.Remarks = ParseHelper.ParseString(row[(int)SystemData.StatusInfo]); helperSensor.Update(eSensor); if (eHead.LogID != null && eHead.LogID.HasValue && eHead.LogID.Value != Guid.Empty) { DevicesUseLogEntity logEntity = helperSensor.SelectSingle <DevicesUseLogEntity>("LogID='" + eHead.LogID.Value.ToString().ToUpper() + "'", string.Empty); if (logEntity != null) { if (eHead.BeginDate != null && eHead.BeginDate.HasValue) { logEntity.OldBeginDate = logEntity.BeginDate; logEntity.BeginDate = eHead.BeginDate.Value; } logEntity.EndDate = eHead.EndDate; // TODO: DevicesUseLog 关联到 Sensor 的字段 //logEntity.MonitorDataID = eHead.SensorDataHeadID; helperSensor.Update(logEntity); } } } break; default: break; } tran.Complete(); logger.Info("数据保存成功。"); } } finally { System.Threading.Monitor.Exit(Monitor.Common.Utility.SyncSqlLock); } }
private void SaveData(SensorData receivedData) { SensorHelper <object> helperSensor = new SensorHelper <object>(); SensorEntity eSensor = helperSensor.SelectSingle <SensorEntity>(string.Format("SensorGroup = '{0}' AND SensorKey = '{1}'", mSensorGroup, receivedData.SourceAddress), string.Empty); if (eSensor == null) { logger.WarnFormat("系统中组和编号为:[{0}].[{1}]的设备没有登记。", mSensorGroup, receivedData.SourceAddress); return; } string dataKey = receivedData.ReceiveDate.Value.ToString("yyyyMMdd"); SensorDataHeadEntity eHead = helperSensor.SelectSingle <SensorDataHeadEntity>(string.Format("SensorID = '{0}' AND DataKey = '{1}'", eSensor.SensorID.ToString().ToUpper(), dataKey), string.Empty); System.Threading.Monitor.Enter(Monitor.Common.Utility.SyncSqlLock); try { logger.Debug("开始保存数据。"); using (TransactionScope tran = Monitor.Common.Utility.GetTransactionScope()) { if (eHead == null) { // 主数据 eHead = new SensorDataHeadEntity(); eHead.SensorDataHeadID = Guid.NewGuid(); eHead.SensorID = eSensor.SensorID; eHead.DataKey = dataKey; eHead.BeginDate = receivedData.ReceiveDate; eHead.IsCompressed = false; helperSensor.Create(eHead); } // 原始数据 SensorDataRawLineEntity eRawLine = new SensorDataRawLineEntity(); eRawLine.SensorDataRawLineID = Guid.NewGuid(); eRawLine.SensorDataHeadID = eHead.SensorDataHeadID; eRawLine.ReceivedDate = receivedData.ReceiveDate; eRawLine.RawData = receivedData.SourceData; helperSensor.Create(eRawLine); // 明细数据 SensorDataLineEntity eLine = new SensorDataLineEntity(); eLine.SensorDataLineID = Guid.NewGuid(); eLine.SensorDataHeadID = eHead.SensorDataHeadID; eLine.SensorDataRawLineID = eRawLine.SensorDataRawLineID; eLine.ReceivedDate = eRawLine.ReceivedDate; eLine.SensorDate = eRawLine.ReceivedDate; if (eLine.SensorDate != null && eLine.SensorDate.HasValue && eHead.BeginDate != null && eHead.BeginDate.HasValue) { eLine.SensorTimeSpan = Convert.ToInt64(eLine.SensorDate.Value.Subtract(eHead.BeginDate.Value).TotalMilliseconds); } //eLine.AnalysedData = string.Empty; eLine.ValueNumber1 = receivedData.Temperature; eLine.ValueNumber2 = receivedData.Pressure; eLine.ValueNumber3 = receivedData.Humidity; eLine.ValueNumber4 = receivedData.Voltage; helperSensor.Create(eLine); tran.Complete(); logger.Debug("数据保存成功。"); } } finally { System.Threading.Monitor.Exit(Monitor.Common.Utility.SyncSqlLock); } }
/// <summary> /// PraseHexString /// 16进制数据处理 /// 根据数据进行解析. /// </summary> /// <param name="hexString"></param> /// <returns></returns> private SensorData PraseHexString(string hexString, IList <byte> rowByte) { SensorData data = new SensorData(); data.SourceData = hexString; data.ReceiveDate = DateTime.Now; data.CMD = hexString.Substring(this.SerialPortCmdFormat.CMD.StartBit, this.SerialPortCmdFormat.CMD.Bits); data.SourceAddress = hexString.Substring(this.SerialPortCmdFormat.SourceAddress.StartBit, this.SerialPortCmdFormat.SourceAddress.Bits); SensorHelper <object> helper = new SensorHelper <object>(); SensorEntity eSensor = null; if (!string.IsNullOrEmpty(data.SourceAddress)) { eSensor = helper.SelectSingle <SensorEntity>(string.Format("SensorGroup = '{0}' AND SensorKey = '{1}'", mSensorGroup, data.SourceAddress), string.Empty); } else { logger.ErrorFormat("接收到的数据中,源地址取得失败。\n数据:{0}", hexString); return(null); } if (eSensor == null) { logger.WarnFormat("系统中组和编号为:[{0}].[{1}]的设备没有登记。", mSensorGroup, data.SourceAddress); return(null); } if (eSensor.SensorModel == SensorModel.SD1HT.ToString()) { // 型号:SD1HT // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 // AA 75 10 62 00 01 7D C5 A9 AC 0A B0 62 14 1B 96 00 00 // ----------- -------- -------- ----- // 源地址 温度 湿度 电压 // 温度:A8(正常温度),A9(温度超上限时的温度),AA(温度超下限是的温度),AB(温度变化过快时的温度) // 湿度:B0(正常湿度),B1(湿度超上限时的湿度),B2(湿度超下限是的湿度),B3(湿度变化过快时的湿度) // 电压:1B(正常电压),1A(电压低于电压下限阀值时的电压) byte[] tempBtye = null; decimal temp; // 温度 if (rowByte[8] == 0xA8 || rowByte[8] == 0xA9 || rowByte[8] == 0xAA || rowByte[8] == 0xAB || rowByte[8] == 0xB0) { tempBtye = new byte[] { rowByte[9], rowByte[10] }; temp = BitConverter.ToUInt16(tempBtye, 0); data.Temperature = temp / 100; } else { logger.ErrorFormat("接收到的数据中,温度取得失败。\n数据:{0}", hexString); return(null); } // 湿度 if (rowByte[11] == 0xB0 || rowByte[11] == 0xB1 || rowByte[11] == 0xB2 || rowByte[11] == 0xB3 || rowByte[11] == 0xB8) { tempBtye = new byte[] { rowByte[12], rowByte[13] }; temp = BitConverter.ToUInt16(tempBtye, 0); data.Humidity = temp / 100; } else { logger.ErrorFormat("接收到的数据中,湿度取得失败。\n数据:{0}", hexString); return(null); } // 电压 if (rowByte[14] == 0x1B || rowByte[14] == 0x1A) { tempBtye = new byte[] { rowByte[15], 0 }; temp = BitConverter.ToUInt16(tempBtye, 0); data.Voltage = temp / 50; } else { logger.ErrorFormat("接收到的数据中,电压取得失败。\n数据:{0}", hexString); return(null); } } else if (eSensor.SensorModel == SensorModel.TH80.ToString()) { // 型号:TH80 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 // AA 75 10 62 00 01 B9 FC B0 87 05 B8 25 0D 1B 97 00 00 // ----------- -------- -------- ----- // 源地址 温度 湿度 电压 // 第一路温湿度参数 // 温度:B0(当前温度),B1(温度上限),B2(温度下限),B3(温度变化) // 湿度:B8(当前湿度),B9(湿度上限),BA(湿度下限),BB(湿度变化) // 电压:1B(正常电压),1A(电压低于电压下限阀值时的电压) byte[] tempBtye = null; decimal temp; // 温度 if (rowByte[8] == 0xB0 || rowByte[8] == 0xB1 || rowByte[8] == 0xB2 || rowByte[8] == 0xB3) { tempBtye = new byte[] { rowByte[9], rowByte[10] }; temp = BitConverter.ToUInt16(tempBtye, 0); data.Temperature = temp / 100; } else { logger.ErrorFormat("接收到的数据中,温度取得失败。\n数据:{0}", hexString); return(null); } // 湿度 if (rowByte[11] == 0xB8 || rowByte[11] == 0xB9 || rowByte[11] == 0xBA || rowByte[11] == 0xBB) { tempBtye = new byte[] { rowByte[12], rowByte[13] }; temp = BitConverter.ToUInt16(tempBtye, 0); data.Humidity = temp / 100; } else { logger.ErrorFormat("接收到的数据中,湿度取得失败。\n数据:{0}", hexString); return(null); } // 电压 if (rowByte[14] == 0x1B || rowByte[14] == 0x1A) { tempBtye = new byte[] { rowByte[15], 0 }; temp = BitConverter.ToUInt16(tempBtye, 0); data.Voltage = temp / 50; } else { logger.ErrorFormat("接收到的数据中,电压取得失败。\n数据:{0}", hexString); return(null); } } else { Payload payload = this.SerialPortCmdFormat.Payloads[data.SourceAddress]; if (payload == null) { //说明该节点未配置在 UserProfile.config中 logger.WarnFormat("请在 UserProfile.config 的 MatchSensorNodes 节中加入传感器[{0}]的信息。", data.SourceAddress); return(null); } data.Payload = hexString.Substring(payload.StartBit, payload.Bits); //data.Payload = data.Payload.Substring(0, 12); int index = -1; if (payload.TemperatureSymbol != null) { //index = data.Payload.IndexOf(payload.TemperatureSymbol.DataDefine); index = payload.TemperatureSymbol.StartBit; if (index != -1) { if (hexString.Substring(22, 2) != "1B") { string Temperature = data.Payload.Substring((index + payload.TemperatureSymbol.Bits), payload.TemperatureData.Bits); ////反转Payload数据, 原始数据 低位在前 高位在后 ////payload 数据格式 EB 02 EB是第一位 02是第二位 因此转成Hex进制时需要反转成0x02EB Temperature = Temperature.Substring(2, 2) + Temperature.Substring(0, 2); ////公式算法 Temperature = Convert.ToInt64("0x" + Temperature, 16).ToString(); //MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControlClass(); //sc.Language = "JavaScript"; Temperature = string.Format(payload.TemperatureData.Expression, Temperature); //m_parser.SetExpr(Temperature); //Temperature = m_parser.Eval().ToString(); Temperature = new DataTable().Compute(Temperature, "").ToString(); //Temperature = Microsoft.JScript.GlobalObject.eval(Temperature).ToString(); //Temperature = sc.Eval(Temperature).ToString(); data.Temperature = Decimal.Parse(Temperature); } else { string Temperature = data.Payload.Substring((index + payload.TemperatureSymbol.Bits), payload.TemperatureData.Bits); ////反转Payload数据, 原始数据 低位在前 高位在后 ////payload 数据格式 EB 02 EB是第一位 02是第二位 因此转成Hex进制时需要反转成0x02EB Temperature = Temperature.Substring(2, 2) + Temperature.Substring(0, 2); ////公式算法 Temperature = Convert.ToInt64("0x" + Temperature, 16).ToString(); //MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControlClass(); //sc.Language = "JavaScript"; //Temperature = string.Format(payload.TemperatureData.Expression, Temperature); //m_parser.SetExpr(Temperature); //Temperature = m_parser.Eval().ToString(); //Temperature = new DataTable().Compute(Temperature, "").ToString(); //Temperature = Microsoft.JScript.GlobalObject.eval(Temperature).ToString(); //Temperature = sc.Eval(Temperature).ToString(); data.Temperature = (decimal)((int.Parse(Temperature) - 500) / 10); } } } if (payload.HumiditySymbol != null) { //index = data.Payload.IndexOf(this.SerialPortCmdFormat.Payload.HumiditySymbol.DataDefine); //if (index != -1) index = payload.HumiditySymbol.StartBit; if (index != -1) { if (hexString.Substring(22, 2) != "1B") { string Humidity = data.Payload.Substring((index + payload.HumiditySymbol.Bits), payload.HumidityData.Bits); ////反转Payload数据, 原始数据 低位在前 高位在后 ////payload 数据格式 EB 02 EB是第一位 02是第二位 因此转成Hex进制时需要反转成0x02EB Humidity = Humidity.Substring(2, 2) + Humidity.Substring(0, 2); ////公式算法 Humidity = Convert.ToInt64("0x" + Humidity, 16).ToString(); //MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControlClass(); //sc.Language = "JavaScript"; Humidity = string.Format(payload.HumidityData.Expression, Humidity); //Humidity = sc.Eval(Humidity).ToString(); //m_parser.SetExpr(Humidity); Humidity = new DataTable().Compute(Humidity, "").ToString(); //Humidity = Microsoft.JScript.GlobalObject.eval(Humidity).ToString(); data.Humidity = Decimal.Parse(Humidity); } else { string Humidity = data.Payload.Substring(10, payload.HumidityData.Bits); ////反转Payload数据, 原始数据 低位在前 高位在后 ////payload 数据格式 EB 02 EB是第一位 02是第二位 因此转成Hex进制时需要反转成0x02EB //Humidity = Humidity.Substring(2, 2) + Humidity.Substring(0, 2); ////公式算法 Humidity = Convert.ToInt64("0x" + Humidity, 16).ToString(); //MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControlClass(); //sc.Language = "JavaScript"; //Humidity = string.Format(payload.HumidityData.Expression, Humidity); //Humidity = sc.Eval(Humidity).ToString(); //m_parser.SetExpr(Humidity); //Humidity = new DataTable().Compute(Humidity, "").ToString(); //Humidity = Microsoft.JScript.GlobalObject.eval(Humidity).ToString(); data.Humidity = Decimal.Parse(Humidity) / 100 * 5; } } } if (payload.PressureSymbol != null) { index = payload.PressureSymbol.StartBit; if (index != -1) { string Pressure = data.Payload.Substring((index + payload.PressureSymbol.Bits), payload.PressureData.Bits); Pressure = Pressure.Substring(2, 2) + Pressure.Substring(0, 2); Pressure = Convert.ToInt64("0x" + Pressure, 16).ToString(); Pressure = string.Format(payload.PressureData.Expression, Pressure); Pressure = new DataTable().Compute(Pressure, "").ToString(); data.Pressure = Decimal.Parse(Pressure); } } if (payload.VoltageSymbol != null) { index = payload.VoltageSymbol.StartBit; if (index != -1) { string Voltage = data.Payload.Substring((index + payload.VoltageSymbol.Bits), payload.VoltageData.Bits); Voltage = Voltage.Substring(0, 2);// Voltage = Convert.ToInt64("0x" + Voltage, 16).ToString(); Voltage = string.Format(payload.VoltageData.Expression, Voltage); Voltage = new DataTable().Compute(Voltage, "").ToString(); data.Voltage = Decimal.Parse(Voltage); } } //处理高精度算法的温度 if (payload.NodeType == NodeType.TemperaturePressureAccurate) { //AA 75 16 62 00 00 36 56 9A 40 51 92 4C 00 93 9F 4A 9F E3 03 00 00 06 0E //AA 75 16 62 00 00 36 56 9A 3E 51 92 4C 00 93 9F 4A 9F E3 03 00 00 06 0C // 9A 21 50 92 4C 00 93 9F 4A 9F F4 03 //StartBit="16" Length="18" //StartBit="34" Length="6" //温度部分 string Temperature = data.Payload.Substring(0, 18); Decimal K = 3932160; string x = data.Payload.Substring(2, 4); x = x.Substring(2, 2) + x.Substring(0, 2); //MSScriptControl.ScriptControl scX = new MSScriptControl.ScriptControlClass(); //scX.Language = "JavaScript"; x = string.Format("0x{0}", x); x = Convert.ToInt64(x, 16).ToString(); //x = scX.Eval(x).ToString(); Decimal X = Decimal.Parse(x); string x0 = data.Payload.Substring(8, 4); x0 = x0.Substring(2, 2) + x0.Substring(0, 2); //MSScriptControl.ScriptControl scX0 = new MSScriptControl.ScriptControlClass(); //scX0.Language = "JavaScript"; x0 = string.Format("0x{0}", x0); x0 = Convert.ToInt64(x0, 16).ToString(); //x0 = scX0.Eval(x0).ToString(); Decimal X0 = Decimal.Parse(x0); string x100 = data.Payload.Substring(14, 4); x100 = x100.Substring(2, 2) + x100.Substring(0, 2); //MSScriptControl.ScriptControl scX100 = new MSScriptControl.ScriptControlClass(); //scX100.Language = "JavaScript"; x100 = string.Format("0x{0}", x100); //x100 = scX100.Eval(x100).ToString(); x100 = Convert.ToInt64(x100, 16).ToString(); Decimal X100 = Decimal.Parse(x100); Decimal RX = X / (K - X); Decimal R0 = X0 / (K - X0); Decimal R100 = X100 / (K - X100); Decimal t1 = 100 * (RX - R100); Decimal t2 = 0.3851m * (R100 - R0); data.Temperature = Math.Round(t1 / t2, 2); //压力部分 string Pressure = data.Payload.Substring(18, 6); Pressure = Pressure.Substring(4, 2) + Pressure.Substring(2, 2); //MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControlClass(); //sc.Language = "JavaScript"; Pressure = string.Format("0x{0}", Pressure); //Pressure = sc.Eval(Pressure).ToString(); Pressure = Convert.ToInt64(Pressure, 16).ToString(); data.Pressure = Decimal.Parse(Pressure); } } return(data); }
public ChartDTO GetChartDataInc(DateTime?lastReceivedDate, bool canChangeHead) { mSyncLast = null; mDataDic = new Dictionary <string, DataRow[]>(); IsNew = false; mProgramData = null; // 刷新状态 SensorHelper <object> helper = new SensorHelper <object>(); mSensor = helper.SelectSingle <SensorEntity>(string.Format("SensorID = '{0}'", mSensor.SensorID.ToString().ToUpper()), string.Empty); SensorDataHeadBll bllHead = new SensorDataHeadBll(); SensorDataHeadEntity eHead = bllHead.GetNewestSensorDataHeadBySensorID(Sensor.SensorID.ToString().ToUpper()); if (eHead == null) { return(null); } else { if (mHeadEntity != null && eHead.SensorDataHeadID != mHeadEntity.SensorDataHeadID && !canChangeHead) { return(null); } if (eHead.IsCompressed != null && eHead.IsCompressed.HasValue && eHead.IsCompressed.Value) { if (canChangeHead) { ChartDTO chartData = new ChartDTO(); chartData.ChartTitle = GetChartTitle(); chartData.IsReset = true; return(chartData); } else { return(null); } } //SensorDataLineBll bllLine = new SensorDataLineBll(); //mSectionList = bllLine.GetSensorDataLineByDataType(eHead.SensorDataHeadID.ToString(), Utility.GetEnumValue(DataType.Body_SectionTitle)); if (mHeadEntity != null && eHead.SensorDataHeadID == mHeadEntity.SensorDataHeadID && lastReceivedDate != null && lastReceivedDate.HasValue) { mProgramData = GetProgramDataInc(eHead, lastReceivedDate.Value); if (Convert.ToInt32(Sensor.SensorType).Equals(Convert.ToInt32(Common.Consts.SensorType.Sterilizer))) { // 灭菌 return(GetSterilizerChartDataInc(eHead, lastReceivedDate.Value)); } else if (Convert.ToInt32(Sensor.SensorType).Equals(Convert.ToInt32(Common.Consts.SensorType.Washer))) { // 清洗 return(GetWasherChartDataInc(eHead, lastReceivedDate.Value)); } else { logger.WarnFormat("未处理的设备类型([传感器:{0},设备类型:{1}])", Sensor.SensorKey, Sensor.SensorType); return(null); } } else { if (canChangeHead) { mSensorData = null; ChartDTO dtoChart = GetChartDataByHead(eHead); dtoChart.IsReset = true; IsNew = true; return(dtoChart); } else { return(null); } } } }