Skip to content

Commit

Permalink
Improve diagnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
arkypita committed Sep 7, 2023
1 parent 0abfc91 commit 202a38e
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 23 deletions.
2 changes: 1 addition & 1 deletion LaserGRBL/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
21 changes: 19 additions & 2 deletions LaserGRBL/Core/GrblCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down Expand Up @@ -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("$$");

Expand Down Expand Up @@ -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)
Expand All @@ -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);
}
}


Expand Down
2 changes: 1 addition & 1 deletion LaserGRBL/Core/MarlinCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected override void ParseMachineStatus(string data)
SetStatus(var);
}

public override void RefreshConfig()
public override void RefreshConfig(RefreshCause cause)
{

}
Expand Down
21 changes: 13 additions & 8 deletions LaserGRBL/GrblConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<GrblConfST.GrblConfParam> changes = GetChanges(); //get changes

if (changes.Count > 0)
Expand Down Expand Up @@ -139,7 +144,7 @@ private bool WriteConf(List<GrblConfST.GrblConfParam> 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 { }
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down
23 changes: 18 additions & 5 deletions LaserGRBL/Logger/ComLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,45 @@ 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
{
if (filename != null)
{
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;
Expand Down
12 changes: 8 additions & 4 deletions LaserGRBL/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}

Expand Down
7 changes: 6 additions & 1 deletion LaserGRBL/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

}
Expand Down
2 changes: 1 addition & 1 deletion setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 202a38e

Please sign in to comment.