添加项目文件。

This commit is contained in:
xyy
2026-03-11 15:21:27 +08:00
parent c0e2ea6482
commit 34083df6de
66 changed files with 8066 additions and 0 deletions

34
Data/BaseWindow.xaml.cs Normal file
View File

@@ -0,0 +1,34 @@
using Modbus.Device;
using System;
using System.Net.Sockets;
using System.Windows;
namespace .Data
{
public partial class BaseWindow : Window
{
// 共享资源(从管理器获取,不自己创建)
protected TcpClient _tcpClient => ModbusResourceManager.Instance.TcpClient;
protected IModbusMaster _modbusMaster => ModbusResourceManager.Instance.ModbusMaster;
protected System.Timers.Timer _readTimer { get; set; } = new System.Timers.Timer();
// 窗口关闭时仅停止定时器,不释放资源(资源由管理器统一释放)
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
_readTimer?.Stop();
_readTimer?.Dispose();
}
// 检查资源是否可用(避免空引用报错)
protected bool CheckResourceAvailable()
{
if (_tcpClient == null || !_tcpClient.Connected || _modbusMaster == null)
{
MessageBox.Show("TCP连接已断开请重新初始化连接", "提示");
return false;
}
return true;
}
}
}