调试数据
This commit is contained in:
@@ -37,7 +37,8 @@ namespace 头罩视野
|
||||
}
|
||||
|
||||
//private void GoTest(object s, RoutedEventArgs e) => MainFrame.Content = new Views.PageTest();
|
||||
private void GoRecord(object s, RoutedEventArgs e) => MainFrame.Content = new Views.RecordDate();
|
||||
//private void GoRecord(object s, RoutedEventArgs e) => MainFrame.Content = new Views.RecordDate();
|
||||
private void GoRecord(object s, RoutedEventArgs e) => MainFrame.Content = new Views.PageTest();
|
||||
//private void GoView(object s, RoutedEventArgs e) => MainFrame.Content = new Views.RecordPage();
|
||||
|
||||
private void GoVisiPage(object s, RoutedEventArgs e) => MainFrame.Content = new Views.VisiData();
|
||||
|
||||
@@ -22,7 +22,8 @@ namespace 头罩视野.Views
|
||||
{
|
||||
public partial class PageTest : Page
|
||||
{
|
||||
|
||||
/// 只加这一个变量
|
||||
private CancellationTokenSource? _cts;
|
||||
private IModbusMaster _modbusMaster => ModbusResourceManager.Instance.ModbusMaster;
|
||||
DispatcherTimer _timer;
|
||||
DataChange c = new DataChange();
|
||||
@@ -157,12 +158,7 @@ namespace 头罩视野.Views
|
||||
TestDataStore.AddNewRecord(data);
|
||||
_lastRecord = data;
|
||||
}
|
||||
private void Page_Unloaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
testTimer?.Stop();
|
||||
_timer?.Stop();
|
||||
|
||||
}
|
||||
//停止btn
|
||||
private void Button_Click_Stop(object sender, RoutedEventArgs e)
|
||||
{
|
||||
@@ -249,7 +245,12 @@ namespace 头罩视野.Views
|
||||
private async Task ReadAndUpdateFloatAsync(int address, int length, System.Windows.Controls.TextBox control, string format, string unit)
|
||||
{
|
||||
try
|
||||
{
|
||||
{ // 1. 页面销毁时直接退出,不执行
|
||||
if (_cts?.IsCancellationRequested == true) return;
|
||||
|
||||
// 2. 关键:判断对象为空就直接返回,不执行
|
||||
if (_modbusMaster == null) return;
|
||||
|
||||
ushort[] registers = await Task.Run(async () =>
|
||||
await _modbusMaster!.ReadHoldingRegistersAsync(1, (ushort)address, (ushort)length)
|
||||
);
|
||||
@@ -409,6 +410,14 @@ namespace 头罩视野.Views
|
||||
c = new DataChange();
|
||||
|
||||
}
|
||||
private void Page_Unloaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
testTimer?.Stop();
|
||||
_timer?.Stop();
|
||||
_cts?.Cancel();
|
||||
_cts = null;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace 头罩视野.Views
|
||||
ModbusHelper.SaveToCsv(RightEyeDataList,$"右眼数据_{DateTime.Now:yyyyMMddHHmmss}.csv");
|
||||
}
|
||||
|
||||
|
||||
//清除
|
||||
private void btnClear_MouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
_isClearPressed = true;
|
||||
|
||||
@@ -168,7 +168,8 @@
|
||||
<Button Content="保存" FontSize="18"
|
||||
Width="120" Height="50" Background="#3498DB" Foreground="White" Margin="840,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="btnSave_Click" />
|
||||
<Button Content="清除" FontSize="18"
|
||||
Width="120" Height="50" Background="White" BorderBrush="red" Foreground="red" Margin="10,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="btnClear_Click"/>
|
||||
Width="120" Height="50" Background="White" BorderBrush="red" Foreground="red" Margin="10,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Top"
|
||||
PreviewMouseLeftButtonDown ="btnClear_MouseDown" PreviewMouseLeftButtonUp ="btnClear_MouseUp" />
|
||||
<TextBlock HorizontalAlignment="Left" Foreground="red" Margin="139,14,0,0" TextWrapping="Wrap" VerticalAlignment="Top" FontSize="18" Width="202"><Run Language="zh-cn" Text="备注: 清除长按"/></TextBlock>
|
||||
</Grid>
|
||||
|
||||
|
||||
@@ -28,8 +28,9 @@ namespace 头罩视野.Views
|
||||
/// </summary>
|
||||
public partial class RecordPage : Page
|
||||
{
|
||||
|
||||
|
||||
//长按清除
|
||||
private bool _isClearPressed = false;
|
||||
private Thread _clearThread;
|
||||
private IModbusMaster _modbusMaster => ModbusResourceManager.Instance.ModbusMaster;
|
||||
|
||||
public RecordPage()
|
||||
@@ -38,16 +39,55 @@ namespace 头罩视野.Views
|
||||
}
|
||||
|
||||
//#region 2. 清除表格数据
|
||||
private void btnClear_Click(object sender, RoutedEventArgs e)
|
||||
//private void btnClear_Click(object sender, RoutedEventArgs e)
|
||||
//{
|
||||
// // 确认清除
|
||||
// if (MessageBox.Show("确定要清除所有记录吗?", "确认", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||||
// {
|
||||
// TestDataStore.Records.Clear();
|
||||
// RecordDataGrid.ItemsSource = null;
|
||||
// RecordDataGrid.ItemsSource = TestDataStore.Records;
|
||||
// }
|
||||
//}
|
||||
|
||||
//清除
|
||||
private void btnClear_MouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
// 确认清除
|
||||
if (MessageBox.Show("确定要清除所有记录吗?", "确认", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||||
_isClearPressed = true;
|
||||
_clearThread = new Thread(() =>
|
||||
{
|
||||
TestDataStore.Records.Clear();
|
||||
RecordDataGrid.ItemsSource = null;
|
||||
RecordDataGrid.ItemsSource = TestDataStore.Records;
|
||||
}
|
||||
Thread.Sleep(500); // 长按1秒触发
|
||||
if (_isClearPressed)
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(() => ClearAllData());
|
||||
}
|
||||
});
|
||||
_clearThread.Start();
|
||||
}
|
||||
// 清除所有数据
|
||||
private void ClearAllData()
|
||||
{
|
||||
TestDataStore.Records.Clear();
|
||||
RecordDataGrid.ItemsSource = null;
|
||||
RecordDataGrid.ItemsSource = TestDataStore.Records;
|
||||
|
||||
MessageBox.Show("数据已清除");
|
||||
}
|
||||
|
||||
private void btnClear_MouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
_isClearPressed = false;
|
||||
_clearThread?.Join(100); // 等待线程结束最多100毫秒,然后强制结束
|
||||
}
|
||||
private void Page_Unloaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
//_plcReadTimer?.Stop();
|
||||
//_plcReadTimer?.Dispose();
|
||||
//_modbusMaster?.Dispose();
|
||||
//ModbusHelper.TcpClient?.Close();
|
||||
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region 3. 保存为Excel
|
||||
private void btnSave_Click(object sender, RoutedEventArgs e)
|
||||
|
||||
@@ -1,146 +0,0 @@
|
||||
#pragma checksum "..\..\..\..\Views\RecordPage.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "2C38967E29481C17659DB2B3BEE79230294D83EF"
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 此代码由工具生成。
|
||||
// 运行时版本:4.0.30319.42000
|
||||
//
|
||||
// 对此文件的更改可能会导致不正确的行为,并且如果
|
||||
// 重新生成代码,这些更改将会丢失。
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Windows;
|
||||
using System.Windows.Automation;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Controls.Ribbon;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Ink;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Markup;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Animation;
|
||||
using System.Windows.Media.Effects;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Media.Media3D;
|
||||
using System.Windows.Media.TextFormatting;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Shell;
|
||||
using 头罩视野.Views;
|
||||
|
||||
|
||||
namespace 头罩视野.Views {
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// RecordPage
|
||||
/// </summary>
|
||||
public partial class RecordPage : System.Windows.Controls.Page, System.Windows.Markup.IComponentConnector {
|
||||
|
||||
|
||||
#line 136 "..\..\..\..\Views\RecordPage.xaml"
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
|
||||
internal System.Windows.Controls.DataGrid RecordDataGrid;
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
|
||||
private bool _contentLoaded;
|
||||
|
||||
/// <summary>
|
||||
/// InitializeComponent
|
||||
/// </summary>
|
||||
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "10.0.6.0")]
|
||||
public void InitializeComponent() {
|
||||
if (_contentLoaded) {
|
||||
return;
|
||||
}
|
||||
_contentLoaded = true;
|
||||
System.Uri resourceLocater = new System.Uri("/头罩视野;component/views/recordpage.xaml", System.UriKind.Relative);
|
||||
|
||||
#line 1 "..\..\..\..\Views\RecordPage.xaml"
|
||||
System.Windows.Application.LoadComponent(this, resourceLocater);
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
}
|
||||
|
||||
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "10.0.6.0")]
|
||||
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
|
||||
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
|
||||
switch (connectionId)
|
||||
{
|
||||
case 1:
|
||||
|
||||
#line 9 "..\..\..\..\Views\RecordPage.xaml"
|
||||
((头罩视野.Views.RecordPage)(target)).Loaded += new System.Windows.RoutedEventHandler(this.Page_Loaded);
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
return;
|
||||
case 2:
|
||||
this.RecordDataGrid = ((System.Windows.Controls.DataGrid)(target));
|
||||
return;
|
||||
case 3:
|
||||
|
||||
#line 169 "..\..\..\..\Views\RecordPage.xaml"
|
||||
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.btnSave_Click);
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
return;
|
||||
case 4:
|
||||
|
||||
#line 171 "..\..\..\..\Views\RecordPage.xaml"
|
||||
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.btnClear_Click);
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
return;
|
||||
case 5:
|
||||
|
||||
#line 185 "..\..\..\..\Views\RecordPage.xaml"
|
||||
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.GoHome);
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
return;
|
||||
case 6:
|
||||
|
||||
#line 187 "..\..\..\..\Views\RecordPage.xaml"
|
||||
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.GoTest);
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
return;
|
||||
case 7:
|
||||
|
||||
#line 189 "..\..\..\..\Views\RecordPage.xaml"
|
||||
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.GoRecord);
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
return;
|
||||
case 8:
|
||||
|
||||
#line 191 "..\..\..\..\Views\RecordPage.xaml"
|
||||
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.GoView);
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
return;
|
||||
}
|
||||
this._contentLoaded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user