This commit is contained in:
xyy
2026-03-21 11:15:47 +08:00
parent 01b2f8f901
commit 140bd2af8e
3 changed files with 60 additions and 3 deletions

View File

@@ -28,6 +28,15 @@
Background="#E67E22" Foreground="White" BorderThickness="0" Click="PauseButton_Click"/>
<Button x:Name="ResumeButton" Content="继续" Width="70" Height="28" Margin="5,0"
Background="#27AE60" Foreground="White" BorderThickness="0" Click="ResumeButton_Click"/>
<!-- 在 ResumeButton 后添加 -->
<TextBlock x:Name="AlarmTextBlock"
Text="无报警"
FontSize="10"
Foreground="Red"
Margin="15,0,0,0"
VerticalAlignment="Center"/>
</StackPanel>
</Border>

View File

@@ -29,6 +29,11 @@ namespace PLCDataMonitor
ResumeRequested?.Invoke(this, EventArgs.Empty);
}
public void UpdateAlarms(string alarmMessage)
{
Dispatcher.Invoke(() => AlarmTextBlock.Text = alarmMessage);
}
// 更新数据显示
public void UpdateData(string pressure1, string pressure2, string friction1, string friction2, int count1, int count2, string t1, string t2, string Distince)
{

View File

@@ -43,9 +43,9 @@ namespace PLCDataMonitor
private IModbusMaster _modbusMaster;
// PLC 地址(根据实际PLC修改
private const int PauseControlCoil = 1000; // 写入 true=暂停false=继续(线圈地址)
private const int PauseStatusCoil = 1001; // 读取当前暂停状态(线圈地址)
// PLC 地址(根据文档修正
private const int PauseControlCoil = 25053; // 写入 true=暂停false=继续(线圈地址)
private const int PauseStatusCoil = 25053; // 读取当前暂停状态(同一地址)
// 记录暂停时间段(用于导出过滤)
@@ -57,6 +57,11 @@ namespace PLCDataMonitor
// 报警线圈地址(连续读取)
private const int AlarmStartAddr_WR4 = 25065; // WR4.0
private const int AlarmCount_WR4 = 5; // WR4.0 ~ WR4.4
private const int AlarmStartAddr_WR9 = 25145; // WR9.0
private const int AlarmCount_WR9 = 5; // WR9.0 ~ WR9.4
// 添加清空方法
public void ClearPausePeriods()
@@ -364,6 +369,41 @@ namespace PLCDataMonitor
var maxFriction1 = data.maxFriction1;
var maxFriction2 = data.maxFriction2;
// 读取报警状态
bool[] alarmsWR4 = null;
bool[] alarmsWR9 = null;
try
{
alarmsWR4 = _modbusMaster?.ReadCoils(0x01, (ushort)AlarmStartAddr_WR4, AlarmCount_WR4);
alarmsWR9 = _modbusMaster?.ReadCoils(0x01, (ushort)AlarmStartAddr_WR9, AlarmCount_WR9);
}
catch { } // 读取失败时不更新报警
// 构建报警消息
string alarmMessage = "";
if (alarmsWR4 != null && alarmsWR4.Length >= 5)
{
if (alarmsWR4[0]) alarmMessage += "超温95℃ ";
if (alarmsWR4[1]) alarmMessage += "超上限水位 ";
if (alarmsWR4[2]) alarmMessage += "急停被按下 ";
if (alarmsWR4[3]) alarmMessage += "测试完成 ";
if (alarmsWR4[4]) alarmMessage += "摩擦过大 ";
}
if (alarmsWR9 != null && alarmsWR9.Length >= 5)
{
if (alarmsWR9[0]) alarmMessage += "1工位低位水 ";
if (alarmsWR9[2]) alarmMessage += "水泵未运行 "; // 索引 2 对应 WR9.2
if (alarmsWR9[3]) alarmMessage += "2工位低位水 ";
}
if (string.IsNullOrEmpty(alarmMessage))
alarmMessage = "无报警";
// 更新UI数据监控页+曲线页)
// 使用 BeginInvoke 避免阻塞后台读取线程,减少 UI 卡死风险
Dispatcher.BeginInvoke(new Action(() =>
@@ -381,6 +421,9 @@ namespace PLCDataMonitor
data.D.ToString("F1")
);
// 新增:更新报警显示
_homePage.UpdateAlarms(alarmMessage);
// 关键修改:确保曲线数据正确记录
if (data.setCount > 0 && data.actualCount > 0 &&
data.setCount > data.actualCount) // 点击了开始,且实际次数小于设定次数,才更新曲线