From 202a38ef8442632424ca1c5ef3f6e27866872be9 Mon Sep 17 00:00:00 2001 From: arkypita Date: Thu, 7 Sep 2023 19:58:33 +0200 Subject: [PATCH] Improve diagnostic --- LaserGRBL/AssemblyInfo.cs | 2 +- LaserGRBL/Core/GrblCore.cs | 21 +++++++++++++++++++-- LaserGRBL/Core/MarlinCore.cs | 2 +- LaserGRBL/GrblConfig.cs | 21 +++++++++++++-------- LaserGRBL/Logger/ComLogger.cs | 23 ++++++++++++++++++----- LaserGRBL/MainForm.cs | 12 ++++++++---- LaserGRBL/Program.cs | 7 ++++++- setup.iss | 2 +- 8 files changed, 67 insertions(+), 23 deletions(-) diff --git a/LaserGRBL/AssemblyInfo.cs b/LaserGRBL/AssemblyInfo.cs index 8e9f2b36c..6a309e1b9 100644 --- a/LaserGRBL/AssemblyInfo.cs +++ b/LaserGRBL/AssemblyInfo.cs @@ -31,5 +31,5 @@ // È possibile specificare tutti i valori oppure impostare valori predefiniti per i numeri relativi alla revisione e alla build // utilizzando l'asterisco (*) come descritto di seguito: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion ("5.5.0")] +[assembly: AssemblyVersion ("5.6.0")] [assembly: NeutralResourcesLanguage("en")] diff --git a/LaserGRBL/Core/GrblCore.cs b/LaserGRBL/Core/GrblCore.cs index 140581f30..9b9cce0d6 100644 --- a/LaserGRBL/Core/GrblCore.cs +++ b/LaserGRBL/Core/GrblCore.cs @@ -845,7 +845,10 @@ private void RefreshConfigOnConnect(object state) //da usare per la chiamata asi { System.Threading.Thread.Sleep(500); //allow the machine to send all the startup messages before refreshing config and info - try { RefreshConfig(); } + try + { + RefreshConfig(RefreshCause.OnConnect); + } catch (Exception ex) { Logger.LogMessage("Refresh Config", ex.Message); } try { RefreshMachineInfo(); } @@ -953,12 +956,15 @@ private void ManageVerMessage(string rline) } } - public virtual void RefreshConfig() + public enum RefreshCause { OnConnect, OnDialog, OnRead, OnExport, OnImport, OnWriteBegin, OnWriteEnd } + public virtual void RefreshConfig(RefreshCause cause) { if (CanReadWriteConfig) { try { + Logger.LogMessage("Refresh Config", "Refreshing grbl configuration [{0}]", cause); + GrblConfST conf = new GrblConfST(GrblVersion); GrblCommand cmd = new GrblCommand("$$"); @@ -1007,8 +1013,15 @@ public virtual void RefreshConfig() if (conf.Count < conf.ExpectedCount) //log but do not show error if some param is missing Logger.LogMessage("Refresh Config", "Wrong number of config param found! (Expected: {0} Found: {1})", conf.Count, conf.ExpectedCount); + else + Logger.LogMessage("Refresh Config", "Configuration successfully received! (Expected: {0} Found: {1})", conf.Count, conf.ExpectedCount); } } + catch (Exception ex) + { + Logger.LogException("Refresh Config", ex); + throw ex; + } finally { lock (this) @@ -1018,6 +1031,10 @@ public virtual void RefreshConfig() } } } + else + { + Logger.LogMessage("Refresh Config", "Cannot refresh config now [{0}] [Connected:{1} Program:{2} Status:{3}]", cause, IsConnected, InProgram, MachineStatus); + } } diff --git a/LaserGRBL/Core/MarlinCore.cs b/LaserGRBL/Core/MarlinCore.cs index fbc6d6edf..68a977c8b 100644 --- a/LaserGRBL/Core/MarlinCore.cs +++ b/LaserGRBL/Core/MarlinCore.cs @@ -63,7 +63,7 @@ protected override void ParseMachineStatus(string data) SetStatus(var); } - public override void RefreshConfig() + public override void RefreshConfig(RefreshCause cause) { } diff --git a/LaserGRBL/GrblConfig.cs b/LaserGRBL/GrblConfig.cs index f2dcd3d0d..f405bf655 100644 --- a/LaserGRBL/GrblConfig.cs +++ b/LaserGRBL/GrblConfig.cs @@ -79,31 +79,36 @@ private void BtnCancel_Click(object sender, EventArgs e) } private void BtnRead_Click(object sender, EventArgs e) + { + DoRead(GrblCore.RefreshCause.OnRead); + + } + + private void DoRead(GrblCore.RefreshCause cause) { try { Cursor = Cursors.WaitCursor; - Core.RefreshConfig(); + Core.RefreshConfig(cause); mLocalCopy = GrblCore.Configuration.ToList(); DGV.DataSource = mLocalCopy; RefreshEnabledButtons(); Cursor = DefaultCursor; - ActionResult( String.Format(Strings.BoxReadConfigSuccess, mLocalCopy.Count)); + ActionResult(String.Format(Strings.BoxReadConfigSuccess, mLocalCopy.Count)); } catch (Exception ex) { Cursor = DefaultCursor; ActionResult($"{Strings.BoxReadConfigError} {ex.Message}"); } - } private void BtnWrite_Click(object sender, EventArgs e) { try { - Core.RefreshConfig(); + Core.RefreshConfig(GrblCore.RefreshCause.OnWriteBegin); List changes = GetChanges(); //get changes if (changes.Count > 0) @@ -139,7 +144,7 @@ private bool WriteConf(List conf, bool import) } finally { - try { Core.RefreshConfig(); } //ensure to have the last conf at least in core + try { Core.RefreshConfig(GrblCore.RefreshCause.OnWriteEnd); } //ensure to have the last conf at least in core catch { } } @@ -173,7 +178,7 @@ private void BtnExport_Click(object sender, EventArgs e) if (filename != null) { - try { Core.RefreshConfig(); } //internally skipped if not possible + try { Core.RefreshConfig(GrblCore.RefreshCause.OnExport); } //internally skipped if not possible catch { } try @@ -257,7 +262,7 @@ private void BtnImport_Click(object sender, EventArgs e) WriteConf(conf, true); //refresh actual conf - Core.RefreshConfig(); + Core.RefreshConfig(GrblCore.RefreshCause.OnImport); mLocalCopy = GrblCore.Configuration.ToList(); DGV.DataSource = mLocalCopy; } @@ -334,7 +339,7 @@ public bool HasChanges() private void GrblConfig_Load(object sender, EventArgs e) { if (BtnRead.Enabled) - BtnRead.PerformClick(); + DoRead(GrblCore.RefreshCause.OnDialog); else ActionResult(Strings.BoxReadConfigPleaseConnect); } diff --git a/LaserGRBL/Logger/ComLogger.cs b/LaserGRBL/Logger/ComLogger.cs index 607260863..8fea39a11 100644 --- a/LaserGRBL/Logger/ComLogger.cs +++ b/LaserGRBL/Logger/ComLogger.cs @@ -16,8 +16,9 @@ public static class ComLogger private static string lockstr = "--- TX RX LOG LOCK ---"; private static AsyncLogFile file; private static int logcnt = 0; + private static string logid = null; - public static void StartLog(string filename) + public static string StartLog(string filename) { try { @@ -25,23 +26,35 @@ public static void StartLog(string filename) { StopLog(); file = new AsyncLogFile(filename, 0); - Log("log", $"Recording session started @ {DateTime.Now}"); + + logid = Guid.NewGuid().ToString().Split('-')[0]; + string message = String.Format("Recording session started @ {0:dd/MM/yyyy HH:mm:ss.fff} - Session ID [{1}]", DateTime.Now, logid); + Log("log", message); + + return message; } } catch { } + + return "Cannot start recording session!"; } - public static void StopLog() + public static string StopLog() { try { if (Enabled) { - Log("log", $"Recording session stopped @ {DateTime.Now}"); + string message = String.Format("Recording session stopped @ {0:dd/MM/yyyy HH:mm:ss.fff} - Session ID [{1}]", DateTime.Now, logid); + Log("log", message); file.Stop(); + + return message; } } - finally { file = null; logcnt = 0; } + finally { file = null; logcnt = 0; logid = null; } + + return null; } public static bool Enabled => file != null; diff --git a/LaserGRBL/MainForm.cs b/LaserGRBL/MainForm.cs index 88b776e0e..7b87ad1ef 100644 --- a/LaserGRBL/MainForm.cs +++ b/LaserGRBL/MainForm.cs @@ -639,7 +639,7 @@ private void slovakToolStripMenuItem_Click(object sender, EventArgs e) private void MNGrblEmulator_Click(object sender, EventArgs e) { - LaserGRBL.GrblEmulator.WebSocketEmulator.Start(); + GrblEmulator.WebSocketEmulator.Start(); } private void blueLaserToolStripMenuItem_Click(object sender, EventArgs e) @@ -794,7 +794,7 @@ private void activateExtendedLogToolStripMenuItem_Click(object sender, EventArgs sfd.FileName = "comlog.txt"; sfd.Title = "Select extended log filename"; - System.Windows.Forms.DialogResult dialogResult = System.Windows.Forms.DialogResult.Cancel; + DialogResult dialogResult = DialogResult.Cancel; try { dialogResult = sfd.ShowDialog(this); @@ -806,12 +806,16 @@ private void activateExtendedLogToolStripMenuItem_Click(object sender, EventArgs } if (dialogResult == DialogResult.OK && sfd.FileName != null) - ComWrapper.ComLogger.StartLog(sfd.FileName); + { + string message = ComWrapper.ComLogger.StartLog(sfd.FileName); + Logger.LogMessage("ComLog", message); + } } } else { - ComWrapper.ComLogger.StopLog(); + string message = ComWrapper.ComLogger.StopLog(); + if (message != null) Logger.LogMessage("ComLog", message); } } diff --git a/LaserGRBL/Program.cs b/LaserGRBL/Program.cs index b770edb6c..837369024 100644 --- a/LaserGRBL/Program.cs +++ b/LaserGRBL/Program.cs @@ -45,7 +45,12 @@ static void Main(string[] args) GrblEmulator.WebSocketEmulator.Stop(); Autotrace.CleanupTmpFolder(); - ComWrapper.ComLogger.StopLog(); + if (ComWrapper.ComLogger.Enabled) + { + string message = ComWrapper.ComLogger.StopLog(); + if (message != null) Logger.LogMessage("ComLog", message); + } + Logger.Stop(); } diff --git a/setup.iss b/setup.iss index 13ab12b96..a38d6ae0a 100644 --- a/setup.iss +++ b/setup.iss @@ -2,7 +2,7 @@ ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! #define MyAppName "LaserGRBL" -#define MyAppVersion "5.5.0" +#define MyAppVersion "5.6.0" #define MyAppVersionName "Rhydon" #define MyAppPublisher "LaserGRBL" #define MyAppURL "https://lasergrbl.com"