FM2014TestApp: - adapted to refactored FM2014

This commit is contained in:
Thomas Wiedebusch 2026-02-17 17:29:08 +01:00
parent d9f1c9fe78
commit 3628fdafc9
5 changed files with 80 additions and 73 deletions

View File

@ -128,7 +128,7 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core.Co
/// Set the pulses for a time measurement for the REF, if the DUT is going to be started, the first
/// rising edge of the DUT pulse will synchronize the REF and start the REF counter from the beginning
/// </summary>
CmdRefSetPulsesRequired,
CmdSetRefPulsesRequired,
/// <summary>
/// Set the pulses for a time measurement for the DUT, if the DUT is going to be started, the first
@ -139,12 +139,12 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core.Co
/// <summary>
/// Read the remaining pulses set up with the 'CmdSetRefPulsesRequired' time measurement command
/// </summary>
CmdRefPulsesRemaining,
CmdGetRefPulsesRemaining,
/// <summary>
/// Read the remaining pulses set up with the 'CmdSetDutPulsesRequired' time measurement command
/// </summary>
CmdDutGetPulsesRemaining,
CmdGetDutPulsesRemaining,
/// <summary>
/// Start the REF pulses counter

View File

@ -1386,7 +1386,7 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
if (firstActiveFm2014.RefPulsesRequired != 0)
{
cmdName = CmdName.CmdRefSetPulsesRequired;
cmdName = CmdName.CmdSetRefPulsesRequired;
if (!Write(cmdName, firstActiveFm2014, firstActiveFm2014.RefPulsesRequired))
{
return false;
@ -1447,7 +1447,7 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
// Read the remaining REF pulses if required
if (fm2014.RefPulsesRequired != 0)
{
cmdName = CmdName.CmdRefPulsesRemaining;
cmdName = CmdName.CmdGetRefPulsesRemaining;
info = GetCmdInfo(cmdName);
if (SharedCyclicMeasSequ != CyclicMeasSequ.idle && Write(cmdName, fm2014))
{
@ -1482,7 +1482,7 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
// Read the remaining DUT pulses if required
if (fm2014.DutPulsesRequired != 0)
{
cmdName = CmdName.CmdDutGetPulsesRemaining;
cmdName = CmdName.CmdGetDutPulsesRemaining;
info = GetCmdInfo(cmdName);
if (SharedCyclicMeasSequ != CyclicMeasSequ.idle && Write(cmdName, fm2014))
{

View File

@ -102,9 +102,9 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
new Cmd(CmdName.CmdSwitchDoublePulseDeadtimeOff, "G", CmdType.broadcast, ParaFormat.parameterless, Resources.StrCmdMsgSetDbplUnlock),
// Main measurement pulse settings and readout
new Cmd(CmdName.CmdSetDutPulsesRequired, "H", CmdType.broadcast, ParaFormat.uintHexValue, Resources.StrCmdMsgDutSetPls),
new Cmd(CmdName.CmdRefSetPulsesRequired, "M", CmdType.broadcast, ParaFormat.uintHexValue, Resources.StrCmdMsgRefSetPls),
new Cmd(CmdName.CmdDutGetPulsesRemaining, "I", CmdType.individual, ParaFormat.uintHexValue, Resources.StrCmdMsgDutGetPlsRmn),
new Cmd(CmdName.CmdRefPulsesRemaining, "J", CmdType.individual, ParaFormat.uintHexValue, Resources.StrCmdMsgRefGetPlsRmn),
new Cmd(CmdName.CmdSetRefPulsesRequired, "M", CmdType.broadcast, ParaFormat.uintHexValue, Resources.StrCmdMsgRefSetPls),
new Cmd(CmdName.CmdGetDutPulsesRemaining, "I", CmdType.individual, ParaFormat.uintHexValue, Resources.StrCmdMsgDutGetPlsRmn),
new Cmd(CmdName.CmdGetRefPulsesRemaining, "J", CmdType.individual, ParaFormat.uintHexValue, Resources.StrCmdMsgRefGetPlsRmn),
// Pulse counters start, readout and backup
new Cmd(CmdName.CmdStartRefPulseCounter, "O", CmdType.broadcast, ParaFormat.parameterless, Resources.StrCmdMsgRefStrPlsCtr),
new Cmd(CmdName.CmdStartDutPulseCounter, "Q", CmdType.broadcast, ParaFormat.parameterless, Resources.StrCmdMsgDutStrPlsCtr),

View File

@ -28,9 +28,9 @@ using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core.Consts;
using Xylem.Common.CommonCore.Consts;
using Xylem.Common.Utils.ProcessExec.EventArguments;
using static Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core.Consts.FM2014CmdDef;
using CheckBox = System.Windows.Controls.CheckBox;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using Label = System.Windows.Controls.Label;
@ -120,13 +120,10 @@ namespace Sensus.Ui.FM2014TestBench
// internal reminders of changed items to avoid write access on startup if items are preloaded
private Int32 _comPortIdx;
// Backups of results from 'Manual REF Calibration' being able to restore those if a manual change
// of the REF pulses per cubic meter clears those fields. Bringing the last calibrated REF pulses
// per cubic meters back will automatically restore these results being able to adjust the measured
// volume in liters without a restart of the 'Manual REF Calibration'
//private String _backupWeightScaleVolumeLitersStr;
//private String _backupRefCalibrationResultPulsePerCmStr;
//private String _backupMeasuredRefPulsesStr;
// Reminder of settings in standalone measurement to avoid repeated storage af already stored values
private UInt32 _initialRefPulsesPerCm;
private UInt16 _initialDutPulsesPerCm;
private Byte _initialCurrentOutputAttenuation;
/// <summary>
/// The regulation setup will be stored directly to the FM2014 being able to use it at startup
@ -731,10 +728,10 @@ namespace Sensus.Ui.FM2014TestBench
if (!slotShallBeUsed || !fm2014.Connect(comPort))
{
ucFm2014Device.SetConnectionStatus(ConnectionStatusName.OFFLINE);
ucFm2014Device.SetConnectionStatus(ConnectionStatusName.offline);
continue;
}
ucFm2014Device.SetConnectionStatus(ConnectionStatusName.ONLINE);
ucFm2014Device.SetConnectionStatus(ConnectionStatusName.online);
if (!fm2014.IsLoggedOn)
{
@ -852,6 +849,31 @@ namespace Sensus.Ui.FM2014TestBench
}
/// <summary>
/// This method checks if any setting applied to the FM2014 memory has been changed.
/// Initially, those values will be read and preset during the connection procedure.
/// </summary>
/// <remarks date="2026-Feb-17" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
private void CheckForFM2014SetupChanged()
{
var firstFm2014 = FM2014.GetFirstConnectedAndLoggedInFm2014();
if (null == firstFm2014)
return;
// Avoid stress to the FM2014 EEPROM as the identical values mustn't be stored again
if (_initialCurrentOutputAttenuation == firstFm2014.CurrentOutputAttenuation &&
_initialRefPulsesPerCm == firstFm2014.RefPulses_per_cm &&
_initialDutPulsesPerCm == firstFm2014.DutPulses_per_cm)
{
_fm2014RegulationSetupHasChanged = false;
UiElmEnable(btnSaveSetupToFm2014, false);
return;
}
DutToRefRegulationSetupHasChanged();
}
/// <summary>
/// Common routine for REF to DUT scale check and update
/// </summary>
@ -1153,38 +1175,41 @@ namespace Sensus.Ui.FM2014TestBench
LogText($"{resp.AnswerStr}: {resp.IntValue:D} {resp.Unit}");
switch (resp.CmdName)
{
case CmdName.CMD_REF_GET_PLS_RMN:
case CmdName.CmdGetRefPulsesRemaining:
ucFm2014.SetValue(CAL_LBL_IDX_REF_RMN_PLS, $"{resp.IntValue:D}", statusColor);
break;
case CmdName.CMD_DUT_GET_PLS_RMN:
case CmdName.CmdGetDutPulsesRemaining:
ucFm2014.SetValue(CAL_LBL_IDX_DUT_RMN_PLS, $"{resp.IntValue:D}", statusColor);
break;
case CmdName.CMD_REF_GET_PLS_CTR:
case CmdName.CMD_REF_GET_PLS_CTR_BU:
case CmdName.CmdGetRefPulsesCounted:
case CmdName.CmdGetRefPulsesCountedBackup:
if (firstFm2014 != null && firstFm2014.Address == fm2014.Address)
UpdateTextBox(tbxRefPulsesMeasured, $"{resp.IntValue:D}", statusColor);
ucFm2014.SetValue(CTR_LBL_IDX_REF_PLS, $"{resp.IntValue:D}", statusColor);
break;
case CmdName.CMD_DUT_GET_PLS_CTR:
case CmdName.CMD_DUT_GET_PLS_CTR_BU:
case CmdName.CmdGetDutPulsesCounted:
case CmdName.CmdGetDutPulsesCountedBackup:
if (firstFm2014 != null && firstFm2014.Address == fm2014.Address)
UpdateTextBox(tbxDutPulsesMeasured, $"{resp.IntValue:D}", statusColor);
ucFm2014.SetValue(CTR_LBL_IDX_DUT_PLS, $"{resp.IntValue:D}", statusColor);
break;
case CmdName.CMD_REF_LPP_SCALE:
case CmdName.CmdSetRefPulsesPerCm:
UpdateTextBox(tbxRefPulsesPerCm, $"{resp.IntValue:D}", statusColor);
_initialRefPulsesPerCm = (UInt32)resp.IntValue;
break;
case CmdName.CMD_DUT_LPP_SCALE:
case CmdName.CmdSetDutPulsesPerCm:
UpdateTextBox(tbxDutPulsesPerCm, $"{resp.IntValue:D}", statusColor);
_initialDutPulsesPerCm = (UInt16)resp.IntValue;
break;
case CmdName.CMD_MEAS_SET_ATTN:
case CmdName.CmdSetCurrentOutputAttenuation:
Dispatcher.Invoke(() => cbxToleranceDisplayAttenuation.SelectedItem = $"{resp.IntValue}");
_initialCurrentOutputAttenuation = (Byte)resp.IntValue;
break;
case CmdName.CMD_GET_REF_FREQU:
case CmdName.CmdGetRefFrequency:
valueStr = $"{resp.IntValue:D}";
ucFm2014.SetValue(REG_LBL_IDX_REF_FREQU, valueStr, statusColor);
break;
case CmdName.CMD_RST_MEAS:
case CmdName.CmdResetMeasurement:
// Immediately lock all buttons and input fields until reset is finished
SetFM2014AccessLocked();
UiElmEnable(lblActualProgressPercent, true);
@ -1199,24 +1224,24 @@ namespace Sensus.Ui.FM2014TestBench
LogText($"{resp.AnswerStr}: {resp.DoubleValue:F2} {resp.Unit}");
switch (resp.CmdName)
{
case CmdName.CMD_REF_GET_TMR:
case CmdName.CmdGetRefTimerTicks:
valueStr = $"{resp.DoubleValue:F3}";
ucFm2014.SetValue(CAL_LBL_IDX_REF_MEAS_TMR, valueStr, statusColor);
break;
case CmdName.CMD_DUT_GET_TMR:
case CmdName.CmdGetDutTimerTicks:
valueStr = $"{resp.DoubleValue:F3}";
ucFm2014.SetValue(CAL_LBL_IDX_DUT_MEAS_TMR, valueStr, statusColor);
break;
case CmdName.CMD_CAL_DUT_TO_REF_TOL:
case CmdName.CmdCalculatedDutToRefTolerance:
valueStr = $"{resp.DoubleValue:F3}";
ucFm2014.SetValue(CAL_LBL_IDX_DUT_TO_REF_TOL, valueStr, statusColor);
break;
case CmdName.CMD_GET_UDTLC:
case CmdName.CMD_GET_DTLC:
case CmdName.CmdGetDutToRefToleranceUndamped:
case CmdName.CmdGetDutToRefToleranceDamped:
valueStr = $"{resp.DoubleValue:F2}";
ucFm2014.SetValue(REG_LBL_IDX_DUT_TO_REF_TOL, valueStr, statusColor);
break;
case CmdName.CMD_REF_SET_SCALE:
case CmdName.CmdRefToDutScale:
UpdateTextBox(tbxScaleRefToDut, $"{resp.DoubleValue:F4}", statusColor);
break;
// // DEBUG
@ -1232,7 +1257,7 @@ namespace Sensus.Ui.FM2014TestBench
// case FM2014CmdDef.CmdName.CMD_CAL_FREQU_DUT_PERIOD:
// tbxDutFrequencyFromDutPeriodHz.Text = $"{resp.DoubleValue:F3}";
// break;
case CmdName.CMD_CAL_FLOW_REF_FREQU:
case CmdName.CmdCalculatedFlowRefFrequ:
valueStr = $"{resp.DoubleValue:F3}";
ucFm2014.SetValue(REG_LBL_IDX_FLOW_RATE, valueStr, statusColor);
//UpdateTextBox(tbxRefFlowRateFromRefFrequencyCmPerH, valueStr);
@ -1278,7 +1303,7 @@ namespace Sensus.Ui.FM2014TestBench
private void btnDutToRefCalibration_Click(Object sender, EventArgs e)
{
_startTime = DateTimeOffset.UtcNow;
if (FM2014.SharedCyclicMeasSequ == CyclicMeasSequ.IDLE)
if (FM2014.SharedCyclicMeasSequ == CyclicMeasSequ.idle)
{
// Disable and hide dynamic measurement labels
foreach (var measLbl in MeasurementLabels)
@ -1388,7 +1413,7 @@ namespace Sensus.Ui.FM2014TestBench
private void btnDutToRefRegulation_Click(Object sender, EventArgs e)
{
_startTime = DateTimeOffset.UtcNow;
if (FM2014.SharedCyclicMeasSequ == CyclicMeasSequ.IDLE)
if (FM2014.SharedCyclicMeasSequ == CyclicMeasSequ.idle)
{
// Disable and hide dynamic measurement labels
foreach (var measLbl in MeasurementLabels)
@ -1488,7 +1513,7 @@ namespace Sensus.Ui.FM2014TestBench
private void btnRefToVolumeCalibration_Click(Object sender, EventArgs e)
{
_startTime = DateTimeOffset.UtcNow;
if (FM2014.SharedCyclicMeasSequ == CyclicMeasSequ.IDLE)
if (FM2014.SharedCyclicMeasSequ == CyclicMeasSequ.idle)
{
// Disable and hide dynamic measurement labels
foreach (var measLbl in MeasurementLabels)
@ -1626,8 +1651,7 @@ namespace Sensus.Ui.FM2014TestBench
{
fm2014.CurrentOutputAttenuation = attenuation;
}
_fm2014RegulationSetupHasChanged = true;
UiElmEnable(btnSaveSetupToFm2014, true);
CheckForFM2014SetupChanged();
}
});
}
@ -2290,9 +2314,6 @@ namespace Sensus.Ui.FM2014TestBench
return;
}
//Backup the actual setting to detect changes
var backupPulses_per_cm = firstFm2014.RefPulses_per_cm;
// Parse and check limits
if (int.TryParse(tbxRefPulsesPerCm.Text, out var pulses_per_cm) &&
FM2014.PULSES_PER_CM_REGULATION_SETUP_MIN <= pulses_per_cm &&
@ -2310,11 +2331,8 @@ namespace Sensus.Ui.FM2014TestBench
return;
}
// Check if values have changed and need to be updated in the standalone setup
if (backupPulses_per_cm != pulses_per_cm || tbxRefPulsesPerCm.Background == ColorProcessFailed)
{
DutToRefRegulationSetupHasChanged();
}
tbxRefPulsesPerCm.Background = ColorStandardInputField;
CheckForFM2014SetupChanged();
}
else
{
@ -2390,9 +2408,6 @@ namespace Sensus.Ui.FM2014TestBench
return;
}
//Backup the actual setting to detect changes
var backupPulses_per_cm = firstFm2014.DutPulses_per_cm;
// Parse and check limits
if (int.TryParse(tbxDutPulsesPerCm.Text, out var pulses_per_cm) &&
FM2014.PULSES_PER_CM_REGULATION_SETUP_MIN <= pulses_per_cm &&
@ -2410,11 +2425,8 @@ namespace Sensus.Ui.FM2014TestBench
return;
}
// Check if values have changed and need to be updated in the standalone setup
if (backupPulses_per_cm != pulses_per_cm || tbxDutPulsesPerCm.Background == ColorProcessFailed)
{
DutToRefRegulationSetupHasChanged();
}
tbxDutPulsesPerCm.Background = ColorStandardInputField;
CheckForFM2014SetupChanged();
}
else
{
@ -2494,9 +2506,6 @@ namespace Sensus.Ui.FM2014TestBench
return;
}
// Backup the old value
var backup_pulses_per_cm = firstFm2014.DutPulses_per_cm;
// Calculate REF pulses per cubic meter
if (int.TryParse(tbxRefPulsesMeasured.Text, out var pulses) && pulses > 0 &&
int.TryParse(tbxVolumeMeasuredLiters.Text, out var liters) && liters > 0)
@ -2522,12 +2531,9 @@ namespace Sensus.Ui.FM2014TestBench
tbxRefPulsesPerCmCalib.Background = ColorProcessFailed;
return;
}
// Check if values have changed and need to be updated in the standalone setup
if (backup_pulses_per_cm != firstFm2014.RefPulses_per_cm)
{
DutToRefRegulationSetupHasChanged();
}
tbxVolumeMeasuredLiters.Background = ColorStandardInputField;
tbxVolumeMeasuredLiters.Background = ColorStandardInputField;
CheckForFM2014SetupChanged();
}
else
{

View File

@ -16,7 +16,8 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Threading;
using static Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core.Consts.FM2014CmdDef;
using Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core.Consts;
using static Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core.FM2014CmdDef;
namespace Sensus.Ui.Fm2014TestBench.UserControls
{
@ -80,7 +81,7 @@ namespace Sensus.Ui.Fm2014TestBench.UserControls
///<inheritdoc/>
public void Clear()
{
SetConnectionStatus(ConnectionStatusName.OFFLINE);
SetConnectionStatus(ConnectionStatusName.offline);
HideMeasurements();
}
@ -124,7 +125,7 @@ namespace Sensus.Ui.Fm2014TestBench.UserControls
private void HideMeasurements()
{
UiElmEnable(brdFM2014Pic, true);
UiElmEnable(picFM2014, lblStatus.Content.Equals(ConnectionStatusName.ONLINE));
UiElmEnable(picFM2014, lblStatus.Content.Equals(ConnectionStatusName.online));
// Hide all measurement borders
foreach (var borders in MeasurementBorders)
@ -155,7 +156,7 @@ namespace Sensus.Ui.Fm2014TestBench.UserControls
}
// Check if device is connected and logged in
if (!lblStatus.Content.Equals(GetConnectionStatusInfo(ConnectionStatusName.ONLINE)))
if (!lblStatus.Content.Equals(GetConnectionStatusInfo(ConnectionStatusName.online)))
return false;
if (numberOfMeasurementFields == 0)
@ -193,9 +194,9 @@ namespace Sensus.Ui.Fm2014TestBench.UserControls
new Action(() =>
{
lblStatus.Content = connectionStatusStr;
var isEnabled = statusName.Equals(ConnectionStatusName.ONLINE);
var isEnabled = statusName.Equals(ConnectionStatusName.online);
UiElmEnable(picFM2014, isEnabled);
if (!statusName.Equals(ConnectionStatusName.ONLINE))
if (!statusName.Equals(ConnectionStatusName.online))
{
HideMeasurements();
lblStatus.Background = ColorStandardDisplayField;