Develop - GciBridge -> GCI -> PreadjustmentUI functions 7 - successful processes - testbench is exported to UnionTown - without CalibParams DB writer

This commit is contained in:
Marek Frniak 2026-06-12 10:43:34 +02:00
parent 2ea0df8faf
commit 4e223549ee
17 changed files with 857 additions and 267 deletions

View File

@ -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<MeterStateControl> _meterControls = new List<MeterStateControl>();
public List<MeterStateControl> _tempMeterControls = new List<MeterStateControl>();
@ -55,6 +54,11 @@ namespace GenesisCordonelInterface.API
private readonly ConcurrentDictionary<int, bool> _selectedSlots = new ConcurrentDictionary<int, bool>();
public InterfaceGCIToLaatzen()
{
}
#endregion
#region ================================== Worker ==================================
@ -1592,22 +1596,30 @@ namespace GenesisCordonelInterface.API
IEnumerable<PublicModels.MeterBatchDebugStatus> 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<PublicModels.MeterBatchDebugStatus> selectedSlots,
CancellationToken token = default)
{
return Preadjustment_Detect(selectedSlots, token);
}
private PreadjustmentDetectResult Preadjustment_DetectCore(
private PreadjustmentDetectResult Preadjustment_Detect(
IEnumerable<PublicModels.MeterBatchDebugStatus> 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<MeterStateControl>();
@ -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();
}
/// <summary>
/// Executes standalone preparation process.
/// </summary>
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;
}
/// <summary>
@ -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);

View File

@ -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.
/// </summary>
public event Action<List<MeterBatchDebugStatus>> MeterBatchStatusChanged;
private readonly IMeterLoginPasswordReader loginPasswordsReader;
private readonly IPreAdjustmentCalibrationParamsReader calibrationParamsReader;
/// <summary>
@ -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<string, UInt32> 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<MeterStateControl> 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<PublicModels.MeterBatchDebugStatus> selectedSlots,
CancellationToken token = default)
{
return _innerMeterAPI.PreAdjustment_DetectDirect(selectedSlots, token);
}
public Task<PreAdjustmentProcessResult> 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<PreAdjustmentProcessResult> 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<PreAdjustmentProcessResult> 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<PreAdjustmentProcessResult> 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
/// </returns>
public Task<Dictionary<string, string>> ReadPreAdjustmentCalibrationParamsAsync(
public Task<Dictionary<string, UInt32>> ReadPreAdjustmentCalibrationParamsAsync(
DataQuery query,
CancellationToken token = default)
{

View File

@ -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"
}
}
}

View File

@ -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"
}
}

View File

@ -0,0 +1,32 @@
namespace GenesisCordonelInterface.Core.DataStorage.Config
{
/// <summary>
/// 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":
/// {
/// ...
/// }
/// }
/// </summary>
public class GciConfig
{
/// <summary>
/// Data storage configuration section.
///
/// Contains definitions for all configured readers and writers,
/// such as:
///
/// - MeterLoginPasswords
/// - PreAdjustmentCalibrationParams
/// - future storage providers
/// </summary>
public GciDataStorageConfig DataStorage { get; set; }
}
}

View File

@ -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
{
/// <summary>
/// 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=...
/// </summary>
public static class GciConfigLoader
{
/// <summary>
/// Loads default GCI configuration from:
///
/// Config\gci_config.json
/// </summary>
/// <returns>
/// Loaded GCI configuration.
/// </returns>
public static GciConfig LoadDefault()
{
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
string configPath = Path.Combine(
baseDirectory,
"Config",
"gci_config.json");
return Load(configPath, baseDirectory);
}
/// <summary>
/// Loads GCI configuration from specified file.
/// </summary>
/// <param name="configPath">
/// Path to configuration json file.
/// </param>
/// <param name="baseDirectory">
/// Base directory used for resolving relative paths.
/// </param>
/// <returns>
/// Loaded configuration object.
/// </returns>
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<GciConfig>(json);
if (config == null)
throw new InvalidOperationException(
"GCI config could not be loaded.");
NormalizeDataStoragePaths(
config,
baseDirectory ?? Path.GetDirectoryName(configPath));
return config;
}
/// <summary>
/// Normalizes paths for all configured data storage entries.
///
/// Converts relative file paths into absolute paths.
/// Database connection strings remain untouched.
/// </summary>
/// <param name="config">
/// Loaded configuration object.
/// </param>
/// <param name="baseDirectory">
/// Base path used for relative resolution.
/// </param>
private static void NormalizeDataStoragePaths(
GciConfig config,
string baseDirectory)
{
if (config.DataStorage == null)
return;
NormalizePath(
config.DataStorage.MeterLoginPasswords,
baseDirectory);
NormalizePath(
config.DataStorage.PreAdjustmentCalibrationParams,
baseDirectory);
}
/// <summary>
/// Converts relative file paths into absolute paths.
///
/// Applies only to:
/// - LocalCsv
/// - RemoteCsv
/// - LocalJson
/// - RemoteJson
///
/// Does not modify:
/// - Database connection strings
/// - REST URLs
/// </summary>
/// <param name="storageConfig">
/// Storage configuration.
/// </param>
/// <param name="baseDirectory">
/// Base path for resolution.
/// </param>
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));
}
}
}

View File

@ -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.
/// </returns>
Dictionary<string, string> GetCalibrationParams(
Dictionary<string, UInt32> GetCalibrationParams(
DataQuery query);
/// <summary>
@ -54,7 +55,7 @@ namespace GenesisCordonelInterface.Core.DataStorage.Reading.Implementation.PreAd
/// Dictionary where key is GENESISFLOW parameter name
/// and value is stored parameter value.
/// </returns>
Task<Dictionary<string, string>> ReadCalibrationParamsAsync(
Task<Dictionary<string, UInt32>> ReadCalibrationParamsAsync(
DataQuery query,
CancellationToken token = default);
}

View File

@ -88,13 +88,17 @@ namespace GenesisCordonelInterface.Core.DataStorage.Reading.Implementation.PreAd
/// Value:
/// Stored parameter value
/// </returns>
public async Task<Dictionary<string, string>> ReadCalibrationParamsAsync(
public async Task<Dictionary<string, UInt32>> 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();
}
}*/
}
/// <summary>
@ -127,7 +131,7 @@ namespace GenesisCordonelInterface.Core.DataStorage.Reading.Implementation.PreAd
/// Value:
/// Stored parameter value
/// </returns>
public Dictionary<string, string> GetCalibrationParams(
public Dictionary<string, UInt32> GetCalibrationParams(
DataQuery query)
{
ValidateQuery(query);
@ -172,11 +176,11 @@ namespace GenesisCordonelInterface.Core.DataStorage.Reading.Implementation.PreAd
/// Dictionary containing calibration parameter
/// name/value pairs.
/// </returns>
private Dictionary<string, string> ConvertResultToDictionary(
object result)
private Dictionary<string, UInt32> ConvertResultToDictionary(
object result)
{
Dictionary<string, string> values =
new Dictionary<string, string>();
Dictionary<string, UInt32> values =
new Dictionary<string, UInt32>();
if (result == null)
return values;
@ -188,19 +192,11 @@ namespace GenesisCordonelInterface.Core.DataStorage.Reading.Implementation.PreAd
foreach (Dictionary<string, object> 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<string, string> dictionary)
return dictionary;
if (diagnosticResult.Data is Dictionary<string, UInt32> uintDictionary)
return uintDictionary;
if (diagnosticResult.Data is Dictionary<string, string> stringDictionary)
{
foreach (var item in stringDictionary)
{
if (TryConvertToUInt32(item.Value, out UInt32 value))
values[item.Key] = value;
}
return values;
}
if (diagnosticResult.Data is Dictionary<string, object> 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<string, string> directDictionary)
return directDictionary;
if (result is Dictionary<string, UInt32> directUIntDictionary)
return directUIntDictionary;
if (result is Dictionary<string, string> directStringDictionary)
{
foreach (var item in directStringDictionary)
{
if (TryConvertToUInt32(item.Value, out UInt32 value))
values[item.Key] = value;
}
return values;
}
if (result is Dictionary<string, object> 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);
}
}
}

View File

@ -201,9 +201,10 @@
<DependentUpon>FrmGCIAPI.cs</DependentUpon>
</EmbeddedResource>
<Content Include="Core\Config\gci_config.json">
<Link>Config\gci_config.json</Link>
<Link>Config\gci_config.json</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="Core\Config\gci_config.json" />
<None Include="docs\articles\API\index.md" />
<None Include="docs\articles\API\PublicModels.md" />
<None Include="docs\articles\API\InterfaceGCIToLaatzen.md" />
@ -241,6 +242,7 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Folder Include="Config\" />
<Folder Include="Core\DataStorage\Writing\NewFolder1\" />
<Folder Include="RuntimePackage\Package\" />
</ItemGroup>

View File

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

View File

@ -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"
}
}
}

View File

@ -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<string, string> calibrationParams =
Dictionary<string, UInt32> calibrationParams =
ExtractPreAdjustmentCalibrationParams(data);
return new UdsPreAdjustmentCalibrationParamsResult
@ -1385,24 +1373,28 @@ namespace TBF.Rig.BridgeComponents.GciBridge
return query;
}
private Dictionary<string, string> ExtractPreAdjustmentCalibrationParams(
private Dictionary<string, UInt32> ExtractPreAdjustmentCalibrationParams(
object data)
{
Dictionary<string, string> result =
new Dictionary<string, string>();
Dictionary<string, UInt32> result =
new Dictionary<string, UInt32>();
if (data == null)
return result;
if (data is Dictionary<string, string> directDictionary)
if (data is Dictionary<string, UInt32> directDictionary)
return directDictionary;
if (data is Dictionary<string, object> 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<GciPublicModels.MeterBatchDebugStatus> 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 =======================================

View File

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

View File

@ -111,7 +111,7 @@ namespace TBF.Rig.BridgeComponents.GciBridge.Interfaces
{
public bool Success { get; set; }
public int MeterSize { get; set; }
public Dictionary<string, string> CalibrationParams { get; set; }
public Dictionary<string, UInt32> CalibrationParams { get; set; }
public string Message { get; set; }
public override string ToString()

View File

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

View File

@ -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();

View File

@ -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 ? "<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<MeterStateControl> 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<int, CancellationToken, Task<PreAdjustmentProcessResult>> asyncAction,
Func<PreAdjustmentProcessResult> 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);
}
}
}