From 505d78a7e096418e95cffd94d1aaaa32f19e25df Mon Sep 17 00:00:00 2001 From: Thomas Wiedebusch Date: Tue, 23 Dec 2025 13:23:41 +0100 Subject: [PATCH] MiniPrf: - function extended, - multilingual --- .../FM2014/FM2014Core/FM2014.cs | 57 ++++++---- MiniPrf/Ui/FrmMainMiniPrf.Designer.cs | 9 +- MiniPrf/Ui/FrmMainMiniPrf.cs | 105 ++++++------------ MiniPrf/Ui/Properties/Resources.Designer.cs | 54 +++++++++ MiniPrf/Ui/Properties/Resources.de.resx | 18 +++ MiniPrf/Ui/Properties/Resources.resx | 18 +++ 6 files changed, 165 insertions(+), 96 deletions(-) diff --git a/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/FM2014.cs b/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/FM2014.cs index ed7a0436..1cfac375 100644 --- a/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/FM2014.cs +++ b/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/FM2014.cs @@ -45,7 +45,7 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core public class FM2014 : IFM2014 { #region properties - + /// /// Logger for raw data output /// @@ -90,35 +90,35 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core } /// - public Boolean UseDampedTolerance + public Boolean UseDampedTolerance { get; private set; } /// - public UInt16 RefPulsePerCm + public UInt16 RefPulsePerCm { get; private set; } /// - public UInt16 DutPulsePerCm + public UInt16 DutPulsePerCm { get; private set; } /// - public Single RefToDutScaleNorm + public Single RefToDutScaleNorm { get; private set; } /// - public Byte Attenuation + public Byte Attenuation { get; private set; @@ -173,29 +173,38 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core } IsLoggedOn = false; - SerialPort.Open(); - - // Establish connection to one specific FM2014 - SerialPort.Write($"**{Address}@\r"); - Thread.Sleep(200); - FullId = SerialPort.ReadTo("\r"); - if (!string.IsNullOrEmpty(FullId)) + try { - FullId = FullId.Replace("*", ""); - var fields = FullId.Split('.'); - FwVersion = fields[1]; + SerialPort.Open(); - // Read out the serial number of this FM2014 - SerialPort.Write("#\r"); - Thread.Sleep(200); - SerialNumber = SerialPort.ReadTo("\r"); - if (!string.IsNullOrEmpty(SerialNumber)) + // Establish connection to one specific FM2014 + SerialPort.ReadTimeout = 1000; + SerialPort.Write($"**{Address}@\r"); + FullId = SerialPort.ReadTo("\r"); + + if (!string.IsNullOrEmpty(FullId)) { - SerialNumber = SerialNumber.Replace("#", ""); - IsLoggedOn = true; + FullId = FullId.Replace("*", ""); + var fields = FullId.Split('.'); + FwVersion = fields[1]; + + // Read out the serial number of this FM2014 + SerialPort.Write("#\r"); + SerialNumber = SerialPort.ReadTo("\r"); + + if (!string.IsNullOrEmpty(SerialNumber)) + { + SerialNumber = SerialNumber.Replace("#", ""); + IsLoggedOn = true; + } } + } - return SerialPort.IsOpen; + catch (Exception e) + { + Console.WriteLine(e); + } + return IsLoggedOn; } /// diff --git a/MiniPrf/Ui/FrmMainMiniPrf.Designer.cs b/MiniPrf/Ui/FrmMainMiniPrf.Designer.cs index e35df5c2..8d6e3784 100644 --- a/MiniPrf/Ui/FrmMainMiniPrf.Designer.cs +++ b/MiniPrf/Ui/FrmMainMiniPrf.Designer.cs @@ -357,7 +357,7 @@ this.tbxScaleRefToDut.Size = new System.Drawing.Size(120, 20); this.tbxScaleRefToDut.TabIndex = 66; // - // lblUpdateTime + // lblUpdateTimeValue // this.lblUpdateTimeValue.AutoSize = true; this.lblUpdateTimeValue.Location = new System.Drawing.Point(290, 393); @@ -371,7 +371,7 @@ this.tmrProgressUpdate.Interval = 200; this.tmrProgressUpdate.Tick += new System.EventHandler(this.tmrProgressUpdate_Tick); // - // lblTime + // lblTimeText // this.lblTimeText.AutoSize = true; this.lblTimeText.Location = new System.Drawing.Point(218, 393); @@ -392,10 +392,11 @@ // // pictureBox1 // + this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.pictureBox1.Image = global::Sensus.MiniPrf.Ui.Properties.Resources.Sensus_Logo; - this.pictureBox1.Location = new System.Drawing.Point(399, 6); + this.pictureBox1.Location = new System.Drawing.Point(395, 6); this.pictureBox1.Name = "pictureBox1"; - this.pictureBox1.Size = new System.Drawing.Size(166, 54); + this.pictureBox1.Size = new System.Drawing.Size(170, 54); this.pictureBox1.TabIndex = 78; this.pictureBox1.TabStop = false; // diff --git a/MiniPrf/Ui/FrmMainMiniPrf.cs b/MiniPrf/Ui/FrmMainMiniPrf.cs index 2c97b5b6..8bc0be46 100644 --- a/MiniPrf/Ui/FrmMainMiniPrf.cs +++ b/MiniPrf/Ui/FrmMainMiniPrf.cs @@ -37,12 +37,10 @@ using Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Config; using Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core; using System; using System.Drawing; -using System.Globalization; using System.IO; using System.IO.Ports; using System.Linq; using System.Reflection; -using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using Sensus.MiniPrf.Ui.Properties; @@ -57,8 +55,6 @@ namespace Sensus.MiniPrf.Ui #region Properties private FM2014 _fm2014; - private const String StrNotConnected = "NOT CONNECTED"; - private const String StrPartPcbConnected = "PCB ID: "; private Boolean _progressBarOn; private DateTimeOffset _startTime; @@ -116,23 +112,28 @@ namespace Sensus.MiniPrf.Ui private void Init() { ViewProcessControl(false); - // Load the configuration from the local file stored in AppData\FM2014 _fm2014Config.ReadFM2014Config(); - // Display actual com-port, if not assigned use the 'NA'. This will be placed on Items[0] - cbxFM2014ComPort.Items.Add(_fm2014Config.SerialPort ?? "?"); - + // Display actual com-port, if not assigned use the '?'. This will be placed on Items[0] + if (_fm2014Config?.SerialPort != null && !cbxFM2014ComPort.Items.Contains(_fm2014Config.SerialPort)) + { + cbxFM2014ComPort.Items.Add(_fm2014Config.SerialPort); + } + else if (_fm2014Config?.SerialPort == null && !cbxFM2014ComPort.Items.Contains("?")) + { + cbxFM2014ComPort.Items.Add("?"); + } // Collect and add all com-ports from device manager to items var comPorts = SerialPort.GetPortNames().ToList(); foreach (var comPort in comPorts.Where(comPort => !cbxFM2014ComPort.Items.Contains(comPort))) { cbxFM2014ComPort.Items.Add(comPort); } - _comPortIdx = 0; - cbxFM2014ComPort.Text = cbxFM2014ComPort.Items[0].ToString(); - - var itemContent = _fm2014Config.Address ?? 1; + //_comPortIdx = 0; + //cbxFM2014ComPort.Text = cbxFM2014ComPort.Items[0].ToString(); + cbxFM2014ComPort.Text = cbxFM2014ComPort.Items[_comPortIdx].ToString(); + var itemContent = _fm2014Config?.Address ?? 1; for (var idx = 0; idx < cbxFM2014Address.MaxDropDownItems; idx++) { if (!cbxFM2014Address.Items[idx].ToString().Equals(itemContent.ToString())) continue; @@ -142,7 +143,7 @@ namespace Sensus.MiniPrf.Ui break; } - itemContent = _fm2014Config.TolerancePercent ?? 3; + itemContent = _fm2014Config?.TolerancePercent ?? 3; for (var idx = 0; idx < cbxFM2014TolerancePercent.MaxDropDownItems; idx++) { if (!cbxFM2014TolerancePercent.Items[idx].ToString().Equals(itemContent.ToString())) continue; @@ -280,7 +281,9 @@ namespace Sensus.MiniPrf.Ui /// private void DisableToolButtons() { - //btnLedOff.Enabled = false; + btnSaveRegulationSetup.Enabled = false; + btnManualRefCalibration.Enabled = false; + btnDutToRefRegulation.Enabled = false; } /// @@ -288,8 +291,9 @@ namespace Sensus.MiniPrf.Ui /// private void EnableToolButtons() { - //btnRead.Enabled = true; - //btnLedOff.Enabled = true; + btnSaveRegulationSetup.Enabled = true; + btnManualRefCalibration.Enabled = true; + btnDutToRefRegulation.Enabled = true; } /// @@ -310,25 +314,17 @@ namespace Sensus.MiniPrf.Ui EnableToolButtons(); } - /// - /// Disable all buttons during operation with device - /// - private void SetControlsLowLevelOpOngoing() - { - btnFM2014Connect.Enabled = false; - DisableToolButtons(); - } - /// /// Restore setting of buttons and timeout after operation with device /// - private void SetControlsLowLevelOpIsFinished() + private void CheckUpdateEnabled() { - if (_fm2014 != null) + if (_fm2014 == null || !_fm2014.IsLoggedOn) { - if (!string.IsNullOrEmpty(_fm2014.FullId)) - SetFM2014AccessEnabled(); + SetFM2014AccessLocked(); + return; } + SetFM2014AccessEnabled(); } #endregion ACtivationControls @@ -350,10 +346,10 @@ namespace Sensus.MiniPrf.Ui { Init(); if (string.IsNullOrEmpty(cbxFM2014ComPort?.SelectedItem?.ToString()) || - cbxFM2014ComPort.SelectedItem.ToString().Equals("NA")) + cbxFM2014ComPort.SelectedItem.ToString().Equals("?")) { - var text = "SERIAL COM PORT CANNOT BE ASSIGNED!"; - MessageBox.Show(text, @"FAILED", MessageBoxButtons.OK, MessageBoxIcon.Error); + var text = Resources.StrErrorMsgComPortNotAssigned; + MessageBox.Show(text, Resources.StrError, MessageBoxButtons.OK, MessageBoxIcon.Error); LogText(text); return; } @@ -375,7 +371,7 @@ namespace Sensus.MiniPrf.Ui else { ActionControl(false); - LogErrorText("ERROR: FM2014 Address is invalid!"); + LogErrorText(Resources.StrErrorMsgFM2014AddressInvalid); } if (int.TryParse(cbxFM2014TolerancePercent.SelectedItem.ToString(), out var tolerancePercent) && (tolerancePercent == 3 || tolerancePercent == 5)) @@ -385,20 +381,19 @@ namespace Sensus.MiniPrf.Ui else { ActionControl(false); - LogErrorText("ERROR: FM2014 Tolerance is invalid!"); + LogErrorText(Resources.StrErrorMsgFM2014ToleranceInvalid); } - lblActualProcess.Text = @"Connecting to FM2014..."; + lblActualProcess.Text = Resources.StrMsgConnecting; _fm2014.Connect(cbxFM2014ComPort.SelectedItem.ToString()); Task.Factory.StartNew(() => { _fm2014.Login(); - if (!_fm2014.IsLoggedOn && string.IsNullOrEmpty(_fm2014.FullId)) + if (!_fm2014.IsLoggedOn) { - ActionControl(false); - LogErrorText("ERROR: Cannot read out FM2014 ID! Access to FM2014 denied!"); + LogErrorText(Resources.StrErrorMsgFM2014AccessDenied); _fm2014.Logout(); return; } @@ -434,7 +429,7 @@ namespace Sensus.MiniPrf.Ui catch (Exception ex) { ActionControl(false); - MessageBox.Show(ex.Message, @"FAILED", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(ex.Message, Resources.StrError, MessageBoxButtons.OK, MessageBoxIcon.Error); LogErrorText(ex.Message); _fm2014?.Dispose(); } @@ -443,17 +438,6 @@ namespace Sensus.MiniPrf.Ui #region ProcessControls - private void CheckUpdateEnabled() - { - if (_fm2014 != null) - { - SetFM2014AccessEnabled(); - return; - } - - SetFM2014AccessLocked(); - } - private void ActionControl(Boolean isActive) { if (isActive) @@ -509,7 +493,7 @@ namespace Sensus.MiniPrf.Ui lblActualProcess.Visible = true; barSingleProgressUpdate.Visible = true; tmrProgressUpdate.Enabled = true; - SetControlsLowLevelOpOngoing(); + SetFM2014AccessLocked(); } else { @@ -518,7 +502,7 @@ namespace Sensus.MiniPrf.Ui tmrProgressUpdate.Enabled = false; lblWaitingForMeterResponse.Visible = false; lblActualProcess.Text = ""; - SetControlsLowLevelOpIsFinished(); + SetFM2014AccessEnabled(); } //common actions and settings @@ -528,21 +512,6 @@ namespace Sensus.MiniPrf.Ui Update(); } - private void StartStopDownload(Boolean isActive) - { - if (isActive) - { - Invoke(new Action(() => - { - ViewProcessControl(true); - tmrProgressUpdate.Enabled = true; - })); - } - else - { - Invoke(new Action(() => { ViewProcessControl(false); })); - } - } #endregion ProcessControls #region InfoWindow @@ -641,7 +610,7 @@ namespace Sensus.MiniPrf.Ui #region Buttons and Controls private void btnConnect_Click(Object sender, EventArgs e) { - //if (_resetTimeMeasurement) + if (_resetTimeMeasurement) { _startTime = DateTimeOffset.UtcNow; _resetTimeMeasurement = false; diff --git a/MiniPrf/Ui/Properties/Resources.Designer.cs b/MiniPrf/Ui/Properties/Resources.Designer.cs index f64f2140..4d96233d 100644 --- a/MiniPrf/Ui/Properties/Resources.Designer.cs +++ b/MiniPrf/Ui/Properties/Resources.Designer.cs @@ -133,6 +133,51 @@ namespace Sensus.MiniPrf.Ui.Properties { } } + /// + /// Looks up a localized string similar to ERROR. + /// + internal static string StrError { + get { + return ResourceManager.GetString("StrError", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to SERIAL COM PORT CANNOT BE ASSIGNED!. + /// + internal static string StrErrorMsgComPortNotAssigned { + get { + return ResourceManager.GetString("StrErrorMsgComPortNotAssigned", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to ERROR: Missing feedback from FM2014! Connection error!. + /// + internal static string StrErrorMsgFM2014AccessDenied { + get { + return ResourceManager.GetString("StrErrorMsgFM2014AccessDenied", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to ERROR: FM2014 Address is invalid!. + /// + internal static string StrErrorMsgFM2014AddressInvalid { + get { + return ResourceManager.GetString("StrErrorMsgFM2014AddressInvalid", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to ERROR: FM2014 Tolerance is invalid!. + /// + internal static string StrErrorMsgFM2014ToleranceInvalid { + get { + return ResourceManager.GetString("StrErrorMsgFM2014ToleranceInvalid", resourceCulture); + } + } + /// /// Looks up a localized string similar to DUT to REF Regulation. /// @@ -313,6 +358,15 @@ namespace Sensus.MiniPrf.Ui.Properties { } } + /// + /// Looks up a localized string similar to Connecting to FM2014. + /// + internal static string StrMsgConnecting { + get { + return ResourceManager.GetString("StrMsgConnecting", resourceCulture); + } + } + /// /// Looks up a localized string similar to Date and Time [min:s]:. /// diff --git a/MiniPrf/Ui/Properties/Resources.de.resx b/MiniPrf/Ui/Properties/Resources.de.resx index d3803050..8811673c 100644 --- a/MiniPrf/Ui/Properties/Resources.de.resx +++ b/MiniPrf/Ui/Properties/Resources.de.resx @@ -121,6 +121,24 @@ ..\Resources\Sensus Logo.JPG;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + FEHLER + + + Verbinde mit FM2014 + + + SERIELLER ANSCHLUSS KANN NICHT BELEGT WERDEN! + + + FEHLER: Ungültige FM2014 Adresse! + + + FEHLER: Ungültige FM2014 Toleranzeinstellung! + + + FEHLER: Keine Rückmeldung vom FM2014 erhalten! Verbindungsfehler! + Seriennummer: diff --git a/MiniPrf/Ui/Properties/Resources.resx b/MiniPrf/Ui/Properties/Resources.resx index d5f812e0..a0b64c58 100644 --- a/MiniPrf/Ui/Properties/Resources.resx +++ b/MiniPrf/Ui/Properties/Resources.resx @@ -121,6 +121,24 @@ ..\Resources\Sensus Logo.JPG;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ERROR + + + Connecting to FM2014 + + + SERIAL COM PORT CANNOT BE ASSIGNED! + + + ERROR: FM2014 Address is invalid! + + + ERROR: FM2014 Tolerance is invalid! + + + ERROR: Missing feedback from FM2014! Connection error! + Serial Number: