Ejemplo n.º 1
0
        void IGXDLMSBase.Load(GXXmlReader reader)
        {
            DataLinkLayerReference = reader.ReadElementContentAsString("DataLinkLayerReference");
            IPAddress = reader.ReadElementContentAsString("IPAddress");
            List <string> list = new List <string>();

            if (reader.IsStartElement("MulticastIPAddress", true))
            {
                while (reader.IsStartElement("Value", false))
                {
                    list.Add(reader.ReadElementContentAsString("Value"));
                }
                reader.ReadEndElement("MulticastIPAddress");
            }
            MulticastIPAddress = list.ToArray();

            List <GXDLMSIp4SetupIpOption> ipOptions = new List <GXDLMSIp4SetupIpOption>();

            if (reader.IsStartElement("IPOptions", true))
            {
                while (reader.IsStartElement("IPOptions", true))
                {
                    GXDLMSIp4SetupIpOption it = new GXDLMSIp4SetupIpOption();
                    it.Type   = (Ip4SetupIpOptionType)reader.ReadElementContentAsInt("Type");
                    it.Length = (byte)reader.ReadElementContentAsInt("Length");
                    it.Data   = GXDLMSTranslator.HexToBytes(reader.ReadElementContentAsString("Data"));
                    ipOptions.Add(it);
                }
                reader.ReadEndElement("IPOptions");
            }
            IPOptions        = ipOptions.ToArray();
            SubnetMask       = reader.ReadElementContentAsString("SubnetMask");
            GatewayIPAddress = reader.ReadElementContentAsString("GatewayIPAddress");
            if (string.IsNullOrEmpty(GatewayIPAddress))
            {
                GatewayIPAddress = "0.0.0.0";
            }
            UseDHCP           = reader.ReadElementContentAsInt("UseDHCP") != 0;
            PrimaryDNSAddress = reader.ReadElementContentAsString("PrimaryDNSAddress");
            if (string.IsNullOrEmpty(PrimaryDNSAddress))
            {
                PrimaryDNSAddress = "0.0.0.0";
            }
            SecondaryDNSAddress = reader.ReadElementContentAsString("SecondaryDNSAddress");
            if (string.IsNullOrEmpty(SecondaryDNSAddress))
            {
                SecondaryDNSAddress = "0.0.0.0";
            }
        }
Ejemplo n.º 2
0
        void IGXDLMSBase.Load(GXXmlReader reader)
        {
            DataLinkLayerReference = reader.ReadElementContentAsString("DataLinkLayerReference");
            IPAddress = GetIpaddress(reader.ReadElementContentAsString("IPAddress"));
            List <IPAddress> list = new List <IPAddress>();

            if (reader.IsStartElement("MulticastIPAddress", true))
            {
                while (reader.IsStartElement("Value", false))
                {
                    list.Add(GetIpaddress(reader.ReadElementContentAsString("Value")));
                }
                reader.ReadEndElement("MulticastIPAddress");
            }
            MulticastIPAddress = list.ToArray();
            List <GXDLMSIp4SetupIpOption> ipOptions = new List <GXDLMSIp4SetupIpOption>();

            if (reader.IsStartElement("IPOptions", true))
            {
                while (reader.IsStartElement("IPOption", true))
                {
                    GXDLMSIp4SetupIpOption it = new GXDLMSIp4SetupIpOption();
                    it.Type   = (Ip4SetupIpOptionType)reader.ReadElementContentAsInt("Type");
                    it.Length = (byte)reader.ReadElementContentAsInt("Length");
                    it.Data   = GXDLMSTranslator.HexToBytes(reader.ReadElementContentAsString("Data"));
                    ipOptions.Add(it);
                }
                //OLD. This can remove in the future.
                while (reader.IsStartElement("IPOptions", true))
                {
                    GXDLMSIp4SetupIpOption it = new GXDLMSIp4SetupIpOption();
                    it.Type   = (Ip4SetupIpOptionType)reader.ReadElementContentAsInt("Type");
                    it.Length = (byte)reader.ReadElementContentAsInt("Length");
                    it.Data   = GXDLMSTranslator.HexToBytes(reader.ReadElementContentAsString("Data"));
                    ipOptions.Add(it);
                }
                reader.ReadEndElement("IPOptions");
            }
            IPOptions           = ipOptions.ToArray();
            SubnetMask          = GetIpaddress(reader.ReadElementContentAsString("SubnetMask"));
            GatewayIPAddress    = GetIpaddress(reader.ReadElementContentAsString("GatewayIPAddress"));
            UseDHCP             = reader.ReadElementContentAsInt("UseDHCP") != 0;
            PrimaryDNSAddress   = GetIpaddress(reader.ReadElementContentAsString("PrimaryDNSAddress"));
            SecondaryDNSAddress = GetIpaddress(reader.ReadElementContentAsString("SecondaryDNSAddress"));
        }
Ejemplo n.º 3
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, 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)
     {
         if (value is string)
         {
             this.DataLinkLayerReference = value.ToString();
         }
         else
         {
             this.DataLinkLayerReference = GXDLMSClient.ChangeType((byte[])value, DataType.OctetString).ToString();
         }
     }
     else if (index == 3)
     {
         IPAddress = Convert.ToUInt32(value);
     }
     else if (index == 4)
     {
         List <uint> data = new List <uint>();
         if (value != null)
         {
             foreach (object it in (Object[])value)
             {
                 data.Add(Convert.ToUInt16(it));
             }
         }
         MulticastIPAddress = data.ToArray();
     }
     else if (index == 5)
     {
         List <GXDLMSIp4SetupIpOption> data = new List <GXDLMSIp4SetupIpOption>();
         if (value != null)
         {
             foreach (object[] it in (Object[])value)
             {
                 GXDLMSIp4SetupIpOption item = new GXDLMSIp4SetupIpOption();
                 item.Type   = (Ip4SetupIpOptionType)Convert.ToInt32(it[0]);
                 item.Length = Convert.ToByte(it[1]);
                 item.Data   = (byte[])it[2];
                 data.Add(item);
             }
         }
         IPOptions = data.ToArray();
     }
     else if (index == 6)
     {
         SubnetMask = Convert.ToUInt32(value);
     }
     else if (index == 7)
     {
         GatewayIPAddress = Convert.ToUInt32(value);
     }
     else if (index == 8)
     {
         UseDHCP = Convert.ToBoolean(value);
     }
     else if (index == 9)
     {
         PrimaryDNSAddress = Convert.ToUInt32(value);
     }
     else if (index == 10)
     {
         SecondaryDNSAddress = Convert.ToUInt32(value);
     }
     else
     {
         throw new ArgumentException("SetValue failed. Invalid attribute index.");
     }
 }
Ejemplo n.º 4
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         DataLinkLayerReference = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 3)
     {
         IPAddress = ToAddressString(e.Value);
     }
     else if (e.Index == 4)
     {
         List <string> data = new List <string>();
         if (e.Value is Object[])
         {
             if (e.Value is Object[])
             {
                 foreach (object it in (Object[])e.Value)
                 {
                     data.Add(ToAddressString(it));
                 }
             }
             else if (e.Value is UInt16[])
             {
                 //Some meters are returning wrong data here.
                 foreach (UInt16 it in (UInt16[])e.Value)
                 {
                     data.Add(ToAddressString(it));
                 }
             }
         }
         MulticastIPAddress = data.ToArray();
     }
     else if (e.Index == 5)
     {
         List <GXDLMSIp4SetupIpOption> data = new List <GXDLMSIp4SetupIpOption>();
         if (e.Value is Object[])
         {
             foreach (object[] it in (Object[])e.Value)
             {
                 GXDLMSIp4SetupIpOption item = new GXDLMSIp4SetupIpOption();
                 item.Type   = (Ip4SetupIpOptionType)Convert.ToInt32(it[0]);
                 item.Length = Convert.ToByte(it[1]);
                 item.Data   = (byte[])it[2];
                 data.Add(item);
             }
         }
         IPOptions = data.ToArray();
     }
     else if (e.Index == 6)
     {
         SubnetMask = ToAddressString(e.Value);
     }
     else if (e.Index == 7)
     {
         GatewayIPAddress = ToAddressString(e.Value);
     }
     else if (e.Index == 8)
     {
         UseDHCP = Convert.ToBoolean(e.Value);
     }
     else if (e.Index == 9)
     {
         PrimaryDNSAddress = ToAddressString(e.Value);
     }
     else if (e.Index == 10)
     {
         SecondaryDNSAddress = ToAddressString(e.Value);
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
Ejemplo n.º 5
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)
     {
         if (e.Value is string)
         {
             this.DataLinkLayerReference = e.Value.ToString();
         }
         else
         {
             this.DataLinkLayerReference = GXDLMSClient.ChangeType((byte[])e.Value, DataType.OctetString, settings.UseUtc2NormalTime).ToString();
         }
     }
     else if (e.Index == 3)
     {
         IPAddress = new System.Net.IPAddress(BitConverter.GetBytes(Convert.ToUInt32(e.Value))).ToString();
     }
     else if (e.Index == 4)
     {
         List <uint> data = new List <uint>();
         if (e.Value != null)
         {
             if (e.Value is Object[])
             {
                 foreach (object it in (Object[])e.Value)
                 {
                     data.Add(Convert.ToUInt16(it));
                 }
             }
             else if (e.Value is UInt16[])
             {
                 //Some meters are returning wrong data here.
                 foreach (UInt16 it in (UInt16[])e.Value)
                 {
                     data.Add(it);
                 }
             }
         }
         MulticastIPAddress = data.ToArray();
     }
     else if (e.Index == 5)
     {
         List <GXDLMSIp4SetupIpOption> data = new List <GXDLMSIp4SetupIpOption>();
         if (e.Value != null)
         {
             foreach (object[] it in (Object[])e.Value)
             {
                 GXDLMSIp4SetupIpOption item = new GXDLMSIp4SetupIpOption();
                 item.Type   = (Ip4SetupIpOptionType)Convert.ToInt32(it[0]);
                 item.Length = Convert.ToByte(it[1]);
                 item.Data   = (byte[])it[2];
                 data.Add(item);
             }
         }
         IPOptions = data.ToArray();
     }
     else if (e.Index == 6)
     {
         SubnetMask = Convert.ToUInt32(e.Value);
     }
     else if (e.Index == 7)
     {
         GatewayIPAddress = Convert.ToUInt32(e.Value);
     }
     else if (e.Index == 8)
     {
         UseDHCP = Convert.ToBoolean(e.Value);
     }
     else if (e.Index == 9)
     {
         PrimaryDNSAddress = Convert.ToUInt32(e.Value);
     }
     else if (e.Index == 10)
     {
         SecondaryDNSAddress = Convert.ToUInt32(e.Value);
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
Ejemplo n.º 6
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)
     {
         if (value is string)
         {
             this.DataLinkLayerReference = value.ToString();
         }
         else
         {
             this.DataLinkLayerReference = GXDLMSClient.ChangeType((byte[])value, DataType.OctetString).ToString();
         }
     }
     else if (index == 3)
     {
         IPAddress = Convert.ToUInt32(value);
     }
     else if (index == 4)
     {        
         List<uint> data = new List<uint>();
         if (value != null)
         {
             foreach (object it in (Object[])value)
             {
                 data.Add(Convert.ToUInt16(it));
             }
         }
         MulticastIPAddress = data.ToArray();
     }
     else if (index == 5)
     {
         List<GXDLMSIp4SetupIpOption> data = new List<GXDLMSIp4SetupIpOption>();
         if (value != null)
         {
             foreach (object[] it in (Object[])value)
             {
                 GXDLMSIp4SetupIpOption item = new GXDLMSIp4SetupIpOption();
                 item.Type = (GXDLMSIp4SetupIpOptionType)Convert.ToInt32(it[0]);
                 item.Length = Convert.ToByte(it[1]);
                 item.Data = (byte[]) it[2];
                 data.Add(item);
             }
         }
         IPOptions = data.ToArray();
     }
     else if (index == 6)
     {
         SubnetMask = Convert.ToUInt32(value);
     }
     else if (index == 7)
     {
         GatewayIPAddress = Convert.ToUInt32(value);
     }
     else if (index == 8)
     {
         UseDHCP = Convert.ToBoolean(value);
     }
     else if (index == 9)
     {
         PrimaryDNSAddress = Convert.ToUInt32(value);
     }
     else if (index == 10)
     {
         SecondaryDNSAddress = Convert.ToUInt32(value);
     }
     else
     {
         throw new ArgumentException("SetValue failed. Invalid attribute index.");
     }
 }
Ejemplo n.º 7
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).ToString();
         }
     }
     else if (e.Index == 2)
     {
         if (e.Value is string)
         {
             this.DataLinkLayerReference = e.Value.ToString();
         }
         else
         {
             this.DataLinkLayerReference = GXDLMSClient.ChangeType((byte[])e.Value, DataType.OctetString).ToString();
         }
     }
     else if (e.Index == 3)
     {
         IPAddress = new System.Net.IPAddress(BitConverter.GetBytes(Convert.ToUInt32(e.Value))).ToString();
     }
     else if (e.Index == 4)
     {
         List<uint> data = new List<uint>();
         if (e.Value != null)
         {
             if (e.Value is Object[])
             {
                 foreach (object it in (Object[])e.Value)
                 {
                     data.Add(Convert.ToUInt16(it));
                 }
             }
             else if (e.Value is UInt16[])
             {
                 //Some meters are returning wrong data here.
                 foreach (UInt16 it in (UInt16[])e.Value)
                 {
                     data.Add(it);
                 }
             }
         }
         MulticastIPAddress = data.ToArray();
     }
     else if (e.Index == 5)
     {
         List<GXDLMSIp4SetupIpOption> data = new List<GXDLMSIp4SetupIpOption>();
         if (e.Value != null)
         {
             foreach (object[] it in (Object[])e.Value)
             {
                 GXDLMSIp4SetupIpOption item = new GXDLMSIp4SetupIpOption();
                 item.Type = (Ip4SetupIpOptionType)Convert.ToInt32(it[0]);
                 item.Length = Convert.ToByte(it[1]);
                 item.Data = (byte[])it[2];
                 data.Add(item);
             }
         }
         IPOptions = data.ToArray();
     }
     else if (e.Index == 6)
     {
         SubnetMask = Convert.ToUInt32(e.Value);
     }
     else if (e.Index == 7)
     {
         GatewayIPAddress = Convert.ToUInt32(e.Value);
     }
     else if (e.Index == 8)
     {
         UseDHCP = Convert.ToBoolean(e.Value);
     }
     else if (e.Index == 9)
     {
         PrimaryDNSAddress = Convert.ToUInt32(e.Value);
     }
     else if (e.Index == 10)
     {
         SecondaryDNSAddress = Convert.ToUInt32(e.Value);
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }