This commit is contained in:
wxt
2026-01-14 20:46:30 +08:00
parent 679c605009
commit 52ad6ec4cc
4 changed files with 835 additions and 712 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -81,7 +81,6 @@ namespace 全自动水压检测仪
try
{
// 配置所有寄存器映射关系(统一管理,便于维护)
var registerConfigs = new List<RegisterConfig>
{
CreateRegisterConfig(394, uiTextBox1, "F2",false), // 控制压力系数
@@ -96,6 +95,7 @@ namespace 全自动水压检测仪
CreateRegisterConfig(1026, uiTextBox12, "F2",false), // 高温液位系数
CreateRegisterConfig(1036, uiTextBox11, "F2",false), // 高温液位上限
CreateRegisterConfig(1034, uiTextBox5, "F2",false), // 高温液位下限
CreateRegisterConfig(300, uiTextBox17, "F2",false), // 高温液位下限
CreateRegisterConfig(408, uiTextBox14, "0",true), // 稳压时间
CreateRegisterConfig(406, uiTextBox15, "0",true), // 通水时间
@@ -121,12 +121,6 @@ namespace 全自动水压检测仪
}
}
/// <summary>
/// 辅助方法创建寄存器配置对象适配C# 7.3语法)
/// </summary>
/// <param name="address">寄存器地址</param>
/// <param name="textBox">绑定的SunnyUI文本框</param>
/// <param name="format">数值格式化字符串</param>
private RegisterConfig CreateRegisterConfig(int address, UITextBox textBox, string format, bool isInteger)
{
var config = new RegisterConfig();
@@ -143,25 +137,20 @@ namespace 全自动水压检测仪
/// <param name="config">寄存器配置</param>
private async Task ReadRegisterAndUpdateUIAsync(RegisterConfig config)
{
// 异步读取Modbus寄存器避免阻塞UI线程
ushort[] registers = await Task.Run(() =>
_modbusMaster?.ReadHoldingRegisters(1, config.Address, 2));
// 数据有效性校验 + 区分整数/浮点处理
if (registers != null && registers.Length >= 2)
{
this.Invoke(new Action(() =>
{
if (config.IsInteger)
{
// 整数处理合并两个ushort为32位整数根据Modbus字节序调整
// 注意字节序需匹配设备端此处为registers[1]高位 + registers[0]低位)
int intValue = (registers[1] << 16) | registers[0];
config.TextBox.Text = intValue.ToString(config.Format);
}
else
{
// 浮点处理:保持原有逻辑
float floatValue = c.UshortToFloat(registers[1], registers[0]);
config.TextBox.Text = floatValue.ToString(config.Format);
}
@@ -172,7 +161,8 @@ namespace 全自动水压检测仪
private void Coeffiicientsetting_Load(object sender, EventArgs e)
{
string plcIp = "192.168.1.10";
//string plcIp = "192.168.1.10";
string plcIp = "127.0.0.1";
bool initSuccess = Data.ModbusResourceManager.Instance.Init(plcIp, 502);
if (!initSuccess)
{
@@ -381,5 +371,48 @@ namespace 全自动水压检测仪
{
ma?.WriteToPLCForNew(uiTextBox16.Text.Trim(), 402, Function.DataType.);
}
//转速设置
private void uiTextBox17_Click(object sender, EventArgs e)
{
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);//水循环
}
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);//恒压启动
}
}
}

View File

@@ -163,6 +163,8 @@ namespace 全自动水压检测仪
this.uiPanel2 = new Sunny.UI.UIPanel();
this.uiLabel1 = new Sunny.UI.UILabel();
this.uiLight1 = new Sunny.UI.UILight();
this.uiLabel48 = new Sunny.UI.UILabel();
this.uiTextBox9 = new Sunny.UI.UITextBox();
this.uiTableLayoutPanel1.SuspendLayout();
this.uiTableLayoutPanel2.SuspendLayout();
this.panel1.SuspendLayout();
@@ -327,6 +329,7 @@ namespace 全自动水压检测仪
this.uiSwitch1.Size = new System.Drawing.Size(156, 51);
this.uiSwitch1.TabIndex = 1;
this.uiSwitch1.Text = "uiSwitch1";
this.uiSwitch1.Click += new System.EventHandler(this.uiSwitch1_Click);
//
// uiPanel7
//
@@ -396,6 +399,7 @@ namespace 全自动水压检测仪
this.uiButton3.TabIndex = 2;
this.uiButton3.Text = "停止测试";
this.uiButton3.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiButton3.Click += new System.EventHandler(this.uiButton3_Click);
//
// uiPanel8
//
@@ -427,6 +431,7 @@ namespace 全自动水压检测仪
this.uiButton2.TabIndex = 1;
this.uiButton2.Text = "启动测试";
this.uiButton2.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiButton2.Click += new System.EventHandler(this.uiButton2_Click);
//
// uiPanel5
//
@@ -1714,6 +1719,8 @@ namespace 全自动水压检测仪
//
// uiPanel14
//
this.uiPanel14.Controls.Add(this.uiLabel48);
this.uiPanel14.Controls.Add(this.uiTextBox9);
this.uiPanel14.Controls.Add(this.uiLabel35);
this.uiPanel14.Controls.Add(this.uiLabel37);
this.uiPanel14.Controls.Add(this.uiTextBox2);
@@ -1939,7 +1946,7 @@ namespace 全自动水压检测仪
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, 83);
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);
@@ -1977,7 +1984,7 @@ 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, 85);
this.uiButton13.Location = new System.Drawing.Point(484, 90);
this.uiButton13.MinimumSize = new System.Drawing.Size(1, 1);
this.uiButton13.Name = "uiButton13";
this.uiButton13.Size = new System.Drawing.Size(110, 66);
@@ -2211,6 +2218,35 @@ namespace 全自动水压检测仪
this.uiLight1.TabIndex = 1;
this.uiLight1.Text = "uiLight1";
//
// 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.Name = "uiLabel48";
this.uiLabel48.Size = new System.Drawing.Size(122, 30);
this.uiLabel48.TabIndex = 14;
this.uiLabel48.Text = "出口温度设置(℃):";
this.uiLabel48.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// uiTextBox9
//
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.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiTextBox9.MinimumSize = new System.Drawing.Size(1, 16);
this.uiTextBox9.Name = "uiTextBox9";
this.uiTextBox9.Padding = new System.Windows.Forms.Padding(5);
this.uiTextBox9.Radius = 3;
this.uiTextBox9.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(220)))), ((int)(((byte)(220)))));
this.uiTextBox9.ShowText = false;
this.uiTextBox9.Size = new System.Drawing.Size(91, 28);
this.uiTextBox9.TabIndex = 15;
this.uiTextBox9.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
this.uiTextBox9.Watermark = "";
this.uiTextBox9.Click += new System.EventHandler(this.uiTextBox9_Click);
//
// NormalTemperatureMode
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
@@ -2414,6 +2450,8 @@ namespace 全自动水压检测仪
private Sunny.UI.UITextBox uiTextBox8;
private Sunny.UI.UILabel uiLabel45;
private Sunny.UI.UITextBox uiTextBox6;
private Sunny.UI.UILabel uiLabel48;
private Sunny.UI.UITextBox uiTextBox9;
}
}

View File

@@ -118,7 +118,8 @@ namespace 全自动水压检测仪
Real9 = _modbusMaster.ReadHoldingRegisters(1, 1030, 2),
Real10 = _modbusMaster.ReadHoldingRegisters(1, 1480, 2),
Real11 = _modbusMaster.ReadHoldingRegisters(1, 1180, 2),
Real12 = _modbusMaster.ReadHoldingRegisters(1, 402, 2),
//Real12 = _modbusMaster.ReadHoldingRegisters(1, 402, 2),
Real13 = _modbusMaster.ReadHoldingRegisters(1, 412, 2),//出口温度设置
CurrentTime = DateTime.Now // 后台线程获取时间不影响
};
@@ -172,6 +173,9 @@ 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]);
@@ -397,8 +401,8 @@ namespace 全自动水压检测仪
private void NormalTemperatureMode_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)
{
@@ -546,30 +550,28 @@ namespace 全自动水压检测仪
{
ma?.WriteToPLCForNew(uiTextBox5.Text.Trim(), 404, Function.DataType.);
}
private bool isbt11on=false;
private bool isbt13on = false;
//系统排气
private void uiButton11_Click_1(object sender, EventArgs e)
{
ToggleButtonWithText(uiButton11, ref isbt11on, "系统排气中", "系统排气");
ma?.BtnClickFunctionForNew(Function.ButtonType., 70);
}
//系统加水
private void uiButton13_Click(object sender, EventArgs e)
{
//ma?.BtnClickFunctionForNew(Function.ButtonType.切换型, 11);
ToggleButtonWithText(uiButton13, ref isbt13on, "系统加水中", "系统加水");
ma?.BtnClickFunctionForNew(Function.ButtonType., 11);
}
//高温模式
private void uiSwitch1_Click(object sender, EventArgs e)
private void ToggleButtonWithText(UIButton button, ref bool state, string onText, string offText)
{
ma?.BtnClickFunctionForNew(Function.ButtonType., 30);
}
//测试按钮
private void uiButton2_Click(object sender, EventArgs e)
{
ma?.BtnClickFunctionForNew(Function.ButtonType., 80);
}
//停止按钮
private void uiButton3_Click(object sender, EventArgs e)
{
ma?.BtnClickFunctionForNew(Function.ButtonType., 82);
state = !state;
button.ForeColor = state ? Color.Red : Color.White;
button.Text = state ? onText : offText;
}
private void uiButton14_MouseDown(object sender, MouseEventArgs e)
@@ -613,5 +615,27 @@ namespace 全自动水压检测仪
{
ma?.WriteToPLCForNew(uiTextBox4.Text.Trim(), 402, Function.DataType.);
}
private void uiButton2_Click(object sender, EventArgs e)
{
ma?.BtnClickFunctionForNew(Function.ButtonType., 80);//启动测试
}
private void uiButton3_Click(object sender, EventArgs e)
{
ma?.BtnClickFunctionForNew(Function.ButtonType., 82);//停止测试
}
private void uiSwitch1_Click(object sender, EventArgs e)
{
ma?.BtnClickFunctionForNew(Function.ButtonType., 30);//切换模式
}
private void uiTextBox9_Click(object sender, EventArgs e)
{
ma?.WriteToPLCForNew(uiTextBox9.Text.Trim(), 412, Function.DataType.);//出口温度设置
}
}
}