diff --git a/Development/GXDLMSDirector.csproj b/Development/GXDLMSDirector.csproj index 6c356b3..2268c97 100644 --- a/Development/GXDLMSDirector.csproj +++ b/Development/GXDLMSDirector.csproj @@ -135,8 +135,8 @@ packages\Gurux.DLMS.8.5.1801.1202\lib\portable-win+net35\Gurux.DLMS.dll - - packages\Gurux.DLMS.UI.8.5.1801.1201\lib\portable-win+net40\Gurux.DLMS.UI.dll + + packages\Gurux.DLMS.UI.8.5.1801.2201\lib\portable-win+net40\Gurux.DLMS.UI.dll packages\Gurux.Net.8.1.1801.1201\lib\portable-win+net40\Gurux.Net.dll @@ -168,6 +168,12 @@ GXExternalMediaForm.cs + + Form + + + GXFindDlg.cs + Form @@ -232,6 +238,9 @@ GXExternalMediaForm.cs + + GXFindDlg.cs + GXObisValueItemForm.cs Designer diff --git a/Development/GXExternalMediaForm.cs b/Development/GXExternalMediaForm.cs index e21fbf6..0f59b99 100644 --- a/Development/GXExternalMediaForm.cs +++ b/Development/GXExternalMediaForm.cs @@ -32,15 +32,9 @@ //--------------------------------------------------------------------------- using Gurux.Common; using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; using System.IO; -using System.Linq; using System.Net; using System.Reflection; -using System.Text; using System.Windows.Forms; namespace GXDLMSDirector diff --git a/Development/GXFindDlg.Designer.cs b/Development/GXFindDlg.Designer.cs new file mode 100644 index 0000000..7b5bfed --- /dev/null +++ b/Development/GXFindDlg.Designer.cs @@ -0,0 +1,108 @@ +namespace GXDLMSDirector +{ + partial class GXFindDlg + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.FindBtn = new System.Windows.Forms.Button(); + this.FindTb = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.CancelBtn = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // FindBtn + // + this.FindBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.FindBtn.DialogResult = System.Windows.Forms.DialogResult.OK; + this.FindBtn.Location = new System.Drawing.Point(251, 4); + this.FindBtn.Name = "FindBtn"; + this.FindBtn.Size = new System.Drawing.Size(75, 23); + this.FindBtn.TabIndex = 1; + this.FindBtn.Text = "Find Next"; + this.FindBtn.Click += new System.EventHandler(this.FindBtn_Click); + // + // FindTb + // + this.FindTb.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.FindTb.Location = new System.Drawing.Point(74, 6); + this.FindTb.Name = "FindTb"; + this.FindTb.Size = new System.Drawing.Size(155, 20); + this.FindTb.TabIndex = 0; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(56, 13); + this.label1.TabIndex = 27; + this.label1.Text = "Find what:"; + // + // CancelBtn + // + this.CancelBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.CancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.CancelBtn.Location = new System.Drawing.Point(251, 33); + this.CancelBtn.Name = "CancelBtn"; + this.CancelBtn.Size = new System.Drawing.Size(75, 23); + this.CancelBtn.TabIndex = 2; + this.CancelBtn.Text = "&Cancel"; + this.CancelBtn.UseVisualStyleBackColor = true; + // + // GXFindDlg + // + this.AcceptButton = this.FindBtn; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this.CancelBtn; + this.ClientSize = new System.Drawing.Size(338, 68); + this.Controls.Add(this.CancelBtn); + this.Controls.Add(this.label1); + this.Controls.Add(this.FindTb); + this.Controls.Add(this.FindBtn); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "GXFindDlg"; + this.Padding = new System.Windows.Forms.Padding(9); + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Find OBIS code"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button FindBtn; + private System.Windows.Forms.TextBox FindTb; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button CancelBtn; + } +} diff --git a/Development/GXFindDlg.cs b/Development/GXFindDlg.cs new file mode 100644 index 0000000..010adc4 --- /dev/null +++ b/Development/GXFindDlg.cs @@ -0,0 +1,169 @@ +// +// -------------------------------------------------------------------------- +// Gurux Ltd +// +// +// +// +// Version: $Revision: 9442 $, +// $Date: 2017-05-23 15:21:03 +0300 (ti, 23 touko 2017) $ +// $Author: gurux01 $ +// +// Copyright (c) Gurux Ltd +// +//--------------------------------------------------------------------------- +// +// DESCRIPTION +// +// This file is a part of Gurux Device Framework. +// +// Gurux Device Framework is Open Source software; you can redistribute it +// and/or modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; version 2 of the License. +// Gurux Device Framework is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// More information of Gurux DLMS/COSEM Director: http://www.gurux.org/GXDLMSDirector +// +// This code is licensed under the GNU General Public License v2. +// Full text may be retrieved at http://www.gnu.org/licenses/gpl-2.0.txt +//--------------------------------------------------------------------------- + +using Gurux.Common; +using System; +using System.Reflection; +using System.Windows.Forms; + +namespace GXDLMSDirector +{ + /// + /// Search dialog for OBIS code. + /// + partial class GXFindDlg : Form + { + public string Target + { + get; + set; + } + + /// + /// Constructor. + /// + /// OBIS code to search. + public GXFindDlg(string target) + { + InitializeComponent(); + FindTb.Text = target; + } + + #region Assembly Attribute Accessors + + public string AssemblyTitle + { + get + { + object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false); + if (attributes.Length > 0) + { + AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0]; + if (titleAttribute.Title != "") + { + return titleAttribute.Title; + } + } + return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase); + } + } + + public string AssemblyVersion + { + get + { + return Assembly.GetExecutingAssembly().GetName().Version.ToString(); + } + } + + public string AssemblyDescription + { + get + { + object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false); + if (attributes.Length == 0) + { + return ""; + } + return ((AssemblyDescriptionAttribute)attributes[0]).Description; + } + } + + public string AssemblyProduct + { + get + { + object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false); + if (attributes.Length == 0) + { + return ""; + } + return ((AssemblyProductAttribute)attributes[0]).Product; + } + } + + public string AssemblyCopyright + { + get + { + object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); + if (attributes.Length == 0) + { + return ""; + } + return ((AssemblyCopyrightAttribute)attributes[0]).Copyright; + } + } + + public string AssemblyCompany + { + get + { + object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false); + if (attributes.Length == 0) + { + return ""; + } + return ((AssemblyCompanyAttribute)attributes[0]).Company; + } + } + #endregion + + private void FindBtn_Click(object sender, EventArgs e) + { + try + { + //If OBIS code is given as hex. + if (FindTb.Text.IndexOf('.') == -1) + { + byte[] tmp = GXCommon.HexToBytes(FindTb.Text); + if (tmp.Length != 6) + { + throw new Exception("Invalid OBIS code."); + } + Target = tmp[5].ToString() + '.' + tmp[4] + '.' + tmp[3] + '.' + tmp[2] + '.' + tmp[1] + '.' + tmp[0] + '.'; + } + else if (FindTb.Text.Split(new char[] { '.' }).Length != 6) + { + throw new Exception("Invalid OBIS code."); + } + Target = FindTb.Text.Trim(); + } + catch (Exception Ex) + { + GXDLMS.Common.Error.ShowError(this, Ex); + DialogResult = DialogResult.None; + } + } + } +} diff --git a/Development/GXFindDlg.resx b/Development/GXFindDlg.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Development/GXFindDlg.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Development/MainForm.Designer.cs b/Development/MainForm.Designer.cs index 1d53591..7119666 100644 --- a/Development/MainForm.Designer.cs +++ b/Development/MainForm.Designer.cs @@ -5,8 +5,8 @@ // // // -// Version: $Revision: 9749 $, -// $Date: 2017-12-05 10:01:35 +0200 (ti, 05 joulu 2017) $ +// Version: $Revision: 9818 $, +// $Date: 2018-01-22 09:05:42 +0200 (ma, 22 tammi 2018) $ // $Author: gurux01 $ // // Copyright (c) Gurux Ltd @@ -77,6 +77,11 @@ private void InitializeComponent() this.RecentFilesMnu = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem11 = new System.Windows.Forms.ToolStripSeparator(); this.ExitMnu = new System.Windows.Forms.ToolStripMenuItem(); + this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.findToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.findNextToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem16 = new System.Windows.Forms.ToolStripSeparator(); + this.CloneBtn = new System.Windows.Forms.ToolStripMenuItem(); this.viewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ViewToolbarMnu = new System.Windows.Forms.ToolStripMenuItem(); this.ViewStatusbarMnu = new System.Windows.Forms.ToolStripMenuItem(); @@ -90,6 +95,11 @@ private void InitializeComponent() this.hexToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.xmlToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.pDUToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem15 = new System.Windows.Forms.ToolStripMenuItem(); + this.NotificationNone = new System.Windows.Forms.ToolStripMenuItem(); + this.NotificationHex = new System.Windows.Forms.ToolStripMenuItem(); + this.NotificationXml = new System.Windows.Forms.ToolStripMenuItem(); + this.NotificationPdu = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator(); this.ForceReadMnu = new System.Windows.Forms.ToolStripMenuItem(); this.PropertiesMnu = new System.Windows.Forms.ToolStripMenuItem(); @@ -110,11 +120,11 @@ private void InitializeComponent() this.OBISCodesMnu = new System.Windows.Forms.ToolStripMenuItem(); this.settingsToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.notificationsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.AutoReset = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem13 = new System.Windows.Forms.ToolStripSeparator(); this.StartNotifications = new System.Windows.Forms.ToolStripMenuItem(); this.StopNotifications = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem14 = new System.Windows.Forms.ToolStripSeparator(); + this.AutoReset = new System.Windows.Forms.ToolStripMenuItem(); this.ClearNotifications = new System.Windows.Forms.ToolStripMenuItem(); this.updateManufactureSettingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -196,11 +206,9 @@ private void InitializeComponent() this.DeviceList = new System.Windows.Forms.ListView(); this.DeviceNameCH = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.ObjectPanelFrame = new System.Windows.Forms.Panel(); - this.toolStripMenuItem15 = new System.Windows.Forms.ToolStripMenuItem(); - this.NotificationNone = new System.Windows.Forms.ToolStripMenuItem(); - this.NotificationHex = new System.Windows.Forms.ToolStripMenuItem(); - this.NotificationXml = new System.Windows.Forms.ToolStripMenuItem(); - this.NotificationPdu = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem17 = new System.Windows.Forms.ToolStripMenuItem(); + this.LogHexBtn = new System.Windows.Forms.ToolStripMenuItem(); + this.LogXmlBtn = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); this.statusStrip1.SuspendLayout(); this.contextMenuStrip1.SuspendLayout(); @@ -217,6 +225,7 @@ private void InitializeComponent() // this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.fileToolStripMenuItem, + this.editToolStripMenuItem, this.viewToolStripMenuItem, this.toolsToolStripMenuItem, this.notificationsToolStripMenuItem, @@ -320,6 +329,46 @@ private void InitializeComponent() this.ExitMnu.Text = "&Exit"; this.ExitMnu.Click += new System.EventHandler(this.ExitMnu_Click); // + // editToolStripMenuItem + // + this.editToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.findToolStripMenuItem, + this.findNextToolStripMenuItem, + this.toolStripMenuItem16, + this.CloneBtn}); + this.editToolStripMenuItem.Name = "editToolStripMenuItem"; + this.editToolStripMenuItem.Size = new System.Drawing.Size(39, 20); + this.editToolStripMenuItem.Text = "&Edit"; + // + // findToolStripMenuItem + // + this.findToolStripMenuItem.Name = "findToolStripMenuItem"; + this.findToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.F))); + this.findToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.findToolStripMenuItem.Text = "Find..."; + this.findToolStripMenuItem.Click += new System.EventHandler(this.findToolStripMenuItem_Click); + // + // findNextToolStripMenuItem + // + this.findNextToolStripMenuItem.Enabled = false; + this.findNextToolStripMenuItem.Name = "findNextToolStripMenuItem"; + this.findNextToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.F3; + this.findNextToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.findNextToolStripMenuItem.Text = "Find Next"; + this.findNextToolStripMenuItem.Click += new System.EventHandler(this.findNextToolStripMenuItem_Click); + // + // toolStripMenuItem16 + // + this.toolStripMenuItem16.Name = "toolStripMenuItem16"; + this.toolStripMenuItem16.Size = new System.Drawing.Size(149, 6); + // + // CloneBtn + // + this.CloneBtn.Name = "CloneBtn"; + this.CloneBtn.Size = new System.Drawing.Size(152, 22); + this.CloneBtn.Text = "Clone..."; + this.CloneBtn.Click += new System.EventHandler(this.CloneBtn_Click); + // // viewToolStripMenuItem // this.viewToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -330,6 +379,7 @@ private void InitializeComponent() this.ObjectListMnu, this.GroupsMnu, this.toolStripMenuItem7, + this.toolStripMenuItem17, this.TraceMnu, this.toolStripMenuItem15, this.toolStripSeparator4, @@ -423,6 +473,45 @@ private void InitializeComponent() this.pDUToolStripMenuItem.Text = "&Pdu"; this.pDUToolStripMenuItem.Click += new System.EventHandler(this.pDUToolStripMenuItem_Click); // + // toolStripMenuItem15 + // + this.toolStripMenuItem15.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.NotificationNone, + this.NotificationHex, + this.NotificationXml, + this.NotificationPdu}); + this.toolStripMenuItem15.Name = "toolStripMenuItem15"; + this.toolStripMenuItem15.Size = new System.Drawing.Size(152, 22); + this.toolStripMenuItem15.Text = "&Notifications"; + // + // NotificationNone + // + this.NotificationNone.Name = "NotificationNone"; + this.NotificationNone.Size = new System.Drawing.Size(152, 22); + this.NotificationNone.Text = "&None"; + this.NotificationNone.Click += new System.EventHandler(this.NotificationNone_Click); + // + // NotificationHex + // + this.NotificationHex.Name = "NotificationHex"; + this.NotificationHex.Size = new System.Drawing.Size(152, 22); + this.NotificationHex.Text = "&Hex"; + this.NotificationHex.Click += new System.EventHandler(this.NotificationHex_Click); + // + // NotificationXml + // + this.NotificationXml.Name = "NotificationXml"; + this.NotificationXml.Size = new System.Drawing.Size(152, 22); + this.NotificationXml.Text = "Xml"; + this.NotificationXml.Click += new System.EventHandler(this.NotificationXml_Click); + // + // NotificationPdu + // + this.NotificationPdu.Name = "NotificationPdu"; + this.NotificationPdu.Size = new System.Drawing.Size(152, 22); + this.NotificationPdu.Text = "&Pdu"; + this.NotificationPdu.Click += new System.EventHandler(this.NotificationPdu_Click); + // // toolStripSeparator4 // this.toolStripSeparator4.Name = "toolStripSeparator4"; @@ -579,23 +668,15 @@ private void InitializeComponent() this.notificationsToolStripMenuItem.Size = new System.Drawing.Size(87, 20); this.notificationsToolStripMenuItem.Text = "Notifications"; // - // AutoReset - // - this.AutoReset.Name = "AutoReset"; - this.AutoReset.Size = new System.Drawing.Size(152, 22); - this.AutoReset.Text = "Auto Reset"; - this.AutoReset.ToolTipText = "Clear notifications view after new message is received."; - this.AutoReset.Click += new System.EventHandler(this.AutoReset_Click); - // // toolStripMenuItem13 // this.toolStripMenuItem13.Name = "toolStripMenuItem13"; - this.toolStripMenuItem13.Size = new System.Drawing.Size(149, 6); + this.toolStripMenuItem13.Size = new System.Drawing.Size(128, 6); // // StartNotifications // this.StartNotifications.Name = "StartNotifications"; - this.StartNotifications.Size = new System.Drawing.Size(152, 22); + this.StartNotifications.Size = new System.Drawing.Size(131, 22); this.StartNotifications.Text = "Start"; this.StartNotifications.ToolTipText = "Start receiving notifications"; this.StartNotifications.Click += new System.EventHandler(this.StartNotifications_Click); @@ -603,7 +684,7 @@ private void InitializeComponent() // StopNotifications // this.StopNotifications.Name = "StopNotifications"; - this.StopNotifications.Size = new System.Drawing.Size(152, 22); + this.StopNotifications.Size = new System.Drawing.Size(131, 22); this.StopNotifications.Text = "Stop"; this.StopNotifications.ToolTipText = "Stop receiving notifications."; this.StopNotifications.Visible = false; @@ -612,12 +693,20 @@ private void InitializeComponent() // toolStripMenuItem14 // this.toolStripMenuItem14.Name = "toolStripMenuItem14"; - this.toolStripMenuItem14.Size = new System.Drawing.Size(149, 6); + this.toolStripMenuItem14.Size = new System.Drawing.Size(128, 6); + // + // AutoReset + // + this.AutoReset.Name = "AutoReset"; + this.AutoReset.Size = new System.Drawing.Size(131, 22); + this.AutoReset.Text = "Auto Reset"; + this.AutoReset.ToolTipText = "Clear notifications view after new message is received."; + this.AutoReset.Click += new System.EventHandler(this.AutoReset_Click); // // ClearNotifications // this.ClearNotifications.Name = "ClearNotifications"; - this.ClearNotifications.Size = new System.Drawing.Size(152, 22); + this.ClearNotifications.Size = new System.Drawing.Size(131, 22); this.ClearNotifications.Text = "Clear"; this.ClearNotifications.ToolTipText = "Clear received notification."; this.ClearNotifications.Click += new System.EventHandler(this.ClearNotifications_Click); @@ -1318,44 +1407,28 @@ private void InitializeComponent() this.ObjectPanelFrame.Size = new System.Drawing.Size(187, 142); this.ObjectPanelFrame.TabIndex = 32; // - // toolStripMenuItem15 - // - this.toolStripMenuItem15.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.NotificationNone, - this.NotificationHex, - this.NotificationXml, - this.NotificationPdu}); - this.toolStripMenuItem15.Name = "toolStripMenuItem15"; - this.toolStripMenuItem15.Size = new System.Drawing.Size(152, 22); - this.toolStripMenuItem15.Text = "&Notifications"; - // - // NotificationNone + // toolStripMenuItem17 // - this.NotificationNone.Name = "NotificationNone"; - this.NotificationNone.Size = new System.Drawing.Size(152, 22); - this.NotificationNone.Text = "&None"; - this.NotificationNone.Click += new System.EventHandler(this.NotificationNone_Click); + this.toolStripMenuItem17.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.LogHexBtn, + this.LogXmlBtn}); + this.toolStripMenuItem17.Name = "toolStripMenuItem17"; + this.toolStripMenuItem17.Size = new System.Drawing.Size(152, 22); + this.toolStripMenuItem17.Text = "&Log"; // - // NotificationHex + // LogHexBtn // - this.NotificationHex.Name = "NotificationHex"; - this.NotificationHex.Size = new System.Drawing.Size(152, 22); - this.NotificationHex.Text = "&Hex"; - this.NotificationHex.Click += new System.EventHandler(this.NotificationHex_Click); - // - // NotificationXml + this.LogHexBtn.Name = "LogHexBtn"; + this.LogHexBtn.Size = new System.Drawing.Size(152, 22); + this.LogHexBtn.Text = "&Hex"; + this.LogHexBtn.Click += new System.EventHandler(this.LogHexBtn_Click); // - this.NotificationXml.Name = "NotificationXml"; - this.NotificationXml.Size = new System.Drawing.Size(152, 22); - this.NotificationXml.Text = "Xml"; - this.NotificationXml.Click += new System.EventHandler(this.NotificationXml_Click); + // LogXmlBtn // - // NotificationPdu - // - this.NotificationPdu.Name = "NotificationPdu"; - this.NotificationPdu.Size = new System.Drawing.Size(152, 22); - this.NotificationPdu.Text = "&Pdu"; - this.NotificationPdu.Click += new System.EventHandler(this.NotificationPdu_Click); + this.LogXmlBtn.Name = "LogXmlBtn"; + this.LogXmlBtn.Size = new System.Drawing.Size(152, 22); + this.LogXmlBtn.Text = "Xml"; + this.LogXmlBtn.Click += new System.EventHandler(this.LogXmlBtn_Click); // // MainForm // @@ -1540,6 +1613,14 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem NotificationHex; private System.Windows.Forms.ToolStripMenuItem NotificationXml; private System.Windows.Forms.ToolStripMenuItem NotificationPdu; + private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem findToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem findNextToolStripMenuItem; + private System.Windows.Forms.ToolStripSeparator toolStripMenuItem16; + private System.Windows.Forms.ToolStripMenuItem CloneBtn; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem17; + private System.Windows.Forms.ToolStripMenuItem LogHexBtn; + private System.Windows.Forms.ToolStripMenuItem LogXmlBtn; } } diff --git a/Development/MainForm.cs b/Development/MainForm.cs index e98a985..18b72ad 100644 --- a/Development/MainForm.cs +++ b/Development/MainForm.cs @@ -5,8 +5,8 @@ // // // -// Version: $Revision: 9796 $, -// $Date: 2018-01-09 12:23:45 +0200 (ti, 09 tammi 2018) $ +// Version: $Revision: 9821 $, +// $Date: 2018-01-22 14:36:35 +0200 (ma, 22 tammi 2018) $ // $Author: gurux01 $ // // Copyright (c) Gurux Ltd @@ -54,6 +54,7 @@ using Gurux.DLMS.UI; using Gurux.Net; using System.Text; +using System.Runtime.Serialization.Formatters.Binary; namespace GXDLMSDirector { @@ -121,17 +122,10 @@ internal void SetDirty(bool dirty) public static void InitMain() { - //Update previous installed settings. - if (Properties.Settings.Default.UpdateSettings) - { - Properties.Settings.Default.Upgrade(); - Properties.Settings.Default.UpdateSettings = false; - Properties.Settings.Default.Save(); - } //Debug traces are written only log file. - if (!System.Diagnostics.Debugger.IsAttached) + if (!Debugger.IsAttached) { - System.Diagnostics.Trace.Listeners.Clear(); + Trace.Listeners.Clear(); } DirectoryInfo di = new System.IO.DirectoryInfo(System.IO.Path.GetDirectoryName((GXLogWriter.LogPath))); if (!di.Exists) @@ -139,9 +133,9 @@ public static void InitMain() di.Create(); } GXLogWriter.ClearLog(); - System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(GXLogWriter.LogPath)); - System.Diagnostics.Trace.AutoFlush = true; - System.Diagnostics.Trace.IndentSize = 4; + Trace.Listeners.Add(new TextWriterTraceListener(GXLogWriter.LogPath)); + Trace.AutoFlush = true; + Trace.IndentSize = 4; if (Environment.OSVersion.Platform != PlatformID.Unix) { Application.EnableVisualStyles(); @@ -373,7 +367,7 @@ private void SelectItem(object obj) ObjectPanelFrame.Controls.Clear(); SelectedView.Target = (GXDLMSObject)obj; SelectedView.Target.OnChange += new ObjectChangeEventHandler(DLMSItemOnChange); - UpdateProperties(obj, SelectedView, new List(), 0); + UpdateProperties(obj, SelectedView, new List(), 0, true); ObjectPanelFrame.Controls.Add((Form)SelectedView); ((Form)SelectedView).Show(); UpdateDeviceUI(GetDevice(SelectedView.Target), GetDevice((GXDLMSObject)obj).Status); @@ -484,6 +478,7 @@ void DLMSItemOnChange(GXDLMSObject sender, bool dirty, int attributeIndex, objec private static GXValueField UpdateProperties(IGXDLMSView view, System.Windows.Forms.Control.ControlCollection controls, GXDLMSObject target, int index, object value) { + GXDLMSDevice dev = (GXDLMSDevice)view.Target.Parent.Tag; GXValueField item = null; foreach (Control it in controls) { @@ -493,7 +488,7 @@ private static GXValueField UpdateProperties(IGXDLMSView view, System.Windows.Fo if (obj.Index == index) { obj.Target = target; - obj.UpdateValueItems(target, index, value); + obj.UpdateValueItems(target, index, value, (dev.Status & DeviceState.Connected) != 0); obj.Value = value; item = obj; } @@ -515,7 +510,7 @@ private static GXValueField UpdateProperties(IGXDLMSView view, System.Windows.Fo if ((btn.Action == ActionType.Read || btn.Action == ActionType.Write) && btn.Index == index) { btn.View = view; - btn.Enabled = (target.GetAccess(index) & AccessMode.Write) != 0; + btn.Enabled = (dev.Status & DeviceState.Connected) != 0 && (target.GetAccess(index) & AccessMode.Write) != 0; if (btn.Enabled) { btn.Target = target; @@ -635,14 +630,14 @@ static void OnHandleAction(object sender, EventArgs e) } } - delegate void ValueChangedEventHandler(IGXDLMSView view, int index, object value, bool changeByUser); + delegate void ValueChangedEventHandler(IGXDLMSView view, int index, object value, bool changeByUser, bool connected); - static void OnValueChanged(IGXDLMSView view, int index, object value, bool changeByUser) + static void OnValueChanged(IGXDLMSView view, int index, object value, bool changeByUser, bool connected) { - view.OnValueChanged(index, value, changeByUser); + view.OnValueChanged(index, value, changeByUser, connected); } - private void UpdateProperties(object obj, IGXDLMSView view, List UpdatedObjects, int index) + private void UpdateProperties(object obj, IGXDLMSView view, List UpdatedObjects, int index, bool updateAccessLevels) { if (obj == null) { @@ -650,6 +645,7 @@ private void UpdateProperties(object obj, IGXDLMSView view, List Updated } UpdateWriteEnabled(); GXDLMSObject tmp = view.Target; + GXDLMSDevice dev = (GXDLMSDevice)tmp.Parent.Tag; view.Description = tmp.Description; if (view.ErrorProvider != null) { @@ -697,30 +693,36 @@ private void UpdateProperties(object obj, IGXDLMSView view, List Updated } GXValueField item = UpdateProperties(view, ((Form)view).Controls, view.Target, it, value); if (item == null || item.NotifyChanges) - { - view.OnAccessRightsChange(it, view.Target.GetAccess(it)); - } - if (item == null || item.NotifyChanges) { if (InvokeRequired) { - ((Form)view).Invoke(new ValueChangedEventHandler(OnValueChanged), new object[] { view, it, value, dirty }); + ((Form)view).Invoke(new ValueChangedEventHandler(OnValueChanged), new object[] { view, it, value, dirty, (dev.Status & DeviceState.Connected) != 0 }); } else { - view.OnValueChanged(it, value, false); + view.OnValueChanged(it, value, false, (dev.Status & DeviceState.Connected) != 0); + } + if (updateAccessLevels) + { + bool connected = (dev.Status & DeviceState.Connected) != 0; + view.OnAccessRightsChange(it, tmp.GetAccess(it), connected); } } } } if (index == 0) { + MethodAccessMode ma = MethodAccessMode.NoAccess; for (int it = 1; it != (obj as IGXDLMSBase).GetMethodCount() + 1; ++it) { bool bFound = UpdateActions(view, ((Form)view).Controls, view.Target, it); if (!bFound) { - view.OnAccessRightsChange(it, view.Target.GetMethodAccess(it)); + if ((dev.Status & DeviceState.Connected) != 0) + { + ma = view.Target.GetMethodAccess(it); + } + view.OnAccessRightsChange(it, ma, (dev.Status & DeviceState.Connected) != 0); } } } @@ -803,6 +805,31 @@ GXDLMSDevice GetSelectedDevice() return null; } + private DialogResult ShowProperties(GXDLMSDevice dev, bool newDevice) + { + string man = dev.Manufacturer; + DevicePropertiesForm dlg = new DevicePropertiesForm(this.Manufacturers, dev); + DialogResult res = dlg.ShowDialog(this); + if (res == DialogResult.OK) + { + if (!newDevice) + { + //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); + } + } + return res; + } + /// /// Show properties of the selected media. /// @@ -815,22 +842,7 @@ private void PropertiesMnu_Click(object sender, EventArgs e) 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); - } + ShowProperties(dev, false); } } catch (Exception Ex) @@ -891,7 +903,7 @@ private void AboutMnu_Click(object sender, EventArgs e) lic.CopyrightText = GXDLMSDirector.Properties.Resources.CopyrightTxt; //Get version info System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly(); - System.Diagnostics.FileVersionInfo info = System.Diagnostics.FileVersionInfo.GetVersionInfo(asm.Location); + FileVersionInfo info = FileVersionInfo.GetVersionInfo(asm.Location); lic.ShowAbout(this, info.FileVersion); } catch (Exception Ex) @@ -1018,6 +1030,21 @@ private void OnFirstConnection(GXDLMSDevice device) } } + /// + /// Ask is association view read when connecting first time. + /// + /// Selected object. + delegate void UpdateAccessRightsEventHandler(GXDLMSObject obj); + + /// + /// Ask is association view read when connecting first time. + /// + /// Selected object. + private void UpdateAccessRights(GXDLMSObject obj) + { + UpdateProperties(obj, SelectedView, new List(), 0, true); + } + void Connect(object sender, GXAsyncWork work, object[] parameters) { try @@ -1067,6 +1094,17 @@ void Connect(object sender, GXAsyncWork work, object[] parameters) } } Connect(sender, work, new object[] { devices }); + if (tmp.Count == 1) + { + if (InvokeRequired) + { + BeginInvoke(new UpdateAccessRightsEventHandler(UpdateAccessRights), tmp[0]); + } + else + { + UpdateAccessRights(tmp[0]); + } + } } else { @@ -1077,6 +1115,14 @@ void Connect(object sender, GXAsyncWork work, object[] parameters) { dev.InitializeConnection(); } + if (InvokeRequired) + { + BeginInvoke(new UpdateAccessRightsEventHandler(UpdateAccessRights), tmp); + } + else + { + UpdateAccessRights(tmp); + } } } catch (ThreadAbortException) @@ -1147,6 +1193,17 @@ void Disconnect(object sender, GXAsyncWork work, object[] parameters) } } Disconnect(sender, work, new object[] { devices }); + if (tmp.Count == 1) + { + if (InvokeRequired) + { + BeginInvoke(new UpdateAccessRightsEventHandler(UpdateAccessRights), tmp[0]); + } + else + { + UpdateAccessRights(tmp[0]); + } + } } else { @@ -1154,6 +1211,14 @@ void Disconnect(object sender, GXAsyncWork work, object[] parameters) GXDLMSObject tmp = obj as GXDLMSObject; GXDLMSDevice dev = tmp.Parent.Tag as GXDLMSDevice; dev.Disconnect(); + if (InvokeRequired) + { + BeginInvoke(new UpdateAccessRightsEventHandler(UpdateAccessRights), tmp); + } + else + { + UpdateAccessRights(tmp); + } } } catch (ThreadAbortException) @@ -1407,6 +1472,11 @@ private void LoadXmlPositioning() ForceReadMnu_Click(null, null); AutoReset.Checked = !Properties.Settings.Default.NotificationAutoReset; AutoReset_Click(null, null); + + LogHexBtn.Checked = (Properties.Settings.Default.Log & 1) != 0; + LogXmlBtn.Checked = (Properties.Settings.Default.Log & 2) != 0; + GXLogWriter.LogLevel = Properties.Settings.Default.Log; + string path = UserDataPath; if (System.Environment.OSVersion.Platform == PlatformID.Unix) { @@ -1634,7 +1704,7 @@ public void OnAfterRead(GXDLMSObject sender, int index) } if (SelectedView != null && SelectedView.Target == sender) { - UpdateProperties(sender, SelectedView, new List(), index); + UpdateProperties(sender, SelectedView, new List(), index, false); } ListViewItem lv = ObjectValueItems[sender] as ListViewItem; if (lv != null) @@ -1815,7 +1885,7 @@ private void WriteMnu_Click(object sender, EventArgs e) foreach (GXDLMSObject obj in objects) { dev.Comm.Write(obj, 0); - UpdateProperties(obj, SelectedView, new List(), 0); + UpdateProperties(obj, SelectedView, new List(), 0, false); } dev.KeepAliveStart(); } @@ -1826,7 +1896,7 @@ private void WriteMnu_Click(object sender, EventArgs e) dev.KeepAliveStop(); OnProgress(dev, "Writing...", 0, 1); dev.Comm.Write(obj, 0); - UpdateProperties(obj, SelectedView, new List(), 0); + UpdateProperties(obj, SelectedView, new List(), 0, false); dev.KeepAliveStart(); } } @@ -2476,20 +2546,25 @@ private void refreshToolStripMenuItem_Click(object sender, EventArgs e) TransactionWork.Start(); } + private void AddDevice(GXDLMSDevice dev) + { + DevicePropertiesForm dlg = new DevicePropertiesForm(this.Manufacturers, dev); + if (dlg.ShowDialog(this) == DialogResult.OK) + { + dlg.Device.Manufacturers = this.Manufacturers; + dlg.Device.Comm.parentForm = this; + AddDevice(dlg.Device, false); + Devices.Add(dlg.Device); + GroupItems(GroupsMnu.Checked); + SetDirty(true); + } + } + 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); - GroupItems(GroupsMnu.Checked); - SetDirty(true); - } + AddDevice(null); } catch (Exception Ex) { @@ -2501,7 +2576,7 @@ private void ContentsMnu_Click(object sender, EventArgs e) { try { - System.Diagnostics.Process.Start("http://www.gurux.fi/index.php?q=GXDLMSDirectorHelp"); + Process.Start("http://www.gurux.fi/index.php?q=GXDLMSDirectorHelp"); } catch (Exception Ex) { @@ -3027,7 +3102,7 @@ private void ObjectList_Resize(object sender, EventArgs e) } catch (Exception ex) { - System.Diagnostics.Debug.WriteLine(ex.Message); + Debug.WriteLine(ex.Message); } } @@ -3122,7 +3197,7 @@ private void ObjectList_ItemSelectionChanged(object sender, ListViewItemSelectio } catch (Exception ex) { - System.Diagnostics.Debug.WriteLine(ex.Message); + Debug.WriteLine(ex.Message); } finally { @@ -3350,5 +3425,191 @@ private void NotificationPdu_Click(object sender, EventArgs e) { UpdateNotification(3); } + + /// + /// OBIS code to search. + /// + string search = null; + + private bool FindTreeNode(TreeNodeCollection nodes, string text, ref TreeNode first) + { + foreach (TreeNode it in nodes) + { + if (first == null) + { + if (it == ObjectTree.SelectedNode) + { + first = it; + } + } + else if (it.Tag is GXDLMSObject && (it.Tag as GXDLMSObject).LogicalName == search) + { + ObjectTree.SelectedNode = it; + return true; + } + if (it.Nodes.Count != 0) + { + if (FindTreeNode(it.Nodes, text, ref first)) + { + return true; + } + } + } + return false; + } + + /// + /// Find OBIS code from the tree view. + /// + /// List of OBIS codes to search. + /// OBIS code to search + /// If selected item found. + /// Is OBIS code found. + private bool FindTreeNode(TreeNodeCollection nodes, string text, ref bool first) + { + TreeNode node = ObjectTree.SelectedNode; + foreach (TreeNode it in nodes) + { + if (!first) + { + first = it == node; + } + else if (it.Tag is GXDLMSObject && (it.Tag as GXDLMSObject).LogicalName == search) + { + ObjectTree.SelectedNode = it; + return true; + } + if (it.Nodes.Count != 0) + { + if (FindTreeNode(it.Nodes, text, ref first)) + { + return true; + } + } + } + return false; + } + + /// + /// Find next OBIS code from the tree view. + /// + private void findNextToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + bool first = false; + if (!FindTreeNode(ObjectTree.Nodes, search, ref first)) + { + first = true; + if (!FindTreeNode(ObjectTree.Nodes, search, ref first)) + { + throw new Exception("OBIS code '" + search + "' not found!"); + } + } + } + catch (Exception Ex) + { + GXDLMS.Common.Error.ShowError(this, Ex); + } + } + + /// + /// Find OBIS code from the tree view. + /// + private void findToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + GXFindDlg dlg = new GXFindDlg(search); + if (dlg.ShowDialog(this) == DialogResult.OK) + { + search = dlg.Target; + bool tmp = string.IsNullOrEmpty(search); + findNextToolStripMenuItem.Enabled = !tmp; + if (!tmp) + { + findNextToolStripMenuItem_Click(null, null); + } + } + } + catch (Exception Ex) + { + GXDLMS.Common.Error.ShowError(this, Ex); + } + } + + /// + /// Clone selected device. + /// + private void CloneBtn_Click(object sender, EventArgs e) + { + try + { + object tag = ObjectTree.SelectedNode.Tag; + GXDLMSDevice dev = null; + if (tag is GXDLMSDevice) + { + dev = tag as GXDLMSDevice; + } + else if (tag is GXDLMSObject) + { + dev = GetDevice(tag as GXDLMSObject); + } + if (dev != null) + { + //Create clone from original items. + using (MemoryStream ms = new MemoryStream()) + { + List types = new List(GXDLMSClient.GetObjectTypes()); + types.Add(typeof(GXDLMSAttributeSettings)); + types.Add(typeof(GXDLMSAttribute)); + XmlAttributeOverrides overrides = new XmlAttributeOverrides(); + XmlAttributes attribs = new XmlAttributes(); + attribs.XmlIgnore = true; + overrides.Add(typeof(GXDLMSDevice), "ObsoleteObjects", attribs); + overrides.Add(typeof(GXDLMSAttributeSettings), attribs); + XmlSerializer x = new XmlSerializer(typeof(GXDLMSDevice), overrides, types.ToArray(), null, "Gurux1"); + using (TextWriter writer = new StreamWriter(ms)) + { + x.Serialize(writer, dev); + ms.Position = 0; + using (XmlReader reader = XmlReader.Create(ms)) + { + dev = (GXDLMSDevice)x.Deserialize(reader); + } + } + ms.Close(); + dev.Name = ""; + AddDevice(dev); + } + } + } + catch (Exception Ex) + { + GXDLMS.Common.Error.ShowError(this, Ex); + } + } + + private void LogHexBtn_Click(object sender, EventArgs e) + { + LogHexBtn.Checked = !LogHexBtn.Checked; + Properties.Settings.Default.Log = LogHexBtn.Checked ? 1 : 0; + if (LogXmlBtn.Checked) + { + Properties.Settings.Default.Log |= 2; + } + GXLogWriter.LogLevel = Properties.Settings.Default.Log; + } + + private void LogXmlBtn_Click(object sender, EventArgs e) + { + LogXmlBtn.Checked = !LogXmlBtn.Checked; + Properties.Settings.Default.Log = LogHexBtn.Checked ? 1 : 0; + if (LogXmlBtn.Checked) + { + Properties.Settings.Default.Log |= 2; + } + GXLogWriter.LogLevel = Properties.Settings.Default.Log; + } } } diff --git a/Development/MainForm.resx b/Development/MainForm.resx index 6efa601..475dfd1 100644 --- a/Development/MainForm.resx +++ b/Development/MainForm.resx @@ -131,7 +131,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAC0 - EwAAAk1TRnQBSQFMAgEBDQEAAfwBAgH8AQIBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo + EwAAAk1TRnQBSQFMAgEBDQEAAQwBAwEMAQMBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo AwABQAMAAUADAAEBAQABCAYAARAYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5 AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA diff --git a/Development/ManufacturerSettings/GXLogWriter.cs b/Development/ManufacturerSettings/GXLogWriter.cs index ef7cb6b..91a0886 100644 --- a/Development/ManufacturerSettings/GXLogWriter.cs +++ b/Development/ManufacturerSettings/GXLogWriter.cs @@ -5,8 +5,8 @@ // // // -// Version: $Revision: 9442 $, -// $Date: 2017-05-23 15:21:03 +0300 (ti, 23 touko 2017) $ +// Version: $Revision: 9818 $, +// $Date: 2018-01-22 09:05:42 +0200 (ma, 22 tammi 2018) $ // $Author: gurux01 $ // // Copyright (c) Gurux Ltd @@ -41,11 +41,25 @@ using System.Diagnostics; using System.Windows.Forms; using Gurux.Common; +using Gurux.DLMS; +using Gurux.DLMS.Enums; namespace GXDLMS.ManufacturerSettings { class GXLogWriter { + /// + /// Received trace data. + /// + private static GXByteBuffer receivedTraceData = new GXByteBuffer(); + private static GXDLMSTranslator translator; + + static GXLogWriter() + { + translator = new GXDLMSTranslator(TranslatorOutputType.SimpleXml); + receivedTraceData = new GXByteBuffer(); + } + static public string LogPath { get @@ -77,6 +91,12 @@ static public string LogPath } } + static public int LogLevel + { + get; + set; + } + /// /// Append data to log file. /// @@ -92,11 +112,34 @@ static public void WriteLog(string data) static public void WriteLog(string text, byte[] value) { string str = DateTime.Now.ToLongTimeString() + " " + text; - if (value != null) + //Show data as hex. + if ((LogLevel & 1) != 0) { - str += "\r\n" + GXCommon.ToHex(value, true); + if (value != null) + { + str += "\r\n" + GXCommon.ToHex(value, true); + } + System.Diagnostics.Trace.WriteLine(str); + } + //Show data as xml. + if ((LogLevel & 2) != 0) + { + receivedTraceData.Set(value); + try + { + GXByteBuffer pdu = new GXByteBuffer(); + InterfaceType type = GXDLMSTranslator.GetDlmsFraming(receivedTraceData); + if (translator.FindNextFrame(receivedTraceData, pdu, type)) + { + System.Diagnostics.Trace.WriteLine(translator.MessageToXml(receivedTraceData)); + receivedTraceData.Clear(); + } + } + catch (Exception) + { + receivedTraceData.Clear(); + } } - System.Diagnostics.Trace.WriteLine(str); } /// diff --git a/Development/Program.cs b/Development/Program.cs index bbc7993..e8a016d 100644 --- a/Development/Program.cs +++ b/Development/Program.cs @@ -4,8 +4,8 @@ // // // -// Version: $Revision: 9806 $, -// $Date: 2018-01-12 11:44:00 +0200 (pe, 12 tammi 2018) $ +// Version: $Revision: 9818 $, +// $Date: 2018-01-22 09:05:42 +0200 (ma, 22 tammi 2018) $ // $Author: gurux01 $ // // Copyright (c) Gurux Ltd @@ -139,6 +139,14 @@ static void Main() { try { + //Update previous installed settings. + if (Properties.Settings.Default.UpdateSettings) + { + Properties.Settings.Default.Upgrade(); + Properties.Settings.Default.UpdateSettings = false; + Properties.Settings.Default.Save(); + } + Assembly asm = Assembly.GetExecutingAssembly(); string updates = Path.Combine(Path.GetDirectoryName(asm.Location), "Updates"); string medias = Path.Combine(Path.GetDirectoryName(asm.Location), "Medias"); diff --git a/Development/Properties/Settings.Designer.cs b/Development/Properties/Settings.Designer.cs index 16e6940..58a4e18 100644 --- a/Development/Properties/Settings.Designer.cs +++ b/Development/Properties/Settings.Designer.cs @@ -202,5 +202,17 @@ internal sealed partial class Settings : global::System.Configuration.Applicatio this["NotificationType"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("1")] + public int Log { + get { + return ((int)(this["Log"])); + } + set { + this["Log"] = value; + } + } } } diff --git a/Development/Properties/Settings.settings b/Development/Properties/Settings.settings index 7111ed7..87a5f6c 100644 --- a/Development/Properties/Settings.settings +++ b/Development/Properties/Settings.settings @@ -47,5 +47,8 @@ 0 + + 1 + \ No newline at end of file diff --git a/Development/Resources/search.bmp b/Development/Resources/search.bmp new file mode 100644 index 0000000..90551df Binary files /dev/null and b/Development/Resources/search.bmp differ diff --git a/Development/app.config b/Development/app.config index e1a4bb1..9d75924 100644 --- a/Development/app.config +++ b/Development/app.config @@ -52,6 +52,9 @@ 0 + + 1 + diff --git a/Development/packages.config b/Development/packages.config index dbc741b..8a6ba07 100644 --- a/Development/packages.config +++ b/Development/packages.config @@ -2,7 +2,7 @@ - +