MeterFile: - high speed file open

FrmLutUpdate, FrmFwUpdate, FrmLowLevelUpdate: - data base connection to connect task to have the progress bar active
This commit is contained in:
Thomas Wiedebusch
2023-01-03 09:52:40 +01:00
parent 4a9d300f4a
commit b48893ff06
10 changed files with 295 additions and 235 deletions
@@ -62,10 +62,6 @@
/// </summary>
PrepareUpdate,
/// <summary>
/// Read configuration file from meter
/// </summary>
UploadConfigFile,
/// <summary>
/// Delimiter for list
/// </summary>
FwUpdateStateListDelimiter
@@ -61,9 +61,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile.Consts
StateInfos[(Int32)FwUpdateState.PrepareUpdate].State = FwUpdateState.PrepareUpdate;
StateInfos[(Int32)FwUpdateState.PrepareUpdate].Message = Resources.StrFwUpdateStatePrepareUpdate;
StateInfos[(Int32)FwUpdateState.UploadConfigFile].State = FwUpdateState.UploadConfigFile;
StateInfos[(Int32)FwUpdateState.UploadConfigFile].Message = Resources.StrUploadConfigFile;
}
/// <summary>
@@ -108,7 +108,6 @@
<Compile Include="Consts\FwUpdateState.cs" />
<Compile Include="Consts\FwUpdateStateInfo.cs" />
<Compile Include="Consts\FwUpdateStateText.cs" />
<Compile Include="MeterConfigFile.cs" />
<Compile Include="MeterLutFile.cs" />
<Compile Include="MeterFileRestore.cs" />
<Compile Include="MeterFilesEraseRestore.cs" />
@@ -1,22 +0,0 @@
using System;
using System.Collections.Generic;
namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
{
/// <summary>
/// File for meter configuration
/// </summary>
public class MeterConfigFile
{
/// <summary>
/// Data length
/// </summary>
public UInt32 DataLength;
/// <summary>
/// Binary file content
/// </summary>
public List<Byte> BinData = new List<Byte>();
}
}
@@ -38,12 +38,12 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
private const String StrOpenFileReadOnlyMode = "rb";
//Open for both reading and writing in binary mode. If the file does not exist, FOpen returns NULL
private const String StrOpenFileReadWriteMode = "rb+";
/// <summary>
/// FSeek for start of file
/// </summary>
public const Int32 FSeekStartOfFile = 0;
/// <summary>
/// FSeek for end of file
/// </summary>
@@ -281,7 +281,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
_currentGenesis.ReadRegister(Register.Configexchange.FileWrite));
returnedFileOffset = ReadFilePointerOffset();
}
//set timeout back to default value
_currentGenesis.TransmitProtocol.SetDefaultResponseTimeout();
CommunicationConfig.RequestRetries = CommunicationConfig.DefaultRequestRetries;
@@ -341,6 +341,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
/// <remarks date="2023-Jan-02" author="Thomas Wiedebusch">
/// - Read data according to file size searched with FSeek.
/// </remarks>
/// <remarks date="2023-Jan-03" author="Thomas Wiedebusch">
/// - Speed up FOpen as read is not so critical.
/// </remarks>
public Boolean ReadMeterFile(String fileName, out List<Byte> readBackData)
{
//set processing counter
@@ -355,55 +358,58 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
// Get the current file size
var returnValue = GetFileSize(fileName, out var readBackCount);
returnValue &= OpenMeterFile(fileName, StrOpenFileReadOnlyMode);
if (returnValue)
{
//set register write retries to 0 to avoid doubling of records
CommunicationConfig.RequestRetries = 0;
_currentGenesis.TransmitProtocol.SetResponseTimeout(ExtendedFileIoTimeoutMs);
//write size to 1
_currentGenesis.WriteRegister(Register.Configexchange.FileRead, 1, false);
//write counts to expected length
_currentGenesis.WriteRegister(Register.Configexchange.FileRead, readBackCount, false);
//write file pointer
_currentGenesis.WriteRegister(Register.Configexchange.FileRead, _filePointer);
//use high speed access
returnValue &= OpenMeterFile(fileName, StrOpenFileReadOnlyMode, true);
//the preceding routine needs to wait for response, else this is always true!
while (readBackCount > 0 && !_stopProcess)
if (returnValue)
{
var remainingData = RegisterConverter.ConvertTo<Int32>(
_currentGenesis.ReadRegister(Register.Configexchange.FileRead));
//set register write retries to 0 to avoid doubling of records
CommunicationConfig.RequestRetries = 0;
_currentGenesis.TransmitProtocol.SetResponseTimeout(ExtendedFileIoTimeoutMs);
readBackCount = remainingData > 0 ? readBackCount - remainingData : 0;
//write size to 1
_currentGenesis.WriteRegister(Register.Configexchange.FileRead, 1, false);
//write counts to expected length
_currentGenesis.WriteRegister(Register.Configexchange.FileRead, readBackCount, false);
//write file pointer
_currentGenesis.WriteRegister(Register.Configexchange.FileRead, _filePointer);
while (remainingData > 0)
//the preceding routine needs to wait for response, else this is always true!
while (readBackCount > 0 && !_stopProcess)
{
var size = remainingData > MaxRawDataSize ? MaxRawDataSize : remainingData;
readBackData.AddRange(_currentGenesis.ReadRegister(Register.Configexchange.FileRead, size));
remainingData -= size;
var remainingData = RegisterConverter.ConvertTo<Int32>(
_currentGenesis.ReadRegister(Register.Configexchange.FileRead));
//set processed bytes for read loop
ProcessedBytesCtr += size;
readBackCount = remainingData > 0 ? readBackCount - remainingData : 0;
//inform the caller of changed statue
var processCtrPercent = 100.0 * ProcessedBytesCtr / (_overallBytesCtr > 0 ? _overallBytesCtr : 1);
OnProcessUpdate?.Invoke(this, new ProcessExecEventArgs("", processCtrPercent));
while (remainingData > 0)
{
var size = remainingData > MaxRawDataSize ? MaxRawDataSize : remainingData;
readBackData.AddRange(_currentGenesis.ReadRegister(Register.Configexchange.FileRead, size));
remainingData -= size;
//set processed bytes for read loop
ProcessedBytesCtr += size;
//inform the caller of changed statue
var processCtrPercent = 100.0 * ProcessedBytesCtr / (_overallBytesCtr > 0 ? _overallBytesCtr : 1);
OnProcessUpdate?.Invoke(this, new ProcessExecEventArgs("", processCtrPercent));
}
}
}
//set timeout back to default value
_currentGenesis.TransmitProtocol.SetDefaultResponseTimeout();
CommunicationConfig.RequestRetries = CommunicationConfig.DefaultRequestRetries;
//set timeout back to default value
_currentGenesis.TransmitProtocol.SetDefaultResponseTimeout();
CommunicationConfig.RequestRetries = CommunicationConfig.DefaultRequestRetries;
}//file open succeeded
}//file open succeeded
//dummy read to avoid 0x040B feedback from meter
//_currentGenesis.ReadRegister(Register.Configexchange.FileRead, 1);
returnValue &= CloseMeterFile();
returnValue &= CloseMeterFile();
}// file size unequal to 0
//processed bytes not longer needed
ProcessedBytesCtr = 0;
@@ -562,16 +568,16 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
public Boolean GetFileSize(String fileName, out Int32 fileSize)
{
fileSize = 0;
var returnValue = OpenMeterFile(fileName, StrOpenFileReadOnlyMode);
var returnValue = OpenMeterFile(fileName, StrOpenFileReadOnlyMode, true);
if (returnValue)
{
returnValue &= SetFilePointerOffset(fSeekPara: FSeekEndOfFile);
returnValue &= SetFilePointerOffset(fSeekPara: FSeekEndOfFile);
if (returnValue)
{
fileSize = ReadFilePointerOffset();
}
if (returnValue)
{
fileSize = ReadFilePointerOffset();
}
}
returnValue &= CloseMeterFile();
@@ -596,7 +602,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
{
var returnValue = true;
if (!ReadMeterFile(fileName, out var binData)|| binData == null || binData.Count == 0)
if (!ReadMeterFile(fileName, out var binData) || binData == null || binData.Count == 0)
return false;
// compare the entire buffer which also includes the header of the file, remind the original
@@ -609,11 +615,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
returnValue = false;
}
}
//if (dataBytes.Where((t, ctr) => t != binData[ctr]).Any())
//{
// returnValue = false;
//}
return returnValue;
}
@@ -704,7 +705,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
/// <remarks date="2023-Jan-02" author="Thomas Wiedebusch">
/// - Extended FSeek for file end positioning.
/// </remarks>
private Boolean SetFilePointerOffset(Int32 filePointerOffset = 0, Int32 fSeekPara = FSeekStartOfFile)
private Boolean SetFilePointerOffset(Int32 filePointerOffset = 0, Int32 fSeekPara = FSeekStartOfFile)
{
Boolean returnValue;
var retryCtr = 0;
@@ -802,7 +803,8 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
/// Open a file of the meter and sets the file pointer
/// </summary>
/// <param name="fileName"></param>
/// <param name="accessMode"></param>
/// <param name="accessMode">read, write eg,</param>
/// <param name="highSpeed">disable high timeouts</param>
/// <returns>true if filePointer higher than zero</returns>
/// <remarks date="2019-Jun-20" author="Thomas Wiedebusch">
/// - Initial
@@ -815,7 +817,10 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
/// - Retries changed for and back,
/// - Timeout changed for and back.
/// </remarks>
private Boolean OpenMeterFile(String fileName, String accessMode)
/// <remarks date="2023-Jan-03" author="Thomas Wiedebusch">
/// - Extended timings removed if high speed is active.
/// </remarks>
private Boolean OpenMeterFile(String fileName, String accessMode, Boolean highSpeed = false)
{
//check if logged on to meter and access level is as expected
if (_currentGenesis == null || !_currentGenesis.IsLoggedOn)
@@ -834,7 +839,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
}
//set extended timeout for file operations
_currentGenesis.TransmitProtocol.SetResponseTimeout(ExtendedFileIoTimeoutMs);
if (highSpeed)
_currentGenesis.TransmitProtocol.SetResponseTimeout(ExtendedFileIoTimeoutMs);
CommunicationConfig.RequestRetries = 0;
//write file name to meter with meter open command, don't wait for response
@@ -25,9 +25,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
{
#region Variables
// Look up table file
public MeterConfigFile ConfigFile;
/// <summary>
/// Port scan result event for message dispatcher to caller
/// </summary>
@@ -713,59 +710,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
}
}
/// <summary>
/// Upload the config file from meter
/// </summary>
/// <returns></returns>
/// <remarks date="2022-Apr-26" author="Thomas Wiedebusch">
/// - Initial
/// </remarks>
public Boolean UploadConfigFile()
{
//counters for actual process information
var retryCtr = 0;
ConfigFile = new MeterConfigFile();
_processedBytesCtr = 0;
_overallBytesCtr = 6;
_meterFile = new MeterFile(_genesisMeter);
if (_meterFile != null)
{
_meterFile.OnProcessUpdate += ProcessUpdate_Event;
}
_genesisMeter?.ReLogin();
_genesisMeter?.SetProcessState(DisplayCodes.FwUpdateActive, webRequest: false);
if (_genesisMeter == null || !_genesisMeter.IsLoggedOn || _meterFile == null)
return false;
var returnValue = true;
//read config file and retry if not successful
do
{
_actualOperation = Resources.StrUploadConfigFile;
// logout and re-login to clear all ongoing processes and clear the Genesis buffers
ReestablishMeterFileSystem();
if (!_meterFile.ReadMeterFile(StrConfigMeterFileName, out ConfigFile.BinData))
{
returnValue = false;
}
if (!returnValue)
{
ReestablishMeterFileSystem();
}
} while (!returnValue && retryCtr++ < FileWriteRetries && !StopUpdateProcess);
_meterFile.OnProcessUpdate -= ProcessUpdate_Event;
return !StopUpdateProcess && returnValue;
}
/// <summary>
/// Update meter firmware
/// </summary>
@@ -1170,6 +1114,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
/// - Prepare update added,
/// - Upload config file added.
/// </remarks>
/// <remarks date="2023-Jan-02" author="Thomas Wiedebusch">
/// - Upload config file removed.
/// </remarks>
private void FwUpdateStateMachine()
{
if (_fwBackupUpdateState == _fwUpdateState)
@@ -1185,12 +1132,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
case FwUpdateState.Idle:
break;
case FwUpdateState.UploadConfigFile:
_fwUpdateState = UploadConfigFile()
? FwUpdateState.Idle
: FwUpdateState.StepFailed;
break;
case FwUpdateState.StartInitial:
_updateProcedureRetryCtr = 0;
_fwUpdateState = FwUpdateState.BuildFileApps;
-2
View File
@@ -807,7 +807,6 @@ namespace Xylem.Common.Ui.GenesisToolBox
{
Invoke(new Action(() =>
{
_lastFwUpdateState = "";
ProcessViewControl(true);
tmrProgressUpdate.Enabled = true;
}));
@@ -855,7 +854,6 @@ namespace Xylem.Common.Ui.GenesisToolBox
{
Invoke(new Action(() =>
{
_lastFwUpdateState = "";
ProcessViewControl(true);
tmrProgressUpdate.Enabled = true;
}));
+22 -9
View File
@@ -57,6 +57,7 @@
this.lblFwUpdateInfo = new System.Windows.Forms.Label();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.btnGetDateTime = new System.Windows.Forms.Button();
this.btnSetDateTime = new System.Windows.Forms.Button();
this.btnRebootMeter = new System.Windows.Forms.Button();
this.btnStoreConfiguration = new System.Windows.Forms.Button();
@@ -67,7 +68,7 @@
this.label7 = new System.Windows.Forms.Label();
this.saveConfigFile = new System.Windows.Forms.SaveFileDialog();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.btnGetDateTime = new System.Windows.Forms.Button();
this.btnReadLogFiles = new System.Windows.Forms.Button();
this.grpSetup.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.groupBox1.SuspendLayout();
@@ -359,6 +360,16 @@
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Tools";
//
// btnGetDateTime
//
this.btnGetDateTime.Location = new System.Drawing.Point(10, 144);
this.btnGetDateTime.Name = "btnGetDateTime";
this.btnGetDateTime.Size = new System.Drawing.Size(116, 25);
this.btnGetDateTime.TabIndex = 38;
this.btnGetDateTime.Text = "Get Date Time";
this.btnGetDateTime.UseVisualStyleBackColor = true;
this.btnGetDateTime.Click += new System.EventHandler(this.btnGetDateTime_Click);
//
// btnSetDateTime
//
this.btnSetDateTime.Location = new System.Drawing.Point(10, 114);
@@ -443,6 +454,7 @@
//
// groupBox2
//
this.groupBox2.Controls.Add(this.btnReadLogFiles);
this.groupBox2.Controls.Add(this.btnUploadConfig);
this.groupBox2.Location = new System.Drawing.Point(417, 69);
this.groupBox2.Name = "groupBox2";
@@ -451,15 +463,15 @@
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Log";
//
// btnGetDateTime
// btnReadLogFiles
//
this.btnGetDateTime.Location = new System.Drawing.Point(10, 144);
this.btnGetDateTime.Name = "btnGetDateTime";
this.btnGetDateTime.Size = new System.Drawing.Size(116, 25);
this.btnGetDateTime.TabIndex = 38;
this.btnGetDateTime.Text = "Get Date Time";
this.btnGetDateTime.UseVisualStyleBackColor = true;
this.btnGetDateTime.Click += new System.EventHandler(this.btnGetDateTime_Click);
this.btnReadLogFiles.Location = new System.Drawing.Point(10, 54);
this.btnReadLogFiles.Name = "btnReadLogFiles";
this.btnReadLogFiles.Size = new System.Drawing.Size(116, 25);
this.btnReadLogFiles.TabIndex = 38;
this.btnReadLogFiles.Text = "Read Log Files";
this.btnReadLogFiles.UseVisualStyleBackColor = true;
this.btnReadLogFiles.Click += new System.EventHandler(this.btnReadLogFiles_Click);
//
// FrmLowLevelTools
//
@@ -542,5 +554,6 @@
private System.Windows.Forms.TextBox tbxDateTime;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button btnGetDateTime;
private System.Windows.Forms.Button btnReadLogFiles;
}
}
+210 -78
View File
@@ -1,12 +1,16 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Logic.ProductionToProductMapper.Cordonel;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore;
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile;
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers;
@@ -27,7 +31,6 @@ namespace Xylem.Common.Ui.GenesisToolBox
private const String StrConnecting = "Connecting to PCB";
private const String StrNotConnected = "NOT CONNECTED";
private const String StrPartPcbConnected = "PCB ID: ";
private const String StrOverallProcess = "Overall Process";
private const String StrBurnUpgrade = "Waiting for meter response";
private MeterFile _meterFile;
@@ -42,7 +45,6 @@ namespace Xylem.Common.Ui.GenesisToolBox
private MeterResetPsu _meterResetPsu;
private Boolean _meterResetProcessActive;
private Boolean _rebootSucceeded;
private MeterFwUpdate _meterFwUpdate;
private Boolean _tryConnectPcb;
@@ -83,7 +85,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
/// </summary>
private void Init()
{
ProcessViewControl(false);
ViewProcessControl(false);
lblConnectPcb.Text = StrNotConnected;
lblConnectPcb.ForeColor = Color.Red;
lblWaitingForMeterResponse.Visible = false;
@@ -98,7 +100,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
lblFwUpdateInfo.Text = $@"Version: {version.Major}.{version.Minor}.{version.Build}";
_resetTimeMeasurement = true;
Init();
var xPosition = Location.X + Size.Width;
var yPosition = Location.Y;
if (_frmHistory != null)
@@ -132,7 +134,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
Init();
}
#endregion
#region ActivationControls
/// <summary>
/// Disable all buttons except the connect button
@@ -146,6 +148,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
btnRebootMeter.Enabled = false;
btnStoreConfiguration.Enabled = false;
btnUploadConfig.Enabled = false;
btnReadLogFiles.Enabled = false;
}
/// <summary>
@@ -160,6 +163,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
btnRebootMeter.Enabled = true;
btnStoreConfiguration.Enabled = true;
btnUploadConfig.Enabled = true;
btnReadLogFiles.Enabled = true;
}
/// <summary>
@@ -194,7 +198,8 @@ namespace Xylem.Common.Ui.GenesisToolBox
/// </summary>
private void SetControlsLowLevelOpIsFinished()
{
_currentGenesis.RequestProtocol.AdditionalRetryTimeoutMs = 0;
if (_currentGenesis != null)
_currentGenesis.RequestProtocol.AdditionalRetryTimeoutMs = 0;
SetCordonelAccessEnabled();
}
#endregion
@@ -227,6 +232,10 @@ namespace Xylem.Common.Ui.GenesisToolBox
_currentGenesis = null;
Thread.Sleep(200);
Invoke(new Action(() =>
{
lblOverall.Text = @"Login to Cordonel";
}));
//assign new meter and assign meter to FW update file if this exists
_currentGenesis = new GenesisMeter();
@@ -250,8 +259,6 @@ namespace Xylem.Common.Ui.GenesisToolBox
_meterFile = new MeterFile(_currentGenesis);
// _meterFile?.AssignGenesis(_currentGenesis);
Invoke(new Action(() =>
{
lblConnectPcb.Text = StrPartPcbConnected;
@@ -301,7 +308,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
lblActualProcess.Text = StrBurnUpgrade;
lblOverall.Text = @"Update Applications and Restart Meter";
ProcessViewControl(true);
ViewProcessControl(true);
//wait until meter update is completed and meter is re-booted
const Double maxBootDelayMs = 10000.0;
@@ -324,19 +331,18 @@ namespace Xylem.Common.Ui.GenesisToolBox
Thread.Sleep((Int32)loopDelayMs);
}
ProcessViewControl(false);
ViewProcessControl(false);
}
#endregion
#region ProcessControls
private void UploadFileControl(Boolean isActive)
private void owLevelActionControl(Boolean isActive)
{
if (isActive)
{
Invoke(new Action(() =>
{
_lastFwUpdateState = "";
ProcessViewControl(true);
ViewProcessControl(true);
tmrProgressUpdate.Enabled = true;
_progressBarOn = true;
}));
@@ -345,8 +351,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
{
Invoke(new Action(() =>
{
ProcessViewControl(false);
SetControlsLowLevelOpIsFinished();
ViewProcessControl(false);
_progressBarOn = false;
}));
}
@@ -358,8 +363,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
{
Invoke(new Action(() =>
{
_lastFwUpdateState = "";
ProcessViewControl(true);
ViewProcessControl(true);
tmrProgressUpdate.Enabled = true;
}));
}
@@ -367,8 +371,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
{
Invoke(new Action(() =>
{
ProcessViewControl(false);
SetControlsLowLevelOpIsFinished();
ViewProcessControl(false);
if (_rebootSucceeded)
{
@@ -394,9 +397,8 @@ namespace Xylem.Common.Ui.GenesisToolBox
Invoke(new Action(() =>
{
_tryConnectPcb = true;
ProcessViewControl(true);
ViewProcessControl(true);
lblActualProcess.Text = StrConnecting;
lblOverall.Text = StrOverallProcess;
}));
}
else
@@ -404,7 +406,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
Invoke(new Action(() =>
{
_tryConnectPcb = false;
ProcessViewControl(false);
ViewProcessControl(false);
}));
}
}
@@ -413,7 +415,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
/// <summary>
/// View all process bars and labels
/// </summary>
private void ProcessViewControl(Boolean view)
private void ViewProcessControl(Boolean view)
{
if (view)
{
@@ -423,6 +425,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
barSingleProgressUpdate.Visible = true;
_lastFwUpdateState = "";
tmrProgressUpdate.Enabled = true;
SetControlsLowLevelOpOngoing();
}
else
{
@@ -435,6 +438,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
lblWaitingForMeterResponse.Visible = false;
lblActualProcess.Text = "";
lblOverall.Text = "";
SetControlsLowLevelOpIsFinished();
}
//common actions and settings
@@ -454,7 +458,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
Invoke(new Action(() =>
{
_lastFwUpdateState = "";
ProcessViewControl(true);
ViewProcessControl(true);
tmrProgressUpdate.Enabled = true;
}));
}
@@ -462,8 +466,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
{
Invoke(new Action(() =>
{
ProcessViewControl(false);
SetControlsLowLevelOpIsFinished();
ViewProcessControl(false);
}));
}
}
@@ -523,7 +526,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
var secSince2000 = RegisterConverter.ConvertTo<Int32>(_currentGenesis.ReadRegister("SYSTEM_CalendarSeconds"));
var ts = TimeSpan.FromSeconds(secSince2000);
var meterDateTime = new DateTime(2000, 1, 1, 0, 0, 0).Add(ts);
msg = $@"{meterDateTime:yyyy-MM-dd hh:mm:ss}";
msg = $@"{meterDateTime:yyyy-MM-dd hh:mm:ss}";
tbxDateTime.Text = msg;
LogText($@"Meter date time [UTC]: {msg}");
@@ -635,7 +638,6 @@ namespace Xylem.Common.Ui.GenesisToolBox
barOverallProgressUpdate.Value + 1;
barSingleProgressUpdate.Value = barSingleProgressUpdate.Value + 4 > 100 ? 0 :
barSingleProgressUpdate.Value + 4;
lblOverall.Text = StrOverallProcess;
}
else if (_meterResetProcessActive)
{
@@ -650,33 +652,6 @@ namespace Xylem.Common.Ui.GenesisToolBox
_lastSingleProgress = singleProgress;
barSingleProgressUpdate.Update();
}
else
{
//lblOverall.Text = _meterFile?.GetStateOperation();
//lblActualProcess.Text = _meterFile?.GetActualOperation();
//var overallProgress = (Int32)(_meterFile?.OverallProcessCtrPercent ?? 0);
//if (overallProgress < 0)
// overallProgress = 0;
//barOverallProgressUpdate.Value = overallProgress > 100 ? 100 : overallProgress;
//barOverallProgressUpdate.Update();
//var singleProgress = (Int32)(_meterFile?.SingleFileProcessCtrPercent ?? 0);
//if (_meterFile?.GetActualOperation() != _lastFwUpdateState)
//{
// _lastFwUpdateState = _meterFile?.GetActualOperation();
// lblWaitingForMeterResponse.Visible = false;
//}
//else
//{
// //if the communication gets frozen
// lblWaitingForMeterResponse.Visible = _lastSingleProgress == singleProgress;
//}
//barSingleProgressUpdate.Value = singleProgress > 100 ? 100 : singleProgress;
//_lastSingleProgress = singleProgress;
//barSingleProgressUpdate.Update();
}
SetTimeDisplay();
Update();
}
@@ -761,11 +736,11 @@ namespace Xylem.Common.Ui.GenesisToolBox
LogText(msg);
lblActualProcess.Text = msg;
UploadFileControl(true);
owLevelActionControl(true);
_currentGenesis.ReLogin();
_currentGenesis.SetLcdText(true, new Byte[] { 0x00, 0x00, 0x00, 0x00 });
// store configuration will logout
btnStoreConfiguration_Click(this, null);
}
@@ -786,10 +761,10 @@ namespace Xylem.Common.Ui.GenesisToolBox
var msg = @"Fix battery settings";
LogText(msg);
lblOverall.Text = msg;
UploadFileControl(true);
owLevelActionControl(true);
_currentGenesis.ReLogin();
msg = @"Seal display for time of setup";
LogText(msg);
lblActualProcess.Text = msg;
@@ -803,9 +778,8 @@ namespace Xylem.Common.Ui.GenesisToolBox
msg = @"Set project end time to meter";
LogText(msg);
lblActualProcess.Text = msg;
_currentGenesis.WriteRegister("POWERMON_WarnFromClamp", (UInt32)630720000); //TODO THW ask Roland!!!
_currentGenesis.WriteRegister("POWERMON_WarnFromClamp", (UInt32)630720000); // 20 years in seconds
msg = @"Set meter battery quantity to 2";
LogText(msg);
lblActualProcess.Text = msg;
@@ -817,7 +791,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
_currentGenesis.WriteRegister("GENESISFLOW_TriggerIdle", (UInt32)0);
_currentGenesis.Logout();
UploadFileControl(false);
owLevelActionControl(false);
// reboot the meter to take the new settings
btnRebootMeter_Click(this, null);
@@ -840,13 +814,13 @@ namespace Xylem.Common.Ui.GenesisToolBox
LogText(msg);
lblActualProcess.Text = msg;
UploadFileControl(true);
owLevelActionControl(true);
_currentGenesis.ReLogin();
_currentGenesis.StoreAllConfigurations();
_currentGenesis.Logout();
UploadFileControl(false);
owLevelActionControl(false);
}
#endregion
@@ -869,7 +843,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
// reset the time
_startTime = DateTimeOffset.UtcNow;
var msg = @"Reboot meter with pseudo FW update";
var msg = @"Reboot meter with pseudo FW update";
LogText(msg);
lblOverall.Text = msg;
@@ -902,7 +876,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
/// <summary>
/// Read config file from meter and store it to disk.
/// </summary>
/// <remarks date="2021-Jan-05" author="Thomas Wiedebusch">
/// <remarks date="2023-Jan-02" author="Thomas Wiedebusch">
/// - Initial
/// </remarks>
private void btnUploadConfig_Click(Object sender, EventArgs e)
@@ -910,20 +884,23 @@ namespace Xylem.Common.Ui.GenesisToolBox
if (_currentGenesis == null)
return;
if (_meterFwUpdate == null)
_meterFwUpdate = new MeterFwUpdate(_currentGenesis);
if (_meterFile == null)
_meterFile = new MeterFile(_currentGenesis);
owLevelActionControl(true);
var msg = @"Upload configuration file from meter";
LogText(msg);
lblOverall.Text = msg;
lblActualProcess.Text = @"Read config file";
UploadFileControl(true);
var rawData = new List<Byte>();
Task.Factory.StartNew(() =>
{
_currentGenesis.ReLogin();
_meterFwUpdate.UploadConfigFile();
_meterFile.ReadMeterFile("0\\config", out var data);
rawData.AddRange(data);
Thread.Sleep(1000);
}).ContinueWith(delegate
{
@@ -933,14 +910,14 @@ namespace Xylem.Common.Ui.GenesisToolBox
{
var fs = new FileStream(saveConfigFile.FileName, FileMode.OpenOrCreate);
var bw = new BinaryWriter(fs);
foreach (var t in _meterFwUpdate.ConfigFile.BinData)
foreach (var t in rawData)
bw.Write(t);
fs.Close();
}
}));
_currentGenesis.Logout();
UploadFileControl(false);
owLevelActionControl(false);
});
}
@@ -965,14 +942,14 @@ namespace Xylem.Common.Ui.GenesisToolBox
LogText(msg);
lblActualProcess.Text = msg;
UploadFileControl(true);
owLevelActionControl(true);
_currentGenesis.ReLogin();
var ts = DateTimeOffset.UtcNow - new DateTimeOffset(2000, 1, 1, 0, 0, 0, new TimeSpan(0));
_currentGenesis.WriteRegister("SYSTEM_CalendarSeconds", Convert.ToInt32(ts.TotalSeconds));
LogPcAndCordonelTime();
// store configuration will logout
btnStoreConfiguration_Click(this, null);
}
@@ -989,6 +966,161 @@ namespace Xylem.Common.Ui.GenesisToolBox
{
LogPcAndCordonelTime();
}
/// <summary>
/// Read engineering log file from meter.
/// </summary>
/// <remarks date="2023-Jan-02" author="Roland Drabesch/Thomas Wiedebusch">
/// - Initial
/// </remarks>
private void btnReadLogFiles_Click(Object sender, EventArgs e)
{
if (_currentGenesis == null)
return;
if (_meterFile == null)
_meterFile = new MeterFile(_currentGenesis);
var statusMap = new Dictionary<Int32, String>();
if (System.IO.File.Exists("Status.json"))
{
var dict = JsonConvert.DeserializeObject<Dictionary<String, JObject>>(System.IO.File.ReadAllText("Status.json"));
foreach (var item in dict)
{
statusMap.Add(int.Parse(item.Value.First.Values().First().ToString()), item.Key);
}
//var jo = JObject.Parse();
//((JObject)jo).ChildrenTokens
//var retListRealCsd = JsonConvert.DeserializeObject(<List<CsdParameterResult>>(retStr);
}
owLevelActionControl(true);
var msg = @"Upload engineering log file from meter";
LogText(msg);
lblOverall.Text = msg;
Task.Factory.StartNew(() =>
{
_currentGenesis.ReLogin();
msg = @"Flushing the logger";
LogText(msg);
Invoke(new Action(() =>
{
lblActualProcess.Text = msg;
}));
_currentGenesis.WriteRegister("LOGGER_TriggerLogFlush", 1);
msg = @"Reading log index file";
LogText(msg);
Invoke(new Action(() =>
{
lblActualProcess.Text = msg;
}));
_meterFile.ReadMeterFile("1\\logindex", out var data);
var fileNames = new List<String>();
var rawData = data.ToArray();
var sample = new Byte[4];
for (var ctr = 0; ctr < data.Count; ctr += 4)
{
for (var x = 0; x < 4; x++)
{
sample[x] = rawData[ctr + x];
}
var name = RegisterConverter.ConvertTo<Int32>(sample).ToString("X8");
LogText(name);
fileNames.Add(name);
}
foreach (var fileName in fileNames)
{
msg = $"1\\{fileName}";
Invoke(new Action(() =>
{
lblActualProcess.Text = "Reading " + msg;
}));
_meterFile.ReadMeterFile(msg, out data);
LogText(msg);
LogText($"Data: {ByteArrayStyle.ByteStyler.ToString(data.ToArray())}");
if (data.Count >= 4)
{
var logType = data[0];
var status = BitConverter.ToUInt16(data.GetRange(1, 2).ToArray(), 0);
var count = (Int32)BitConverter.ToUInt16(data.GetRange(2, 2).ToArray(), 0);
count += 1;
var extraDataSize = data.GetRange(3, 1).ToString();
switch (logType)
{
case 0:
msg = $"({logType}) Informational";
break;
case 1:
msg = $"({logType}) Warning";
break;
case 2:
msg = $"({logType}) Critical";
break;
}
LogText($"Log type:{msg}");
if (statusMap.ContainsKey(status))
{
LogText($"Status: ({status}) {statusMap[status]}");
}
else
{
LogText($"Status:{status}");
}
LogText($"Count:{count}");
LogText($"Extra data size:{extraDataSize}");
if (int.TryParse(extraDataSize, out var extraDataLength))
{
LogText("Extra data: ");
for (var i = 0; i <= extraDataLength; i++)
{
LogText(data.GetRange(i, 2).First().ToString("X2"));
LogText(" ");
}
LogText(" ");
}
}
else
{
LogText("File is empty");
}
}
Thread.Sleep(1000);
}).ContinueWith(delegate
{
//Invoke(new Action(() =>
//{
// if (saveConfigFile.ShowDialog() == DialogResult.OK)
// {
// var fs = new FileStream(saveConfigFile.FileName, FileMode.OpenOrCreate);
// var bw = new BinaryWriter(fs);
// foreach (var t in rawData)
// bw.Write(t);
// fs.Close();
// }
//}));
_currentGenesis.Logout();
owLevelActionControl(false);
});
}
}
}
-1
View File
@@ -333,7 +333,6 @@ namespace Xylem.Common.Ui.GenesisToolBox
{
Invoke(new Action(() =>
{
_lastFwUpdateState = "";
ProcessViewControl(true);
tmrProgressUpdate.Enabled = true;
}));