Beispiel #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);
        }
Beispiel #2
0
        /// <summary>
        /// This method retrieves a date 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.  Also
        /// note that the value may or may not contain a year
        /// </summary>
        /// <returns></returns>
        /// <remarks >
        /// MM/DD/YY who Version Issue# Description
        /// -------- --- ------- ------ ---------------------------------------
        /// 12/07/06 mah 8.00.00  N/A   Created
        /// </remarks>
        protected string GetDateValue(ref SCSDevice device)
        {
            int    nYear = 0;
            int    nMonth;
            int    nDay;
            String strValue = "";

            DateTime dateValue;

            // The register type indicates the format while the address indicates which
            // value is to be displayed

            if (LowerAddress == 0) // this is a special case - the meter's current date
            {
                dateValue = device.DeviceTime;

                nYear  = dateValue.Year % 100; // note that the devices only store 2 digits for the year
                nMonth = dateValue.Month;
                nDay   = dateValue.Day;
            }
            else
            {
                // We need to determine if we should upload 2 bytes for the month and the day
                // verses 3 bytes for month day year.  If register type calls for a year to be displayed
                // the value must be a 3 byte date that includes the year.  If the register type only
                // calls for month and day, then we have to assume that at 2 byte date is being used

                if (RegisterType == 3 || RegisterType == 4)
                {
                    device.ReadBCDDate(device.TranslateDisplayAddress(this), out nMonth, out nDay);
                }
                else
                {
                    device.ReadBCDDate(device.TranslateDisplayAddress(this), out nYear, out nMonth, out nDay);
                }
            }

            // 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:     // date as MM-DD-YY
                strValue = nMonth.ToString("00", CultureInfo.InvariantCulture) + "-" + nDay.ToString("00", CultureInfo.InvariantCulture) + "-" + nYear.ToString("00", CultureInfo.InvariantCulture);
                break;

            case 1:     // date as DD-MM-YY
                strValue = nDay.ToString("00", CultureInfo.InvariantCulture) + "-" + nMonth.ToString("00", CultureInfo.InvariantCulture) + "-" + nYear.ToString("00", CultureInfo.InvariantCulture);
                break;

            case 2:     // date as YY-MM-DD
                strValue = nYear.ToString("00", CultureInfo.InvariantCulture) + "-" + nMonth.ToString("00", CultureInfo.InvariantCulture) + "-" + nDay.ToString("00", CultureInfo.InvariantCulture);
                break;

            case 3:     // date as MM-DD
                strValue = nMonth.ToString("00", CultureInfo.InvariantCulture) + "-" + nDay.ToString("00", CultureInfo.InvariantCulture);
                break;

            case 4:     // date as DD-MM
                strValue = nDay.ToString("00", CultureInfo.InvariantCulture) + "-" + nMonth.ToString("00", CultureInfo.InvariantCulture);
                break;
            }

            return(strValue);
        }