From 4e223549eedd22db817e10ede808bd42442ca902 Mon Sep 17 00:00:00 2001 From: Marek Frniak Date: Fri, 12 Jun 2026 10:43:34 +0200 Subject: [PATCH] Develop - GciBridge -> GCI -> PreadjustmentUI functions 7 - successful processes - testbench is exported to UnionTown - without CalibParams DB writer --- .../API/InterfaceGCIToLaatzen.cs | 110 +++++---- .../API/InterfaceOutsideToGCI.cs | 69 +++++- .../Config/gci_config.json | 36 +++ .../Core/Config/gci_config.json | 4 +- .../Core/DataStorage/Config/GciConfig.cs | 32 +++ .../DataStorage/Config/GciConfigLoader.cs | 177 ++++++++++++++ .../IPreAdjustmentCalibrationParamsReader.cs | 5 +- .../PreAdjustmentCalibrationParamsReader.cs | 111 ++++++--- .../GenesisCordonelInterface.csproj | 4 +- .../UI/Debug/MeterBatchConfigPanel.cs | 29 +-- .../bin/Debug/Config/gci_config.json | 36 +++ .../BridgeComponents/GciBridge/GciBridge.cs | 215 ++++++++++++++++-- .../GciBridge/GciBridgeCfgCtrl.Designer.cs | 116 +++++----- .../GciBridge/Interfaces/PublicModels.cs | 2 +- .../GciBridge/UI/MainView.Designer.cs | 6 +- .../BridgeComponents/GciBridge/UI/MainView.cs | 2 +- .../PreadjustmentActionsView.cs | 170 +++++++------- 17 files changed, 857 insertions(+), 267 deletions(-) create mode 100644 GenesisCordonelInterface/Config/gci_config.json create mode 100644 GenesisCordonelInterface/Core/DataStorage/Config/GciConfig.cs create mode 100644 GenesisCordonelInterface/Core/DataStorage/Config/GciConfigLoader.cs create mode 100644 GenesisCordonelInterface/bin/Debug/Config/gci_config.json diff --git a/GenesisCordonelInterface/API/InterfaceGCIToLaatzen.cs b/GenesisCordonelInterface/API/InterfaceGCIToLaatzen.cs index 5d0b8649a..b4bca85a0 100644 --- a/GenesisCordonelInterface/API/InterfaceGCIToLaatzen.cs +++ b/GenesisCordonelInterface/API/InterfaceGCIToLaatzen.cs @@ -42,7 +42,6 @@ namespace GenesisCordonelInterface.API private readonly MeterBatch _meterBatch = new MeterBatch(); //Preadjustment - public PreAdjustmentSettingsContainer _settings = new PreAdjustmentSettingsContainer(); public ProcessProgress _progressProcess = new ProcessProgress(); public List _meterControls = new List(); public List _tempMeterControls = new List(); @@ -55,6 +54,11 @@ namespace GenesisCordonelInterface.API private readonly ConcurrentDictionary _selectedSlots = new ConcurrentDictionary(); + public InterfaceGCIToLaatzen() + { + + } + #endregion #region ================================== Worker ================================== @@ -1592,22 +1596,30 @@ namespace GenesisCordonelInterface.API IEnumerable selectedSlots, CancellationToken token = default) { - return Task.Run(() => Preadjustment_DetectCore(selectedSlots, token), token); + return Task.Run(() => Preadjustment_Detect(selectedSlots, token), token); + } + public PreadjustmentDetectResult PreAdjustment_DetectDirect( + IEnumerable selectedSlots, + CancellationToken token = default) + { + return Preadjustment_Detect(selectedSlots, token); } - private PreadjustmentDetectResult Preadjustment_DetectCore( + private PreadjustmentDetectResult Preadjustment_Detect( IEnumerable selectedSlots, - CancellationToken token) + CancellationToken token = default) { - const string operation = nameof(Preadjustment_DetectCore); + const string operation = nameof(Preadjustment_Detect); try { + LogInfo(operation, "Start."); + MeterBatch globalMeterBatch = new MeterBatch(); MeterBatch thermoMeterBatch = new MeterBatch(); - if (_settings == null) - throw new ArgumentNullException(nameof(_settings)); + if (_progressProcess.Setting == null) + throw new ArgumentNullException(nameof(_progressProcess.Setting)); if (_meterControls == null) throw new ArgumentNullException(nameof(_meterControls)); @@ -1624,7 +1636,7 @@ namespace GenesisCordonelInterface.API globalMeterBatch = _meterBatch; _meterControls = CreateMeterControls(selectedSlots); - if (!_settings.GetTempUseTempFlansh()) + if (!_progressProcess.Setting.GetTempUseTempFlansh()) _tempMeterControls.Clear(); var allMeterControls = new List(); @@ -1654,7 +1666,7 @@ namespace GenesisCordonelInterface.API SetUnknownStatus(allMeterControls); CheckTemperatureMeters( - _settings, + _progressProcess.Setting, _tempMeterControls, token); @@ -1817,11 +1829,16 @@ namespace GenesisCordonelInterface.API token); } + public PreAdjustmentProcessResult PreAdjustment_PreparationDirect() + { + return PreAdjustment_Preparation(); + } + /// /// Executes standalone preparation process. /// public PreAdjustmentProcessResult PreAdjustment_Preparation( - int slot) + int slot = -1) { const string operation = nameof(PreAdjustment_Preparation); @@ -1829,9 +1846,6 @@ namespace GenesisCordonelInterface.API { LogInfo(operation, $"Start. Slot={slot}"); - var meter = GetMeterThreadSafe(slot); - EnsureConnected(meter); - BaseProcess process = CreatePreparationProcess(_progressProcess); bool success = @@ -1890,6 +1904,17 @@ namespace GenesisCordonelInterface.API PreAdjustmentControl.PredefinedMessages.PreparationFailed(pp.Setting.Culture), 60); } + public bool PreAdjustment_PushCalibrationParams(double temperature) + { + if (_progressProcess != null) + { + _progressProcess.PushedTestBenchTemp = temperature; + _progressProcess.TempretureSelected = true; + return true; + } + + return false; + } #endregion @@ -1903,8 +1928,13 @@ namespace GenesisCordonelInterface.API token); } + public PreAdjustmentProcessResult PreAdjustment_AmplitudeTestDirect() + { + return PreAdjustment_AmplitudeTest(); + } + public PreAdjustmentProcessResult PreAdjustment_AmplitudeTest( - int slot) + int slot = -1) { const string operation = nameof(PreAdjustment_AmplitudeTest); @@ -1912,9 +1942,6 @@ namespace GenesisCordonelInterface.API { LogInfo(operation, $"Start. Slot={slot}"); - var meter = GetMeterThreadSafe(slot); - EnsureConnected(meter); - if (_progressProcess.Setting.TempOnly) { return new PreAdjustmentProcessResult @@ -1991,19 +2018,19 @@ namespace GenesisCordonelInterface.API token); } + public PreAdjustmentProcessResult PreAdjustment_TemperatureCalibrationDirect() + { + return PreAdjustment_TemperatureCalibration(); + } + public PreAdjustmentProcessResult PreAdjustment_TemperatureCalibration( - int slot) + int slot = -1) { const string operation = nameof(PreAdjustment_TemperatureCalibration); try { - LogInfo(operation, $"Start. Slot={slot}"); - - var meter = - GetMeterThreadSafe(slot); - - EnsureConnected(meter); + LogInfo(operation, $"Start."); BaseProcess process = CreateTemperatureCalibrationProcess(_progressProcess); @@ -2040,10 +2067,14 @@ namespace GenesisCordonelInterface.API public bool PreAdjustment_PushTemperature(double temperature) { - _progressProcess.PushedTestBenchTemp = temperature; - _progressProcess.TempretureSelected = true; + if (_progressProcess != null) + { + _progressProcess.PushedTestBenchTemp = temperature; + _progressProcess.TempretureSelected = true; + return true; + } - return true; + return false; } /// @@ -2084,8 +2115,13 @@ namespace GenesisCordonelInterface.API token); } + public PreAdjustmentProcessResult PreAdjustment_OffsetTestDirect() + { + return PreAdjustment_OffsetTest(); + } + public PreAdjustmentProcessResult PreAdjustment_OffsetTest( - int slot) + int slot = -1) { const string operation = nameof(PreAdjustment_OffsetTest); @@ -2093,10 +2129,6 @@ namespace GenesisCordonelInterface.API { LogInfo(operation, $"Start. Slot={slot}"); - var meter = GetMeterThreadSafe(slot); - - EnsureConnected(meter); - if (_progressProcess.Setting.TempOnly) { return new PreAdjustmentProcessResult @@ -2178,19 +2210,19 @@ namespace GenesisCordonelInterface.API token); } + public PreAdjustmentProcessResult PreAdjustment_CompletionDirect() + { + return PreAdjustment_Completion(); + } + public PreAdjustmentProcessResult PreAdjustment_Completion( - int slot) + int slot = -1) { const string operation = nameof(PreAdjustment_Completion); try { - LogInfo(operation, $"Start. Slot={slot}"); - - var meter = - GetMeterThreadSafe(slot); - - EnsureConnected(meter); + LogInfo(operation, $"Start."); BaseProcess process = CreateCompletionProcess(_progressProcess); diff --git a/GenesisCordonelInterface/API/InterfaceOutsideToGCI.cs b/GenesisCordonelInterface/API/InterfaceOutsideToGCI.cs index a0695c71e..e6c0726c1 100644 --- a/GenesisCordonelInterface/API/InterfaceOutsideToGCI.cs +++ b/GenesisCordonelInterface/API/InterfaceOutsideToGCI.cs @@ -10,6 +10,7 @@ using System.IO.Ports; using System.Threading; using System.Threading.Tasks; using Xylem.Common.Hardware.WaterMeter.WaterMeterCore; +using Xylem.Common.Logic.ProductionOrderCore.OrderData; using Xylem.Common.Ui.CordonelPreadjustmentUi; using static GenesisCordonelInterface.API.PublicModels; @@ -39,9 +40,7 @@ namespace GenesisCordonelInterface.API /// Occurs when meter batch status information changes. /// public event Action> MeterBatchStatusChanged; - private readonly IMeterLoginPasswordReader loginPasswordsReader; - private readonly IPreAdjustmentCalibrationParamsReader calibrationParamsReader; /// @@ -61,10 +60,35 @@ namespace GenesisCordonelInterface.API IPreAdjustmentCalibrationParamsReader calibrationReader) { _innerMeterAPI = innerMeterApi?? throw new ArgumentNullException(nameof(innerMeterApi)); - loginPasswordsReader = passwordReader ?? throw new ArgumentNullException(nameof(passwordReader)); - calibrationParamsReader = calibrationReader ?? throw new ArgumentNullException(nameof(calibrationReader)); + + //init handlers + //_innerMeterAPI._progressProcess.OnRequestedCalibrationParamsFromDb += RequestedCalibrationParamsFromDb; + } + + private async void RequestedCalibrationParamsFromDb( + object sender, + EventArgsProcessProgress e) + { + try + { + DataQuery query = new DataQuery(); + query.QueryParams.Add(((int)e.Value.Setting.MeterSize).ToString()); + + Dictionary calibrationParams = await ReadPreAdjustmentCalibrationParamsAsync(query).ConfigureAwait(false); + + e.Value.PushedCalibrationParams = calibrationParams; + } + catch (Exception ex) + { + e.Value.DebugMessage( + $"Calibration params reading failed: {ex.Message}"); + } + finally + { + e.Value.CalibrationParamsReadEvent.Set(); + } } // Laatzen ToolBox actions @@ -613,6 +637,9 @@ namespace GenesisCordonelInterface.API ProcessProgress pp, List mc) { + //init handlers + pp.OnRequestedCalibrationParamsFromDb += RequestedCalibrationParamsFromDb; + return _innerMeterAPI?.Preadjustment_Initialization(pp, mc); } @@ -623,6 +650,13 @@ namespace GenesisCordonelInterface.API return _innerMeterAPI.PreAdjustment_DetectAsync(selectedSlots, token); } + public PreadjustmentDetectResult PreAdjustment_DetectDirect( + IEnumerable selectedSlots, + CancellationToken token = default) + { + return _innerMeterAPI.PreAdjustment_DetectDirect(selectedSlots, token); + } + public Task PreAdjustment_PreparationAsync( int slot, CancellationToken token = default) @@ -630,6 +664,11 @@ namespace GenesisCordonelInterface.API return _innerMeterAPI.PreAdjustment_PreparationAsync(slot, token); } + public PreAdjustmentProcessResult PreAdjustment_PreparationDirect() + { + return _innerMeterAPI.PreAdjustment_PreparationDirect(); + } + public Task PreAdjustment_AmplitudeTestAsync( int slot, CancellationToken token = default) @@ -637,6 +676,11 @@ namespace GenesisCordonelInterface.API return _innerMeterAPI.PreAdjustment_AmplitudeTestAsync(slot, token); } + public PreAdjustmentProcessResult PreAdjustment_AmplitudeTestDirect() + { + return _innerMeterAPI.PreAdjustment_AmplitudeTestDirect(); + } + public Task PreAdjustment_TemperatureCalibrationAsync( int slot, CancellationToken token = default) @@ -644,6 +688,11 @@ namespace GenesisCordonelInterface.API return _innerMeterAPI.PreAdjustment_TemperatureCalibrationAsync(slot, token); } + public PreAdjustmentProcessResult PreAdjustment_TemperatureCalibrationDirect() + { + return _innerMeterAPI.PreAdjustment_TemperatureCalibrationDirect(); + } + public bool PreAdjustment_PushTemperature( double temperature) { @@ -657,6 +706,11 @@ namespace GenesisCordonelInterface.API return _innerMeterAPI.PreAdjustment_OffsetTestAsync(slot, token); } + public PreAdjustmentProcessResult PreAdjustment_OffsetTestDirect() + { + return _innerMeterAPI.PreAdjustment_OffsetTestDirect(); + } + public Task PreAdjustment_CompletionAsync( int slot, CancellationToken token = default) @@ -664,6 +718,11 @@ namespace GenesisCordonelInterface.API return _innerMeterAPI.PreAdjustment_CompletionAsync(slot, token); } + public PreAdjustmentProcessResult PreAdjustment_CompletionDirect() + { + return _innerMeterAPI.PreAdjustment_CompletionDirect(); + } + #endregion #region ================================== UNI DATA STORAGE READER ================================== @@ -712,7 +771,7 @@ namespace GenesisCordonelInterface.API /// Value: /// Calibration parameter value /// - public Task> ReadPreAdjustmentCalibrationParamsAsync( + public Task> ReadPreAdjustmentCalibrationParamsAsync( DataQuery query, CancellationToken token = default) { diff --git a/GenesisCordonelInterface/Config/gci_config.json b/GenesisCordonelInterface/Config/gci_config.json new file mode 100644 index 000000000..f4c43ac1f --- /dev/null +++ b/GenesisCordonelInterface/Config/gci_config.json @@ -0,0 +1,36 @@ +{ + "_Comment": "GCI DataStorage configuration", + + "DataStorage": { + + "MeterLoginPasswords": { + + "___Documentation___": { + "Description": "Reads login passwords for meters by PCB ID", + "Type": "Supported: LocalDatabase, RemoteDatabase, LocalCsv, LocalJson, RestApi", + "DataSource": "Database connection string", + "QueryTemplate": "QUERYPARAM is placeholder for runtime value. Example: WHERE [PcbId]=QUERYPARAM -> PCB ID provided during GetPasswordAsync()." + }, + + "Name": "MeterLoginPasswords", + "Type": "LocalDatabase", + "DataSource": "Server=(localdb)\\MojaDB;Database=UnionTownCalibAndSkeleton;Integrated Security=True;", + "QueryTemplate": "SELECT [Password] FROM [dbo].[SkeletonKeys] WHERE [PcbId] = QUERYPARAM" + }, + + "PreAdjustmentCalibrationParams": { + + "___Documentation___": { + "Description": "Reads pre-adjustment calibration parameters by meter size", + "Type": "Supported: LocalDatabase, RemoteDatabase, LocalCsv, LocalJson, RestApi", + "DataSource": "Database connection string", + "QueryTemplate": "QUERYPARAM is placeholder for runtime value. Example: WHERE [MeterSize]=QUERYPARAM -> meter size provided during ReadCalibrationParamsAsync()." + }, + + "Name": "PreAdjustmentCalibrationParams", + "Type": "LocalDatabase", + "DataSource": "Server=(localdb)\\MojaDB;Database=UnionTownCalibAndSkeleton;Integrated Security=True;", + "QueryTemplate": "SELECT [ParameterName], [ParameterValue] FROM [dbo].[PreAdjustmentCalibrationParams] WHERE [MeterSize] = QUERYPARAM" + } + } +} diff --git a/GenesisCordonelInterface/Core/Config/gci_config.json b/GenesisCordonelInterface/Core/Config/gci_config.json index febe63041..0a25a6d34 100644 --- a/GenesisCordonelInterface/Core/Config/gci_config.json +++ b/GenesisCordonelInterface/Core/Config/gci_config.json @@ -14,7 +14,7 @@ "Name": "MeterLoginPasswords", "Type": "LocalDatabase", - "DataSource": "Server=(localdb)\\MojaDB;Database=UnionTownCalibAndSkeleton;Integrated Security=True;", + "DataSource": "Server=(localdb)\\SensusLocalDB;Database=UnionTownCalibAndSkeleton;Integrated Security=True;", "QueryTemplate": "SELECT [Password] FROM [dbo].[SkeletonKeys] WHERE [PcbId] = QUERYPARAM" }, @@ -29,7 +29,7 @@ "Name": "PreAdjustmentCalibrationParams", "Type": "LocalDatabase", - "DataSource": "Server=(localdb)\\MojaDB;Database=UnionTownCalibAndSkeleton;Integrated Security=True;", + "DataSource": "Server=(localdb)\\SensusLocalDB;Database=UnionTownCalibAndSkeleton;Integrated Security=True;", "QueryTemplate": "SELECT [ParameterName], [ParameterValue] FROM [dbo].[PreAdjustmentCalibrationParams] WHERE [MeterSize] = QUERYPARAM" } } diff --git a/GenesisCordonelInterface/Core/DataStorage/Config/GciConfig.cs b/GenesisCordonelInterface/Core/DataStorage/Config/GciConfig.cs new file mode 100644 index 000000000..c4cf686c0 --- /dev/null +++ b/GenesisCordonelInterface/Core/DataStorage/Config/GciConfig.cs @@ -0,0 +1,32 @@ +namespace GenesisCordonelInterface.Core.DataStorage.Config +{ + /// + /// Root GCI configuration object loaded from gci_config.json. + /// + /// This class represents the top-level configuration structure + /// and serves as an entry point for all configurable GCI features. + /// + /// Example: + /// + /// { + /// "DataStorage": + /// { + /// ... + /// } + /// } + /// + public class GciConfig + { + /// + /// Data storage configuration section. + /// + /// Contains definitions for all configured readers and writers, + /// such as: + /// + /// - MeterLoginPasswords + /// - PreAdjustmentCalibrationParams + /// - future storage providers + /// + public GciDataStorageConfig DataStorage { get; set; } + } +} \ No newline at end of file diff --git a/GenesisCordonelInterface/Core/DataStorage/Config/GciConfigLoader.cs b/GenesisCordonelInterface/Core/DataStorage/Config/GciConfigLoader.cs new file mode 100644 index 000000000..b88db0d3b --- /dev/null +++ b/GenesisCordonelInterface/Core/DataStorage/Config/GciConfigLoader.cs @@ -0,0 +1,177 @@ +using System; +using System.IO; +using GenesisCordonelInterface.Core.DataStorage.Reading.Common; +using GenesisCordonelInterface.Core.DataStorage.Reading.Common.Models; +using Newtonsoft.Json; + +namespace GenesisCordonelInterface.Core.DataStorage.Config +{ + /// + /// Loads GCI configuration from gci_config.json. + /// + /// Responsibilities: + /// - Locate configuration file + /// - Deserialize JSON into strongly typed objects + /// - Normalize relative file paths + /// - Preserve database connection strings and REST URLs + /// + /// Example: + /// + /// Config/ + /// gci_config.json + /// + /// Data/ + /// meter_passwords.csv + /// + /// Relative paths: + /// Data\file.csv + /// + /// become: + /// + /// C:\App\bin\Debug\Data\file.csv + /// + /// Database sources remain unchanged: + /// + /// Server=(localdb)\MojaDB;Database=... + /// + public static class GciConfigLoader + { + /// + /// Loads default GCI configuration from: + /// + /// Config\gci_config.json + /// + /// + /// Loaded GCI configuration. + /// + public static GciConfig LoadDefault() + { + string baseDirectory = AppDomain.CurrentDomain.BaseDirectory; + + string configPath = Path.Combine( + baseDirectory, + "Config", + "gci_config.json"); + + return Load(configPath, baseDirectory); + } + + /// + /// Loads GCI configuration from specified file. + /// + /// + /// Path to configuration json file. + /// + /// + /// Base directory used for resolving relative paths. + /// + /// + /// Loaded configuration object. + /// + public static GciConfig Load( + string configPath, + string baseDirectory = null) + { + if (string.IsNullOrWhiteSpace(configPath)) + throw new ArgumentException( + "Config path must not be empty.", + nameof(configPath)); + + if (!File.Exists(configPath)) + throw new FileNotFoundException( + "GCI config file was not found.", + configPath); + + string json = File.ReadAllText(configPath); + + GciConfig config = + JsonConvert.DeserializeObject(json); + + if (config == null) + throw new InvalidOperationException( + "GCI config could not be loaded."); + + NormalizeDataStoragePaths( + config, + baseDirectory ?? Path.GetDirectoryName(configPath)); + + return config; + } + + /// + /// Normalizes paths for all configured data storage entries. + /// + /// Converts relative file paths into absolute paths. + /// Database connection strings remain untouched. + /// + /// + /// Loaded configuration object. + /// + /// + /// Base path used for relative resolution. + /// + private static void NormalizeDataStoragePaths( + GciConfig config, + string baseDirectory) + { + if (config.DataStorage == null) + return; + + NormalizePath( + config.DataStorage.MeterLoginPasswords, + baseDirectory); + + NormalizePath( + config.DataStorage.PreAdjustmentCalibrationParams, + baseDirectory); + } + + /// + /// Converts relative file paths into absolute paths. + /// + /// Applies only to: + /// - LocalCsv + /// - RemoteCsv + /// - LocalJson + /// - RemoteJson + /// + /// Does not modify: + /// - Database connection strings + /// - REST URLs + /// + /// + /// Storage configuration. + /// + /// + /// Base path for resolution. + /// + private static void NormalizePath( + DataStorageConfig storageConfig, + string baseDirectory) + { + if (storageConfig == null) + return; + + if (string.IsNullOrWhiteSpace(storageConfig.DataSource)) + return; + + // Database connection strings and URLs + // must never be treated as file paths. + if (storageConfig.Type == DataStorageType.LocalDatabase || + storageConfig.Type == DataStorageType.RemoteDatabase || + storageConfig.Type == DataStorageType.RestApi) + { + return; + } + + if (Path.IsPathRooted(storageConfig.DataSource)) + return; + + storageConfig.DataSource = + Path.GetFullPath( + Path.Combine( + baseDirectory, + storageConfig.DataSource)); + } + } +} \ No newline at end of file diff --git a/GenesisCordonelInterface/Core/DataStorage/Reading/Implementation/PreAdjustmentCalibrationParams/IPreAdjustmentCalibrationParamsReader.cs b/GenesisCordonelInterface/Core/DataStorage/Reading/Implementation/PreAdjustmentCalibrationParams/IPreAdjustmentCalibrationParamsReader.cs index 822aa4d8c..239d51d82 100644 --- a/GenesisCordonelInterface/Core/DataStorage/Reading/Implementation/PreAdjustmentCalibrationParams/IPreAdjustmentCalibrationParamsReader.cs +++ b/GenesisCordonelInterface/Core/DataStorage/Reading/Implementation/PreAdjustmentCalibrationParams/IPreAdjustmentCalibrationParamsReader.cs @@ -1,4 +1,5 @@ using GenesisCordonelInterface.Core.DataStorage.Reading.Common.Models; +using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -37,7 +38,7 @@ namespace GenesisCordonelInterface.Core.DataStorage.Reading.Implementation.PreAd /// Dictionary where key is GENESISFLOW parameter name /// and value is stored parameter value. /// - Dictionary GetCalibrationParams( + Dictionary GetCalibrationParams( DataQuery query); /// @@ -54,7 +55,7 @@ namespace GenesisCordonelInterface.Core.DataStorage.Reading.Implementation.PreAd /// Dictionary where key is GENESISFLOW parameter name /// and value is stored parameter value. /// - Task> ReadCalibrationParamsAsync( + Task> ReadCalibrationParamsAsync( DataQuery query, CancellationToken token = default); } diff --git a/GenesisCordonelInterface/Core/DataStorage/Reading/Implementation/PreAdjustmentCalibrationParams/PreAdjustmentCalibrationParamsReader.cs b/GenesisCordonelInterface/Core/DataStorage/Reading/Implementation/PreAdjustmentCalibrationParams/PreAdjustmentCalibrationParamsReader.cs index 29ba742d2..ad79e7490 100644 --- a/GenesisCordonelInterface/Core/DataStorage/Reading/Implementation/PreAdjustmentCalibrationParams/PreAdjustmentCalibrationParamsReader.cs +++ b/GenesisCordonelInterface/Core/DataStorage/Reading/Implementation/PreAdjustmentCalibrationParams/PreAdjustmentCalibrationParamsReader.cs @@ -88,13 +88,17 @@ namespace GenesisCordonelInterface.Core.DataStorage.Reading.Implementation.PreAd /// Value: /// Stored parameter value /// - public async Task> ReadCalibrationParamsAsync( + public async Task> ReadCalibrationParamsAsync( DataQuery query, CancellationToken token = default) { ValidateQuery(query); - await readLock.WaitAsync(token); + return await Task.Run( + () => GetCalibrationParams(query), + token).ConfigureAwait(false); ; + + /*await readLock.WaitAsync(token); try { @@ -105,7 +109,7 @@ namespace GenesisCordonelInterface.Core.DataStorage.Reading.Implementation.PreAd finally { readLock.Release(); - } + }*/ } /// @@ -127,7 +131,7 @@ namespace GenesisCordonelInterface.Core.DataStorage.Reading.Implementation.PreAd /// Value: /// Stored parameter value /// - public Dictionary GetCalibrationParams( + public Dictionary GetCalibrationParams( DataQuery query) { ValidateQuery(query); @@ -172,11 +176,11 @@ namespace GenesisCordonelInterface.Core.DataStorage.Reading.Implementation.PreAd /// Dictionary containing calibration parameter /// name/value pairs. /// - private Dictionary ConvertResultToDictionary( - object result) + private Dictionary ConvertResultToDictionary( + object result) { - Dictionary values = - new Dictionary(); + Dictionary values = + new Dictionary(); if (result == null) return values; @@ -188,19 +192,11 @@ namespace GenesisCordonelInterface.Core.DataStorage.Reading.Implementation.PreAd foreach (Dictionary row in dbResult.Rows) { - if (!row.TryGetValue( - "ParameterName", - out object parameterNameObject)) - { + if (!row.TryGetValue("ParameterName", out object parameterNameObject)) continue; - } - if (!row.TryGetValue( - "ParameterValue", - out object parameterValueObject)) - { + if (!row.TryGetValue("ParameterValue", out object parameterValueObject)) continue; - } string parameterName = parameterNameObject?.ToString(); @@ -208,8 +204,11 @@ namespace GenesisCordonelInterface.Core.DataStorage.Reading.Implementation.PreAd if (string.IsNullOrWhiteSpace(parameterName)) continue; - values[parameterName] = - parameterValueObject?.ToString(); + if (TryConvertToUInt32(parameterValueObject, out UInt32 parameterValue)) + { + values[parameterName] = + parameterValue; + } } return values; @@ -217,34 +216,90 @@ namespace GenesisCordonelInterface.Core.DataStorage.Reading.Implementation.PreAd if (result is ReaderDiagnosticResult diagnosticResult) { - if (diagnosticResult.Data is Dictionary dictionary) - return dictionary; + if (diagnosticResult.Data is Dictionary uintDictionary) + return uintDictionary; + + if (diagnosticResult.Data is Dictionary stringDictionary) + { + foreach (var item in stringDictionary) + { + if (TryConvertToUInt32(item.Value, out UInt32 value)) + values[item.Key] = value; + } + + return values; + } if (diagnosticResult.Data is Dictionary objectDictionary) { foreach (var item in objectDictionary) { - values[item.Key] = - item.Value?.ToString(); + if (TryConvertToUInt32(item.Value, out UInt32 value)) + values[item.Key] = value; } return values; } } - if (result is Dictionary directDictionary) - return directDictionary; + if (result is Dictionary directUIntDictionary) + return directUIntDictionary; + + if (result is Dictionary directStringDictionary) + { + foreach (var item in directStringDictionary) + { + if (TryConvertToUInt32(item.Value, out UInt32 value)) + values[item.Key] = value; + } + + return values; + } if (result is Dictionary directObjectDictionary) { foreach (var item in directObjectDictionary) { - values[item.Key] = - item.Value?.ToString(); + if (TryConvertToUInt32(item.Value, out UInt32 value)) + values[item.Key] = value; } } return values; } + + private static bool TryConvertToUInt32( + object value, + out UInt32 result) + { + result = 0; + + if (value == null) + return false; + + if (value is UInt32 uintValue) + { + result = uintValue; + return true; + } + + if (value is int intValue && intValue >= 0) + { + result = Convert.ToUInt32(intValue); + return true; + } + + if (value is long longValue && + longValue >= 0 && + longValue <= UInt32.MaxValue) + { + result = Convert.ToUInt32(longValue); + return true; + } + + return UInt32.TryParse( + value.ToString(), + out result); + } } } \ No newline at end of file diff --git a/GenesisCordonelInterface/GenesisCordonelInterface.csproj b/GenesisCordonelInterface/GenesisCordonelInterface.csproj index 9a5c3ecaa..bee1f7ab5 100644 --- a/GenesisCordonelInterface/GenesisCordonelInterface.csproj +++ b/GenesisCordonelInterface/GenesisCordonelInterface.csproj @@ -201,9 +201,10 @@ FrmGCIAPI.cs - Config\gci_config.json + Config\gci_config.json PreserveNewest + @@ -241,6 +242,7 @@ + diff --git a/GenesisCordonelInterface/UI/Debug/MeterBatchConfigPanel.cs b/GenesisCordonelInterface/UI/Debug/MeterBatchConfigPanel.cs index a2b52d06e..b647bc9b6 100644 --- a/GenesisCordonelInterface/UI/Debug/MeterBatchConfigPanel.cs +++ b/GenesisCordonelInterface/UI/Debug/MeterBatchConfigPanel.cs @@ -122,22 +122,23 @@ namespace GenesisCordonelInterface.UI.Debug { isRefreshing = true; - foreach (var meter in data) - { - EnsurePortValueExists(meter.RequestPort); - EnsurePortValueExists(meter.StreamingPort); + if(data != null) + foreach (var meter in data) + { + EnsurePortValueExists(meter.RequestPort); + EnsurePortValueExists(meter.StreamingPort); - var row = FindOrCreateRow(meter.Slot); + var row = FindOrCreateRow(meter.Slot); - Set(row, "Slot", meter.Slot); - Set(row, "Selected", meter.Selected); - Set(row, "PcbId", meter.PcbId); - Set(row, "IsLoggedOn", meter.IsLoggedOn); - Set(row, "RequestPort", meter.RequestPort); - Set(row, "StreamingPort", meter.StreamingPort); - Set(row, "FwVersion", meter.FwVersion); - Set(row, "InterfaceVersion", meter.InterfaceVersion); - } + Set(row, "Slot", meter.Slot); + Set(row, "Selected", meter.Selected); + Set(row, "PcbId", meter.PcbId); + Set(row, "IsLoggedOn", meter.IsLoggedOn); + Set(row, "RequestPort", meter.RequestPort); + Set(row, "StreamingPort", meter.StreamingPort); + Set(row, "FwVersion", meter.FwVersion); + Set(row, "InterfaceVersion", meter.InterfaceVersion); + } isRefreshing = false; } diff --git a/GenesisCordonelInterface/bin/Debug/Config/gci_config.json b/GenesisCordonelInterface/bin/Debug/Config/gci_config.json new file mode 100644 index 000000000..0a25a6d34 --- /dev/null +++ b/GenesisCordonelInterface/bin/Debug/Config/gci_config.json @@ -0,0 +1,36 @@ +{ + "_Comment": "GCI DataStorage configuration", + + "DataStorageSection": { + + "MeterLoginPasswords": { + + "___Documentation___": { + "Description": "Reads login passwords for meters by PCB ID", + "Type": "Supported: LocalDatabase, RemoteDatabase, LocalCsv, LocalJson, RestApi", + "DataSource": "Database connection string", + "QueryTemplate": "QUERYPARAM is placeholder for runtime value. Example: WHERE [PcbId]=QUERYPARAM -> PCB ID provided during GetPasswordAsync()." + }, + + "Name": "MeterLoginPasswords", + "Type": "LocalDatabase", + "DataSource": "Server=(localdb)\\SensusLocalDB;Database=UnionTownCalibAndSkeleton;Integrated Security=True;", + "QueryTemplate": "SELECT [Password] FROM [dbo].[SkeletonKeys] WHERE [PcbId] = QUERYPARAM" + }, + + "PreAdjustmentCalibrationParams": { + + "___Documentation___": { + "Description": "Reads pre-adjustment calibration parameters by meter size", + "Type": "Supported: LocalDatabase, RemoteDatabase, LocalCsv, LocalJson, RestApi", + "DataSource": "Database connection string", + "QueryTemplate": "QUERYPARAM is placeholder for runtime value. Example: WHERE [MeterSize]=QUERYPARAM -> meter size provided during ReadCalibrationParamsAsync()." + }, + + "Name": "PreAdjustmentCalibrationParams", + "Type": "LocalDatabase", + "DataSource": "Server=(localdb)\\SensusLocalDB;Database=UnionTownCalibAndSkeleton;Integrated Security=True;", + "QueryTemplate": "SELECT [ParameterName], [ParameterValue] FROM [dbo].[PreAdjustmentCalibrationParams] WHERE [MeterSize] = QUERYPARAM" + } + } +} diff --git a/TBF/Rig/BridgeComponents/GciBridge/GciBridge.cs b/TBF/Rig/BridgeComponents/GciBridge/GciBridge.cs index 25b2ab1fe..2dbbeb851 100644 --- a/TBF/Rig/BridgeComponents/GciBridge/GciBridge.cs +++ b/TBF/Rig/BridgeComponents/GciBridge/GciBridge.cs @@ -52,12 +52,11 @@ namespace TBF.Rig.BridgeComponents.GciBridge readonly GciBridgeCfg gciBridgeCfg; - //readonly UdsReaderType_LoginPasswords loginPasswordsDataStorageReader; - //readonly UdsReaderType_CalibrationParams calibrationParamsStorageReader; + readonly Reader reader; readonly UdsWriterType writer; //GCI main init - GciEngine _gciEngine; + public GciEngine _gciEngine; //diag GUI for GCI GciGUIType gciGUI; @@ -94,9 +93,9 @@ namespace TBF.Rig.BridgeComponents.GciBridge gciBridgeCfg = cfg as GciBridgeCfg; if (gciBridgeCfg == null) throw new Exception("Invalid GciBridgeCfg."); - /*if (!string.IsNullOrEmpty(gciBridgeCfg.ReaderName)) + if (!string.IsNullOrEmpty(gciBridgeCfg.ReaderName)) { - reader = TbfComponents.FindComponent(gciBridgeCfg.ReaderName, components) as UdsReaderType_LoginPasswords; + reader = TbfComponents.FindComponent(gciBridgeCfg.ReaderName, components) as Reader; if (reader == null) throw new Exception("Cannot find reader component '" + gciBridgeCfg.ReaderName + "'"); } @@ -104,7 +103,7 @@ namespace TBF.Rig.BridgeComponents.GciBridge { writer = TbfComponents.FindComponent(gciBridgeCfg.WriterName, components) as UdsWriterType; if (writer == null) throw new Exception("Cannot find writer component '" + gciBridgeCfg.WriterName + "'"); - }*/ + } _gciEngine = new GciEngine(); @@ -144,17 +143,6 @@ namespace TBF.Rig.BridgeComponents.GciBridge gciBridgeGuiForm.Height = 600; gciBridgeGuiForm.StartPosition = FormStartPosition.CenterScreen; - /*gciBridgeGUI = new MainView(this, gciBridgeGuiForm); - gciBridgeGUI.Dock = DockStyle.Fill; - - gciBridgeGuiForm.Controls.Add(gciBridgeGUI); - - gciBridgeGuiForm.FormClosed += (s, e) => - { - gciBridgeGUI = null; - gciBridgeGuiForm = null; - };*/ - log.InfoFormat("{0}: GciBridge GUI view initialized.", Name); } catch (Exception ex) @@ -1342,7 +1330,7 @@ namespace TBF.Rig.BridgeComponents.GciBridge object data = await _gciEngine.gciExternalInterface.ReadPreAdjustmentCalibrationParamsAsync(query, token); - Dictionary calibrationParams = + Dictionary calibrationParams = ExtractPreAdjustmentCalibrationParams(data); return new UdsPreAdjustmentCalibrationParamsResult @@ -1385,24 +1373,28 @@ namespace TBF.Rig.BridgeComponents.GciBridge return query; } - private Dictionary ExtractPreAdjustmentCalibrationParams( + private Dictionary ExtractPreAdjustmentCalibrationParams( object data) { - Dictionary result = - new Dictionary(); + Dictionary result = + new Dictionary(); if (data == null) return result; - if (data is Dictionary directDictionary) + if (data is Dictionary directDictionary) return directDictionary; if (data is Dictionary objectDictionary) { foreach (var item in objectDictionary) { - result[item.Key] = - item.Value?.ToString(); + if (UInt32.TryParse( + item.Value?.ToString(), + out UInt32 value)) + { + result[item.Key] = value; + } } return result; @@ -1648,6 +1640,36 @@ namespace TBF.Rig.BridgeComponents.GciBridge } } + public PreadjustmentDetectResult PreAdjustment_DetectDirect( + IEnumerable selectedSlots, + CancellationToken token = default) + { + const string operation = nameof(PreAdjustment_DetectDirect); + + try + { + EnsureExternalInterface(); + + log.InfoFormat("{0}: {1} Start.", Name, operation); + + PreadjustmentDetectResult result = _gciEngine.gciExternalInterface.PreAdjustment_DetectDirect(selectedSlots, token); + + log.InfoFormat("{0}: {1} Finish. {2}", Name, operation, result); + + return result; + } + catch (Exception ex) + { + log.Error($"{Name}: {operation} failed.", ex); + + return new PreadjustmentDetectResult + { + Success = false, + ErrorMessage = ex.Message + }; + } + } + #endregion #region ================================== PreAdjustment PREPARATION bridge ================================== @@ -1699,6 +1721,35 @@ namespace TBF.Rig.BridgeComponents.GciBridge } } + public PreAdjustmentProcessResult PreAdjustment_PreparationDirect() + { + const string operation = nameof(PreAdjustment_PreparationDirect); + + try + { + EnsureExternalInterface(); + + log.InfoFormat("{0}: {1} Start.", Name, operation); + + PreAdjustmentProcessResult result = _gciEngine.gciExternalInterface.PreAdjustment_PreparationDirect(); + + log.InfoFormat("{0}: {1} Finish. {2}", Name, operation, result); + + return result; + } + catch (Exception ex) + { + log.Error($"{Name}: {operation} failed.", ex); + + return new PreAdjustmentProcessResult + { + Success = false, + ProcessName = "Preparation", + ErrorMessage = ex.Message + }; + } + } + #endregion #region ================================== PreAdjustment AMPLITUDE TEST bridge ================================== @@ -1750,6 +1801,35 @@ namespace TBF.Rig.BridgeComponents.GciBridge } } + public PreAdjustmentProcessResult PreAdjustment_AmplitudeTestDirect() + { + const string operation = nameof(PreAdjustment_AmplitudeTestDirect); + + try + { + EnsureExternalInterface(); + + log.InfoFormat("{0}: {1} Start.", Name, operation); + + PreAdjustmentProcessResult result = _gciEngine.gciExternalInterface.PreAdjustment_AmplitudeTestDirect(); + + log.InfoFormat("{0}: {1} Finish. {2}", Name, operation, result); + + return result; + } + catch (Exception ex) + { + log.Error($"{Name}: {operation} failed.", ex); + + return new PreAdjustmentProcessResult + { + Success = false, + ProcessName = "AmplitudeTest", + ErrorMessage = ex.Message + }; + } + } + #endregion #region ================================== PreAdjustment TEMPERATURE CALIBRATION bridge ================================== @@ -1828,6 +1908,35 @@ namespace TBF.Rig.BridgeComponents.GciBridge } } + public PreAdjustmentProcessResult PreAdjustment_TemperatureCalibrationDirect() + { + const string operation = nameof(PreAdjustment_TemperatureCalibrationDirect); + + try + { + EnsureExternalInterface(); + + log.InfoFormat("{0}: {1} Start.", Name, operation); + + PreAdjustmentProcessResult result = _gciEngine.gciExternalInterface.PreAdjustment_TemperatureCalibrationDirect(); + + log.InfoFormat("{0}: {1} Finish. {2}", Name, operation, result); + + return result; + } + catch (Exception ex) + { + log.Error($"{Name}: {operation} failed.", ex); + + return new PreAdjustmentProcessResult + { + Success = false, + ProcessName = "TemperatureCalibration", + ErrorMessage = ex.Message + }; + } + } + #endregion #region ================================== PreAdjustment OFFSET TEST bridge ================================== @@ -1879,6 +1988,35 @@ namespace TBF.Rig.BridgeComponents.GciBridge } } + public PreAdjustmentProcessResult PreAdjustment_OffsetTestDirect() + { + const string operation = nameof(PreAdjustment_OffsetTestDirect); + + try + { + EnsureExternalInterface(); + + log.InfoFormat("{0}: {1} Start.", Name, operation); + + PreAdjustmentProcessResult result = _gciEngine.gciExternalInterface.PreAdjustment_OffsetTestDirect(); + + log.InfoFormat("{0}: {1} Finish. {2}", Name, operation, result); + + return result; + } + catch (Exception ex) + { + log.Error($"{Name}: {operation} failed.", ex); + + return new PreAdjustmentProcessResult + { + Success = false, + ProcessName = "OffsetTest", + ErrorMessage = ex.Message + }; + } + } + #endregion #region ================================== PreAdjustment COMPLETION bridge ================================== @@ -1930,6 +2068,35 @@ namespace TBF.Rig.BridgeComponents.GciBridge } } + public PreAdjustmentProcessResult PreAdjustment_CompletionDirect() + { + const string operation = nameof(PreAdjustment_CompletionDirect); + + try + { + EnsureExternalInterface(); + + log.InfoFormat("{0}: {1} Start.", Name, operation); + + PreAdjustmentProcessResult result = _gciEngine.gciExternalInterface.PreAdjustment_CompletionDirect(); + + log.InfoFormat("{0}: {1} Finish. {2}", Name, operation, result); + + return result; + } + catch (Exception ex) + { + log.Error($"{Name}: {operation} failed.", ex); + + return new PreAdjustmentProcessResult + { + Success = false, + ProcessName = "Completion", + ErrorMessage = ex.Message + }; + } + } + #endregion #region ======================================= Helpers ======================================= diff --git a/TBF/Rig/BridgeComponents/GciBridge/GciBridgeCfgCtrl.Designer.cs b/TBF/Rig/BridgeComponents/GciBridge/GciBridgeCfgCtrl.Designer.cs index 57ba790d1..d6781e0ae 100644 --- a/TBF/Rig/BridgeComponents/GciBridge/GciBridgeCfgCtrl.Designer.cs +++ b/TBF/Rig/BridgeComponents/GciBridge/GciBridgeCfgCtrl.Designer.cs @@ -31,18 +31,18 @@ this.classNameLabel = new System.Windows.Forms.Label(); this.nameLabel = new System.Windows.Forms.Label(); this.nameTextBox = new System.Windows.Forms.TextBox(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.showGciBridgeGUIButton = new System.Windows.Forms.Button(); + this.showGciGuiButton = new System.Windows.Forms.Button(); this.readerNameLabel = new System.Windows.Forms.Label(); this.readerNameComboBox = new System.Windows.Forms.ComboBox(); this.writerNameLabel = new System.Windows.Forms.Label(); this.writerNameComboBox = new System.Windows.Forms.ComboBox(); + this.externalTypeNameTextBox = new System.Windows.Forms.TextBox(); + this.externalTypeNameLabel = new System.Windows.Forms.Label(); this.enableGuiCheckBox = new System.Windows.Forms.CheckBox(); this.enableExternalCheckBox = new System.Windows.Forms.CheckBox(); this.showGuiOnInitializeCheckBox = new System.Windows.Forms.CheckBox(); - this.externalTypeNameLabel = new System.Windows.Forms.Label(); - this.externalTypeNameTextBox = new System.Windows.Forms.TextBox(); - this.groupBox1 = new System.Windows.Forms.GroupBox(); - this.showGciBridgeGUIButton = new System.Windows.Forms.Button(); - this.showGciGuiButton = new System.Windows.Forms.Button(); this.groupBox1.SuspendLayout(); this.SuspendLayout(); // @@ -72,6 +72,37 @@ this.nameTextBox.Size = new System.Drawing.Size(290, 20); this.nameTextBox.TabIndex = 2; // + // groupBox1 + // + this.groupBox1.Controls.Add(this.showGciBridgeGUIButton); + this.groupBox1.Controls.Add(this.showGciGuiButton); + this.groupBox1.Location = new System.Drawing.Point(31, 241); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(573, 60); + this.groupBox1.TabIndex = 12; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Diagnostic GUI"; + // + // showGciBridgeGUIButton + // + this.showGciBridgeGUIButton.Location = new System.Drawing.Point(311, 19); + this.showGciBridgeGUIButton.Name = "showGciBridgeGUIButton"; + this.showGciBridgeGUIButton.Size = new System.Drawing.Size(134, 28); + this.showGciBridgeGUIButton.TabIndex = 2; + this.showGciBridgeGUIButton.Text = "Show GciBridge GUI"; + this.showGciBridgeGUIButton.UseVisualStyleBackColor = true; + this.showGciBridgeGUIButton.Click += new System.EventHandler(this.showGciBridgeGUIButton_Click); + // + // showGciGuiButton + // + this.showGciGuiButton.Location = new System.Drawing.Point(451, 19); + this.showGciGuiButton.Name = "showGciGuiButton"; + this.showGciGuiButton.Size = new System.Drawing.Size(107, 28); + this.showGciGuiButton.TabIndex = 1; + this.showGciGuiButton.Text = "Show GCI GUI"; + this.showGciGuiButton.UseVisualStyleBackColor = true; + this.showGciGuiButton.Click += new System.EventHandler(this.showGuiButton_Click); + // // readerNameLabel // this.readerNameLabel.AutoSize = true; @@ -108,6 +139,23 @@ this.writerNameComboBox.Size = new System.Drawing.Size(465, 21); this.writerNameComboBox.TabIndex = 6; // + // externalTypeNameTextBox + // + this.externalTypeNameTextBox.Enabled = false; + this.externalTypeNameTextBox.Location = new System.Drawing.Point(139, 202); + this.externalTypeNameTextBox.Name = "externalTypeNameTextBox"; + this.externalTypeNameTextBox.Size = new System.Drawing.Size(290, 20); + this.externalTypeNameTextBox.TabIndex = 11; + // + // externalTypeNameLabel + // + this.externalTypeNameLabel.AutoSize = true; + this.externalTypeNameLabel.Location = new System.Drawing.Point(28, 205); + this.externalTypeNameLabel.Name = "externalTypeNameLabel"; + this.externalTypeNameLabel.Size = new System.Drawing.Size(105, 13); + this.externalTypeNameLabel.TabIndex = 10; + this.externalTypeNameLabel.Text = "External type / name"; + // // enableGuiCheckBox // this.enableGuiCheckBox.AutoSize = true; @@ -141,54 +189,6 @@ this.showGuiOnInitializeCheckBox.Text = "Show GUI on initialize"; this.showGuiOnInitializeCheckBox.UseVisualStyleBackColor = true; // - // externalTypeNameLabel - // - this.externalTypeNameLabel.AutoSize = true; - this.externalTypeNameLabel.Location = new System.Drawing.Point(28, 205); - this.externalTypeNameLabel.Name = "externalTypeNameLabel"; - this.externalTypeNameLabel.Size = new System.Drawing.Size(105, 13); - this.externalTypeNameLabel.TabIndex = 10; - this.externalTypeNameLabel.Text = "External type / name"; - // - // externalTypeNameTextBox - // - this.externalTypeNameTextBox.Enabled = false; - this.externalTypeNameTextBox.Location = new System.Drawing.Point(139, 202); - this.externalTypeNameTextBox.Name = "externalTypeNameTextBox"; - this.externalTypeNameTextBox.Size = new System.Drawing.Size(290, 20); - this.externalTypeNameTextBox.TabIndex = 11; - // - // groupBox1 - // - this.groupBox1.Controls.Add(this.showGciBridgeGUIButton); - this.groupBox1.Controls.Add(this.showGciGuiButton); - this.groupBox1.Location = new System.Drawing.Point(31, 241); - this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(573, 60); - this.groupBox1.TabIndex = 12; - this.groupBox1.TabStop = false; - this.groupBox1.Text = "Diagnostic GUI"; - // - // showGciBridgeGUIButton - // - this.showGciBridgeGUIButton.Location = new System.Drawing.Point(311, 19); - this.showGciBridgeGUIButton.Name = "showGciBridgeGUIButton"; - this.showGciBridgeGUIButton.Size = new System.Drawing.Size(134, 28); - this.showGciBridgeGUIButton.TabIndex = 2; - this.showGciBridgeGUIButton.Text = "Show GciBridge GUI"; - this.showGciBridgeGUIButton.UseVisualStyleBackColor = true; - this.showGciBridgeGUIButton.Click += new System.EventHandler(this.showGciBridgeGUIButton_Click); - // - // showGciGuiButton - // - this.showGciGuiButton.Location = new System.Drawing.Point(451, 19); - this.showGciGuiButton.Name = "showGciGuiButton"; - this.showGciGuiButton.Size = new System.Drawing.Size(107, 28); - this.showGciGuiButton.TabIndex = 1; - this.showGciGuiButton.Text = "Show GCI GUI"; - this.showGciGuiButton.UseVisualStyleBackColor = true; - this.showGciGuiButton.Click += new System.EventHandler(this.showGuiButton_Click); - // // GciBridgeCfgCtrl // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -220,17 +220,17 @@ private System.Windows.Forms.Label classNameLabel; private System.Windows.Forms.Label nameLabel; private System.Windows.Forms.TextBox nameTextBox; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.Button showGciGuiButton; + private System.Windows.Forms.Button showGciBridgeGUIButton; private System.Windows.Forms.Label readerNameLabel; private System.Windows.Forms.ComboBox readerNameComboBox; private System.Windows.Forms.Label writerNameLabel; private System.Windows.Forms.ComboBox writerNameComboBox; + private System.Windows.Forms.TextBox externalTypeNameTextBox; + private System.Windows.Forms.Label externalTypeNameLabel; private System.Windows.Forms.CheckBox enableGuiCheckBox; private System.Windows.Forms.CheckBox enableExternalCheckBox; private System.Windows.Forms.CheckBox showGuiOnInitializeCheckBox; - private System.Windows.Forms.Label externalTypeNameLabel; - private System.Windows.Forms.TextBox externalTypeNameTextBox; - private System.Windows.Forms.GroupBox groupBox1; - private System.Windows.Forms.Button showGciGuiButton; - private System.Windows.Forms.Button showGciBridgeGUIButton; } } \ No newline at end of file diff --git a/TBF/Rig/BridgeComponents/GciBridge/Interfaces/PublicModels.cs b/TBF/Rig/BridgeComponents/GciBridge/Interfaces/PublicModels.cs index 797ad39e7..f3cf2a6dd 100644 --- a/TBF/Rig/BridgeComponents/GciBridge/Interfaces/PublicModels.cs +++ b/TBF/Rig/BridgeComponents/GciBridge/Interfaces/PublicModels.cs @@ -111,7 +111,7 @@ namespace TBF.Rig.BridgeComponents.GciBridge.Interfaces { public bool Success { get; set; } public int MeterSize { get; set; } - public Dictionary CalibrationParams { get; set; } + public Dictionary CalibrationParams { get; set; } public string Message { get; set; } public override string ToString() diff --git a/TBF/Rig/BridgeComponents/GciBridge/UI/MainView.Designer.cs b/TBF/Rig/BridgeComponents/GciBridge/UI/MainView.Designer.cs index 86d9058c0..190f7bce2 100644 --- a/TBF/Rig/BridgeComponents/GciBridge/UI/MainView.Designer.cs +++ b/TBF/Rig/BridgeComponents/GciBridge/UI/MainView.Designer.cs @@ -316,7 +316,7 @@ // this.splitWorkArea.Panel2.Controls.Add(this.rtbMainLog); this.splitWorkArea.Size = new System.Drawing.Size(700, 320); - this.splitWorkArea.SplitterDistance = 233; + this.splitWorkArea.SplitterDistance = 320; this.splitWorkArea.SplitterWidth = 6; this.splitWorkArea.TabIndex = 0; // @@ -326,7 +326,7 @@ this.pnlGciViewHost.Dock = System.Windows.Forms.DockStyle.Fill; this.pnlGciViewHost.Location = new System.Drawing.Point(0, 0); this.pnlGciViewHost.Name = "pnlGciViewHost"; - this.pnlGciViewHost.Size = new System.Drawing.Size(233, 320); + this.pnlGciViewHost.Size = new System.Drawing.Size(320, 320); this.pnlGciViewHost.TabIndex = 0; // // rtbMainLog @@ -336,7 +336,7 @@ this.rtbMainLog.Location = new System.Drawing.Point(0, 0); this.rtbMainLog.Name = "rtbMainLog"; this.rtbMainLog.ReadOnly = true; - this.rtbMainLog.Size = new System.Drawing.Size(461, 320); + this.rtbMainLog.Size = new System.Drawing.Size(374, 320); this.rtbMainLog.TabIndex = 0; this.rtbMainLog.Text = ""; // diff --git a/TBF/Rig/BridgeComponents/GciBridge/UI/MainView.cs b/TBF/Rig/BridgeComponents/GciBridge/UI/MainView.cs index 24a978409..75f69e984 100644 --- a/TBF/Rig/BridgeComponents/GciBridge/UI/MainView.cs +++ b/TBF/Rig/BridgeComponents/GciBridge/UI/MainView.cs @@ -55,7 +55,7 @@ namespace TBF.Rig.BridgeComponents.GciBridge.UI _mainForm = mainform; _bridge = bridge; _gciApi = bridge.gciExternalInterface; - _laatzenApi = _bridge.gciExternalInterface._innerMeterAPI; + _laatzenApi = bridge._gciEngine.gciExternalInterface._innerMeterAPI; InitializeComponent(); InitializeDebugPanels(); //InitializeWorkerDebugPanel(); diff --git a/TBF/Rig/BridgeComponents/GciBridge/UI/StaraTuraAPI_GciBridge/PreadjustmentActionsView.cs b/TBF/Rig/BridgeComponents/GciBridge/UI/StaraTuraAPI_GciBridge/PreadjustmentActionsView.cs index 06924bdc4..9a3bc1bbb 100644 --- a/TBF/Rig/BridgeComponents/GciBridge/UI/StaraTuraAPI_GciBridge/PreadjustmentActionsView.cs +++ b/TBF/Rig/BridgeComponents/GciBridge/UI/StaraTuraAPI_GciBridge/PreadjustmentActionsView.cs @@ -21,6 +21,8 @@ using GciPublicModels = GenesisCordonelInterface.API.PublicModels; namespace TBF.Rig.BridgeComponents.GciBridge.UI.StaraTuraAPI_GciBridge { + + public partial class PreadjustmentActionsView : UserControl { private readonly GciBridge _bridge; @@ -33,6 +35,18 @@ namespace TBF.Rig.BridgeComponents.GciBridge.UI.StaraTuraAPI_GciBridge private readonly System.Windows.Forms.Timer _tempRequestTimer = new System.Windows.Forms.Timer(); private bool _tempButtonHighlight; + + private enum PreadjustmentExecutionMode + { + AsyncSlotWorker, + DirectToProcessTasks + } + + private PreadjustmentExecutionMode _preadjustmentExecutionMode = PreadjustmentExecutionMode.DirectToProcessTasks; + + private bool UseDirectProcess => + _preadjustmentExecutionMode == PreadjustmentExecutionMode.DirectToProcessTasks; + public PreadjustmentActionsView( MainView mainview, GciBridge bridge, @@ -59,10 +73,6 @@ namespace TBF.Rig.BridgeComponents.GciBridge.UI.StaraTuraAPI_GciBridge cb_Metersize.Items.Add(size); } var setM = MeterSize.DN50; - if (_mainView._gciApi._innerMeterAPI._settings.MeterSize != null) - { - setM = _mainView._gciApi._innerMeterAPI._settings.MeterSize; - } cb_Metersize.SelectedItem = setM; // @@ -185,24 +195,18 @@ namespace TBF.Rig.BridgeComponents.GciBridge.UI.StaraTuraAPI_GciBridge Log(result == null ? "" : result.ToString()); }*/ - private void Log(string message) + private void Log(string msg) { txtLog.AppendText( DateTime.Now.ToString("HH:mm:ss.fff") + " " + - message + + msg + Environment.NewLine); } - private void Log(int slot, string message) + private void Log(string msg, int? slot = null, string source = "APP", string PcbID = "") { - txtLog.AppendText( - DateTime.Now.ToString("HH:mm:ss.fff") + - " " + - $"Slot: {slot}" + - " - " + - message + - Environment.NewLine); + txtLog.AppendText($"{DateTime.Now.ToString("HH:mm:ss.fff")} {source} {msg} ({PcbID}){Environment.NewLine}"); } private void LoadRegisterComboBoxes() @@ -229,7 +233,7 @@ namespace TBF.Rig.BridgeComponents.GciBridge.UI.StaraTuraAPI_GciBridge return; } - ProcessProgress pp = CreatePreparationProgress(); + ProcessProgress pp = CreateProcessProgress(); List mc = CreateMeterControls(selectedSlots); var result = _bridge.Preadjustment_Initialization(pp, mc); @@ -250,8 +254,8 @@ namespace TBF.Rig.BridgeComponents.GciBridge.UI.StaraTuraAPI_GciBridge } private void detectActionButton_Click( - object sender, - EventArgs e) + object sender, + EventArgs e) { ExecuteAsync(async token => { @@ -264,13 +268,24 @@ namespace TBF.Rig.BridgeComponents.GciBridge.UI.StaraTuraAPI_GciBridge return; } - PreadjustmentDetectResult result = - await _bridge.PreAdjustment_DetectAsync(selectedSlots, token); + PreadjustmentDetectResult result; - Log( - result.Success - ? "Detect completed. " + result - : "Detect failed. " + result); + if (UseDirectProcess) + { + result = await Task.Run(() => + _bridge.PreAdjustment_DetectDirect(selectedSlots, token), + token); + } + else + { + result = await _bridge.PreAdjustment_DetectAsync( + selectedSlots, + token); + } + + Log(result.Success + ? "Detect completed. " + result + : "Detect failed. " + result); RefreshGrid(); }); @@ -282,8 +297,9 @@ namespace TBF.Rig.BridgeComponents.GciBridge.UI.StaraTuraAPI_GciBridge { ExecuteAsync(async token => { - await ExecutePreadjustmentForSelectedSlotsAsync( + await ExecutePreadjustmentActionAsync( _bridge.PreAdjustment_PreparationAsync, + _bridge.PreAdjustment_PreparationDirect, "Preparation", token); }); @@ -295,8 +311,9 @@ namespace TBF.Rig.BridgeComponents.GciBridge.UI.StaraTuraAPI_GciBridge { ExecuteAsync(async token => { - await ExecutePreadjustmentForSelectedSlotsAsync( + await ExecutePreadjustmentActionAsync( _bridge.PreAdjustment_AmplitudeTestAsync, + _bridge.PreAdjustment_AmplitudeTestDirect, "Amplitude Test", token); }); @@ -308,19 +325,13 @@ namespace TBF.Rig.BridgeComponents.GciBridge.UI.StaraTuraAPI_GciBridge { ExecuteAsync(async token => { - await ExecutePreadjustmentForSelectedSlotsAsync( + await ExecutePreadjustmentActionAsync( _bridge.PreAdjustment_TemperatureCalibrationAsync, + _bridge.PreAdjustment_TemperatureCalibrationDirect, "Temperature Calibration", token); }); } - private void pushTestBenchTempButton_Click(object sender, EventArgs e) - { - _bridge.PreAdjustment_PushTemperature(Convert.ToDouble(pushedTestBenchTempTextBox.Text)); - - _tempRequestTimer.Stop(); - pushTestBenchTempButton.BackColor = SystemColors.Control; - } private void offsetTestActionButton_Click( object sender, @@ -328,8 +339,9 @@ namespace TBF.Rig.BridgeComponents.GciBridge.UI.StaraTuraAPI_GciBridge { ExecuteAsync(async token => { - await ExecutePreadjustmentForSelectedSlotsAsync( + await ExecutePreadjustmentActionAsync( _bridge.PreAdjustment_OffsetTestAsync, + _bridge.PreAdjustment_OffsetTestDirect, "Offset Test", token); }); @@ -341,14 +353,15 @@ namespace TBF.Rig.BridgeComponents.GciBridge.UI.StaraTuraAPI_GciBridge { ExecuteAsync(async token => { - await ExecutePreadjustmentForSelectedSlotsAsync( + await ExecutePreadjustmentActionAsync( _bridge.PreAdjustment_CompletionAsync, + _bridge.PreAdjustment_CompletionDirect, "Completion", token); }); } - private ProcessProgress CreatePreparationProgress() + private ProcessProgress CreateProcessProgress() { ProcessProgress pp = new ProcessProgress { @@ -380,7 +393,7 @@ namespace TBF.Rig.BridgeComponents.GciBridge.UI.StaraTuraAPI_GciBridge { BeginInvoke(new Action(() => { - Log(e.Value); + Log(e.Value, e.Slot, e.Source, e.PcbId); })); } @@ -412,58 +425,13 @@ namespace TBF.Rig.BridgeComponents.GciBridge.UI.StaraTuraAPI_GciBridge return controls; } - private void writeRegisterButton_Click(object sender, EventArgs e) + + private void pushTestBenchTempButton_Click(object sender, EventArgs e) { - /*ExecuteAsync(async token => - { - string registerName = Convert.ToString(writeRegisterNameComboBox.Text).Trim(); - string valueText = writeRegisterValueTextBox.Text.Trim(); + _bridge.PreAdjustment_PushTemperature(Convert.ToDouble(pushedTestBenchTempTextBox.Text)); - if (string.IsNullOrWhiteSpace(registerName)) - throw new Exception("Write register name is empty."); - - if (string.IsNullOrWhiteSpace(valueText)) - throw new Exception("Write register value is empty."); - - object value; - - if (registerName == "GENESISFLOW_LedMode") - { - value = byte.Parse(valueText); - } - else - { - value = valueText; - } - - var tasks = GetSelectedSlots() - .Select(async slot => - { - //var result = await _bridge.WriteRegisterAsync(slot.Slot, registerName, value, false, false, token); - //var result = await _bridge.WriteRegisterWithRetryAsync(slot.Slot, registerName, value, false, false, token); - - var result = Xylem.Common.Ui.CordonelPreadjustmentUi. Processes.WriteRegisterSafe(meter, "Calibration factor1", Register.Genesisflow.CalFactor1, setting.CalFactor1); - Processes - - return new - { - Slot = slot.Slot, - Result = result - }; - }) - .ToList(); - - var results = await Task.WhenAll(tasks); - - foreach (var item in results.OrderBy(x => x.Slot)) - { - LogResult( - $"WriteRegisterAsync slot {item.Slot}, register {registerName}, value {value}", - item.Result); - } - - RefreshGrid(); - });*/ + _tempRequestTimer.Stop(); + pushTestBenchTempButton.BackColor = SystemColors.Control; } private async Task ExecutePreadjustmentForSelectedSlotsAsync( @@ -480,8 +448,6 @@ namespace TBF.Rig.BridgeComponents.GciBridge.UI.StaraTuraAPI_GciBridge return; } - var pp = CreatePreparationProgress(); - foreach (var selectedSlot in selectedSlots) { PreAdjustmentProcessResult result = @@ -499,5 +465,31 @@ namespace TBF.Rig.BridgeComponents.GciBridge.UI.StaraTuraAPI_GciBridge RefreshGrid(); } + + private async Task ExecutePreadjustmentActionAsync( + Func> asyncAction, + Func directAction, + string processName, + CancellationToken token) + { + if (UseDirectProcess) + { + PreAdjustmentProcessResult result = + await Task.Run(() => directAction(), token); + + Log(result.Success + ? $"{processName} completed. {result}" + : $"{processName} failed. {result}"); + + RefreshGrid(); + + return; + } + + await ExecutePreadjustmentForSelectedSlotsAsync( + asyncAction, + processName, + token); + } } } \ No newline at end of file