private void OKBtn_Click(object sender, EventArgs e) { try { if (NameTB.Text.Length == 0) { throw new Exception("Invalid manufacturer name."); } if (ManufacturerIdTB.Text.Length != 3) { throw new Exception("Invalid manufacturer identification."); } if (ManufacturerIdTB.Enabled && Manufacturers.FindByIdentification(ManufacturerIdTB.Text) != null) { throw new Exception("Manufacturer identification already exists."); } if (!SerialNumberFormulaTB.ReadOnly && SerialNumberFormulaTB.Text.Length == 0) { throw new Exception("Invalid Serial Number."); } Manufacturer.Name = NameTB.Text; Manufacturer.Identification = ManufacturerIdTB.Text; Manufacturer.UseLogicalNameReferencing = UseLNCB.Checked; Manufacturer.UseIEC47 = UseIEC47CB.Checked; Manufacturer.StartProtocol = (StartProtocolType)StartProtocolCB.SelectedItem; Manufacturer.Standard = (Standard)StandardCb.SelectedItem; GXAuthentication authentication = Manufacturer.GetActiveAuthentication(); authentication.ClientAddress = Convert.ToInt32(this.ClientAddTB.Value); //Save server values. UpdateServer((GXServerAddress)ServerAddressTypeCB.SelectedItem); Manufacturer.WebAddress = WebAddressTB.Text; if (!string.IsNullOrEmpty(InfoTB.Text)) { Manufacturer.Info = Convert.ToBase64String(ASCIIEncoding.UTF8.GetBytes(InfoTB.Text)); } else { Manufacturer.Info = null; } Manufacturer.Security = (Security)SecurityCB.SelectedItem; Manufacturer.SystemTitle = GXCommon.HexToBytes(DevicePropertiesForm.GetAsHex(SystemTitleTB.Text, SystemTitleAsciiCb.Checked)); Manufacturer.BlockCipherKey = GXCommon.HexToBytes(DevicePropertiesForm.GetAsHex(BlockCipherKeyTB.Text, BlockCipherKeyAsciiCb.Checked)); Manufacturer.AuthenticationKey = GXCommon.HexToBytes(DevicePropertiesForm.GetAsHex(AuthenticationKeyTB.Text, AuthenticationKeyAsciiCb.Checked)); } catch (Exception Ex) { GXDLMS.Common.Error.ShowError(this, Ex); this.DialogResult = DialogResult.None; } }
private void AddDeviceCMnu_Click(object sender, EventArgs e) { try { DevicePropertiesForm dlg = new DevicePropertiesForm(Manufacturers, new GXDLMSMeter()); if (dlg.ShowDialog(this) == DialogResult.OK) { target.AddDevices(new GXDLMSMeter[] { dlg.Device }); } } catch (Exception ex) { MessageBox.Show(this, ex.Message); } }
private void PropertiesCMnu_Click(object sender, EventArgs e) { try { if (Devices.SelectedNode != null) { GXDLMSMeter m = Devices.SelectedNode.Tag as GXDLMSMeter; DevicePropertiesForm dlg = new DevicePropertiesForm(Manufacturers, m); if (dlg.ShowDialog(this) == DialogResult.OK) { target.EditDevices(new GXDLMSMeter[] { dlg.Device }); } } } catch (Exception ex) { MessageBox.Show(this, ex.Message); } }
private void AddDeviceMnu_Click(object sender, EventArgs e) { try { DevicePropertiesForm dlg = new DevicePropertiesForm(this.Manufacturers, null); if (dlg.ShowDialog(this) == DialogResult.OK) { dlg.Device.Manufacturers = this.Manufacturers; dlg.Device.Comm.parentForm = this; AddDevice(dlg.Device, false); Devices.Add(dlg.Device); SetDirty(true); } } catch (Exception Ex) { GXDLMS.Common.Error.ShowError(this, Ex); } }
/// <summary> /// Show properties of the selected media. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PropertiesMnu_Click(object sender, EventArgs e) { try { GXDLMSDevice dev = GetSelectedDevice(); if (dev != null) { string man = dev.Manufacturer; DevicePropertiesForm dlg = new DevicePropertiesForm(this.Manufacturers, dev); if (dlg.ShowDialog(this) == DialogResult.OK) { //If user has change meter manufacturer. if (man != dev.Manufacturer) { while (dev.Objects.Count != 0) { RemoveObject(dev.Objects[0]); } SelectItem(dev); } ((TreeNode)ObjectTreeItems[dev]).Text = dev.Name; SetDirty(true); } } } catch (Exception Ex) { GXDLMS.Common.Error.ShowError(this, Ex); } }
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); } }
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; } }
private void OKBtn_Click(object sender, EventArgs e) { try { if (NameTB.Text.Length == 0) { throw new Exception("Invalid manufacturer name."); } if (ManufacturerIdTB.Text.Length != 3) { throw new Exception("Invalid manufacturer identification."); } if (ManufacturerIdTB.Enabled && Manufacturers.FindByIdentification(ManufacturerIdTB.Text) != null) { throw new Exception("Manufacturer identification already exists."); } if (!SerialNumberFormulaTB.ReadOnly && SerialNumberFormulaTB.Text.Length == 0) { throw new Exception("Invalid Serial Number."); } Manufacturer.Name = NameTB.Text; Manufacturer.Identification = ManufacturerIdTB.Text; Manufacturer.UseLogicalNameReferencing = UseLNCB.Checked; Manufacturer.Standard = (Standard)StandardCb.SelectedItem; Manufacturer.UtcTimeZone = UseUtcTimeZone.Checked; GXAuthentication authentication = Manufacturer.GetActiveAuthentication(); authentication.ClientAddress = Convert.ToInt32(this.ClientAddTB.Value); //Save server values. UpdateServer((GXServerAddress)ServerAddressTypeCB.SelectedItem); Manufacturer.WebAddress = WebAddressTB.Text; if (!string.IsNullOrEmpty(InfoTB.Text)) { Manufacturer.Info = Convert.ToBase64String(ASCIIEncoding.UTF8.GetBytes(InfoTB.Text)); } else { Manufacturer.Info = null; } Manufacturer.Security = (Security)SecurityCB.SelectedItem; Manufacturer.SystemTitle = GXCommon.HexToBytes(DevicePropertiesForm.GetAsHex(SystemTitleTB.Text, SystemTitleAsciiCb.Checked)); Manufacturer.BlockCipherKey = GXCommon.HexToBytes(DevicePropertiesForm.GetAsHex(BlockCipherKeyTB.Text, BlockCipherKeyAsciiCb.Checked)); Manufacturer.AuthenticationKey = GXCommon.HexToBytes(DevicePropertiesForm.GetAsHex(AuthenticationKeyTB.Text, AuthenticationKeyAsciiCb.Checked)); Manufacturer.SupporterdInterfaces = 0; if (HdlcCb.Checked) { Manufacturer.SupporterdInterfaces |= 1 << (int)InterfaceType.HDLC; } if (HdlcWithModeECb.Checked) { Manufacturer.SupporterdInterfaces |= 1 << (int)InterfaceType.HdlcWithModeE; } if (WrapperCb.Checked) { Manufacturer.SupporterdInterfaces |= 1 << (int)InterfaceType.WRAPPER; } if (WirelessMBusCb.Checked) { Manufacturer.SupporterdInterfaces |= 1 << (int)InterfaceType.WirelessMBus; } if (PlcCb.Checked) { Manufacturer.SupporterdInterfaces |= 1 << (int)InterfaceType.Plc; } if (PlcHdlcCb.Checked) { Manufacturer.SupporterdInterfaces |= 1 << (int)InterfaceType.PlcHdlc; } if (LpWanCb.Checked) { Manufacturer.SupporterdInterfaces |= 1 << (int)InterfaceType.LPWAN; } if (WiSunCb.Checked) { Manufacturer.SupporterdInterfaces |= 1 << (int)InterfaceType.WiSUN; } if (Manufacturer.SupporterdInterfaces == 0) { throw new Exception("Supporterd interfaces are not selected."); } } catch (Exception Ex) { GXDLMS.Common.Error.ShowError(this, Ex); this.DialogResult = DialogResult.None; } }