public void UpdateManufactureSettings(string id)
        {
            if (Manufacturer != null && string.Compare(Manufacturer.Identification, id, true) != 0)
            {
                throw new Exception(string.Format("Manufacturer type does not match. Manufacturer is {0} and it should be {1}.", id, Manufacturer.Identification));
            }
            if (this.Media is GXNet && Manufacturer.UseIEC47)
            {
                Client.InterfaceType = InterfaceType.WRAPPER;
            }
            else
            {
                Client.InterfaceType = InterfaceType.HDLC;
            }
            Client.UseLogicalNameReferencing = Manufacturer.UseLogicalNameReferencing;
            //If network media is used check is manufacturer supporting IEC 62056-47
            GXServerAddress server = Manufacturer.GetServer(HDLCAddressing);

            Client.ClientAddress = Manufacturer.GetAuthentication(Client.Authentication).ClientAddress;
            if (HDLCAddressing == HDLCAddressType.SerialNumber)
            {
                Client.ServerAddress = GXDLMSClient.GetServerAddress(server.PhysicalAddress, server.Formula);
            }
            else
            {
                Client.ServerAddress = GXDLMSClient.GetServerAddress(server.LogicalAddress, server.PhysicalAddress);
            }
        }
Exemple #2
0
        public void UpdateManufactureSettings(string id)
        {
            if (Manufacturer != null && string.Compare(Manufacturer.Identification, id, true) != 0)
            {
                throw new Exception(string.Format("Manufacturer type does not match. Manufacturer is {0} and it should be {1}.", id, Manufacturer.Identification));
            }
            m_Parser.InterfaceType             = InterfaceType.General;
            m_Parser.UseLogicalNameReferencing = Manufacturer.UseLN;
            //If network media is used check is manufacturer supporting IEC 62056-47
            GXServerAddress server = Manufacturer.GetServer(HDLCAddressing);

            if (this.Media is GXNet && Manufacturer.UseIEC47)
            {
                m_Parser.InterfaceType = InterfaceType.Net;
                m_Parser.ClientID      = Convert.ToUInt16(Manufacturer.GetAuthentication(m_Parser.Authentication).ClientID);
                m_Parser.ServerID      = Convert.ToUInt16(server.PhysicalAddress);
            }
            else
            {
                if (HDLCAddressing == HDLCAddressType.Custom)
                {
                    m_Parser.ClientID = Manufacturer.GetAuthentication(m_Parser.Authentication).ClientID;
                }
                else
                {
                    m_Parser.ClientID = (byte)(Convert.ToByte(Manufacturer.GetAuthentication(m_Parser.Authentication).ClientID) << 1 | 0x1);
                }
                m_Parser.ServerID = GXManufacturer.CountServerAddress(HDLCAddressing, server.Formula, server.PhysicalAddress, server.LogicalAddress);
            }
        }
        public void UpdateManufactureSettings(string id)
        {
            if (!string.IsNullOrEmpty(this.Parent.Manufacturer) && string.Compare(this.Parent.Manufacturer, id, true) != 0)
            {
                throw new Exception(string.Format("Manufacturer type does not match. Manufacturer is {0} and it should be {1}.", id, this.Parent.Manufacturer));
            }
            GXManufacturer manufacturer = this.Parent.Manufacturers.FindByIdentification(id);

            if (manufacturer == null)
            {
                throw new Exception("Unknown manufacturer " + id);
            }
            this.Parent.Manufacturer = manufacturer.Identification;
            m_Cosem.Authentication   = this.Parent.Authentication;
            m_Cosem.InterfaceType    = InterfaceType.General;
            if (!string.IsNullOrEmpty(this.Parent.Password))
            {
                m_Cosem.Password = CryptHelper.Decrypt(this.Parent.Password, Password.Key);
            }
            m_Cosem.UseLogicalNameReferencing = this.Parent.UseLogicalNameReferencing;
            //If network media is used check is manufacturer supporting IEC 62056-47
            if (!Parent.UseRemoteSerial && this.Media is GXNet && manufacturer.UseIEC47)
            {
                m_Cosem.InterfaceType = InterfaceType.Net;
                m_Cosem.ClientID      = Convert.ToUInt16(Parent.ClientID);
                m_Cosem.ServerID      = Convert.ToUInt16((Parent.LogicalAddress << 9) | Convert.ToUInt16(Parent.PhysicalAddress));
            }
            else
            {
                if (Parent.HDLCAddressing == HDLCAddressType.Custom)
                {
                    m_Cosem.ClientID = Parent.ClientID;
                }
                else
                {
                    m_Cosem.ClientID = (byte)(Convert.ToByte(Parent.ClientID) << 1 | 0x1);
                }
                string          formula = null;
                GXServerAddress server  = manufacturer.GetServer(Parent.HDLCAddressing);
                if (server != null)
                {
                    formula = server.Formula;
                }
                m_Cosem.ServerID = GXManufacturer.CountServerAddress(Parent.HDLCAddressing, formula, Parent.PhysicalAddress, Parent.LogicalAddress);
            }
        }
        public void UpdateManufactureSettings(string id)
        {
            if (!string.IsNullOrEmpty(this.parent.Manufacturer) && string.Compare(this.parent.Manufacturer, id, true) != 0)
            {
                throw new Exception(string.Format("Manufacturer type does not match. Manufacturer is {0} and it should be {1}.", id, this.parent.Manufacturer));
            }
            GXManufacturer manufacturer = this.parent.Manufacturers.FindByIdentification(id);

            if (manufacturer == null)
            {
                throw new Exception("Unknown manufacturer " + id);
            }
            this.parent.Manufacturer = manufacturer.Identification;
            client.Authentication    = this.parent.Authentication;
            client.InterfaceType     = InterfaceType.HDLC;
            if (!string.IsNullOrEmpty(this.parent.Password))
            {
                client.Password = CryptHelper.Decrypt(this.parent.Password, Password.Key);
            }
            else if (this.parent.HexPassword != null)
            {
                client.Password = CryptHelper.Decrypt(this.parent.HexPassword, Password.Key);
            }
            client.UseLogicalNameReferencing = this.parent.UseLogicalNameReferencing;
            client.UtcTimeZone = parent.UtcTimeZone;
            //Show media verbose.
            if (this.parent.Verbose && media.Trace != System.Diagnostics.TraceLevel.Verbose)
            {
                media.Trace    = System.Diagnostics.TraceLevel.Verbose;
                media.OnTrace += new TraceEventHandler(Media_OnTrace);
            }
            else if (!this.parent.Verbose && media.Trace == System.Diagnostics.TraceLevel.Verbose)
            {
                media.Trace    = System.Diagnostics.TraceLevel.Off;
                media.OnTrace -= new TraceEventHandler(Media_OnTrace);
            }

            //If network media is used check is manufacturer supporting IEC 62056-47
            if (parent.UseWrapper && !parent.UseRemoteSerial && this.media is GXNet)
            {
                client.InterfaceType = InterfaceType.WRAPPER;
            }

            client.ClientAddress = parent.ClientAddress;
            if (parent.HDLCAddressing == HDLCAddressType.SerialNumber)
            {
                string          formula = null;
                GXServerAddress server  = manufacturer.GetServer(parent.HDLCAddressing);
                if (server != null)
                {
                    formula = server.Formula;
                }
                client.ServerAddress     = GXDLMSClient.GetServerAddress(Convert.ToInt32(parent.PhysicalAddress), formula);
                client.ServerAddressSize = 4;
            }
            else
            {
                if (client.InterfaceType == InterfaceType.WRAPPER)
                {
                    client.ServerAddress = Convert.ToInt32(parent.PhysicalAddress);
                }
                else
                {
                    client.ServerAddress = GXDLMSClient.GetServerAddress(parent.LogicalAddress, Convert.ToInt32(parent.PhysicalAddress));
                    GXServerAddress server = manufacturer.GetServer(parent.HDLCAddressing);
                    if (server != null)
                    {
                        client.ServerAddressSize = (byte)server.Size;
                    }
                }
            }
            client.Ciphering.Security = parent.Security;
            if (parent.SystemTitle != null && parent.BlockCipherKey != null && parent.AuthenticationKey != null)
            {
                client.Ciphering.SystemTitle       = GXCommon.HexToBytes(parent.SystemTitle);
                client.Ciphering.BlockCipherKey    = GXCommon.HexToBytes(parent.BlockCipherKey);
                client.Ciphering.AuthenticationKey = GXCommon.HexToBytes(parent.AuthenticationKey);
                client.Ciphering.InvocationCounter = parent.InvocationCounter;
            }
            else
            {
                client.Ciphering.SystemTitle       = null;
                client.Ciphering.BlockCipherKey    = null;
                client.Ciphering.AuthenticationKey = null;
                client.Ciphering.InvocationCounter = 0;
            }

            if (!string.IsNullOrEmpty(parent.Challenge))
            {
                client.CtoSChallenge = GXCommon.HexToBytes(parent.Challenge);
            }
            else
            {
                client.CtoSChallenge = null;
            }
        }