This commit is contained in:
@@ -78,6 +78,7 @@ namespace MembranePoreTester.ViewModels
|
||||
set => SetProperty(ref _pressButtonText, value);
|
||||
}
|
||||
|
||||
|
||||
public bool EnableStatus
|
||||
{
|
||||
get => _enableStatus;
|
||||
@@ -85,12 +86,17 @@ namespace MembranePoreTester.ViewModels
|
||||
{
|
||||
if (SetProperty(ref _enableStatus, value))
|
||||
{
|
||||
// 当 EnableStatus 变化时,通知依赖的属性也变化
|
||||
// 当设备停止运行时,停止孔分布自动采集
|
||||
if (!value)
|
||||
{
|
||||
PoreDistributionVM?.StopCollecting();
|
||||
}
|
||||
OnPropertyChanged(nameof(EnableStatusText));
|
||||
OnPropertyChanged(nameof(EnableStatusColor));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 使能状态显示文本
|
||||
public string EnableStatusText => EnableStatus ? "运行中" : "未启动";
|
||||
|
||||
@@ -113,23 +119,25 @@ namespace MembranePoreTester.ViewModels
|
||||
|
||||
private double _pressureUpperLimit;
|
||||
private double _pressureRate;
|
||||
// 防止从PLC读取时触发校验弹窗
|
||||
private bool _suppressPressureValidation = false;
|
||||
|
||||
public double PressureUpperLimit
|
||||
{
|
||||
get => _pressureUpperLimit;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _pressureUpperLimit, value))
|
||||
// 如果不是从PLC读取(即用户交互或程序主动设置),先校验再设置
|
||||
if (!_suppressPressureValidation && HighLowPressure.Contains("低压") && value > 200)
|
||||
{
|
||||
MessageBox.Show("低压模式,加压上限不能超过200!");
|
||||
return;
|
||||
}
|
||||
|
||||
bool changed = SetProperty(ref _pressureUpperLimit, value);
|
||||
// 仅在非抑制模式下将改变写回PLC,避免把PLC读回的值再次写入造成循环
|
||||
if (changed && !_suppressPressureValidation)
|
||||
{
|
||||
if (HighLowPressure == "低压")
|
||||
{
|
||||
if (value > 200)
|
||||
{
|
||||
MessageBox.Show("低压模式,加压上限不能超过200!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 值改变时写入PLC
|
||||
_ = _plcService.WriteMultipleRegistersAsync(_plcConfig.PressureUpperLimit, (float)value);
|
||||
}
|
||||
}
|
||||
@@ -161,8 +169,11 @@ namespace MembranePoreTester.ViewModels
|
||||
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
// 在将PLC读取的值赋回到属性时,抑制用户校验提示和避免回写PLC
|
||||
_suppressPressureValidation = true;
|
||||
PressureUpperLimit = upperLimit;
|
||||
PressureRate = rate;
|
||||
_suppressPressureValidation = false;
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user