项目逻辑添加

This commit is contained in:
2026-05-15 11:13:06 +08:00
parent 0b68413bf9
commit a050c307a8
5 changed files with 25 additions and 25 deletions

View File

@@ -313,7 +313,7 @@
<TextBlock Text="片剂四用仪 (硬度·脆碎度·崩解·溶出) 符合《中国药典》"
FontSize="22" FontWeight="Bold" Foreground="White" VerticalAlignment="Center"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center">
<Button Command="{Binding OpenSettingsCommand}" Content="⚙ 参数设置" Style="{StaticResource ActionButton}"/>
<!--<Button Command="{Binding OpenSettingsCommand}" Content="⚙ 参数设置" Style="{StaticResource ActionButton}"/>-->
<Button Command="{Binding OpenHistoryCommand}" Content="📜 历史记录" Style="{StaticResource ActionButton}"/>
<Button Command="{Binding OpenCalibrationCommand}" Content="🔧 校准" Style="{StaticResource ActionButton}"/>
<Button Command="{Binding ExportAllCommand}" Content="📁 导出全部" Style="{StaticResource ActionButton}"/>

View File

@@ -47,32 +47,17 @@ namespace 片剂四用仪.Views
if (m.Type == PlcParamType.Int)
{
ushort[] res = await _plc.ReadHoldingRegistersAsync((ushort)m.Address, 1);
if (_plc.IsConnected)
{
Dispatcher.Invoke(() => tb.Text = res[0].ToString());
}
else
{
Dispatcher.Invoke(() => tb.Text = "0"); // 读取失败时显示占位符
}
int value = await _plc.ReadIntAsync((ushort)m.Address);
Dispatcher.Invoke(() => tb.Text = value.ToString());
}
else
{
ushort[] res = await _plc.ReadHoldingRegistersAsync((ushort)m.Address, 2);
// 同样增加有效性判断
if (_plc.IsConnected)
{
float value = BitConverter.ToSingle(BitConverter.GetBytes((uint)(res[0] << 16 | res[1])), 0);
Dispatcher.Invoke(() => tb.Text = value.ToString("F2"));
}
else
{
Dispatcher.Invoke(() => tb.Text = "0"); // 读取失败时显示占位符
}
float value = await _plc.ReadFloatAsync((ushort)m.Address);
Dispatcher.Invoke(() => tb.Text = value.ToString("F2"));
}
}
// 正常循环的Delay同样处理取消异常