From 855a17c46edfb8bb9276fb46fdecdab25a26cc8e Mon Sep 17 00:00:00 2001 From: arkypita Date: Fri, 6 Dec 2024 21:36:15 +0100 Subject: [PATCH] Add diagnostic driver information in logfile --- LaserGRBL/Core/GrblCore.cs | 44 +++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/LaserGRBL/Core/GrblCore.cs b/LaserGRBL/Core/GrblCore.cs index 8c82cee1..8a719b21 100644 --- a/LaserGRBL/Core/GrblCore.cs +++ b/LaserGRBL/Core/GrblCore.cs @@ -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 { @@ -336,6 +338,11 @@ public int OrturFWVersionNumber public RetainedSetting PreviewLineSize { get; } = new RetainedSetting("PreviewLineSize", 1f); public RetainedSetting AutoSizeOnDrawing { get; } = new RetainedSetting("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); @@ -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) { @@ -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); } @@ -2790,6 +2828,10 @@ private string WaitComLineOrDisconnect() } + + + + private bool HasIncomingData() { try