This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user