This commit is contained in:
@@ -113,5 +113,7 @@ namespace MembranePoreTester.Communication
|
||||
Task WriteMultipleRegistersAsync(ushort registerAddress, float value);
|
||||
|
||||
float UshortToFloat(ushort P1, ushort P2);
|
||||
|
||||
Task<float> ReadFloatAsync(ushort startAddress);
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ namespace MembranePoreTester.Communication
|
||||
}
|
||||
|
||||
// 读取两个连续的保持寄存器,转换为32位浮点数(假设大端模式)
|
||||
private async Task<float> ReadFloatAsync(ushort startAddress)
|
||||
public async Task<float> ReadFloatAsync(ushort startAddress)
|
||||
{
|
||||
await EnsureConnectedAsync();
|
||||
var registers = await ReadHoldingRegistersAsync(startAddress, 2);
|
||||
|
||||
@@ -110,6 +110,57 @@ namespace MembranePoreTester.ViewModels
|
||||
|
||||
|
||||
|
||||
|
||||
private double _pressureUpperLimit;
|
||||
private double _pressureRate;
|
||||
|
||||
public double PressureUpperLimit
|
||||
{
|
||||
get => _pressureUpperLimit;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _pressureUpperLimit, value))
|
||||
{
|
||||
// 值改变时写入PLC
|
||||
_ = WriteFloatAsync(_plcConfig.PressureUpperLimit, (float)value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public double PressureRate
|
||||
{
|
||||
get => _pressureRate;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _pressureRate, value))
|
||||
{
|
||||
// 值改变时写入PLC
|
||||
_ = WriteFloatAsync(_plcConfig.PressureRate, (float)value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 添加读取这两个参数的方法
|
||||
private async Task ReadPressureParametersAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
float upperLimit = await _plcService.ReadFloatAsync(_plcConfig.PressureUpperLimit);
|
||||
float rate = await _plcService.ReadFloatAsync(_plcConfig.PressureRate);
|
||||
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
PressureUpperLimit = upperLimit;
|
||||
PressureRate = rate;
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"读取压力参数失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public StationItem()
|
||||
{
|
||||
|
||||
@@ -153,13 +204,19 @@ namespace MembranePoreTester.ViewModels
|
||||
// 启动定时器,每秒读取一次 M21 状态
|
||||
_timer = new System.Windows.Threading.DispatcherTimer();
|
||||
_timer.Interval = TimeSpan.FromSeconds(1);
|
||||
_timer.Tick += async (s, e) => await ReadEnableStatusAsync();
|
||||
_timer.Tick += async (s, e) =>
|
||||
{
|
||||
await ReadEnableStatusAsync();
|
||||
await ReadPressureParametersAsync(); // 新增:读取压力参数
|
||||
};
|
||||
_timer.Start();
|
||||
|
||||
// 延迟2秒后读取,确保连接稳定
|
||||
Task.Delay(2000).ContinueWith(async _ =>
|
||||
{
|
||||
await ReadPressureModeAsync();
|
||||
await ReadPressureParametersAsync(); // 新增:读取压力参数
|
||||
|
||||
}, TaskScheduler.Default);
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
xmlns:viewModels="clr-namespace:MembranePoreTester.ViewModels"
|
||||
xmlns:conv="clr-namespace:MembranePoreTester.Converters"
|
||||
Title="膜孔径测试系统 (GB/T 32361-2015)"
|
||||
Width="1024" Height="768" WindowState="Maximized"
|
||||
Width="1024" MinHeight="768" WindowState="Maximized"
|
||||
WindowStartupLocation="CenterScreen" KeyDown="Window_KeyDown"
|
||||
Background="#F5F7FA" FontFamily="Segoe UI">
|
||||
|
||||
@@ -138,6 +138,20 @@
|
||||
</Grid>
|
||||
<TextBlock Text="{Binding EnableStatusText}" VerticalAlignment="Center" Margin="5,0,0,0" FontSize="12"/>
|
||||
</StackPanel>
|
||||
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="15,0,0,0">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,0,10,0">
|
||||
<Label Content="加压上限:" VerticalAlignment="Center" Margin="0,0,5,0"/>
|
||||
<TextBox x:Name="txtPressureUpper" Width="120" FontSize="16" Height="32" VerticalAlignment="Center" Text="{Binding PressureUpperLimit, UpdateSourceTrigger=LostFocus, StringFormat=F3}" />
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Label Content="加压速率:" VerticalAlignment="Center" Margin="0,0,5,0"/>
|
||||
<TextBox x:Name="txtPressureRate" Width="120" FontSize="16" Height="32" VerticalAlignment="Center" Text="{Binding PressureRate, UpdateSourceTrigger=LostFocus, StringFormat=F3}" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
|
||||
@@ -5,25 +5,7 @@
|
||||
WindowStartupLocation="CenterOwner">
|
||||
<ScrollViewer>
|
||||
<StackPanel Margin="10">
|
||||
<GroupBox Header="加压控制">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="150"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Label Grid.Row="0" Grid.Column="0">加压上限(D300):</Label>
|
||||
<TextBox x:Name="txtPressureUpper" Grid.Row="0" Grid.Column="1"/>
|
||||
<Label Grid.Row="1" Grid.Column="0">加压速率(D280):</Label>
|
||||
<TextBox x:Name="txtPressureRate" Grid.Row="1" Grid.Column="1"/>
|
||||
<!--<Label Grid.Row="2" Grid.Column="0">加压系数(D282):</Label>
|
||||
<TextBox x:Name="txtPressureCoeff" Grid.Row="2" Grid.Column="1"/>-->
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
|
||||
<GroupBox Header="高压/低压系数">
|
||||
<Grid>
|
||||
|
||||
@@ -28,8 +28,8 @@ namespace MembranePoreTester.Views
|
||||
// 初始化文本框到寄存器地址的映射
|
||||
_textBoxMapping = new Dictionary<TextBox, (ushort, string)>
|
||||
{
|
||||
[txtPressureUpper] = (_config.PressureUpperLimit, "加压上限"),
|
||||
[txtPressureRate] = (_config.PressureRate, "加压速率"),
|
||||
//[txtPressureUpper] = (_config.PressureUpperLimit, "加压上限"),
|
||||
//[txtPressureRate] = (_config.PressureRate, "加压速率"),
|
||||
//[txtPressureCoeff] = (_config.PressureCoeff, "加压系数"),
|
||||
|
||||
[txtHPCoeff1] = (_config.HPCoeff1, "工位1高压系数"),
|
||||
|
||||
Reference in New Issue
Block a user