/// <summary>
 /// Deletes an entry from the table.
 /// </summary>
 public byte[][] Delete(GXDLMSClient client, GXDLMSTarget entry)
 {
     GXByteBuffer bb = new GXByteBuffer();
     bb.SetUInt8(DataType.Structure);
     bb.SetUInt8(3);
     GXCommon.SetData(null, bb, DataType.UInt16, entry.Target.ObjectType);
     GXCommon.SetData(null, bb, DataType.OctetString, GXCommon.LogicalNameToBytes(entry.Target.LogicalName));
     GXCommon.SetData(null, bb, DataType.Int8, entry.AttributeIndex);
     return client.Method(this, 2, bb.Array(), DataType.Array);
 }
 byte[] IGXDLMSBase.Invoke(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index != 1 && e.Index != 2)
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
     else
     {
         if (e.Index == 1)
         {
             List <object> tmp   = (List <object>)e.Parameters;
             ObjectType    type  = (ObjectType)Convert.ToUInt16(tmp[0]);
             string        ln    = GXCommon.ToLogicalName((byte[])tmp[1]);
             byte          index = Convert.ToByte(tmp[2]);
             foreach (GXDLMSTarget item in Parameters)
             {
                 if (item.Target.ObjectType == type && item.Target.LogicalName == ln && item.AttributeIndex == index)
                 {
                     Parameters.Remove(item);
                     break;
                 }
             }
             GXDLMSTarget it = new GXDLMSTarget();
             it.Target = settings.Objects.FindByLN(type, (byte[])tmp[1]);
             if (it.Target == null)
             {
                 it.Target             = GXDLMSClient.CreateObject(type);
                 it.Target.LogicalName = ln;
             }
             it.AttributeIndex = index;
             Parameters.Add(it);
         }
         else if (e.Index == 2)
         {
             List <object> tmp   = (List <object>)e.Parameters;
             ObjectType    ot    = (ObjectType)Convert.ToUInt16(tmp[0]);
             string        ln    = GXCommon.ToLogicalName((byte[])tmp[1]);
             byte          index = Convert.ToByte(tmp[2]);
             foreach (GXDLMSTarget item in Parameters)
             {
                 if (item.Target.ObjectType == ot && item.Target.LogicalName == ln && item.AttributeIndex == index)
                 {
                     Parameters.Remove(item);
                     break;
                 }
             }
         }
     }
     return(null);
 }
 void IGXDLMSBase.Load(GXXmlReader reader)
 {
     ChangedParameter = new GXDLMSTarget();
     if (reader.IsStartElement("ChangedParameter", true))
     {
         ObjectType ot = (ObjectType)reader.ReadElementContentAsInt("Type");
         string     ln = reader.ReadElementContentAsString("LN");
         ChangedParameter.Target = reader.Objects.FindByLN(ot, ln);
         if (ChangedParameter.Target == null)
         {
             ChangedParameter.Target             = GXDLMSClient.CreateObject(ot);
             ChangedParameter.Target.LogicalName = ln;
         }
         ChangedParameter.AttributeIndex = (byte)reader.ReadElementContentAsInt("Index");
         ChangedParameter.Value          = reader.ReadElementContentAsObject("Value", null);
         reader.ReadEndElement("ChangedParameter");
     }
     if (string.Compare("Time", reader.Name, true) == 0)
     {
         CaptureTime = new GXDateTime(reader.ReadElementContentAsString("Time"), CultureInfo.InvariantCulture);
     }
     else
     {
         CaptureTime = DateTime.MinValue;
     }
     Parameters.Clear();
     if (reader.IsStartElement("Parameters", true))
     {
         while (reader.IsStartElement("Item", true))
         {
             GXDLMSTarget obj = new GXDLMSTarget();
             ObjectType   ot  = (ObjectType)reader.ReadElementContentAsInt("Type");
             string       ln  = reader.ReadElementContentAsString("LN");
             obj.Target = reader.Objects.FindByLN(ot, ln);
             if (obj.Target == null)
             {
                 obj.Target             = GXDLMSClient.CreateObject(ot);
                 obj.Target.LogicalName = ln;
             }
             obj.AttributeIndex = (byte)reader.ReadElementContentAsInt("Index");
             Parameters.Add(obj);
         }
         reader.ReadEndElement("Parameters");
     }
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="ln">Logical Name of the object.</param>
 /// <param name="sn">Short Name of the object.</param>
 public GXDLMSParameterMonitor(string ln, ushort sn)
     : base(ObjectType.ParameterMonitor, ln, sn)
 {
     Parameters       = new List <GXDLMSTarget>();
     ChangedParameter = new GXDLMSTarget();
 }
        void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
        {
            switch (e.Index)
            {
            case 1:
                LogicalName = GXCommon.ToLogicalName(e.Value);
                break;

            case 2:
            {
                ChangedParameter = new GXDLMSTarget();
                if (e.Value is List <object> )
                {
                    List <object> tmp = (List <object>)e.Value;
                    if (tmp.Count != 4)
                    {
                        throw new GXDLMSException("Invalid structure format.");
                    }
                    ObjectType type = (ObjectType)Convert.ToInt16(tmp[0]);
                    ChangedParameter.Target = settings.Objects.FindByLN(type, (byte[])tmp[1]);
                    if (ChangedParameter.Target == null)
                    {
                        ChangedParameter.Target             = GXDLMSClient.CreateObject(type);
                        ChangedParameter.Target.LogicalName = GXCommon.ToLogicalName((byte[])tmp[1]);
                    }
                    ChangedParameter.AttributeIndex = Convert.ToByte(tmp[2]);
                    ChangedParameter.Value          = tmp[3];
                }

                break;
            }

            case 3:
            {
                if (e.Value == null)
                {
                    CaptureTime = new GXDateTime(DateTime.MinValue);
                }
                else
                {
                    if (e.Value is byte[])
                    {
                        e.Value = GXDLMSClient.ChangeType((byte[])e.Value, DataType.DateTime, settings.UseUtc2NormalTime);
                    }
                    else if (e.Value is string)
                    {
                        e.Value = new GXDateTime((string)e.Value);
                    }
                    if (e.Value is GXDateTime)
                    {
                        CaptureTime = (GXDateTime)e.Value;
                    }
                    else if (e.Value is String)
                    {
                        DateTime tm;
                        if (!DateTime.TryParse((String)e.Value, out tm))
                        {
                            CaptureTime = DateTime.ParseExact((String)e.Value, CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern + " " + CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern, CultureInfo.CurrentUICulture);
                        }
                        else
                        {
                            CaptureTime = tm;
                        }
                    }
                    else
                    {
                        CaptureTime = Convert.ToDateTime(e.Value);
                    }
                }

                break;
            }

            case 4:
            {
                Parameters.Clear();
                if (e.Value != null)
                {
                    foreach (List <object> tmp in (e.Value as List <object>))
                    {
                        if (tmp.Count != 3)
                        {
                            throw new GXDLMSException("Invalid structure format.");
                        }
                        GXDLMSTarget obj  = new GXDLMSTarget();
                        ObjectType   type = (ObjectType)Convert.ToInt16(tmp[0]);
                        obj.Target = settings.Objects.FindByLN(type, (byte[])tmp[1]);
                        if (obj.Target == null)
                        {
                            obj.Target             = GXDLMSClient.CreateObject(type);
                            obj.Target.LogicalName = GXCommon.ToLogicalName((byte[])tmp[1]);
                        }
                        obj.AttributeIndex = Convert.ToByte(tmp[2]);
                        Parameters.Add(obj);
                    }
                }

                break;
            }

            default:
                e.Error = ErrorCode.ReadWriteDenied;
                break;
            }
        }