更新20260522
This commit is contained in:
@@ -9,9 +9,10 @@ namespace ConeCalorimeter.ViewModels;
|
|||||||
|
|
||||||
public sealed class ConeRadiationSettingsViewModel : PageViewModel
|
public sealed class ConeRadiationSettingsViewModel : PageViewModel
|
||||||
{
|
{
|
||||||
private const ushort CurrentHeatFluxRegister = 32;
|
private const ushort CurrentHeatFluxRegister = 410;
|
||||||
private const ushort TargetTemperatureRegister = 400;
|
private const ushort TargetTemperatureRegister = 400;
|
||||||
private const ushort HeatTransferRegister = 418;
|
private const ushort HeatTransferRegister = 418;
|
||||||
|
private const double TargetTemperatureScale = 10;
|
||||||
private const double CurrentHeatFluxMinimum = 0;
|
private const double CurrentHeatFluxMinimum = 0;
|
||||||
private const double CurrentHeatFluxMaximum = 1000;
|
private const double CurrentHeatFluxMaximum = 1000;
|
||||||
private const double HeatTransferInputMinimum = 0;
|
private const double HeatTransferInputMinimum = 0;
|
||||||
@@ -193,7 +194,7 @@ public sealed class ConeRadiationSettingsViewModel : PageViewModel
|
|||||||
|
|
||||||
if (CanRefreshConeParameters())
|
if (CanRefreshConeParameters())
|
||||||
{
|
{
|
||||||
TargetTemperatureText = ReadInt16Text(TargetTemperatureRegister);
|
TargetTemperatureText = ReadScaledInt16Text(TargetTemperatureRegister, TargetTemperatureScale, "0.#");
|
||||||
if (TryReadRangedFloatText(
|
if (TryReadRangedFloatText(
|
||||||
"ConeHeatTransfer",
|
"ConeHeatTransfer",
|
||||||
HeatTransferRegister,
|
HeatTransferRegister,
|
||||||
@@ -258,25 +259,34 @@ public sealed class ConeRadiationSettingsViewModel : PageViewModel
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string ReadInt16Text(ushort registerAddress)
|
private string ReadScaledInt16Text(ushort registerAddress, double scale, string format)
|
||||||
{
|
{
|
||||||
return _tcpDeviceConnectionService.TryReadInt16(registerAddress, out var value)
|
return _tcpDeviceConnectionService.TryReadInt16(registerAddress, out var rawValue)
|
||||||
? value.ToString(CultureInfo.InvariantCulture)
|
? (rawValue / scale).ToString(format, CultureInfo.InvariantCulture)
|
||||||
: string.Empty;
|
: string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool WriteTargetTemperature()
|
private bool WriteTargetTemperature()
|
||||||
{
|
{
|
||||||
if (!short.TryParse(TargetTemperatureText, NumberStyles.Integer, CultureInfo.InvariantCulture, out var value))
|
if (!double.TryParse(TargetTemperatureText, NumberStyles.Float, CultureInfo.InvariantCulture, out var value)
|
||||||
|
|| !double.IsFinite(value))
|
||||||
{
|
{
|
||||||
LastAction = "辐射温度输入无效";
|
LastAction = "辐射温度输入无效";
|
||||||
Debug.WriteLine($"Invalid cone radiation target temperature: {TargetTemperatureText}");
|
Debug.WriteLine($"Invalid cone radiation target temperature: {TargetTemperatureText}");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_tcpDeviceConnectionService.TryWriteInt16(TargetTemperatureRegister, value))
|
var scaledValue = Math.Round(value * TargetTemperatureScale, MidpointRounding.AwayFromZero);
|
||||||
|
if (scaledValue is < short.MinValue or > short.MaxValue)
|
||||||
{
|
{
|
||||||
TargetTemperatureText = value.ToString(CultureInfo.InvariantCulture);
|
LastAction = "辐射温度输入超出范围";
|
||||||
|
Debug.WriteLine($"Cone radiation target temperature out of range: {TargetTemperatureText}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_tcpDeviceConnectionService.TryWriteInt16(TargetTemperatureRegister, (short)scaledValue))
|
||||||
|
{
|
||||||
|
TargetTemperatureText = value.ToString("0.#", CultureInfo.InvariantCulture);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ public sealed class MainViewModel : ObservableObject
|
|||||||
+ "3.温度恒定后,打开隔热板;\n"
|
+ "3.温度恒定后,打开隔热板;\n"
|
||||||
+ " 打开风机;\n\n"
|
+ " 打开风机;\n\n"
|
||||||
+ "4.风速恒定后,点击测试;\n\n"
|
+ "4.风速恒定后,点击测试;\n\n"
|
||||||
+ "5.试样点燃后,点击【点火关】;\n\n"
|
+ "5.点火时点击【点火开】,试样点燃后点击【点火关】;\n\n"
|
||||||
+ "6.试样完全燃烧后,点击【停止】; 实验结束");
|
+ "6.试样完全燃烧后,点击【停止】; 实验结束");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ namespace ConeCalorimeter.ViewModels;
|
|||||||
public sealed class TestPageViewModel : PageViewModel
|
public sealed class TestPageViewModel : PageViewModel
|
||||||
{
|
{
|
||||||
private const string ResetAction = "复位";
|
private const string ResetAction = "复位";
|
||||||
private const ushort ResetCoil = 80;
|
private const ushort ResetCoil = 88;
|
||||||
private const ushort ResetCompleteCoil = 82;
|
private const ushort ResetCompleteCoil = 89;
|
||||||
|
|
||||||
private readonly IExperimentDataService _experimentDataService;
|
private readonly IExperimentDataService _experimentDataService;
|
||||||
private readonly ITcpDeviceConnectionService _tcpDeviceConnectionService;
|
private readonly ITcpDeviceConnectionService _tcpDeviceConnectionService;
|
||||||
@@ -81,6 +81,7 @@ public sealed class TestPageViewModel : PageViewModel
|
|||||||
new DeviceActionViewModel("测试结束", ExecuteDeviceActionCommand),
|
new DeviceActionViewModel("测试结束", ExecuteDeviceActionCommand),
|
||||||
new DeviceActionViewModel("风机开", ExecuteDeviceActionCommand),
|
new DeviceActionViewModel("风机开", ExecuteDeviceActionCommand),
|
||||||
new DeviceActionViewModel("风机关", ExecuteDeviceActionCommand),
|
new DeviceActionViewModel("风机关", ExecuteDeviceActionCommand),
|
||||||
|
new DeviceActionViewModel("点火开", ExecuteDeviceActionCommand),
|
||||||
new DeviceActionViewModel("点火关", ExecuteDeviceActionCommand),
|
new DeviceActionViewModel("点火关", ExecuteDeviceActionCommand),
|
||||||
_resetAction
|
_resetAction
|
||||||
];
|
];
|
||||||
@@ -387,8 +388,12 @@ public sealed class TestPageViewModel : PageViewModel
|
|||||||
case "测试结束":
|
case "测试结束":
|
||||||
coilAddress = 67;
|
coilAddress = 67;
|
||||||
return true;
|
return true;
|
||||||
|
case "点火开":
|
||||||
|
coilAddress = 53;
|
||||||
|
return true;
|
||||||
case "点火关":
|
case "点火关":
|
||||||
coilAddress = 53;
|
coilAddress = 53;
|
||||||
|
value = false;
|
||||||
return true;
|
return true;
|
||||||
case "风机开":
|
case "风机开":
|
||||||
coilAddress = 54;
|
coilAddress = 54;
|
||||||
|
|||||||
@@ -206,7 +206,7 @@
|
|||||||
<ItemsControl ItemsSource="{Binding DeviceActions}">
|
<ItemsControl ItemsSource="{Binding DeviceActions}">
|
||||||
<ItemsControl.ItemsPanel>
|
<ItemsControl.ItemsPanel>
|
||||||
<ItemsPanelTemplate>
|
<ItemsPanelTemplate>
|
||||||
<UniformGrid Columns="2" Rows="5" />
|
<UniformGrid Columns="3" Rows="4" />
|
||||||
</ItemsPanelTemplate>
|
</ItemsPanelTemplate>
|
||||||
</ItemsControl.ItemsPanel>
|
</ItemsControl.ItemsPanel>
|
||||||
<ItemsControl.ItemTemplate>
|
<ItemsControl.ItemTemplate>
|
||||||
|
|||||||
Reference in New Issue
Block a user