diff --git a/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/FM2014.cs b/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/FM2014.cs index d5cf9442..2cdee8f1 100644 --- a/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/FM2014.cs +++ b/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/FM2014.cs @@ -160,7 +160,7 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core { get; set; - } = false; + } private UInt16 _ref_pulse_per_cm = 1000; /// @@ -511,10 +511,9 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core { cmdName = UseDampedTolerance ? CmdName.CMD_GET_DTLC : CmdName.CMD_GET_UDTLC; var info = GetCmdInfo(cmdName); - var responseStr = ""; if (Write(cmdName)) { - responseStr = SerialPort.ReadTo(END_OF_STR); + var responseStr = SerialPort.ReadTo(END_OF_STR); var signMultiplier = responseStr.Contains("+") ? 1.0f : -1.0f; var cleanedStr = responseStr.Replace("+", "").Replace("-",""); if (int.TryParse(cleanedStr, NumberStyles.HexNumber, new CultureInfo("en"), out var measTolerance)) @@ -764,6 +763,8 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core return true; CyclicReceiveTaskLoopIsActive = false; + // Schedule to other tasks + Thread.Sleep(100); // Reset measurement var infoStr = GetCmdInfo(CmdName.CMD_RST_MEAS); if (!Write(CmdName.CMD_RST_MEAS)) diff --git a/MiniPrf/Ui/FrmMainMiniPrf.Designer.cs b/MiniPrf/Ui/FrmMainMiniPrf.Designer.cs index c92470c6..afd43eec 100644 --- a/MiniPrf/Ui/FrmMainMiniPrf.Designer.cs +++ b/MiniPrf/Ui/FrmMainMiniPrf.Designer.cs @@ -467,9 +467,9 @@ this.lblWeightScaleVolume.AutoSize = true; this.lblWeightScaleVolume.Location = new System.Drawing.Point(10, 53); this.lblWeightScaleVolume.Name = "lblWeightScaleVolume"; - this.lblWeightScaleVolume.Size = new System.Drawing.Size(107, 13); + this.lblWeightScaleVolume.Size = new System.Drawing.Size(19, 13); this.lblWeightScaleVolume.TabIndex = 70; - this.lblWeightScaleVolume.Text = "Weight Scale [liters]:"; + this.lblWeightScaleVolume.Text = "ba"; // // tbxWeightScaleVolumeLiters // diff --git a/MiniPrf/Ui/FrmMainMiniPrf.cs b/MiniPrf/Ui/FrmMainMiniPrf.cs index 5c370111..41d86dc2 100644 --- a/MiniPrf/Ui/FrmMainMiniPrf.cs +++ b/MiniPrf/Ui/FrmMainMiniPrf.cs @@ -103,6 +103,15 @@ namespace Sensus.MiniPrf.Ui private Int32 _comPortIdx; private Int32 _addressIdx; private Int32 _toleranceIdx; + + // 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; + private Boolean _regulationSetupHasChanged; #endregion Properties @@ -465,6 +474,9 @@ namespace Sensus.MiniPrf.Ui tbxFM2014FullId.Visible = true; tbxFM2014ApplicationFwVersion.Text = Fm2014.FwVersion; tbxFM2014SerialNumber.Text = Fm2014.SerialNumber; + tbxRefPulsePerCm.Text = $@"{Fm2014.Ref_pulse_per_cm:D}"; + tbxDutPulsePerCm.Text = $@"{Fm2014.Dut_pulse_per_cm:D}"; + tbxScaleRefToDut.Text = $@"{Fm2014.RefToDutScale_norm:F3}"; // Logging to history window LogText("FM2014 ID:\t\t" + Fm2014.FullId); @@ -695,6 +707,16 @@ namespace Sensus.MiniPrf.Ui if (!Fm2014.CyclicReceiveTaskLoopIsActive) { ActionControl(true); + tbxMeasuredRefPulses.Text = ""; + tbxWeightScaleVolumeLiters.Text = ""; + tbxRefCalibrationResultPulsePerCm.Text = ""; + tbxActualFlowRateCmPerHour.Text = ""; + tbxActualMeasuredToleranceDutToRef.Text = ""; + + _backupMeasuredRefPulsesStr = ""; + _backupRefCalibrationResultPulsePerCmStr = ""; + _backupWeightScaleVolumeLitersStr = ""; + _autoProgressBar = true; if (Fm2014.PulseCounterMeasurement()) { @@ -755,10 +777,6 @@ namespace Sensus.MiniPrf.Ui tbxRefPulsePerVolume_Leave(this, null); } } - - private String _backupWeightScaleVolumeLitersStr; - private String _backupRefCalibrationResultPulsePerCmStr; - private String _backupMeasuredRefPulsesStr; /// /// After manual input of the REF pulses per cubic meter the scale REF to DUT has to be recalculated /// @@ -766,30 +784,37 @@ namespace Sensus.MiniPrf.Ui /// private void tbxRefPulsePerVolume_Leave(Object sender, EventArgs e) { - _regulationSetupHasChanged = true; // Setup FM2014 if (Fm2014 != null && int.TryParse(tbxRefPulsePerCm.Text, out var pulses_per_cm)) { - Fm2014.Ref_pulse_per_cm = (UInt16)pulses_per_cm; - tbxScaleRefToDut.Text = $@"{Fm2014.RefToDutScale_norm:F3}"; - // If the REF pulses per cubic meter have been changed manually, the 'Manual REF Calibration' - // fields have to be cleared if those are different. A backup to restore it may be useful. - if (!tbxRefPulsePerCm.Text.Equals(tbxRefCalibrationResultPulsePerCm.Text) && - !string.IsNullOrEmpty(tbxRefCalibrationResultPulsePerCm.Text)) + if (pulses_per_cm != Fm2014.Ref_pulse_per_cm) { - _backupMeasuredRefPulsesStr = tbxMeasuredRefPulses.Text; - tbxMeasuredRefPulses.Text = ""; - _backupRefCalibrationResultPulsePerCmStr = tbxRefCalibrationResultPulsePerCm.Text; - tbxRefCalibrationResultPulsePerCm.Text = ""; - _backupWeightScaleVolumeLitersStr = tbxWeightScaleVolumeLiters.Text; - tbxWeightScaleVolumeLiters.Text = ""; - } - // Restore values if REF pulses per cubic meters is back to the calibrated one - else if (tbxRefPulsePerCm.Text.Equals(_backupRefCalibrationResultPulsePerCmStr)) - { - tbxMeasuredRefPulses.Text = _backupMeasuredRefPulsesStr; - tbxRefCalibrationResultPulsePerCm.Text = _backupRefCalibrationResultPulsePerCmStr; - tbxWeightScaleVolumeLiters.Text = _backupWeightScaleVolumeLitersStr; + _regulationSetupHasChanged = true; + btnSaveRegulationSetup.Enabled = true; + tbxActualFlowRateCmPerHour.Text = ""; + tbxActualMeasuredToleranceDutToRef.Text = ""; + + Fm2014.Ref_pulse_per_cm = (UInt16)pulses_per_cm; + tbxScaleRefToDut.Text = $@"{Fm2014.RefToDutScale_norm:F3}"; + // If the REF pulses per cubic meter have been changed manually, the 'Manual REF Calibration' + // fields have to be cleared if those are different. A backup to restore it may be useful. + if (!tbxRefPulsePerCm.Text.Equals(tbxRefCalibrationResultPulsePerCm.Text) && + !string.IsNullOrEmpty(tbxRefCalibrationResultPulsePerCm.Text)) + { + _backupMeasuredRefPulsesStr = tbxMeasuredRefPulses.Text; + tbxMeasuredRefPulses.Text = ""; + _backupRefCalibrationResultPulsePerCmStr = tbxRefCalibrationResultPulsePerCm.Text; + tbxRefCalibrationResultPulsePerCm.Text = ""; + _backupWeightScaleVolumeLitersStr = tbxWeightScaleVolumeLiters.Text; + tbxWeightScaleVolumeLiters.Text = ""; + } + // Restore values if REF pulses per cubic meters is back to the calibrated one + else if (tbxRefPulsePerCm.Text.Equals(_backupRefCalibrationResultPulsePerCmStr)) + { + tbxMeasuredRefPulses.Text = _backupMeasuredRefPulsesStr; + tbxRefCalibrationResultPulsePerCm.Text = _backupRefCalibrationResultPulsePerCmStr; + tbxWeightScaleVolumeLiters.Text = _backupWeightScaleVolumeLitersStr; + } } } } @@ -812,14 +837,22 @@ namespace Sensus.MiniPrf.Ui /// private void tbxDutPulsePerVolume_Leave(Object sender, EventArgs e) { - _regulationSetupHasChanged = true; // Setup FM2014 if (Fm2014 != null && int.TryParse(tbxDutPulsePerCm.Text, out var pulses_per_cm)) { - Fm2014.Dut_pulse_per_cm = (UInt16)pulses_per_cm; - tbxScaleRefToDut.Text = $@"{Fm2014.RefToDutScale_norm:F3}"; + if (pulses_per_cm != Fm2014.Dut_pulse_per_cm) + { + _regulationSetupHasChanged = true; + btnSaveRegulationSetup.Enabled = true; + tbxActualFlowRateCmPerHour.Text = ""; + tbxActualMeasuredToleranceDutToRef.Text = ""; + + Fm2014.Dut_pulse_per_cm = (UInt16)pulses_per_cm; + tbxScaleRefToDut.Text = $@"{Fm2014.RefToDutScale_norm:F3}"; + } } } + /// /// Redirect keystroke 'Enter' to leaving the cell event /// @@ -850,6 +883,10 @@ namespace Sensus.MiniPrf.Ui if (!tbxRefCalibrationResultPulsePerCm.Text.Equals(tbxRefPulsePerCm.Text)) { _regulationSetupHasChanged = true; + btnSaveRegulationSetup.Enabled = true; + tbxActualFlowRateCmPerHour.Text = ""; + tbxActualMeasuredToleranceDutToRef.Text = ""; + tbxRefPulsePerCm.Text = tbxRefCalibrationResultPulsePerCm.Text; // Setup FM2014 if (Fm2014 != null && int.TryParse(tbxRefCalibrationResultPulsePerCm.Text, out var pulses_per_cm)) @@ -907,6 +944,8 @@ namespace Sensus.MiniPrf.Ui } } + // Catch the latest information + Update(); })); } diff --git a/MiniPrf/Ui/Properties/Resources.Designer.cs b/MiniPrf/Ui/Properties/Resources.Designer.cs index eab07817..4dbdba56 100644 --- a/MiniPrf/Ui/Properties/Resources.Designer.cs +++ b/MiniPrf/Ui/Properties/Resources.Designer.cs @@ -305,7 +305,7 @@ namespace Sensus.MiniPrf.Ui.Properties { } /// - /// Looks up a localized string similar to Weight Scale [l]:. + /// Looks up a localized string similar to Volume [liters]:. /// internal static string StrLblMeasuredWeightScaleVolume { get { diff --git a/MiniPrf/Ui/Properties/Resources.de.resx b/MiniPrf/Ui/Properties/Resources.de.resx index db40117e..f7f8013c 100644 --- a/MiniPrf/Ui/Properties/Resources.de.resx +++ b/MiniPrf/Ui/Properties/Resources.de.resx @@ -197,7 +197,7 @@ Gemessene REF [Pulse]: - Waageninhalt [l]: + Volumen [Liter]: DUT zu REF Regulierung diff --git a/MiniPrf/Ui/Properties/Resources.resx b/MiniPrf/Ui/Properties/Resources.resx index 439f6717..a99da3e8 100644 --- a/MiniPrf/Ui/Properties/Resources.resx +++ b/MiniPrf/Ui/Properties/Resources.resx @@ -197,7 +197,7 @@ Measured REF [pulses]: - Weight Scale [l]: + Volume [liters]: DUT to REF Regulation