This commit is contained in:
@@ -18,7 +18,7 @@ namespace AciTester.ViewModels
|
||||
private CancellationTokenSource _testCts;
|
||||
private bool _alarmShownLow = false;
|
||||
private bool _alarmShownHigh = false;
|
||||
|
||||
public IAsyncRelayCommand OpenValveCommand { get; }
|
||||
[ObservableProperty]
|
||||
private bool isConnected;
|
||||
|
||||
@@ -34,6 +34,9 @@ namespace AciTester.ViewModels
|
||||
[ObservableProperty]
|
||||
private bool isTesting;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool canStopTest; // 控制“停止测试”按钮的启用状态
|
||||
|
||||
[ObservableProperty]
|
||||
private int sampleTimeSeconds = 60;
|
||||
|
||||
@@ -55,6 +58,17 @@ namespace AciTester.ViewModels
|
||||
[ObservableProperty]
|
||||
private bool constantTempStartEnabled = true; // 是否允许恒温启动(除霜时为false)
|
||||
|
||||
public IAsyncRelayCommand StartPumpCommand { get; }
|
||||
public IAsyncRelayCommand StopPumpCommand { get; }
|
||||
// 阀门/泵状态(用于界面显示)
|
||||
[ObservableProperty]
|
||||
private bool valveStatus; // true=开启, false=关闭
|
||||
|
||||
[ObservableProperty]
|
||||
private bool pumpStatus; // true=运行, false=停止
|
||||
|
||||
public IAsyncRelayCommand CloseValveCommand { get; }
|
||||
|
||||
public MainViewModel()
|
||||
{
|
||||
_config = new PlcConfiguration();
|
||||
@@ -77,6 +91,7 @@ namespace AciTester.ViewModels
|
||||
ConnectCommand = new AsyncRelayCommand(ConnectAsync);
|
||||
DisconnectCommand = new RelayCommand(Disconnect);
|
||||
StartTestCommand = new AsyncRelayCommand(StartTestAsync);
|
||||
StopTestCommand = new AsyncRelayCommand(StopTestAsync, () => IsTesting);
|
||||
CalculateCommand = new RelayCommand(CalculateResult);
|
||||
ExportReportCommand = new AsyncRelayCommand(ExportReportAsync);
|
||||
|
||||
@@ -88,6 +103,28 @@ namespace AciTester.ViewModels
|
||||
|
||||
RealTime = new RealTimeData();
|
||||
Calibration = new CalibrationConfig();
|
||||
OpenValveCommand = new AsyncRelayCommand(async () =>
|
||||
{
|
||||
await _plcService.WriteCoilAsync(_config.ValveCoil, true);
|
||||
ValveStatus = true;
|
||||
});
|
||||
CloseValveCommand = new AsyncRelayCommand(async () =>
|
||||
{
|
||||
await _plcService.WriteCoilAsync(_config.ValveCoil, false);
|
||||
ValveStatus = false;
|
||||
});
|
||||
|
||||
StartPumpCommand = new AsyncRelayCommand(async () =>
|
||||
{
|
||||
await _plcService.WriteCoilAsync(_config.PumpCoil, true);
|
||||
PumpStatus = true;
|
||||
});
|
||||
StopPumpCommand = new AsyncRelayCommand(async () =>
|
||||
{
|
||||
await _plcService.WriteCoilAsync(_config.PumpCoil, false);
|
||||
PumpStatus = false;
|
||||
});
|
||||
|
||||
|
||||
// 监听属性变化,当除霜启动时更新恒温启动使能
|
||||
RealTime.PropertyChanged += async (s, e) =>
|
||||
@@ -101,8 +138,9 @@ namespace AciTester.ViewModels
|
||||
await WriteDefrostTimeSetAsync(RealTime.DefrostTimeSet);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
public IAsyncRelayCommand StopTestCommand { get; }
|
||||
public IAsyncRelayCommand ConnectCommand { get; }
|
||||
public IRelayCommand DisconnectCommand { get; }
|
||||
public IAsyncRelayCommand StartTestCommand { get; }
|
||||
@@ -113,6 +151,38 @@ namespace AciTester.ViewModels
|
||||
public IAsyncRelayCommand<float> WriteDefrostTempSetCommand { get; }
|
||||
public IAsyncRelayCommand<int> WriteDefrostTimeSetCommand { get; }
|
||||
|
||||
private async Task StopTestAsync()
|
||||
{
|
||||
if (!IsTesting) return;
|
||||
|
||||
try
|
||||
{
|
||||
// 停止真空泵
|
||||
await _plcService.WriteCoilAsync(_config.PumpCoil, false);
|
||||
IsPumpRunning = false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"停止泵失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// 重置状态
|
||||
IsTesting = false;
|
||||
CanStopTest = false;
|
||||
_testCts?.Cancel(); // 取消倒计时
|
||||
|
||||
RemainingSeconds = 0;
|
||||
|
||||
// 更新按钮状态
|
||||
StopTestCommand.NotifyCanExecuteChanged();
|
||||
}
|
||||
|
||||
//MessageBox.Show("测试已手动停止,请进行称重并录入数据。", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private async Task ConnectAsync()
|
||||
{
|
||||
try
|
||||
@@ -179,10 +249,21 @@ namespace AciTester.ViewModels
|
||||
RealTime.DifferentialPressure = calibratedImp - calibratedPump;
|
||||
});
|
||||
|
||||
// 在 ReadRealTimeLoop 中添加
|
||||
var valve = await _plcService.ReadCoilAsync(_config.ValveCoil);
|
||||
var pump = await _plcService.ReadCoilAsync(_config.PumpCoil);
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
ValveStatus = valve;
|
||||
PumpStatus = pump;
|
||||
});
|
||||
|
||||
|
||||
|
||||
if (calibrated < Calibration.FlowLowLimit || calibrated > Calibration.FlowHighLimit)
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
MessageBox.Show($"流量异常: {calibrated:F2} L/min", "警告", MessageBoxButton.OK, MessageBoxImage.Warning));
|
||||
//Application.Current.Dispatcher.Invoke(() =>
|
||||
// MessageBox.Show($"流量异常: {calibrated:F2} L/min", "警告", MessageBoxButton.OK, MessageBoxImage.Warning));
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
@@ -322,7 +403,7 @@ namespace AciTester.ViewModels
|
||||
|
||||
IsTesting = true;
|
||||
_testCts = new CancellationTokenSource();
|
||||
|
||||
//StopTestCommand.NotifyCanExecuteChanged();
|
||||
try
|
||||
{
|
||||
await _plcService.WriteCoilAsync(_config.PumpCoil, true);
|
||||
|
||||
Reference in New Issue
Block a user