示例#1
0
        public IDictionary <string, string[]> GetDeviceConfigurationTripInfoRowsContents(SuperDevice device)
        {
            IDictionary <string, string[]> result = new Dictionary <string, string[]>();

            string[] row1Contents = new string[2];
            string[] row2Contents = new string[2];
            string[] row3Contents = new string[2];

            string[] tripInfoContents = new string[3];

            result.Add("row1Contents", row1Contents);
            result.Add("row2Contents", row2Contents);
            result.Add("row3Contents", row3Contents);
            result.Add("tripInfoContents", tripInfoContents);
            if (device != null)
            {
                row1Contents[0] = string.Format("Device: {0}", device.DeviceName);
                row1Contents[1] = string.Format("Model: {0}", device.Model);
                row2Contents[0] = string.Format("Serial Number: {0}", device.SerialNumber);
                row2Contents[1] = string.Format("Log Interval/Cycle: {0}{2}{1}", TempsenFormatHelper.ConvertSencondToFormmatedTime(device.LogInterval), device.LogCycle, "/");
                row3Contents[0] = string.Format("Start Mode: {0}", device.StartModel);
                if (device.StartModel == "Manual Start")
                {
                    row3Contents[1] = string.Format("Start Delay: {0}", device.LogStartDelay);
                }
                else
                {
                    row3Contents[1] = string.Empty;
                }
                string tripNumberWithoutSuffix = string.Empty;
                if (device.TripNumber != null && device.TripNumber.IndexOf('_') != -1)
                {
                    tripNumberWithoutSuffix = device.TripNumber.Substring(0, device.TripNumber.IndexOf('_'));
                }
                else
                {
                    tripNumberWithoutSuffix = device.TripNumber;
                }

                tripInfoContents[0] = tripNumberWithoutSuffix;
                tripInfoContents[1] = device.DeviceID < 200 ? string.Empty : "Description: ";
                string rawDescription = string.IsNullOrWhiteSpace(device.Description) ? string.Empty : device.Description;
                if (device.DeviceID < 200)
                {
                    tripInfoContents[2] = string.Empty;
                }
                else
                {
                    tripInfoContents[2] = rawDescription;
                }
            }
            return(result);
        }
示例#2
0
        public IDictionary <string, string[]> GetAlarmRowContents(SuperDevice device)
        {
            IDictionary <string, string[]> result = new Dictionary <string, string[]>();

            string[] highRowContents = new string[6];
            string[] lowRowContents  = new string[6];
            string[] a1RowContents   = new string[6];
            string[] a2RowContents   = new string[6];
            string[] a3RowContents   = new string[6];
            string[] a4RowContents   = new string[6];
            string[] a5RowContents   = new string[6];
            string[] a6RowContents   = new string[6];

            result.Add("highRowContents", highRowContents);
            result.Add("lowRowContents", lowRowContents);
            result.Add("a1RowContents", a1RowContents);
            result.Add("a2RowContents", a2RowContents);
            result.Add("a3RowContents", a3RowContents);
            result.Add("a4RowContents", a4RowContents);
            result.Add("a5RowContents", a5RowContents);
            result.Add("a6RowContents", a6RowContents);

            if (device.AlarmMode == 1)
            {
                if (!string.IsNullOrEmpty(device.AlarmLowLimit))
                {
                    lowRowContents[0] = string.Format("Low limit: {0}°{1}", device.AlarmLowLimit, device.TempUnit);
                    lowRowContents[1] = string.Format("{0}({1})", device.AlarmLowDelay, device.LowAlarmType);
                    lowRowContents[2] = string.Format("{0}", device.tempList.Count == 0 ? string.Empty : device.LowAlarmTotalTimeBelow);
                    lowRowContents[3] = string.Format("{0}", device.tempList.Count == 0 ? string.Empty : device.LowAlarmEvents.ToString());
                    if (device.LowAlarmEvents > 0)
                    {
                        lowRowContents[4] = string.Format("{0}", Convert.ToDateTime(device.LowAlarmFirstTrigged) == DateTime.MinValue ? string.Empty : TempsenFormatHelper.GetFormattedDateTime(Convert.ToDateTime(device.LowAlarmFirstTrigged).ToLocalTime()));
                    }
                    else
                    {
                        lowRowContents[4] = string.Empty;
                    }
                    lowRowContents[5] = string.Format("{0}", device.tempList.Count == 0 ? string.Empty : device.AlarmLowStatus);
                }
                else
                {
                    lowRowContents[0] = "Low limit: ";
                }
                if (!string.IsNullOrEmpty(device.AlarmHighLimit))
                {
                    highRowContents[0] = string.Format("High limit: {0}°{1}", device.AlarmHighLimit, device.TempUnit);
                    highRowContents[1] = string.Format("{0}({1})", device.AlarmHighDelay, device.HighAlarmType);
                    highRowContents[2] = string.Format("{0}", device.tempList.Count == 0 ? string.Empty : device.HighAlarmTotalTimeAbove);
                    highRowContents[3] = string.Format("{0}", device.tempList.Count == 0 ? string.Empty : device.HighAlarmEvents.ToString());
                    if (device.HighAlarmEvents > 0)
                    {
                        highRowContents[4] = string.Format("{0}", Convert.ToDateTime(device.HighAlarmFirstTrigged) == DateTime.MinValue ? string.Empty : TempsenFormatHelper.GetFormattedDateTime(Convert.ToDateTime(device.HighAlarmFirstTrigged).ToLocalTime()));
                    }
                    else
                    {
                        highRowContents[4] = string.Empty;
                    }

                    highRowContents[5] = string.Format("{0}", device.tempList.Count == 0 ? string.Empty : device.AlarmHighStatus);
                }
                else
                {
                    highRowContents[0] = "High limit: ";
                }
            }
            else if (device.AlarmMode == 2)
            {
                if (!string.IsNullOrEmpty(device.A1))
                {
                    a1RowContents[0] = string.Format("A1: over {0}°{1}", device.A1, device.TempUnit);
                    a1RowContents[1] = string.Format("{0}({1})", TempsenFormatHelper.ConvertSencondToFormmatedTime(device.AlarmDelayA1.ToString()), device.AlarmTypeA1);
                    a1RowContents[2] = string.Format("{0}", device.tempList.Count == 0 ? string.Empty : device.AlarmTotalTimeA1);
                    a1RowContents[3] = string.Format("{0}", device.tempList.Count == 0 ? string.Empty : device.AlarmNumA1.ToString());
                    if (device.AlarmNumA1 > 0)
                    {
                        a1RowContents[4] = string.Format("{0}", Convert.ToDateTime(device.AlarmA1First) == DateTime.MinValue ? string.Empty : TempsenFormatHelper.GetFormattedDateTime(Convert.ToDateTime(device.AlarmA1First).ToLocalTime()));
                    }
                    else
                    {
                        a1RowContents[4] = string.Empty;
                    }
                    a1RowContents[5] = string.Format("{0}", device.tempList.Count == 0 ? string.Empty : device.AlarmA1Status);
                }
                else
                {
                    a1RowContents[0] = "A1: ";
                }
                //a5
                if (!string.IsNullOrEmpty(device.A2))
                {
                    a2RowContents[0] = string.Format("A2: over {0}°{1}", device.A2, device.TempUnit);
                    a2RowContents[1] = string.Format("{0}({1})", TempsenFormatHelper.ConvertSencondToFormmatedTime(device.AlarmDelayA2.ToString()), device.AlarmTypeA2);
                    a2RowContents[2] = string.Format("{0}", device.tempList.Count == 0 ? string.Empty : device.AlarmTotalTimeA2);
                    a2RowContents[3] = string.Format("{0}", device.tempList.Count == 0 ? string.Empty : device.AlarmNumA2.ToString());
                    if (device.AlarmNumA2 > 0)
                    {
                        a2RowContents[4] = string.Format("{0}", Convert.ToDateTime(device.AlarmA2First) == DateTime.MinValue ? string.Empty : TempsenFormatHelper.GetFormattedDateTime(Convert.ToDateTime(device.AlarmA2First).ToLocalTime()));
                    }
                    else
                    {
                        a2RowContents[4] = string.Empty;
                    }
                    a2RowContents[5] = string.Format("{0}", device.tempList.Count == 0 ? string.Empty : device.AlarmA2Status);
                }
                else
                {
                    a2RowContents[0] = "A2: ";
                }
                //a4
                if (!string.IsNullOrEmpty(device.A3))
                {
                    a3RowContents[0] = string.Format("A3: over {0}°{1}", device.A3, device.TempUnit);
                    a3RowContents[1] = string.Format("{0}({1})", TempsenFormatHelper.ConvertSencondToFormmatedTime(device.AlarmDelayA3.ToString()), device.AlarmTypeA3);
                    a3RowContents[2] = string.Format("{0}", device.tempList.Count == 0 ? string.Empty : device.AlarmTotalTimeA3);
                    a3RowContents[3] = string.Format("{0}", device.tempList.Count == 0 ? string.Empty : device.AlarmNumA3.ToString());
                    if (device.AlarmNumA3 > 0)
                    {
                        a3RowContents[4] = string.Format("{0}", Convert.ToDateTime(device.AlarmA3First) == DateTime.MinValue ? string.Empty : TempsenFormatHelper.GetFormattedDateTime(Convert.ToDateTime(device.AlarmA3First).ToLocalTime()));
                    }
                    else
                    {
                        a3RowContents[4] = string.Empty;
                    }
                    a3RowContents[5] = string.Format("{0}", device.tempList.Count == 0 ? string.Empty : device.AlarmA3Status);
                }
                else
                {
                    a3RowContents[0] = "A3: ";
                }
                //a3
                a4RowContents[0] = string.Format("A4: {0} to {1}°{2}", device.A4, device.A3, device.TempUnit);
                a4RowContents[1] = string.Format("{0}", "Unlimited");
                a4RowContents[2] = string.Format("{0}", device.tempList.Count == 0 ? string.Empty : device.AlarmTotalTimeIdeal);
                //a2
                if (!string.IsNullOrEmpty(device.A4))
                {
                    a5RowContents[0] = string.Format("A5: under {0}°{1}", device.A4, device.TempUnit);
                    a5RowContents[1] = string.Format("{0}({1})", TempsenFormatHelper.ConvertSencondToFormmatedTime(device.AlarmDelayA4.ToString()), device.AlarmTypeA4);
                    a5RowContents[2] = string.Format("{0}", device.tempList.Count == 0 ? string.Empty : device.AlarmTotalTimeA4);
                    a5RowContents[3] = string.Format("{0}", device.tempList.Count == 0 ? string.Empty : device.AlarmNumA4.ToString());
                    if (device.AlarmNumA4 > 0)
                    {
                        a5RowContents[4] = string.Format("{0}", Convert.ToDateTime(device.AlarmA4First) == DateTime.MinValue ? string.Empty : TempsenFormatHelper.GetFormattedDateTime(Convert.ToDateTime(device.AlarmA4First).ToLocalTime()));
                    }
                    else
                    {
                        a5RowContents[4] = string.Empty;
                    }
                    a5RowContents[5] = string.Format("{0}", device.tempList.Count == 0 ? string.Empty : device.AlarmA4Status);
                }
                else
                {
                    a5RowContents[0] = "A5: ";
                }
                //a1
                if (!string.IsNullOrEmpty(device.A5))
                {
                    a6RowContents[0] = string.Format("A6: under {0}°{1}", device.A5, device.TempUnit);
                    a6RowContents[1] = string.Format("{0}({1})", TempsenFormatHelper.ConvertSencondToFormmatedTime(device.AlarmDelayA5.ToString()), device.AlarmTypeA5);
                    a6RowContents[2] = string.Format("{0}", device.tempList.Count == 0 ? string.Empty : device.AlarmTotalTimeA5);
                    a6RowContents[3] = string.Format("{0}", device.tempList.Count == 0 ? string.Empty : device.AlarmNumA5.ToString());
                    if (device.AlarmNumA5 > 0)
                    {
                        a6RowContents[4] = string.Format("{0}", Convert.ToDateTime(device.AlarmA5First) == DateTime.MinValue ? string.Empty : TempsenFormatHelper.GetFormattedDateTime(Convert.ToDateTime(device.AlarmA5First).ToLocalTime()));
                    }
                    else
                    {
                        a6RowContents[4] = string.Empty;
                    }
                    a6RowContents[5] = string.Format("{0}", device.tempList.Count == 0 ? string.Empty : device.AlarmA5Status);
                }
                else
                {
                    a6RowContents[0] = "A6: ";
                }
            }
            return(result);
        }
示例#3
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;
 }
示例#4
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";
        }
示例#5
0
        private bool ConnectInit(int code)
        {
            bool result = false;

            if (ObjectManage.DeviceNew == null || ObjectManage.DeviceNew.Data == null)
            {
                ObjectManage.DeviceNew = new DevicePDF();
                result = ObjectManage.DeviceNew.connectDevice();
            }
            try
            {
                if (ObjectManage.DeviceNew != null)
                {
                    if (Convert.ToInt32(ObjectManage.DeviceNew.Data.DevModel.Substring(0, 3)) != code / 10)
                    {
                        Common.IsConnectCompleted = true;
                        return(false);
                    }
                    switch (ObjectManage.DeviceNew.Data.DevModel)
                    {
                    case "0100":
                        ProductName = DeviceName = "ITAG-PDF";
                        Model       = "TAGP";
                        DeviceID    = 100;
                        Memory      = 3600;
                        break;

                    case "0101":
                        ProductName = DeviceName = "ITAG3";
                        Model       = "TAGT";
                        DeviceID    = 101;
                        Memory      = 3600;
                        break;

                    case "0102":
                        ProductName = DeviceName = Model = "ITAG3 Pro";
                        Model       = "TAGH";
                        DeviceID    = 102;
                        Memory      = 3600;
                        break;

                    case "0200":
                        ProductName = DeviceName = Model = "Tempod";
                        Model       = "TP15";
                        DeviceID    = 200;
                        Memory      = 3600;
                        break;

                    case "0201":
                        ProductName = DeviceName = Model = "Tempod";
                        Model       = "TP15S";
                        DeviceID    = 201;
                        Memory      = 3600;
                        break;

                    case "0202":
                        ProductName = DeviceName = Model = "Tempod";
                        Model       = "TP25";
                        DeviceID    = 202;
                        Memory      = 7200;
                        break;

                    case "0203":
                        ProductName = DeviceName = Model = "Tempod";
                        Model       = "TP25S";
                        DeviceID    = 203;
                        Memory      = 7200;
                        break;

                    case "0300":
                        ProductName = DeviceName = Model = "Elog TE";
                        Model       = "EL-TE";
                        DeviceID    = 300;
                        Memory      = 7200;
                        break;

                    case "0301":
                        ProductName = DeviceName = Model = "Elog TI";
                        Model       = "EL-TI";
                        DeviceID    = 301;
                        Memory      = 7200;
                        break;

                    default:
                        ProductName = DeviceName = Model = "TAGS";
                        DeviceID    = 100;
                        Memory      = 3600;
                        break;
                    }
                    this.Battery   = ObjectManage.DeviceNew.Data.Battery >= 255 ? "100" : ObjectManage.DeviceNew.Data.Battery.ToString();
                    this.RunStatus = ObjectManage.DeviceNew.Data.RunStatus;
                    switch (ObjectManage.DeviceNew.Data.RunStatus)
                    {
                    case 0:
                        this.CurrentStatus = "Unconfigured";
                        break;

                    case 1:
                        this.CurrentStatus = "Standby";
                        break;

                    case 2:
                        this.CurrentStatus = "Recording";
                        break;

                    default:
                        this.CurrentStatus = "Stopped";
                        break;
                    }
                    this.SerialNumber = ObjectManage.DeviceNew.Data.DevNo.Trim();
                    if (ObjectManage.DeviceNew.Data.RunStatus != 0)
                    {
                        #region summary
                        this.TripNumber  = ObjectManage.DeviceNew.Data.TripNo.Trim() == "" ? SerialNumber : ObjectManage.DeviceNew.Data.TripNo.Trim();
                        this.LogCycle    = string.Format("{0}", TempsenFormatHelper.ConvertSencondToFormmatedTime((ObjectManage.DeviceNew.Data.LogCycle * 3600).ToString()));
                        this.LogInterval = ObjectManage.DeviceNew.Data.LogInterval.ToString();
                        if (ObjectManage.DeviceNew.Data.RunStatus != 1 && ObjectManage.DeviceNew.Data.TempListWithTime.Count > 0)
                        {
                            this.LoggingStart = ObjectManage.DeviceNew.Data.LogStartTime;
                            this.LoggingEnd   = ObjectManage.DeviceNew.Data.LogEndTime;
                            this.TripLength   = TempsenFormatHelper.ConvertSencondToFormmatedTime((LoggingEnd - LoggingStart).TotalSeconds.ToString());
                        }
                        this.Description = ObjectManage.DeviceNew.Data.Description;
                        this.TempUnit    = ObjectManage.DeviceNew.Data.TemperatureUnit == 1 ? "C" : "F";
                        this.StartModel  = ObjectManage.DeviceNew.Data.StartMode == "F8" ? "Manual Start" : "Auto Start";
                        if (ObjectManage.DeviceNew.Data.StartMode == "F8")
                        {
                            this.LogStartDelay = TempsenFormatHelper.ConvertSencondToFormmatedTime((ObjectManage.DeviceNew.Data.StartDelay * 60).ToString());
                        }
                        else
                        {
                            this.StartConditionTime = ObjectManage.DeviceNew.Data.StartConditionTime;
                        }
                        this.AlarmMode = ObjectManage.DeviceNew.Data.AlarmMode;
                        DataPoints     = ObjectManage.DeviceNew.Data.LogCount;
                        if (ObjectManage.DeviceNew.Data.TempListWithTime.Count > 0 && SerializePointInfo(ObjectManage.DeviceNew))
                        {
                            _points.FirstPoint = _points.StartTime = this.LoggingStart;
                            _points.EndTime    = this.LoggingEnd;
                            _points.TripLength = this.TripLength;
                            if (tempList != null && tempList.Count > 0)
                            {
                                AverageC = ObjectManage.DeviceNew.Data.AvgTemp;
                                switch (ObjectManage.DeviceNew.Data.DevModel)
                                {
                                case "0101":
                                case "0200":
                                case "0201":
                                    AverageC = Math.Round(tempList.Select(p => p.PointTemp).Average(), 1).ToString();
                                    MKT      = Common.CalcMKT(tempList.Select(p => (int)(p.PointTemp * 100)).ToList());
                                    break;

                                default:
                                    MKT = ObjectManage.DeviceNew.Data.MKT;
                                    break;
                                }
                                //test mkt
                                //Debug.WriteLine(Common.CalcMKT(tempList.Select(p => (int)p.PointTemp * 100).ToList()), "MKT");
                                HighestC         = ObjectManage.DeviceNew.Data.MaxTemp + "°" + (this.TempUnit) + "@" + ObjectManage.DeviceNew.Data.MaxTempTime.ToString(Common.GetDefaultDateTimeFormat(), CultureInfo.InvariantCulture);
                                LowestC          = ObjectManage.DeviceNew.Data.MinTemp + "°" + (this.TempUnit) + "@" + ObjectManage.DeviceNew.Data.MinTempTime.ToString(Common.GetDefaultDateTimeFormat(), CultureInfo.InvariantCulture);
                                _points.HighestC = this.HighestC;
                                _points.LowestC  = this.LowestC;
                                _points.AVGTemp  = AverageC;
                                _points.MKT      = this.MKT;
                            }
                        }
                        if (ObjectManage.DeviceNew.Data.AlarmMode == 1)
                        {
                            if ((ObjectManage.DeviceNew.Data.AlarmType2 & 0x80) > 0)
                            {
                                AlarmHighLimit = ObjectManage.DeviceNew.Data.AlarmLimits2;
                                AlarmHighDelay = TempsenFormatHelper.ConvertSencondToFormmatedTime(ObjectManage.DeviceNew.Data.AlarmDelay2.ToString());
                                HighAlarmType  = Convert.ToInt32(ObjectManage.DeviceNew.Data.AlarmType2 & 0x01) > 0 ? "Cumulative" : "Single";
                                if (ObjectManage.DeviceNew.Data.RunStatus != 1)
                                {
                                    AlarmHighStatus         = ObjectManage.DeviceNew.Data.AllZoneAlartStatusArray[2] > 0 ? "Alarm" : "OK";
                                    HighAlarmTotalTimeAbove = TempsenFormatHelper.ConvertSencondToFormmatedTime(ObjectManage.DeviceNew.Data.AllZoneOverTempTimeStatArray[2].ToString());
                                    if (ObjectManage.DeviceNew.Data.AllZoneAlartStatusArray[2] > 0)
                                    {
                                        HighAlarmFirstTrigged = ObjectManage.DeviceNew.Data.FirstAlarmTimeArray[2].ToString(Common.GetDefaultDateTimeFormat(), CultureInfo.InvariantCulture);
                                    }
                                    HighAlarmEvents = ObjectManage.DeviceNew.Data.AllZoneOverTempTimesStatArray[2];
                                }
                            }
                            if ((ObjectManage.DeviceNew.Data.AlarmType3 & 0x80) > 0)
                            {
                                AlarmLowLimit = ObjectManage.DeviceNew.Data.AlarmLimits3;
                                AlarmLowDelay = TempsenFormatHelper.ConvertSencondToFormmatedTime(ObjectManage.DeviceNew.Data.AlarmDelay3.ToString());
                                LowAlarmType  = Convert.ToInt32(ObjectManage.DeviceNew.Data.AlarmType3 & 0x01) > 0 ? "Cumulative" : "Single";
                                if (ObjectManage.DeviceNew.Data.RunStatus != 1)
                                {
                                    AlarmLowStatus         = ObjectManage.DeviceNew.Data.AllZoneAlartStatusArray[3] > 0 ? "Alarm" : "OK";
                                    LowAlarmTotalTimeBelow = TempsenFormatHelper.ConvertSencondToFormmatedTime(ObjectManage.DeviceNew.Data.AllZoneOverTempTimeStatArray[3].ToString());
                                    if (ObjectManage.DeviceNew.Data.AllZoneAlartStatusArray[3] > 0)
                                    {
                                        LowAlarmFirstTrigged = ObjectManage.DeviceNew.Data.FirstAlarmTimeArray[3].ToString(Common.GetDefaultDateTimeFormat(), CultureInfo.InvariantCulture);
                                    }
                                    LowAlarmEvents = ObjectManage.DeviceNew.Data.AllZoneOverTempTimesStatArray[3];
                                }
                            }
                        }
                        else if (ObjectManage.DeviceNew.Data.AlarmMode == 2)
                        {
                            if ((ObjectManage.DeviceNew.Data.AlarmType0 & 0x80) > 0)
                            {
                                AlarmDelayA1 = ObjectManage.DeviceNew.Data.AlarmDelay0;
                                A1           = ObjectManage.DeviceNew.Data.AlarmLimits0;
                                AlarmTypeA1  = Convert.ToInt32(ObjectManage.DeviceNew.Data.AlarmType0 & 0x01) > 0 ? "Cumulative" : "Single";
                                if (ObjectManage.DeviceNew.Data.RunStatus != 1)
                                {
                                    if (ObjectManage.DeviceNew.Data.AllZoneAlartStatusArray[0] > 0)
                                    {
                                        AlarmA1First = ObjectManage.DeviceNew.Data.FirstAlarmTimeArray[0].ToString(Common.GetDefaultDateTimeFormat(), CultureInfo.InvariantCulture);
                                    }
                                    AlarmNumA1       = ObjectManage.DeviceNew.Data.AllZoneOverTempTimesStatArray[0];
                                    AlarmA1Status    = ObjectManage.DeviceNew.Data.AllZoneAlartStatusArray[0] == 0 ? "OK" : "Alarm";
                                    AlarmTotalTimeA1 = TempsenFormatHelper.ConvertSencondToFormmatedTime(ObjectManage.DeviceNew.Data.AllZoneOverTempTimeStatArray[0].ToString());
                                }
                            }
                            if ((ObjectManage.DeviceNew.Data.AlarmType1 & 0x80) > 0)
                            {
                                AlarmDelayA2 = ObjectManage.DeviceNew.Data.AlarmDelay1;
                                A2           = ObjectManage.DeviceNew.Data.AlarmLimits1;
                                AlarmTypeA2  = Convert.ToInt32(ObjectManage.DeviceNew.Data.AlarmType1 & 0x01) > 0 ? "Cumulative" : "Single";
                                if (ObjectManage.DeviceNew.Data.RunStatus != 1)
                                {
                                    if (ObjectManage.DeviceNew.Data.AllZoneAlartStatusArray[1] > 0)
                                    {
                                        AlarmA2First = ObjectManage.DeviceNew.Data.FirstAlarmTimeArray[1].ToString(Common.GetDefaultDateTimeFormat(), CultureInfo.InvariantCulture);
                                    }
                                    AlarmA2Status    = ObjectManage.DeviceNew.Data.AllZoneAlartStatusArray[1] == 0 ? "OK" : "Alarm";
                                    AlarmTotalTimeA2 = TempsenFormatHelper.ConvertSencondToFormmatedTime(ObjectManage.DeviceNew.Data.AllZoneOverTempTimeStatArray[1].ToString());
                                }
                            }
                            if ((ObjectManage.DeviceNew.Data.AlarmType4 & 0x80) > 0)
                            {
                                AlarmDelayA5 = ObjectManage.DeviceNew.Data.AlarmDelay4;
                                A5           = ObjectManage.DeviceNew.Data.AlarmLimits4;
                                AlarmTypeA5  = Convert.ToInt32(ObjectManage.DeviceNew.Data.AlarmType4 & 0x01) > 0 ? "Cumulative" : "Single";
                                if (ObjectManage.DeviceNew.Data.RunStatus != 1)
                                {
                                    if (ObjectManage.DeviceNew.Data.AllZoneAlartStatusArray[4] > 0)
                                    {
                                        AlarmA5First = ObjectManage.DeviceNew.Data.FirstAlarmTimeArray[4].ToString(Common.GetDefaultDateTimeFormat(), CultureInfo.InvariantCulture);
                                    }
                                    AlarmNumA5       = ObjectManage.DeviceNew.Data.AllZoneOverTempTimesStatArray[4];
                                    AlarmTotalTimeA5 = TempsenFormatHelper.ConvertSencondToFormmatedTime(ObjectManage.DeviceNew.Data.AllZoneOverTempTimeStatArray[4].ToString());
                                }
                            }
                            AlarmDelayA3 = ObjectManage.DeviceNew.Data.AlarmDelay2;
                            AlarmDelayA4 = ObjectManage.DeviceNew.Data.AlarmDelay3;
                            A3           = ObjectManage.DeviceNew.Data.AlarmLimits2;
                            A4           = ObjectManage.DeviceNew.Data.AlarmLimits3;
                            AlarmTypeA3  = Convert.ToInt32(ObjectManage.DeviceNew.Data.AlarmType2 & 0x01) > 0 ? "Cumulative" : "Single";
                            AlarmTypeA4  = Convert.ToInt32(ObjectManage.DeviceNew.Data.AlarmType3 & 0x01) > 0 ? "Cumulative" : "Single";
                            if (ObjectManage.DeviceNew.Data.RunStatus != 1)
                            {
                                AlarmA3Status = ObjectManage.DeviceNew.Data.AllZoneAlartStatusArray[2] == 0 ? "OK" : "Alarm";
                                AlarmA4Status = ObjectManage.DeviceNew.Data.AllZoneAlartStatusArray[3] == 0 ? "OK" : "Alarm";
                                AlarmA5Status = ObjectManage.DeviceNew.Data.AllZoneAlartStatusArray[4] == 0 ? "OK" : "Alarm";
                                if (ObjectManage.DeviceNew.Data.AllZoneAlartStatusArray[2] > 0)
                                {
                                    AlarmA3First = ObjectManage.DeviceNew.Data.FirstAlarmTimeArray[2].ToString(Common.GetDefaultDateTimeFormat(), CultureInfo.InvariantCulture);
                                }
                                if (ObjectManage.DeviceNew.Data.AllZoneAlartStatusArray[3] > 0)
                                {
                                    AlarmA4First = ObjectManage.DeviceNew.Data.FirstAlarmTimeArray[3].ToString(Common.GetDefaultDateTimeFormat(), CultureInfo.InvariantCulture);
                                }

                                AlarmNumA2          = ObjectManage.DeviceNew.Data.AllZoneOverTempTimesStatArray[1];
                                AlarmNumA3          = ObjectManage.DeviceNew.Data.AllZoneOverTempTimesStatArray[2];
                                AlarmNumA4          = ObjectManage.DeviceNew.Data.AllZoneOverTempTimesStatArray[3];
                                AlarmTotalTimeA3    = TempsenFormatHelper.ConvertSencondToFormmatedTime(ObjectManage.DeviceNew.Data.AllZoneOverTempTimeStatArray[2].ToString());
                                AlarmTotalTimeA4    = TempsenFormatHelper.ConvertSencondToFormmatedTime(ObjectManage.DeviceNew.Data.AllZoneOverTempTimeStatArray[3].ToString());
                                AlarmTotalTimeIdeal = TempsenFormatHelper.ConvertSencondToFormmatedTime(CalcMultiAlarmTotalTime("Ideal").ToString());
                            }
                        }
                        else
                        {
                            //<ToDo>
                        }
                        //Common.IsConnectCompleted = true;
                        //result= ObjectManage.DeviceNew.disconnectDevice();
                        result = true;
                        //return true;
                        #endregion
                    }
                    else
                    {
                        result = true;
                    }
                }
                Common.IsConnectCompleted = true;
                return(result);
            }
            catch
            {
                Common.IsConnectCompleted = true;
                return(false);
            }
        }