This commit is contained in:
wxt
2026-01-16 12:00:20 +08:00
parent da979e6d0a
commit 28a817bc8c
13 changed files with 615 additions and 238 deletions

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>

40
WindowsFormsApp1/Form1.Designer.cs generated Normal file
View File

@@ -0,0 +1,40 @@
namespace WindowsFormsApp1
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}

20
WindowsFormsApp1/Form1.cs Normal file
View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
internal static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}

View File

@@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("WindowsFormsApp1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WindowsFormsApp1")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("9171ed81-4c92-4d3b-94db-57b0162bd09b")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,71 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本: 4.0.30319.42000
//
// 对此文件的更改可能导致不正确的行为,如果
// 重新生成代码,则所做更改将丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace WindowsFormsApp1.Properties
{
/// <summary>
/// 强类型资源类,用于查找本地化字符串等。
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
}
/// <summary>
/// 返回此类使用的缓存 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WindowsFormsApp1.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 重写当前线程的 CurrentUICulture 属性,对
/// 使用此强类型资源类的所有资源查找执行重写。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
}
}

View File

@@ -0,0 +1,30 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace WindowsFormsApp1.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
return defaultInstance;
}
}
}
}

View File

@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9171ED81-4C92-4D3B-94DB-57B0162BD09B}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>WindowsFormsApp1</RootNamespace>
<AssemblyName>WindowsFormsApp1</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36717.8 d17.14
VisualStudioVersion = 17.14.36717.8
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "全自动水压检测仪", "全自动水压检测仪\全自动水压检测仪.csproj", "{B8367B3D-2438-4D0F-A253-56F2BC5A415F}"
EndProject

View File

@@ -4,6 +4,7 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Net.Sockets;
@@ -19,8 +20,6 @@ namespace 全自动水压检测仪
{
public partial class Coeffiicientsetting : UIForm
{
//private Coeffiicientsetting _coeffiicientsetting;
private HighTemperatureMode _highTemperatureMode;
private NormalTemperatureMode _normalTemperatureMode;
private TcpClient _tcpClient => ModbusResourceManager.Instance.TcpClient;
@@ -111,6 +110,8 @@ namespace 全自动水压检测仪
{
await ReadRegisterAndUpdateUIAsync(config);
}
await ReadButtonStatusAsync();
}
catch (Exception ex)
{
@@ -158,11 +159,48 @@ namespace 全自动水压检测仪
}
}
private async Task ReadButtonStatusAsync()
{
try
{
// 读取水循环状态 - 地址0
bool[] waterStatus = await Task.Run(() =>
_modbusMaster?.ReadCoils(1, 0, 1));
// 读取恒压启动状态 - 地址110
bool[] pressureStatus = await Task.Run(() =>
_modbusMaster?.ReadCoils(1, 110, 1));
this.Invoke(new Action(() =>
{
// 更新水循环按钮
if (waterStatus != null && waterStatus.Length > 0)
{
bool isWaterOn = waterStatus[0];
uiButton2.ForeColor = isWaterOn ? Color.Red : Color.White;
uiButton2.Text = isWaterOn ? "水循环中" : "水循环";
}
// 更新恒压启动按钮
if (pressureStatus != null && pressureStatus.Length > 0)
{
bool isPressureOn = pressureStatus[0];
uiButton3.ForeColor = isPressureOn ? Color.Red : Color.White;
uiButton3.Text = isPressureOn ? "恒压启动中" : "恒压启动";
}
}));
}
catch(Exception ex)
{
Debug.WriteLine($"[错误] 更新按钮状态失败: {ex.Message}");
}
}
private void Coeffiicientsetting_Load(object sender, EventArgs e)
{
//string plcIp = "192.168.1.10";
string plcIp = "127.0.0.1";
string plcIp = "192.168.1.10";
//string plcIp = "127.0.0.1";
bool initSuccess = Data.ModbusResourceManager.Instance.Init(plcIp, 502);
if (!initSuccess)
{
@@ -182,19 +220,6 @@ namespace 全自动水压检测仪
c = new DataChange();
}
private void ShowErrorMsg(string msg)
{
// 判断当前线程是否是UI线程避免跨线程访问控件异常
if (this.InvokeRequired)
{
// 跨线程时通过Invoke切换到UI线程执行
this.Invoke(new Action<string>(ShowErrorMsg), msg);
return;
}
// UI线程直接显示错误提示框
MessageBox.Show(msg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private bool TryReconnect()
{
@@ -210,7 +235,7 @@ namespace 全自动水压检测仪
}
catch (Exception ex)
{
ShowErrorMsg($"重新连接失败:{ex.Message}");
MessageBox.Show($"重新连接失败:{ex.Message}");
}
return false;
}
@@ -225,13 +250,13 @@ namespace 全自动水压检测仪
// 2. 检查资源是否可用(添加重连机制)
if (_tcpClient == null || !_tcpClient.Connected || _modbusMaster == null)
{
// 尝试重新连接
//bool reconnectSuccess = TryReconnect();
//if (!reconnectSuccess)
//{
// MessageBox.Show("TCP连接已断开请重新连接", "提示");
// return;
//}
//尝试重新连接
bool reconnectSuccess = TryReconnect();
if (!reconnectSuccess)
{
MessageBox.Show("TCP连接已断开请重新连接", "提示");
return;
}
}
// 3. 复用窗口实例:不存在则创建,存在则激活
@@ -280,7 +305,6 @@ namespace 全自动水压检测仪
private void Coeffiicientsetting_FormClosed(object sender, FormClosedEventArgs e)
{
_highTemperatureMode?.Dispose();
_normalTemperatureMode?.Dispose();
}
@@ -377,42 +401,18 @@ namespace 全自动水压检测仪
ma?.WriteToPLCForNew(uiTextBox17.Text.Trim(), 300, Function.DataType.);
}
private bool _isWaterCycleOn = false;
private bool _isConstantPressureOn = false;
//水循环
private void uiButton2_Click(object sender, EventArgs e)
{
_isWaterCycleOn = !_isWaterCycleOn; // 切换状态
{
if (_isWaterCycleOn)
{
uiButton2.ForeColor = Color.Red;
uiButton2.Text = "水循环中";
}
else
{
uiButton2.ForeColor = Color.White;
uiButton2.Text = "水循环";
}
ma?.BtnClickFunctionForNew(Function.ButtonType., 0);//水循环
ma?.BtnClickFunctionForNew(Function.ButtonType., 0);
}
//恒压启动
private void uiButton3_Click(object sender, EventArgs e)
{
_isConstantPressureOn = !_isConstantPressureOn; // 切换状态
if (_isConstantPressureOn)
{
uiButton3.ForeColor = Color.Red;
uiButton3.Text = "恒压启动中";
}
else
{
uiButton3.ForeColor = Color.White;
uiButton3.Text = "恒压启动";
}
ma?.BtnClickFunctionForNew(Function.ButtonType., 110);//恒压启动
ma?.BtnClickFunctionForNew(Function.ButtonType., 110);
}
}
}

View File

@@ -47,6 +47,7 @@ namespace 全自动水压检测仪
this.uiTableLayoutPanel3 = new Sunny.UI.UITableLayoutPanel();
this.uiPanel6 = new Sunny.UI.UIPanel();
this.uiButton1 = new Sunny.UI.UIButton();
this.uiButton11 = new Sunny.UI.UIButton();
this.uiTableLayoutPanel5 = new Sunny.UI.UITableLayoutPanel();
this.uiPanel9 = new Sunny.UI.UIPanel();
this.uiTableLayoutPanel6 = new Sunny.UI.UITableLayoutPanel();
@@ -132,6 +133,7 @@ namespace 全自动水压检测仪
this.uiPanel13 = new Sunny.UI.UIPanel();
this.uiTableLayoutPanel9 = new Sunny.UI.UITableLayoutPanel();
this.uiPanel14 = new Sunny.UI.UIPanel();
this.uiButton5 = new Sunny.UI.UIButton();
this.uiLabel48 = new Sunny.UI.UILabel();
this.uiTextBox9 = new Sunny.UI.UITextBox();
this.uiLabel35 = new Sunny.UI.UILabel();
@@ -147,7 +149,6 @@ namespace 全自动水压检测仪
this.uiLabel36 = new Sunny.UI.UILabel();
this.uiTextBox3 = new Sunny.UI.UITextBox();
this.uiTextBox5 = new Sunny.UI.UITextBox();
this.uiButton11 = new Sunny.UI.UIButton();
this.uiLabel41 = new Sunny.UI.UILabel();
this.uiLabel4 = new Sunny.UI.UILabel();
this.uiButton13 = new Sunny.UI.UIButton();
@@ -259,6 +260,7 @@ namespace 全自动水压检测仪
this.panel1.Controls.Add(this.uiPanel29);
this.panel1.Controls.Add(this.uiPanel7);
this.panel1.Controls.Add(this.uiPanel5);
this.panel1.Controls.Add(this.uiButton11);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(780, 8);
this.panel1.Name = "panel1";
@@ -498,6 +500,22 @@ namespace 全自动水压检测仪
this.uiButton1.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiButton1.Click += new System.EventHandler(this.uiButton1_Click);
//
// uiButton11
//
this.uiButton11.Cursor = System.Windows.Forms.Cursors.Hand;
this.uiButton11.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(70)))), ((int)(((byte)(130)))), ((int)(((byte)(240)))));
this.uiButton11.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(90)))), ((int)(((byte)(150)))), ((int)(((byte)(255)))));
this.uiButton11.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(60)))), ((int)(((byte)(120)))), ((int)(((byte)(220)))));
this.uiButton11.Font = new System.Drawing.Font("微软雅黑", 14F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiButton11.Location = new System.Drawing.Point(46, 542);
this.uiButton11.MinimumSize = new System.Drawing.Size(1, 1);
this.uiButton11.Name = "uiButton11";
this.uiButton11.Size = new System.Drawing.Size(100, 60);
this.uiButton11.TabIndex = 0;
this.uiButton11.Text = "系统排气";
this.uiButton11.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiButton11.Click += new System.EventHandler(this.uiButton11_Click_1);
//
// uiTableLayoutPanel5
//
this.uiTableLayoutPanel5.ColumnCount = 1;
@@ -1040,7 +1058,7 @@ namespace 全自动水压检测仪
this.uiLabel39.Name = "uiLabel39";
this.uiLabel39.Size = new System.Drawing.Size(121, 30);
this.uiLabel39.TabIndex = 0;
this.uiLabel39.Text = "出口温度(°):";
this.uiLabel39.Text = "出口温度(°C):";
this.uiLabel39.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// uiLabel40
@@ -1091,7 +1109,7 @@ namespace 全自动水压检测仪
this.uiLabel43.Name = "uiLabel43";
this.uiLabel43.Size = new System.Drawing.Size(121, 30);
this.uiLabel43.TabIndex = 0;
this.uiLabel43.Text = "箱体温度(°):";
this.uiLabel43.Text = "箱体温度(°C):";
this.uiLabel43.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// uiLabel44
@@ -1330,7 +1348,7 @@ namespace 全自动水压检测仪
//
this.uiLabel8.Font = new System.Drawing.Font("微软雅黑", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiLabel8.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
this.uiLabel8.Location = new System.Drawing.Point(-1, 3);
this.uiLabel8.Location = new System.Drawing.Point(-2, 3);
this.uiLabel8.Name = "uiLabel8";
this.uiLabel8.Size = new System.Drawing.Size(139, 30);
this.uiLabel8.TabIndex = 0;
@@ -1381,7 +1399,7 @@ namespace 全自动水压检测仪
//
this.uiLabel16.Font = new System.Drawing.Font("微软雅黑", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiLabel16.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(80)))), ((int)(((byte)(80)))));
this.uiLabel16.Location = new System.Drawing.Point(-1, 3);
this.uiLabel16.Location = new System.Drawing.Point(-2, 3);
this.uiLabel16.Name = "uiLabel16";
this.uiLabel16.Size = new System.Drawing.Size(139, 30);
this.uiLabel16.TabIndex = 0;
@@ -1719,6 +1737,7 @@ namespace 全自动水压检测仪
//
// uiPanel14
//
this.uiPanel14.Controls.Add(this.uiButton5);
this.uiPanel14.Controls.Add(this.uiLabel48);
this.uiPanel14.Controls.Add(this.uiTextBox9);
this.uiPanel14.Controls.Add(this.uiLabel35);
@@ -1734,7 +1753,6 @@ namespace 全自动水压检测仪
this.uiPanel14.Controls.Add(this.uiLabel36);
this.uiPanel14.Controls.Add(this.uiTextBox3);
this.uiPanel14.Controls.Add(this.uiTextBox5);
this.uiPanel14.Controls.Add(this.uiButton11);
this.uiPanel14.Controls.Add(this.uiLabel41);
this.uiPanel14.Controls.Add(this.uiLabel4);
this.uiPanel14.Controls.Add(this.uiButton13);
@@ -1752,11 +1770,27 @@ namespace 全自动水压检测仪
this.uiPanel14.Text = null;
this.uiPanel14.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
//
// uiButton5
//
this.uiButton5.Cursor = System.Windows.Forms.Cursors.Hand;
this.uiButton5.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(70)))), ((int)(((byte)(130)))), ((int)(((byte)(240)))));
this.uiButton5.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(90)))), ((int)(((byte)(150)))), ((int)(((byte)(255)))));
this.uiButton5.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(60)))), ((int)(((byte)(120)))), ((int)(((byte)(220)))));
this.uiButton5.Font = new System.Drawing.Font("微软雅黑", 14F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiButton5.Location = new System.Drawing.Point(358, 52);
this.uiButton5.MinimumSize = new System.Drawing.Size(1, 1);
this.uiButton5.Name = "uiButton5";
this.uiButton5.Size = new System.Drawing.Size(100, 60);
this.uiButton5.TabIndex = 3;
this.uiButton5.Text = "高温加水";
this.uiButton5.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiButton5.Click += new System.EventHandler(this.uiButton5_Click);
//
// uiLabel48
//
this.uiLabel48.Font = new System.Drawing.Font("微软雅黑", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiLabel48.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
this.uiLabel48.Location = new System.Drawing.Point(484, 52);
this.uiLabel48.Location = new System.Drawing.Point(246, 14);
this.uiLabel48.Name = "uiLabel48";
this.uiLabel48.Size = new System.Drawing.Size(122, 30);
this.uiLabel48.TabIndex = 14;
@@ -1767,7 +1801,7 @@ namespace 全自动水压检测仪
//
this.uiTextBox9.Cursor = System.Windows.Forms.Cursors.IBeam;
this.uiTextBox9.Font = new System.Drawing.Font("微软雅黑", 10.5F);
this.uiTextBox9.Location = new System.Drawing.Point(606, 52);
this.uiTextBox9.Location = new System.Drawing.Point(368, 14);
this.uiTextBox9.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiTextBox9.MinimumSize = new System.Drawing.Size(1, 16);
this.uiTextBox9.Name = "uiTextBox9";
@@ -1784,8 +1818,8 @@ namespace 全自动水压检测仪
// uiLabel35
//
this.uiLabel35.Font = new System.Drawing.Font("微软雅黑", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiLabel35.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
this.uiLabel35.Location = new System.Drawing.Point(92, 131);
this.uiLabel35.ForeColor = System.Drawing.Color.Red;
this.uiLabel35.Location = new System.Drawing.Point(62, 131);
this.uiLabel35.Name = "uiLabel35";
this.uiLabel35.Size = new System.Drawing.Size(79, 30);
this.uiLabel35.TabIndex = 2;
@@ -1807,7 +1841,7 @@ namespace 全自动水压检测仪
//
this.uiTextBox2.Cursor = System.Windows.Forms.Cursors.IBeam;
this.uiTextBox2.Font = new System.Drawing.Font("微软雅黑", 10.5F);
this.uiTextBox2.Location = new System.Drawing.Point(171, 132);
this.uiTextBox2.Location = new System.Drawing.Point(141, 132);
this.uiTextBox2.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiTextBox2.MinimumSize = new System.Drawing.Size(1, 16);
this.uiTextBox2.Name = "uiTextBox2";
@@ -1823,8 +1857,8 @@ namespace 全自动水压检测仪
// uiLabel46
//
this.uiLabel46.Font = new System.Drawing.Font("微软雅黑", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiLabel46.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
this.uiLabel46.Location = new System.Drawing.Point(247, 52);
this.uiLabel46.ForeColor = System.Drawing.Color.Red;
this.uiLabel46.Location = new System.Drawing.Point(508, 46);
this.uiLabel46.Name = "uiLabel46";
this.uiLabel46.Size = new System.Drawing.Size(104, 30);
this.uiLabel46.TabIndex = 10;
@@ -1853,7 +1887,7 @@ namespace 全自动水压检测仪
//
this.uiTextBox7.Cursor = System.Windows.Forms.Cursors.IBeam;
this.uiTextBox7.Font = new System.Drawing.Font("微软雅黑", 10.5F);
this.uiTextBox7.Location = new System.Drawing.Point(358, 52);
this.uiTextBox7.Location = new System.Drawing.Point(619, 46);
this.uiTextBox7.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiTextBox7.MinimumSize = new System.Drawing.Size(1, 16);
this.uiTextBox7.Name = "uiTextBox7";
@@ -1869,8 +1903,8 @@ namespace 全自动水压检测仪
// uiLabel47
//
this.uiLabel47.Font = new System.Drawing.Font("微软雅黑", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiLabel47.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
this.uiLabel47.Location = new System.Drawing.Point(502, 12);
this.uiLabel47.ForeColor = System.Drawing.Color.Red;
this.uiLabel47.Location = new System.Drawing.Point(508, 132);
this.uiLabel47.Name = "uiLabel47";
this.uiLabel47.Size = new System.Drawing.Size(104, 30);
this.uiLabel47.TabIndex = 8;
@@ -1881,7 +1915,7 @@ namespace 全自动水压检测仪
//
this.uiTextBox8.Cursor = System.Windows.Forms.Cursors.IBeam;
this.uiTextBox8.Font = new System.Drawing.Font("微软雅黑", 10.5F);
this.uiTextBox8.Location = new System.Drawing.Point(606, 12);
this.uiTextBox8.Location = new System.Drawing.Point(619, 132);
this.uiTextBox8.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiTextBox8.MinimumSize = new System.Drawing.Size(1, 16);
this.uiTextBox8.Name = "uiTextBox8";
@@ -1897,8 +1931,8 @@ namespace 全自动水压检测仪
// uiLabel45
//
this.uiLabel45.Font = new System.Drawing.Font("微软雅黑", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiLabel45.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
this.uiLabel45.Location = new System.Drawing.Point(247, 94);
this.uiLabel45.ForeColor = System.Drawing.Color.Red;
this.uiLabel45.Location = new System.Drawing.Point(508, 89);
this.uiLabel45.Name = "uiLabel45";
this.uiLabel45.Size = new System.Drawing.Size(104, 30);
this.uiLabel45.TabIndex = 6;
@@ -1909,7 +1943,7 @@ namespace 全自动水压检测仪
//
this.uiTextBox6.Cursor = System.Windows.Forms.Cursors.IBeam;
this.uiTextBox6.Font = new System.Drawing.Font("微软雅黑", 10.5F);
this.uiTextBox6.Location = new System.Drawing.Point(358, 94);
this.uiTextBox6.Location = new System.Drawing.Point(619, 89);
this.uiTextBox6.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiTextBox6.MinimumSize = new System.Drawing.Size(1, 16);
this.uiTextBox6.Name = "uiTextBox6";
@@ -1925,8 +1959,8 @@ namespace 全自动水压检测仪
// uiLabel36
//
this.uiLabel36.Font = new System.Drawing.Font("微软雅黑", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiLabel36.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
this.uiLabel36.Location = new System.Drawing.Point(247, 12);
this.uiLabel36.ForeColor = System.Drawing.Color.Red;
this.uiLabel36.Location = new System.Drawing.Point(508, 5);
this.uiLabel36.Name = "uiLabel36";
this.uiLabel36.Size = new System.Drawing.Size(104, 30);
this.uiLabel36.TabIndex = 4;
@@ -1937,7 +1971,7 @@ namespace 全自动水压检测仪
//
this.uiTextBox3.Cursor = System.Windows.Forms.Cursors.IBeam;
this.uiTextBox3.Font = new System.Drawing.Font("微软雅黑", 10.5F);
this.uiTextBox3.Location = new System.Drawing.Point(358, 12);
this.uiTextBox3.Location = new System.Drawing.Point(619, 5);
this.uiTextBox3.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiTextBox3.MinimumSize = new System.Drawing.Size(1, 16);
this.uiTextBox3.Name = "uiTextBox3";
@@ -1968,22 +2002,6 @@ namespace 全自动水压检测仪
this.uiTextBox5.Watermark = "";
this.uiTextBox5.Click += new System.EventHandler(this.uiTextBox5_Click);
//
// uiButton11
//
this.uiButton11.Cursor = System.Windows.Forms.Cursors.Hand;
this.uiButton11.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(70)))), ((int)(((byte)(130)))), ((int)(((byte)(240)))));
this.uiButton11.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(90)))), ((int)(((byte)(150)))), ((int)(((byte)(255)))));
this.uiButton11.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(60)))), ((int)(((byte)(120)))), ((int)(((byte)(220)))));
this.uiButton11.Font = new System.Drawing.Font("微软雅黑", 14F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiButton11.Location = new System.Drawing.Point(610, 88);
this.uiButton11.MinimumSize = new System.Drawing.Size(1, 1);
this.uiButton11.Name = "uiButton11";
this.uiButton11.Size = new System.Drawing.Size(110, 66);
this.uiButton11.TabIndex = 0;
this.uiButton11.Text = "系统排气";
this.uiButton11.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiButton11.Click += new System.EventHandler(this.uiButton11_Click_1);
//
// uiLabel41
//
this.uiLabel41.Font = new System.Drawing.Font("微软雅黑", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
@@ -2013,12 +2031,12 @@ namespace 全自动水压检测仪
this.uiButton13.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(90)))), ((int)(((byte)(150)))), ((int)(((byte)(255)))));
this.uiButton13.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(60)))), ((int)(((byte)(120)))), ((int)(((byte)(220)))));
this.uiButton13.Font = new System.Drawing.Font("微软雅黑", 14F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiButton13.Location = new System.Drawing.Point(484, 90);
this.uiButton13.Location = new System.Drawing.Point(246, 52);
this.uiButton13.MinimumSize = new System.Drawing.Size(1, 1);
this.uiButton13.Name = "uiButton13";
this.uiButton13.Size = new System.Drawing.Size(110, 66);
this.uiButton13.Size = new System.Drawing.Size(100, 60);
this.uiButton13.TabIndex = 1;
this.uiButton13.Text = "系统加水";
this.uiButton13.Text = "常温加水";
this.uiButton13.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiButton13.Click += new System.EventHandler(this.uiButton13_Click);
//
@@ -2452,6 +2470,7 @@ namespace 全自动水压检测仪
private Sunny.UI.UITextBox uiTextBox6;
private Sunny.UI.UILabel uiLabel48;
private Sunny.UI.UITextBox uiTextBox9;
private Sunny.UI.UIButton uiButton5;
}
}

View File

@@ -1,4 +1,5 @@
using Modbus.Device;
using Microsoft.Win32;
using Modbus.Device;
using Sunny.UI;
using System;
using System.Collections.Generic;
@@ -11,6 +12,7 @@ using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Forms;
using .Data;
using .DATA;
@@ -22,14 +24,16 @@ namespace 全自动水压检测仪
{
BoolSignal boolSignal1 = new BoolSignal();
private Coeffiicientsetting _coeffiicientsetting;
private HighTemperatureMode _highTemperatureMode;
public List<ConductivityTestData> CurrentReport;
private Report _report;
private Stopwatch pressStopwatch;
private const int LONG_PRESS_THRESHOLD = 1000; // 1000毫秒=1秒
#region
private TcpClient _tcpClient => ModbusResourceManager.Instance.TcpClient;
private IModbusMaster _modbusMaster => ModbusResourceManager.Instance.ModbusMaster;
#endregion
Function ma;
DataChange c;
@@ -92,34 +96,26 @@ namespace 全自动水压检测仪
private async System.Threading.Tasks.Task ReadLeakTestParametersAsync()
{
if (_tcpClient == null || !_tcpClient.Connected || _modbusMaster == null)
{
return;
}
if (_tcpClient == null || !_tcpClient.Connected || _modbusMaster == null) return;
try
{
// 核心将CPU/IO密集的Modbus读取操作放到后台线程执行
// 避免阻塞UI线程await等待执行完成
var modbusData = await Task.Run(() =>
{
// 此匿名方法在后台线程执行不能访问UI控件
return new
{
// 读取所有需要的寄存器(同步操作,但是在后台线程)
Real1 = _modbusMaster.ReadHoldingRegisters(1, 1130, 2),
Real2 = _modbusMaster.ReadHoldingRegisters(1, 1080, 2),
Real3 = _modbusMaster.ReadHoldingRegisters(1, 100, 2),
Real4 = _modbusMaster.ReadHoldingRegisters(1, 102, 2),
Real5 = _modbusMaster.ReadHoldingRegisters(1, 104, 2),
Real6 = _modbusMaster.ReadHoldingRegisters(1, 82, 2),
Real7 = _modbusMaster.ReadHoldingRegisters(1, 84, 2),
Real8 = _modbusMaster.ReadHoldingRegisters(1, 86, 2),
Real9 = _modbusMaster.ReadHoldingRegisters(1, 1030, 2),
Real10 = _modbusMaster.ReadHoldingRegisters(1, 1480, 2),
Real11 = _modbusMaster.ReadHoldingRegisters(1, 1180, 2),
//Real12 = _modbusMaster.ReadHoldingRegisters(1, 402, 2),
Real13 = _modbusMaster.ReadHoldingRegisters(1, 412, 2),//出口温度设置
//读取所有需要的寄存器(同步操作,但是在后台线程)
Real1 = _modbusMaster.ReadHoldingRegisters(1, 3130, 2),// 实时压力
Real2 = _modbusMaster.ReadHoldingRegisters(1, 3080, 2),// 常温实时液位
Real3 = _modbusMaster.ReadHoldingRegisters(1, 2100, 2),// 初始压力
Real4 = _modbusMaster.ReadHoldingRegisters(1, 2102, 2),// 结束压力
Real5 = _modbusMaster.ReadHoldingRegisters(1, 2104, 2),// 压差
Real6 = _modbusMaster.ReadHoldingRegisters(1, 2082, 2),// 计时s
Real7 = _modbusMaster.ReadHoldingRegisters(1, 2084, 2),// 计时min
Real8 = _modbusMaster.ReadHoldingRegisters(1, 2086, 2),// 计时h
Real9 = _modbusMaster.ReadHoldingRegisters(1, 3030, 2),// 高温实时液位
Real10 = _modbusMaster.ReadHoldingRegisters(1, 3480, 2),// 箱体温度
Real11 = _modbusMaster.ReadHoldingRegisters(1, 3180, 2),// 出口温度
CurrentTime = DateTime.Now // 后台线程获取时间不影响
};
@@ -173,69 +169,123 @@ namespace 全自动水压检测仪
var value10 = c.UshortToFloat(modbusData.Real11[1], modbusData.Real11[0]);
uiLabel38.Text = value10.ToString("F1");
// 出口温度设置
var value11 = c.UshortToFloat(modbusData.Real13[1], modbusData.Real13[0]);
uiLabel38.Text = value11.ToString("F1");
// 出口温度
//var value12 = c.UshortToFloat(modbusData.Real12[1], modbusData.Real12[0]);
//uiLabel40.Text = value12.ToString("F1");
}
catch (Exception ex)
{
_readTimer.Stop();
MessageBox.Show($"读取调试参数失败:{ex.Message}", "错误",
MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private async System.Threading.Tasks.Task ReadLeakTestParametersAsyncTwo()
{
if (_tcpClient == null || !_tcpClient.Connected || _modbusMaster == null)
{
return;
//是否连接
if (_tcpClient == null || !_tcpClient.Connected || _modbusMaster == null) return;
//测试步
try
{
ushort[] testslip = _modbusMaster?.ReadHoldingRegisters(1, 2080, 2);
if (testslip == null || testslip.Length == 0) return;
int testvalue = testslip[0];
uiLabel3.Text = testvalue.ToString();
}
catch (Exception ex)
{
Debug.WriteLine($"[错误] 读取测试步(地址80)失败: {ex.Message}");
}
//压力设定
try
{
ushort[] registers = await Task.Run(() =>
_modbusMaster?.ReadHoldingRegisters(1, 2400, 2)
);
if (registers == null || registers.Length == 0) return;
float pressureValue = c.UshortToFloat(registers[1], registers[0]);
this.Invoke(new Action(() =>
{
uiTextBox1.Text = pressureValue.ToString("F2");
}));
}
catch (Exception ex)
{
Debug.WriteLine($"[错误] 读取压力设定(地址400)失败: {ex.Message}");
}
//箱体温度
try
{
ushort[] registers = await Task.Run(() =>
_modbusMaster?.ReadHoldingRegisters(1, 2402, 1)
);
if (registers == null || registers.Length == 0) return;
float registerValue = registers[0];
this.Invoke(new Action(() =>
{
uiTextBox4.Text = registerValue.ToString("F2");
}));
}
catch (Exception ex)
{
Debug.WriteLine($"[错误] 读取箱体温度(地址402)失败: {ex.Message}");
}
//保压时间
try
{
ushort[] registers = await Task.Run(() =>
_modbusMaster?.ReadHoldingRegisters(1, 2404, 2)
);
if (registers == null || registers.Length == 0) return;
float pressureValue = c.UshortToFloat(registers[1], registers[0]);
this.Invoke(new Action(() =>
{
uiTextBox5.Text = pressureValue.ToString("F2");
}));
}
catch (Exception ex)
{
Debug.WriteLine($"[错误] 读取保压时间设置(地址404)失败: {ex.Message}");
}
//出口温度设置
try
{
ushort[] registers = await Task.Run(() =>
_modbusMaster?.ReadHoldingRegisters(1, 2412, 2)
);
if (registers == null || registers.Length == 0) return;
float temperatureValue = c.UshortToFloat(registers[1], registers[0]);
this.Invoke(new Action(() =>
{
uiTextBox9.Text = temperatureValue.ToString("F2");
}));
}
catch (Exception ex)
{
Debug.WriteLine($"[错误] 读取出口温度设置(地址412)失败: {ex.Message}");
}
try
{
//测试步
ushort[] testslip = _modbusMaster?.ReadHoldingRegisters(1, 80, 2);
int testvalue = testslip[0];
uiLabel3.Text = testvalue.ToString();
// 读取压力设置 (D-400)
ushort[] set1 = await System.Threading.Tasks.Task.Run(() =>
_modbusMaster?.ReadHoldingRegisters(1, 400, 2)
);
if (set1 != null && set1.Length >= 2)
{
float Value0 = c.UshortToFloat(set1[1], set1[0]);
this.Invoke(new Action(() => uiTextBox1.Text = Value0.ToString("F2")));
}
// 读取压力设置 (D-402)
ushort[] set11 = await System.Threading.Tasks.Task.Run(() =>
_modbusMaster?.ReadHoldingRegisters(1, 402, 1)
);
if (set11 != null && set11.Length >= 1)
{
float Value0 = set11[0];
this.Invoke(new Action(() => uiTextBox4.Text = Value0.ToString("F2")));
}
// 读取测试保压时间 (D-404)
ushort[] set2 = await System.Threading.Tasks.Task.Run(() =>
_modbusMaster?.ReadHoldingRegisters(1, 404, 2)
);
if (set2 != null && set2.Length >= 2)
{
float Value1 = c.UshortToFloat(set2[1], set2[0]);
this.Invoke(new Action(() => uiTextBox5.Text = Value1.ToString("F2")));
}
//测试按钮
bool[] testStatus = _modbusMaster?.ReadCoils(1, 81, 1);
bool[] testStatus = _modbusMaster?.ReadCoils(1, 10081, 1);
if (testStatus[0])
{
uiButton2.Text = "测试中";
@@ -252,7 +302,7 @@ namespace 全自动水压检测仪
boolSignal1.Value = false;
}
//高低温切换
bool[] buttonStatus = _modbusMaster?.ReadCoils(1, 30, 1);
bool[] buttonStatus = _modbusMaster?.ReadCoils(1, 10030, 1);
if (buttonStatus[0])
{
uiSwitch1.Active = false;
@@ -262,7 +312,7 @@ namespace 全自动水压检测仪
uiSwitch1.Active = true;
}
//低温指示
bool[] lowStatus = _modbusMaster?.ReadCoils(1, 31, 1);
bool[] lowStatus = _modbusMaster?.ReadCoils(1, 10031, 1);
if (lowStatus[0])
{
uiLight1.State = UILightState.On;
@@ -272,7 +322,7 @@ namespace 全自动水压检测仪
uiLight1.State = UILightState.Off;
}
//高温指示
bool[] highStatus = _modbusMaster?.ReadCoils(1, 32, 1);
bool[] highStatus = _modbusMaster?.ReadCoils(1, 10032, 1);
if (highStatus[0])
{
uiLight2.State = UILightState.On;
@@ -282,7 +332,7 @@ namespace 全自动水压检测仪
uiLight2.State = UILightState.Off;
}
//进气阀指示
bool[] valve1 = _modbusMaster?.ReadCoils(1, 14, 1);
bool[] valve1 = _modbusMaster?.ReadCoils(1, 10014, 1);
if (valve1[0])
{
uiLight3.State = UILightState.On;
@@ -292,7 +342,7 @@ namespace 全自动水压检测仪
uiLight3.State = UILightState.Off;
}
//测试高压阀指示
bool[] valve2 = _modbusMaster?.ReadCoils(1, 8, 1);
bool[] valve2 = _modbusMaster?.ReadCoils(1, 10008, 1);
if (valve2[0])
{
uiLight4.State = UILightState.On;
@@ -302,7 +352,7 @@ namespace 全自动水压检测仪
uiLight4.State = UILightState.Off;
}
//常温抽水阀指示
bool[] valve3 = _modbusMaster?.ReadCoils(1, 6, 1);
bool[] valve3 = _modbusMaster?.ReadCoils(1, 10006, 1);
if (valve3[0])
{
uiLight5.State = UILightState.On;
@@ -312,17 +362,21 @@ namespace 全自动水压检测仪
uiLight5.State = UILightState.Off;
}
//常温水箱加水阀指示
bool[] valve4 = _modbusMaster?.ReadCoils(1, 13, 1);
bool[] valve4 = _modbusMaster?.ReadCoils(1, 10013, 1);
if (valve4[0])
{
uiLight6.State = UILightState.On;
uiButton13.ForeColor = Color.Red;
uiButton13.Text = "常温加水中";
}
else
{
uiLight6.State = UILightState.Off;
uiButton13.ForeColor = Color.White;
uiButton13.Text = "常温加水";
}
//高温抽水阀指示
bool[] valve5 = _modbusMaster?.ReadCoils(1, 5, 1);
bool[] valve5 = _modbusMaster?.ReadCoils(1, 10005, 1);
if (valve5[0])
{
uiLight7.State = UILightState.On;
@@ -332,7 +386,7 @@ namespace 全自动水压检测仪
uiLight7.State = UILightState.Off;
}
//空气抽气阀指示
bool[] valve6 = _modbusMaster?.ReadCoils(1, 7, 1);
bool[] valve6 = _modbusMaster?.ReadCoils(1, 10007, 1);
if (valve6[0])
{
uiLight8.State = UILightState.On;
@@ -342,9 +396,17 @@ namespace 全自动水压检测仪
uiLight8.State = UILightState.Off;
}
//升温阀
bool[] valve7 = _modbusMaster?.ReadCoils(1, 10004, 1);
if (valve7[0])
{
uiLight9.State = UILightState.On;
}
else
{
uiLight9.State = UILightState.Off;
}
//常温回水阀指示
bool[] valve8 = _modbusMaster?.ReadCoils(1, 10, 1);
bool[] valve8 = _modbusMaster?.ReadCoils(1, 10010, 1);
if (valve8[0])
{
uiLight10.State = UILightState.On;
@@ -354,17 +416,21 @@ namespace 全自动水压检测仪
uiLight10.State = UILightState.Off;
}
//高温水箱加水阀指示
bool[] valve9 = _modbusMaster?.ReadCoils(1, 12, 1);
bool[] valve9 = _modbusMaster?.ReadCoils(1, 10012, 1);
if (valve9[0])
{
uiLight11.State = UILightState.On;
uiButton5.ForeColor = Color.Red;
uiButton5.Text = "高温加水中";
}
else
{
uiLight11.State = UILightState.Off;
uiButton5.ForeColor = Color.White;
uiButton5.Text = "高温加水";
}
//高温回水阀指示
bool[] valve10 = _modbusMaster?.ReadCoils(1, 9, 1);
bool[] valve10 = _modbusMaster?.ReadCoils(1, 10009, 1);
if (valve10[0])
{
uiLight12.State = UILightState.On;
@@ -373,29 +439,29 @@ namespace 全自动水压检测仪
{
uiLight12.State = UILightState.Off;
}
//系统排水指示
bool[] valve11 = _modbusMaster?.ReadCoils(1, 10070, 1);
if (valve11[0])
{
uiButton11.ForeColor = Color.Red;
uiButton11.Text = "系统排气中";
}
else
{
uiButton11.ForeColor = Color.White;
uiButton11.Text = "系统排气";
}
}
catch (Exception ex)
catch (Exception ex)
{
this.Invoke(new Action(() =>
MessageBox.Show($"读取调试参数失败:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error)));
}
Debug.WriteLine($"[错误] 读取阀门状态失败: {ex.Message}");
}
}
//系数页
//系数页
private void uiButton14_Click(object sender, EventArgs e)
{
//FormManager.Instance.SwitchTo<Coeffiicientsetting>();
SwitchWindow(ref _coeffiicientsetting, () => new Coeffiicientsetting());
}
@@ -473,7 +539,7 @@ namespace 全自动水压检测仪
}
catch (Exception ex)
{
//ShowErrorMsg($"重新连接失败:{ex.Message}");
Debug.WriteLine($"[错误] 重连失败: {ex.Message}");
}
return false;
}
@@ -536,44 +602,34 @@ namespace 全自动水压检测仪
private void NormalTemperatureMode_FormClosed_1(object sender, FormClosedEventArgs e)
{
_coeffiicientsetting?.Dispose();
_highTemperatureMode?.Dispose();
}
//压力设置
private void uiTextBox1_Click(object sender, EventArgs e)
{
ma?.WriteToPLCForNew(uiTextBox1.Text.Trim(), 400, Function.DataType.);
ma?.WriteToPLCForNew(uiTextBox1.Text.Trim(), 2400, Function.DataType.);
}
//测试保压时间设置
private void uiTextBox5_Click(object sender, EventArgs e)
{
ma?.WriteToPLCForNew(uiTextBox5.Text.Trim(), 404, Function.DataType.);
ma?.WriteToPLCForNew(uiTextBox5.Text.Trim(), 2404, Function.DataType.);
}
private bool isbt11on=false;
private bool isbt13on = false;
#region
//系统排气
private void uiButton11_Click_1(object sender, EventArgs e)
{
ToggleButtonWithText(uiButton11, ref isbt11on, "系统排气中", "系统排气");
ma?.BtnClickFunctionForNew(Function.ButtonType., 70);
ma?.BtnClickFunctionForNew(Function.ButtonType., 10070);
}
//系统加水
//常温加水
private void uiButton13_Click(object sender, EventArgs e)
{
ToggleButtonWithText(uiButton13, ref isbt13on, "系统加水中", "系统加水");
ma?.BtnClickFunctionForNew(Function.ButtonType., 11);
{
ma?.BtnClickFunctionForNew(Function.ButtonType., 10013);
}
private void ToggleButtonWithText(UIButton button, ref bool state, string onText, string offText)
{
state = !state;
button.ForeColor = state ? Color.Red : Color.White;
button.Text = state ? onText : offText;
}
//隐藏
private void uiButton14_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
@@ -581,7 +637,6 @@ namespace 全自动水压检测仪
pressStopwatch.Restart();
}
}
private void uiButton14_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
@@ -599,43 +654,53 @@ namespace 全自动水压检测仪
//}
}
}
private void EnterFunction()
{
// 长按后进入的功能
SwitchWindow(ref _coeffiicientsetting, () => new Coeffiicientsetting());
}
//切换报告界面
private void uiButton1_Click(object sender, EventArgs e)
{
SwitchWindow(ref _report, () => new Report(CurrentReport));
}
//箱体温度设置
private void uiTextBox4_Click(object sender, EventArgs e)
{
ma?.WriteToPLCForNew(uiTextBox4.Text.Trim(), 402, Function.DataType.);
ma?.WriteToPLCForNew(uiTextBox4.Text.Trim(), 2402, Function.DataType.);
}
//启动测试
private void uiButton2_Click(object sender, EventArgs e)
{
ma?.BtnClickFunctionForNew(Function.ButtonType., 80);//启动测试
ma?.BtnClickFunctionForNew(Function.ButtonType., 10080);
}
//停止测试
private void uiButton3_Click(object sender, EventArgs e)
{
ma?.BtnClickFunctionForNew(Function.ButtonType., 82);//停止测试
ma?.BtnClickFunctionForNew(Function.ButtonType., 10082);
}
//切换实验模式
private void uiSwitch1_Click(object sender, EventArgs e)
{
ma?.BtnClickFunctionForNew(Function.ButtonType., 30);//切换模式
ma?.BtnClickFunctionForNew(Function.ButtonType., 10030);
}
//出口温度设置
private void uiTextBox9_Click(object sender, EventArgs e)
{
ma?.WriteToPLCForNew(uiTextBox9.Text.Trim(), 412, Function.DataType.);//出口温度设置
ma?.WriteToPLCForNew(uiTextBox9.Text.Trim(), 2412, Function.DataType.);
}
//高温加水
private void uiButton5_Click(object sender, EventArgs e)
{
ma?.BtnClickFunctionForNew(Function.ButtonType., 10012);
}
#endregion
}
}

View File

@@ -130,12 +130,6 @@
<Compile Include="DATA\LoginData.cs" />
<Compile Include="DATA\ModbusResourceManager.cs" />
<Compile Include="DATA\PLC_Data.cs" />
<Compile Include="HighTemperatureMode.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="HighTemperatureMode.Designer.cs">
<DependentUpon>HighTemperatureMode.cs</DependentUpon>
</Compile>
<Compile Include="NormalTemperatureMode.cs">
<SubType>Form</SubType>
</Compile>
@@ -153,9 +147,6 @@
<EmbeddedResource Include="Coeffiicientsetting.resx">
<DependentUpon>Coeffiicientsetting.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="HighTemperatureMode.resx">
<DependentUpon>HighTemperatureMode.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="NormalTemperatureMode.resx">
<DependentUpon>NormalTemperatureMode.cs</DependentUpon>
</EmbeddedResource>