From 225ca2393216ba6052e6c0041a17ea966b8d3c78 Mon Sep 17 00:00:00 2001 From: tylhk <498435443@QQ.COM> Date: Mon, 26 May 2025 17:21:18 +0800 Subject: [PATCH 01/13] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8E=A5=E6=94=B6?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=97=B6=E9=97=B4=E6=88=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WPFSerialAssistant/App.config | 2 +- WPFSerialAssistant/Core.cs | 9 --------- WPFSerialAssistant/EventHandler.cs | 10 ++++++++-- WPFSerialAssistant/MainWindow.xaml | 10 +++------- WPFSerialAssistant/Properties/Resources.Designer.cs | 6 +++--- WPFSerialAssistant/Properties/Settings.Designer.cs | 2 +- WPFSerialAssistant/WPFSerialAssistant.csproj | 2 +- 7 files changed, 17 insertions(+), 24 deletions(-) diff --git a/WPFSerialAssistant/App.config b/WPFSerialAssistant/App.config index e707b32..92c094c 100644 --- a/WPFSerialAssistant/App.config +++ b/WPFSerialAssistant/App.config @@ -2,5 +2,5 @@ - + diff --git a/WPFSerialAssistant/Core.cs b/WPFSerialAssistant/Core.cs index 144a47c..f61d915 100644 --- a/WPFSerialAssistant/Core.cs +++ b/WPFSerialAssistant/Core.cs @@ -78,15 +78,6 @@ private void Information(string message) #endregion - private void RecvDataBoxAppend(string textData) - { - if (showRecvDataCheckBox.IsChecked == true) - { - this.recvDataRichTextBox.AppendText(textData); - this.recvDataRichTextBox.ScrollToEnd(); - } - } - private bool SendData() { string textToSend = sendDataTextBox.Text; diff --git a/WPFSerialAssistant/EventHandler.cs b/WPFSerialAssistant/EventHandler.cs index eac33fb..b2a2398 100644 --- a/WPFSerialAssistant/EventHandler.cs +++ b/WPFSerialAssistant/EventHandler.cs @@ -491,6 +491,7 @@ private void CheckTimer_Tick(object sender, EventArgs e) private void ReceivedDataHandler(object obj) { + List recvBuffer = new List(); recvBuffer.AddRange((List)obj); @@ -506,8 +507,13 @@ private void ReceivedDataHandler(object obj) { if (showReceiveData) { - // 根据显示模式显示接收到的字节. - recvDataRichTextBox.AppendText(Utilities.BytesToText(recvBuffer, receiveMode, serialPort.Encoding)); + string timestamp = DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss] "); + // 转换数据为文本 + string dataText = Utilities.BytesToText(recvBuffer, receiveMode, serialPort.Encoding); + // 拼接时间戳和数据 + string displayText = timestamp + dataText; + + recvDataRichTextBox.AppendText(displayText); recvDataRichTextBox.ScrollToEnd(); } diff --git a/WPFSerialAssistant/MainWindow.xaml b/WPFSerialAssistant/MainWindow.xaml index 980454d..338e5c3 100644 --- a/WPFSerialAssistant/MainWindow.xaml +++ b/WPFSerialAssistant/MainWindow.xaml @@ -41,7 +41,7 @@ - 欢迎使用串口助手! + 欢迎使用 @@ -158,12 +158,8 @@ - - 主要功能: - 1. 可自由显示、隐藏的设置面板 - 2. 简洁视图模式,专注于数据收发 - 3. 软件主要配置可保存并恢复 - 快捷键提示: + + 快捷键: 1. Ctrl+S: 保存接收区数据 2. Ctrl+Enter: 进/退简洁视图模式 3. Enter: 发送数据 diff --git a/WPFSerialAssistant/Properties/Resources.Designer.cs b/WPFSerialAssistant/Properties/Resources.Designer.cs index e467f8a..54b661e 100644 --- a/WPFSerialAssistant/Properties/Resources.Designer.cs +++ b/WPFSerialAssistant/Properties/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace WPFSerialAssistant.Properties { // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen // (以 /str 作为命令选项),或重新生成 VS 项目。 - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { @@ -47,8 +47,8 @@ internal Resources() { } /// - /// 使用此强类型资源类,为所有资源查找 - /// 重写当前线程的 CurrentUICulture 属性。 + /// 重写当前线程的 CurrentUICulture 属性,对 + /// 使用此强类型资源类的所有资源查找执行重写。 /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Globalization.CultureInfo Culture { diff --git a/WPFSerialAssistant/Properties/Settings.Designer.cs b/WPFSerialAssistant/Properties/Settings.Designer.cs index 9243b31..f53e224 100644 --- a/WPFSerialAssistant/Properties/Settings.Designer.cs +++ b/WPFSerialAssistant/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace WPFSerialAssistant.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.14.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/WPFSerialAssistant/WPFSerialAssistant.csproj b/WPFSerialAssistant/WPFSerialAssistant.csproj index dc4cb92..4e1918e 100644 --- a/WPFSerialAssistant/WPFSerialAssistant.csproj +++ b/WPFSerialAssistant/WPFSerialAssistant.csproj @@ -9,7 +9,7 @@ Properties WPFSerialAssistant WPFSerialAssistant - v4.5 + v4.8 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 From 67e31608073f2b4164b07a1530b8b8c08835ea52 Mon Sep 17 00:00:00 2001 From: tylhk <498435443@QQ.COM> Date: Mon, 26 May 2025 17:46:42 +0800 Subject: [PATCH 02/13] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=B8=B8=E7=94=A8?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E9=9D=A2=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WPFSerialAssistant/CommandItem.cs | 11 ++ WPFSerialAssistant/InputDialog.xaml | 14 +++ WPFSerialAssistant/InputDialog.xaml.cs | 37 +++++++ WPFSerialAssistant/MainWindow.xaml | 23 ++++- WPFSerialAssistant/MainWindow.xaml.cs | 101 ++++++++++++++++++- WPFSerialAssistant/WPFSerialAssistant.csproj | 13 ++- WPFSerialAssistant/packages.config | 4 + 7 files changed, 199 insertions(+), 4 deletions(-) create mode 100644 WPFSerialAssistant/CommandItem.cs create mode 100644 WPFSerialAssistant/InputDialog.xaml create mode 100644 WPFSerialAssistant/InputDialog.xaml.cs create mode 100644 WPFSerialAssistant/packages.config diff --git a/WPFSerialAssistant/CommandItem.cs b/WPFSerialAssistant/CommandItem.cs new file mode 100644 index 0000000..e04cb80 --- /dev/null +++ b/WPFSerialAssistant/CommandItem.cs @@ -0,0 +1,11 @@ +using System; + +namespace WPFSerialAssistant +{ + [Serializable] // 关键序列化标记 + public class CommandItem + { + public string Name { get; set; } + public string Value { get; set; } + } +} \ No newline at end of file diff --git a/WPFSerialAssistant/InputDialog.xaml b/WPFSerialAssistant/InputDialog.xaml new file mode 100644 index 0000000..f35adc3 --- /dev/null +++ b/WPFSerialAssistant/InputDialog.xaml @@ -0,0 +1,14 @@ + + + + + + + diff --git a/WPFSerialAssistant/MainWindow.xaml.cs b/WPFSerialAssistant/MainWindow.xaml.cs index c40d1dd..9e5aa80 100644 --- a/WPFSerialAssistant/MainWindow.xaml.cs +++ b/WPFSerialAssistant/MainWindow.xaml.cs @@ -124,5 +124,55 @@ private void RemoveCommand_Click(object sender, RoutedEventArgs e) SaveCommands(); } } + // 字号控制参数 + private const double DefaultFontSize = 14; // 默认字号(与XAML中FlowDocument设置一致) + private const double MinFontSize = 8; // 最小字号 + private const double MaxFontSize = 36; // 最大字号 + private const double FontStep = 2; // 字号调整步长 + + // 放大字号 + private void IncreaseFontSize_Click(object sender, RoutedEventArgs e) + { + if (recvDataRichTextBox.FontSize + FontStep <= MaxFontSize) + { + recvDataRichTextBox.FontSize += FontStep; + UpdateDocumentFontSize(recvDataRichTextBox.Document, recvDataRichTextBox.FontSize); + } + } + + // 缩小字号 + private void DecreaseFontSize_Click(object sender, RoutedEventArgs e) + { + if (recvDataRichTextBox.FontSize - FontStep >= MinFontSize) + { + recvDataRichTextBox.FontSize -= FontStep; + UpdateDocumentFontSize(recvDataRichTextBox.Document, recvDataRichTextBox.FontSize); + } + } + + // 重置字号 + private void ResetFontSize_Click(object sender, RoutedEventArgs e) + { + recvDataRichTextBox.FontSize = DefaultFontSize; + UpdateDocumentFontSize(recvDataRichTextBox.Document, DefaultFontSize); + } + + // 更新文档内所有文字字号(兼容已有内容) + private void UpdateDocumentFontSize(FlowDocument document, double newSize) + { + foreach (var block in document.Blocks) + { + if (block is Paragraph paragraph) + { + foreach (var inline in paragraph.Inlines) + { + if (inline is Run run) + { + run.FontSize = newSize; + } + } + } + } + } } } From 124366fb32aa0734c2e3533f5b084821a74c92b0 Mon Sep 17 00:00:00 2001 From: tylhk <498435443@QQ.COM> Date: Mon, 26 May 2025 18:37:13 +0800 Subject: [PATCH 04/13] Update README.md --- README.md | 128 ++++++++---------------------------------------------- 1 file changed, 18 insertions(+), 110 deletions(-) diff --git a/README.md b/README.md index 2f571b8..ea2f49e 100644 --- a/README.md +++ b/README.md @@ -1,127 +1,35 @@ -# WPFSerialAssitan +# WPFSerialAssistant + ------------------ ## + **һC#WPFĴֲ㣬UIࡣʵ˻ĴͨѶҪĹܣ߿ԻڴԶĹܡ⣬Իڴ˿һЩ򵥵Ĵڿ** ## Ŀҳ -* [WPFԴĴڵ(https://github.com/ChrisLeeGit/SerialAssistant)](https://github.com/ChrisLeeGit/SerialAssistant) - - -## -* ݽգԲöģʽʾյݣַʮƵ -* ݷֶͣ/Զ -* 洮ڽյʾ -* / -* ġͼģʽ ûרעݵĽպͷ - -## ʹð -**Ƚϼ򵥣Ľܡ** - - -## ͼƬ -### ʼͼ -![ʼͼ](https://raw.githubusercontent.com/ChrisLeeGit/SerialAssistant/master/DebugPics/1.PNG) - -### 򿪶˿ڲ -![򿪶˿ڲ](https://raw.githubusercontent.com/ChrisLeeGit/SerialAssistant/master/DebugPics/2.PNG) - -### ص -![ص1](https://raw.githubusercontent.com/ChrisLeeGit/SerialAssistant/master/DebugPics/3.PNG) -![ص2](https://raw.githubusercontent.com/ChrisLeeGit/SerialAssistant/master/DebugPics/4.PNG) - -### ޸ŵͼ -![޸ŵͼ](https://raw.githubusercontent.com/ChrisLeeGit/SerialAssistant/master/DebugPics/5.PNG) - -## ʹõĿԴ -* ʹõһԴJson.Net⣬ԷdzʹJsonʽ洢Ϣ߼JsonʽļҳΪhttp://www.newtonsoft.com/json -## ɿ -һVisual Studio 2015ֱ̣Cloneɡ +- Github[WPFԴĴڵ](https://github.com/tylhk/SerialAssistant) +- Blog[WPFSerialAssistant ](https://satone1008.cn/wp-admin/post.php?post=412&action=edit) -## ؿԴĿ -ͬʱһArduino̫ԶˮϵͳȻϵͳûʵʹϣƵĹܻʵˡĿڱȽۺϵˡʹ˴ͨŵķʽPC˵ĿͨšPCڿԸƬԶĿָִСԣ漰ͨõԶЭƣArduinoָϵͳƺʵ֡ȤĻҲͬԹעͬѧϰллĿйַܵ +## ԭĿҳ -1. Githubַhttps://github.com/ChrisLeeGit/AutomaticWaterSupplySystem -2. CSDN Codeַhttps://code.csdn.net/u011193957/automaticwatersupplysystem +* [WPFԴĴڵ](https://github.com/ChrisLeeGit/SerialAssistant) -# ־ -## 2016124 Version 1.3 -### -* ֱֶ֧뷽ʽշ -* ַ֧׷ݣ绻(\n)ȣμ->׷ӡ˵ -* Ϣı͸ԭ -* ״̬ݽ״ָ̬ʾ - -### Bug޸ -* ޸ ״̬ʾ⣺Զʱ״̬ʾ -* ޸ ߰ʱַת쳣 - -### -* һ汾ͻзʱҪֶASCII룬˲ -* ȶԽһ - -## 2016121 Version 1.2 -### -* յĴݿѡʹijַʽʾ`ַ````˽``ʮ``ʮ`ʽ -* ڷͿѡ`ַ``ʮ`ģʽ -* ˿ɹIJ֣Ӧڳߴ磬˴ڱ仯 -* ݴʱһݴյݣһֵ󣬻ݴ߳ں̨ͷݣ̣߳˳ȶԺͿɿ - -### Bug޸ -* ޸ ijЩΪݻûеֵָٳٵò -* ޸ ֽʾ -* ޸ ݽȶ - -## -* ηʹתַıݣ - * ѡѡͷʽΪ`ַ`ģʽȻڷͿҪ͵ı`Hello world!` - * ȻѡͷʽΪ`ʮ`ģʽȻı׷Ҫ͵תַASCII룬绻з`0A` - * ٴл`ַ`ģʽʱٽзʱὫзһˡ - -* Է֣ʹͼΪ1msڲ˶߳ģʽʾûпٵ - - -## 2015920 Version 1.1 -### -* Զҿö˿ںŹ -* ݵָ洢· -* ˳ǰԶرѿĶ˿ںţѯǷ񱣴ù -* ݱݹ(Ctrl+S) -* ݽ/˳ͼģʽܣCtrl+Enter) -* ָͨ˵˳ͼģʽ - -### Bug޸ -* ޸ ûлָñϴιرյλ -* ޸ ˳˵Ч -* ޸ ijر£Ӽͼģʽָʱֱ - -### -* Ƴ˵棨Sò˵бݰťظ -* ӡڡ -* 汾Version 1.1 +## +* ݽգԲöģʽʾյݣַʮƵ -## 2015915 ܶ Version 1.0 -### -* Ϣ湦ܣĿǰϢУ - * - * żУλ - * λ - * ֹͣλ - * ֽڱ - * ı - * Զʱ - * ״̬|߶+ - * ʾ״̬ +* ݷֶͣ/Զ -* ԶϢ +* 洮ڽյʾ -### Bug޸ -* ʾϢ״̬Ӧ˵ʾһµ +* / -### -* Ƴ˵(L)ΪԶò -* Ƴ˵ģʽֶȫغԶ롰ģʽʱȥһ롰ģʽܲ˵ +* ġͼģʽ ûרעݵĽպͷ +## ־ +### 2025/5/26 +- ӽʱ +- ӳ +- ֺŵ From b6bda6197da450a4efb10051b1b7df03353d819c Mon Sep 17 00:00:00 2001 From: tylhk <498435443@QQ.COM> Date: Tue, 27 May 2025 11:31:34 +0800 Subject: [PATCH 05/13] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AD=97=E5=8F=B7?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WPFSerialAssistant/MainWindow.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WPFSerialAssistant/MainWindow.xaml.cs b/WPFSerialAssistant/MainWindow.xaml.cs index 9e5aa80..cb3efef 100644 --- a/WPFSerialAssistant/MainWindow.xaml.cs +++ b/WPFSerialAssistant/MainWindow.xaml.cs @@ -128,7 +128,7 @@ private void RemoveCommand_Click(object sender, RoutedEventArgs e) private const double DefaultFontSize = 14; // 默认字号(与XAML中FlowDocument设置一致) private const double MinFontSize = 8; // 最小字号 private const double MaxFontSize = 36; // 最大字号 - private const double FontStep = 2; // 字号调整步长 + private const double FontStep = 1; // 字号调整步长 // 放大字号 private void IncreaseFontSize_Click(object sender, RoutedEventArgs e) From fee528dc24f694bfb007de89295c4d99ccd46a79 Mon Sep 17 00:00:00 2001 From: tylhk <498435443@QQ.COM> Date: Tue, 27 May 2025 11:35:26 +0800 Subject: [PATCH 06/13] =?UTF-8?q?=E9=80=9A=E8=BF=87=E7=BC=93=E5=86=B2?= =?UTF-8?q?=E5=8C=BA=E6=AD=A3=E7=A1=AE=E8=BE=93=E5=87=BA=E6=8E=A5=E6=94=B6?= =?UTF-8?q?=E5=8C=BA=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WPFSerialAssistant/Core.cs | 23 ++++++++++++++++-- WPFSerialAssistant/EventHandler.cs | 34 +++++++++++---------------- WPFSerialAssistant/MainWindow.xaml.cs | 5 ++++ 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/WPFSerialAssistant/Core.cs b/WPFSerialAssistant/Core.cs index f61d915..41881ba 100644 --- a/WPFSerialAssistant/Core.cs +++ b/WPFSerialAssistant/Core.cs @@ -22,11 +22,30 @@ private void InitCore() InitClockTimer(); InitAutoSendDataTimer(); InitSerialPort(); - + // 新增:初始化批量处理定时器(间隔设为100ms) + _batchTimer.Interval = TimeSpan.FromMilliseconds(100); + _batchTimer.Tick += BatchTimer_Tick; + _batchTimer.IsEnabled = true; // 查找可以使用的端口号 FindPorts(); } - + private void BatchTimer_Tick(object sender, EventArgs e) + { + _batchTimer.Stop(); + lock (_batchLock) + { + if (_batchBuffer.Length > 0) + { + string timestamp = DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss] "); + Dispatcher.Invoke(() => + { + recvDataRichTextBox.AppendText(timestamp + _batchBuffer.ToString() + "\n"); + recvDataRichTextBox.ScrollToEnd(); + }); + _batchBuffer.Clear(); + } + } + } #region 状态栏 /// /// 更新时间信息 diff --git a/WPFSerialAssistant/EventHandler.cs b/WPFSerialAssistant/EventHandler.cs index 61bf9d4..4f8dc32 100644 --- a/WPFSerialAssistant/EventHandler.cs +++ b/WPFSerialAssistant/EventHandler.cs @@ -498,38 +498,32 @@ private void CheckTimer_Tick(object sender, EventArgs e) private void ReceivedDataHandler(object obj) { - List recvBuffer = new List(); recvBuffer.AddRange((List)obj); + shouldClear = true; if (recvBuffer.Count == 0) { return; } - // 必须应当保证全局缓冲区的数据能够被完整地备份出来,这样才能进行进一步的处理。 - shouldClear = true; + // 将字节数据转换为文本 + string dataText = Utilities.BytesToText(recvBuffer, receiveMode, serialPort.Encoding); - this.Dispatcher.Invoke(new Action(() => + // 将数据暂存到批量缓冲区 + lock (_batchLock) { - if (showReceiveData) - { - string timestamp = DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss] "); - // 转换数据为文本 - string dataText = Utilities.BytesToText(recvBuffer, receiveMode, serialPort.Encoding); - // 拼接时间戳和数据 - string displayText = timestamp + dataText; - - recvDataRichTextBox.AppendText(displayText); - recvDataRichTextBox.ScrollToEnd(); - } - - dataRecvStatusBarItem.Visibility = Visibility.Collapsed; - })); + _batchBuffer.Append(dataText); + } - // TO-DO: - // 处理数据,比如解析指令等等 + // 重置批量处理定时器(停止后重新启动) + Dispatcher.Invoke(() => + { + _batchTimer.Stop(); + _batchTimer.Start(); + }); } + #endregion } } diff --git a/WPFSerialAssistant/MainWindow.xaml.cs b/WPFSerialAssistant/MainWindow.xaml.cs index cb3efef..bb6d106 100644 --- a/WPFSerialAssistant/MainWindow.xaml.cs +++ b/WPFSerialAssistant/MainWindow.xaml.cs @@ -14,6 +14,7 @@ using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using System.Windows.Threading; using Path = System.IO.Path; namespace WPFSerialAssistant @@ -23,6 +24,10 @@ namespace WPFSerialAssistant /// public partial class MainWindow : Window { + private StringBuilder _batchBuffer = new StringBuilder(); // 合并短时间内的数据 + private DispatcherTimer _batchTimer = new DispatcherTimer(); // 批量处理定时器 + private readonly object _batchLock = new object(); // 线程锁 + private static readonly string ConfigFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "WPFSerialAssistant"); From 1b8f77581a0e04980cd8a5090e288a163da0f4be Mon Sep 17 00:00:00 2001 From: tylhk <498435443@QQ.COM> Date: Tue, 27 May 2025 11:45:33 +0800 Subject: [PATCH 07/13] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E5=8C=BA=E8=AE=BE=E7=BD=AE=20=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E4=BF=9D=E5=AD=98=E5=AD=97=E5=8F=B7=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 181 +++++++++++++++++--------- WPFSerialAssistant/MainWindow.xaml | 2 +- WPFSerialAssistant/MainWindow.xaml.cs | 2 +- 3 files changed, 120 insertions(+), 65 deletions(-) diff --git a/.gitignore b/.gitignore index 0d6c45d..0c2d0ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,5 @@ -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. - # User-specific files +*.rsuser *.suo *.user *.userosscache @@ -11,18 +9,22 @@ *.userprefs # Build results +[Dd]ebug/ [Dd]ebugPublic/ [Rr]elease/ [Rr]eleases/ x64/ x86/ -build/ bld/ [Bb]in/ [Oo]bj/ -# Visual Studio 2015 cache/options directory -.vs/ +# Visual Studio 2019/2022 cache/options directory +vs/ +vscode/ + +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ # MSTest test Results [Tt]est[Rr]esult*/ @@ -37,18 +39,24 @@ TestResult.xml [Rr]eleasePS/ dlldata.c -# DNX +# .NET Core project.lock.json file project.lock.json -artifacts/ +project.fragment.lock.json +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio *_i.c *_p.c *_i.h *.ilk *.meta *.obj +*.iobj *.pch *.pdb +*.ipdb *.pgc *.pgd *.rsp @@ -56,15 +64,7 @@ artifacts/ *.tlb *.tli *.tlh -*.tmp *.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc # Chutzpah Test files _Chutzpah* @@ -73,14 +73,10 @@ _Chutzpah* ipch/ *.aps *.ncb -*.opensdf -*.sdf -*.cachefile +*.opendb -# Visual Studio profiler +# Visual Studio profiler files *.psess -*.vsp -*.vspx # TFS 2012 Local Workspace $tf/ @@ -91,27 +87,36 @@ $tf/ # ReSharper is a .NET coding add-in _ReSharper*/ *.[Rr]e[Ss]harper -*.DotSettings.user +*.[Rr]e[Ss]harper.user +*.[Rr]e[Ss]harper.Caches/ # JustCode is a .NET coding add-in -.JustCode +JustCode # TeamCity is a build add-in _TeamCity* # DotCover is a Code Coverage Tool -*.dotCover +dotCover + +# AxoCover is a Code Coverage Tool +axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +coverage +coveragexml # NCrunch _NCrunch_* -.*crunch*.local.xml +*crunch*.local.xml +nCrunchTemp_* # MightyMoose -*.mm.* -AutoTest.Net/ +mm.* # Web workbench (sass) -.sass-cache/ +sass-cache/ # Installshield output folder [Ee]xpress/ @@ -130,55 +135,46 @@ DocProject/Help/html publish/ # Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -## TODO: Comment the next line if you want to checkin your -## web deploy settings but do note that will include unencrypted -## passwords -#*.pubxml +*.publish.xml -*.publishproj +# Microsoft Azure Web App publish settings. Comment the next line if you want to checkin your Azure Web App publish settings, but sensitive information contained in these scripts will be unencrypted +PublishScripts/ # NuGet Packages *.nupkg -# The packages folder can be ignored because of Package Restore -**/packages/* -# except build/, which is used as an MSBuild target. -!**/packages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/packages/repositories.config - -# Windows Azure Build Output -csx/ -*.build.csdef - -# Windows Store app package directory +**/[Pp]ackages/* + +# Windows Store app package directories and files AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx # Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!*.[Cc]ache/ +*.cache # Others ClientBin/ -[Ss]tyle[Cc]op.* ~$* *~ *.dbmdl *.dbproj.schemaview +*.jfm *.pfx *.publishsettings -node_modules/ orleans.codegen.cs +# Including strong name files can present a security risk (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + # RIA/Silverlight projects Generated_Code/ -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) +# Backup & report files from converting an old project file to a newer Visual Studio version. Backup files are not needed, because we have git ;-) _UpgradeReport_Files/ Backup*/ UpgradeLog*.XML @@ -196,8 +192,11 @@ UpgradeLog*.htm # Microsoft Fakes FakesAssemblies/ -# Node.js Tools for Visual Studio -.ntvs_analysis.dat +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio (NTVS) +ntvs_analysis.dat # Visual Studio 6 build log *.plg @@ -205,7 +204,63 @@ FakesAssemblies/ # Visual Studio 6 workspace options file *.opt -# LightSwitch generated files -GeneratedArtifacts/ -_Pvt_Extensions/ -ModelManifest.xml +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml + +_Pvt_Extensions + +### OSX ### +DS_Store +AppleDouble +LSOverride + +# Directories potentially created on remote AFP share +AppleDB +AppleDesktop +Network Trash Folder +Temporary Items +apdisk + +### Windows ### +Thumbs.db +ehthumbs.db + +### Linux ### +*~ + +### Node ### +node_modules/ + +### JetBrains Rider ### +idea/ +sln.iml + +### CodeRush ### +cr/ + +### Python Tools for Visual Studio (PTVS) ### +__pycache__/ +*.pyc + +### Cake ### +tools/** +!tools/packages.config + +### Tabs Studio ### +*.tss + +### Telerik's JustMock configuration file ### +*.jmconfig + +### BizTalk build output ### +*.btp.cs +*.btm.cs +*.odx.cs +* \ No newline at end of file diff --git a/WPFSerialAssistant/MainWindow.xaml b/WPFSerialAssistant/MainWindow.xaml index 8871d44..8e7ec56 100644 --- a/WPFSerialAssistant/MainWindow.xaml +++ b/WPFSerialAssistant/MainWindow.xaml @@ -281,7 +281,7 @@ - + diff --git a/WPFSerialAssistant/MainWindow.xaml.cs b/WPFSerialAssistant/MainWindow.xaml.cs index bb6d106..11a92b2 100644 --- a/WPFSerialAssistant/MainWindow.xaml.cs +++ b/WPFSerialAssistant/MainWindow.xaml.cs @@ -130,7 +130,7 @@ private void RemoveCommand_Click(object sender, RoutedEventArgs e) } } // 字号控制参数 - private const double DefaultFontSize = 14; // 默认字号(与XAML中FlowDocument设置一致) + private const double DefaultFontSize = 12; // 默认字号(与XAML中FlowDocument设置一致) private const double MinFontSize = 8; // 最小字号 private const double MaxFontSize = 36; // 最大字号 private const double FontStep = 1; // 字号调整步长 From aac3d1564640b8b7d895263d6ab85a45a2d9ae07 Mon Sep 17 00:00:00 2001 From: tylhk <498435443@QQ.COM> Date: Tue, 27 May 2025 15:28:16 +0800 Subject: [PATCH 08/13] =?UTF-8?q?=E4=B8=BA=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E6=B7=BB=E5=8A=A0=E9=A1=B5=E9=9D=A2=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WPFSerialAssistant/CommandConfig.cs | 16 ++ WPFSerialAssistant/CommandSettingsWindow.xaml | 45 ++++ .../CommandSettingsWindow.xaml.cs | 200 ++++++++++++++++++ WPFSerialAssistant/MainWindow.xaml | 10 +- WPFSerialAssistant/MainWindow.xaml.cs | 86 +++++--- WPFSerialAssistant/WPFSerialAssistant.csproj | 8 + 6 files changed, 329 insertions(+), 36 deletions(-) create mode 100644 WPFSerialAssistant/CommandConfig.cs create mode 100644 WPFSerialAssistant/CommandSettingsWindow.xaml create mode 100644 WPFSerialAssistant/CommandSettingsWindow.xaml.cs diff --git a/WPFSerialAssistant/CommandConfig.cs b/WPFSerialAssistant/CommandConfig.cs new file mode 100644 index 0000000..023f65b --- /dev/null +++ b/WPFSerialAssistant/CommandConfig.cs @@ -0,0 +1,16 @@ +// CommandConfig.cs +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WPFSerialAssistant +{ + public class CommandConfig + { + public List> AllPagesCommands { get; set; } + public int CurrentPageIndex { get; set; } = 0; // 默认显示第一页 + public List PageNames { get; set; } = new List(); // 新增属性存储页面名称 + } +} diff --git a/WPFSerialAssistant/CommandSettingsWindow.xaml b/WPFSerialAssistant/CommandSettingsWindow.xaml new file mode 100644 index 0000000..260aec6 --- /dev/null +++ b/WPFSerialAssistant/CommandSettingsWindow.xaml @@ -0,0 +1,45 @@ + + + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + 1200 + 2400 + 4800 + 9600 + 19200 + 38400 + 115200 + + + + + + + + + + + 无(None) + 偶校验(Even) + 奇校验(Odd) + 保留为0(Space) + 保留为1(Mark) + + + + + + + + + + + 8 + 7 + 6 + 5 + + + + + + + + + + + 1 + 1.5 + 2 + + + + + + + + + + + Default + ASCII + Unicode + UTF-8 + + + + + + + + + + + + 快捷键: - 1. Ctrl+S: 保存接收区数据 - 2. Ctrl+Enter: 进/退简洁视图模式 - 3. Enter: 发送数据 - - - - - - + 1. Ctrl+S: 保存接收区数据 + 2. Ctrl+Enter: 进/退简洁视图模式 + 3. Enter: 发送数据 + + + + + + - - - - - - - - - - - - - - - - + + + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - 自动发送时间间隔 - - - 毫秒 - 秒钟 - 分钟 - + + + + + + + + 自动发送时间间隔 + + + 毫秒 + 秒钟 + 分钟 + - - 使能自动发送 - - + + 使能自动发送 + + diff --git a/WPFSerialAssistant/MainWindow.xaml.cs b/WPFSerialAssistant/MainWindow.xaml.cs index 6d5db18..6518a46 100644 --- a/WPFSerialAssistant/MainWindow.xaml.cs +++ b/WPFSerialAssistant/MainWindow.xaml.cs @@ -4,6 +4,10 @@ using System.IO; using System.Linq; using System.Text; +using System.Threading; +using System.Threading.Tasks; + + //using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; @@ -16,7 +20,6 @@ using System.Windows.Shapes; using System.Windows.Threading; using Path = System.IO.Path; - namespace WPFSerialAssistant { /// @@ -36,6 +39,8 @@ public partial class MainWindow : Window private List> allPagesCommands = new List>(); private CommandConfig commandConfig = new CommandConfig(); + + // 保存命令列表到JSON文件 private void SaveCommands() { @@ -106,8 +111,71 @@ public MainWindow() InitializeComponent(); InitCore(); LoadCommands(); + quickTestTimer.Interval = TimeSpan.FromMilliseconds(50); + quickTestTimer.Tick += QuickTestTimer_Tick; + } + + private Dictionary> quickTestCmdDict = new Dictionary> + { + { "初始化", new List { "AT", "AT+PRTR=1", "AT+PRTS=1", "AT+TEST=1," } }, + { "信道1", new List { "AT", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+TEST=1,1" } }, + { "信道2", new List { "AT", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+TEST=1,2" } }, + { "信道3", new List { "AT", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+TEST=1,3" } }, + { "信道4", new List { "AT", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+TEST=1,4" } }, + { "信道5", new List { "AT", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+TEST=1,5" } }, + { "信道6", new List { "AT", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+TEST=1,6" } }, + { "信道7", new List { "AT", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+TEST=1,7" } }, + { "信道8", new List { "AT", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+TEST=1,8" } }, + { "信道9", new List { "AT", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+TEST=1,9" } }, + { "信道10", new List { "AT", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+TEST=1,10" } }, + { "信道11", new List { "AT", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+TEST=1,11" } }, + { "信道12", new List { "AT", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+TEST=1,12" } }, + { "信道13", new List { "AT", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+TEST=1,13" } }, + { "信道14", new List { "AT", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+TEST=1,14" } }, + { "信道15", new List { "AT", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+TEST=1,15" } }, + { "信道16", new List { "AT", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+TEST=1,16" } }, + { "信道17", new List { "AT", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+TEST=1,17" } }, + { "信道18", new List { "AT", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+TEST=1,18" } }, + { "信道19", new List { "AT", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+TEST=1,19" } }, + { "信道20", new List { "AT", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+TEST=1,20" } }, + { "信道21", new List { "AT", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+SEND=20,0302030405060708091003020304050607080910,1", "AT+TEST=1,21" } }, + }; + private List currentQuickTestCmdList = null; + private int quickTestCount = 0; + private int quickTestTotal = 0; + private DispatcherTimer quickTestTimer = new DispatcherTimer(); + private void QuickTestButton_Click(object sender, RoutedEventArgs e) + { + // 弹出自定义选择窗口 + var dlg = new SelectDialog(quickTestCmdDict.Keys); + dlg.Owner = this; + if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.SelectedType)) + { + currentQuickTestCmdList = quickTestCmdDict[dlg.SelectedType]; + quickTestCount = 0; + quickTestTotal = currentQuickTestCmdList.Count; + quickTestTimer.Start(); + } + } + + + + private void QuickTestTimer_Tick(object sender, EventArgs e) + { + if (quickTestCount < quickTestTotal) + { + string cmd = currentQuickTestCmdList[quickTestCount]; + SerialPortWrite(cmd); + recvDataRichTextBox.ScrollToEnd(); + quickTestCount++; + } + else + { + quickTestTimer.Stop(); + } } + // 命令数据类 public class CommandItem { @@ -128,8 +196,7 @@ private void CmdListBox_SelectionChanged(object sender, SelectionChangedEventArg { if (cmdListBox.SelectedItem is CommandItem selectedCmd) { - sendDataTextBox.Text = selectedCmd.Value; - sendDataButton.Focus(); + SerialPortWrite(selectedCmd.Value); } } @@ -203,5 +270,97 @@ private void UpdateDocumentFontSize(FlowDocument document, double newSize) } } } + + private void FileDropBorder_DragOver(object sender, DragEventArgs e) + { + e.Effects = e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.Copy : DragDropEffects.None; + e.Handled = true; + } + + private void FileDropBorder_Drop(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(DataFormats.FileDrop)) + { + string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); + if (files.Length > 0) + filePathTextBlock.Text = files[0]; + } + } + + private void SelectFileButton_Click(object sender, RoutedEventArgs e) + { + var dialog = new Microsoft.Win32.OpenFileDialog(); + if (dialog.ShowDialog() == true) + filePathTextBlock.Text = dialog.FileName; + } + + private void SendFileButton_Click(object sender, RoutedEventArgs e) + { + string path = filePathTextBlock.Text; + if (string.IsNullOrWhiteSpace(path) || !System.IO.File.Exists(path)) + { + MessageBox.Show("请选择有效的文件!"); + return; + } + SendFileBySerial(path); // 你自己的串口发送函数 + } + + private void SendFileBySerial(string filePath) + { + Task.Run(() => + { + try + { + string[] lines = System.IO.File.ReadAllLines(filePath); + int total = lines.Length; + + // 主线程显示进度条 + Application.Current.Dispatcher.Invoke(() => + { + progressBar.Visibility = Visibility.Visible; + progressBar.Minimum = 0; + progressBar.Maximum = 100; + progressBar.Value = 0; + }); + + for (int i = 0; i < total; i++) + { + SerialPortWrite(lines[i], false); // 只发送,不回显 + + // 每50行刷新一次进度条 + if (i % 50 == 0 || i == total - 1) + { + int percent = (int)((i + 1) * 100.0 / total); + Application.Current.Dispatcher.Invoke(() => + { + progressBar.Value = percent; + }); + } + + Thread.Sleep(1); // 视你的设备性能可调小一点 + } + + Application.Current.Dispatcher.Invoke(() => + { + progressBar.Visibility = Visibility.Collapsed; + MessageBox.Show($"文件已全部发送:{System.IO.Path.GetFileName(filePath)}"); + }); + } + catch (Exception ex) + { + Application.Current.Dispatcher.Invoke(() => + { + progressBar.Visibility = Visibility.Collapsed; + MessageBox.Show($"发送文件失败:{ex.Message}"); + }); + } + }); + } + + + + + + } } diff --git a/WPFSerialAssistant/Properties/AssemblyInfo.cs b/WPFSerialAssistant/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..4669abc --- /dev/null +++ b/WPFSerialAssistant/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("WPFSerialAssistant")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("WPFSerialAssistant")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +//将 ComVisible 设置为 false 将使此程序集中的类型 +//对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +//若要开始生成可本地化的应用程序,请 +// 中的 .csproj 文件中 +//例如,如果您在源文件中使用的是美国英语, +//使用的是美国英语,请将 设置为 en-US。 然后取消 +//对以下 NeutralResourceLanguage 特性的注释。 更新 +//以下行中的“en-US”以匹配项目文件中的 UICulture 设置。 + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //主题特定资源词典所处位置 + //(当资源未在页面 + //或应用程序资源字典中找到时使用) + ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置 + //(当资源未在页面 + //、应用程序或任何主题专用资源字典中找到时使用) +)] + + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/WPFSerialAssistant/SASerialPort.cs b/WPFSerialAssistant/SASerialPort.cs index 655e4ca..a13cd24 100644 --- a/WPFSerialAssistant/SASerialPort.cs +++ b/WPFSerialAssistant/SASerialPort.cs @@ -6,6 +6,8 @@ using System.Threading; //using System.Threading.Tasks; using System.Windows; +using System.Windows.Documents; +using System.Windows.Media; using System.Windows.Threading; namespace WPFSerialAssistant @@ -185,21 +187,13 @@ private Encoding GetSelectedEncoding() return enc; } - private bool SerialPortWrite(string textData) - { - SerialPortWrite(textData, false); - return false; - } - private string appendContent = "\n"; - private bool SerialPortWrite(string textData, bool reportEnable) + /// + /// 串口写入数据。可选回显(用于手动输入/单条命令)。 + /// + private bool SerialPortWrite(string textData, bool echoToUI = true) { - if (serialPort == null) - { - return false; - } - - if (serialPort.IsOpen == false) + if (serialPort == null || !serialPort.IsOpen) { Alert("串口未打开,无法发送数据。"); return false; @@ -207,9 +201,6 @@ private bool SerialPortWrite(string textData, bool reportEnable) try { - //serialPort.DiscardOutBuffer(); - //serialPort.DiscardInBuffer(); - if (sendMode == SendMode.Character) { serialPort.Write(textData + appendContent); @@ -217,32 +208,45 @@ private bool SerialPortWrite(string textData, bool reportEnable) else if (sendMode == SendMode.Hex) { string[] grp = textData.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); - List list = new List(); - foreach (var item in grp) - { list.Add(Convert.ToByte(item, 16)); - } - serialPort.Write(list.ToArray(), 0, list.Count); } - - if (reportEnable) - { - // 报告发送成功的消息,提示用户。 - Information(string.Format("成功发送:{0}。", textData)); - } } catch (Exception ex) { - Alert(ex.Message); + Application.Current.Dispatcher.Invoke(() => Alert(ex.Message)); return false; } + // 回显,只能在UI线程 + if (echoToUI && sendEchoCheckBox != null && sendEchoCheckBox.IsChecked == true) + { + Application.Current.Dispatcher.Invoke(() => + { + string timeStr = DateTime.Now.ToString("[发送 HH:mm:ss.fff]"); + Paragraph para = new Paragraph(); + Run timeRun = new Run(timeStr + "\n") { Foreground = Brushes.Red }; + Run contentRun = new Run(textData + "\n") { Foreground = Brushes.Red }; + para.Inlines.Add(timeRun); + para.Inlines.Add(contentRun); + recvDataRichTextBox.Document.Blocks.Add(para); + recvDataRichTextBox.ScrollToEnd(); + }); + } + return true; } + // 兼容你的老接口,只保留,不建议再直接用 + private bool SerialPortWrite(string textData) + { + // 默认回显 + return SerialPortWrite(textData, true); + } + + #region 定时器 /// /// 超时时间为50ms diff --git a/WPFSerialAssistant/SAViewMode.cs b/WPFSerialAssistant/SAViewMode.cs index d76c1b1..5585927 100644 --- a/WPFSerialAssistant/SAViewMode.cs +++ b/WPFSerialAssistant/SAViewMode.cs @@ -10,7 +10,7 @@ namespace WPFSerialAssistant public partial class MainWindow : Window { // 保存面板的显示状态 - private Stack panelVisibilityStack = new Stack(3); + private Stack panelVisibilityStack = new Stack(4); /// /// 判断是否处于简洁视图模式 @@ -20,7 +20,8 @@ private bool IsCompactViewMode() { if (autoSendConfigPanel.Visibility == Visibility.Collapsed && serialCommunicationConfigPanel.Visibility == Visibility.Collapsed && - autoSendConfigPanel.Visibility == Visibility.Collapsed) + autoSendConfigPanel.Visibility == Visibility.Collapsed && + commonCommandsPanel.Visibility == Visibility.Collapsed) { return true; } @@ -39,7 +40,7 @@ private void EnterCompactViewMode() panelVisibilityStack.Push(serialPortConfigPanel.Visibility); panelVisibilityStack.Push(autoSendConfigPanel.Visibility); panelVisibilityStack.Push(serialCommunicationConfigPanel.Visibility); - panelVisibilityStack.Push(commonCommandsViewMenuItem.Visibility); + panelVisibilityStack.Push(commonCommandsPanel.Visibility); // 进入简洁视图模式 serialPortConfigPanel.Visibility = Visibility.Collapsed; @@ -62,7 +63,6 @@ private void EnterCompactViewMode() // 切换至简洁视图模式,菜单项选中 compactViewMenuItem.IsChecked = true; - // Information("进入简洁视图模式。"); } @@ -72,10 +72,11 @@ private void EnterCompactViewMode() private void RestoreViewMode() { // 恢复面板显示状态 + commonCommandsPanel.Visibility = panelVisibilityStack.Pop(); serialCommunicationConfigPanel.Visibility = panelVisibilityStack.Pop(); autoSendConfigPanel.Visibility = panelVisibilityStack.Pop(); serialPortConfigPanel.Visibility = panelVisibilityStack.Pop(); - commonCommandsViewMenuItem.Visibility = panelVisibilityStack.Pop(); + // 恢复菜单选中状态 if (serialPortConfigPanel.Visibility == Visibility.Visible) { @@ -100,7 +101,7 @@ private void RestoreViewMode() serialSettingViewMenuItem.IsEnabled = true; autoSendDataSettingViewMenuItem.IsEnabled = true; serialCommunicationSettingViewMenuItem.IsEnabled = true; - commonCommandsViewMenuItem.IsChecked = true; + commonCommandsViewMenuItem.IsEnabled = true; compactViewMenuItem.IsChecked = false; diff --git a/WPFSerialAssistant/SelectDialog.xaml b/WPFSerialAssistant/SelectDialog.xaml new file mode 100644 index 0000000..14bea2e --- /dev/null +++ b/WPFSerialAssistant/SelectDialog.xaml @@ -0,0 +1,16 @@ + + + + + +