FM2014TestBench: - refactor

This commit is contained in:
Thomas Wiedebusch 2026-02-18 13:05:44 +01:00
parent 3628fdafc9
commit abfe13c896
4 changed files with 214 additions and 303 deletions

View File

@ -73,34 +73,49 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Config
public List<Boolean?> SlotIsSelected { get; set; }
/// <summary>
/// Backup REF pulses for calibration measurement to simplify manual setup
/// Backup the REF pulse rate per cubic-meter
/// </summary>
public UInt16 RefPulsesRequired { get; set; } = 500;
public UInt32 RefPulsesPerCm { get; set; } = 1000;
/// <summary>
/// Backup DUT pulses for calibration measurement to simplify manual setup
/// Backup the DUT pulse rate per cubic-meter
/// </summary>
public UInt16 DutPulsesPerCm { get; set; } = 100;
/// <summary>
/// Backup REF pulses for calibration measurement to simplify manual setup.
/// </summary>
public UInt32 RefPulsesRequired { get; set; } = 500;
/// <summary>
/// Backup DUT pulses for calibration measurement to simplify manual setup.
/// </summary>
public UInt16 DutPulsesRequired { get; set; } = 50;
/// <summary>
/// Backup double pulses detection deadtime for calibration measurement to simplify manual setup
/// Current output attenuation for the tolerance display.
/// </summary>
public UInt16 DoublePulseDeadtime { get; set; }
public Byte CurrentOutputAttenuation { get; set; } = 1;
/// <summary>
/// Backup tolerance maximal value for calibration measurement threshold check to simplify manual setup
/// Backup double pulses detection deadtime for calibration measurement to simplify manual setup.
/// </summary>
public Double DutToRefToleranceMax { get; set; } = 0.8;
public UInt16 DoublePulseDeadtime_ms { get; set; } = 1;
/// <summary>
/// Backup tolerance maximal value for calibration measurement threshold check to simplify manual setup
/// Backup tolerance maximal value for calibration measurement threshold check to simplify manual setup.
/// </summary>
public Double DutToRefToleranceMin { get; set; } = -0.5;
public Double DutToRefCalibrationToleranceMax_percent { get; set; } = 0.8;
/// <summary>
/// Backup tolerance maximal value for calibration measurement threshold check to simplify manual setup.
/// </summary>
public Double DutToRefCalibrationToleranceMin_percent { get; set; } = -0.5;
#endregion
#region methods
/// <summary>
/// Load the FM2014 configuration file from the 'C:\ProgramData\FM2014' directory
/// Load the FM2014 configuration file from the 'C:\ProgramData\FM2014' directory.
/// </summary>
/// <remarks date="2025-Nov-13..2026-F3b-16" author="Thomas Wiedebusch">
/// - Initial.
@ -127,16 +142,18 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Config
SlotIsSelected = fm2014Setup.SlotIsSelected;
RefPulsesRequired = fm2014Setup.RefPulsesRequired;
DutPulsesRequired = fm2014Setup.DutPulsesRequired;
DutToRefToleranceMax = fm2014Setup.DutToRefToleranceMax;
DutToRefToleranceMin = fm2014Setup.DutToRefToleranceMin;
DoublePulseDeadtime = fm2014Setup.DoublePulseDeadtime;
DutToRefCalibrationToleranceMax_percent = fm2014Setup.DutToRefCalibrationToleranceMax_percent;
DutToRefCalibrationToleranceMin_percent = fm2014Setup.DutToRefCalibrationToleranceMin_percent;
DoublePulseDeadtime_ms = fm2014Setup.DoublePulseDeadtime_ms;
RefPulsesPerCm = fm2014Setup.RefPulsesPerCm;
DutPulsesPerCm = fm2014Setup.DutPulsesPerCm;
}
return true;
}
/// <summary>
/// Store the FM2014 configuration file from the 'C:\ProgramData\FM2014' directory
/// Store the FM2014 configuration file from the 'C:\ProgramData\FM2014' directory.
/// </summary>
/// <remarks date="2025-Nov-13..2026-Feb-16" author="Thomas Wiedebusch">
/// - Initial.

View File

@ -185,6 +185,11 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
/// Progress counter maximal value for saving settings
/// </summary>
private const Int32 PROCESSES_SAVE_STAND_ALONE_MEASUREMENT = 5;
/// <summary>
/// Internal sleep time to schedule processing time to other threads/tasks
/// </summary>
private const Int32 THREAD_SLEEP_TIME_ms = 20;
#endregion ---------------------------------------- constants -------------------------------------------------
#region ------------------------------------------- events ----------------------------------------------------
/// <summary>
@ -878,7 +883,7 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
/// <returns>true if initialization successfully executed or
/// <see cref="SharedCyclicMeasSequ"/> marks the already started cyclic requests
/// for all registered FM2014s</returns>
/// <remarks date="2026-Jan-10..Feb-14" author="Thomas Wiedebusch">
/// <remarks date="2026-Jan-10..Feb-18" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
public static Boolean PulseCounterMeasurement(Boolean refPulseCtrOn, Boolean dutPulseCtrOn)
@ -1016,7 +1021,11 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
PublishResponse(fm2014, new ProcessExecEventArgs(Resources.StrError,
specificInfoObj: response, statusReturn: StatusReturn.Failed));
}
}
// Idle thread to free time for others
Thread.Sleep(THREAD_SLEEP_TIME_ms);
} // loop all FM2014s
} while (SharedCyclicMeasSequ != CyclicMeasSequ.idle);
}, SharedCancellationToken).ContinueWith(delegate
{
@ -1060,7 +1069,7 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
/// <param name="doublePulseDeadtime_ms"></param>
/// <param name="currentOutputAttenuation"></param>
/// <returns></returns>
/// <remarks date="2026-Jan-14..Feb-14" author="Thomas Wiedebusch">
/// <remarks date="2026-Jan-14..Feb-18" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
public static Boolean RegulationMeasurement(UInt32 refPulses_per_cm, UInt16 dutPulses_per_cm,
@ -1273,7 +1282,11 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
PublishResponse(fm2014, new ProcessExecEventArgs(Resources.StrError,
specificInfoObj: response, statusReturn: StatusReturn.Failed));
}
}
// Idle thread to free time for others
Thread.Sleep(THREAD_SLEEP_TIME_ms);
} // loop all FM2014s
} while (SharedCyclicMeasSequ != CyclicMeasSequ.idle);
}, SharedCancellationToken);
@ -1312,7 +1325,7 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
/// <param name="doublePulseDeadtime_ms">0 if double impulse deadtime detection is off</param>
/// </summary>
/// <returns></returns>
/// <remarks date="2026-Jan-14..Feb-14" author="Thomas Wiedebusch">
/// <remarks date="2026-Jan-14..Feb-18" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
public static Boolean PulseTimeMeasurement(UInt16? refPulsesRequired = null, UInt16? dutPulsesRequired = null,
@ -1598,7 +1611,10 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
PublishResponse(fm2014, new ProcessExecEventArgs(Resources.StrError,
specificInfoObj: response, statusReturn: StatusReturn.Failed));
}
}
// Idle thread to free time for others
Thread.Sleep(THREAD_SLEEP_TIME_ms);
} // loop all FM2014s
// Check all remaining DUT and REF pulses are counted on all connected devices and finalize process by
// reading out all results
@ -2210,16 +2226,18 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
/// all devices.
/// - Additionally, it is going to read out the individual device information for early detection
/// which one is responsive on the SharedSerialPort.
/// - Optional the standalone measurement can be read out for the 'MiniPrf' operation.
/// </summary>
/// <param name="comPort"></param>
/// <param name="readFm2014StandaloneMeasSetup">reading out of standalone measurement required</param>
/// <returns></returns>
/// <remarks date="2026-Jan-28" author="Thomas Wiedebusch">
/// - Support for multiple FM2014s.
/// </remarks>
/// <remarks date="2026-Feb-04..05" author="Thomas Wiedebusch">
/// <remarks date="2026-Feb-04..Feb-18" author="Thomas Wiedebusch">
/// - ´Login to individual FM2014.
/// </remarks>
public Boolean Connect(String comPort)
public Boolean Connect(String comPort, Boolean readFm2014StandaloneMeasSetup = false)
{
if (SharedSerialPort == null)
{
@ -2280,7 +2298,8 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
Lifetime_h = intValue;
}
IsLoggedOn = ReadStandAloneMeasurement(CmdName.CmdReadEepMeasSetup);
if (readFm2014StandaloneMeasSetup)
IsLoggedOn = ReadStandAloneMeasurement(CmdName.CmdReadEepMeasSetup);
}
catch (Exception e)
{

View File

@ -50,6 +50,7 @@ namespace Sensus.Ui.FM2014TestBench
private CancellationTokenSource _cancellationTokenSource;
private CancellationToken _cancellationToken;
// Maximal FM2014 which can be served
private const Int32 MaxFm2014s = 10;
/// <summary>
@ -103,7 +104,7 @@ namespace Sensus.Ui.FM2014TestBench
private static readonly Brush ColorProcessFailed = Brushes.Red;
//private static readonly Color ColorOngoingProcess = Color.Blue;
//private static readonly Color ColorUnknownStatus = Color.Gray;
private static Brush ColorStandardInputField;
private static Brush ColorStandardInputField = Brushes.White;
private static Brush ColorStandardDisplayField;
//private static Brush ColorStandardTextColor;
@ -117,6 +118,10 @@ namespace Sensus.Ui.FM2014TestBench
//private readonly ILogger _logger = NLogHelper.CreateOrGetLogger("FM2014");
private readonly FM2014Config _fm2014Config = new FM2014Config();
// Common FM2014 to take care of all settings and limit chacks on input without real usage as
// connected device.
private readonly FM2014 _fm2014Common = new FM2014();
// internal reminders of changed items to avoid write access on startup if items are preloaded
private Int32 _comPortIdx;
@ -130,16 +135,11 @@ namespace Sensus.Ui.FM2014TestBench
/// </summary>
private Boolean _fm2014RegulationSetupHasChanged;
/// <summary>
/// If the program configuration has changed, this shall be stored to the configuration file
/// </summary>
private Boolean _programConfigSetupHasChanged;
/// <summary>
/// If the program configuration for the calibration measurement has changed, this shall be stored to the
/// configuration file
/// </summary>
private Boolean _programCalibrationSetupHasChanged;
private Boolean _programConfigurationSetupHasChanged;
private String _lastLoggingTextToAvoidRepetition;
@ -167,6 +167,9 @@ namespace Sensus.Ui.FM2014TestBench
private const Int32 CTR_MEASURE_COUNT = 2;
// Hide button to avoid stress to EEPROM of FM2014
private readonly Boolean _displayBtnSaveSetupToFm2014 = false;
#endregion ---------------------------------------- Properties ------------------------------------------------
#region ------------------------------------------- FormControls ----------------------------------------------
/// <summary>
@ -183,7 +186,7 @@ namespace Sensus.Ui.FM2014TestBench
//Thread.CurrentThread.CurrentCulture = cultureInfo;
ColorStandardDisplayField = lblRefPulsesPerCm.Background;
ColorStandardInputField = tbxRefPulsesPerCm.Background;
ColorStandardInputField = chkSlot1.Background;
//ColorStandardTextColor = lblRefPulsesPerCm.Foreground;
_cancellationTokenSource = new CancellationTokenSource();
@ -449,7 +452,7 @@ namespace Sensus.Ui.FM2014TestBench
/// - Slot selections,
/// - Individual hardware tolerance selection.
/// </summary>
/// <remarks date="2025-Nov-13..09" author="Thomas Wiedebusch">
/// <remarks date="2025-Nov-13..2026-Feb-18" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
private void Init()
@ -465,7 +468,7 @@ namespace Sensus.Ui.FM2014TestBench
}
_fm2014RegulationSetupHasChanged = false;
_programCalibrationSetupHasChanged = false;
_programConfigurationSetupHasChanged = false;
// Load the configuration from the local file stored in AppData\FM2014
_fm2014Config.ReadFM2014Config();
@ -512,8 +515,9 @@ namespace Sensus.Ui.FM2014TestBench
if (_fm2014Config?.IndividualCurrentOutputDisplayRangeNominal_percent?[ctr] != null &&
_fm2014Config.IndividualCurrentOutputDisplayRangeNominal_percent.Count == MaxFm2014s)
{
fm2014.CurrentOutputDisplayRangeNominal_percent = _fm2014Config?.IndividualCurrentOutputDisplayRangeNominal_percent[ctr] ??
FM2014.CURRENT_OUTPUT_DISPLAY_RANGE_STANDARD_NOMINAL_percent;
fm2014.CurrentOutputDisplayRangeNominal_percent =
_fm2014Config?.IndividualCurrentOutputDisplayRangeNominal_percent[ctr] ??
FM2014.CURRENT_OUTPUT_DISPLAY_RANGE_STANDARD_NOMINAL_percent;
}
}
if (_fm2014Config != null)
@ -521,12 +525,30 @@ namespace Sensus.Ui.FM2014TestBench
// Restore baudrate
FM2014.Baudrate = _fm2014Config.Baudrate;
// Restore calibration settings for user convenience
tbxRefPulsesRequired.Text = $"{_fm2014Config.RefPulsesRequired:D}";
tbxDutPulsesRequired.Text = $"{_fm2014Config.DutPulsesRequired:D}";
tbxDoublePulseDeadtime.Text = $"{_fm2014Config.DoublePulseDeadtime:D}";
tbxDutToRefTolMax.Text = $"{_fm2014Config.DutToRefToleranceMax:F2}";
tbxDutToRefTolMin.Text = $"{_fm2014Config.DutToRefToleranceMin:F2}";
// Restore calibration settings for user convenience and use the FM2014 properties to limit the settings.
_fm2014Common.RefPulsesRequired = _fm2014Config.RefPulsesRequired;
_fm2014Common.DutPulsesRequired = _fm2014Config.DutPulsesRequired;
_fm2014Common.DoublePulseDeadtime_ms = _fm2014Config.DoublePulseDeadtime_ms;
_fm2014Common.DutToRefCalibrationToleranceMax_percent = _fm2014Config.DutToRefCalibrationToleranceMax_percent;
_fm2014Common.DutToRefCalibrationToleranceMin_percent = _fm2014Config.DutToRefCalibrationToleranceMin_percent;
tbxRefPulsesRequired.Text = $"{_fm2014Common.RefPulsesRequired:D}";
tbxDutPulsesRequired.Text = $"{_fm2014Common.DutPulsesRequired:D}";
tbxDoublePulseDeadtime.Text = $"{_fm2014Common.DoublePulseDeadtime_ms:D}";
tbxDutToRefTolMax.Text = $"{_fm2014Common.DutToRefCalibrationToleranceMax_percent:F2}";
tbxDutToRefTolMin.Text = $"{_fm2014Common.DutToRefCalibrationToleranceMin_percent:F2}";
// Restore pulse to cubic-meter ratios as those will not be taken from the FM2014 standalone measurement but
// the configuration file to avoid stress to the FM2014 EEPROM if a change should remain permanently.
// Using one FM2014 with its properties to build the RefToDutScale and to limit the inputs.
_fm2014Common.RefPulses_per_cm = _fm2014Config.RefPulsesPerCm;
_fm2014Common.DutPulses_per_cm = _fm2014Config.DutPulsesPerCm;
_fm2014Common.CurrentOutputAttenuation = _fm2014Config.CurrentOutputAttenuation;
// Publish the limited and recalculated inputs to the GUI
tbxRefPulsesPerCm.Text = $"{_fm2014Common.RefPulses_per_cm:D}";
tbxDutPulsesPerCm.Text = $"{_fm2014Common.DutPulses_per_cm:D}";
tbxScaleRefToDut.Text = $"{_fm2014Common.RefToDutScale_norm:F4}";
cbxToleranceDisplayAttenuation.SelectedItem = $"{_fm2014Common.CurrentOutputAttenuation}";
// Display on regulation page as common setup for ALL
cbxToleranceDisplayRange.SelectedItem = _fm2014Config.CommonCurrentOutputDisplayRangeNominal_percent.ToString();
@ -577,14 +599,13 @@ namespace Sensus.Ui.FM2014TestBench
// DUT to REF Regulation Setup
lblRefPulsesPerCm.Content = Properties.Resources.StrLblRefPulsesPerCmRatio;
tbxRefPulsesPerCm.Text = "";
lblDutPulsesPerCm.Content = Properties.Resources.StrLblDutPulsesPerCmRatio;
tbxDutPulsesPerCm.Text = "";
lblScaleRefToDut.Content = Properties.Resources.StrLblRefToDutScale;
tbxScaleRefToDut.Text = "";
tbxScaleRefToDut.IsReadOnly = true;
lblToleranceDisplayAttenuation.Content = Properties.Resources.StrLblDisplayAttenuation;
btnSaveSetupToFm2014.Content = Properties.Resources.StrBtnSaveRegulationSetup;
UiElmEnable(btnSaveSetupToFm2014, false, _displayBtnSaveSetupToFm2014);
lblToleranceDisplayRange.Content = Properties.Resources.StrLblFM2014Tolerance;
chkUseDampedTolerance.Content = Properties.Resources.StrChkUseDampedTolerance;
btnDutToRefRegulation.Content = Properties.Resources.StrBtnStartRegulation;
@ -627,11 +648,10 @@ namespace Sensus.Ui.FM2014TestBench
{
if (_fm2014Config == null)
return;
Dispatcher.Invoke(() =>
{
_programConfigSetupHasChanged = false;
_programCalibrationSetupHasChanged = false;
_programConfigurationSetupHasChanged = false;
_fm2014Config.IndividualCurrentOutputDisplayRangeNominal_percent?.Clear();
_fm2014Config.IndividualCurrentOutputDisplayRangeNominal_percent = null;
_fm2014Config.IndividualCurrentOutputDisplayRangeNominal_percent = new List<Int32?>();
@ -652,25 +672,16 @@ namespace Sensus.Ui.FM2014TestBench
_fm2014Config.SlotIsSelected.Add(SlotSelections[ctr].IsChecked);
}
// Restore Calibration settings for user convenience
var firstFm2014 = FM2014.GetFirstConnectedAndLoggedInFm2014();
if (null == firstFm2014)
return;
// Preset the 'firstFm2014' with all items
tbxRefPulsesRequired_LostFocus(this, null);
tbxDutPulsesRequired_LostFocus(this, null);
tbxDoublePulseDeadtime_LostFocus(this, null);
tbxDutToRefToleranceMax_LostFocus(this, null);
tbxDutToRefToleranceMin_LostFocus(this, null);
_fm2014Config.CommonCurrentOutputDisplayRangeNominal_percent =
firstFm2014.CurrentOutputDisplayRangeNominal_percent;
_fm2014Config.RefPulsesRequired = (UInt16)firstFm2014.RefPulsesRequired;
_fm2014Config.DutPulsesRequired = (UInt16)firstFm2014.DutPulsesRequired;
_fm2014Config.DoublePulseDeadtime = firstFm2014.DoublePulseDeadtime_ms;
_fm2014Config.DutToRefToleranceMax = firstFm2014.DutToRefCalibrationToleranceMax_percent;
_fm2014Config.DutToRefToleranceMin = firstFm2014.DutToRefCalibrationToleranceMin_percent;
_fm2014Config.CommonCurrentOutputDisplayRangeNominal_percent =
_fm2014Common.CurrentOutputDisplayRangeNominal_percent;
_fm2014Config.RefPulsesRequired = _fm2014Common.RefPulsesRequired;
_fm2014Config.DutPulsesRequired = (UInt16)_fm2014Common.DutPulsesRequired;
_fm2014Config.DoublePulseDeadtime_ms = _fm2014Common.DoublePulseDeadtime_ms;
_fm2014Config.DutToRefCalibrationToleranceMax_percent = _fm2014Common.DutToRefCalibrationToleranceMax_percent;
_fm2014Config.DutToRefCalibrationToleranceMin_percent = _fm2014Common.DutToRefCalibrationToleranceMin_percent;
_fm2014Config.RefPulsesPerCm = _fm2014Common.RefPulses_per_cm;
_fm2014Config.DutPulsesPerCm = _fm2014Common.DutPulses_per_cm;
_fm2014Config.CurrentOutputAttenuation = _fm2014Common.CurrentOutputAttenuation;
});
_fm2014Config.Update();
@ -685,7 +696,7 @@ namespace Sensus.Ui.FM2014TestBench
{
try
{
if (_programConfigSetupHasChanged || _programCalibrationSetupHasChanged)
if (_programConfigurationSetupHasChanged)
StoreProgramConfiguration();
Init();
@ -853,48 +864,43 @@ 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.
/// </summary>
/// <remarks date="2026-Feb-17" author="Thomas Wiedebusch">
/// <remarks date="2026-Feb-17..18" 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)
if (_initialCurrentOutputAttenuation == _fm2014Common.CurrentOutputAttenuation &&
_initialRefPulsesPerCm == _fm2014Common.RefPulses_per_cm &&
_initialDutPulsesPerCm == _fm2014Common.DutPulses_per_cm)
{
_fm2014RegulationSetupHasChanged = false;
UiElmEnable(btnSaveSetupToFm2014, false);
UiElmEnable(btnSaveSetupToFm2014, false, _displayBtnSaveSetupToFm2014);
return;
}
// Mark that the setup has to be stored to the configuration file
_programConfigurationSetupHasChanged = true;
DutToRefRegulationSetupHasChanged();
}
/// <summary>
/// Common routine for REF to DUT scale check and update
/// </summary>
/// <returns></returns>
/// <remarks date="2026-Jan-14..21" author="Thomas Wiedebusch">
/// <remarks date="2026-Jan-14..Feb-18" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
private Boolean UpdateRefToDutScale()
{
var firstFm2014 = FM2014.GetFirstConnectedAndLoggedInFm2014();
if (null == firstFm2014)
return false;
UpdateTextBox(tbxScaleRefToDut, $@"{firstFm2014.RefToDutScale_norm:F4}");
UpdateTextBox(tbxScaleRefToDut, $@"{_fm2014Common.RefToDutScale_norm:F4}");
// Display error if scale doesn't fit
var tempRefToDutScale_norm = (Double)firstFm2014.RefPulses_per_cm / firstFm2014.DutPulses_per_cm;
var tempRefToDutScale_norm = (Double)_fm2014Common.RefPulses_per_cm / _fm2014Common.DutPulses_per_cm;
if (tempRefToDutScale_norm < FM2014.REF_TO_DUT_SCALE_MIN ||
tempRefToDutScale_norm > FM2014.REF_TO_DUT_SCALE_MAX ||
firstFm2014.RefToDutScale_norm < FM2014.REF_TO_DUT_SCALE_MIN ||
firstFm2014.RefToDutScale_norm > FM2014.REF_TO_DUT_SCALE_MAX)
_fm2014Common.RefToDutScale_norm < FM2014.REF_TO_DUT_SCALE_MIN ||
_fm2014Common.RefToDutScale_norm > FM2014.REF_TO_DUT_SCALE_MAX)
{
Dispatcher.Invoke(() =>
{
@ -913,7 +919,7 @@ namespace Sensus.Ui.FM2014TestBench
}
/// <summary>
/// Common routine to reset the cancellation token on restart or new meter
/// Common routine to reset the cancellation token on restart or new meter.
/// </summary>
/// <remarks date="2026-Jan-26" author="Thomas Wiedebusch">
/// - Initial
@ -1021,7 +1027,7 @@ namespace Sensus.Ui.FM2014TestBench
{
// Disable all buttons
UiElmEnable(btnDutToRefCalibration, false);
UiElmEnable(btnSaveSetupToFm2014, false);
UiElmEnable(btnSaveSetupToFm2014, false, _displayBtnSaveSetupToFm2014);
UiElmEnable(btnDutToRefRegulation, false);
UiElmEnable(btnFM2014Connect, false);
UiElmEnable(btnRefToVolumeCalibration, false);
@ -1062,7 +1068,7 @@ namespace Sensus.Ui.FM2014TestBench
{
// Enable buttons and display correct information
UiElmEnable(btnDutToRefCalibration, true);
UiElmEnable(btnSaveSetupToFm2014, _fm2014RegulationSetupHasChanged); // Activate if setup has changed
UiElmEnable(btnSaveSetupToFm2014, _fm2014RegulationSetupHasChanged, _displayBtnSaveSetupToFm2014);
UiElmEnable(btnDutToRefRegulation, true);
UiElmEnable(btnFM2014Connect, true);
UiElmEnable(btnRefToVolumeCalibration, true);
@ -1112,15 +1118,15 @@ namespace Sensus.Ui.FM2014TestBench
/// <summary>
/// Feedback from FM2014being parsed to GUI
/// </summary>
/// <remarks date="2026-Feb-02..14" author="Thomas Wiedebusch">
/// <remarks date="2026-Feb-02..18" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
private void DataReceived_Handler(Object sender, ProcessExecEventArgs e)
{
try
{
// Remind the FM2014 user control based on the address of the FM2014 to dispatch received message to the
// correct device
// Remind the FM2014 user control based on the address of the FM2014 to dispatch received message to
// the correct device
UcFM2014Device ucFm2014;
if (sender is FM2014 fm2014)
{
@ -1151,7 +1157,7 @@ namespace Sensus.Ui.FM2014TestBench
// Data dispatcher
var resp = (CmdResponse)e.SpecificInfoObj;
String valueStr;
// Used as marker for error, null means measurement is in range or status or health is good
Brush statusColor = null;
@ -1194,16 +1200,25 @@ namespace Sensus.Ui.FM2014TestBench
ucFm2014.SetValue(CTR_LBL_IDX_DUT_PLS, $"{resp.IntValue:D}", statusColor);
break;
case CmdName.CmdSetRefPulsesPerCm:
UpdateTextBox(tbxRefPulsesPerCm, $"{resp.IntValue:D}", statusColor);
_initialRefPulsesPerCm = (UInt32)resp.IntValue;
if (firstFm2014 != null && firstFm2014.Address == fm2014.Address)
{
UpdateTextBox(tbxRefPulsesPerCm, $"{resp.IntValue:D}", statusColor);
_initialRefPulsesPerCm = (UInt32)resp.IntValue;
}
break;
case CmdName.CmdSetDutPulsesPerCm:
UpdateTextBox(tbxDutPulsesPerCm, $"{resp.IntValue:D}", statusColor);
_initialDutPulsesPerCm = (UInt16)resp.IntValue;
if (firstFm2014 != null && firstFm2014.Address == fm2014.Address)
{
UpdateTextBox(tbxDutPulsesPerCm, $"{resp.IntValue:D}", statusColor);
_initialDutPulsesPerCm = (UInt16)resp.IntValue;
}
break;
case CmdName.CmdSetCurrentOutputAttenuation:
Dispatcher.Invoke(() => cbxToleranceDisplayAttenuation.SelectedItem = $"{resp.IntValue}");
_initialCurrentOutputAttenuation = (Byte)resp.IntValue;
if (firstFm2014 != null && firstFm2014.Address == fm2014.Address)
{
Dispatcher.Invoke(() => cbxToleranceDisplayAttenuation.SelectedItem = $"{resp.IntValue}");
_initialCurrentOutputAttenuation = (Byte)resp.IntValue;
}
break;
case CmdName.CmdGetRefFrequency:
valueStr = $"{resp.IntValue:D}";
@ -1242,7 +1257,8 @@ namespace Sensus.Ui.FM2014TestBench
ucFm2014.SetValue(REG_LBL_IDX_DUT_TO_REF_TOL, valueStr, statusColor);
break;
case CmdName.CmdRefToDutScale:
UpdateTextBox(tbxScaleRefToDut, $"{resp.DoubleValue:F4}", statusColor);
if (firstFm2014 != null && firstFm2014.Address == fm2014.Address)
UpdateTextBox(tbxScaleRefToDut, $"{resp.DoubleValue:F4}", statusColor);
break;
// // DEBUG
// case FM2014CmdDef.CmdName.CMD_GET_REF_PERIOD:
@ -1297,7 +1313,7 @@ namespace Sensus.Ui.FM2014TestBench
/// <summary>
/// Start and stop the DUT to REF calibration measurement.
/// </summary>
/// <remarks date="2026-Feb-07..11" author="Thomas Wiedebusch">
/// <remarks date="2026-Feb-07..18" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
private void btnDutToRefCalibration_Click(Object sender, EventArgs e)
@ -1328,45 +1344,6 @@ namespace Sensus.Ui.FM2014TestBench
if (FM2014.RegisteredFm2014s == null || FM2014.RegisteredFm2014s.Count == 0)
return;
// Take the settings from the inputs
UInt16? refPulsesRequired = null;
UInt16? dutPulsesRequired = null;
UInt16 doublePulseDeadtime_ms = 0;
Double toleranceThresholdMax_percent = 1.0;
Double toleranceThresholdMin_percent = -0.7;
Dispatcher.Invoke(() =>
{
if (int.TryParse(tbxRefPulsesRequired.Text, out var pulses) &&
FM2014.PULSES_TIME_MEASUREMENT_INPUT_MIN <= pulses &&
FM2014.PULSES_TIME_MEASUREMENT_INPUT_MAX >= pulses)
{
refPulsesRequired = (UInt16)pulses;
}
if (int.TryParse(tbxDutPulsesRequired.Text, out pulses) &&
FM2014.PULSES_TIME_MEASUREMENT_INPUT_MIN <= pulses &&
FM2014.PULSES_TIME_MEASUREMENT_INPUT_MAX >= pulses)
{
dutPulsesRequired = (UInt16)pulses;
}
if (int.TryParse(tbxDoublePulseDeadtime.Text, out var deadtime_ms) &&
FM2014.DOUBLE_PULSE_DEADTIME_MIN_ms <= deadtime_ms &&
FM2014.DOUBLE_PULSE_DEADTIME_MAX_ms >= deadtime_ms)
{
doublePulseDeadtime_ms = (UInt16)deadtime_ms;
}
var englishNumberFormat = tbxDutToRefTolMax.Text.Replace(',', '.');
if (double.TryParse(englishNumberFormat, NumberStyles.Any, new CultureInfo("en"), out var tolerance))
{
toleranceThresholdMax_percent = tolerance;
}
englishNumberFormat = tbxDutToRefTolMin.Text.Replace(',', '.');
if (double.TryParse(englishNumberFormat, NumberStyles.Any, new CultureInfo("en"), out tolerance))
{
toleranceThresholdMin_percent = tolerance;
}
});
// Adjust the user control
foreach (var fm2014 in FM2014.RegisteredFm2014s.Where(x => x.IsLoggedOn))
{
@ -1375,19 +1352,21 @@ namespace Sensus.Ui.FM2014TestBench
ucFM2014.EnableMeasurements(CAL_MEASURE_COUNT);
// Set initial required pulses as those are static upon the entire measurement
ucFM2014.SetValue(CAL_LBL_IDX_REF_REQ_PLS, refPulsesRequired != null ? $"{refPulsesRequired}" : "---");
ucFM2014.SetValue(CAL_LBL_IDX_DUT_REQ_PLS, dutPulsesRequired != null ? $"{dutPulsesRequired}" : "---");
ucFM2014.SetValue(CAL_LBL_IDX_REF_REQ_PLS, $"{_fm2014Common.RefPulsesRequired:D}");
ucFM2014.SetValue(CAL_LBL_IDX_DUT_REQ_PLS, $"{_fm2014Common.DutPulsesRequired:D}");
// Set thresholds for tolerance verification
fm2014.DutToRefCalibrationToleranceMax_percent = toleranceThresholdMax_percent;
fm2014.DutToRefCalibrationToleranceMin_percent = toleranceThresholdMin_percent;
fm2014.DutToRefCalibrationToleranceMax_percent = _fm2014Common.DutToRefCalibrationToleranceMax_percent;
fm2014.DutToRefCalibrationToleranceMin_percent = _fm2014Common.DutToRefCalibrationToleranceMin_percent;
}
// Backup if meanwhile anything has changed
if (_programConfigSetupHasChanged || _programCalibrationSetupHasChanged)
if (_programConfigurationSetupHasChanged)
StoreProgramConfiguration();
if (FM2014.PulseTimeMeasurement(refPulsesRequired, dutPulsesRequired, doublePulseDeadtime_ms))
if (FM2014.PulseTimeMeasurement((UInt16)_fm2014Common.RefPulsesRequired,
(UInt16)_fm2014Common.DutPulsesRequired,
_fm2014Common.DoublePulseDeadtime_ms))
{
_autoProgressBar = false;
ActionControl(true);
@ -1403,11 +1382,10 @@ namespace Sensus.Ui.FM2014TestBench
}
}
/// <summary>
/// Start and stop the DUT to REF regulation measurement.
/// </summary>
/// <remarks date="2026-Jan-14..Feb-11" author="Thomas Wiedebusch">
/// <remarks date="2026-Jan-14..Feb-18" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
private void btnDutToRefRegulation_Click(Object sender, EventArgs e)
@ -1430,64 +1408,21 @@ namespace Sensus.Ui.FM2014TestBench
if (FM2014.RegisteredFm2014s == null || FM2014.RegisteredFm2014s.Count == 0)
return;
// Take the settings from the inputs
UInt32 refPulses_per_cm = 1000;
UInt16 dutPulses_per_cm = 100;
UInt16 doublePulseDeadtime_ms = 0;
Byte currentOutputAttenuation = 1;
Int32 toleranceSetup = 1;
Dispatcher.Invoke(() =>
{
if (int.TryParse(tbxRefPulsesPerCm.Text, out var pulses_per_cm) &&
FM2014.PULSES_PER_CM_REGULATION_SETUP_MIN <= pulses_per_cm &&
FM2014.REF_PULSES_PER_CM_REGULATION_INPUT_MAX >= pulses_per_cm)
{
refPulses_per_cm = (UInt32)pulses_per_cm;
}
if (int.TryParse(tbxDutPulsesPerCm.Text, out pulses_per_cm) &&
FM2014.PULSES_PER_CM_REGULATION_SETUP_MIN <= pulses_per_cm &&
FM2014.PULSES_PER_CM_REGULATION_SETUP_MAX >= pulses_per_cm)
{
dutPulses_per_cm = (UInt16)pulses_per_cm;
}
if (int.TryParse(tbxDoublePulseDeadtime.Text, out var deadtime_ms) &&
FM2014.DOUBLE_PULSE_DEADTIME_MIN_ms <= deadtime_ms &&
FM2014.DOUBLE_PULSE_DEADTIME_MAX_ms >= deadtime_ms)
{
doublePulseDeadtime_ms = (UInt16)deadtime_ms;
}
if (byte.TryParse(cbxToleranceDisplayAttenuation.SelectedItem.ToString(), out var attenuation) &&
attenuation >= FM2014.CURRENT_OUTPUT_ATTENUATION_MIN &&
attenuation <= FM2014.CURRENT_OUTPUT_ATTENUATION_MAX)
{
currentOutputAttenuation = attenuation;
}
if (int.TryParse(cbxToleranceDisplayRange.SelectedItem.ToString(), out var tolerance) &&
(tolerance == FM2014.CURRENT_OUTPUT_DISPLAY_RANGE_STANDARD_NOMINAL_percent ||
tolerance == FM2014.CURRENT_OUTPUT_DISPLAY_RANGE_EXTENDED_NOMINAL_percent))
{
toleranceSetup = tolerance;
}
});
// Adjust the user control
foreach (var fm2014 in FM2014.RegisteredFm2014s.Where(x => x.IsLoggedOn))
{
var idx = fm2014.Address - 1;
var ucFM2014 = (UcFM2014Device)UcFM2014s[idx];
ucFM2014.EnableMeasurements(REG_MEASURE_COUNT);
fm2014.CurrentOutputDisplayRangeNominal_percent = toleranceSetup;
fm2014.CurrentOutputDisplayRangeNominal_percent = _fm2014Common.CurrentOutputDisplayRangeNominal_percent;
}
// Backup if meanwhile anything has changed
if (_programConfigSetupHasChanged || _programCalibrationSetupHasChanged)
if (_programConfigurationSetupHasChanged || _programConfigurationSetupHasChanged)
StoreProgramConfiguration();
if (FM2014.RegulationMeasurement(refPulses_per_cm, dutPulses_per_cm, doublePulseDeadtime_ms,
currentOutputAttenuation))
if (FM2014.RegulationMeasurement(_fm2014Common.RefPulses_per_cm, _fm2014Common.DutPulses_per_cm,
_fm2014Common.DoublePulseDeadtime_ms, _fm2014Common.CurrentOutputAttenuation))
{
_autoProgressBar = true;
ActionControl(true);
@ -1545,7 +1480,7 @@ namespace Sensus.Ui.FM2014TestBench
}
// Backup if meanwhile anything has changed
if (_programConfigSetupHasChanged || _programCalibrationSetupHasChanged)
if (_programConfigurationSetupHasChanged || _programConfigurationSetupHasChanged)
StoreProgramConfiguration();
if (FM2014.PulseCounterMeasurement(true, measureDutPulses))
@ -1586,25 +1521,21 @@ namespace Sensus.Ui.FM2014TestBench
/// FM2014 tolerance setup for calculation of it item has changed:
/// - This will dispatch the new value to all FM2014s.
/// </summary>
/// <remarks date="2026-Feb-09..Feb-16" author="Thomas Wiedebusch">
/// <remarks date="2026-Feb-09..Feb-18" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
private void cbxToleranceDisplayRange_SelectedIndexChanged(Object sender, EventArgs e)
{
var firstFm2014 = FM2014.GetFirstConnectedAndLoggedInFm2014();
if (null == firstFm2014)
return;
Dispatcher.Invoke(() =>
{
if (byte.TryParse(cbxToleranceDisplayRange.SelectedItem.ToString(), out var tolerance) &&
(tolerance == FM2014.CURRENT_OUTPUT_DISPLAY_RANGE_STANDARD_NOMINAL_percent ||
tolerance == FM2014.CURRENT_OUTPUT_DISPLAY_RANGE_EXTENDED_NOMINAL_percent) &&
firstFm2014.CurrentOutputDisplayRangeNominal_percent != tolerance)
_fm2014Common.CurrentOutputDisplayRangeNominal_percent != tolerance)
{
_programConfigSetupHasChanged = true;
firstFm2014.CurrentOutputDisplayRangeNominal_percent = tolerance;
_programConfigurationSetupHasChanged = true;
_fm2014Common.CurrentOutputDisplayRangeNominal_percent = tolerance;
}
});
}
@ -1630,27 +1561,19 @@ namespace Sensus.Ui.FM2014TestBench
/// FM2014 current attenuation item has changed:
/// - This will dispatch the new value to all FM2014s.
/// </summary>
/// <remarks date="2026-Jan-18" author="Thomas Wiedebusch">
/// <remarks date="2026-Jan-18..Feb-18" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
private void cbxToleranceDisplayAttenuation_SelectedIndexChanged(Object sender, EventArgs e)
{
var firstFm2014 = FM2014.GetFirstConnectedAndLoggedInFm2014();
if (null == firstFm2014)
return;
Dispatcher.Invoke(() =>
{
if (byte.TryParse(cbxToleranceDisplayAttenuation.SelectedItem.ToString(), out var attenuation) &&
attenuation >= FM2014.CURRENT_OUTPUT_ATTENUATION_MIN &&
attenuation <= FM2014.CURRENT_OUTPUT_ATTENUATION_MAX &&
firstFm2014.CurrentOutputAttenuation != attenuation)
_fm2014Common.CurrentOutputAttenuation != attenuation)
{
foreach (var fm2014 in FM2014.RegisteredFm2014s)
{
fm2014.CurrentOutputAttenuation = attenuation;
}
_fm2014Common.CurrentOutputAttenuation = attenuation;
CheckForFM2014SetupChanged();
}
});
@ -1669,7 +1592,7 @@ namespace Sensus.Ui.FM2014TestBench
if (_comPortIdx != cbxProgramComPort.SelectedIndex)
{
_comPortIdx = cbxProgramComPort.SelectedIndex;
_programConfigSetupHasChanged = true;
_programConfigurationSetupHasChanged = true;
}
}
@ -1687,7 +1610,7 @@ namespace Sensus.Ui.FM2014TestBench
if (FM2014.StoreAllConfigurations())
{
_fm2014RegulationSetupHasChanged = false;
UiElmEnable(btnSaveSetupToFm2014, false);
UiElmEnable(btnSaveSetupToFm2014, false, _displayBtnSaveSetupToFm2014);
}
}
@ -1733,6 +1656,7 @@ namespace Sensus.Ui.FM2014TestBench
UiElmEnable(tbxDutPulsesMeasured, isChecked);
});
}
/// <summary>
/// Common check for key input to edit an integer field:
/// - Allows Left, Right, Back, Delete and 0-9 keys . and ,
@ -1823,15 +1747,11 @@ namespace Sensus.Ui.FM2014TestBench
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <remarks date="2026-Feb-09..Feb-16" author="Thomas Wiedebusch">
/// <remarks date="2026-Feb-09..Feb-18" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
private void tbxRefPulsesRequired_LostFocus(Object sender, EventArgs e)
{
var firstFm2014 = FM2014.GetFirstConnectedAndLoggedInFm2014();
if (null == firstFm2014)
return;
Dispatcher.Invoke(() =>
{
if (string.IsNullOrEmpty(tbxRefPulsesRequired.Text))
@ -1840,7 +1760,7 @@ namespace Sensus.Ui.FM2014TestBench
return;
}
// Check for change
var backupPulsesRequired = firstFm2014.RefPulsesRequired;
var backupPulsesRequired = _fm2014Common.RefPulsesRequired;
// Convert the input and check limits
if (int.TryParse(tbxRefPulsesRequired.Text, out var pulses) &&
@ -1849,9 +1769,9 @@ namespace Sensus.Ui.FM2014TestBench
{
if (backupPulsesRequired != pulses)
{
_programCalibrationSetupHasChanged = true;
_programConfigurationSetupHasChanged = true;
// Preset to fill the configuration file storage ability
firstFm2014.RefPulsesRequired = (UInt32)pulses;
_fm2014Common.RefPulsesRequired = (UInt32)pulses;
}
tbxRefPulsesRequired.Background = ColorStandardInputField;
@ -1926,10 +1846,6 @@ namespace Sensus.Ui.FM2014TestBench
/// </remarks>
private void tbxDutPulsesRequired_LostFocus(Object sender, EventArgs e)
{
var firstFm2014 = FM2014.GetFirstConnectedAndLoggedInFm2014();
if (null == firstFm2014)
return;
Dispatcher.Invoke(() =>
{
if (string.IsNullOrEmpty(tbxDutPulsesRequired.Text))
@ -1939,17 +1855,18 @@ namespace Sensus.Ui.FM2014TestBench
}
// Check for change
var backupPulsesRequired = firstFm2014.DutPulsesRequired;
var backupPulsesRequired = _fm2014Common.DutPulsesRequired;
// Convert the input and check limits
if (int.TryParse(tbxDutPulsesRequired.Text, out var pulses) &&
FM2014.PULSES_TIME_MEASUREMENT_INPUT_MIN <= pulses &&
FM2014.PULSES_TIME_MEASUREMENT_INPUT_MAX >= pulses)
{
if (backupPulsesRequired != pulses){
_programCalibrationSetupHasChanged = true;
if (backupPulsesRequired != pulses)
{
_programConfigurationSetupHasChanged = true;
// Preset to fill the configuration file storage ability
firstFm2014.DutPulsesRequired = (UInt32)pulses;
_fm2014Common.DutPulsesRequired = (UInt32)pulses;
}
tbxDutPulsesRequired.Background = ColorStandardInputField;
@ -2010,15 +1927,11 @@ namespace Sensus.Ui.FM2014TestBench
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <remarks date="2026-Feb-09..Feb-16" author="Thomas Wiedebusch">
/// <remarks date="2026-Feb-09..Feb-18" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
private void tbxDoublePulseDeadtime_LostFocus(Object sender, EventArgs e)
{
var firstFm2014 = FM2014.GetFirstConnectedAndLoggedInFm2014();
if (null == firstFm2014)
return;
Dispatcher.Invoke(() =>
{
if (string.IsNullOrEmpty(tbxDoublePulseDeadtime.Text))
@ -2028,7 +1941,7 @@ namespace Sensus.Ui.FM2014TestBench
}
// Check for change
var backupDoublePulseDeadtime = firstFm2014.DoublePulseDeadtime_ms;
var backupDoublePulseDeadtime = _fm2014Common.DoublePulseDeadtime_ms;
// Convert the input and check limits
if (int.TryParse(tbxDoublePulseDeadtime.Text, out var deadtime) &&
@ -2037,9 +1950,9 @@ namespace Sensus.Ui.FM2014TestBench
{
if (backupDoublePulseDeadtime != deadtime)
{
_programCalibrationSetupHasChanged = true;
_programConfigurationSetupHasChanged = true;
// Preset to fill the configuration file storage ability
firstFm2014.DoublePulseDeadtime_ms = (UInt16)deadtime;
_fm2014Common.DoublePulseDeadtime_ms = (UInt16)deadtime;
}
tbxDoublePulseDeadtime.Background = ColorStandardInputField;
@ -2102,15 +2015,11 @@ namespace Sensus.Ui.FM2014TestBench
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <remarks date="2026-Feb-09..Feb-16" author="Thomas Wiedebusch">
/// <remarks date="2026-Feb-09..Feb-18" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
private void tbxDutToRefToleranceMax_LostFocus(Object sender, EventArgs e)
{
var firstFm2014 = FM2014.GetFirstConnectedAndLoggedInFm2014();
if (null == firstFm2014)
return;
Dispatcher.Invoke(() =>
{
@ -2121,32 +2030,24 @@ namespace Sensus.Ui.FM2014TestBench
}
// Check for change
var backupDutToRefTolerance = firstFm2014.DutToRefCalibrationToleranceMax_percent;
var backupDutToRefTolerance = _fm2014Common.DutToRefCalibrationToleranceMax_percent;
var englishNumberFormat = tbxDutToRefTolMax.Text.Replace(',', '.');
if (double.TryParse(englishNumberFormat, NumberStyles.Any, new CultureInfo("en"), out var tolerance))
{
if (Math.Abs(backupDutToRefTolerance - tolerance) > 0.05)
{
_programCalibrationSetupHasChanged = true;
_programConfigurationSetupHasChanged = true;
// Preset to fill the configuration file storage ability
firstFm2014.DutToRefCalibrationToleranceMax_percent = tolerance;
_fm2014Common.DutToRefCalibrationToleranceMax_percent = tolerance;
}
tbxDutToRefTolMax.Background = ColorStandardInputField;
// Dispatch settings to all connected FM2014!!!!
foreach (var fm2014 in FM2014.RegisteredFm2014s)
{
fm2014.DutToRefCalibrationToleranceMax_percent = tolerance;
}
}
else
{
tbxDutToRefTolMax.Background = ColorProcessFailed;
}
});
}
@ -2200,15 +2101,11 @@ namespace Sensus.Ui.FM2014TestBench
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <remarks date="2026-Feb-09..Feb-16" author="Thomas Wiedebusch">
/// <remarks date="2026-Feb-09..Feb-18" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
private void tbxDutToRefToleranceMin_LostFocus(Object sender, EventArgs e)
{
var firstFm2014 = FM2014.GetFirstConnectedAndLoggedInFm2014();
if (null == firstFm2014)
return;
Dispatcher.Invoke(() =>
{
@ -2219,25 +2116,19 @@ namespace Sensus.Ui.FM2014TestBench
}
// Check for change
var backupDutToRefTolerance = firstFm2014.DutToRefCalibrationToleranceMin_percent;
var backupDutToRefTolerance = _fm2014Common.DutToRefCalibrationToleranceMin_percent;
var englishNumberFormat = tbxDutToRefTolMin.Text.Replace(',', '.');
if (double.TryParse(englishNumberFormat, NumberStyles.Any, new CultureInfo("en"), out var tolerance))
{
if (Math.Abs(backupDutToRefTolerance - tolerance) > 0.05)
{
_programCalibrationSetupHasChanged = true;
_programConfigurationSetupHasChanged = true;
// Preset to fill the configuration file storage ability
firstFm2014.DutToRefCalibrationToleranceMin_percent = tolerance;
_fm2014Common.DutToRefCalibrationToleranceMin_percent = tolerance;
}
tbxDutToRefTolMin.Background = ColorStandardInputField;
// Dispatch settings to all connected FM2014!!!!
foreach (var fm2014 in FM2014.RegisteredFm2014s)
{
fm2014.DutToRefCalibrationToleranceMin_percent = tolerance;
}
}
else
{
@ -2295,15 +2186,11 @@ namespace Sensus.Ui.FM2014TestBench
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <remarks date="2026-Jan-14..24" author="Thomas Wiedebusch">
/// <remarks date="2026-Jan-14..Feb-18" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
private void tbxRefPulsesPerCm_LostFocus(Object sender, EventArgs e)
{
var firstFm2014 = FM2014.GetFirstConnectedAndLoggedInFm2014();
if (null == firstFm2014)
return;
Dispatcher.Invoke(() =>
{
if (string.IsNullOrEmpty(tbxRefPulsesPerCm.Text))
@ -2320,10 +2207,7 @@ namespace Sensus.Ui.FM2014TestBench
FM2014.REF_PULSES_PER_CM_REGULATION_INPUT_MAX >= pulses_per_cm)
{
// During setup of the 'Ref_pulse_per_cm' the 'RefToDutScaleStr' will be generated
foreach (var fm2014 in FM2014.RegisteredFm2014s)
{
fm2014.RefPulses_per_cm = (UInt32)pulses_per_cm;
}
_fm2014Common.RefPulses_per_cm = (UInt32)pulses_per_cm;
if (!UpdateRefToDutScale())
{
@ -2331,6 +2215,7 @@ namespace Sensus.Ui.FM2014TestBench
return;
}
_programConfigurationSetupHasChanged = true;
tbxRefPulsesPerCm.Background = ColorStandardInputField;
CheckForFM2014SetupChanged();
}
@ -2389,15 +2274,11 @@ namespace Sensus.Ui.FM2014TestBench
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <remarks date="2026-Jan-14..24" author="Thomas Wiedebusch">
/// <remarks date="2026-Jan-14..Feb-18" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
private void tbxDutPulsesPerCm_LostFocus(Object sender, EventArgs e)
{
var firstFm2014 = FM2014.GetFirstConnectedAndLoggedInFm2014();
if (null == firstFm2014)
return;
Dispatcher.Invoke(() =>
{
if (string.IsNullOrEmpty(tbxDutPulsesPerCm.Text))
@ -2414,10 +2295,7 @@ namespace Sensus.Ui.FM2014TestBench
FM2014.PULSES_PER_CM_REGULATION_SETUP_MAX >= pulses_per_cm)
{
// During setup of the 'Dut_pulse_per_cm' the 'RefToDutScaleStr' will be generated
foreach (var fm2014 in FM2014.RegisteredFm2014s)
{
fm2014.DutPulses_per_cm = (UInt16)pulses_per_cm;
}
_fm2014Common.DutPulses_per_cm = (UInt16)pulses_per_cm;
if (!UpdateRefToDutScale())
{
@ -2425,6 +2303,7 @@ namespace Sensus.Ui.FM2014TestBench
return;
}
_programConfigurationSetupHasChanged = true;
tbxDutPulsesPerCm.Background = ColorStandardInputField;
CheckForFM2014SetupChanged();
}
@ -2486,15 +2365,11 @@ namespace Sensus.Ui.FM2014TestBench
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <remarks date="2026-Feb-09..10" author="Thomas Wiedebusch">
/// <remarks date="2026-Feb-09..18" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
private void tbxVolumeMeasuredLiters_LostFocus(Object sender, EventArgs e)
{
var firstFm2014 = FM2014.GetFirstConnectedAndLoggedInFm2014();
if (null == firstFm2014)
return;
Dispatcher.Invoke(() =>
{
@ -2514,24 +2389,24 @@ namespace Sensus.Ui.FM2014TestBench
var pulses_per_cm = (UInt32)(pulses / (liters / 1000.0) + 0.5);
// Try to set the new calculated REF pulses limited by the property setter
firstFm2014.RefPulses_per_cm = pulses_per_cm;
_fm2014Common.RefPulses_per_cm = pulses_per_cm;
// If this succeeded, then update the new manual calibrated value
if (pulses_per_cm == firstFm2014.RefPulses_per_cm)
if (pulses_per_cm == _fm2014Common.RefPulses_per_cm)
{
tbxRefPulsesPerCm.Text = $@"{firstFm2014.RefPulses_per_cm:D}";
tbxRefPulsesPerCm.Background = ColorStandardDisplayField;
tbxRefPulsesPerCmCalib.Text = $@"{firstFm2014.RefPulses_per_cm:D}";
tbxRefPulsesPerCmCalib.Background = ColorStandardDisplayField;
tbxVolumeMeasuredLiters.Background = ColorStandardInputField;
tbxRefPulsesPerCm.Text = $@"{_fm2014Common.RefPulses_per_cm:D}";
tbxRefPulsesPerCmCalib.Text = $@"{_fm2014Common.RefPulses_per_cm:D}";
if (!UpdateRefToDutScale())
{
tbxVolumeMeasuredLiters.Background = ColorProcessFailed;
tbxRefPulsesPerCmCalib.Background = ColorProcessFailed;
tbxRefPulsesPerCm.Background = ColorProcessFailed;
return;
}
tbxVolumeMeasuredLiters.Background = ColorStandardInputField;
_programConfigurationSetupHasChanged = true;
tbxRefPulsesPerCmCalib.Background = ColorStandardDisplayField;
tbxRefPulsesPerCm.Background = ColorStandardInputField;
tbxVolumeMeasuredLiters.Background = ColorStandardInputField;
CheckForFM2014SetupChanged();
}
@ -2547,7 +2422,7 @@ namespace Sensus.Ui.FM2014TestBench
private void chkAnySlot_Click(Object sender, RoutedEventArgs e)
{
_programConfigSetupHasChanged = true;
_programConfigurationSetupHasChanged = true;
}
/// <summary>

View File

@ -479,7 +479,7 @@ namespace Sensus.MiniPrf.Ui
}
lblActualProcess.Text = Resources.StrMsgConnecting;
Fm2014.Connect(cbxProgramComPort.SelectedItem.ToString());
Fm2014.Connect(cbxProgramComPort.SelectedItem.ToString(), true);
Task.Factory.StartNew(() =>
{