public AuthenticationGmacForm(GXManufacturer target) { InitializeComponent(); SecurityCB.Items.AddRange(new object[] { Security.None, Security.Authentication, Security.Encryption, Security.AuthenticationEncryption }); Target = target; this.Text = " Security connection settings"; this.SecurityCB.SelectedItem = target.Security; //Update default values. if (target.SystemTitle == null && target.BlockCipherKey == null && target.AuthenticationKey == null) { this.SystemTitleTB.Text = GXCommon.ToHex(ASCIIEncoding.ASCII.GetBytes("ABCDEFGH"), true); this.BlockCipherKeyTB.Text = "00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F"; this.AuthenticationKeyTB.Text = "D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF"; AsciiRB.Enabled = false; } else { this.SystemTitleTB.Text = GXCommon.ToHex(target.SystemTitle, true); this.BlockCipherKeyTB.Text = GXCommon.ToHex(target.BlockCipherKey, true); this.AuthenticationKeyTB.Text = GXCommon.ToHex(target.AuthenticationKey, true); } if (!IsPrintable(target.SystemTitle) || !IsPrintable(target.BlockCipherKey) || !IsPrintable(target.AuthenticationKey)) { AsciiRB.Enabled = false; } }
void AddColumn(GXDLMSClient cosem, GXManufacturer man, GXDLMSTable table, byte[] ln, object scalar, int index, string name) { string logicanName = null; if (ln != null) { logicanName = GXHelpers.ConvertFromDLMS(ln, DataType.OctetString, DataType.OctetString, false).ToString(); if (string.IsNullOrEmpty(name)) { GXObisCode code = man.ObisCodes.FindByLN(ObjectType.None, logicanName, null); if (code != null) { name = code.Description; } else { name = logicanName; } } } if (scalar == null) { GXDLMSProperty prop = new GXDLMSProperty(ObjectType.Data, logicanName, 0, name, index, DataType.DateTime); prop.ValueType = DataType.DateTime; prop.AccessMode = Gurux.Device.AccessMode.Read; table.Columns.Add(prop); } else { object[] tmp = (object[])scalar; Gurux.DLMS.AddIn.GXDLMSRegister prop = new Gurux.DLMS.AddIn.GXDLMSRegister(); prop.Scaler = Math.Pow(10, Convert.ToInt32(tmp[0])); prop.Unit = tmp[1].ToString(); prop.LogicalName = logicanName; prop.Name = name; prop.AttributeOrdinal = index; prop.DLMSType = DataType.UInt32; prop.ValueType = DataType.Float64; prop.AccessMode = Gurux.Device.AccessMode.Read; table.Columns.Add(prop); } }
public void UpdateColumns(GXDLMSProfileGeneric item, GXManufacturer man) { if (Comm.ParentForm.InvokeRequired) { Comm.ParentForm.Invoke(new UpdateColumnsEventHandler(UpdateColumns), item, man); return; } item.Buffer.Clear(); item.CaptureObjects.Clear(); List<GXKeyValuePair<GXDLMSObject, GXDLMSCaptureObject>> cols = null; List<DataColumn> columns = new List<DataColumn>(); if (this.Extension != null) { cols = this.Extension.Refresh(item, this.Comm); } if (cols == null) { cols = Comm.GetProfileGenericColumns(item.Name); } item.CaptureObjects = cols; }
/// <summary> /// Add new manufacturer. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void NewBtn_Click(object sender, EventArgs e) { try { GXManufacturer m = new GXManufacturer(); ManufacturerForm dlg = new ManufacturerForm(Manufacturers, m); if (dlg.ShowDialog(this) == DialogResult.OK) { Manufacturers.Add(m); AddManufacturer(m).Selected = true; } } catch (Exception Ex) { GXDLMS.Common.Error.ShowError(this, Ex); } }
ListViewItem AddManufacturer(GXManufacturer manufacturer) { ListViewItem it = ManufacturersList.Items.Add(manufacturer.Name); it.Tag = manufacturer; Items.Add(manufacturer, it); return it; }
public void InitializeConnection(GXManufacturer man) { Manufacturer = man; UpdateManufactureSettings(man.Identification); if (Media is GXSerial) { Console.WriteLine("Initializing serial connection."); InitSerial(); } else if (Media is GXNet) { //Console.WriteLine("Initializing Network connection."); InitNet(); //Some Electricity meters need some time before first message can be send. System.Threading.Thread.Sleep(500); } else { throw new Exception("Unknown media type."); } byte[] data, reply = null; data = Client.SNRMRequest(); if (data != null) { if (Trace) { Console.WriteLine("Send SNRM request." + BitConverter.ToString(data)); } reply = ReadDLMSPacket(data); if (Trace) { Console.WriteLine("Parsing UA reply." + BitConverter.ToString(reply)); } //Has server accepted client. Client.ParseUAResponse(reply); Console.WriteLine("Parsing UA reply succeeded."); } //Generate AARQ request. //Split requests to multible packets if needed. //If password is used all data might not fit to one packet. foreach (byte[] it in Client.AARQRequest(null)) { if (Trace) { Console.WriteLine("Send AARQ request", BitConverter.ToString(it)); } reply = ReadDLMSPacket(it); } if (Trace) { Console.WriteLine("Parsing AARE reply" + BitConverter.ToString(reply)); } //Parse reply. Client.ParseAAREResponse(reply); //Get challenge Is HSL authentication is used. if (Client.IsAuthenticationRequired) { foreach (byte[] it in Client.GetApplicationAssociationRequest()) { reply = ReadDLMSPacket(it); } Client.ParseApplicationAssociationResponse(reply); } //Console.WriteLine("Parsing AARE reply succeeded."); }
public void InitializeConnection(GXManufacturer man) { Manufacturer = man; UpdateManufactureSettings(man.Identification); if (Media is GXSerial) { Console.WriteLine("Initializing serial connection."); InitSerial(); } else if (Media is GXNet) { Console.WriteLine("Initializing Network connection."); InitNet(); //Some Electricity meters need some time before first message can be send. System.Threading.Thread.Sleep(500); } else { throw new Exception("Unknown media type."); } byte[] data, reply = null; data = m_Parser.SNRMRequest(); if (data != null) { if (Trace) { Console.WriteLine("Send SNRM request." + BitConverter.ToString(data)); } reply = ReadDLMSPacket(data); if (Trace) { Console.WriteLine("Parsing UA reply." + BitConverter.ToString(reply)); } //Has server accepted client. m_Parser.ParseUAResponse(reply); Console.WriteLine("Parsing UA reply succeeded."); } //Generate AARQ request. data = m_Parser.AARQRequest(null); if (Trace) { Console.WriteLine("Send AARQ request", BitConverter.ToString(data)); } //Split requests to multible packets if needed. //If password is used all data might not fit to one packet. Array arr = (Array)m_Parser.SplitDataToPackets(data); int len = arr.Length; int pos = 0; foreach (byte[] it in arr) { data = it; data = m_Parser.Read(data, ++pos, len, ObjectType.None, 0); reply = ReadDLMSPacket(data); } if (Trace) { Console.WriteLine("Parsing AARE reply" + BitConverter.ToString(reply)); } //Parse reply. m_Parser.ParseAAREResponse(reply); Console.WriteLine("Parsing AARE reply succeeded."); }
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; }
/// <summary> /// Update categories data. /// </summary> /// <param name="trace"></param> /// <param name="progressbar"></param> /// <param name="media"></param> /// <param name="Device"></param> /// <param name="wt"></param> /// <param name="cosem"></param> /// <param name="man"></param> /// <param name="objs"></param> /// <param name="dataItems"></param> /// <param name="registers"></param> private object UpdateData(Gurux.Common.IGXMedia media, GXDLMSDevice Device, int wt, GXDLMSClient cosem, GXManufacturer man, GXDLMSObject it, GXCategory dataItems, GXCategory registers) { GXObisCode code = man.ObisCodes.FindByLN(it.ObjectType, it.LogicalName, null); if (it.ObjectType == ObjectType.Register) { GXDLMSRegister prop = new GXDLMSRegister(); UpdateObject(it, prop, 2); registers.Properties.Add(prop); return prop; } else if (it.ObjectType == Gurux.DLMS.ObjectType.Data) { GXDLMSProperty prop = new GXDLMSProperty(); prop.ObjectType = ObjectType.Data; UpdateObject(it, prop, 2); dataItems.Properties.Add(prop); return prop; } else if (it.ObjectType == Gurux.DLMS.ObjectType.ProfileGeneric) { GXDLMSProfileGeneric pg = it as GXDLMSProfileGeneric; GXDLMSTable table = new GXDLMSTable(); table.Name = it.LogicalName + " " + it.Description; table.ShortName = it.ShortName; table.LogicalName = it.LogicalName; table.AccessMode = Gurux.Device.AccessMode.Read; foreach(var it2 in pg.CaptureObjects) { GXDLMSProperty prop; if (it2.Key is Gurux.DLMS.Objects.GXDLMSRegister) { Gurux.DLMS.Objects.GXDLMSRegister tmp = it2.Key as Gurux.DLMS.Objects.GXDLMSRegister; GXDLMSRegister r = new GXDLMSRegister(); prop = r; r.Scaler = tmp.Scaler; r.Unit = tmp.Unit.ToString(); } else { prop = new GXDLMSProperty(); } int index = it2.Value.AttributeIndex; prop.Name = it2.Key.LogicalName + " " + it2.Key.Description; prop.ObjectType = it2.Key.ObjectType; prop.AttributeOrdinal = index; prop.LogicalName = it2.Key.LogicalName; table.Columns.Add(prop); prop.DLMSType = it.GetDataType(index); prop.ValueType = it2.Key.GetUIDataType(index); } Device.Tables.Add(table); return table; } GXDLMSCategory cat = new GXDLMSCategory(); cat.ObjectType = it.ObjectType; UpdateObject(it, cat); Device.Categories.Add(cat); return cat; }
internal void CreateColumns(Gurux.Common.IGXMedia media, GXDLMSDevice Device, GXManufacturer man, int wt, GXDLMSClient cosem, IGXManufacturerExtension Extension, GXCategory dataItems, GXCategory registers, GXDLMSObject it, GXDLMSTable table) { }
/* Mikko private void CreateTables(Gurux.Common.IGXMedia media, GXDLMSDevice Device, GXManufacturer man, int wt, GXDLMSClient cosem, IGXManufacturerExtension Extension, GXDLMSObjectCollection objs, GXCategory dataItems, GXCategory registers) { //Profile generic will handle here, because it will need register objects and they must read fist. foreach (GXDLMSObject it in objs) { if (it.ObjectType == ObjectType.ProfileGeneric) { GXDLMSTable table = new GXDLMSTable(); table.Name = it.LogicalName + " " + it.Description; table.ShortName = it.ShortName; table.LogicalName = it.LogicalName; table.AccessMode = Gurux.Device.AccessMode.Read; Device.Tables.Add(table); System.Diagnostics.Debug.WriteLine("---- " + it.LogicalName); if (Extension != null) { Extension.UpdateColumns(Device, man, cosem, media, wt, it, table, this, dataItems, registers); } else { CreateColumns(media, Device, man, wt, cosem, Extension, dataItems, registers, it, table); } } } } */ string GetName(GXManufacturer man, Gurux.DLMS.ObjectType type, string logicanName) { GXObisCode code = man.ObisCodes.FindByLN(type, logicanName, null); string name = null; if (code != null) { name = code.Description; } if (string.IsNullOrEmpty(name)) { name = logicanName; } return name; }
string GetName(GXManufacturer manufacturer, bool useLN, GXDLMSObject it) { string name; if (useLN) { name = it.LogicalName; } else { name = "0x" + Convert.ToString(it.ShortName, 16).PadLeft(4) + " " + it.LogicalName; } GXObisCode code = manufacturer.ObisCodes.FindByLN(it.ObjectType, it.LogicalName, null); if (code != null && !string.IsNullOrEmpty(code.Description)) { name += " " + code.Description; } else { name += " " + it.Description; } return name; }
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 void UpdateColumns(GXDLMSDevice Device, GXManufacturer man, GXDLMSClient cosem, Gurux.Common.IGXMedia media, int wt, Gurux.DLMS.Objects.GXDLMSObject it, GXDLMSTable table, GXDLMSAddIn parent, GXCategory dataItems, GXCategory registers) { //Reading data. //If Load profile1 if (it.LogicalName == "0.0.99.1.2.255") { //Read Load Profile 1 information byte[] allData = parent.ReadDataBlock(cosem, media, cosem.Read("0.0.99.128.1.255", ObjectType.ProfileGeneric, 2)[0], wt, 0); object[] items = (object[])((object[])cosem.GetValue(allData)).GetValue(0); int pos = 0; AddColumn(cosem, man, table, null, null, 0, "DateTime"); AddColumn(cosem, man, table, null, null, 1, "Status"); AddColumn(cosem, man, table, (byte[])items.GetValue(pos), items.GetValue(pos + 1), 2, null); pos += 2; AddColumn(cosem, man, table, (byte[])items.GetValue(pos), items.GetValue(pos + 1), 3, null); pos += 2; AddColumn(cosem, man, table, (byte[])items.GetValue(pos), items.GetValue(pos + 1), 4, null); pos += 2; AddColumn(cosem, man, table, (byte[])items.GetValue(pos), items.GetValue(pos + 1), 5, null); pos += 2; AddColumn(cosem, man, table, (byte[])items.GetValue(pos), items.GetValue(pos + 1), 6, null); pos += 2; AddColumn(cosem, man, table, (byte[])items.GetValue(pos), items.GetValue(pos + 1), 7, null); pos += 2; AddColumn(cosem, man, table, (byte[])items.GetValue(pos), items.GetValue(pos + 1), 8, null); pos += 2; AddColumn(cosem, man, table, (byte[])items.GetValue(pos), items.GetValue(pos + 1), 9, null); return; } parent.CreateColumns(media, Device, man, wt, cosem, this, dataItems, registers, it, table); }