common/Ui/GenesisToolBox/FrmQsTool.cs
2026-04-23 17:50:07 +02:00

909 lines
35 KiB
C#

using Logic.ProductionToProductMapper.Cordonel;
using NLog;
using System;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Xylem.Common.Hardware.WaterMeter.Genesis.Applications.Const;
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore;
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore.Consts;
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisStatus;
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers;
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers.DataTypes;
using Xylem.Common.Hardware.WaterMeter.WaterMeterCore;
using Xylem.Common.Utils.Logging;
using Register = Xylem.Common.Hardware.WaterMeter.Genesis.Registers.Register;
namespace Xylem.Common.Ui.GenesisToolBox
{
public partial class FrmQsTool : Form
{
#region Properties
private readonly MeterBatch _meterBatch = new MeterBatch();
private GenesisMeter _currentGenesis;
private const String StrNotConnected = "NOT CONNECTED";
private const String StrPartPcbConnected = "PCB ID: ";
private const String StrBurnUpgrade = "Waiting for meter response";
private Boolean _progressBarOn;
private DateTimeOffset _startTime;
private Boolean _resetTimeMeasurement;
private readonly Boolean _updateGui = true;
private Boolean _autoProgressBar;
// external update remarks form
private readonly FrmHistory _frmHistory = new FrmHistory();
private readonly Version _version;
// status information
private static readonly Color ColorDefault = Color.Black;
private static readonly Color ColorSuccess = Color.Green;
private static readonly Color ColorProcessFailed = Color.Red;
//private static readonly Color ColorOngoingProcess = Color.Blue;
//private static readonly Color ColorUnknownStatus = Color.Gray;
//private const String SuccessSign = @"✔";
//private const String FailedSign = @"✘";
private const String StrSeparator = "--------------------------------------------------" +
"--------------------------------------------------" +
"--------------------------------------------------";
private readonly ILogger logger = NLogHelper.CreateOrGetLogger("GenesisConfigurator");
#endregion Properties
#region FormControls
/// <summary>
/// Ctor FW update
/// </summary>
public FrmQsTool()
{
InitializeComponent();
var cultureInfo = new CultureInfo("en-GB");
Thread.CurrentThread.CurrentUICulture = cultureInfo;
Thread.CurrentThread.CurrentCulture = cultureInfo;
_version = Assembly.GetExecutingAssembly().GetName().Version;
}
/// <summary>
/// Clear data table and set genesis to not connected
/// </summary>
private void Init()
{
ViewProcessControl(false);
lblConnectPcb.Text = StrNotConnected;
lblConnectPcb.ForeColor = Color.Red;
lblWaitingForMeterResponse.Visible = false;
tbxMeterFw.Text = "";
tbxMeterLutCrc.Text = "";
tbxMeterSize.Text = "";
tbxRegion.Text = "";
tbxDateTime.Text = "";
tbxRadio.Text = "";
tbxExpiredLifeTime.Text = "";
tbxDrainedLoad_uAs.Text = "";
tbxBatteries.Text = "";
tbxInitialBatteryLoad.Text = "";
tbxDrainedBatteryLoad_percent.Text = "";
tbxRemainingLifeTimeFw.Text = "";
tbxRemainingLifeTimeSw.Text = "";
tbxStorageMonths.Text = "";
SetCordonelAccessLocked();
tbxPcbId.Visible = false;
btnConnect.Focus();
}
private void FrmQsTool_Load(Object sender, EventArgs e)
{
var version = Assembly.GetExecutingAssembly().GetName().Version;
lblFwUpdateInfo.Text = $@"GTB Version: {version.Major}.{version.Minor}.{version.Build}";
_resetTimeMeasurement = true;
Init();
var xPosition = Location.X + Size.Width;
var yPosition = Location.Y;
if (_frmHistory != null)
{
_frmHistory.SetDesktopLocation(xPosition, yPosition);
_frmHistory.Show();
}
LogText($"GenesisToolBox: {_version.Major}.{_version.Minor}.{_version.Build}");
LogText(StrSeparator);
}
private void FrmQsTool_FormClosing(Object sender, FormClosingEventArgs e)
{
_frmHistory?.Close();
_currentGenesis?.Logout();
_meterBatch?.RemoveAllMeters();
_meterBatch?.Dispose();
Dispose();
}
private void cbComSlot_SelectedIndexChanged(Object sender, EventArgs e)
{
_resetTimeMeasurement = true;
Init();
}
#endregion FormControls
#region TimerControls
private void tmrProgressUpdate_Tick(Object sender, EventArgs e)
{
//cbxManualControl.Visible = true;
if (_autoProgressBar || _progressBarOn)
{
//barOverallProgressUpdate.Value =
// barOverallProgressUpdate.Value + 1 > 100 ? 0 : barOverallProgressUpdate.Value + 1;
barSingleProgressUpdate.Value =
barSingleProgressUpdate.Value + 4 > 100 ? 0 : barSingleProgressUpdate.Value + 4;
}
SetTimeDisplay();
Update();
}
private void SetTimeDisplay()
{
var time = DateTimeOffset.UtcNow;
var timeSpan = time - _startTime;
lblUpdateTime.Text = $@"{(UInt32)timeSpan.TotalMinutes}:{timeSpan.Seconds:00}";
}
#endregion TimerControls
#region ActivationControls
/// <summary>
/// Disable all buttons except the connect button
/// </summary>
private void DisableToolButtons()
{
//btnRead.Enabled = false;
btnLedOff.Enabled = false;
}
/// <summary>
/// Enable all buttons except the connect button
/// </summary>
private void EnableToolButtons()
{
//btnRead.Enabled = true;
btnLedOff.Enabled = true;
}
/// <summary>
/// Lock all buttons, enable the connect button
/// </summary>
private void SetCordonelAccessLocked()
{
btnConnect.Enabled = true;
DisableToolButtons();
}
/// <summary>
/// Enable all buttons, Cordonel has to be connected
/// </summary>
private void SetCordonelAccessEnabled()
{
btnConnect.Enabled = true;
EnableToolButtons();
}
/// <summary>
/// Disable all buttons during operation with device
/// </summary>
private void SetControlsLowLevelOpOngoing()
{
btnConnect.Enabled = false;
DisableToolButtons();
}
/// <summary>
/// Restore setting of buttons and timeout after operation with device
/// </summary>
private void SetControlsLowLevelOpIsFinished()
{
if (_currentGenesis != null)
{
_currentGenesis.RequestProtocol.AdditionalRetryTimeoutMs = 0;
if (!string.IsNullOrEmpty(_currentGenesis.PcbId))
SetCordonelAccessEnabled();
}
}
#endregion ACtivationControls
#region BoardControls
/// <summary>
/// Establish connection
/// </summary>
/// <remarks date="2025-Aug-07" author="Thomas Wiedebusch">
/// - Compare the max supported FW versions of the configuration.json.
/// </remarks>
/// <remarks date="2025-Oct-02" author="Thomas Wiedebusch">
/// - Catch error message on unknown data type and kill meter.
/// </remarks>
private void Connect()
{
try
{
Init();
if (string.IsNullOrEmpty(cbComSlot.SelectedItem.ToString()) ||
!int.TryParse(cbComSlot.SelectedItem.ToString(), out var slotNr))
{
return;
}
//lblOverall.Text = @"Login to Cordonel...";
LowLevelActionControl(true);
_currentGenesis?.DisposeMeter();
//dispose old meter
_meterBatch.RemoveAllMeters();
_currentGenesis = null;
//assign new meter and assign meter to FW update file if this exists
_currentGenesis = new GenesisMeter();
_currentGenesis.UseOfflinePasswords = cbxUseOfflinePwds.Checked;
_currentGenesis.SetupFromConfigFile(slotNr);
_meterBatch.AddMeter(_currentGenesis);
_currentGenesis.Configuration.UseRegisterWatchService = false;
_currentGenesis.Configuration.UseMinMaxCheck = false;
lblActualProcess.Text = @"Connecting to PCB...";
Task.Factory.StartNew(() =>
{
_meterBatch.MetersLogin();
if (!_currentGenesis.IsLoggedOn && String.IsNullOrEmpty(_currentGenesis.PcbId))
{
LowLevelActionControl(false);
LogErrorText("ERROR: Cannot read out PcbId! Access to Cordonel denied!");
return;
}
if (_currentGenesis.IsLoggedOn)
{
Invoke(new Action(() =>
{
lblConnectPcb.Text = StrPartPcbConnected;
tbxPcbId.Text = _currentGenesis.PcbId;
tbxPcbId.Visible = true;
tbxMeterFw.Text = _currentGenesis.FwVersion;
tbxMeterSize.Text = _currentGenesis.MeterSize;
tbxMeterLutCrc.Text = _currentGenesis.LutCrc;
tbxRegion.Text = _currentGenesis.Region;
LogText("Meter FW Version:\t" + _currentGenesis.FwVersion);
LogText("Meter LUT CRC:\t" + _currentGenesis.LutCrc);
LogText("Meter Size:\t" + _currentGenesis.MeterSize);
LogText("Meter Region:\t" + _currentGenesis.Region);
if (_currentGenesis.RadioFrequencyMhz != null)
{
tbxRadio.Text = $@"{_currentGenesis.RadioFrequencyMhz}";
LogText("Radio frequency:\t" + $"{_currentGenesis.RadioFrequencyMhz} MHz");
}
LogText("");
LogText("'Configuration.json' version: " + _currentGenesis.InterfaceInfo.InterfaceVersion);
lblConfigVersion.Text = @"Interface Version: " + _currentGenesis.InterfaceInfo.InterfaceVersion;
lblConfigVersion.ForeColor = _currentGenesis.InterfaceSupportsFwVersion ? Color.Green : Color.Red;
if (!_currentGenesis.InterfaceSupportsFwVersion)
{
var text = "INTERFACE VERSION OUTDATED!\n" +
"The loaded \'configuration.json\' " +
$"version: {_currentGenesis.InterfaceInfo.InterfaceVersion}\n" +
$"does NOT support the Cordonel FW version: {_currentGenesis.FwVersion}!";
MessageBox.Show(text, @"FAILED", MessageBoxButtons.OK, MessageBoxIcon.Error);
LogText(text);
}
else
{
LogText($"\'Configuration.json\' supports installed FW version: {_currentGenesis.FwVersion}");
}
LogText("");
lblConnectPcb.ForeColor = Color.Green;
CheckUpdateEnabled();
LogPcAndCordonelTime();
LogInstalledMeterFw();
}));
}
}).ContinueWith(delegate
{
LowLevelActionControl(false);
_currentGenesis.ReLogin();
if (_currentGenesis.IsLoggedOn)
btnReadLifetime_Click(this, null);
else
{
Invoke(new Action(() =>
{
Init();
}));
}
});
}
catch (Exception ex)
{
LowLevelActionControl(false);
MessageBox.Show(ex.Message, @"FAILED", MessageBoxButtons.OK, MessageBoxIcon.Error);
LogErrorText(ex.Message);
// Dispose meter
_meterBatch.RemoveAllMeters();
// If meter is not already assigned to batch as the config reader may fail
_currentGenesis?.DisposeMeter();
}
}
#endregion BoardControls
#region ProcessControls
private void CheckUpdateEnabled()
{
if (_currentGenesis != null)
{
SetCordonelAccessEnabled();
return;
}
SetCordonelAccessLocked();
}
private void LowLevelActionControl(Boolean isActive)
{
if (isActive)
{
Invoke(new Action(() =>
{
ViewProcessControl(true);
tmrProgressUpdate.Enabled = true;
_progressBarOn = true;
}));
}
else
{
Invoke(new Action(() =>
{
ViewProcessControl(false);
_progressBarOn = false;
CheckUpdateEnabled();
}));
}
}
private void ViewProgressPcb(Boolean isActive)
{
if (_updateGui)
{
if (isActive)
{
Invoke(new Action(() =>
{
_autoProgressBar = true;
ViewProcessControl(true);
}));
}
else
{
Invoke(new Action(() =>
{
_autoProgressBar = false;
ViewProcessControl(false);
}));
}
}
}
/// <summary>
/// View all process bars and labels
/// </summary>
private void ViewProcessControl(Boolean view)
{
if (view)
{
lblActualProcess.Visible = true;
//lblOverall.Visible = true;
//barOverallProgressUpdate.Visible = true;
barSingleProgressUpdate.Visible = true;
//_lastFwUpdateState = "";
tmrProgressUpdate.Enabled = true;
SetControlsLowLevelOpOngoing();
}
else
{
lblActualProcess.Visible = false;
//lblOverall.Visible = false;
//barOverallProgressUpdate.Visible = false;
barSingleProgressUpdate.Visible = false;
tmrProgressUpdate.Enabled = false;
//_lastFwUpdateState = "";
lblWaitingForMeterResponse.Visible = false;
lblActualProcess.Text = "";
//lblOverall.Text = "";
SetControlsLowLevelOpIsFinished();
}
//common actions and settings
lblActualProcess.Update();
//lblOverall.Update();
//barOverallProgressUpdate.Value = 0;
//barOverallProgressUpdate.Update();
barSingleProgressUpdate.Value = 0;
barSingleProgressUpdate.Update();
Update();
}
private void StartStopDownload(Boolean isActive)
{
if (isActive)
{
Invoke(new Action(() =>
{
//_lastFwUpdateState = "";
ViewProcessControl(true);
tmrProgressUpdate.Enabled = true;
}));
}
else
{
Invoke(new Action(() => { ViewProcessControl(false); }));
}
}
#endregion ProcessControls
#region InfoWindow
/// <summary>
/// Clear history window.
/// </summary>
/// <remarks date="2021-Jan-05" author="Thomas Wiedebusch">
/// - Initial
/// </remarks>
private void ClearHistoryWindow()
{
if (_frmHistory != null && _frmHistory.rtbHistory.InvokeRequired)
{
_frmHistory.rtbHistory.Invoke(new Action(() => { _frmHistory.rtbHistory.Clear(); }));
}
else
{
_frmHistory?.rtbHistory.Clear();
}
}
/// <summary>
/// Output exclusively to user update remarks text window.
/// </summary>
/// <remarks date="2021-Apr-26" author="Thomas Wiedebusch">
/// - Color added.
/// </remarks>
/// <remarks date="2023-Aug-15" author="Thomas Wiedebusch">
/// - File output added.
/// </remarks>
private void LogText(String txtHistory, String filename = null)
{
InfoWindowColoredText(txtHistory, ColorDefault);
if (!string.IsNullOrEmpty(filename))
{
File.AppendAllLines(filename, new[] { txtHistory });
}
}
/// <summary>
/// Output exclusively to user update remarks text window.
/// </summary>
private void LogErrorText(String txtHistory)
{
InfoWindowColoredText(txtHistory, ColorProcessFailed);
}
/// <summary>
/// Output exclusively to user update remarks text window.
/// </summary>
private void LogSuccessText(String txtHistory)
{
InfoWindowColoredText(txtHistory, ColorSuccess);
}
/// <summary>
/// Output exclusively to user update remarks text window.
/// </summary>
private void InfoWindowColoredText(String txtHistory, Color color)
{
if (_frmHistory?.rtbHistory == null)
{
return;
}
Invoke(new Action(() =>
{
_frmHistory.rtbHistory.SuspendLayout();
_frmHistory.rtbHistory.SelectionStart = _frmHistory.rtbHistory.Text.Length;
_frmHistory.rtbHistory.SelectionLength = 0;
_frmHistory.rtbHistory.SelectionColor = color;
_frmHistory.rtbHistory.AppendText($"{txtHistory}{Environment.NewLine}");
_frmHistory.rtbHistory.SelectionColor = _frmHistory.rtbHistory.ForeColor;
_frmHistory.rtbHistory.ScrollToCaret();
_frmHistory.rtbHistory.ResumeLayout();
}));
}
#endregion HistoryWindow
#region Tools
/// <summary>
/// Display installed meter FW.
/// </summary>
/// <remarks date="2022-Mar-25" author="Thomas Wiedebusch">
/// - Init.
/// </remarks>
private void LogInstalledMeterFw()
{
if (_currentGenesis == null)
{
return;
}
LogText(StrSeparator);
LogText($"PCB ID :\t{_currentGenesis.PcbId}");
LogText($"Core Version:\t{_currentGenesis.StrCoreRevision}");
LogText("");
LogText("Installed Applications:");
foreach (var app in _currentGenesis.MeterAppListVersion)
{
var versionString =
app.IsInstalled ? $"V: {app.StrVersion} - CRC: 0x{app.Crc:X4}" : "App NOT Installed";
if (app.Status == MeterAppState.Unknown)
versionString = "COMMUNICATION ERROR";
LogText($"AppId: 0x{app.AppId:X2} - {versionString} - " + $"AppName: {app.AppName}");
if (app.IsInstalled)
{
var appVersion = new CordonelAppVersion(app.AppId, app.StrVersion);
// Copy metrology update permission
if (app.AppName == MetrologyDefinition.MetrologyName &&
_currentGenesis.MetrologyUpgradePermission != MetrologyDefinition.MetrologyUpgradePermitted)
{
appVersion.IsUpdateable = false;
}
}
}
LogText(StrSeparator);
}
/// <summary>
/// Set the actual process and log the text.
/// </summary>
/// <remarks date="2023-Jan-04" author="Thomas Wiedebusch">
/// - Color added.
/// </remarks>
private void SetActualProcessAndLog(String message, String logFileName = null)
{
Invoke(new Action(() => { lblActualProcess.Text = message; }));
LogText(message, logFileName);
}
/// <summary>
/// Calculate and log the PC and Cordonel time.
/// </summary>
/// <remarks date="2023-Jan-02" author="Thomas Wiedebusch">
/// - Init.
/// </remarks>
private void LogPcAndCordonelTime()
{
if (_currentGenesis == null)
{
return;
}
_currentGenesis.ReLogin();
var dt = DateTime.UtcNow;
var msg = $"{dt:yyyy-MM-dd HH:mm:ss} UTC";
LogText($"PC date time:\t{msg}");
CalculateMeterDateTime(RegisterConverter.ByteArrayToValue<Int32>(
_currentGenesis.ReadRegister("SYSTEM_CalendarSeconds")));
//add a blank line to separate next operation
LogText("");
_currentGenesis.Logout();
}
/// <summary>
/// Calculate and log Cordonel time.
/// </summary>
/// <remarks date="2023-Jan-06" author="Thomas Wiedebusch">
/// - Init.
/// </remarks>
/// <remarks date="2023-Jul-19" author="Thomas Wiedebusch">
/// - Used <see cref="TimeT"/> to calculate time in UTC based on 01. Jan 2000
/// and the given offset in seconds.
/// </remarks>
private void CalculateMeterDateTime(Int32 secSince2000)
{
var meterDateTime = new TimeT { SecondsSince2000 = secSince2000 };
var msg = meterDateTime.ToString();
Invoke(new Action(() => { tbxDateTime.Text = msg; }));
LogText($"Meter date time:\t{msg}");
}
#endregion
#region Buttons and Controls
private void btnSwitchPressure_Click(Object sender, EventArgs e)
{
if (_currentGenesis != null && _currentGenesis.IsLoggedOn)
{
var pressureReadOut =
RegisterConverter.ByteArrayToValue<Boolean>(_currentGenesis.ReadRegister("METROLOGYASST_PressurePresent"));
_currentGenesis.WriteRegister("METROLOGYASST_PressurePresent", !pressureReadOut, true, true);
_currentGenesis.StoreAllConfigurations();
}
}
private void btnLogout_Click(Object sender, EventArgs e)
{
if (_currentGenesis != null && _currentGenesis.IsLoggedOn)
{
_currentGenesis.Logout();
}
}
private void btnConnect_Click(Object sender, EventArgs e)
{
if (_resetTimeMeasurement)
{
_startTime = DateTimeOffset.UtcNow;
_resetTimeMeasurement = false;
}
Connect();
}
private void btnReadLifetime_Click(Object sender, EventArgs e)
{
LowLevelActionControl(true);
var sbMSG = new StringBuilder();
var genesisStatus = new GenesisStatus();
Task.Factory.StartNew(() =>
{
try
{
_currentGenesis.WriteRegister(Register.Powermon.BatteryQuantity, 2, true, true);
// var requirements = new CordonelRequirements();
// TODO THW Just display lifetime as is in Low Level Tools as Order is not assigned and meter size is unknown (ROLAND)
// TODO THW Dropdown list to select requirement to check if this meter fits to it
sbMSG.Append(GenesisStatusHandler.LifeTimeInformationString(_currentGenesis, genesisStatus));
Invoke(new Action(() =>
{
if (!sbMSG.ToString().Contains(GenesisStatusHandler.ERROR_MARKER))
{
tbxBatteries.Text = $@"{genesisStatus.BatteryQuantity}";
tbxDrainedLoad_uAs.Text = $@"{genesisStatus.DrainedBatteryLoad_uAs:N0}";
tbxExpiredLifeTime.Text = $@"{genesisStatus.ExceededLifeTime_s:N0}";
tbxInitialBatteryLoad.Text = $@"{genesisStatus.InitialBatteryLoad_mAh:N0}";
tbxDrainedBatteryLoad_percent.Text = $@"{genesisStatus.DrainedBatteryLoadPercent:F2}";
tbxRemainingLifeTimeSw.Text = $@"{genesisStatus.RemainingLifeTimeYears:F2}";
tbxRemainingLifeTimeFw.Text = genesisStatus.FwCalculatedRemainingLifeTimeYears != null ?
$@"{genesisStatus.FwCalculatedRemainingLifeTimeYears:F2}" : "not supported";
tbxStorageMonths.Text = $@"{genesisStatus.StorageMonths:F1}";
}
else
{
tbxDrainedBatteryLoad_percent.Text = "";
tbxRemainingLifeTimeSw.Text = "";
tbxRemainingLifeTimeFw.Text = "";
tbxStorageMonths.Text = "";
tbxBatteries.Text = "";
tbxDrainedLoad_uAs.Text = "";
tbxExpiredLifeTime.Text = "";
tbxInitialBatteryLoad.Text = "";
}
}));
/* if (!GenesisStatusHandler.GetCordonelRequirementInfoFromDb($"{_currentGenesis.PcbId}",
requirements, out var errorMsg))
{
if (!string.IsNullOrWhiteSpace(errorMsg))
{
sbMSG.AppendLine(errorMsg);
}
// Try to get a requirement base on size
_currentGenesis.ReLogin();
var size = RegisterConverter.ByteArrayToValue<Int32>(
_currentGenesis.ReadRegister(Register.Genesisflow.MeterSize));
if (!GenesisStatusHandler.GetCordonelRequirementInfoFromDbByMeterSize(size, requirements,
out errorMsg))
{
errorMarker = true;
if (!string.IsNullOrWhiteSpace(errorMsg))
{
sbMSG.AppendLine(errorMsg);
}
}
}
if (!errorMarker)
{
sbMSG.AppendLine($"Standard requirement: {requirements.StandardId}.{requirements.StandardVersion}");
sbMSG.AppendLine($"Special requirement: {requirements.SpecialId}.{requirements.SpecialVersion}");
// Check lifetime for assembly
if (genesisStatus.RemainingLifeTimeYears < requirements.RequiredLifeTimeYearsAssembly)
{
errorMarker = true;
sbMSG.AppendLine($"ERROR: {nameof(requirements.RequiredLifeTimeYearsAssembly)}: " +
$"{genesisStatus.RemainingLifeTimeYears:F2} < " +
$"{requirements.RequiredLifeTimeYearsAssembly:F2}!");
}
else
{
sbMSG.AppendLine("Success: Remaining Lifetime for 'Assembly' is accepted");
}
// Check lifetime for shipping
if (genesisStatus.RemainingLifeTimeYears < requirements.RequiredLifeTimeYearsShipping)
{
errorMarker = true;
sbMSG.AppendLine($"ERROR: {nameof(requirements.RequiredLifeTimeYearsShipping)}: " +
$"{genesisStatus.RemainingLifeTimeYears:F2} < " +
$"{requirements.RequiredLifeTimeYearsShipping:F2}!");
}
else
{
sbMSG.AppendLine("Success: Remaining Lifetime for 'Shipping' is accepted");
}
if (genesisStatus.AlternativeRequiredBatteryLoadPercent != null &&
genesisStatus.AlternativeRequiredBatteryLoadPercent >
requirements.MaxDrainedBatteryLoadPercentAssembly)
{
sbMSG.AppendLine($"ERROR: {nameof(genesisStatus.AlternativeRequiredBatteryLoadPercent)}: " +
$"{genesisStatus.AlternativeRequiredBatteryLoadPercent:F2} > " +
$"{requirements.MaxDrainedBatteryLoadPercentAssembly:F2}!");
}
else
{
sbMSG.AppendLine("Success: Battery power consumption for 'Assembly' is accepted");
}
//TODO THW check from here on
if (genesisStatus.DrainedBatteryLoadPercent >
requirements.MaxDrainedBatteryLoadPercentAssembly)
{
sbMSG.AppendLine($"{nameof(requirements.MaxDrainedBatteryLoadPercentAssembly)}: " +
$"{genesisStatus.DrainedBatteryLoadPercent:F2} > " +
$"{requirements.MaxDrainedBatteryLoadPercentAssembly:F2}");
}
else sbMSG.AppendLine("Maximaler Batterieverbrauch Montage i.O.");
if (genesisStatus.StorageMonths > requirements.MaxStorageMonths)
{
sbMSG.AppendLine($"{nameof(genesisStatus.StorageMonths)}: " +
$"{genesisStatus.StorageMonths} > " +
$"{requirements.MaxStorageMonths}");
}
else sbMSG.AppendLine($"Maximallagerzeit i.O.");
}// valid requirement
else
{
sbMSG.AppendLine("Requirement not assigned.");
}
if (errorMarker)
sbMSG.AppendLine($"Battery lifetime limits sind Übreschritten");
else
sbMSG.AppendLine($"Battery lifetime limits sind OK");
sbMSG.AppendLine(
);
sbMSG.AppendLine(
$"Preproduction max. drained battery load: {genesisStatus.AlternativeRequiredBatteryLoadPercent} %");
sbMSG.AppendLine(
$"Meter reports drained battery load: {genesisStatus.DrainedBatteryLoadPercent} %");
}*/
}
catch (Exception ex)
{
sbMSG.AppendLine(GenesisStatusHandler.ERROR_MARKER + " " + ex.Message);
}
finally
{
if (sbMSG.ToString().Contains(GenesisStatusHandler.ERROR_MARKER))
{
LogErrorText(sbMSG.ToString());
//MessageBox.Show( sbMSG.ToString(), @"ERROR",
// buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error);
}
else
{
LogSuccessText(sbMSG.ToString());
//MessageBox.Show(sbMSG.ToString(), @"Success",
// buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Information);
}
}
}).ContinueWith(delegate { Invoke(new Action(() => { LowLevelActionControl(false); })); });
}
private void btnLedOff_Click(Object sender, EventArgs e)
{
if (!_currentGenesis.IsLoggedOn)
{
_currentGenesis.ReLogin();
}
SetActualProcessAndLog("Set sample rate to 2 Hz");
_currentGenesis.WriteRegister(Register.Genesisflow.SampleRate, 2);
SetActualProcessAndLog("Switch LED OFF");
_currentGenesis.WriteRegister(Register.Genesisflow.LedMode, 0);
SetActualProcessAndLog("Set trigger active");
_currentGenesis.WriteRegister(Register.Genesisflow.TriggerActive, 1);
}
private void cbxUseOfflinePwds_CheckedChanged(Object sender, EventArgs e)
{
cbxUseOfflinePwds.ForeColor = cbxUseOfflinePwds.Checked ? Color.Red : Color.Black;
}
private void btnDisplayDefault_Click(Object sender, EventArgs e)
{
if (_currentGenesis != null && _currentGenesis.IsLoggedOn)
{
_currentGenesis.WriteRegister("GENESISFLOW_SealDisplay", 0);
_currentGenesis.WriteRegister("CUSTOMER_Locale", 0);
_currentGenesis.WriteRegister("GENESISFLOW_DisplayPow10", 253);
_currentGenesis.WriteRegister("GENESISFLOW_DisplayUnits", 0);
_currentGenesis.WriteRegister("METROLOGYASST_FlowUnits", 1);
_currentGenesis.StoreAllConfigurations();
_currentGenesis.WriteRegister("SENSUSRADIO_SYSTEMSTATE", 0xFF);
}
}
#endregion
}
}