Refactor iPerlCommunication module to integrate GenesisSmartReader, update related logic and methods, optimize asynchronous operations, and increment assembly version to 3.9.3091.1.
This commit is contained in:
parent
0b1e09e0df
commit
1709ef842d
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("3.9.3085.1")]
|
||||
[assembly: AssemblyFileVersion("3.9.3085.1")]
|
||||
[assembly: AssemblyVersion("3.9.3091.1")]
|
||||
[assembly: AssemblyFileVersion("3.9.3091.1")]
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
/// * mark test method from smart family devices
|
||||
/// * (this Test method is used for devices that support smart reader)
|
||||
/// </summary>
|
||||
public interface ITestMethodSmart
|
||||
public interface ITestMethodSmart : ITestMethod
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Common;
|
||||
using GenesisCordonelInterface.API;
|
||||
@ -25,6 +26,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
{
|
||||
await BuildConnectionAsync(genesidHead).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task BuildConnectionAsync(GenesisSmartReader genesidHead)
|
||||
{
|
||||
if (genesidHead == null)
|
||||
@ -32,6 +34,21 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
|
||||
bool simulation = genesidHead.DebugLevel == DebugMode.Simulate;
|
||||
|
||||
//No simulation
|
||||
var bridge = genesidHead.CommInterfaceBridge;
|
||||
if (bridge == null)
|
||||
throw new InvalidOperationException($"CommInterfaceBridge is null. Head: {genesidHead.GetSlotNr}");
|
||||
|
||||
//Check if exist and connected
|
||||
PublicModels.GciSlotInfo gciSlotInfo = await bridge.GetSlotAsync(genesidHead.GetSlotNr);
|
||||
|
||||
if (gciSlotInfo == null && gciSlotInfo.IsConnected)
|
||||
{
|
||||
log.Debug($"BuildConnection() - SlotNr: {genesidHead.GetSlotNr} already exist and connected!");
|
||||
return;
|
||||
}
|
||||
|
||||
//Unconnected - do connection
|
||||
var request = new PublicModels.GciInitSlotRequest
|
||||
{
|
||||
SlotId = genesidHead.GetSlotNr,
|
||||
@ -53,24 +70,23 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
|
||||
log.Debug($"BuildConnection() - SlotNr: {genesidHead.GetSlotNr} initializing... Request: {request}");
|
||||
|
||||
var bridge = genesidHead.CommInterfaceBridge;
|
||||
if (bridge == null)
|
||||
throw new InvalidOperationException("CommInterfaceBridge is null.");
|
||||
|
||||
|
||||
var initResult = await ExecuteWithRetryAsync(
|
||||
() => bridge.InitSlotAsync(request),
|
||||
r => r.Success,
|
||||
$"InitSlotAsync({genesidHead.GetSlotNr})");
|
||||
|
||||
var initResult = await WithTimeout(
|
||||
bridge.InitSlotAsync(request),
|
||||
TimeSpan.FromSeconds(15),
|
||||
"InitSlotAsync timeout");
|
||||
|
||||
log.Debug($"BuildConnection() - SlotNr: {genesidHead.GetSlotNr} initialized. Result: {initResult}");
|
||||
|
||||
if (initResult == null)
|
||||
throw new InvalidOperationException("InitSlotAsync returned null.");
|
||||
|
||||
var updateResult = await WithTimeout(
|
||||
bridge.UpdateSlotAsync(request),
|
||||
TimeSpan.FromSeconds(15),
|
||||
"UpdateSlotAsync timeout");
|
||||
var updateResult = await ExecuteWithRetryAsync(
|
||||
() => bridge.UpdateSlotAsync(request),
|
||||
r => r.Success,
|
||||
$"UpdateSlotAsync({genesidHead.GetSlotNr})");
|
||||
|
||||
log.Debug($"BuildConnection() - SlotNr: {genesidHead.GetSlotNr} updated! Result: {updateResult}");
|
||||
|
||||
@ -80,6 +96,57 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
slotDefined = true;
|
||||
}
|
||||
|
||||
private async Task<T> ExecuteWithRetryAsync<T>(
|
||||
Func<Task<T>> action,
|
||||
Func<T, bool> successCondition,
|
||||
string operationName,
|
||||
int maxRetries = 5,
|
||||
int timeoutSeconds = 30,
|
||||
int delayMs = 1000)
|
||||
{
|
||||
using var cts = new CancellationTokenSource( TimeSpan.FromSeconds(timeoutSeconds));
|
||||
|
||||
Exception lastException = null;
|
||||
|
||||
for (int attempt = 1; attempt <= maxRetries; attempt++)
|
||||
{
|
||||
if (cts.IsCancellationRequested)
|
||||
{
|
||||
throw new TimeoutException( $"{operationName} timeout after {timeoutSeconds} seconds.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
log.Debug($"{operationName} attempt {attempt}/{maxRetries}");
|
||||
|
||||
T result = await action();
|
||||
|
||||
if (result == null)
|
||||
throw new InvalidOperationException(
|
||||
$"{operationName} returned null.");
|
||||
|
||||
if (successCondition(result))
|
||||
{
|
||||
log.Debug($"{operationName} success.");
|
||||
return result;
|
||||
}
|
||||
|
||||
log.Debug($"{operationName} failed. Success condition not met.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
lastException = ex;
|
||||
log.Error($"{operationName} failed on attempt {attempt}/{maxRetries}", ex);
|
||||
}
|
||||
|
||||
await Task.Delay(delayMs, cts.Token);
|
||||
}
|
||||
|
||||
throw new InvalidOperationException(
|
||||
$"{operationName} failed after {maxRetries} attempts.",
|
||||
lastException);
|
||||
}
|
||||
|
||||
private static async Task<T> WithTimeout<T>(
|
||||
Task<T> task,
|
||||
TimeSpan timeout,
|
||||
@ -102,12 +169,25 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
|
||||
public void CloseConnection()
|
||||
{
|
||||
genesisHead?.CommInterfaceBridge?.DisconnectAsync(genesisHead.GetSlotNr);
|
||||
Task.Run(CloseConnectionAsync)
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
return;
|
||||
}
|
||||
|
||||
public async Task<bool> CloseConnectionAsync()
|
||||
{
|
||||
log.Debug("CloseConnectionAsync called for iHead: " + genesisHead);
|
||||
await genesisHead?.CommInterfaceBridge?.DisconnectAsync(genesisHead.GetSlotNr)!;
|
||||
log.Debug("DisconnectAsync completed for iHead: " + genesisHead);
|
||||
await genesisHead?.CommInterfaceBridge?.CleanSlotAsync(genesisHead.GetSlotNr)!;
|
||||
log.Debug("CleanSlotAsync completed for iHead: " + genesisHead);
|
||||
DisposeSlot();
|
||||
|
||||
// if (serialDriver != null)
|
||||
// serialDriver.CloseConnection();
|
||||
// serialDriver = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool isConnected = false;
|
||||
@ -122,7 +202,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
{
|
||||
try
|
||||
{
|
||||
log.Debug("ReadRequest_PCB called for iHead: " + genesisHead);
|
||||
log.Debug("ReadRequest_PCBAsync called for iHead: " + genesisHead);
|
||||
|
||||
if (genesisHead == null)
|
||||
return string.Empty;
|
||||
@ -133,27 +213,26 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
if (genesisHead.CommInterfaceBridge == null)
|
||||
return string.Empty;
|
||||
|
||||
if (!IsSlotDefined)
|
||||
{
|
||||
await BuildConnectionAsync(genesisHead);
|
||||
}
|
||||
|
||||
await BuildConnectionAsync(genesisHead);
|
||||
|
||||
|
||||
if (genesisHead.DebugLevel == DebugMode.Simulate)
|
||||
{
|
||||
log.Debug("ReadRequest_PCB() - Simulated response");
|
||||
log.Debug($"ReadRequest_PCBAsync({genesisHead.GetSlotNr}) - Simulated response");
|
||||
return "-OK Simulated PCB-";
|
||||
}
|
||||
|
||||
GciBridge gciBridge = genesisHead.CommInterfaceBridge;
|
||||
|
||||
log.Debug("ReadRequest_PCB() - GciBridge created");
|
||||
log.Debug($"ReadRequest_PCBAsync({genesisHead.GetSlotNr}) - GciBridge created");
|
||||
|
||||
gciBridge.GciBridgeCfg.EnableExternalAccess = true;
|
||||
gciBridge.GciBridgeCfg.EnableGuiAccess = false;
|
||||
|
||||
gciBridge.Initialize();
|
||||
|
||||
log.Debug("ReadRequest_PCB() - GciBridge initialized");
|
||||
log.Debug($"ReadRequest_PCBAsync({genesisHead.GetSlotNr}) - GciBridge initialized");
|
||||
|
||||
RadioService headService = new RadioService(gciBridge);
|
||||
|
||||
@ -185,13 +264,18 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.Error("ReadRequest_PCBAsync() - Exception:", ex);
|
||||
log.Error($"ReadRequest_PCBAsync({genesisHead.GetSlotNr}) - Exception:", ex);
|
||||
return ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
public string ReadRequest_PCB()
|
||||
{
|
||||
if (genesisHead != null && genesisHead.DebugLevel == DebugMode.Simulate)
|
||||
{
|
||||
log.Debug("ReadRequest_PCB() - Simulated response");
|
||||
return "Simulated PCB-123";
|
||||
}
|
||||
return Task.Run(() => ReadRequest_PCBAsync(genesisHead))
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
@ -227,10 +311,8 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
if (genesisHead.CommInterfaceBridge == null)
|
||||
return false;
|
||||
|
||||
if (!IsSlotDefined)
|
||||
{
|
||||
await BuildConnectionAsync(genesisHead);
|
||||
}
|
||||
await BuildConnectionAsync(genesisHead);
|
||||
|
||||
|
||||
if (genesisHead.DebugLevel == DebugMode.Simulate)
|
||||
{
|
||||
@ -306,11 +388,8 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
|
||||
if (genesisHead.CommInterfaceBridge == null)
|
||||
return false;
|
||||
|
||||
if (!IsSlotDefined)
|
||||
{
|
||||
await BuildConnectionAsync(genesisHead);
|
||||
}
|
||||
|
||||
await BuildConnectionAsync(genesisHead);
|
||||
|
||||
if (genesisHead.DebugLevel == DebugMode.Simulate)
|
||||
{
|
||||
@ -383,7 +462,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
if (genesisHead.DebugLevel == DebugMode.Simulate)
|
||||
{
|
||||
isTestModeSuccessful = true;
|
||||
return "-OK Simulated response-";
|
||||
return "-OK SetTestMode Simulated response-";
|
||||
}
|
||||
|
||||
try
|
||||
@ -399,6 +478,17 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set Active mode
|
||||
/// </summary>
|
||||
/// <param name="iHead"></param>
|
||||
/// <returns></returns>
|
||||
public bool TurnOffRadio()
|
||||
{
|
||||
return Task.Run(CloseConnectionAsync)
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
@ -439,6 +529,33 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TurnOffRadio - string response
|
||||
/// </summary>
|
||||
/// <param name="iHead"></param>
|
||||
/// <param name="isTestModeSuccessful"></param>
|
||||
/// <returns></returns>
|
||||
public string TurnOffRadio(ref bool isTestModeSuccessful)
|
||||
{
|
||||
if (genesisHead.DebugLevel == DebugMode.Simulate)
|
||||
{
|
||||
isTestModeSuccessful = true;
|
||||
return "-OK TurnOffRadio Simulated response-";
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
bool turnOffRadio = TurnOffRadio();
|
||||
isTestModeSuccessful = turnOffRadio;
|
||||
return turnOffRadio ? "TurnOffRadio - OK" : "TurnOffRadio - FAILED";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.Error("SetActiveMode() - Exception:" + ex.StackTrace);
|
||||
return "Set Active Mode - Exception";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set Active mode - string response
|
||||
/// </summary>
|
||||
@ -450,7 +567,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
if (genesisHead.DebugLevel == DebugMode.Simulate)
|
||||
{
|
||||
isTestModeSuccessful = true;
|
||||
return "-OK Simulated response-";
|
||||
return "-OK SetActiveMode Simulated response-";
|
||||
}
|
||||
|
||||
try
|
||||
@ -514,11 +631,8 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
|
||||
if (genesisHead.CommInterfaceBridge == null)
|
||||
return false;
|
||||
|
||||
if (!IsSlotDefined)
|
||||
{
|
||||
await BuildConnectionAsync(genesisHead);
|
||||
}
|
||||
|
||||
await BuildConnectionAsync(genesisHead);
|
||||
|
||||
if (genesisHead.DebugLevel == DebugMode.Simulate)
|
||||
{
|
||||
@ -591,7 +705,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
CloseConnection();
|
||||
CloseConnectionAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -144,20 +144,22 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
log.Debug("LoginByPasswordAsync( Slot: {0}) - set password to: " + txtPassword.Substring(0, 4) + "************");
|
||||
log.Debug($"LoginByPasswordAsync( Slot: {slotId}) - set password to: " + txtPassword.Substring(0, 4) + "************");
|
||||
var gciSetPasswordResult = await _bridge.SetPasswordAsync(slotId,txtPassword, token);
|
||||
log.Debug("LoginByPasswordAsync( Slot: {0}) - SetPasswordAsync Result: " + gciSetPasswordResult);
|
||||
log.Debug($"LoginByPasswordAsync( Slot: {slotId}) - SetPasswordAsync Result: " + gciSetPasswordResult);
|
||||
|
||||
// LOGIN
|
||||
log.Debug($"LoginByPasswordAsync( Slot: {slotId}) - START LOGIN");
|
||||
|
||||
var gciSlotInfo = await _bridge.GetSlotAsync(slotId);
|
||||
log.Debug($"LoginByPasswordAsync( Checked before Login() Slot: {slotId}) - START LOGIN Slot: {gciSlotInfo}");
|
||||
GenesisCordonelInterface.API.PublicModels.GciLoginResult result = await _bridge.LoginAsync(slotId, token);
|
||||
|
||||
log.Debug($"LoginByPasswordAsync( Slot: {slotId}) Result: " + result);
|
||||
|
||||
log.Debug($"LoginByPasswordAsync( Slot: {slotId}) - END LOGIN, Success: {result.Success}");
|
||||
// ~ LOGIN
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<ReadPcbResult> ReadRequest_PCBAsync( GenesisSmartReader head)
|
||||
public async Task<ReadPcbResult> ReadRequest_PCBAsync( GenesisSmartReader head, bool bReload = false)
|
||||
{
|
||||
log.Debug("ReadRequest_PCB called for iHead: " + head);
|
||||
|
||||
@ -174,8 +176,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
try
|
||||
{
|
||||
// CONNECT ONLY IF NEEDED
|
||||
var connectResult =
|
||||
await EnsureConnectedAsync(head);
|
||||
var connectResult = await EnsureConnectedAsync(head);
|
||||
|
||||
if (!connectResult.IsConnected)
|
||||
{
|
||||
@ -183,24 +184,42 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
}
|
||||
|
||||
log.Debug($"ReadRequest_PCB() connect - {connectResult.Message}");
|
||||
|
||||
|
||||
//Check if exist PCB
|
||||
if (!bReload)
|
||||
{
|
||||
var gciSlotInfo = await head.CommInterfaceBridge.GetSlotAsync(head.GetSlotNr);
|
||||
|
||||
if (gciSlotInfo == null && gciSlotInfo.Success && string.IsNullOrEmpty(gciSlotInfo.PcbId))
|
||||
{
|
||||
log.Debug(
|
||||
$"BuildConnection() - SlotNr: {head.GetSlotNr} already exist PCB: {gciSlotInfo.PcbId}");
|
||||
return new ReadPcbResult
|
||||
{
|
||||
IsConnected = gciSlotInfo.IsConnected,
|
||||
IsValidPcb = true,
|
||||
PcbId = gciSlotInfo.PcbId,
|
||||
Message = "PCB already exist."
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// PCB READ LOOP
|
||||
string validPcbId = null;
|
||||
int maxAttempts = 5;
|
||||
DateTime startTime = DateTime.UtcNow;
|
||||
TimeSpan maxDuration = TimeSpan.FromSeconds(10);
|
||||
TimeSpan maxDuration = TimeSpan.FromSeconds(30);
|
||||
|
||||
//LOOP
|
||||
for (int attempt = 1; attempt <= maxAttempts; attempt++)
|
||||
{
|
||||
if (DateTime.UtcNow - startTime > maxDuration)
|
||||
{
|
||||
log.Debug("ReadRequest_PCB() - PCB max duration exceeded");
|
||||
log.Debug($"ReadRequest_PCB({head.GetSlotNr}) - PCB max duration exceeded");
|
||||
break;
|
||||
}
|
||||
|
||||
log.Debug($"ReadRequest_PCB() - PCB attempt {attempt}/{maxAttempts}");
|
||||
log.Debug($"ReadRequest_PCB({head.GetSlotNr}) - PCB attempt {attempt}/{maxAttempts}");
|
||||
var pcbTask = head.CommInterfaceBridge.GetPcbIdAsync(head.GetSlotNr);
|
||||
var timeoutTaskPcb = Task.Delay(TimeSpan.FromSeconds(5));
|
||||
var completedTaskPcb = await Task.WhenAny(pcbTask, timeoutTaskPcb);
|
||||
@ -217,13 +236,13 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
{
|
||||
if (resultPCB == null)
|
||||
{
|
||||
log.Debug($"ReadRequest_PCB() PCB attempt {attempt} - result is null");
|
||||
log.Debug($"ReadRequest_PCB({head.GetSlotNr}) PCB attempt {attempt} - result is null");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!resultPCB.Success)
|
||||
{
|
||||
log.Debug($"ReadRequest_PCB() PCB attempt {attempt} - Success=false");
|
||||
log.Debug($"ReadRequest_PCB({head.GetSlotNr}) PCB attempt {attempt} - Success=false");
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -231,7 +250,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
|
||||
if (string.IsNullOrWhiteSpace(pcbId))
|
||||
{
|
||||
log.Debug($"ReadRequest_PCB() PCB attempt {attempt} - PCB empty");
|
||||
log.Debug($"ReadRequest_PCB({head.GetSlotNr}) PCB attempt {attempt} - PCB empty");
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -239,12 +258,12 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
|
||||
if (pcbId.Length != 9)
|
||||
{
|
||||
log.Debug( $"ReadRequest_PCB() PCB attempt {attempt} - Invalid PCB length: '{pcbId}', len={pcbId.Length}");
|
||||
log.Debug( $"ReadRequest_PCB({head.GetSlotNr}) PCB attempt {attempt} - Invalid PCB length: '{pcbId}', len={pcbId.Length}");
|
||||
continue;
|
||||
}
|
||||
|
||||
validPcbId = pcbId;
|
||||
log.Debug($"ReadRequest_PCB() PCB valid: {validPcbId}");
|
||||
log.Debug($"ReadRequest_PCB({head.GetSlotNr}) PCB valid: {validPcbId}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,6 +40,11 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
if(Head != null && Head.OptoHeadTest != null)
|
||||
{
|
||||
Head.OptoHeadTest.CloseConnection();
|
||||
}
|
||||
|
||||
stopWorkerThread = true;
|
||||
if (optoThread != null)
|
||||
{
|
||||
|
||||
@ -195,9 +195,9 @@ namespace TBF.Rig
|
||||
new TestMethods.FlyingStartFirstRepetWithMassColl.HeatMeters.Factory(),
|
||||
new TestMethods.FlyingStartTankCollection.Single.Factory(),
|
||||
new TestMethods.FlyingStartTankCollection.Compound.Factory(),
|
||||
//new TestMethods.GenesisCommunication.GenesisHead.Factory(),
|
||||
new TestMethods.GenesisCommunication.Factory(),//GenesisTestMethod - inserted/ into IperlCommunication
|
||||
new TestMethods.GrabImage.Factory(),
|
||||
new TestMethods.iPerlCommunication.TestMethodFactory(), /// iPerlCommunication
|
||||
//new TestMethods.iPerlCommunication.TestMethodFactory(), /// iPerlCommunication
|
||||
new TestMethods.LeakTest.Factory(),
|
||||
new TestMethods.LiveStream.Factory(),
|
||||
new TestMethods.ManualEntry.Factory(),
|
||||
|
||||
@ -16,7 +16,7 @@ using iPerlCommunicationSeq = TBF.Rig.TestMethods.iPerlCommunication.iPerlCommun
|
||||
|
||||
namespace TBF.Rig.TestMethods.GenesisCommunication
|
||||
{
|
||||
public class TestMethod : SmartComponentBase, ISimultTestMethod, ISequenceCondition, ISessionDataMngmnt, ITestMethodSmart
|
||||
public class TestMethod : SmartComponentBase, ISimultTestMethod, ISequenceCondition, ISessionDataMngmnt, ITestMethodSmart
|
||||
{
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(TestMethod));
|
||||
protected static readonly ILog rfidDataLogger = LogManager.GetLogger("RfidData");
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
/// Author: Milan Hanajík
|
||||
///
|
||||
using System;
|
||||
using TBF.Rig.RegisterReaders.GenesisRegReader.implementations;
|
||||
|
||||
namespace TBF.Rig.TestMethods.iPerlCommunication
|
||||
{
|
||||
@ -10,12 +11,12 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
||||
{
|
||||
public int ThreadId;
|
||||
public int WMNr0; /// 0-based water meter position
|
||||
public iPerlHead.IperlHead Ihead;
|
||||
public GenesisSmartReader Ihead;
|
||||
public Results.Entities.WaterMeter Wm;
|
||||
public string CommMessage;
|
||||
public CommErr CommErr;
|
||||
|
||||
public CommCompletedEventArgs(int threadId, int wmNr0, iPerlHead.IperlHead ihead, Results.Entities.WaterMeter wm, string commMessage, CommErr commErr)
|
||||
public CommCompletedEventArgs(int threadId, int wmNr0, GenesisSmartReader ihead, Results.Entities.WaterMeter wm, string commMessage, CommErr commErr)
|
||||
{
|
||||
this.ThreadId = threadId;
|
||||
this.WMNr0 = wmNr0;
|
||||
|
||||
@ -20,10 +20,16 @@ using TBF.Rig.TestMethods.iPerlCommunication.iPerlHead;
|
||||
using Results.Entities;
|
||||
using static Sensus.iPerl.NfcHandler.MCI_Protocol;
|
||||
using System.Threading.Tasks;
|
||||
using TBF.Rig.RegisterReaders.GenesisRegReader.implementations;
|
||||
using TBF.Rig.TestMethods.GenesisCommunication;
|
||||
using TBF.Rig.TestMethods.iPerlCommunication.communication;
|
||||
using TBF.Rig.TestMethods.iPerlCommunication.communication.C4.diagnosticLed;
|
||||
using TBF.Rig.TestMethods.iPerlCommunication.communication.C4.protocolCommons;
|
||||
using TBF.Rig.Uni.SharedDialogs.SmartMetersCommunication.common;
|
||||
using CommunicationInterface = TBF.Rig.TestMethods.iPerlCommunication.iPerlHead.CommunicationInterface;
|
||||
using ConfigStruct = TBF.Rig.TestMethods.iPerlCommunication.iPerlHead.ConfigStruct;
|
||||
using MessageID = TBF.Rig.TestMethods.iPerlCommunication.iPerlHead.MessageID;
|
||||
using MeterType = TBF.Rig.TestMethods.iPerlCommunication.iPerlHead.MeterType;
|
||||
|
||||
namespace TBF.Rig.TestMethods.iPerlCommunication
|
||||
{
|
||||
@ -190,7 +196,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
||||
static int[] ckbIndex;
|
||||
static bool[] ckbState;
|
||||
|
||||
static IList<IperlHead> iperlHeads;
|
||||
static IList<GenesisSmartReader> genesisHeads;
|
||||
static IList<int> waterMeterPositions0; /// keeps original 0-based indices in RegisterReaders list
|
||||
static int commonWMType;
|
||||
|
||||
@ -327,21 +333,21 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
||||
StartForceCloseHandler();
|
||||
|
||||
|
||||
iperlHeads = new List<IperlHead>();
|
||||
genesisHeads = new List<GenesisSmartReader>();
|
||||
waterMeterPositions0 = new List<int>();
|
||||
///
|
||||
for (int wmPos = 0; wmPos < ProcessData.RegisterReaders.Length; wmPos++)
|
||||
{
|
||||
IperlHead iperlHead = ProcessData.RegisterReaders[wmPos] as IperlHead;
|
||||
GenesisSmartReader genesisSmartReader = ProcessData.RegisterReaders[wmPos] as GenesisSmartReader;
|
||||
|
||||
if (iperlHead != null)
|
||||
if (genesisSmartReader != null)
|
||||
{
|
||||
iperlHeads.Add(iperlHead);
|
||||
genesisHeads.Add(genesisSmartReader);
|
||||
waterMeterPositions0.Add(wmPos);
|
||||
}
|
||||
}
|
||||
|
||||
WaterMetersCount = iperlHeads.Count;
|
||||
WaterMetersCount = genesisHeads.Count;
|
||||
ShuffleTextBoxes(WaterMetersCount, ProcessData.LineSize);
|
||||
|
||||
///
|
||||
@ -354,7 +360,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
||||
|
||||
/// group numbers are >=1, lastGroup == 0 means there is no group
|
||||
lastGroup = 0;
|
||||
foreach (var iPerl in iPerlCommunicationForm.iperlHeads)
|
||||
foreach (var iPerl in iPerlCommunicationForm.genesisHeads)
|
||||
{
|
||||
if (iPerl.Group > lastGroup) lastGroup = iPerl.Group;
|
||||
}
|
||||
@ -369,7 +375,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
||||
}
|
||||
|
||||
muxBrdOrGroup14Nrs = new List<int>();
|
||||
foreach (var iPerl in iPerlCommunicationForm.iperlHeads)
|
||||
foreach (var iPerl in iPerlCommunicationForm.genesisHeads)
|
||||
{
|
||||
if (!muxBrdOrGroup14Nrs.Contains(iPerl.MuxBoardNrOrGroup14)) muxBrdOrGroup14Nrs.Add(iPerl.MuxBoardNrOrGroup14);
|
||||
}
|
||||
@ -451,7 +457,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
||||
textBoxesCount = wmsCount;
|
||||
}
|
||||
|
||||
int count = checkBoxesEditMode ? textBoxesCount : Math.Min(textBoxesCount, iperlHeads.Count);
|
||||
int count = checkBoxesEditMode ? textBoxesCount : Math.Min(textBoxesCount, genesisHeads.Count);
|
||||
for (int j = 0; j < count; j++)
|
||||
{
|
||||
labels[j].Text = (j + 1).ToString();
|
||||
@ -511,7 +517,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
||||
{
|
||||
labels[i].Visible = counters[i].Visible = messages[i].Visible = checkBoxes[i].Visible = true;
|
||||
|
||||
if (!checkBoxesEditMode && (iperlHeads[i] == null || iperlHeads[i].Disabled))
|
||||
if (!checkBoxesEditMode && (genesisHeads[i] == null || genesisHeads[i].Disabled))
|
||||
{
|
||||
/// iPerl position i+1 is disabled
|
||||
checkBoxes[i].Enabled = checkBoxes[i].Checked = ckbState[i] = false;
|
||||
@ -539,7 +545,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
||||
/// Regular activity (not a checkbox edit mode invoked from TBF menu)
|
||||
|
||||
/// Reset opto-data indication
|
||||
for (int i = 0; i < iperlHeads.Count; i++)
|
||||
for (int i = 0; i < genesisHeads.Count; i++)
|
||||
{
|
||||
counters[i].BackColor = OptoNokColor;
|
||||
}
|
||||
@ -640,12 +646,12 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
||||
{
|
||||
/// Start processing of opto-datastreams from all iPERL-s
|
||||
int count = 0;
|
||||
for (int wmNr0 = 0; wmNr0 < iperlHeads.Count; wmNr0++)
|
||||
for (int wmNr0 = 0; wmNr0 < genesisHeads.Count; wmNr0++)
|
||||
{
|
||||
WaterMeter wm = (ProcessData.BatchRslts.Batch.WaterMeters != null && ProcessData.BatchRslts.Batch.WaterMeters.Count > wmNr0)
|
||||
? ProcessData.BatchRslts.Batch.WaterMeters[wmNr0] : null;
|
||||
|
||||
IperlHead ihead = iperlHeads[wmNr0];
|
||||
GenesisSmartReader ihead = genesisHeads[wmNr0];
|
||||
|
||||
if (ihead != null && wm != null && !wm.Disabled)
|
||||
{
|
||||
@ -683,9 +689,9 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
||||
{
|
||||
bool wmFound = false;
|
||||
|
||||
for (int wmNr0 = 0; wmNr0 < iperlHeads.Count; wmNr0++)
|
||||
for (int wmNr0 = 0; wmNr0 < genesisHeads.Count; wmNr0++)
|
||||
{
|
||||
IperlHead ihead = iperlHeads[wmNr0];
|
||||
GenesisSmartReader ihead = genesisHeads[wmNr0];
|
||||
if ((ihead.Group == group) && (threadIx < muxBrdOrGroup14Nrs.Count) && (ihead.MuxBoardNrOrGroup14 == muxBrdOrGroup14Nrs[threadIx]))
|
||||
{
|
||||
wmFound = true;
|
||||
@ -808,23 +814,24 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
||||
}
|
||||
}
|
||||
|
||||
private CommErr ReadSerialNr(int threadId, IperlHead ihead, ref string resultStr)
|
||||
private CommErr ReadSerialNr(int threadId, GenesisSmartReader ihead, ref string resultStr)
|
||||
{
|
||||
log.Debug("ReadSerialNr threadId=" + threadId + ", ihead=" + ihead.ToString());
|
||||
if (ihead.ConfigStruct == null)
|
||||
{
|
||||
log.Debug("ConfigStruct is null - created new in ReadSerialNr()");
|
||||
ihead.ConfigStruct = new ConfigStruct();
|
||||
ihead.ConfigStruct = new TBF.Rig.RegisterReaders.GenesisRegReader.implementations.ConfigStruct();
|
||||
}
|
||||
if (ihead.CommFailed || ihead.ConfigStruct == null) return CommErr.CommFailed;
|
||||
|
||||
//I will do communication to meter now
|
||||
|
||||
CommErr error = CommErr.Read;
|
||||
if (ihead.OptoHeadTest.ReadSerialNr())
|
||||
var result = ihead.OptoHeadTest.ReadRequest_PCB();
|
||||
if (string.IsNullOrEmpty(result))
|
||||
{
|
||||
log.Debug("ReadSerialNr successful");
|
||||
resultStr = string.Format($"Serial No: {ihead.OptoHeadTest.ReadRequest_PCB()}");
|
||||
resultStr = string.Format($"Serial No: {result}");
|
||||
error = CommErr.None;
|
||||
}
|
||||
else
|
||||
@ -835,7 +842,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
||||
return error;
|
||||
}
|
||||
|
||||
private CommErr SetIdleMode(int threadId, IperlHead ihead, ref string resultStr)
|
||||
private CommErr SetIdleMode(int threadId, GenesisSmartReader ihead, ref string resultStr)
|
||||
{
|
||||
log.Debug("SetActiveMode threadId=" + threadId);
|
||||
CommErr error = CommErr.CmdActive;
|
||||
@ -871,7 +878,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
||||
/// <param name="wm">Water meter object</param>
|
||||
/// <param name="resultStr">String passed to caller</param>
|
||||
/// <returns>true on success</returns>
|
||||
static CommErr ReadConfiguration(IperlHead ihead, WaterMeter wm, ref string resultStr)
|
||||
static CommErr ReadConfiguration(GenesisSmartReader ihead, WaterMeter wm, ref string resultStr)
|
||||
{
|
||||
// TODO BUMI in clasic case we need to read most of data - see ConfigStruct
|
||||
|
||||
@ -929,13 +936,13 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
||||
/// <param name="ihead">iPERL head object</param>
|
||||
/// <param name="resultStr">String passed to caller</param>
|
||||
/// <returns>true on success</returns>
|
||||
static CommErr SetTestMode(int threadId, IperlHead ihead, ref string resultStr)
|
||||
static CommErr SetTestMode(int threadId, GenesisSmartReader ihead, ref string resultStr)
|
||||
{
|
||||
log.Debug("SetTestMode threadId=" + threadId + ", ihead=" + ihead.ToString());
|
||||
if (ihead.ConfigStruct == null)
|
||||
{
|
||||
log.Debug("ConfigStruct is null - created new in SetTestMode()");
|
||||
ihead.ConfigStruct = new ConfigStruct();
|
||||
ihead.ConfigStruct = new TBF.Rig.RegisterReaders.GenesisRegReader.implementations.ConfigStruct();
|
||||
}
|
||||
if (ihead.CommFailed || ihead.ConfigStruct == null) return CommErr.CommFailed;
|
||||
|
||||
@ -988,7 +995,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
||||
/// <param name="ihead">iPERL head object</param>
|
||||
/// <param name="resultStr">String passed to caller</param>
|
||||
/// <returns>true on success</returns>
|
||||
static CommErr SetActiveMode(int threadId, IperlHead ihead, ref string resultStr)
|
||||
static CommErr SetActiveMode(int threadId, GenesisSmartReader ihead, ref string resultStr)
|
||||
{
|
||||
log.Debug("SetActiveMode threadId=" + threadId);
|
||||
CommErr error = CommErr.CmdActive;
|
||||
@ -2476,7 +2483,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
||||
return CommErr.None;
|
||||
}
|
||||
|
||||
static CommErr Simulate(IperlHead ihead, WaterMeter wm, ref string resultStr)
|
||||
static CommErr Simulate(GenesisSmartReader ihead, WaterMeter wm, ref string resultStr)
|
||||
{
|
||||
string[] arguments = multiTestParams[currentActivityStep].Activity.Split(new char[] { ' ' });
|
||||
|
||||
@ -2544,15 +2551,16 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
||||
///
|
||||
/// Update opto-communication indication
|
||||
///
|
||||
for (int i = 0; i < iperlHeads.Count; i++)
|
||||
for (int i = 0; i < genesisHeads.Count; i++)
|
||||
{
|
||||
if (iperlHeads[i] == null || iperlHeads[i].Disabled)
|
||||
if (genesisHeads[i] == null || genesisHeads[i].Disabled)
|
||||
{
|
||||
counters[i].BackColor = DisabledColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (iperlHeads[i].CheckFlowDirection())
|
||||
counters[i].BackColor = OptoAndDirOKColor;
|
||||
/*switch (genesisHeads[i].CheckFlowDirection())
|
||||
{
|
||||
case OptoHeadState.OptoAndDirOK:
|
||||
counters[i].BackColor = OptoAndDirOKColor;
|
||||
@ -2566,7 +2574,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
||||
case OptoHeadState.OptoNok:
|
||||
counters[i].BackColor = OptoNokColor;
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
@ -2657,15 +2665,15 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
||||
tstRslt.MassOfEvapWater = 0;
|
||||
tstRslt.TestTime += testTime; /// [s] total communication time of all tests
|
||||
|
||||
for (int i = 0; i < iperlHeads.Count; i++)
|
||||
for (int i = 0; i < genesisHeads.Count; i++)
|
||||
{
|
||||
Results.Entities.MeterTestRslt meterRslt =
|
||||
ProcessData.BatchRslts.GetMeterTestRslt(test.Name, waterMeterPositions0[i], CompoundMeterId.Single);
|
||||
|
||||
if (meterRslt != null && iperlHeads[i] != null)
|
||||
if (meterRslt != null && genesisHeads[i] != null)
|
||||
{
|
||||
meterRslt.WaterMeter.SerialNr = iperlHeads[i].SerialNr;
|
||||
meterRslt.Passed = (!iperlHeads[i].CommFailed && !iperlHeads[i].Disabled);
|
||||
meterRslt.WaterMeter.SerialNr = genesisHeads[i].SerialNr;
|
||||
meterRslt.Passed = (!genesisHeads[i].CommFailed && !genesisHeads[i].Disabled);
|
||||
meterRslt.TestDone = true;
|
||||
}
|
||||
}
|
||||
@ -2687,7 +2695,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
||||
MenuItem menuItem = (MenuItem)sender;
|
||||
activityLabel.Text = menuItem.Text;
|
||||
List<Task> tasks = new List<Task>();
|
||||
foreach (var iHead in ProcessData.IperlHeads)
|
||||
foreach (var iHead in ProcessData.SmartHeadsUni)
|
||||
{
|
||||
if (!checkBoxes[iHead.Position - 1].Checked)
|
||||
{
|
||||
@ -2698,27 +2706,30 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
||||
Application.DoEvents(); // Refresh UI
|
||||
tasks.Add(Task.Run(async () =>
|
||||
{
|
||||
string result = await ProcessTask(iHead, menuItem.Tag);
|
||||
this.Invoke((Action)(() =>
|
||||
{
|
||||
messages[iHead.Position - 1].Text = result;
|
||||
Application.DoEvents(); // Refresh UI
|
||||
}));
|
||||
|
||||
if (iHead is GenesisSmartReader genesisHead)
|
||||
{
|
||||
string result = await ProcessTask(genesisHead, menuItem.Tag);
|
||||
this.Invoke((Action)(() =>
|
||||
{
|
||||
messages[iHead.Position - 1].Text = result;
|
||||
Application.DoEvents(); // Refresh UI
|
||||
}));
|
||||
}
|
||||
|
||||
}));
|
||||
|
||||
}
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
|
||||
private async Task<string> ProcessTask(IperlHead iHead, object tag)
|
||||
private async Task<string> ProcessTask(GenesisSmartReader iHead, object tag)
|
||||
{
|
||||
string txt = "";
|
||||
bool success = false;
|
||||
switch (tag)
|
||||
{
|
||||
case "ReadPCB":
|
||||
txt = iHead.OptoHeadTest.ReadRequest_PCB();
|
||||
txt = iHead.OptoHeadTest.ReadRequest_PCB();
|
||||
break;
|
||||
case "WriteRequestPort_u8_Customer_Text":
|
||||
txt = "Not Supported NOW!";//OpticalHeadTest.WriteRequestPort_u8_Customer_Text(iHead);
|
||||
@ -2733,7 +2744,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
|
||||
txt = iHead.OptoHeadTest.SetActiveMode(ref success);
|
||||
break;
|
||||
case "TurnOffRadio":
|
||||
txt = "Not Supported NOW!";//OpticalHeadTest.TurnOffRadio(iHead);
|
||||
txt = iHead.OptoHeadTest.TurnOffRadio(ref success);
|
||||
break;
|
||||
case "SetProductionMode":
|
||||
txt = "Not Supported NOW!";//OpticalHeadTest.SetProductionMode(iHead);
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user