Refactor RadioService for improved asynchronous handling, consolidate unused namespaces, update OptoHeadTest logic, and increment assembly version to 3.9.3085.1.
This commit is contained in:
parent
f4b8e42f59
commit
b4c0384b57
@ -1,23 +1,17 @@
|
||||
using GenesisCordonelInterface.Core.Threading;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Xylem.Common.Hardware.Interfaces.Ports.PortCore;
|
||||
using Xylem.Common.Hardware.Interfaces.Ports.PortCore.EventArguments;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers;
|
||||
using Xylem.Common.Hardware.WaterMeter.WaterMeterCore;
|
||||
using Xylem.Common.Hardware.WaterMeter.WaterMeterRegisters;
|
||||
using static GenesisCordonelInterface.API.PublicModels;
|
||||
using static Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore.GenesisMeter;
|
||||
using static Xylem.Common.Hardware.WaterMeter.Genesis.Registers.Register;
|
||||
|
||||
namespace GenesisCordonelInterface.API
|
||||
{
|
||||
|
||||
@ -1,12 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Xylem.Common.Hardware.Interfaces.Ports.PortCore;
|
||||
using static GenesisCordonelInterface.API.InterfaceOutsideToGCI;
|
||||
using static Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore.GenesisMeter;
|
||||
|
||||
namespace GenesisCordonelInterface.API
|
||||
{
|
||||
|
||||
@ -4,12 +4,9 @@ using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Xylem.Common.CommonCore.Consts;
|
||||
using Xylem.Common.Hardware.Interfaces.Ports.PortCore;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisConfig;
|
||||
using Xylem.Common.Hardware.WaterMeter.WaterMeterCore;
|
||||
using Xylem.Common.Ui.CordonelPreadjustmentUi;
|
||||
using CordonelPreadjustmentUi;
|
||||
|
||||
@ -14,12 +14,11 @@ using Xylem.Common.CommonCore.Consts;
|
||||
using Xylem.Common.Hardware.Interfaces.Ports.PortCore;
|
||||
using Xylem.Common.Hardware.Interfaces.Ports.PortCore.EventArguments;
|
||||
using Xylem.Common.Hardware.Interfaces.Ports.SerialPorts;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisConfig;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore;
|
||||
using Xylem.Common.Hardware.WaterMeter.WaterMeterCore;
|
||||
using Xylem.Common.Utils.Logging;
|
||||
using NLog;
|
||||
using GenesisCordonelInterface.API;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisConfig;
|
||||
|
||||
namespace GenesisCordonelInterface.UI.LaatzenAPI_GenesisToolBox
|
||||
{
|
||||
|
||||
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("3.9.3079.1")]
|
||||
[assembly: AssemblyFileVersion("3.9.3079.1")]
|
||||
[assembly: AssemblyVersion("3.9.3085.1")]
|
||||
[assembly: AssemblyFileVersion("3.9.3085.1")]
|
||||
|
||||
@ -522,6 +522,8 @@ namespace TBF.Rig.BridgeComponents.GciBridge
|
||||
int slotId,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
log.InfoFormat("{0}: DisconnectAsync({1}) invoked.", Name, slotId);
|
||||
|
||||
EnsureExternalInterface();
|
||||
|
||||
if (slotId <= 0)
|
||||
|
||||
@ -46,7 +46,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
|
||||
StreamingPort = new PublicModels.GciPortConfig
|
||||
{
|
||||
PortName = $"COM{genesidHead.OptoComPortNr}",
|
||||
PortName = "NA", //$"COM{genesidHead.OptoComPortNr}",
|
||||
Type = simulation ? "SIMULATE" : string.Empty
|
||||
}
|
||||
};
|
||||
@ -158,7 +158,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
RadioService headService = new RadioService(gciBridge);
|
||||
|
||||
|
||||
ReadPcbResult pcbResult = await headService.ReadRequest_PCBAsync(genesisHead, isConnected);
|
||||
ReadPcbResult pcbResult = await headService.ReadRequest_PCBAsync(genesisHead);
|
||||
|
||||
if (pcbResult == null)
|
||||
{
|
||||
@ -170,6 +170,16 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
|
||||
string serialNo = pcbResult.PcbId;
|
||||
log.Info( $"PCB Number: {serialNo} on COM{genesisHead.RfidComPortNr} SlotNr: {genesisHead.GetSlotNr}");
|
||||
|
||||
if (pcbResult.IsValidPcb)
|
||||
{
|
||||
genesisHead.SerialNr = pcbResult.PcbId;
|
||||
if (genesisHead.ConfigStruct != null)
|
||||
{
|
||||
genesisHead.ConfigStruct.PCBNumberString = pcbResult.PcbId;
|
||||
}
|
||||
log.Info( $"PCB STORED TO HEAD Number: {serialNo} on COM{genesisHead.RfidComPortNr} SlotNr: {genesisHead.GetSlotNr} is valid");
|
||||
}
|
||||
|
||||
return serialNo;
|
||||
}
|
||||
@ -206,7 +216,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
{
|
||||
try
|
||||
{
|
||||
log.Debug("ReadRequest_PCB called for iHead: " + genesisHead);
|
||||
log.Debug("SetTestMode_Async called for iHead: " + genesisHead);
|
||||
|
||||
if (genesisHead == null)
|
||||
return false;
|
||||
@ -224,40 +234,48 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
|
||||
if (genesisHead.DebugLevel == DebugMode.Simulate)
|
||||
{
|
||||
log.Debug("ReadRequest_PCB() - Simulated response");
|
||||
log.Debug("SetTestMode_Async() - Simulated response");
|
||||
return true;
|
||||
}
|
||||
|
||||
GciBridge gciBridge = genesisHead.CommInterfaceBridge;
|
||||
|
||||
log.Debug("ReadRequest_PCB() - GciBridge created");
|
||||
log.Debug("SetTestMode_Async() - GciBridge created");
|
||||
|
||||
gciBridge.GciBridgeCfg.EnableExternalAccess = true;
|
||||
gciBridge.GciBridgeCfg.EnableGuiAccess = false;
|
||||
gciBridge.Initialize();
|
||||
|
||||
log.Debug("ReadRequest_PCB() - GciBridge initialized");
|
||||
log.Debug("SetTestMode_Async() - GciBridge initialized");
|
||||
|
||||
RadioService headService = new RadioService(gciBridge);
|
||||
|
||||
|
||||
var ledModeAsync = await headService.SetLedMode_Async(genesisHead,LedState.active, isConnected);
|
||||
var ledModeAsync = await headService.SetLedMode_Async(genesisHead, LedState.active, isConnected);
|
||||
|
||||
if (!ledModeAsync)
|
||||
{
|
||||
log.Info( $"FAILED - SET LED MODE ACTIVE on COM{genesisHead.RfidComPortNr} SlotNr: {genesisHead.GetSlotNr}");
|
||||
log.Info(
|
||||
$"FAILED - SET LED MODE ACTIVE on COM{genesisHead.RfidComPortNr} SlotNr: {genesisHead.GetSlotNr}");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
isConnected = true;
|
||||
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
await headService.Disconnect_Async(genesisHead);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.Error("SetTestMode_Async() - DISCONNECT Exception:", ex);
|
||||
}
|
||||
|
||||
|
||||
return ledModeAsync;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.Error("ReadRequest_PCBAsync() - Exception:", ex);
|
||||
return ex.Message;
|
||||
log.Error("SetTestMode_Async() - Exception:", ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -274,11 +292,11 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
}
|
||||
|
||||
|
||||
public async Task<bool> SetActiveMode_Async()
|
||||
public async Task<bool> SetActiveMode_Async()
|
||||
{
|
||||
try
|
||||
{
|
||||
log.Debug("ReadRequest_PCB called for iHead: " + genesisHead);
|
||||
log.Debug("SetActiveMode_Async called for iHead: " + genesisHead);
|
||||
|
||||
if (genesisHead == null)
|
||||
return false;
|
||||
@ -296,39 +314,47 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
|
||||
if (genesisHead.DebugLevel == DebugMode.Simulate)
|
||||
{
|
||||
log.Debug("ReadRequest_PCB() - Simulated response");
|
||||
log.Debug("SetActiveMode_Async() - Simulated response");
|
||||
return true;
|
||||
}
|
||||
|
||||
GciBridge gciBridge = genesisHead.CommInterfaceBridge;
|
||||
|
||||
log.Debug("ReadRequest_PCB() - GciBridge created");
|
||||
log.Debug("SetActiveMode_Async() - GciBridge created");
|
||||
|
||||
gciBridge.GciBridgeCfg.EnableExternalAccess = true;
|
||||
gciBridge.GciBridgeCfg.EnableGuiAccess = false;
|
||||
gciBridge.Initialize();
|
||||
|
||||
log.Debug("ReadRequest_PCB() - GciBridge initialized");
|
||||
log.Debug("SetActiveMode_Async() - GciBridge initialized");
|
||||
|
||||
RadioService headService = new RadioService(gciBridge);
|
||||
|
||||
|
||||
var ledModeAsync = await headService.SetLedMode_Async(genesisHead,LedState.active, isConnected);
|
||||
var ledModeAsync = await headService.SetLedMode_Async(genesisHead, LedState.inactive, isConnected);
|
||||
|
||||
if (!ledModeAsync)
|
||||
{
|
||||
log.Info( $"FAILED - SET LED MODE ACTIVE on COM{genesisHead.RfidComPortNr} SlotNr: {genesisHead.GetSlotNr}");
|
||||
log.Info(
|
||||
$"FAILED - SET LED MODE INACTIVE on COM{genesisHead.RfidComPortNr} SlotNr: {genesisHead.GetSlotNr}");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
isConnected = true;
|
||||
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
await headService.Disconnect_Async(genesisHead);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.Error("SetActiveMode_Async() - DISCONNECT Exception:", ex);
|
||||
}
|
||||
|
||||
|
||||
return ledModeAsync;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.Error("ReadRequest_PCBAsync() - Exception:", ex);
|
||||
log.Error("SetActiveMode_Async() - Exception:", ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -427,19 +453,17 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
return "-OK Simulated response-";
|
||||
}
|
||||
|
||||
// try
|
||||
// {
|
||||
// bool activeMode = SetActiveMode();
|
||||
// isTestModeSuccessful = activeMode;
|
||||
// return activeMode ? "Set Active Mode - OK" : "Set Active Mode - FAILED";
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// log.Error("SetActiveMode() - Exception:" + ex.StackTrace);
|
||||
// return "Set Active Mode - Exception";
|
||||
// }
|
||||
|
||||
return "Set Active Mode - No Implemented Exception";
|
||||
try
|
||||
{
|
||||
bool testMode = SetActiveMode();
|
||||
isTestModeSuccessful = testMode;
|
||||
return testMode ? "Set Active Mode - OK" : "Set Active Mode - FAILED";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.Error("SetActiveMode() - Exception:" + ex.StackTrace);
|
||||
return "Set Active Mode - Exception";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -480,7 +504,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
|
||||
try
|
||||
{
|
||||
log.Debug("ReadRequest_PCB called for iHead: " + genesisHead);
|
||||
log.Debug("SetActivityMode_Active called for iHead: " + genesisHead);
|
||||
|
||||
if (genesisHead == null)
|
||||
return false;
|
||||
@ -498,40 +522,36 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
|
||||
if (genesisHead.DebugLevel == DebugMode.Simulate)
|
||||
{
|
||||
log.Debug("ReadRequest_PCB() - Simulated response");
|
||||
log.Debug("SetActivityMode_Active() - Simulated response");
|
||||
return true;
|
||||
}
|
||||
|
||||
GciBridge gciBridge = genesisHead.CommInterfaceBridge;
|
||||
|
||||
log.Debug("ReadRequest_PCB() - GciBridge created");
|
||||
log.Debug("SetActivityMode_Active() - GciBridge created");
|
||||
|
||||
gciBridge.GciBridgeCfg.EnableExternalAccess = true;
|
||||
gciBridge.GciBridgeCfg.EnableGuiAccess = false;
|
||||
|
||||
gciBridge.Initialize();
|
||||
|
||||
log.Debug("ReadRequest_PCB() - GciBridge initialized");
|
||||
log.Debug("SetActivityMode_Active() - GciBridge initialized");
|
||||
|
||||
RadioService headService = new RadioService(gciBridge);
|
||||
ReadPcbResult pcbResult = await headService.SetActivityMode_Active(genesisHead, isConnected);
|
||||
var active = await headService.SetActivityMode_Active(genesisHead, isConnected);
|
||||
|
||||
if (pcbResult == null)
|
||||
if (!active)
|
||||
{
|
||||
log.Info( $"PCB Number NOT found on COM{genesisHead.RfidComPortNr} SlotNr: {genesisHead.GetSlotNr}");
|
||||
log.Info( $"SetActivityMode_Active not set on COM{genesisHead.RfidComPortNr} SlotNr: {genesisHead.GetSlotNr}");
|
||||
return false;
|
||||
}
|
||||
|
||||
isConnected = pcbResult.IsConnected;
|
||||
|
||||
string serialNo = pcbResult.PcbId;
|
||||
log.Info( $"PCB Number: {serialNo} on COM{genesisHead.RfidComPortNr} SlotNr: {genesisHead.GetSlotNr}");
|
||||
|
||||
log.Info( $"SetActivityMode_Active set on COM{genesisHead.RfidComPortNr} SlotNr: {genesisHead.GetSlotNr}");
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.Error("ReadRequest_PCBAsync() - Exception:", ex);
|
||||
log.Error("SetActivityMode_Active() - Exception:", ex);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -1,15 +1,11 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using GenesisCordonelInterface.API;
|
||||
using log4net;
|
||||
using TBF.Rig.BridgeComponents.GciBridge;
|
||||
using TBF.Rig.RegisterReaders.GenesisRegReader.common;
|
||||
using TBF.Rig.RegisterReaders.GenesisRegReader.communication.common;
|
||||
using TBF.Rig.RegisterReaders.GenesisRegReader.implementations;
|
||||
using TBF.Rig.TestMethods.iPerlCommunication.communication.C4.diagnosticLed;
|
||||
using TBF.Rig.TestMethods.iPerlCommunication.communication.C4.protocolCommons;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore;
|
||||
using PublicModels = TBF.Rig.BridgeComponents.GciBridge.Interfaces.PublicModels;
|
||||
|
||||
|
||||
@ -18,6 +14,8 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
public class ReadPcbResult
|
||||
{
|
||||
public bool IsConnected { get; set; }
|
||||
|
||||
public bool IsLoggedOn { get; set; }
|
||||
|
||||
public bool IsValidPcb { get; set; }
|
||||
|
||||
@ -45,30 +43,40 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
|
||||
private async Task<ReadPcbResult> EnsureConnectedAsync(
|
||||
GenesisSmartReader head,
|
||||
bool isConnected,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
log.Debug("EnsureConnectedAsync called for iHead: " + head);
|
||||
if (head?.CommInterfaceBridge == null)
|
||||
{
|
||||
return new ReadPcbResult
|
||||
{
|
||||
IsConnected = false,
|
||||
IsLoggedOn = false,
|
||||
IsValidPcb = false,
|
||||
Message = "CommInterfaceBridge is null."
|
||||
};
|
||||
}
|
||||
|
||||
if (isConnected)
|
||||
var slotInfo = await _bridge.GetSlotAsync(head.GetSlotNr);
|
||||
if (slotInfo == null || !slotInfo.Success)
|
||||
{
|
||||
//just no definet yet ?
|
||||
log.Debug("EnsureConnectedAsync() - SlotInfo is null.");
|
||||
}
|
||||
else if (slotInfo.IsConnected)
|
||||
{
|
||||
log.Debug("EnsureConnectedAsync() - Slot: " + slotInfo);
|
||||
return new ReadPcbResult
|
||||
{
|
||||
IsConnected = true,
|
||||
IsLoggedOn = slotInfo.IsLoggedOn,
|
||||
IsValidPcb = false,
|
||||
PcbId = slotInfo.PcbId,
|
||||
Message = "Already connected."
|
||||
};
|
||||
}
|
||||
|
||||
log.Debug("Connecting...");
|
||||
log.Debug("EnsureConnectedAsync() - Connecting...");
|
||||
|
||||
var connectTask = head.CommInterfaceBridge.ConnectAsync(head.GetSlotNr, token);
|
||||
var timeoutTask = Task.Delay(TimeSpan.FromMinutes(1), token);
|
||||
@ -80,6 +88,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
return new ReadPcbResult
|
||||
{
|
||||
IsConnected = false,
|
||||
IsLoggedOn = false,
|
||||
IsValidPcb = false,
|
||||
Message = "Connect timeout."
|
||||
};
|
||||
@ -87,11 +96,12 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
|
||||
var result = await connectTask;
|
||||
|
||||
if (result == null )//|| !result.Success)
|
||||
if (result == null || !result.Success)
|
||||
{
|
||||
return new ReadPcbResult
|
||||
{
|
||||
IsConnected = false,
|
||||
IsLoggedOn = false,
|
||||
IsValidPcb = false,
|
||||
Message = result == null ? "Connect result is null." : "Connect failed."
|
||||
};
|
||||
@ -99,7 +109,8 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
|
||||
return new ReadPcbResult
|
||||
{
|
||||
IsConnected = true,
|
||||
IsConnected = result.IsConnected,
|
||||
IsLoggedOn = false,
|
||||
IsValidPcb = false,
|
||||
Message = "Connected OK."
|
||||
};
|
||||
@ -129,9 +140,15 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
CancellationToken token = default)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(txtPassword))
|
||||
throw new Exception("PASSWORD is empty.");
|
||||
throw new Exception("LoginByPasswordAsync() - PASSWORD is empty.");
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
log.Debug("LoginByPasswordAsync( Slot: {0}) - 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}) - START LOGIN");
|
||||
|
||||
GenesisCordonelInterface.API.PublicModels.GciLoginResult result = await _bridge.LoginAsync(slotId, token);
|
||||
|
||||
@ -140,7 +157,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<ReadPcbResult> ReadRequest_PCBAsync( GenesisSmartReader head, bool isConnected)
|
||||
public async Task<ReadPcbResult> ReadRequest_PCBAsync( GenesisSmartReader head)
|
||||
{
|
||||
log.Debug("ReadRequest_PCB called for iHead: " + head);
|
||||
|
||||
@ -158,15 +175,13 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
{
|
||||
// CONNECT ONLY IF NEEDED
|
||||
var connectResult =
|
||||
await EnsureConnectedAsync(head, isConnected);
|
||||
await EnsureConnectedAsync(head);
|
||||
|
||||
if (!connectResult.IsConnected)
|
||||
{
|
||||
return connectResult;
|
||||
}
|
||||
|
||||
isConnected = true;
|
||||
|
||||
log.Debug($"ReadRequest_PCB() connect - {connectResult.Message}");
|
||||
|
||||
|
||||
@ -238,7 +253,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
{
|
||||
return new ReadPcbResult
|
||||
{
|
||||
IsConnected = isConnected,
|
||||
IsConnected = connectResult.IsConnected,
|
||||
IsValidPcb = false,
|
||||
PcbId = null,
|
||||
Message = "Valid PCB not found."
|
||||
@ -252,7 +267,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
|
||||
return new ReadPcbResult
|
||||
{
|
||||
IsConnected = isConnected,
|
||||
IsConnected = connectResult.IsConnected,
|
||||
IsValidPcb = true,
|
||||
PcbId = validPcbId,
|
||||
Message = "PCB OK"
|
||||
@ -264,7 +279,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
|
||||
return new ReadPcbResult
|
||||
{
|
||||
IsConnected = isConnected,
|
||||
IsConnected = false,
|
||||
IsValidPcb = false,
|
||||
PcbId = null,
|
||||
Message = ex.Message
|
||||
@ -286,26 +301,50 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
{
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
// GET SLOT - CHECK CONNECTION, LOGGING
|
||||
//TODO BUMI doplnit !!!!!!!!!!!!!
|
||||
|
||||
var connectResult = await EnsureConnectedAsync(iHead, isConnected, token);
|
||||
var connectResult = await EnsureConnectedAsync(iHead, token);
|
||||
|
||||
if (!connectResult.IsConnected)
|
||||
return false;
|
||||
log.Debug($"PrepareLoginAdnConnect_Async() connect - {connectResult.Message}");
|
||||
|
||||
//isConnected = connectResult.IsConnected;
|
||||
|
||||
log.Debug($"GetActivityStatusMode() connect - {connectResult.Message}");
|
||||
|
||||
if (connectResult.IsLoggedOn)
|
||||
return true;
|
||||
|
||||
//get stored PCB - Keystone
|
||||
log.Debug("Have we PCB stored?");
|
||||
string pcb = iHead.ConfigStruct?.PCBNumberString;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(pcb))
|
||||
return false;
|
||||
{
|
||||
pcb = connectResult.PcbId;
|
||||
if (string.IsNullOrWhiteSpace(pcb))
|
||||
{
|
||||
pcb = iHead.SerialNr;
|
||||
}
|
||||
//GET PCB FROM Meter
|
||||
if (string.IsNullOrWhiteSpace(pcb))
|
||||
{
|
||||
log.Debug("PrepareLoginAdnConnect_Async() No PCB stored. Trying to get PCB from Meter");
|
||||
var pcbResult = await ReadRequest_PCBAsync(iHead);
|
||||
if (pcbResult.IsValidPcb)
|
||||
{
|
||||
pcb = pcbResult.PcbId;
|
||||
iHead.SerialNr = pcb;
|
||||
if (iHead.ConfigStruct != null)
|
||||
{
|
||||
iHead.ConfigStruct.PCBNumberString = pcb;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.Debug( $"GetActivityStatusMode() Start Find Keystone Slot: {iHead.GetSlotNr} PCB:{iHead.SerialNr} Calib PCB:{pcb} - find keystone");
|
||||
if (string.IsNullOrWhiteSpace(pcb))
|
||||
{
|
||||
log.Debug("PrepareLoginAdnConnect_Async() No PCB stored. MISSING PCB!!!!!");
|
||||
return false;
|
||||
}
|
||||
|
||||
log.Debug( $"PrepareLoginAdnConnect_Async() Start Find Keystone Slot: {iHead.GetSlotNr} PCB:{iHead.SerialNr} Calib PCB:{pcb} - find keystone");
|
||||
|
||||
var keyStoneResult = await FindKeyStone(pcb, token);
|
||||
|
||||
@ -314,7 +353,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
|
||||
//LOGIN
|
||||
|
||||
log.Debug( $"GetActivityStatusMode() Start Login Slot: {iHead.GetSlotNr} PCB:{iHead.SerialNr} Calib PCB:{pcb} - login");
|
||||
log.Debug( $"PrepareLoginAdnConnect_Async() Start Login Slot: {iHead.GetSlotNr} PCB:{iHead.SerialNr} Calib PCB:{pcb} - login");
|
||||
GenesisCordonelInterface.API.PublicModels.GciLoginResult loginByPasswordAsync =
|
||||
await LoginByPasswordAsync(iHead.GetSlotNr, keyStoneResult.Password, token);
|
||||
|
||||
@ -323,12 +362,12 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
return false;
|
||||
}
|
||||
|
||||
log.Debug($"GetActivityStatusMode() Login OK");
|
||||
log.Debug($"PrepareLoginAdnConnect_Async() Login OK");
|
||||
return true;
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
log.Debug("GetActivityStatusMode() canceled.");
|
||||
log.Debug("PrepareLoginAdnConnect_Async() canceled.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -398,30 +437,30 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
CancellationToken token = default)
|
||||
{
|
||||
log.Debug("SetLedMode_Async called for iHead: " + iHead + " isConnected: " + isConnected);
|
||||
|
||||
log.Debug("GetActivityLedStatusMode_Async called for iHead: " + iHead + " isConnected: " + isConnected);
|
||||
|
||||
if (iHead?.CommInterfaceBridge == null)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
var loginAdnConnectAsync = await PrepareLoginAdnConnect_Async(iHead, isConnected, token);
|
||||
|
||||
|
||||
if (!loginAdnConnectAsync)
|
||||
return false;
|
||||
|
||||
//Get Activity Status
|
||||
byte valueLed = (ledMode == LedState.active) ? (byte)6 : (byte)0;
|
||||
|
||||
var registerWriteResult = await _bridge.WriteRegisterAsync(iHead.GetSlotNr,LedMode, valueLed, false, false, token);
|
||||
log.Debug($"SetLedMode_Async() Set Led Mode: {valueLed}");
|
||||
var registerWriteResult =
|
||||
await _bridge.WriteRegisterAsync(iHead.GetSlotNr, LedMode, valueLed, false, false, token);
|
||||
|
||||
if (registerWriteResult == null || !registerWriteResult.Success)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
log.Debug($"GetActivityStatusMode() Read Register OK Response: {registerWriteResult}");
|
||||
return true;
|
||||
|
||||
|
||||
log.Debug($"SetLedMode_Async() Write Register OK Response: {registerWriteResult}");
|
||||
return true;
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
@ -433,8 +472,33 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
log.Error("GetActivityLedStatusMode_Async() failed", ex);
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
log.Debug("SetLedMode_Async() - End - DO DISCONNECT");
|
||||
var gciDisconnectResult = await _bridge.DisconnectAsync(iHead.GetSlotNr);
|
||||
log.Debug($"SetLedMode_Async() Disconnect Result: {gciDisconnectResult}");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> Disconnect_Async(GenesisSmartReader iHead)
|
||||
{
|
||||
try
|
||||
{
|
||||
log.Debug("Disconnect_Async() - Start");
|
||||
var gciSlotInfo = await _bridge.GetSlotAsync(iHead.GetSlotNr);
|
||||
log.Debug($"Disconnect_Async() - Slot: {iHead.GetSlotNr} - SlotInfo: {gciSlotInfo}");
|
||||
log.Debug("Disconnect_Async() - DO DISCONNECT");
|
||||
var gciDisconnectResult = await _bridge.DisconnectAsync(iHead.GetSlotNr);
|
||||
log.Debug($"Disconnect_Async() Disconnect Result: {gciDisconnectResult}");
|
||||
|
||||
return gciDisconnectResult.Success;
|
||||
}catch(Exception ex)
|
||||
{
|
||||
log.Error("Disconnect_Async() failed", ex);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static ushort SafeIntToUShort(int value)
|
||||
{
|
||||
@ -455,7 +519,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
|
||||
if (connectResult == null || !connectResult.Success || !connectResult.IsLoggedOn)
|
||||
if (connectResult == null || !connectResult.Success || !connectResult.IsConnected)
|
||||
return string.Empty;
|
||||
|
||||
// if (!string.IsNullOrEmpty(version))
|
||||
@ -483,25 +547,29 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
{
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
var connectResult = await EnsureConnectedAsync(iHead, isConnected,token);
|
||||
var connectResult = await EnsureConnectedAsync(iHead, token);
|
||||
|
||||
if (!connectResult.IsConnected)
|
||||
return false;
|
||||
|
||||
isConnected = connectResult.IsConnected;
|
||||
|
||||
log.Debug($"GetActivityStatusMode() connect - {connectResult.Message}");
|
||||
log.Debug($"SetActivityMode_Active() connect - {connectResult.Message}");
|
||||
|
||||
//Set LED to state 4
|
||||
// string version = _bridge?.GciExternalInterface?.GetPcbId(iHead.GetSlotNr);
|
||||
// if (!string.IsNullOrEmpty(version))
|
||||
// {
|
||||
// if (iHead.ConfigStruct != null) // store mechanism
|
||||
// {
|
||||
// iHead.ConfigStruct.Version = version;
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
//Set LED to state 4
|
||||
// string version = _bridge?.GciExternalInterface?.GetPcbId(iHead.GetSlotNr);
|
||||
// if (!string.IsNullOrEmpty(version))
|
||||
// {
|
||||
// if (iHead.ConfigStruct != null) // store mechanism
|
||||
// {
|
||||
// iHead.ConfigStruct.Version = version;
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
}catch(OperationCanceledException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -516,7 +584,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
|
||||
if (connectResult == null || !connectResult.Success || !connectResult.IsLoggedOn)
|
||||
if (connectResult == null || !connectResult.Success || !connectResult.IsConnected)
|
||||
return false;
|
||||
|
||||
//Set Activity State Idle
|
||||
@ -543,7 +611,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
|
||||
if (connectResult == null || !connectResult.Success || !connectResult.IsLoggedOn)
|
||||
if (connectResult == null || !connectResult.Success || !connectResult.IsConnected)
|
||||
return false;
|
||||
|
||||
//Set LED to state 4
|
||||
@ -575,7 +643,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
|
||||
if (connectResult == null || !connectResult.Success || !connectResult.IsLoggedOn)
|
||||
if (connectResult == null || !connectResult.Success || !connectResult.IsConnected)
|
||||
return false;
|
||||
|
||||
//Set LED to state 1
|
||||
@ -602,7 +670,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
|
||||
if (connectResult == null || !connectResult.Success || !connectResult.IsLoggedOn)
|
||||
if (connectResult == null || !connectResult.Success || !connectResult.IsConnected)
|
||||
return string.Empty;
|
||||
|
||||
// string version = _bridge?.GciExternalInterface?.GetPcbId(iperlHead.GetSlotNr);
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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