Exemplo n.º 1
0
        /// <inheritdoc cref="IGXDLMSBase.GetDataType"/>
        public override DataType GetDataType(int index)
        {
            DataType dt;

            switch (index)
            {
            case 1:
                dt = DataType.OctetString;
                break;

            case 2:
                dt = base.GetDataType(index);
                if (dt == DataType.None && CurrentAverageValue != null)
                {
                    dt = GXCommon.GetDLMSDataType(CurrentAverageValue.GetType());
                }
                break;

            case 3:
                dt = base.GetDataType(index);
                if (dt == DataType.None && LastAverageValue != null)
                {
                    dt = GXCommon.GetDLMSDataType(LastAverageValue.GetType());
                }
                break;

            case 4:
                dt = DataType.Array;
                break;

            case 5:
                dt = base.GetDataType(index);
                if (dt == DataType.None && Status != null)
                {
                    dt = GXCommon.GetDLMSDataType(Status.GetType());
                }
                break;

            case 6:
                dt = DataType.OctetString;
                break;

            case 7:
                dt = DataType.OctetString;
                break;

            case 8:
                dt = DataType.UInt32;
                break;

            case 9:
                dt = DataType.UInt16;
                break;

            default:
                throw new ArgumentException("GetDataType failed. Invalid attribute index.");
            }
            return(dt);
        }
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return(GXCommon.LogicalNameToBytes(LogicalName));
     }
     if (e.Index == 2)
     {
         //If client set new value.
         if (!settings.IsServer && Scaler != 1 && CurrentAverageValue != null)
         {
             Type type = null;
             if (CurrentAverageValue != null)
             {
                 type = CurrentAverageValue.GetType();
             }
             object tmp;
             tmp = Convert.ToDouble(CurrentAverageValue) / Scaler;
             if (type != null)
             {
                 tmp = Convert.ChangeType(tmp, type);
             }
             return(tmp);
         }
         return(CurrentAverageValue);
     }
     if (e.Index == 3)
     {
         //If client set new value.
         if (!settings.IsServer && Scaler != 1 && LastAverageValue != null)
         {
             DataType dt = base.GetDataType(3);
             if (dt == DataType.None && LastAverageValue != null)
             {
                 dt = GXCommon.GetDLMSDataType(LastAverageValue.GetType());
             }
             object tmp;
             tmp = Convert.ToDouble(LastAverageValue) / Scaler;
             if (dt != DataType.None)
             {
                 tmp = Convert.ChangeType(tmp, GXCommon.GetDataType(dt));
             }
             return(tmp);
         }
         return(LastAverageValue);
     }
     if (e.Index == 4)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Structure);
         data.SetUInt8(2);
         GXCommon.SetData(settings, data, DataType.Int8, scaler);
         GXCommon.SetData(settings, data, DataType.Enum, Unit);
         return(data.Array());
     }
     if (e.Index == 5)
     {
         return(Status);
     }
     if (e.Index == 6)
     {
         return(CaptureTime);
     }
     if (e.Index == 7)
     {
         return(StartTimeCurrent);
     }
     if (e.Index == 8)
     {
         return(Period);
     }
     if (e.Index == 9)
     {
         return(NumberOfPeriods);
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return(null);
 }