void IGXDLMSBase.Load(GXXmlReader reader)
        {
            PushObjectList.Clear();
            if (reader.IsStartElement("ObjectList", true))
            {
                while (reader.IsStartElement("Item", true))
                {
                    ObjectType ot = (ObjectType)reader.ReadElementContentAsInt("ObjectType");
                    string     ln = reader.ReadElementContentAsString("LN");
                    int        ai = reader.ReadElementContentAsInt("AI");
                    int        di = reader.ReadElementContentAsInt("DI");
                    reader.ReadEndElement("Item");
                    GXDLMSCaptureObject co  = new GXDLMSCaptureObject(ai, di);
                    GXDLMSObject        obj = reader.Objects.FindByLN(ot, ln);
                    if (obj == null)
                    {
                        obj             = GXDLMSClient.CreateObject(ot);
                        obj.LogicalName = ln;
                    }
                    PushObjectList.Add(new KeyValuePair <Objects.GXDLMSObject, Objects.GXDLMSCaptureObject>(obj, co));
                }
                reader.ReadEndElement("ObjectList");
            }

            Service     = (ServiceType)reader.ReadElementContentAsInt("Service");
            Destination = reader.ReadElementContentAsString("Destination");
            Message     = (MessageType)reader.ReadElementContentAsInt("Message");
            CommunicationWindow.Clear();
            if (reader.IsStartElement("CommunicationWindow", true))
            {
                while (reader.IsStartElement("Item", true))
                {
                    GXDateTime start = new GXDateTime(reader.ReadElementContentAsString("Start"), CultureInfo.InvariantCulture);
                    GXDateTime end   = new GXDateTime(reader.ReadElementContentAsString("End"), CultureInfo.InvariantCulture);
                    CommunicationWindow.Add(new KeyValuePair <DLMS.GXDateTime, DLMS.GXDateTime>(start, end));
                }
                reader.ReadEndElement("CommunicationWindow");
            }
            RandomisationStartInterval = (ushort)reader.ReadElementContentAsInt("RandomisationStartInterval");
            NumberOfRetries            = (byte)reader.ReadElementContentAsInt("NumberOfRetries");
            RepetitionDelay            = (ushort)reader.ReadElementContentAsInt("RepetitionDelay");
        }
Esempio n. 2
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         if (e.Value is string)
         {
             LogicalName = e.Value.ToString();
         }
         else
         {
             LogicalName = GXDLMSClient.ChangeType((byte[])e.Value, DataType.OctetString, settings.UseUtc2NormalTime).ToString();
         }
     }
     else if (e.Index == 2)
     {
         PushObjectList.Clear();
         if (e.Value is Object[])
         {
             foreach (object it in e.Value as Object[])
             {
                 Object[]     tmp  = it as Object[];
                 ObjectType   type = (ObjectType)Convert.ToUInt16(tmp[0]);
                 String       ln   = GXDLMSClient.ChangeType((byte[])tmp[1], DataType.OctetString, settings.UseUtc2NormalTime).ToString();
                 GXDLMSObject obj  = settings.Objects.FindByLN(type, ln);
                 if (obj == null)
                 {
                     obj             = GXDLMSClient.CreateObject(type);
                     obj.LogicalName = ln;
                 }
                 GXDLMSCaptureObject co = new GXDLMSCaptureObject(Convert.ToInt32(tmp[2]), Convert.ToInt32(tmp[3]));
                 PushObjectList.Add(new KeyValuePair <GXDLMSObject, GXDLMSCaptureObject>(obj, co));
             }
         }
     }
     else if (e.Index == 3)
     {
         object[] tmp = e.Value as object[];
         if (tmp != null)
         {
             Service     = (ServiceType)Convert.ToInt32(tmp[0]);
             Destination = (string)GXDLMSClient.ChangeType((byte[])tmp[1], DataType.String, settings.UseUtc2NormalTime);
             Message     = (MessageType)Convert.ToInt32(tmp[2]);
         }
     }
     else if (e.Index == 4)
     {
         CommunicationWindow.Clear();
         if (e.Value is Object[])
         {
             foreach (object it in e.Value as Object[])
             {
                 Object[]   tmp   = it as Object[];
                 GXDateTime start = GXDLMSClient.ChangeType((byte[])tmp[0], DataType.DateTime, settings.UseUtc2NormalTime) as GXDateTime;
                 GXDateTime end   = GXDLMSClient.ChangeType((byte[])tmp[1], DataType.DateTime, settings.UseUtc2NormalTime) as GXDateTime;
                 CommunicationWindow.Add(new KeyValuePair <GXDateTime, GXDateTime>(start, end));
             }
         }
     }
     else if (e.Index == 5)
     {
         RandomisationStartInterval = (UInt16)e.Value;
     }
     else if (e.Index == 6)
     {
         NumberOfRetries = (byte)e.Value;
     }
     else if (e.Index == 7)
     {
         RepetitionDelay = (UInt16)e.Value;
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         PushObjectList.Clear();
         List <object> it;
         if (e.Value != null)
         {
             foreach (object t in (IEnumerable <object>)e.Value)
             {
                 if (t is List <object> )
                 {
                     it = (List <object>)t;
                 }
                 else
                 {
                     it = new List <object>((object[])t);
                 }
                 ObjectType   type = (ObjectType)Convert.ToUInt16(it[0]);
                 String       ln   = GXCommon.ToLogicalName(it[1]);
                 GXDLMSObject obj  = settings.Objects.FindByLN(type, ln);
                 if (obj == null)
                 {
                     obj             = GXDLMSClient.CreateObject(type);
                     obj.LogicalName = ln;
                 }
                 GXDLMSCaptureObject co = new GXDLMSCaptureObject(Convert.ToInt32(it[2]), Convert.ToInt32(it[3]));
                 PushObjectList.Add(new KeyValuePair <GXDLMSObject, GXDLMSCaptureObject>(obj, co));
             }
         }
     }
     else if (e.Index == 3)
     {
         List <object> tmp = null;
         if (e.Value is List <object> )
         {
             tmp = (List <object>)e.Value;
         }
         else
         {
             tmp = new List <object>((object[])e.Value);
         }
         if (tmp != null)
         {
             Service = (ServiceType)Convert.ToInt32(tmp[0]);
             //LN can be used with HDLC
             if (Service == ServiceType.Hdlc && ((byte[])tmp[1]).Length == 6 && ((byte[])tmp[1])[5] == 0xFF)
             {
                 Destination = GXCommon.ToLogicalName((byte[])tmp[1]);
             }
             else
             {
                 object str = GXDLMSClient.ChangeType((byte[])tmp[1], DataType.String, settings.UseUtc2NormalTime);
                 if (str is string)
                 {
                     Destination = (string)str;
                 }
                 else
                 {
                     Destination = GXCommon.ToHex((byte[])tmp[1], true);
                 }
             }
             Message = (MessageType)Convert.ToInt32(tmp[2]);
         }
     }
     else if (e.Index == 4)
     {
         CommunicationWindow.Clear();
         if (e.Value is List <object> )
         {
             foreach (List <object> it in e.Value as List <object> )
             {
                 GXDateTime start = GXDLMSClient.ChangeType((byte[])it[0], DataType.DateTime, settings.UseUtc2NormalTime) as GXDateTime;
                 GXDateTime end   = GXDLMSClient.ChangeType((byte[])it[1], DataType.DateTime, settings.UseUtc2NormalTime) as GXDateTime;
                 CommunicationWindow.Add(new KeyValuePair <GXDateTime, GXDateTime>(start, end));
             }
         }
     }
     else if (e.Index == 5)
     {
         RandomisationStartInterval = (UInt16)e.Value;
     }
     else if (e.Index == 6)
     {
         NumberOfRetries = (byte)e.Value;
     }
     else if (e.Index == 7)
     {
         RepetitionDelay = (UInt16)e.Value;
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
Esempio n. 4
0
 void IGXDLMSBase.SetValue(int index, object value)
 {
     if (index == 1)
     {
         if (value is string)
         {
             LogicalName = value.ToString();
         }
         else
         {
             LogicalName = GXDLMSClient.ChangeType((byte[])value, DataType.OctetString).ToString();
         }
     }
     else if (index == 2)
     {
         PushObjectList.Clear();
         if (value is Object[])
         {
             foreach (object it in value as Object[])
             {
                 Object[]         tmp = it as Object[];
                 GXDLMSPushObject obj = new GXDLMSPushObject();
                 obj.Type           = (ObjectType)Convert.ToInt32(tmp[0]);
                 obj.LogicalName    = GXDLMSClient.ChangeType((byte[])tmp[1], DataType.BitString).ToString();
                 obj.AttributeIndex = Convert.ToInt32(tmp[2]);
                 obj.DataIndex      = Convert.ToInt32(tmp[3]);
                 PushObjectList.Add(obj);
             }
         }
     }
     else if (index == 3)
     {
         object[] tmp = value as object[];
         if (tmp != null)
         {
             SendDestinationAndMethod.Service     = (ServiceType)Convert.ToInt32(tmp[0]);
             SendDestinationAndMethod.Destination = ASCIIEncoding.ASCII.GetString((byte[])tmp[1]);
             SendDestinationAndMethod.Message     = (MessageType)Convert.ToInt32(tmp[2]);
         }
     }
     else if (index == 4)
     {
         CommunicationWindow.Clear();
         if (value is Object[])
         {
             foreach (object it in value as Object[])
             {
                 Object[]   tmp   = it as Object[];
                 GXDateTime start = GXDLMSClient.ChangeType((byte[])tmp[0], DataType.DateTime) as GXDateTime;
                 GXDateTime end   = GXDLMSClient.ChangeType((byte[])tmp[1], DataType.DateTime) as GXDateTime;
                 CommunicationWindow.Add(new KeyValuePair <GXDateTime, GXDateTime>(start, end));
             }
         }
     }
     else if (index == 5)
     {
         RandomisationStartInterval = (UInt16)value;
     }
     else if (index == 6)
     {
         NumberOfRetries = (byte)value;
     }
     else if (index == 7)
     {
         RepetitionDelay = (UInt16)value;
     }
     else
     {
         throw new ArgumentException("SetValue failed. Invalid attribute index.");
     }
 }