更新
This commit is contained in:
@@ -16,6 +16,16 @@ public sealed class CValueCalibrationViewModel : PageViewModel
|
||||
private const ushort CalibrationOxygenRegister = 286;
|
||||
private const ushort CValueRegister = 308;
|
||||
private const ushort MethaneFlowRegister = 34;
|
||||
private const double OxygenMinimum = 0;
|
||||
private const double OxygenMaximum = 30;
|
||||
private const double TemperatureMinimum = 200;
|
||||
private const double TemperatureMaximum = 1500;
|
||||
private const double PressureDifferenceMinimum = -5000;
|
||||
private const double PressureDifferenceMaximum = 5000;
|
||||
private const double CValueMinimum = 0;
|
||||
private const double CValueMaximum = 1000;
|
||||
private const double MethaneFlowMinimum = 0;
|
||||
private const double MethaneFlowMaximum = 20;
|
||||
private const ushort CirculatingWaterCoil = 49;
|
||||
private const ushort SamplingPumpCoil = 50;
|
||||
private const ushort IgniterCoil = 53;
|
||||
@@ -40,6 +50,8 @@ public sealed class CValueCalibrationViewModel : PageViewModel
|
||||
private readonly ITcpDeviceConnectionService _tcpDeviceConnectionService;
|
||||
private readonly DispatcherTimer _refreshTimer;
|
||||
private readonly Dictionary<string, CValueCalibrationActionViewModel> _actionsByLabel = [];
|
||||
private readonly HashSet<ushort> _loggedFloatDiagnostics = [];
|
||||
private readonly HashSet<ushort> _loggedInvalidFloatDiagnostics = [];
|
||||
private string _baselineOxygenText = "";
|
||||
private string _temperatureText = "";
|
||||
private string _pressureDifferenceText = "";
|
||||
@@ -162,20 +174,98 @@ public sealed class CValueCalibrationViewModel : PageViewModel
|
||||
|
||||
private void RefreshDeviceValues()
|
||||
{
|
||||
BaselineOxygenText = ReadFloatText(BaselineOxygenRegister);
|
||||
TemperatureText = ReadFloatText(TemperatureRegister);
|
||||
PressureDifferenceText = ReadFloatText(PressureDifferenceRegister);
|
||||
CalibrationOxygenText = ReadFloatText(CalibrationOxygenRegister);
|
||||
CValueText = ReadFloatText(CValueRegister);
|
||||
MethaneFlowText = ReadFloatText(MethaneFlowRegister);
|
||||
BaselineOxygenText = ReadRangedFloatText(
|
||||
"BaselineOxygen",
|
||||
BaselineOxygenRegister,
|
||||
OxygenMinimum,
|
||||
OxygenMaximum,
|
||||
"0.00");
|
||||
TemperatureText = ReadRangedFloatText(
|
||||
"Temperature",
|
||||
TemperatureRegister,
|
||||
TemperatureMinimum,
|
||||
TemperatureMaximum,
|
||||
"0.00");
|
||||
PressureDifferenceText = ReadRangedFloatText(
|
||||
"PressureDifference",
|
||||
PressureDifferenceRegister,
|
||||
PressureDifferenceMinimum,
|
||||
PressureDifferenceMaximum,
|
||||
"0.00");
|
||||
CalibrationOxygenText = ReadRangedFloatText(
|
||||
"CalibrationOxygen",
|
||||
CalibrationOxygenRegister,
|
||||
OxygenMinimum,
|
||||
OxygenMaximum,
|
||||
"0.00");
|
||||
CValueText = ReadRangedFloatText(
|
||||
"CValue",
|
||||
CValueRegister,
|
||||
CValueMinimum,
|
||||
CValueMaximum,
|
||||
"0.00");
|
||||
MethaneFlowText = ReadRangedFloatText(
|
||||
"MethaneFlow",
|
||||
MethaneFlowRegister,
|
||||
MethaneFlowMinimum,
|
||||
MethaneFlowMaximum,
|
||||
"0.00");
|
||||
RefreshActionStates();
|
||||
}
|
||||
|
||||
private string ReadFloatText(ushort registerAddress)
|
||||
private string ReadRangedFloatText(
|
||||
string label,
|
||||
ushort registerAddress,
|
||||
double minimum,
|
||||
double maximum,
|
||||
string format)
|
||||
{
|
||||
return _tcpDeviceConnectionService.TryReadFloat(registerAddress, out var value)
|
||||
? value.ToString("0.00", CultureInfo.InvariantCulture)
|
||||
: string.Empty;
|
||||
if (!_tcpDeviceConnectionService.TryReadFloatValues(registerAddress, out var result))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
if (!ModbusFloatSelector.TrySelectRangedFloat(result, minimum, maximum, out var byteOrder, out var value, out var matchCount))
|
||||
{
|
||||
LogFloatDiagnostic(label, registerAddress, result, null, matchCount);
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
LogFloatDiagnostic(label, registerAddress, result, byteOrder, matchCount);
|
||||
return NormalizeDisplayValue(value).ToString(format, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
private void LogFloatDiagnostic(
|
||||
string label,
|
||||
ushort registerAddress,
|
||||
ModbusFloatReadResult result,
|
||||
ModbusFloatByteOrder? selectedByteOrder,
|
||||
int matchCount)
|
||||
{
|
||||
if (selectedByteOrder is null)
|
||||
{
|
||||
if (!_loggedInvalidFloatDiagnostics.Add(registerAddress))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (!_loggedFloatDiagnostics.Add(registerAddress))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var selectedText = selectedByteOrder?.ToString() ?? "none";
|
||||
|
||||
Debug.WriteLine(
|
||||
$"C value calibration float {label} register {registerAddress} raw [{result.RawHex}], "
|
||||
+ $"ABCD={result.Abcd:G9}, CDAB={result.Cdab:G9}, "
|
||||
+ $"BADC={result.Badc:G9}, DCBA={result.Dcba:G9}, "
|
||||
+ $"selected={selectedText}, matches={matchCount}.");
|
||||
}
|
||||
|
||||
private static double NormalizeDisplayValue(double value)
|
||||
{
|
||||
return Math.Abs(value) < 0.005 ? 0 : value;
|
||||
}
|
||||
|
||||
private CValueCalibrationActionViewModel CreateAction(
|
||||
|
||||
Reference in New Issue
Block a user