private void ServerAddressTypeCB_DrawItem(object sender, DrawItemEventArgs e)
        {
            // If the index is invalid then simply exit.
            if (e.Index == -1 || e.Index >= ServerAddressTypeCB.Items.Count)
            {
                return;
            }

            // Draw the background of the item.
            e.DrawBackground();

            // Should we draw the focus rectangle?
            if ((e.State & DrawItemState.Focus) != 0)
            {
                e.DrawFocusRectangle();
            }

            Font f = new Font(e.Font, FontStyle.Regular);
            // Create a new background brush.
            Brush b = new SolidBrush(e.ForeColor);
            // Draw the item.
            GXServerAddress item = (GXServerAddress)ServerAddressTypeCB.Items[e.Index];

            if (item == null)
            {
                return;
            }
            string name = item.HDLCAddress.ToString();
            SizeF  s    = e.Graphics.MeasureString(name, f);

            e.Graphics.DrawString(name, f, b, e.Bounds);
        }
Ejemplo n.º 2
0
 void UpdateServer(GXServerAddress server)
 {
     server.Formula         = SerialNumberFormulaTB.Text;
     server.PhysicalAddress = Convert.ToInt32(PhysicalServerAddTB.Value);
     server.LogicalAddress  = Convert.ToInt32(LogicalServerAddTB.Value);
     server.Size            = Convert.ToInt32(SizeCb.Text);
 }
Ejemplo n.º 3
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));
            }
            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);
            }
        }
Ejemplo n.º 4
0
 void RefreshServer(GXServerAddress server)
 {
     SerialNumberFormulaTB.Text      = server.Formula;
     PhysicalServerAddTB.Value       = Convert.ToDecimal(server.PhysicalAddress);
     LogicalServerAddTB.Value        = server.LogicalAddress;
     PhysicalServerAddTB.Hexadecimal = SerialNumberFormulaTB.ReadOnly = server.HDLCAddress != HDLCAddressType.SerialNumber;
 }
Ejemplo n.º 5
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);
            }
        }
 void RefreshServer(GXServerAddress server)
 {
     SerialNumberFormulaTB.Text = server.Formula;
     if (server.PhysicalAddress != null)
     {
         ServerAddTypeCB.SelectedItem = server.PhysicalAddress.GetType();
     }
     PhysicalServerAddTB.Value       = Convert.ToDecimal(server.PhysicalAddress);
     LogicalServerAddTB.Value        = server.LogicalAddress;
     PhysicalServerAddTB.Hexadecimal = SerialNumberFormulaTB.ReadOnly = server.HDLCAddress != HDLCAddressType.SerialNumber;
 }
Ejemplo n.º 7
0
 void RefreshServer(GXServerAddress server)
 {
     SerialNumberFormulaTB.Text      = server.Formula;
     PhysicalServerAddTB.Value       = Convert.ToDecimal(server.PhysicalAddress);
     LogicalServerAddTB.Value        = server.LogicalAddress;
     PhysicalServerAddTB.Hexadecimal = SerialNumberFormulaTB.ReadOnly = server.HDLCAddress != HDLCAddressType.SerialNumber;
     SizeCb.Items.Add(0);
     SizeCb.Items.Add(1);
     SizeCb.Items.Add(2);
     SizeCb.Items.Add(4);
     SizeCb.SelectedItem = server.Size;
 }
        private void ServerAddressTypeCB_SelectedIndexChanged(object sender, EventArgs e)
        {
            GXServerAddress server = (GXServerAddress)ServerAddressTypeCB.SelectedItem;

            PhysicalServerAddressTB.Hexadecimal = server.HDLCAddress != HDLCAddressType.SerialNumber;
            this.PhysicalServerAddressTB.Value  = Convert.ToDecimal(server.PhysicalAddress);
            this.LogicalServerAddressTB.Value   = server.LogicalAddress;
            if (!PhysicalServerAddressTB.Hexadecimal)
            {
                PhysicalServerAddressLbl.Text = "Serial Number:";
            }
            else
            {
                PhysicalServerAddressLbl.Text = "Physical Server:";
            }
        }
        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);
            }
        }
        private void ServerAddressTypeCB_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                GXServerAddress server = Manufacturer.GetActiveServer();
                server.Selected = false;
                //Save old values.
                UpdateServer(server);

                server          = ((GXServerAddress)ServerAddressTypeCB.SelectedItem);
                server.Selected = true;
                RefreshServer(server);
            }
            catch (Exception Ex)
            {
                GXDLMS.Common.Error.ShowError(this, Ex);
            }
        }
Ejemplo n.º 11
0
        public ManufacturerForm(GXManufacturerCollection manufacturers, GXManufacturer manufacturer)
        {
            InitializeComponent();
            Manufacturers = manufacturers;
            Manufacturer  = manufacturer;
            if (manufacturer.Settings.Count == 0)
            {
                manufacturer.Settings.Add(new GXAuthentication(Authentication.None, (byte)0x10));
                manufacturer.Settings.Add(new GXAuthentication(Authentication.Low, (byte)0x11));
                manufacturer.Settings.Add(new GXAuthentication(Authentication.High, (byte)0x12));
                manufacturer.Settings.Add(new GXAuthentication(Authentication.HighMD5, (byte)0x13));
                manufacturer.Settings.Add(new GXAuthentication(Authentication.HighSHA1, (byte)0x14));
                GXAuthentication gmac = new GXAuthentication(Authentication.HighGMAC, (byte)0x15);
            }
            GXAuthentication authentication = manufacturer.GetActiveAuthentication();

            foreach (GXAuthentication it in manufacturer.Settings)
            {
                AuthenticationCB.Items.Add(it);
            }
            AuthenticationCB.SelectedItem = authentication;
            AdvancedBtn.Enabled           = authentication.Type == Authentication.HighGMAC;
            this.AuthenticationCB.SelectedIndexChanged += new System.EventHandler(this.AuthenticationCB_SelectedIndexChanged);
            if (manufacturer.ServerSettings.Count == 0)
            {
                manufacturer.ServerSettings.Add(new GXServerAddress(HDLCAddressType.Default, (byte)1, true));
                manufacturer.ServerSettings.Add(new GXServerAddress(HDLCAddressType.SerialNumber, (byte)1, false));
                manufacturer.ServerSettings.Add(new GXServerAddress(HDLCAddressType.Custom, (byte)1, false));
            }
            foreach (GXServerAddress it in manufacturer.ServerSettings)
            {
                ServerAddressTypeCB.Items.Add(it);
            }

            GXServerAddress server = manufacturer.GetActiveServer();

            ServerAddressTypeCB.SelectedItem = server;
            RefreshServer(server);
            this.ServerAddressTypeCB.SelectedIndexChanged += new System.EventHandler(this.ServerAddressTypeCB_SelectedIndexChanged);

            ServerAddressTypeCB.DrawMode = AuthenticationCB.DrawMode = DrawMode.OwnerDrawFixed;
            ClientAddTB.Value            = authentication.ClientAddress;

            InactivityModeCB.Items.Add(InactivityMode.None);
            InactivityModeCB.Items.Add(InactivityMode.KeepAlive);
            InactivityModeCB.Items.Add(InactivityMode.Reopen);
            InactivityModeCB.Items.Add(InactivityMode.ReopenActive);
            InactivityModeCB.Items.Add(InactivityMode.Disconnect);
            StartProtocolCB.Items.Add(StartProtocolType.IEC);
            StartProtocolCB.Items.Add(StartProtocolType.DLMS);
            NameTB.Text                   = manufacturer.Name;
            ManufacturerIdTB.Text         = manufacturer.Identification;
            ForceKeepAliveCB.Checked      = manufacturer.ForceInactivity;
            UseLNCB.Checked               = manufacturer.UseLogicalNameReferencing;
            UseIEC47CB.Checked            = manufacturer.UseIEC47;
            StartProtocolCB.SelectedItem  = manufacturer.StartProtocol;
            InactivityModeCB.SelectedItem = Manufacturer.InactivityMode;
            //Manufacturer ID can not change after creation.
            ManufacturerIdTB.Enabled  = string.IsNullOrEmpty(manufacturer.Identification);
            KeepAliveIntervalTB.Value = Manufacturer.KeepAliveInterval / 1000;
            AdvancedBtn.Enabled       = SecuredConnectionCB.Checked = manufacturer.SystemTitle != null;
            WebAddressTB.Text         = Manufacturer.WebAddress;
            if (!string.IsNullOrEmpty(Manufacturer.Info))
            {
                try
                {
                    InfoTB.Text = ASCIIEncoding.UTF8.GetString(Convert.FromBase64String(Manufacturer.Info));
                }
                catch (Exception)
                {
                    InfoTB.Text = "";
                }
            }
        }
        public ManufacturerForm(GXManufacturerCollection manufacturers, GXManufacturer manufacturer)
        {
            InitializeComponent();
            Manufacturers = manufacturers;
            Manufacturer  = manufacturer;
            if (manufacturer.Settings.Count == 0)
            {
                manufacturer.Settings.Add(new GXAuthentication(Gurux.DLMS.Authentication.None, (byte)0x10));
                manufacturer.Settings.Add(new GXAuthentication(Gurux.DLMS.Authentication.Low, (byte)0x11));
                manufacturer.Settings.Add(new GXAuthentication(Gurux.DLMS.Authentication.High, (byte)0x12));
                manufacturer.Settings.Add(new GXAuthentication(Gurux.DLMS.Authentication.HighMD5, (byte)0x13));
                manufacturer.Settings.Add(new GXAuthentication(Gurux.DLMS.Authentication.HighSHA1, (byte)0x14));
                GXAuthentication gmac = new GXAuthentication(Gurux.DLMS.Authentication.HighGMAC, (byte)0x15);
                gmac.BlockCipherKey    = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };
                gmac.AuthenticationKey = new byte[] { 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF };
                manufacturer.Settings.Add(gmac);
            }
            GXAuthentication authentication = manufacturer.GetActiveAuthentication();

            foreach (GXAuthentication it in manufacturer.Settings)
            {
                AuthenticationCB.Items.Add(it);
            }
            AuthenticationCB.SelectedItem = authentication;
            if (authentication.Type == Gurux.DLMS.Authentication.High ||
                authentication.Type == Gurux.DLMS.Authentication.HighSHA1 ||
                authentication.Type == Gurux.DLMS.Authentication.HighGMAC)
            {
                AdvancedBtn.Enabled = true;
            }
            this.AuthenticationCB.SelectedIndexChanged += new System.EventHandler(this.AuthenticationCB_SelectedIndexChanged);
            if (manufacturer.ServerSettings.Count == 0)
            {
                manufacturer.ServerSettings.Add(new GXServerAddress(HDLCAddressType.Default, (byte)1, true));
                manufacturer.ServerSettings.Add(new GXServerAddress(HDLCAddressType.SerialNumber, (byte)1, false));
                manufacturer.ServerSettings.Add(new GXServerAddress(HDLCAddressType.Custom, (byte)1, false));
            }
            foreach (GXServerAddress it in manufacturer.ServerSettings)
            {
                ServerAddressTypeCB.Items.Add(it);
            }

            ServerAddTypeCB.Items.Add(typeof(byte));
            ServerAddTypeCB.Items.Add(typeof(ushort));
            ServerAddTypeCB.Items.Add(typeof(uint));
            GXServerAddress server = manufacturer.GetActiveServer();

            ServerAddressTypeCB.SelectedItem = server;
            RefreshServer(server);
            this.ServerAddressTypeCB.SelectedIndexChanged += new System.EventHandler(this.ServerAddressTypeCB_SelectedIndexChanged);

            ServerAddressTypeCB.DrawMode = AuthenticationCB.DrawMode = ClientAddTypeCB.DrawMode = ServerAddTypeCB.DrawMode = DrawMode.OwnerDrawFixed;
            ClientAddTypeCB.Items.Add(typeof(byte));
            ClientAddTypeCB.Items.Add(typeof(ushort));
            ClientAddTypeCB.Items.Add(typeof(uint));
            if (authentication.ClientID != null)
            {
                ClientAddTB.Value            = Convert.ToDecimal(authentication.ClientID);
                ClientAddTypeCB.SelectedItem = authentication.ClientID.GetType();
            }
            RefreshAuthentication(authentication);

            InactivityModeCB.Items.Add(InactivityMode.None);
            InactivityModeCB.Items.Add(InactivityMode.KeepAlive);
            InactivityModeCB.Items.Add(InactivityMode.Reopen);
            InactivityModeCB.Items.Add(InactivityMode.ReopenActive);
            InactivityModeCB.Items.Add(InactivityMode.Disconnect);
            StartProtocolCB.Items.Add(StartProtocolType.IEC);
            StartProtocolCB.Items.Add(StartProtocolType.DLMS);
            NameTB.Text                   = manufacturer.Name;
            ManufacturerIdTB.Text         = manufacturer.Identification;
            ForceKeepAliveCB.Checked      = manufacturer.ForceInactivity;
            UseLNCB.Checked               = manufacturer.UseLogicalNameReferencing;
            UseIEC47CB.Checked            = manufacturer.UseIEC47;
            StartProtocolCB.SelectedItem  = manufacturer.StartProtocol;
            InactivityModeCB.SelectedItem = Manufacturer.InactivityMode;
            //Manufacturer ID can not change after creation.
            ManufacturerIdTB.Enabled  = string.IsNullOrEmpty(manufacturer.Identification);
            KeepAliveIntervalTB.Value = Manufacturer.KeepAliveInterval / 1000;
        }
 void UpdateServer(GXServerAddress server)
 {
     server.Formula         = SerialNumberFormulaTB.Text;
     server.PhysicalAddress = Convert.ChangeType(PhysicalServerAddTB.Value, (Type)ServerAddTypeCB.SelectedItem);
     server.LogicalAddress  = Convert.ToInt32(LogicalServerAddTB.Value);
 }
Ejemplo n.º 14
0
 private void OKBtn_Click(object sender, EventArgs e)
 {
     try
     {
         //Check security settings.
         if ((Security)SecurityCB.SelectedItem != Security.None ||
             ((GXAuthentication)AuthenticationCB.SelectedItem).Type == Authentication.HighGMAC)
         {
             if (SystemTitleTB.Text.Trim().Length == 0)
             {
                 throw new ArgumentException("Invalid system title.");
             }
             if (AuthenticationKeyTB.Text.Trim().Length == 0)
             {
                 throw new ArgumentException("Invalid authentication key.");
             }
             if (BlockCipherKeyTB.Text.Trim().Length == 0)
             {
                 throw new ArgumentException("Invalid block cipher key.");
             }
         }
         GXServerAddress server = (GXServerAddress)ServerAddressTypeCB.SelectedItem;
         if (server.HDLCAddress == HDLCAddressType.SerialNumber && PhysicalServerAddressTB.Value == 0)
         {
             throw new Exception("Invalid Serial Number.");
         }
         GXManufacturer man = (GXManufacturer)ManufacturerCB.SelectedItem;
         Target.client.Authentication = ((GXAuthentication)this.AuthenticationCB.SelectedItem).Type;
         if (Target.client.Authentication != Authentication.None)
         {
             if (PasswordAsciiCb.Checked)
             {
                 Target.client.Password = ASCIIEncoding.ASCII.GetBytes(PasswordTB.Text);
             }
             else
             {
                 Target.client.Password = GXDLMSTranslator.HexToBytes(this.PasswordTB.Text);
             }
         }
         else
         {
             Target.client.Password = null;
         }
         Target.media = SelectedMedia;
         if (SelectedMedia is GXSerial)
         {
             if (this.SerialPortCB.Text.Length == 0)
             {
                 throw new Exception("Invalid serial port.");
             }
             ((GXSerial)SelectedMedia).PortName = this.SerialPortCB.Text;
         }
         else if (SelectedMedia is GXNet)
         {
             if (this.HostNameTB.Text.Length == 0)
             {
                 throw new Exception("Invalid host name.");
             }
             ((GXNet)SelectedMedia).HostName = this.HostNameTB.Text;
             int port;
             if (!Int32.TryParse(this.PortTB.Text, out port))
             {
                 throw new Exception("Invalid port number.");
             }
             ((GXNet)SelectedMedia).Port     = port;
             ((GXNet)SelectedMedia).Protocol = (NetworkType)NetProtocolCB.SelectedItem;
         }
         Properties.Settings.Default.Media                = SelectedMedia.MediaType;
         Properties.Settings.Default.MediaSettings        = SelectedMedia.Settings;
         Properties.Settings.Default.SelectedManufacturer = man.Identification;
         Properties.Settings.Default.WaitTime             = Convert.ToInt32(WaitTimeTB.Value);
         Target.WaitTime = Properties.Settings.Default.WaitTime * 1000;
         GXAuthentication authentication = (GXAuthentication)AuthenticationCB.SelectedItem;
         HDLCAddressType  HDLCAddressing = ((GXServerAddress)ServerAddressTypeCB.SelectedItem).HDLCAddress;
         Properties.Settings.Default.HDLCAddressing = (int)HDLCAddressing;
         Properties.Settings.Default.ClientAddress  = Target.client.ClientAddress = Convert.ToInt32(ClientAddTB.Value);
         if (HDLCAddressing == HDLCAddressType.SerialNumber)
         {
             int address = Convert.ToInt32(PhysicalServerAddressTB.Value);
             Properties.Settings.Default.PhysicalServerAddress = address;
             Target.client.ServerAddress = GXDLMSClient.GetServerAddress(address);
         }
         else if (HDLCAddressing == HDLCAddressType.Default)
         {
             Properties.Settings.Default.PhysicalServerAddress = Convert.ToInt32(PhysicalServerAddressTB.Value);
             Properties.Settings.Default.LogicalServerAddress  = Convert.ToInt32(LogicalServerAddressTB.Value);
             Target.client.ServerAddress = GXDLMSClient.GetServerAddress(Properties.Settings.Default.LogicalServerAddress,
                                                                         Properties.Settings.Default.PhysicalServerAddress);
         }
         Target.client.UseLogicalNameReferencing = this.UseLNCB.Checked;
         Target.iec = (StartProtocolType)this.StartProtocolCB.SelectedItem == StartProtocolType.IEC;
         Target.client.Ciphering.Security          = (Security)SecurityCB.SelectedItem;
         Target.client.Ciphering.SystemTitle       = GetAsHex(SystemTitleTB.Text, SystemTitleAsciiCb.Checked);
         Target.client.Ciphering.BlockCipherKey    = GetAsHex(BlockCipherKeyTB.Text, BlockCipherKeyAsciiCb.Checked);
         Target.client.Ciphering.AuthenticationKey = GetAsHex(AuthenticationKeyTB.Text, AuthenticationKeyAsciiCb.Checked);
         Target.client.Ciphering.InvocationCounter = UInt32.Parse(InvocationCounterTB.Text);
         Target.client.CtoSChallenge = GXCommon.HexToBytes(ChallengeTB.Text);
         if (man.UseIEC47)
         {
             Target.client.InterfaceType = InterfaceType.WRAPPER;
         }
         UpdateConformance();
         Properties.Settings.Default.Save();
     }
     catch (Exception Ex)
     {
         this.DialogResult = DialogResult.None;
         MessageBox.Show(this, Ex.Message, Properties.Resources.CTT, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Ejemplo n.º 15
0
        public ManufacturerForm(GXManufacturerCollection manufacturers, GXManufacturer manufacturer)
        {
            InitializeComponent();
#if !GURUX_LPWAN
            LpWanCb.Visible = WiSunCb.Visible = false;
#endif //GURUX_LPWAN
            foreach (object it in Enum.GetValues(typeof(Standard)))
            {
                StandardCb.Items.Add(it);
            }
            StandardCb.SelectedItem = manufacturer.Standard;

            SecurityCB.Items.AddRange(new object[] { Security.None, Security.Authentication,
                                                     Security.Encryption, Security.AuthenticationEncryption });
            Manufacturers = manufacturers;
            Manufacturer  = manufacturer;
            if (manufacturer.Settings.Count == 0)
            {
                manufacturer.Settings.Add(new GXAuthentication(Authentication.None, (byte)0x10));
                manufacturer.Settings.Add(new GXAuthentication(Authentication.Low, (byte)0x11));
                manufacturer.Settings.Add(new GXAuthentication(Authentication.High, (byte)0x12));
                manufacturer.Settings.Add(new GXAuthentication(Authentication.HighMD5, (byte)0x13));
                manufacturer.Settings.Add(new GXAuthentication(Authentication.HighSHA1, (byte)0x14));
                manufacturer.Settings.Add(new GXAuthentication(Authentication.HighGMAC, (byte)0x14));
                manufacturer.Settings.Add(new GXAuthentication(Authentication.HighSHA256, (byte)0x14));
                manufacturer.Settings.Add(new GXAuthentication(Authentication.HighECDSA, (byte)0x14));
                GXAuthentication gmac = new GXAuthentication(Authentication.HighGMAC, (byte)0x15);
            }
            GXAuthentication authentication = manufacturer.GetActiveAuthentication();
            foreach (GXAuthentication it in manufacturer.Settings)
            {
                AuthenticationCB.Items.Add(it);
            }
            AuthenticationCB.SelectedItem = authentication;
            this.AuthenticationCB.SelectedIndexChanged += new System.EventHandler(this.AuthenticationCB_SelectedIndexChanged);
            if (manufacturer.ServerSettings.Count == 0)
            {
                manufacturer.ServerSettings.Add(new GXServerAddress(HDLCAddressType.Default, (byte)1, true));
                manufacturer.ServerSettings.Add(new GXServerAddress(HDLCAddressType.SerialNumber, (byte)1, false));
                manufacturer.ServerSettings.Add(new GXServerAddress(HDLCAddressType.Custom, (byte)1, false));
            }
            foreach (GXServerAddress it in manufacturer.ServerSettings)
            {
                ServerAddressTypeCB.Items.Add(it);
            }

            GXServerAddress server = manufacturer.GetActiveServer();
            ServerAddressTypeCB.SelectedItem = server;
            RefreshServer(server);
            this.ServerAddressTypeCB.SelectedIndexChanged += new System.EventHandler(this.ServerAddressTypeCB_SelectedIndexChanged);

            ServerAddressTypeCB.DrawMode = AuthenticationCB.DrawMode = DrawMode.OwnerDrawFixed;
            ClientAddTB.Value            = authentication.ClientAddress;
            NameTB.Text           = manufacturer.Name;
            ManufacturerIdTB.Text = manufacturer.Identification;
            UseLNCB.Checked       = manufacturer.UseLogicalNameReferencing;
            //Manufacturer ID can not change after creation.
            ManufacturerIdTB.Enabled = string.IsNullOrEmpty(manufacturer.Identification);
            WebAddressTB.Text        = Manufacturer.WebAddress;
            if (!string.IsNullOrEmpty(Manufacturer.Info))
            {
                try
                {
                    InfoTB.Text = ASCIIEncoding.UTF8.GetString(Convert.FromBase64String(Manufacturer.Info));
                }
                catch (Exception)
                {
                    InfoTB.Text = "";
                }
            }
            SecurityCB.SelectedItem = manufacturer.Security;
            if (DevicePropertiesForm.IsAscii(manufacturer.SystemTitle))
            {
                SystemTitleAsciiCb.Checked = true;
                SystemTitleTB.Text         = ASCIIEncoding.ASCII.GetString((manufacturer.SystemTitle));
            }
            else
            {
                SystemTitleTB.Text = GXCommon.ToHex(manufacturer.SystemTitle, true);
            }
            if (DevicePropertiesForm.IsAscii(manufacturer.BlockCipherKey))
            {
                BlockCipherKeyAsciiCb.Checked = true;
                BlockCipherKeyTB.Text         = ASCIIEncoding.ASCII.GetString(manufacturer.BlockCipherKey);
            }
            else
            {
                BlockCipherKeyTB.Text = GXCommon.ToHex(manufacturer.BlockCipherKey, true);
            }
            if (DevicePropertiesForm.IsAscii(manufacturer.AuthenticationKey))
            {
                AuthenticationKeyAsciiCb.Checked = true;
                AuthenticationKeyTB.Text         = ASCIIEncoding.ASCII.GetString(manufacturer.AuthenticationKey);
            }
            else
            {
                AuthenticationKeyTB.Text = GXCommon.ToHex(manufacturer.AuthenticationKey, true);
            }
            UseUtcTimeZone.Checked = manufacturer.UtcTimeZone;
            if (manufacturer.SupporterdInterfaces != 0)
            {
                HdlcCb.Checked          = (manufacturer.SupporterdInterfaces & (1 << (int)InterfaceType.HDLC)) != 0;
                HdlcWithModeECb.Checked = (manufacturer.SupporterdInterfaces & (1 << (int)InterfaceType.HdlcWithModeE)) != 0;
                WrapperCb.Checked       = (manufacturer.SupporterdInterfaces & (1 << (int)InterfaceType.WRAPPER)) != 0;
                WirelessMBusCb.Checked  = (manufacturer.SupporterdInterfaces & (1 << (int)InterfaceType.WirelessMBus)) != 0;
                PlcCb.Checked           = (manufacturer.SupporterdInterfaces & (1 << (int)InterfaceType.Plc)) != 0;
                PlcHdlcCb.Checked       = (manufacturer.SupporterdInterfaces & (1 << (int)InterfaceType.PlcHdlc)) != 0;
                LpWanCb.Checked         = (manufacturer.SupporterdInterfaces & (1 << (int)InterfaceType.LPWAN)) != 0;
                WiSunCb.Checked         = (manufacturer.SupporterdInterfaces & (1 << (int)InterfaceType.WiSUN)) != 0;
            }
            else
            {
                //Select default interfaces.
                HdlcCb.Checked = HdlcWithModeECb.Checked = WrapperCb.Checked = true;
            }
        }
Ejemplo n.º 16
0
        public ManufacturerForm(GXManufacturerCollection manufacturers, GXManufacturer manufacturer)
        {
            InitializeComponent();
            foreach (object it in Enum.GetValues(typeof(Standard)))
            {
                StandardCb.Items.Add(it);
            }
            StandardCb.SelectedItem = manufacturer.Standard;

            SecurityCB.Items.AddRange(new object[] { Security.None, Security.Authentication,
                                                     Security.Encryption, Security.AuthenticationEncryption });
            Manufacturers = manufacturers;
            Manufacturer  = manufacturer;
            if (manufacturer.Settings.Count == 0)
            {
                manufacturer.Settings.Add(new GXAuthentication(Authentication.None, (byte)0x10));
                manufacturer.Settings.Add(new GXAuthentication(Authentication.Low, (byte)0x11));
                manufacturer.Settings.Add(new GXAuthentication(Authentication.High, (byte)0x12));
                manufacturer.Settings.Add(new GXAuthentication(Authentication.HighMD5, (byte)0x13));
                manufacturer.Settings.Add(new GXAuthentication(Authentication.HighSHA1, (byte)0x14));
                manufacturer.Settings.Add(new GXAuthentication(Authentication.HighGMAC, (byte)0x14));
                manufacturer.Settings.Add(new GXAuthentication(Authentication.HighSHA256, (byte)0x14));
                manufacturer.Settings.Add(new GXAuthentication(Authentication.HighECDSA, (byte)0x14));
                GXAuthentication gmac = new GXAuthentication(Authentication.HighGMAC, (byte)0x15);
            }
            GXAuthentication authentication = manufacturer.GetActiveAuthentication();

            foreach (GXAuthentication it in manufacturer.Settings)
            {
                AuthenticationCB.Items.Add(it);
            }
            AuthenticationCB.SelectedItem = authentication;
            this.AuthenticationCB.SelectedIndexChanged += new System.EventHandler(this.AuthenticationCB_SelectedIndexChanged);
            if (manufacturer.ServerSettings.Count == 0)
            {
                manufacturer.ServerSettings.Add(new GXServerAddress(HDLCAddressType.Default, (byte)1, true));
                manufacturer.ServerSettings.Add(new GXServerAddress(HDLCAddressType.SerialNumber, (byte)1, false));
                manufacturer.ServerSettings.Add(new GXServerAddress(HDLCAddressType.Custom, (byte)1, false));
            }
            foreach (GXServerAddress it in manufacturer.ServerSettings)
            {
                ServerAddressTypeCB.Items.Add(it);
            }

            GXServerAddress server = manufacturer.GetActiveServer();

            ServerAddressTypeCB.SelectedItem = server;
            RefreshServer(server);
            this.ServerAddressTypeCB.SelectedIndexChanged += new System.EventHandler(this.ServerAddressTypeCB_SelectedIndexChanged);

            ServerAddressTypeCB.DrawMode = AuthenticationCB.DrawMode = DrawMode.OwnerDrawFixed;
            ClientAddTB.Value            = authentication.ClientAddress;

            StartProtocolCB.Items.Add(StartProtocolType.IEC);
            StartProtocolCB.Items.Add(StartProtocolType.DLMS);
            NameTB.Text                  = manufacturer.Name;
            ManufacturerIdTB.Text        = manufacturer.Identification;
            UseLNCB.Checked              = manufacturer.UseLogicalNameReferencing;
            UseIEC47CB.Checked           = manufacturer.UseIEC47;
            StartProtocolCB.SelectedItem = manufacturer.StartProtocol;
            //Manufacturer ID can not change after creation.
            ManufacturerIdTB.Enabled = string.IsNullOrEmpty(manufacturer.Identification);
            WebAddressTB.Text        = Manufacturer.WebAddress;
            if (!string.IsNullOrEmpty(Manufacturer.Info))
            {
                try
                {
                    InfoTB.Text = ASCIIEncoding.UTF8.GetString(Convert.FromBase64String(Manufacturer.Info));
                }
                catch (Exception)
                {
                    InfoTB.Text = "";
                }
            }
            SecurityCB.SelectedItem = manufacturer.Security;
            if (DevicePropertiesForm.IsAscii(manufacturer.SystemTitle))
            {
                SystemTitleAsciiCb.Checked = true;
                SystemTitleTB.Text         = ASCIIEncoding.ASCII.GetString((manufacturer.SystemTitle));
            }
            else
            {
                SystemTitleTB.Text = GXCommon.ToHex(manufacturer.SystemTitle, true);
            }
            if (DevicePropertiesForm.IsAscii(manufacturer.BlockCipherKey))
            {
                BlockCipherKeyAsciiCb.Checked = true;
                BlockCipherKeyTB.Text         = ASCIIEncoding.ASCII.GetString(manufacturer.BlockCipherKey);
            }
            else
            {
                BlockCipherKeyTB.Text = GXCommon.ToHex(manufacturer.BlockCipherKey, true);
            }
            if (DevicePropertiesForm.IsAscii(manufacturer.AuthenticationKey))
            {
                AuthenticationKeyAsciiCb.Checked = true;
                AuthenticationKeyTB.Text         = ASCIIEncoding.ASCII.GetString(manufacturer.AuthenticationKey);
            }
            else
            {
                AuthenticationKeyTB.Text = GXCommon.ToHex(manufacturer.AuthenticationKey, true);
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Apply new settings from property pages.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OKBtn_Click(object sender, EventArgs e)
        {
            try
            {
                string name = NameTB.Text.Trim();
                if (name.Length == 0)
                {
                    throw new Exception("Invalid name.");
                }
                GXServerAddress server = (GXServerAddress)ServerAddressTypeCB.SelectedItem;
                if (server.HDLCAddress == HDLCAddressType.SerialNumber && PhysicalServerAddressTB.Value == 0)
                {
                    throw new Exception("Invalid Serial Number.");
                }
                GXManufacturer man = (GXManufacturer)ManufacturerCB.SelectedItem;
                Device.Authentication = ((GXAuthentication)this.AuthenticationCB.SelectedItem).Type;
                if (Device.Authentication != Authentication.None)
                {
                    Device.Password = CryptHelper.Encrypt(this.PasswordTB.Text, Password.Key);
                }
                else
                {
                    Device.Password = "";
                }
                Device.Name            = name;
                Device.Media           = SelectedMedia;
                Device.Manufacturer    = man.Identification;
                Device.WaitTime        = Convert.ToInt32(WaitTimeTB.Value);
                Device.Verbose         = VerboseModeCB.Checked;
                Device.MaximumBaudRate = 0;
                Device.UtcTimeZone     = UseUtcTimeZone.Checked;

                if (SelectedMedia is GXSerial)
                {
                    Device.UseRemoteSerial = false;

                    if (this.SerialPortCB.Text.Length == 0)
                    {
                        throw new Exception("Invalid serial port.");
                    }
                    ((GXSerial)SelectedMedia).PortName = this.SerialPortCB.Text;
                    if (UseMaximumBaudRateCB.Checked)
                    {
                        Device.MaximumBaudRate = (int)MaximumBaudRateCB.SelectedItem;
                    }
                }
                else if (SelectedMedia is GXNet)
                {
                    if (this.HostNameTB.Text.Length == 0)
                    {
                        throw new Exception("Invalid host name.");
                    }
                    ((GXNet)SelectedMedia).HostName = this.HostNameTB.Text;
                    int port;
                    if (!Int32.TryParse(this.PortTB.Text, out port))
                    {
                        throw new Exception("Invalid port number.");
                    }
                    ((GXNet)SelectedMedia).Port     = port;
                    Device.UseRemoteSerial          = UseRemoteSerialCB.Checked;
                    ((GXNet)SelectedMedia).Protocol = (NetworkType)NetProtocolCB.SelectedItem;
                }
                else if (SelectedMedia is Gurux.Terminal.GXTerminal)
                {
                    if (this.TerminalPortCB.Text.Length == 0)
                    {
                        throw new Exception("Invalid serial port.");
                    }
                    if (this.TerminalPhoneNumberTB.Text.Length == 0)
                    {
                        throw new Exception("Invalid phone number.");
                    }
                    Gurux.Terminal.GXTerminal terminal = SelectedMedia as Gurux.Terminal.GXTerminal;
                    terminal.ConfigurableSettings = Gurux.Terminal.AvailableMediaSettings.All & ~Gurux.Terminal.AvailableMediaSettings.Server;
                    Device.UseRemoteSerial        = false;
                    terminal.PortName             = this.TerminalPortCB.Text;
                    terminal.PhoneNumber          = this.TerminalPhoneNumberTB.Text;
                }
                GXAuthentication authentication = (GXAuthentication)AuthenticationCB.SelectedItem;
                Device.HDLCAddressing = ((GXServerAddress)ServerAddressTypeCB.SelectedItem).HDLCAddress;
                Device.ClientAddress  = Convert.ToInt32(ClientAddTB.Value);
                if (Device.HDLCAddressing == HDLCAddressType.SerialNumber)
                {
                    Device.PhysicalAddress = PhysicalServerAddressTB.Value;
                }
                else
                {
                    Device.PhysicalAddress = Convert.ChangeType(PhysicalServerAddressTB.Value, server.PhysicalAddress.GetType());
                }
                Device.UseLogicalNameReferencing = this.UseLNCB.Checked;
                Device.LogicalAddress            = Convert.ToInt32(LogicalServerAddressTB.Value);
                Device.StartProtocol             = (StartProtocolType)this.StartProtocolCB.SelectedItem;
                GXDLMSDirector.Properties.Settings.Default.SelectedManufacturer = man.Name;

                Device.Security          = (Security)SecurityCB.SelectedItem;
                Device.SystemTitle       = SystemTitleTB.Text;
                Device.BlockCipherKey    = BlockCipherKeyTB.Text;
                Device.AuthenticationKey = AuthenticationKeyTB.Text;
            }
            catch (Exception Ex)
            {
                this.DialogResult = DialogResult.None;
                GXDLMS.Common.Error.ShowError(this, Ex);
            }
        }
Ejemplo n.º 18
0
        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;
            }
        }