From 03a8ab215cad6010a8fc3468c15c158e07fd7e11 Mon Sep 17 00:00:00 2001 From: hehaoyang <1109196436@qq.com> Date: Wed, 25 Oct 2023 11:59:04 +0800 Subject: [PATCH] 1.1.2 Alpha Bulid 20231025 --- .gitignore | 12 ++ PrinterClient/PrinterClient/ReadMe.cs | 4 + PrinterClient/PrinterClient/TaskDispatcher.cs | 116 ++++++++---------- ReadMe.md | 3 + 4 files changed, 71 insertions(+), 64 deletions(-) diff --git a/.gitignore b/.gitignore index e11f4fc..26ab8fc 100644 --- a/.gitignore +++ b/.gitignore @@ -315,3 +315,15 @@ PrinterClient/PrinterClient/._BoxServer.cs PrinterClient/PrinterClient/._Program.cs PrinterClient/PrinterClient/._TaskDispatcher.cs ._printer.sh +其他资料/._gcm +其他资料/._gcm.zip +其他资料/gcm/._gcm.bin +其他资料/gcm/._install.sh +其他资料/gcm/gcm.bin +其他资料/gcm/install.sh +其他资料/install.zip +PrinterClient/.vs/PrinterClient/FileContentIndex/380efad8-1bf7-477a-a2ed-10befb6e69e8.vsidx +PrinterClient/.vs/PrinterClient/FileContentIndex/00734b31-8f07-4a4d-a6cf-df51dca98a72.vsidx +PrinterClient/.vs/PrinterClient/FileContentIndex/5fa9dda6-6f0e-44f6-aece-97d5743e32ec.vsidx +PrinterClient/.vs/PrinterClient/FileContentIndex/2d42fda6-5f3b-4099-a3df-2a7bea5a8424.vsidx +PrinterClient/.vs/PrinterClient/FileContentIndex/8b95cfed-56f9-4e94-abb0-9e49f4e05051.vsidx diff --git a/PrinterClient/PrinterClient/ReadMe.cs b/PrinterClient/PrinterClient/ReadMe.cs index a1f0686..6fb9479 100644 --- a/PrinterClient/PrinterClient/ReadMe.cs +++ b/PrinterClient/PrinterClient/ReadMe.cs @@ -16,6 +16,10 @@ static class ReadMe static readonly Dictionary> Versions = new() { + ["1.1.2 Alpha Bulid 20231025"] = new List() + { + "优化 Windows 模式下代码", + }, ["1.1.1 Alpha Bulid 20231019"] = new List() { "修复: 无法检测到\"打印中\"状态的BUG", diff --git a/PrinterClient/PrinterClient/TaskDispatcher.cs b/PrinterClient/PrinterClient/TaskDispatcher.cs index 2d5b853..30f9078 100644 --- a/PrinterClient/PrinterClient/TaskDispatcher.cs +++ b/PrinterClient/PrinterClient/TaskDispatcher.cs @@ -145,6 +145,8 @@ namespace PrinterClient { var value = GetStatus(); + Console.WriteLine($"{value:X4}"); + switch (value) { case PrinterStatus.Normal: @@ -163,44 +165,56 @@ namespace PrinterClient public static string Serial = ""; private static void FindSerial() - { - /* 获取打印机信息 */ - if (TaskDispatcher.ExecuteCommand("lpinfo", "-v", out string result)) - { - if (result.IndexOf("gutenprint52+usb://Dai+Nippon+Printing/Photo+Printer?serial=") == -1) - { - return; - } - - var arrays = result.Split(new char[] { '\r', '\n' }); - - var directs = arrays.ToList().FindAll(ar => ar.IndexOf("gutenprint52+usb://Dai+Nippon+Printing/Photo+Printer?serial=") != -1); - - string code = ""; - - foreach (var direct in directs) - { - int a = direct.LastIndexOf("serial="), b = direct.LastIndexOf("&backend"); - - if (a == -1 || b == -1) - continue; - - code = direct.Substring(a + 7, b - a - 7); - - if (code.IndexOf("NONE_UNKNOWN") != -1) - continue; - - break; - } - - if (code.Equals("NONE_UNKNOWN")) - Serial = ""; - else - Serial = code; - } - } - - private static PrinterStatus GetStatus() + { + string code = ""; + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + var res = CyStatus.GetSerialNo(rx1_handle, ref code); + + if (res == int.MinValue) + return; + + Serial = code; + } + else + { + /* 获取打印机信息 */ + if (TaskDispatcher.ExecuteCommand("lpinfo", "-v", out string result)) + { + if (result.IndexOf("gutenprint52+usb://Dai+Nippon+Printing/Photo+Printer?serial=") == -1) + { + return; + } + + var arrays = result.Split(new char[] { '\r', '\n' }); + + var directs = arrays.ToList().FindAll(ar => ar.IndexOf("gutenprint52+usb://Dai+Nippon+Printing/Photo+Printer?serial=") != -1); + + foreach (var direct in directs) + { + int a = direct.LastIndexOf("serial="), b = direct.LastIndexOf("&backend"); + + if (a == -1 || b == -1) + continue; + + code = direct.Substring(a + 7, b - a - 7); + + if (code.IndexOf("NONE_UNKNOWN") != -1) + continue; + + break; + } + + if (code.Equals("NONE_UNKNOWN")) + Serial = ""; + else + Serial = code; + } + } + } + + private static PrinterStatus GetStatus() { PrinterStatus status = PrinterStatus.Normal; @@ -376,10 +390,6 @@ namespace PrinterClient } else { - //TaskDispatcher.AsyncExecuteCommand("lpr", file); - - //TaskDispatcher.ExecuteCommand("PrintPhoto", $"DS-RX1HS {file}", out string result); - string file_format = "TextGraphics", print_mode = "RGB", print_size = "B7"; switch (file_format_id) @@ -444,28 +454,6 @@ namespace PrinterClient return false; } - - public static void SetProperty(string name, string value) => TaskDispatcher.AsyncExecuteCommand("lpoptions", $"-o {name}={value}"); - - public static bool GetProperty(string name, out string value) - { - value = string.Empty; - - try - { - if (TaskDispatcher.ExecuteCommand("lpoptions", $"-l", out string result)) - { - result = result.Split(new char[] { '\n', '\r' }).ToList().Find(s => s.IndexOf(name) != -1); - - value = result.Split(' ').ToList().Find(s => s[0] == '*').Remove(0, 1); - - return true; - } - } - catch { } - - return false; - } } public class LprEntries diff --git a/ReadMe.md b/ReadMe.md index 4111c85..a9ad18d 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -1,5 +1,8 @@ # PrinterClient 版本历史介绍 +## 1.1.2 Alpha Bulid 20231025 +* 优化 Windows 模式下代码 + ## 1.1.1 Alpha Bulid 20231019 * 修复: 无法检测到"打印中"状态的BUG * 修复: 下载延时大的BUG