Esempio n. 1
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);
            }
        }