コード例 #1
0
        /// <summary>
        /// Reads the TIME out of the stream. Time Format must be set to
        /// a correct value for this to work correctly.
        /// </summary>
        /// <returns>DateTime representing the time of day</returns>
        // Revision History
        // MM/DD/YY who Version Issue# Description
        // -------- --- ------- ------ -------------------------------------------
        // 10/12/06 RCG 7.35.00 N/A    Created

        public TimeSpan ReadTIME(TM_FORMAT TimeFormat)
        {
            TimeSpan tsValue;

            switch (TimeFormat)
            {
            case TM_FORMAT.UINT32_TIME:
            {
                UInt32 uiNumSeconds;
                int    iHours;
                int    iMinutes;
                int    iSeconds;

                // Format in this case is the total number of seconds since
                // 00:00:00
                uiNumSeconds = base.ReadUInt32();

                iHours   = (int)(uiNumSeconds / 3600);
                iMinutes = (int)((uiNumSeconds % 3600) / 60);
                iSeconds = (int)(uiNumSeconds % 60);

                tsValue = new TimeSpan(iHours, iMinutes, iSeconds);
                break;
            }

            default:
            {
                throw (new Exception("Selected Time Format is not implemented"));
            }
            }

            return(tsValue);
        }
コード例 #2
0
        /// <summary>
        /// Reads the STIME out of the stream.  Time Format must be set
        /// to correct value for this to work correctly.
        /// </summary>
        /// <returns>DateTime</returns>
        // Revision History
        // MM/DD/YY who Version Issue# Description
        // -------- --- ------- ------ ---------------------------------------
        // 09/25/06 AF  7.40.00 N/A    Created
        // 11/17/06 AF  8.00.00        Corrected bug with time calculation
        // 03/28/07 AF  8.00.22 2791   This is really Kevin's fix.  LTIME uses a
        //                             reference date of 1/1/1970, not 1/1/2000
        // 06/25/08 AF  1.50.44 116853 This is a hack.  There is a firmware bug
        //                             where an STIME field is initialized with
        //                             0xFFFFFFFF instead of zero.  We will get
        //                             an out of bounds exception if we try to
        //                             add that to the reference date.
        //
        public DateTime ReadSTIME(TM_FORMAT TimeFormat)
        {
            DateTime dtValue;

            switch (TimeFormat)
            {
            case TM_FORMAT.UINT32_TIME:
            {
                UInt32 uiNumMinutes;

                // Format in this case is the first four bytes indicate
                // the number of minutes since Jan. 1st 1970.
                uiNumMinutes = base.ReadUInt32();
                dtValue      = STIMEReferenceDate;

                // If the time has been initialized with all FFs or a high number this could fail
                try
                {
                    dtValue = dtValue.AddMinutes((double)uiNumMinutes);
                }
                catch (Exception)
                {
                    // Just go with the reference date
                }
                break;
            }

            //TODO: Handle other types here...
            default:
            {
                throw (new Exception("Selected Time Format is not implemented"));
            }
            }

            return(dtValue);
        }
コード例 #3
0
        /// <summary>
        /// Reads the LTIME out of the stream.  Time Format must be set
        /// to correct value for this to work correctly.
        /// </summary>
        /// <returns>DateTime</returns>
        //  Revision History
        //  MM/DD/YY Who Version Issue# Description
        //  -------- --- ------- ------ -------------------------------------------
        //                              Created
        //  03/28/07 AF  8.00.22 2791   This is really Kevin's fix.  LTIME uses a
        //                              reference date of 1/1/1970, not 1/1/2000
        //  05/11/09 AF  2.20.04        If an LTIME field is initialized with
        //                              0xFFFFFFFF instead of zero, we will get an
        //                              out of bounds exception if we try to add
        //                              the minutes to the reference date.
        //  05/15/14 MDP                Added support for uint8 time, GE meters use this
        //
        public DateTime ReadLTIME(TM_FORMAT TimeFormat)
        {
            DateTime dtValue;

            switch (TimeFormat)
            {
            case TM_FORMAT.UINT32_TIME:
            {
                UInt32 uiNumMinutes;
                uint   uiNumSeconds;

                // Format in this case is the first four bytes indicate
                // the number of minutes since Jan. 1st 1970.  The last
                // byte indicates number of seconds.
                uiNumMinutes = base.ReadUInt32();
                uiNumSeconds = base.ReadByte();

                dtValue = LTIMEReferenceDate;

                // If the time has been initialized with all FFs, don't
                // try to use it -- it's invalid
                if (0xFFFFFFFF > uiNumMinutes)
                {
                    dtValue = dtValue.AddMinutes((double)uiNumMinutes);
                    dtValue = dtValue.AddSeconds((double)uiNumSeconds);
                }

                break;
            }
            //TODO: Handle other types here...
            //case TM_FORMAT.UINT8_TIME:
            //{
            //    //uint8: year, month, day, hour, minute, second
            //    byte byYear;
            //    byte byMonth;
            //    byte byDay;
            //    byte byNumHours;
            //    byte byNumMinutes;
            //    byte byNumSeconds;

            //    byYear = base.ReadByte();
            //    byMonth = base.ReadByte();
            //    byDay = base.ReadByte();
            //    byNumHours = base.ReadByte();
            //    byNumMinutes = base.ReadByte();
            //    byNumSeconds = base.ReadByte();

            //    dtValue = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Local);
            //    dtValue = dtValue.AddYears(byYear);
            //    dtValue = dtValue.AddMonths(byMonth - 1);
            //    dtValue = dtValue.AddDays(byDay - 1);
            //    dtValue = dtValue.AddHours(byNumHours);
            //    dtValue = dtValue.AddMinutes(byNumMinutes);
            //    dtValue = dtValue.AddSeconds(byNumSeconds);

            //    break;
            //}
            default:
            {
                throw(new Exception("Selected Time Format is not implemented"));
            }
            }

            return(dtValue);
        }