예제 #1
0
 /// <summary>
 /// 取得摘要的值
 /// </summary>
 public override void Summary()
 {
     if (Config[0] == "OK")
     {
         SerialNumber  = Config[1];
         _TripNumber   = SerialNumber;
         LogCycle      = TempsenFormatHelper.ConvertSencondToFormmatedTime(TempsenFormatHelper.GetSecondsFromFormatString(Config[3]));
         LogInterval   = TempsenFormatHelper.GetSecondsFromFormatString(Config[2]);
         TempUnit      = AlarmSet[1];
         LogStartDelay = TempsenFormatHelper.ConvertSencondToFormmatedTime(TempsenFormatHelper.GetSecondsFromFormatString(Config[4]));
         LoggingStart  = Convert.ToDateTime(Config[6]);
         //LoggingEnd = Convert.ToDateTime(Config[6]).AddSeconds(int.Parse(Config[2].Substring(0, Config[2].Length - 1)) * int.Parse(Config[5]));
         DataPoints     = Convert.ToInt32(Config[5]);
         AlarmHighDelay = TempsenFormatHelper.ConvertSencondToFormmatedTime(TempsenFormatHelper.GetSecondsFromFormatString(AlarmSet[4]));
         AlarmLowDelay  = TempsenFormatHelper.ConvertSencondToFormmatedTime(TempsenFormatHelper.GetSecondsFromFormatString(AlarmSet[4]));
         Battery        = OtherInfo[1];
         AlarmMode      = 1;
         if (AlarmSet[2] == "--" && AlarmSet[3] == "--")
         {
             AlarmMode = 0;
         }
         else if (AlarmSet[2] != "--" && AlarmSet[3] == "--")
         {
             AlarmHighLimit = AlarmSet[2];
         }
         else if (AlarmSet[3] != "--" && AlarmSet[2] == "--")
         {
             AlarmLowLimit = AlarmSet[3];
         }
         else
         {
             AlarmHighLimit = AlarmSet[2];
             AlarmLowLimit  = AlarmSet[3];
         }
         if (SerializePointInfo())
         {
             points.FirstPoint = points.StartTime = this.LoggingStart;
             if (tempList != null && tempList.Count > 0)
             {
                 LoggingEnd = tempList[tempList.Count - 1].PointTime;
             }
             TripLength        = TempsenFormatHelper.ConvertSencondToFormmatedTime((LoggingEnd - LoggingStart).TotalSeconds.ToString());
             points.EndTime    = this.LoggingEnd;
             points.TripLength = this.TripLength;
             if (AlarmSet[2] != "--")
             {
                 HighAlarmEvents = tempList.Count(p => p.PointTemp >= Convert.ToDouble(AlarmSet[2]));
                 var v = tempList.Where(p => p.PointTemp >= Convert.ToDouble(AlarmSet[2]));
                 HighAlarmFirstTrigged = v.ToList().Count == 0 ? DateTime.MinValue.ToString() : v.Min(p => p.PointTime).ToString();
             }
             if (AlarmSet[3] != "--")
             {
                 LowAlarmEvents = tempList.Count(p => p.PointTemp <= Convert.ToDouble(AlarmSet[3]));
                 var v = tempList.Where(p => p.PointTemp <= Convert.ToDouble(AlarmSet[3]));
                 LowAlarmFirstTrigged = v.ToList().Count == 0 ? DateTime.MinValue.ToString() : v.Min(p => p.PointTime).ToString();
             }
             HighAlarmTotalTimeAbove = TempsenFormatHelper.ConvertSencondToFormmatedTime((Convert.ToDouble(LogInterval) * (HighAlarmEvents - 1)).ToString());
             LowAlarmTotalTimeBelow  = TempsenFormatHelper.ConvertSencondToFormmatedTime((Convert.ToDouble(LogInterval) * (LowAlarmEvents - 1)).ToString());
             if (tempList != null && tempList.Count > 0)
             {
                 AverageC = Math.Round(tempList.Select(p => p.PointTemp).Average(), 1).ToString();
                 MKT      = Common.CalcMKT(tempList.Select(p => (int)(p.PointTemp * 100)).ToList());
                 var s = (from p in tempList
                          where p.PointTemp == tempList.Select(t => t.PointTemp).Max()
                          select p.PointTemp.ToString() + "°" + (this.TempUnit) + "@" + p.PointTime.ToString(Common.GetDefaultDateTimeFormat(), CultureInfo.InvariantCulture));
                 HighestC = s.ToList().Count == 0 ? "" : s.ToList().First();
                 s        = (from p in tempList
                             where p.PointTemp == tempList.Select(t => t.PointTemp).Min()
                             select p.PointTemp + "°" + (this.TempUnit) + "@" + p.PointTime.ToString(Common.GetDefaultDateTimeFormat(), CultureInfo.InvariantCulture));
                 LowestC         = s.ToList().Count == 0 ? "" : s.First();
                 points.HighestC = this.HighestC;
                 points.LowestC  = this.LowestC;
                 points.AVGTemp  = AverageC;
                 points.MKT      = this.MKT;
             }
         }
     }
     return;
 }
예제 #2
0
        private void CalculateAlarmEvents()
        {
            int    tempIntForTryParse    = 0;
            double tempDoubleForTryParse = 0;

            IList <PointKeyValue> points = this.tempList;

            double highLimit = double.MaxValue;

            if (double.TryParse(this.AlarmHighLimit, out tempDoubleForTryParse))
            {
                highLimit = double.Parse(this.AlarmHighLimit);
            }
            double lowLimit = double.MinValue;

            if (double.TryParse(this.AlarmLowLimit, out tempDoubleForTryParse))
            {
                lowLimit = double.Parse(this.AlarmLowLimit);
            }
            int highAlarmDelay = int.MaxValue;

            highAlarmDelay = int.Parse(TempsenFormatHelper.GetSecondsFromFormatString(this.AlarmHighDelay));
            int lowAlarmDelay = int.MaxValue;

            lowAlarmDelay = int.Parse(TempsenFormatHelper.GetSecondsFromFormatString(this.AlarmLowDelay));
            AlarmType highAlarmType = AlarmType.Single;

            if ("Cumulative Event".Equals(this.HighAlarmType, StringComparison.InvariantCultureIgnoreCase))
            {
                highAlarmType = AlarmType.Cumulative;
            }
            AlarmType lowAlarmType = AlarmType.Single;

            if ("Cumulative Event".Equals(this.LowAlarmType, StringComparison.InvariantCultureIgnoreCase))
            {
                lowAlarmType = AlarmType.Cumulative;
            }
            int logInterval = 0;

            if (int.TryParse(this.LogInterval, out tempIntForTryParse))
            {
                logInterval = int.Parse(this.LogInterval);
            }

            int      overHighLimitEvents     = 0;
            int      belowLowLimitEvents     = 0;
            DateTime highAlarmFirstTriggered = DateTime.MinValue;
            DateTime lowAlarmFirstTriggered  = DateTime.MinValue;
            int      overHighLimitTotalTime  = 0;
            int      belowLowLimitTotalTime  = 0;

            int overHighLimitCumulativePoints = 0;
            int belowLowLimitCumulativePoints = 0;

            DateTime timeOfTheLastPointWithoutMark = DateTime.MinValue;

            foreach (var item in points)
            {
                if (!item.IsMark)
                {
                    if (item.PointTemp >= highLimit)
                    {
                        overHighLimitCumulativePoints++;
                        if (belowLowLimitCumulativePoints > 0)
                        {
                            belowLowLimitEvents++;
                            int actualIntervals = belowLowLimitCumulativePoints - 1;
                            if (actualIntervals == 0)
                            {
                                actualIntervals = 1;
                            }
                            belowLowLimitTotalTime       += logInterval * actualIntervals;
                            belowLowLimitCumulativePoints = 0;
                        }

                        int actualIntervalsToCheckAlarm = overHighLimitCumulativePoints - 1;
                        int actualTotalTimeToCheckAlarm = 0;
                        if (actualIntervalsToCheckAlarm == 0)
                        {
                            actualIntervalsToCheckAlarm = 1;
                        }
                        actualTotalTimeToCheckAlarm += logInterval * actualIntervalsToCheckAlarm;
                        if (AlarmType.Cumulative == highAlarmType)
                        {
                            actualTotalTimeToCheckAlarm += overHighLimitTotalTime;
                        }
                        if (highAlarmFirstTriggered == DateTime.MinValue && actualTotalTimeToCheckAlarm >= highAlarmDelay)
                        {
                            highAlarmFirstTriggered = item.PointTime;
                        }
                    }
                    else if (item.PointTemp <= lowLimit)
                    {
                        belowLowLimitCumulativePoints++;
                        if (overHighLimitCumulativePoints > 0)
                        {
                            overHighLimitEvents++;
                            int actualIntervals = overHighLimitCumulativePoints - 1;
                            if (actualIntervals == 0)
                            {
                                actualIntervals = 1;
                            }
                            overHighLimitTotalTime       += logInterval * actualIntervals;
                            overHighLimitCumulativePoints = 0;
                        }

                        int actualIntervalsToCheckAlarm = belowLowLimitCumulativePoints - 1;
                        int actualTotalTimeToCheckAlarm = 0;
                        if (actualIntervalsToCheckAlarm == 0)
                        {
                            actualIntervalsToCheckAlarm = 1;
                        }
                        actualTotalTimeToCheckAlarm += logInterval * actualIntervalsToCheckAlarm;
                        if (AlarmType.Cumulative == lowAlarmType)
                        {
                            actualTotalTimeToCheckAlarm += belowLowLimitTotalTime;
                        }
                        if (lowAlarmFirstTriggered == DateTime.MinValue && actualTotalTimeToCheckAlarm >= lowAlarmDelay)
                        {
                            lowAlarmFirstTriggered = item.PointTime;
                        }
                    }
                    else
                    {
                        if (belowLowLimitCumulativePoints > 0)
                        {
                            belowLowLimitEvents++;
                            int actualIntervals = belowLowLimitCumulativePoints - 1;
                            if (actualIntervals == 0)
                            {
                                actualIntervals = 1;
                            }
                            belowLowLimitTotalTime       += logInterval * actualIntervals;
                            belowLowLimitCumulativePoints = 0;

                            int actualIntervalsToCheckAlarm = belowLowLimitCumulativePoints - 1;
                            int actualTotalTimeToCheckAlarm = 0;
                            if (actualIntervalsToCheckAlarm == 0)
                            {
                                actualIntervalsToCheckAlarm = 1;
                            }
                            actualTotalTimeToCheckAlarm += logInterval * actualIntervalsToCheckAlarm;
                            if (AlarmType.Cumulative == lowAlarmType)
                            {
                                actualTotalTimeToCheckAlarm += belowLowLimitTotalTime;
                            }
                            if (lowAlarmFirstTriggered == DateTime.MinValue && actualTotalTimeToCheckAlarm >= lowAlarmDelay)
                            {
                                lowAlarmFirstTriggered = item.PointTime;
                            }
                        }
                        if (overHighLimitCumulativePoints > 0)
                        {
                            overHighLimitEvents++;
                            int actualIntervals = overHighLimitCumulativePoints - 1;
                            if (actualIntervals == 0)
                            {
                                actualIntervals = 1;
                            }
                            overHighLimitTotalTime       += logInterval * actualIntervals;
                            overHighLimitCumulativePoints = 0;

                            int actualIntervalsToCheckAlarm = overHighLimitCumulativePoints - 1;
                            int actualTotalTimeToCheckAlarm = 0;
                            if (actualIntervalsToCheckAlarm == 0)
                            {
                                actualIntervalsToCheckAlarm = 1;
                            }
                            actualTotalTimeToCheckAlarm += logInterval * actualIntervalsToCheckAlarm;
                            if (AlarmType.Cumulative == highAlarmType)
                            {
                                actualTotalTimeToCheckAlarm += overHighLimitTotalTime;
                            }
                            if (highAlarmFirstTriggered == DateTime.MinValue && actualTotalTimeToCheckAlarm >= highAlarmDelay)
                            {
                                highAlarmFirstTriggered = item.PointTime;
                            }
                        }
                    }
                    timeOfTheLastPointWithoutMark = item.PointTime;
                }
            }
            if (belowLowLimitCumulativePoints > 0)
            {
                belowLowLimitEvents++;
                int actualIntervals = belowLowLimitCumulativePoints - 1;
                if (actualIntervals == 0)
                {
                    actualIntervals = 1;
                }
                belowLowLimitTotalTime       += logInterval * actualIntervals;
                belowLowLimitCumulativePoints = 0;

                int actualIntervalsToCheckAlarm = belowLowLimitCumulativePoints - 1;
                int actualTotalTimeToCheckAlarm = 0;
                if (actualIntervalsToCheckAlarm == 0)
                {
                    actualIntervalsToCheckAlarm = 1;
                }
                actualTotalTimeToCheckAlarm += logInterval * actualIntervalsToCheckAlarm;
                if (AlarmType.Cumulative == lowAlarmType)
                {
                    actualTotalTimeToCheckAlarm += belowLowLimitTotalTime;
                }
                if (lowAlarmFirstTriggered == DateTime.MinValue && actualTotalTimeToCheckAlarm >= lowAlarmDelay)
                {
                    lowAlarmFirstTriggered = timeOfTheLastPointWithoutMark;
                }
            }
            if (overHighLimitCumulativePoints > 0)
            {
                overHighLimitEvents++;
                int actualIntervals = overHighLimitCumulativePoints - 1;
                if (actualIntervals == 0)
                {
                    actualIntervals = 1;
                }
                overHighLimitTotalTime       += logInterval * actualIntervals;
                overHighLimitCumulativePoints = 0;

                int actualIntervalsToCheckAlarm = overHighLimitCumulativePoints - 1;
                int actualTotalTimeToCheckAlarm = 0;
                if (actualIntervalsToCheckAlarm == 0)
                {
                    actualIntervalsToCheckAlarm = 1;
                }
                actualTotalTimeToCheckAlarm += logInterval * actualIntervalsToCheckAlarm;
                if (AlarmType.Cumulative == highAlarmType)
                {
                    actualTotalTimeToCheckAlarm += overHighLimitTotalTime;
                }
                if (highAlarmFirstTriggered == DateTime.MinValue && actualTotalTimeToCheckAlarm >= highAlarmDelay)
                {
                    highAlarmFirstTriggered = timeOfTheLastPointWithoutMark;
                }
            }

            this.HighAlarmEvents         = overHighLimitEvents;
            this.LowAlarmEvents          = belowLowLimitEvents;
            this.HighAlarmFirstTrigged   = highAlarmFirstTriggered.ToString(Common.GetDefaultDateTimeFormat(), CultureInfo.InvariantCulture);
            this.LowAlarmFirstTrigged    = lowAlarmFirstTriggered.ToString(Common.GetDefaultDateTimeFormat(), CultureInfo.InvariantCulture);
            this.HighAlarmTotalTimeAbove = TempsenFormatHelper.ConvertSencondToFormmatedTime(overHighLimitTotalTime.ToString());
            this.LowAlarmTotalTimeBelow  = TempsenFormatHelper.ConvertSencondToFormmatedTime(belowLowLimitTotalTime.ToString());
            AlarmHighStatus = HighAlarmEvents > 0 ? "Alarm" : "OK";
            AlarmLowStatus  = LowAlarmEvents > 0 ? "Alarm" : "OK";
        }
예제 #3
0
 public virtual bool WriteConfiguration(ConfigurationProfile cfg)
 {
     //DevicePDF device = new DevicePDF();
     try
     {
         //device = this.Pdf;
         if (ObjectManage.DeviceNew != null)
         {
             ObjectManage.DeviceNew.Data.TripNo      = cfg.Tn;
             ObjectManage.DeviceNew.Data.Description = cfg.Desc;
             //ObjectManage.DeviceNew.Data.AlarmType = cfg.
             ObjectManage.DeviceNew.Data.TemperatureUnit = cfg.TempUnit == "C" ? 1 : 2;
             ObjectManage.DeviceNew.Data.LogInterval     = Convert.ToInt32(cfg.LogIntervalH) * 3600 + Convert.ToInt32(cfg.LogIntervalM) * 60 + Convert.ToInt32(cfg.LogIntervalS);
             string cycle = TempsenFormatHelper.GetSecondsFromFormatString(cfg.LogCycle);
             ObjectManage.DeviceNew.Data.LogCycle = Convert.ToInt32(cycle) / 3600;//log cycle
             //if (cycle.Count > 1)
             //    ObjectManage.DeviceNew.Data.LogCycle += cycle[1];
             if (cfg.StartMode == "Manual Start")
             {
                 ObjectManage.DeviceNew.Data.StartDelay = (Convert.ToInt32(cfg.StartDelayD) * 1440 + Convert.ToInt32(cfg.StartDelayH) * 60 + Convert.ToInt32(cfg.StartDelayM));
                 ObjectManage.DeviceNew.Data.StartMode  = "F8";
             }
             else
             {
                 ObjectManage.DeviceNew.Data.StartConditionTime = Convert.ToDateTime(cfg.StartDate).ToUniversalTime();//UTC时间写入
                 //ObjectManage.DeviceNew.Data.StartConditionTime = Convert.ToDateTime(cfg.StartDate);
                 ObjectManage.DeviceNew.Data.StartMode = "8F";
             }
             if (cfg.IsSingleAlarm)
             {
                 ObjectManage.DeviceNew.Data.AlarmMode = 1;
                 if (cfg.IsHighLimit)
                 {
                     ObjectManage.DeviceNew.Data.AlarmLimits2 = cfg.HighTemp;
                     ObjectManage.DeviceNew.Data.AlarmType2   = cfg.HighAlarmType == "Single" ? Convert.ToByte(192) : Convert.ToByte(193);
                     ObjectManage.DeviceNew.Data.AlarmDelay2  = cfg.HighDay * 24 * 3600 + cfg.HighH * 3600 + cfg.HighM * 60;
                 }
                 else
                 {
                     ObjectManage.DeviceNew.Data.AlarmType2 = Convert.ToByte(0);
                 }
                 if (cfg.IsLowLimit)
                 {
                     ObjectManage.DeviceNew.Data.AlarmLimits3 = cfg.LowTemp;
                     ObjectManage.DeviceNew.Data.AlarmType3   = cfg.LowAlarmType == "Single" ? Convert.ToByte(128) : Convert.ToByte(129);
                     ObjectManage.DeviceNew.Data.AlarmDelay3  = cfg.LowDay * 24 * 3600 + cfg.LowH * 3600 + cfg.LowM * 60;
                 }
                 else
                 {
                     ObjectManage.DeviceNew.Data.AlarmType3 = Convert.ToByte(0);
                 }
                 ObjectManage.DeviceNew.Data.AlarmType0 = Convert.ToByte(0);
                 ObjectManage.DeviceNew.Data.AlarmType1 = Convert.ToByte(0);
                 ObjectManage.DeviceNew.Data.AlarmType4 = Convert.ToByte(0);
             }
             else if (cfg.IsMultiAlarm)
             {
                 ObjectManage.DeviceNew.Data.AlarmMode = 2;
                 if (cfg.IsA6)
                 {
                     ObjectManage.DeviceNew.Data.AlarmLimits0 = cfg.A6Temp;
                     ObjectManage.DeviceNew.Data.AlarmType0   = cfg.A6AlarmType == "Single" ? Convert.ToByte(192) : Convert.ToByte(193);
                     ObjectManage.DeviceNew.Data.AlarmDelay0  = cfg.A6Day * 24 * 3600 + cfg.A6H * 3600 + cfg.A6M * 60;
                 }
                 else
                 {
                     ObjectManage.DeviceNew.Data.AlarmType0 = Convert.ToByte(0);
                 }
                 if (cfg.IsA5)
                 {
                     ObjectManage.DeviceNew.Data.AlarmLimits1 = cfg.A5Temp;
                     ObjectManage.DeviceNew.Data.AlarmType1   = cfg.A5AlarmType == "Single" ? Convert.ToByte(192) : Convert.ToByte(193);
                     ObjectManage.DeviceNew.Data.AlarmDelay1  = cfg.A5Day * 24 * 3600 + cfg.A5H * 3600 + cfg.A5M * 60;
                 }
                 else
                 {
                     ObjectManage.DeviceNew.Data.AlarmType1 = Convert.ToByte(0);
                 }
                 ObjectManage.DeviceNew.Data.AlarmLimits2 = cfg.A4Temp;
                 ObjectManage.DeviceNew.Data.AlarmLimits3 = cfg.A3Temp;
                 if (cfg.IsA1)
                 {
                     ObjectManage.DeviceNew.Data.AlarmLimits4 = cfg.A1Temp;
                     ObjectManage.DeviceNew.Data.AlarmType4   = cfg.A1AlarmType == "Single" ? Convert.ToByte(128) : Convert.ToByte(129);
                     ObjectManage.DeviceNew.Data.AlarmDelay4  = cfg.A1Day * 24 * 3600 + cfg.A1H * 3600 + cfg.A1M * 60;
                 }
                 else
                 {
                     ObjectManage.DeviceNew.Data.AlarmType4 = Convert.ToByte(0);
                 }
                 ObjectManage.DeviceNew.Data.AlarmType2  = cfg.A4AlarmType == "Single" ? Convert.ToByte(192) : Convert.ToByte(193);
                 ObjectManage.DeviceNew.Data.AlarmType3  = cfg.A2AlarmType == "Single" ? Convert.ToByte(128) : Convert.ToByte(129);
                 ObjectManage.DeviceNew.Data.AlarmDelay2 = cfg.A4Day * 24 * 3600 + cfg.A4H * 3600 + cfg.A4M * 60;
                 ObjectManage.DeviceNew.Data.AlarmDelay3 = cfg.A2Day * 24 * 3600 + cfg.A2H * 3600 + cfg.A2M * 60;
             }
             else
             {
                 ObjectManage.DeviceNew.Data.AlarmMode = 0;
             }
             return(ObjectManage.DeviceNew.DoWrite());
         }
         return(false);
     }
     catch
     {
         //ObjectManage.DeviceNew.disconnectDevice();
         return(false);
     }
 }