更新2026/5/22
This commit is contained in:
@@ -10,11 +10,12 @@ namespace ConeCalorimeter.ViewModels;
|
|||||||
|
|
||||||
public sealed class CValueCalibrationViewModel : PageViewModel
|
public sealed class CValueCalibrationViewModel : PageViewModel
|
||||||
{
|
{
|
||||||
private const ushort BaselineOxygenRegister = 280;
|
private const ushort BaselineOxygenRegister = 268;
|
||||||
private const ushort TemperatureRegister = 282;
|
private const ushort TemperatureRegister = 282;
|
||||||
private const ushort PressureDifferenceRegister = 284;
|
private const ushort PressureDifferenceRegister = 284;
|
||||||
private const ushort CalibrationOxygenRegister = 286;
|
private const ushort CalibrationOxygenRegister = 286;
|
||||||
private const ushort CValueRegister = 308;
|
private const ushort CValueRegister = 308;
|
||||||
|
private const ushort MethaneFlowRegister = 34;
|
||||||
private const ushort CirculatingWaterCoil = 49;
|
private const ushort CirculatingWaterCoil = 49;
|
||||||
private const ushort SamplingPumpCoil = 50;
|
private const ushort SamplingPumpCoil = 50;
|
||||||
private const ushort IgniterCoil = 53;
|
private const ushort IgniterCoil = 53;
|
||||||
@@ -34,6 +35,8 @@ public sealed class CValueCalibrationViewModel : PageViewModel
|
|||||||
|
|
||||||
private readonly Action _closeAction;
|
private readonly Action _closeAction;
|
||||||
private readonly Action _helpAction;
|
private readonly Action _helpAction;
|
||||||
|
private readonly Action _baselineCollectionCompletedAction;
|
||||||
|
private readonly Action _calibrationCompletedAction;
|
||||||
private readonly ITcpDeviceConnectionService _tcpDeviceConnectionService;
|
private readonly ITcpDeviceConnectionService _tcpDeviceConnectionService;
|
||||||
private readonly DispatcherTimer _refreshTimer;
|
private readonly DispatcherTimer _refreshTimer;
|
||||||
private readonly Dictionary<string, CValueCalibrationActionViewModel> _actionsByLabel = [];
|
private readonly Dictionary<string, CValueCalibrationActionViewModel> _actionsByLabel = [];
|
||||||
@@ -42,15 +45,20 @@ public sealed class CValueCalibrationViewModel : PageViewModel
|
|||||||
private string _pressureDifferenceText = "";
|
private string _pressureDifferenceText = "";
|
||||||
private string _calibrationOxygenText = "";
|
private string _calibrationOxygenText = "";
|
||||||
private string _cValueText = "";
|
private string _cValueText = "";
|
||||||
|
private string _methaneFlowText = "";
|
||||||
private string _lastAction = "待机";
|
private string _lastAction = "待机";
|
||||||
|
|
||||||
public CValueCalibrationViewModel(
|
public CValueCalibrationViewModel(
|
||||||
Action closeAction,
|
Action closeAction,
|
||||||
Action helpAction,
|
Action helpAction,
|
||||||
|
Action baselineCollectionCompletedAction,
|
||||||
|
Action calibrationCompletedAction,
|
||||||
ITcpDeviceConnectionService tcpDeviceConnectionService) : base("C值标定")
|
ITcpDeviceConnectionService tcpDeviceConnectionService) : base("C值标定")
|
||||||
{
|
{
|
||||||
_closeAction = closeAction;
|
_closeAction = closeAction;
|
||||||
_helpAction = helpAction;
|
_helpAction = helpAction;
|
||||||
|
_baselineCollectionCompletedAction = baselineCollectionCompletedAction;
|
||||||
|
_calibrationCompletedAction = calibrationCompletedAction;
|
||||||
_tcpDeviceConnectionService = tcpDeviceConnectionService;
|
_tcpDeviceConnectionService = tcpDeviceConnectionService;
|
||||||
CloseCommand = new RelayCommand(_closeAction);
|
CloseCommand = new RelayCommand(_closeAction);
|
||||||
HelpCommand = new RelayCommand(_helpAction);
|
HelpCommand = new RelayCommand(_helpAction);
|
||||||
@@ -122,6 +130,12 @@ public sealed class CValueCalibrationViewModel : PageViewModel
|
|||||||
private set => SetProperty(ref _cValueText, value);
|
private set => SetProperty(ref _cValueText, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string MethaneFlowText
|
||||||
|
{
|
||||||
|
get => _methaneFlowText;
|
||||||
|
private set => SetProperty(ref _methaneFlowText, value);
|
||||||
|
}
|
||||||
|
|
||||||
public string LastAction
|
public string LastAction
|
||||||
{
|
{
|
||||||
get => _lastAction;
|
get => _lastAction;
|
||||||
@@ -153,6 +167,7 @@ public sealed class CValueCalibrationViewModel : PageViewModel
|
|||||||
PressureDifferenceText = ReadFloatText(PressureDifferenceRegister);
|
PressureDifferenceText = ReadFloatText(PressureDifferenceRegister);
|
||||||
CalibrationOxygenText = ReadFloatText(CalibrationOxygenRegister);
|
CalibrationOxygenText = ReadFloatText(CalibrationOxygenRegister);
|
||||||
CValueText = ReadFloatText(CValueRegister);
|
CValueText = ReadFloatText(CValueRegister);
|
||||||
|
MethaneFlowText = ReadFloatText(MethaneFlowRegister);
|
||||||
RefreshActionStates();
|
RefreshActionStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,12 +265,26 @@ public sealed class CValueCalibrationViewModel : PageViewModel
|
|||||||
|
|
||||||
if (_tcpDeviceConnectionService.TryWriteCoil(coilAddress, true))
|
if (_tcpDeviceConnectionService.TryWriteCoil(coilAddress, true))
|
||||||
{
|
{
|
||||||
LastAction = actionText;
|
var completedBaselineCollection = action == BaselineCollectionAction && isActive;
|
||||||
|
var completedCalibration = action == CalibrationStartAction && isActive;
|
||||||
|
LastAction = completedBaselineCollection
|
||||||
|
? "基线采集完成"
|
||||||
|
: completedCalibration ? "标定完成" : actionText;
|
||||||
if (_actionsByLabel.TryGetValue(action, out var actionViewModel))
|
if (_actionsByLabel.TryGetValue(action, out var actionViewModel))
|
||||||
{
|
{
|
||||||
actionViewModel.UpdateStatus(!isActive);
|
actionViewModel.UpdateStatus(!isActive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (completedBaselineCollection)
|
||||||
|
{
|
||||||
|
_baselineCollectionCompletedAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (completedCalibration)
|
||||||
|
{
|
||||||
|
_calibrationCompletedAction();
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ public sealed class MainViewModel : ObservableObject
|
|||||||
new CValueCalibrationViewModel(
|
new CValueCalibrationViewModel(
|
||||||
() => SelectPage(testItem),
|
() => SelectPage(testItem),
|
||||||
ShowCValueCalibrationHelp,
|
ShowCValueCalibrationHelp,
|
||||||
|
ShowBaselineCollectionCompleted,
|
||||||
|
ShowCalibrationCompleted,
|
||||||
tcpDeviceConnectionService));
|
tcpDeviceConnectionService));
|
||||||
var coneRadiationItem = new NavigationItemViewModel(
|
var coneRadiationItem = new NavigationItemViewModel(
|
||||||
"辐射锥设置",
|
"辐射锥设置",
|
||||||
@@ -161,6 +163,22 @@ public sealed class MainViewModel : ObservableObject
|
|||||||
+ "6.标定完成后,弹出“标定完成!”;");
|
+ "6.标定完成后,弹出“标定完成!”;");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ShowBaselineCollectionCompleted()
|
||||||
|
{
|
||||||
|
_helpDialogService.ShowHelp(
|
||||||
|
"C值标定提示",
|
||||||
|
"C值标定提示",
|
||||||
|
"基线采集完成");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ShowCalibrationCompleted()
|
||||||
|
{
|
||||||
|
_helpDialogService.ShowHelp(
|
||||||
|
"C值标定提示",
|
||||||
|
"C值标定提示",
|
||||||
|
"标定完成!");
|
||||||
|
}
|
||||||
|
|
||||||
private void ShowConeRadiationHelp()
|
private void ShowConeRadiationHelp()
|
||||||
{
|
{
|
||||||
_helpDialogService.ShowHelp(
|
_helpDialogService.ShowHelp(
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ public sealed class TestPageViewModel : PageViewModel
|
|||||||
private const string ResetAction = "复位";
|
private const string ResetAction = "复位";
|
||||||
private const ushort ResetCoil = 88;
|
private const ushort ResetCoil = 88;
|
||||||
private const ushort ResetCompleteCoil = 89;
|
private const ushort ResetCompleteCoil = 89;
|
||||||
|
private static readonly TimeSpan ResetPulseDuration = TimeSpan.FromMilliseconds(300);
|
||||||
|
private static readonly TimeSpan ResetCompletionTimeout = TimeSpan.FromSeconds(15);
|
||||||
|
|
||||||
private readonly IExperimentDataService _experimentDataService;
|
private readonly IExperimentDataService _experimentDataService;
|
||||||
private readonly ITcpDeviceConnectionService _tcpDeviceConnectionService;
|
private readonly ITcpDeviceConnectionService _tcpDeviceConnectionService;
|
||||||
@@ -27,6 +29,7 @@ public sealed class TestPageViewModel : PageViewModel
|
|||||||
private DeviceActionViewModel _resetAction = null!;
|
private DeviceActionViewModel _resetAction = null!;
|
||||||
private bool _flameDetected;
|
private bool _flameDetected;
|
||||||
private bool _resetInProgress;
|
private bool _resetInProgress;
|
||||||
|
private DateTime _resetStartedAt;
|
||||||
private string _lastAction = "待机";
|
private string _lastAction = "待机";
|
||||||
|
|
||||||
public TestPageViewModel(
|
public TestPageViewModel(
|
||||||
@@ -331,8 +334,13 @@ public sealed class TestPageViewModel : PageViewModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ExecuteResetAction()
|
private async void ExecuteResetAction()
|
||||||
{
|
{
|
||||||
|
if (_resetInProgress)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!_tcpDeviceConnectionService.TryWriteCoil(ResetCoil, true))
|
if (!_tcpDeviceConnectionService.TryWriteCoil(ResetCoil, true))
|
||||||
{
|
{
|
||||||
LastAction = "复位失败";
|
LastAction = "复位失败";
|
||||||
@@ -341,6 +349,14 @@ public sealed class TestPageViewModel : PageViewModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
SetResetInProgress(true);
|
SetResetInProgress(true);
|
||||||
|
LastAction = "复位中";
|
||||||
|
_resetStartedAt = DateTime.Now;
|
||||||
|
|
||||||
|
await Task.Delay(ResetPulseDuration);
|
||||||
|
if (!_tcpDeviceConnectionService.TryWriteCoil(ResetCoil, false))
|
||||||
|
{
|
||||||
|
Debug.WriteLine("Device reset pulse release failed.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RefreshResetStatus()
|
private void RefreshResetStatus()
|
||||||
@@ -350,13 +366,21 @@ public sealed class TestPageViewModel : PageViewModel
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_tcpDeviceConnectionService.TryReadCoil(ResetCompleteCoil, out var resetComplete) || !resetComplete)
|
var statusRead = _tcpDeviceConnectionService.TryReadCoil(ResetCompleteCoil, out var resetComplete);
|
||||||
|
if (statusRead && resetComplete)
|
||||||
|
{
|
||||||
|
SetResetInProgress(false);
|
||||||
|
LastAction = "复位完成";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DateTime.Now - _resetStartedAt < ResetCompletionTimeout)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetResetInProgress(false);
|
SetResetInProgress(false);
|
||||||
LastAction = "复位完成";
|
LastAction = statusRead ? "复位超时" : "复位状态读取失败";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetResetInProgress(bool resetInProgress)
|
private void SetResetInProgress(bool resetInProgress)
|
||||||
|
|||||||
@@ -201,6 +201,18 @@
|
|||||||
Text="%"
|
Text="%"
|
||||||
Style="{StaticResource DataLabelStyle}" />
|
Style="{StaticResource DataLabelStyle}" />
|
||||||
|
|
||||||
|
<TextBlock Grid.Row="2"
|
||||||
|
Text="甲烷流量:"
|
||||||
|
Style="{StaticResource DataLabelStyle}" />
|
||||||
|
<TextBlock Grid.Row="2"
|
||||||
|
Grid.Column="1"
|
||||||
|
Text="{Binding MethaneFlowText}"
|
||||||
|
Style="{StaticResource DataValueStyle}" />
|
||||||
|
<TextBlock Grid.Row="2"
|
||||||
|
Grid.Column="2"
|
||||||
|
Text="L/Min"
|
||||||
|
Style="{StaticResource DataLabelStyle}" />
|
||||||
|
|
||||||
<TextBlock Grid.Row="2"
|
<TextBlock Grid.Row="2"
|
||||||
Grid.Column="5"
|
Grid.Column="5"
|
||||||
Text="C:"
|
Text="C:"
|
||||||
|
|||||||
Reference in New Issue
Block a user