This commit is contained in:
2026-04-21 13:36:09 +08:00
parent 68959ce119
commit 54c92d9644
11 changed files with 81 additions and 523 deletions

View File

@@ -25,7 +25,8 @@ namespace 头罩视野
public MainWindow()
{
InitializeComponent();
InitializeModbusTcp();
ModbusHelper.Connect("192.168.1.10", 502); // 连接一次,全局生效
//InitializeModbusTcp();
//MainFrame.Content = new Views.ChangeLanguage();
}
@@ -38,35 +39,35 @@ namespace 头罩视野
//NavigationService.Navigate(new Views.RecordDate()); 页面相互跳转
private void InitializeModbusTcp()
{
try
{
//private void InitializeModbusTcp()
//{
// try
// {
string plcIp = "192.168.1.10";
bool initSuccess = ModbusResourceManager.Instance.Init(plcIp, 502);
if (!initSuccess)
{
MessageBox.Show("连接Modbus服务器失败", "错误");
//this.Close();
return;
}
// string plcIp = "192.168.1.10";
// bool initSuccess = ModbusResourceManager.Instance.Init(plcIp, 502);
// if (!initSuccess)
// {
// MessageBox.Show("连接Modbus服务器失败", "错误");
// //this.Close();
// return;
// }
// 检查连接状态
if (_tcpClient == null || !_tcpClient.Connected)
{
MessageBox.Show("Modbus连接异常", "错误");
// // 检查连接状态
// if (_tcpClient == null || !_tcpClient.Connected)
// {
// MessageBox.Show("Modbus连接异常", "错误");
return;
}
// return;
// }
}
catch (Exception ex)
{
ShowError($"Modbus初始化失败: {ex.Message}");
}
}
// }
// catch (Exception ex)
// {
// ShowError($"Modbus初始化失败: {ex.Message}");
// }
//}
private void ShowError(string msg) => MessageBox.Show(msg, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}

View File

@@ -0,0 +1,17 @@
using System.Net.Sockets;
using .Services.Data;
public static class ModbusHelper
{
// 全局唯一连接,所有页面共用
public static TcpClient TcpClient => ModbusResourceManager.Instance.TcpClient;
// 统一连接方法(全项目只调用一次)
public static bool Connect(string ip, int port = 502)
{
return ModbusResourceManager.Instance.Init(ip, port);
}
// 判断是否连接成功
public static bool IsConnected => TcpClient != null && TcpClient.Connected;
}

View File

@@ -45,6 +45,18 @@ namespace 头罩视野.Views
testTimer.Interval = TimeSpan.FromMilliseconds(500); // 500ms = 0.5秒
testTimer.Tick += Timer_Tick;
//// 判断连接
if (!ModbusHelper.IsConnected)
{
MessageBox.Show("未连接");
return;
}
// 获取客户端
var client = ModbusHelper.TcpClient;
}
//复位btn
@@ -346,6 +358,8 @@ namespace 头罩视野.Views
_timer.Start();
ma = new Function(_modbusMaster);
c = new DataChange();
}
}
}

View File

@@ -85,10 +85,20 @@ namespace 头罩视野.Views
private void Page_Loaded(object sender, RoutedEventArgs e)
{
//进入页面是否要保留原来的数据????,
// 判断连接
if (!ModbusHelper.IsConnected)
{
MessageBox.Show("未连接");
return;
}
// 获取客户端
var client = ModbusHelper.TcpClient;
//进入页面是否要保留原来的数据????,
RecordDataGrid.ItemsSource = null;
RecordDataGrid.ItemsSource = TestDataStore.Records;
}
private void GoHome(object s, RoutedEventArgs e) => NavigationService.Content = null;

View File

@@ -31,6 +31,17 @@ namespace 头罩视野.Views
InitializeComponent();
_timer = InitDispatcherTimer();
// 判断连接
if (!ModbusHelper.IsConnected)
{
MessageBox.Show("未连接");
return;
}
// 获取客户端
var client = ModbusHelper.TcpClient;
}
//复位btn
private void Button_Click_Reset(object sender, RoutedEventArgs e)
@@ -251,6 +262,8 @@ namespace 头罩视野.Views
private void Page_Loaded(object sender, RoutedEventArgs e)
{
_timer.Start();
ma = new Function(_modbusMaster);

View File

@@ -1,343 +0,0 @@
#pragma checksum "..\..\..\..\Views\PageTest.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "CC165992FB311CDDE115E339868F704FC7865550"
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
using HandyControl.Controls;
using HandyControl.Data;
using HandyControl.Expression.Media;
using HandyControl.Expression.Shapes;
using HandyControl.Interactivity;
using HandyControl.Media.Animation;
using HandyControl.Media.Effects;
using HandyControl.Properties.Langs;
using HandyControl.Themes;
using HandyControl.Tools;
using HandyControl.Tools.Converter;
using HandyControl.Tools.Extension;
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>
/// PageTest
/// </summary>
public partial class PageTest : System.Windows.Controls.Page, System.Windows.Markup.IComponentConnector {
#line 113 "..\..\..\..\Views\PageTest.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox fbspeed;
#line default
#line hidden
#line 119 "..\..\..\..\Views\PageTest.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox dqangle;
#line default
#line hidden
#line 125 "..\..\..\..\Views\PageTest.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox zdangle;
#line default
#line hidden
#line 145 "..\..\..\..\Views\PageTest.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBlock ;
#line default
#line hidden
#line 164 "..\..\..\..\Views\PageTest.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox zmsyarea;
#line default
#line hidden
#line 170 "..\..\..\..\Views\PageTest.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox smsyarea;
#line default
#line hidden
#line 176 "..\..\..\..\Views\PageTest.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox kbsyarea;
#line default
#line hidden
#line 189 "..\..\..\..\Views\PageTest.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox ymsyarea;
#line default
#line hidden
#line 195 "..\..\..\..\Views\PageTest.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox xfsyarea;
#line default
#line hidden
#line 201 "..\..\..\..\Views\PageTest.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox sybhl;
#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/pagetest.xaml", System.UriKind.Relative);
#line 1 "..\..\..\..\Views\PageTest.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 11 "..\..\..\..\Views\PageTest.xaml"
((.Views.PageTest)(target)).Loaded += new System.Windows.RoutedEventHandler(this.Page_Loaded);
#line default
#line hidden
#line 11 "..\..\..\..\Views\PageTest.xaml"
((.Views.PageTest)(target)).Unloaded += new System.Windows.RoutedEventHandler(this.Page_Unloaded);
#line default
#line hidden
return;
case 2:
this.fbspeed = ((System.Windows.Controls.TextBox)(target));
#line 113 "..\..\..\..\Views\PageTest.xaml"
this.fbspeed.GotFocus += new System.Windows.RoutedEventHandler(this.fbspeed_GotFocus);
#line default
#line hidden
return;
case 3:
this.dqangle = ((System.Windows.Controls.TextBox)(target));
#line 119 "..\..\..\..\Views\PageTest.xaml"
this.dqangle.GotFocus += new System.Windows.RoutedEventHandler(this.dqangle_GotFocus);
#line default
#line hidden
return;
case 4:
this.zdangle = ((System.Windows.Controls.TextBox)(target));
#line 125 "..\..\..\..\Views\PageTest.xaml"
this.zdangle.GotFocus += new System.Windows.RoutedEventHandler(this.zdangle_GotFocus);
#line default
#line hidden
return;
case 5:
#line 136 "..\..\..\..\Views\PageTest.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.Button_Click_Print);
#line default
#line hidden
return;
case 6:
#line 141 "..\..\..\..\Views\PageTest.xaml"
((System.Windows.Controls.RadioButton)(target)).Checked += new System.Windows.RoutedEventHandler(this.RadioButton_Checked);
#line default
#line hidden
#line 143 "..\..\..\..\Views\PageTest.xaml"
((System.Windows.Controls.RadioButton)(target)).Unchecked += new System.Windows.RoutedEventHandler(this.RadioButton_Unchecked);
#line default
#line hidden
return;
case 7:
this. = ((System.Windows.Controls.TextBlock)(target));
return;
case 8:
this.zmsyarea = ((System.Windows.Controls.TextBox)(target));
return;
case 9:
this.smsyarea = ((System.Windows.Controls.TextBox)(target));
return;
case 10:
this.kbsyarea = ((System.Windows.Controls.TextBox)(target));
return;
case 11:
this.ymsyarea = ((System.Windows.Controls.TextBox)(target));
return;
case 12:
this.xfsyarea = ((System.Windows.Controls.TextBox)(target));
return;
case 13:
this.sybhl = ((System.Windows.Controls.TextBox)(target));
return;
case 14:
#line 225 "..\..\..\..\Views\PageTest.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.Button_Click_Reset);
#line default
#line hidden
return;
case 15:
#line 229 "..\..\..\..\Views\PageTest.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.Button_Click_left);
#line default
#line hidden
return;
case 16:
#line 233 "..\..\..\..\Views\PageTest.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.Button_Click_Res);
#line default
#line hidden
return;
case 17:
#line 237 "..\..\..\..\Views\PageTest.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.Button_Click_Right);
#line default
#line hidden
return;
case 18:
#line 241 "..\..\..\..\Views\PageTest.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.Button_Click_For);
#line default
#line hidden
return;
case 19:
#line 245 "..\..\..\..\Views\PageTest.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.Button_Click_Test);
#line default
#line hidden
return;
case 20:
#line 249 "..\..\..\..\Views\PageTest.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.Button_Click_Stop);
#line default
#line hidden
return;
case 21:
#line 261 "..\..\..\..\Views\PageTest.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.GoHome);
#line default
#line hidden
return;
case 22:
#line 263 "..\..\..\..\Views\PageTest.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.GoTest);
#line default
#line hidden
return;
case 23:
#line 265 "..\..\..\..\Views\PageTest.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.GoRecord);
#line default
#line hidden
return;
case 24:
#line 267 "..\..\..\..\Views\PageTest.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.GoView);
#line default
#line hidden
return;
}
this._contentLoaded = true;
}
}
}

View File

@@ -1,133 +0,0 @@
#pragma checksum "..\..\..\..\Views\RecordDate.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "26A6787944E77FB072929431D63045D09E531706"
//------------------------------------------------------------------------------
// <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>
/// RecordDate
/// </summary>
public partial class RecordDate : System.Windows.Controls.Page, System.Windows.Markup.IComponentConnector {
#line 146 "..\..\..\..\Views\RecordDate.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.DataGrid dataGrid1;
#line default
#line hidden
#line 183 "..\..\..\..\Views\RecordDate.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.DataGrid dataGrid2;
#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/recorddate.xaml", System.UriKind.Relative);
#line 1 "..\..\..\..\Views\RecordDate.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:
this.dataGrid1 = ((System.Windows.Controls.DataGrid)(target));
return;
case 2:
this.dataGrid2 = ((System.Windows.Controls.DataGrid)(target));
return;
case 3:
#line 245 "..\..\..\..\Views\RecordDate.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.GoHome);
#line default
#line hidden
return;
case 4:
#line 247 "..\..\..\..\Views\RecordDate.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.GoTest);
#line default
#line hidden
return;
case 5:
#line 249 "..\..\..\..\Views\RecordDate.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.GoRecord);
#line default
#line hidden
return;
case 6:
#line 251 "..\..\..\..\Views\RecordDate.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.GoView);
#line default
#line hidden
return;
}
this._contentLoaded = true;
}
}
}

View File

@@ -1 +0,0 @@
1b5037bba807e51f9f9806aa25e4e4a18475e10245cb9df956b023739f5bd1c8

View File

@@ -1,20 +0,0 @@
头罩视野
winexe
C#
.cs
D:\work\hoodFieldOfView\头罩视野slove\头罩视野\obj\Debug\net10.0-windows\
头罩视野
none
false
TRACE;DEBUG;NET;NET10_0;NETCOREAPP;WINDOWS;WINDOWS7_0;NET5_0_OR_GREATER;NET6_0_OR_GREATER;NET7_0_OR_GREATER;NET8_0_OR_GREATER;NET9_0_OR_GREATER;NET10_0_OR_GREATER;NETCOREAPP3_0_OR_GREATER;NETCOREAPP3_1_OR_GREATER;WINDOWS7_0_OR_GREATER
D:\work\hoodFieldOfView\头罩视野slove\头罩视野\App.xaml
91871649718
23-2095027487
2291904981109
MainWindow.xaml;Views\ChangeLanguage.xaml;Views\Help.xaml;Views\PageTest.xaml;Views\RecordDate.xaml;Views\RecordPage.xaml;Views\SetPassWord.xaml;Views\SetTime.xaml;Views\VisiData.xaml;
False