Skip to content

Commit

Permalink
Add diagnostic driver information in logfile
Browse files Browse the repository at this point in the history
  • Loading branch information
arkypita committed Dec 6, 2024
1 parent e735b93 commit 855a17c
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion LaserGRBL/Core/GrblCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class GrblCore
public static string GCODE_STD_PASSES = ";(Uncomment if you want to sink Z axis)\r\n;G91 (use relative coordinates)\r\n;G0 Z-1 (sinks the Z axis, 1mm)\r\n;G90 (use absolute coordinates)";
public static string GCODE_STD_FOOTER = "G0 X0 Y0 Z0 (move back to origin)";

private static string CH340Version;

[Serializable]
public class ThreadingMode
{
Expand Down Expand Up @@ -336,6 +338,11 @@ public int OrturFWVersionNumber
public RetainedSetting<float> PreviewLineSize { get; } = new RetainedSetting<float>("PreviewLineSize", 1f);
public RetainedSetting<bool> AutoSizeOnDrawing { get; } = new RetainedSetting<bool>("AutoSizeOnDrawing", true);

static GrblCore() //static constructor for static initialization
{
System.Threading.ThreadPool.QueueUserWorkItem(GetCH340Version);
}

public GrblCore(System.Windows.Forms.Control syncroObject, PreviewForm cbform, JogForm jogform)
{
if (Type != Firmware.Grbl) Logger.LogMessage("Program", "Load {0} core", Type);
Expand Down Expand Up @@ -387,6 +394,33 @@ public GrblCore(System.Windows.Forms.Control syncroObject, PreviewForm cbform, J
CSVD.LoadAppropriateCSV(GrblVersion); //load setting for last known version
}

public static void GetCH340Version(Object stateInfo)
{
try
{
System.Management.ManagementObjectSearcher objSearcher = new System.Management.ManagementObjectSearcher("SELECT * FROM Win32_PnPSignedDriver WHERE DeviceName LIKE '%CH340%' OR Manufacturer LIKE '%wch.cn%'");

System.Management.ManagementObjectCollection objCollection = objSearcher.Get();

foreach (System.Management.ManagementObject obj in objCollection)
{
try
{
if (obj["DeviceName"].ToString().ToLower().Contains("ch340") || obj["Manufacturer"].ToString().ToLower().Contains("wch.cn"))
{
string date = obj["DriverDate"] as string;
if (date != null && date.Length >= 8) date = date.Substring(0, 8);

CH340Version = String.Format("Device='{0}' Manufacturer='{1}' Version='{2}' Date='{3}'", obj["DeviceName"], obj["Manufacturer"], obj["DriverVersion"], date);
break;
}
}
catch { }
}
}
catch { }
}

internal void HotKeyOverride(HotKeysManager.HotKey.Actions action)
{

Expand Down Expand Up @@ -2775,7 +2809,11 @@ private string WaitComLineOrDisconnect()
}
catch (System.IO.IOException ex)
{
FixCH340 = true; //self fix for CH340, use HasIncomingData to check if there is data, this reduce the number of exceptions
if (!FixCH340)
{
FixCH340 = true; //self fix for CH340, use HasIncomingData to check if there is data, this reduce the number of exceptions
Logger.LogMessage("FixCH340", $"Detected CH340 driver issue {CH340Version}");
}
FixCH340_exception++;
if (FixCH340_exception % 10 == 0) System.Threading.Thread.Sleep(1);
}
Expand All @@ -2790,6 +2828,10 @@ private string WaitComLineOrDisconnect()

}





private bool HasIncomingData()
{
try
Expand Down

0 comments on commit 855a17c

Please sign in to comment.