From 3628fdafc9045d3e54800cc18c1a5973e3b89658 Mon Sep 17 00:00:00 2001 From: Thomas Wiedebusch Date: Tue, 17 Feb 2026 17:29:08 +0100 Subject: [PATCH] FM2014TestApp: - adapted to refactored FM2014 --- .../FM2014/FM2014Core/Consts/CmdName.cs | 6 +- .../FM2014/FM2014Core/FM2014.cs | 6 +- .../FM2014/FM2014Core/FM2014CmdDef.cs | 6 +- .../Fm2014sTest/FM2014TestBenchWindow.xaml.cs | 122 +++++++++--------- .../UserControls/UcFM2014Device.xaml.cs | 13 +- 5 files changed, 80 insertions(+), 73 deletions(-) diff --git a/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/Consts/CmdName.cs b/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/Consts/CmdName.cs index 5bfd4870..1c66bb55 100644 --- a/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/Consts/CmdName.cs +++ b/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/Consts/CmdName.cs @@ -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 /// - CmdRefSetPulsesRequired, + CmdSetRefPulsesRequired, /// /// 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 /// /// Read the remaining pulses set up with the 'CmdSetRefPulsesRequired' time measurement command /// - CmdRefPulsesRemaining, + CmdGetRefPulsesRemaining, /// /// Read the remaining pulses set up with the 'CmdSetDutPulsesRequired' time measurement command /// - CmdDutGetPulsesRemaining, + CmdGetDutPulsesRemaining, /// /// Start the REF pulses counter diff --git a/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/FM2014.cs b/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/FM2014.cs index 40ae6ccb..0f15a737 100644 --- a/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/FM2014.cs +++ b/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/FM2014.cs @@ -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)) { diff --git a/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/FM2014CmdDef.cs b/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/FM2014CmdDef.cs index 4572ebe0..8e03f34c 100644 --- a/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/FM2014CmdDef.cs +++ b/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/FM2014CmdDef.cs @@ -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), diff --git a/FM2014TestApp/Ui/Fm2014sTest/FM2014TestBenchWindow.xaml.cs b/FM2014TestApp/Ui/Fm2014sTest/FM2014TestBenchWindow.xaml.cs index c862aa71..78f40bf0 100644 --- a/FM2014TestApp/Ui/Fm2014sTest/FM2014TestBenchWindow.xaml.cs +++ b/FM2014TestApp/Ui/Fm2014sTest/FM2014TestBenchWindow.xaml.cs @@ -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; /// /// 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 } + /// + /// 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. + /// + /// + /// - Initial. + /// + 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(); + } /// /// Common routine for REF to DUT scale check and update /// @@ -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 { diff --git a/FM2014TestApp/Ui/Fm2014sTest/UserControls/UcFM2014Device.xaml.cs b/FM2014TestApp/Ui/Fm2014sTest/UserControls/UcFM2014Device.xaml.cs index 325383e3..2d86675f 100644 --- a/FM2014TestApp/Ui/Fm2014sTest/UserControls/UcFM2014Device.xaml.cs +++ b/FM2014TestApp/Ui/Fm2014sTest/UserControls/UcFM2014Device.xaml.cs @@ -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 /// 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;