Ejemplo n.º 1
0
        /// <summary>
        /// This method retrieves a time from the meter and formats it according
        /// to the display'ss formatting rules established in the meter's program.  NOte that
        /// the value is not formatted according regional settings or preferences.  The
        /// value will be formatted precisely as it would be displayed by the meter.
        /// </summary>
        /// <returns></returns>
        /// <remarks >
        /// MM/DD/YY who Version Issue# Description
        /// -------- --- ------- ------ ---------------------------------------
        /// 12/07/06 mah 8.00.00  N/A   Created
        /// </remarks>
        protected string GetTimeValue(ref SCSDevice device)
        {
            String strValue = "";

            int nBasepageAddress = device.TranslateDisplayAddress(this);

            // NOte that there are certain dates & times that are simply not available.  They are
            // indicated by a basepage address of zero.  If we encounter one of these simply
            // return an empty string

            if (nBasepageAddress != 0x0)
            {
                int      nHour;
                int      nMinute;
                int      nSecond = 0;
                DateTime dateValue;

                // The register type indicates the format while the address indicates which
                // value is to be displayed
                if (LowerAddress == 0x06) // this is a special case - the meter's current date
                {
                    dateValue = device.DeviceTime;

                    nHour   = dateValue.Hour;
                    nMinute = dateValue.Minute;
                    nSecond = dateValue.Second;
                }
                else
                {
                    if (RegisterType == 0)
                    {
                        device.ReadBCDTime(nBasepageAddress, out nHour, out nMinute, out nSecond);
                    }
                    else
                    {
                        device.ReadBCDDate(nBasepageAddress, out nHour, out nMinute);
                    }
                }

                // Now that we have a valid date, we can go ahead and format it as it was shown
                // on the display

                switch (RegisterType)
                {
                case 0:     // time as HH-MM:SS
                    strValue = nHour.ToString("00", CultureInfo.InvariantCulture) + ":" + nMinute.ToString("00", CultureInfo.InvariantCulture) + ":" + nSecond.ToString("00", CultureInfo.InvariantCulture);
                    break;

                case 1:     // date as HH:MM or MM:SS
                    strValue = nHour.ToString("00", CultureInfo.InvariantCulture) + ":" + nMinute.ToString("00", CultureInfo.InvariantCulture);
                    break;
                }
            }

            return(strValue);
        }