Beispiel #1
0
        /// <summary>
        /// This method retrieves an energy value from the meter and formats it according
        /// to the meter's formatting rules established in the meter's program
        /// </summary>
        /// <returns></returns>
        /// <remarks >
        /// MM/DD/YY who Version Issue# Description
        /// -------- --- ------- ------ ---------------------------------------
        /// 12/07/06 mah 8.00.00  N/A   Created
        /// </remarks>
        protected string GetEnergyValue(ref SCSDevice device)
        {
            String strValue;

            if (RegisterType == 0x00 || RegisterType == 0x02 || RegisterType == 0x03)
            {
                strValue = device.ReadFixedBCDValue(device.TranslateDisplayAddress(this), 4, 7);
            }
            else if (RegisterType == 0x07)
            {
                strValue = device.ReadFloatingBCDValue(device.TranslateDisplayAddress(this), 3);
            }
            else
            {
                strValue = "";
            }

            if (strValue.Length > 0)
            {
                // Now that we have a value that we can display we need to format it to match
                // the display format currently configured in the meter

                strValue = FormatDisplayValue(strValue, device.EnergyFormat);
            }

            return(strValue);
        }
Beispiel #2
0
        /// <summary>
        /// This method retrieves a BCD floating point from the meter.  Note that the
        /// value is returned as a string in order to prevent any rounding or client formatting
        /// issues.
        /// </summary>
        /// <returns></returns>
        /// <remarks >
        /// MM/DD/YY who Version Issue# Description
        /// -------- --- ------- ------ ---------------------------------------
        /// 12/07/06 mah 8.00.00  N/A   Created
        /// 03/12/07 mah 8.00.18           Removed leading zeros per SCR #2459
        /// </remarks>
        protected string GetFixedBCDValue(ref SCSDevice device)
        {
            String strValue = "";;

            int nBasepageAddress = device.TranslateDisplayAddress(this);

            // A basepage address of zero indicates that the item is either undefined
            // or not displayable - simply return an empty string in this case
            if (nBasepageAddress != 0x00)
            {
                if (RegisterClass == SCSDisplayClass.ExtendedBCDValue)
                {
                    // The extended BCD format is XXX.XXX - we need to treat this a 3 byte BCD integer
                    // and manually insert the decimal point

                    int    nBCDValue = device.ReadBCDInteger(device.TranslateDisplayAddress(this), 3);
                    double fValue    = (nBCDValue / 1000.0);

                    strValue = fValue.ToString("##0.000", CultureInfo.InvariantCulture);
                }
                else if (RegisterType == 0x01)
                {
                    strValue = device.ReadFixedBCDValue(device.TranslateDisplayAddress(this), 1, 2);
                }
                else if (RegisterType == 0x02)
                {
                    strValue = device.ReadFixedBCDValue(device.TranslateDisplayAddress(this), 1, 3);
                }
            }

            // Remove leading zeros - addresses SCR #2459
            strValue = strValue.TrimStart('0');

            // But did we get trim too much?
            int nDecimalLocation = strValue.IndexOf('.');

            // if so, add the initial zero back
            if (nDecimalLocation < 1)
            {
                strValue = strValue.Insert(0, "0");
            }

            return(strValue);
        }