/// <summary> /// This method retrieves a BCD integer from the meter and returns it as a string value /// </summary> /// <returns></returns> /// <remarks > /// MM/DD/YY who Version Issue# Description /// -------- --- ------- ------ --------------------------------------- /// 12/07/06 mah 8.00.00 N/A Created /// </remarks> protected string GetBCDValue(ref SCSDevice device) { string strBCDValue; int nBCDValue = 0; int nAddress = device.TranslateDisplayAddress(this); if (nAddress != 0x0) { switch (RegisterType) { case 0: // 1 byte field nBCDValue = device.ReadBCDInteger(nAddress, 1); break; case 1: // 2 byte field nBCDValue = device.ReadBCDInteger(nAddress, 2); break; case 2: // 3 byte field nBCDValue = device.ReadBCDInteger(nAddress, 3); break; case 3: // MSN nBCDValue = device.ReadBCDInteger(nAddress, 1); break; case 4: // LSN nBCDValue = device.ReadBCDInteger(nAddress, 1); break; } strBCDValue = nBCDValue.ToString(CultureInfo.InvariantCulture); } else { strBCDValue = ""; } return(strBCDValue); }
/// <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); }