MiniPrf: - function extended, - multilingual

This commit is contained in:
Thomas Wiedebusch 2025-12-23 13:23:41 +01:00
parent 1340fa691f
commit 505d78a7e0
6 changed files with 165 additions and 96 deletions

View File

@ -45,7 +45,7 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
public class FM2014 : IFM2014
{
#region properties
/// <summary>
/// Logger for raw data output
/// </summary>
@ -90,35 +90,35 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
}
/// <inheritdoc/>
public Boolean UseDampedTolerance
public Boolean UseDampedTolerance
{
get;
private set;
}
/// <inheritdoc/>
public UInt16 RefPulsePerCm
public UInt16 RefPulsePerCm
{
get;
private set;
}
/// <inheritdoc/>
public UInt16 DutPulsePerCm
public UInt16 DutPulsePerCm
{
get;
private set;
}
/// <inheritdoc/>
public Single RefToDutScaleNorm
public Single RefToDutScaleNorm
{
get;
private set;
}
/// <inheritdoc/>
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;
}
/// <inheritdoc/>

View File

@ -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;
//

View File

@ -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
/// </summary>
private void DisableToolButtons()
{
//btnLedOff.Enabled = false;
btnSaveRegulationSetup.Enabled = false;
btnManualRefCalibration.Enabled = false;
btnDutToRefRegulation.Enabled = false;
}
/// <summary>
@ -288,8 +291,9 @@ namespace Sensus.MiniPrf.Ui
/// </summary>
private void EnableToolButtons()
{
//btnRead.Enabled = true;
//btnLedOff.Enabled = true;
btnSaveRegulationSetup.Enabled = true;
btnManualRefCalibration.Enabled = true;
btnDutToRefRegulation.Enabled = true;
}
/// <summary>
@ -310,25 +314,17 @@ namespace Sensus.MiniPrf.Ui
EnableToolButtons();
}
/// <summary>
/// Disable all buttons during operation with device
/// </summary>
private void SetControlsLowLevelOpOngoing()
{
btnFM2014Connect.Enabled = false;
DisableToolButtons();
}
/// <summary>
/// Restore setting of buttons and timeout after operation with device
/// </summary>
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;

View File

@ -133,6 +133,51 @@ namespace Sensus.MiniPrf.Ui.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to ERROR.
/// </summary>
internal static string StrError {
get {
return ResourceManager.GetString("StrError", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to SERIAL COM PORT CANNOT BE ASSIGNED!.
/// </summary>
internal static string StrErrorMsgComPortNotAssigned {
get {
return ResourceManager.GetString("StrErrorMsgComPortNotAssigned", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to ERROR: Missing feedback from FM2014! Connection error!.
/// </summary>
internal static string StrErrorMsgFM2014AccessDenied {
get {
return ResourceManager.GetString("StrErrorMsgFM2014AccessDenied", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to ERROR: FM2014 Address is invalid!.
/// </summary>
internal static string StrErrorMsgFM2014AddressInvalid {
get {
return ResourceManager.GetString("StrErrorMsgFM2014AddressInvalid", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to ERROR: FM2014 Tolerance is invalid!.
/// </summary>
internal static string StrErrorMsgFM2014ToleranceInvalid {
get {
return ResourceManager.GetString("StrErrorMsgFM2014ToleranceInvalid", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to DUT to REF Regulation.
/// </summary>
@ -313,6 +358,15 @@ namespace Sensus.MiniPrf.Ui.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Connecting to FM2014.
/// </summary>
internal static string StrMsgConnecting {
get {
return ResourceManager.GetString("StrMsgConnecting", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Date and Time [min:s]:.
/// </summary>

View File

@ -121,6 +121,24 @@
<data name="Sensus Logo" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Sensus Logo.JPG;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="StrError" xml:space="preserve">
<value>FEHLER</value>
</data>
<data name="StrMsgConnecting" xml:space="preserve">
<value>Verbinde mit FM2014</value>
</data>
<data name="StrErrorMsgComPortNotAssigned" xml:space="preserve">
<value>SERIELLER ANSCHLUSS KANN NICHT BELEGT WERDEN!</value>
</data>
<data name="StrErrorMsgFM2014AddressInvalid" xml:space="preserve">
<value>FEHLER: Ungültige FM2014 Adresse!</value>
</data>
<data name="StrErrorMsgFM2014ToleranceInvalid" xml:space="preserve">
<value>FEHLER: Ungültige FM2014 Toleranzeinstellung!</value>
</data>
<data name="StrErrorMsgFM2014AccessDenied" xml:space="preserve">
<value>FEHLER: Keine Rückmeldung vom FM2014 erhalten! Verbindungsfehler!</value>
</data>
<data name="StrLblFM2014SerialNumber" xml:space="preserve">
<value>Seriennummer:</value>
</data>

View File

@ -121,6 +121,24 @@
<data name="Sensus Logo" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Sensus Logo.JPG;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="StrError" xml:space="preserve">
<value>ERROR</value>
</data>
<data name="StrMsgConnecting" xml:space="preserve">
<value>Connecting to FM2014</value>
</data>
<data name="StrErrorMsgComPortNotAssigned" xml:space="preserve">
<value>SERIAL COM PORT CANNOT BE ASSIGNED!</value>
</data>
<data name="StrErrorMsgFM2014AddressInvalid" xml:space="preserve">
<value>ERROR: FM2014 Address is invalid!</value>
</data>
<data name="StrErrorMsgFM2014ToleranceInvalid" xml:space="preserve">
<value>ERROR: FM2014 Tolerance is invalid!</value>
</data>
<data name="StrErrorMsgFM2014AccessDenied" xml:space="preserve">
<value>ERROR: Missing feedback from FM2014! Connection error!</value>
</data>
<data name="StrLblFM2014SerialNumber" xml:space="preserve">
<value>Serial Number:</value>
</data>