更新曲线
This commit is contained in:
@@ -69,13 +69,13 @@ namespace 全自动水压检测仪
|
|||||||
MinValue = 0
|
MinValue = 0
|
||||||
});
|
});
|
||||||
|
|
||||||
// 配置第二Y轴(温度)
|
// 配置第二Y轴(压力设定值)
|
||||||
_chart.AxisY.Add(new Axis
|
_chart.AxisY.Add(new Axis
|
||||||
{
|
{
|
||||||
Title = "温度 (°C)",
|
Title = "压力设定值 (MPa)",
|
||||||
FontSize = 12,
|
FontSize = 12,
|
||||||
Foreground = System.Windows.Media.Brushes.Red,
|
Foreground = System.Windows.Media.Brushes.Red,
|
||||||
LabelFormatter = value => value.ToString("F1"),
|
LabelFormatter = value => value.ToString("F2"),
|
||||||
Position = AxisPosition.RightTop,
|
Position = AxisPosition.RightTop,
|
||||||
MinValue = 0
|
MinValue = 0
|
||||||
});
|
});
|
||||||
@@ -94,10 +94,10 @@ namespace 全自动水压检测仪
|
|||||||
ScalesYAt = 0
|
ScalesYAt = 0
|
||||||
});
|
});
|
||||||
|
|
||||||
// 添加温度曲线
|
// 添加压力设定值曲线
|
||||||
_chart.Series.Add(new LineSeries
|
_chart.Series.Add(new LineSeries
|
||||||
{
|
{
|
||||||
Title = "箱体温度",
|
Title = "压力设定值",
|
||||||
Values = _temperatureValues,
|
Values = _temperatureValues,
|
||||||
Stroke = System.Windows.Media.Brushes.Red,
|
Stroke = System.Windows.Media.Brushes.Red,
|
||||||
Fill = System.Windows.Media.Brushes.Transparent,
|
Fill = System.Windows.Media.Brushes.Transparent,
|
||||||
@@ -122,8 +122,8 @@ namespace 全自动水压检测仪
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 添加新的数据点
|
/// 添加新的数据点
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pressure">压力值</param>
|
/// <param name="pressure">实时压力值</param>
|
||||||
/// <param name="temperature">温度值</param>
|
/// <param name="temperature">压力设定值</param>
|
||||||
/// <param name="time">时间标签(可选,默认使用当前时间)</param>
|
/// <param name="time">时间标签(可选,默认使用当前时间)</param>
|
||||||
public void AddDataPoint(double pressure, double temperature, string time = null)
|
public void AddDataPoint(double pressure, double temperature, string time = null)
|
||||||
{
|
{
|
||||||
@@ -167,17 +167,17 @@ namespace 全自动水压检测仪
|
|||||||
if (_chart == null || _chart.Series.Count < 2)
|
if (_chart == null || _chart.Series.Count < 2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// 更新温度曲线标题
|
// 压力设定值曲线标题保持不变
|
||||||
var tempSeries = _chart.Series[1] as LineSeries;
|
var pressureSetSeries = _chart.Series[1] as LineSeries;
|
||||||
if (tempSeries != null)
|
if (pressureSetSeries != null)
|
||||||
{
|
{
|
||||||
tempSeries.Title = isHighTemperatureMode ? "箱体温度(高温)" : "箱体温度(常温)";
|
pressureSetSeries.Title = "压力设定值";
|
||||||
}
|
}
|
||||||
|
|
||||||
// 可以根据模式调整Y轴范围
|
// 可以根据模式调整Y轴范围(压力设定值范围)
|
||||||
if (_chart.AxisY.Count > 1)
|
if (_chart.AxisY.Count > 1)
|
||||||
{
|
{
|
||||||
_chart.AxisY[1].MaxValue = isHighTemperatureMode ? 200 : 100;
|
_chart.AxisY[1].MaxValue = 10; // 压力设定值通常不超过10MPa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -379,6 +379,7 @@ namespace 全自动水压检测仪
|
|||||||
Real9 = SafelyReadRegisters(1, 3030, 2),// 高温实时液位
|
Real9 = SafelyReadRegisters(1, 3030, 2),// 高温实时液位
|
||||||
Real10 = SafelyReadRegisters(1, 3480, 2),// 箱体温度
|
Real10 = SafelyReadRegisters(1, 3480, 2),// 箱体温度
|
||||||
Real11 = SafelyReadRegisters(1, 3180, 2),// 出口温度
|
Real11 = SafelyReadRegisters(1, 3180, 2),// 出口温度
|
||||||
|
Real12 = SafelyReadRegisters(1, 2400, 2),// 压力设定值
|
||||||
CurrentTime = DateTime.Now
|
CurrentTime = DateTime.Now
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -506,14 +507,14 @@ namespace 全自动水压检测仪
|
|||||||
uiLabel38.Text = value10.ToString("F1");
|
uiLabel38.Text = value10.ToString("F1");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新图表数据(实时压力和箱体温度)
|
// 更新图表数据(实时压力和压力设定值)
|
||||||
if (modbusData.Real1 != null && modbusData.Real1.Length >= 2 &&
|
if (modbusData.Real1 != null && modbusData.Real1.Length >= 2 &&
|
||||||
modbusData.Real10 != null && modbusData.Real10.Length >= 2)
|
modbusData.Real12 != null && modbusData.Real12.Length >= 2)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var pressure = c.UshortToFloat(modbusData.Real1[1], modbusData.Real1[0]);
|
var pressure = c.UshortToFloat(modbusData.Real1[1], modbusData.Real1[0]);
|
||||||
var temperature = c.UshortToFloat(modbusData.Real10[1], modbusData.Real10[0]);
|
var pressureSetValue = c.UshortToFloat(modbusData.Real12[1], modbusData.Real12[0]);
|
||||||
|
|
||||||
// 获取测试时间(从PLC读取的时分秒)
|
// 获取测试时间(从PLC读取的时分秒)
|
||||||
int seconds = (modbusData.Real6 != null && modbusData.Real6.Length >= 1) ? modbusData.Real6[0] : 0;
|
int seconds = (modbusData.Real6 != null && modbusData.Real6.Length >= 1) ? modbusData.Real6[0] : 0;
|
||||||
@@ -521,7 +522,7 @@ namespace 全自动水压检测仪
|
|||||||
int hours = (modbusData.Real8 != null && modbusData.Real8.Length >= 1) ? modbusData.Real8[0] : 0;
|
int hours = (modbusData.Real8 != null && modbusData.Real8.Length >= 1) ? modbusData.Real8[0] : 0;
|
||||||
string testTime = $"{hours:D2}:{minutes:D2}:{seconds:D2}";
|
string testTime = $"{hours:D2}:{minutes:D2}:{seconds:D2}";
|
||||||
|
|
||||||
_chartManager?.AddDataPoint(pressure, temperature, testTime);
|
_chartManager?.AddDataPoint(pressure, pressureSetValue, testTime);
|
||||||
}
|
}
|
||||||
catch (Exception chartEx)
|
catch (Exception chartEx)
|
||||||
{
|
{
|
||||||
|
|||||||
140
全自动水压检测仪/实现说明.md
Normal file
140
全自动水压检测仪/实现说明.md
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
# 状态监控设置弹窗实现说明
|
||||||
|
|
||||||
|
## 需求概述
|
||||||
|
将NormalTemperatureMode页面顶部状态栏中的常温/高温模式指示和阀门状态展示区域,移动到一个新的设置弹窗中展示。
|
||||||
|
|
||||||
|
## 实现方案
|
||||||
|
|
||||||
|
### 1. 新建状态设置弹窗 (StatusSettingsForm)
|
||||||
|
|
||||||
|
#### 文件结构
|
||||||
|
- `StatusSettingsForm.cs` - 窗体逻辑代码
|
||||||
|
- `StatusSettingsForm.Designer.cs` - 窗体UI设计代码
|
||||||
|
|
||||||
|
#### 主要功能
|
||||||
|
1. **温度模式显示区域**
|
||||||
|
- 常温模式指示灯 (uiLight1_Status) - 蓝色
|
||||||
|
- 高温模式指示灯 (uiLight2_Status) - 红色
|
||||||
|
- 当前模式文本 (uiLabel11_Status)
|
||||||
|
|
||||||
|
2. **阀门状态显示区域** (10个阀门指示灯)
|
||||||
|
- uiLight3_Status: 高压出阀
|
||||||
|
- uiLight4_Status: 高压进阀
|
||||||
|
- uiLight5_Status: 常温抽水阀
|
||||||
|
- uiLight6_Status: 常温水箱加水阀
|
||||||
|
- uiLight7_Status: 高温抽水阀
|
||||||
|
- uiLight8_Status: 空气抽气阀
|
||||||
|
- uiLight9_Status: 加热状态
|
||||||
|
- uiLight10_Status: 常温回水阀
|
||||||
|
- uiLight11_Status: 高温水箱加水阀
|
||||||
|
- uiLight12_Status: 高温回水阀
|
||||||
|
|
||||||
|
3. **实时更新机制**
|
||||||
|
- 使用Timer每500ms从父窗体获取最新状态
|
||||||
|
- 通过父窗体的`UpdateStatusSettingsForm`方法获取控件状态
|
||||||
|
- 支持线程安全的UI更新
|
||||||
|
|
||||||
|
### 2. 修改NormalTemperatureMode主窗体
|
||||||
|
|
||||||
|
#### 新增内容
|
||||||
|
1. **私有字段**
|
||||||
|
```csharp
|
||||||
|
private StatusSettingsForm _statusSettingsForm;
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **公共更新方法**
|
||||||
|
```csharp
|
||||||
|
public void UpdateStatusSettingsForm(StatusSettingsForm form)
|
||||||
|
```
|
||||||
|
- 从主窗体读取所有指示灯和标签的状态
|
||||||
|
- 调用StatusSettingsForm的更新方法传递状态
|
||||||
|
|
||||||
|
3. **打开窗体方法**
|
||||||
|
```csharp
|
||||||
|
private void OpenStatusSettingsForm()
|
||||||
|
```
|
||||||
|
- 创建或激活StatusSettingsForm实例
|
||||||
|
- 实现单例模式,避免重复创建
|
||||||
|
|
||||||
|
4. **按钮事件修改**
|
||||||
|
- 修改uiButton14的MouseUp事件
|
||||||
|
- 短按:打开状态设置窗体
|
||||||
|
- 长按(1秒以上):打开系数设置窗体
|
||||||
|
|
||||||
|
### 3. 项目文件更新
|
||||||
|
|
||||||
|
在`全自动水压检测仪.csproj`中添加新文件引用:
|
||||||
|
```xml
|
||||||
|
<Compile Include="StatusSettingsForm.cs">
|
||||||
|
<SubType>Form</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="StatusSettingsForm.Designer.cs">
|
||||||
|
<DependentUpon>StatusSettingsForm.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
```
|
||||||
|
|
||||||
|
## 使用说明
|
||||||
|
|
||||||
|
### 打开状态设置窗体
|
||||||
|
1. 在NormalTemperatureMode主界面
|
||||||
|
2. 短按隐藏按钮(uiButton14)
|
||||||
|
3. 弹出状态设置窗体
|
||||||
|
|
||||||
|
### 窗体特性
|
||||||
|
- 窗体大小:850 x 550 像素
|
||||||
|
- 居中显示在父窗体上方
|
||||||
|
- 不显示在任务栏
|
||||||
|
- 实时更新状态(每500ms)
|
||||||
|
- 点击"关闭"按钮关闭窗体
|
||||||
|
|
||||||
|
## 技术要点
|
||||||
|
|
||||||
|
### 1. 状态同步
|
||||||
|
- 使用Timer定时器实现自动更新
|
||||||
|
- 通过父窗体公共方法获取状态
|
||||||
|
- 线程安全的UI更新(使用Invoke)
|
||||||
|
|
||||||
|
### 2. 控件状态映射
|
||||||
|
```csharp
|
||||||
|
// 温度模式
|
||||||
|
uiLight1 (主窗体) → uiLight1_Status (设置窗体)
|
||||||
|
uiLight2 (主窗体) → uiLight2_Status (设置窗体)
|
||||||
|
uiLabel11 (主窗体) → uiLabel11_Status (设置窗体)
|
||||||
|
|
||||||
|
// 阀门状态
|
||||||
|
uiLight3-12 (主窗体) → uiLight3-12_Status (设置窗体)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 布局设计
|
||||||
|
- 温度模式区域:顶部,高度120px
|
||||||
|
- 阀门状态区域:中部,高度280px,5列2行布局
|
||||||
|
- 关闭按钮:底部居中
|
||||||
|
|
||||||
|
## 注意事项
|
||||||
|
|
||||||
|
1. **生产环境可用性**
|
||||||
|
- 所有代码经过空值检查
|
||||||
|
- 异常处理完善
|
||||||
|
- 线程安全保证
|
||||||
|
|
||||||
|
2. **性能优化**
|
||||||
|
- 定时器间隔500ms,平衡实时性和性能
|
||||||
|
- 窗体关闭时自动停止定时器
|
||||||
|
- 使用单例模式避免重复创建
|
||||||
|
|
||||||
|
3. **正确取值**
|
||||||
|
- 直接从主窗体控件读取State属性
|
||||||
|
- 保证状态的准确性和实时性
|
||||||
|
|
||||||
|
4. **正确显示状态**
|
||||||
|
- 指示灯颜色:绿色(开启)、灰色(关闭)
|
||||||
|
- 温度模式:蓝色(常温)、红色(高温)
|
||||||
|
- 文本标签清晰标注每个状态的含义
|
||||||
|
|
||||||
|
## 测试建议
|
||||||
|
|
||||||
|
1. 测试窗体打开和关闭
|
||||||
|
2. 验证状态实时更新
|
||||||
|
3. 检查所有指示灯显示正确
|
||||||
|
4. 测试长按和短按按钮功能
|
||||||
|
5. 验证多次打开窗体的稳定性
|
||||||
Reference in New Issue
Block a user