Skip to content

Commit 01100b9

Browse files
committed
增加对收发数据显示长度的限制,防止因过长而卡死软件
增加对收发数量条目数显示的限制,超过500条自动清空 去除是否保存串口日志的选项,强制保存日志 收发串口数据后,再新建日志文件
1 parent 0f7e989 commit 01100b9

File tree

8 files changed

+49
-14
lines changed

8 files changed

+49
-14
lines changed

changlog/autoUpdate.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<item>
3-
<version>1.0.1.5</version>
4-
<url>https://llcom.papapoi.com/update/1.0.1.5.zip</url>
5-
<changelog>https://llcom.papapoi.com/changelog/1.0.1.5.html</changelog>
3+
<version>1.0.1.6</version>
4+
<url>https://llcom.papapoi.com/update/1.0.1.6.zip</url>
5+
<changelog>https://llcom.papapoi.com/changelog/1.0.1.6.html</changelog>
66
<mandatory mode="1">true</mandatory>
77
</item>

changlog/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,21 @@
88

99
> 欢迎加入交流群:`906307487`
1010

11+
## LLCOM 1.0.1.6
12+
13+
- 增加对收发数据显示长度的限制,防止因过长而卡死软件
14+
- 增加对收发数量条目数显示的限制,超过500条自动清空
15+
- 去除是否保存串口日志的选项,强制保存日志
16+
- 收发串口数据后,再新建日志文件,不会一开软件就创建日志文件了
17+
18+
---
19+
1120
## LLCOM 1.0.1.5
1221

1322
- .net framework 框架版本需求降低为4.5,照顾没升级的用户
1423

24+
---
25+
1526
## LLCOM 1.0.1.4
1627

1728
- **重要:** 更正遗留的定时器处理逻辑错误问题

llcom/MainWindow.xaml.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using FontAwesome.WPF;
1+
using FontAwesome.WPF;
22
using ICSharpCode.AvalonEdit.Highlighting;
33
using ICSharpCode.AvalonEdit.Highlighting.Xshd;
44
using ICSharpCode.AvalonEdit.Search;
@@ -313,8 +313,13 @@ private void addUartLog(byte[] data, bool send)
313313
text.Foreground = Brushes.Black;
314314
text.FontWeight = FontWeights.Bold;
315315
p.Inlines.Add(text);
316+
317+
if (data.Length > 2000)
318+
text = new Span(new Run(Tools.Global.Byte2String(data.Skip(0).Take(2000).ToArray())
319+
+"\r\n数据过长,剩余部分请去日志文件查看"));
320+
else
321+
text = new Span(new Run(Tools.Global.Byte2String(data)));
316322

317-
text = new Span(new Run(Tools.Global.Byte2String(data)));
318323
if (send)
319324
text.Foreground = Brushes.DarkRed;
320325
else
@@ -328,14 +333,26 @@ private void addUartLog(byte[] data, bool send)
328333

329334
if (Tools.Global.setting.showHex)
330335
{
331-
p = new Paragraph(new Run("HEX:" + Tools.Global.Byte2Hex(data," ")));
336+
if (data.Length > 600)
337+
p = new Paragraph(new Run("HEX:" + Tools.Global.Byte2Hex(data.Skip(0).Take(600).ToArray(), " ")
338+
+ "\r\n数据过长,剩余部分请去日志文件查看"));
339+
else
340+
p = new Paragraph(new Run("HEX:" + Tools.Global.Byte2Hex(data, " ")));
341+
332342
if (send)
333343
p.Foreground = Brushes.LightPink;
334344
else
335345
p.Foreground = Brushes.LightGreen;
336346
p.Margin = new Thickness(0, 0, 0, 8);
337347
uartDataFlowDocument.Document.Blocks.Add(p);
338348
}
349+
350+
//条目过多,自动清空
351+
if(uartDataFlowDocument.Document.Blocks.Count > 500)
352+
{
353+
uartDataFlowDocument.Document.Blocks.Clear();
354+
addUartLog(Tools.Global.Hex2Byte(Tools.Global.String2Hex("数据量过大,自动清理,请去日志文件查看历史数据","")), true);
355+
}
339356

340357
sv.ScrollToBottom();
341358
}

llcom/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
5252
//通过使用 "*",如下所示:
5353
// [assembly: AssemblyVersion("1.0.*")]
54-
[assembly: AssemblyVersion("1.0.1.5")]
55-
[assembly: AssemblyFileVersion("1.0.1.5")]
54+
[assembly: AssemblyVersion("1.0.1.6")]
55+
[assembly: AssemblyFileVersion("1.0.1.6")]
5656
[assembly: NeutralResourcesLanguage("zh-CN")]
5757

llcom/SettingWindow.xaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Window x:Class="llcom.SettingWindow"
1+
<Window x:Class="llcom.SettingWindow"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@@ -16,7 +16,8 @@
1616
<TabItem Header="串口基本设置">
1717
<StackPanel Margin="10,5,0,0" >
1818
<CheckBox Content="自动恢复被断开的串口连接" Margin="5" IsChecked="{Binding autoReconnect}"/>
19-
<CheckBox Content="自动保存串口收发日志" Margin="5" IsChecked="{Binding autoSaveLog}"/>
19+
<!--<CheckBox Content="自动保存串口收发日志" Margin="5" IsChecked="{Binding autoSaveLog}"/>-->
20+
<Button Name="OpenLogButton" Content="打开串口收发日志目录" Click="OpenLogButton_Click" Margin="5"/>
2021
<CheckBox Content="串口数据窗口显示HEX值" Margin="5" IsChecked="{Binding showHex}"/>
2122
<CheckBox Content="窗口保持置顶显示" Margin="5" IsChecked="{Binding topmost}"/>
2223
<WrapPanel Margin="5">

llcom/SettingWindow.xaml.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using ICSharpCode.AvalonEdit.Highlighting;
1+
using ICSharpCode.AvalonEdit.Highlighting;
22
using ICSharpCode.AvalonEdit.Highlighting.Xshd;
33
using ICSharpCode.AvalonEdit.Search;
44
using System;
@@ -260,5 +260,10 @@ private void SettingsButton_Click(object sender, RoutedEventArgs e)
260260
string path = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;
261261
System.Diagnostics.Process.Start("explorer.exe", path.Substring(0,path.Length-11));
262262
}
263+
264+
private void OpenLogButton_Click(object sender, RoutedEventArgs e)
265+
{
266+
System.Diagnostics.Process.Start("explorer.exe", "logs");
267+
}
263268
}
264269
}

llcom/Tools/Global.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using LibUsbDotNet;
1+
using LibUsbDotNet;
22
using LibUsbDotNet.Main;
33
using System;
44
using System.Collections.Generic;
@@ -53,7 +53,6 @@ public static void Initial()
5353
setting = new Model.Settings();
5454
Model.Settings.UpdateQuickSend();
5555

56-
Logger.InitUartLog();
5756
uart.Init();
5857
uart.serial.BaudRate = setting.baudRate;
5958
uart.serial.Parity = (Parity)setting.parity;

llcom/Tools/Logger.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
@@ -27,6 +27,8 @@ public static void InitUartLog()
2727
/// <param name="l"></param>
2828
public static void AddUartLog(string l)
2929
{
30+
if (uartLogFile == "")
31+
InitUartLog();
3032
try
3133
{
3234
File.AppendAllText(uartLogFile, DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss:ffff]") + l + "\r\n");

0 commit comments

Comments
 (0)