polishing - work now

This commit is contained in:
2025-10-18 09:59:07 +02:00
parent 3bc9e731e8
commit a2c564d789
67 changed files with 2294 additions and 1647 deletions
@@ -17,13 +17,14 @@ using System.Linq;
using System.Xml;
using System.Xml.Linq; // This line is correct and does not need to be changed.
using System.Windows;
using TBF.Rig.Uni.SharedDialogs.SmartMetersCommunication.common;
namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
{
/// <summary>
/// This component = instance of this class is a placeholder for a combined main watermeter
/// </summary>
public class IperlHead : ComponentBase, IDevice,IRegReaderDatastream, ISessionDataMngmnt, IOperation
public class IperlHead : ComponentBase, IDevice,IRegReaderDatastream, ISessionDataMngmnt, IOperation, IntIPerlReader
{
private static readonly ILog log = LogManager.GetLogger(typeof(IperlHead));
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
@@ -42,7 +43,10 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
readonly IperlHeadCfg iperlHeadCfg;
RegisterReaders.CommonRR.CommunicationInterface IntIPerlReader.CommInterface => _commInterface;
public int RfidComPortNr { get { return iperlHeadCfg.RfidComPortNr; } }
public bool CommFailed { get; set; }
public int OptoComPortNr { get { return iperlHeadCfg.OptoComPortNr; } }
public int MuxBoardNrOrGroup14 { get { return iperlHeadCfg.MuxBoardNr; } }
public int Group { get { return iperlHeadCfg.Group; } }
@@ -87,7 +91,6 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
}
public bool Disabled;
public bool CommFailed;
public int ResultCode;
@@ -930,6 +933,11 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
dataStreamState = DataStreamState.ProcessAndSave;
}
public void SetCommunicationInterface(RegisterReaders.CommonRR.CommunicationInterface commInterface)
{
throw new NotImplementedException();
}
/// <summary>
/// Returns true when processing and saving datastream data is in progress
/// </summary>
@@ -938,6 +946,11 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
return dataStreamState == DataStreamState.ProcessAndSave;
}
void IntIPerlReader.SetRfidInterface()
{
SetRfidInterface();
}
/// <summary>
/// Stop processing and saving datastream data
/// </summary>
@@ -953,8 +966,9 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
bool synchronized;
bool synchronized2;
string partOfTelegram;
private RegisterReaders.CommonRR.CommunicationInterface _commInterface;
/// <summary>
/// <summary>
/// Reads opto-datastream via serial port. Invoked from RunDeviceBefore()
///
/// Telegram description:
@@ -1063,6 +1077,11 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
}
}
void IntIPerlReader.ResetNfcInterface(bool? nfc_on)
{
ResetNfcInterface(nfc_on);
}
public string ReadOptoData()
{
if (optoSerialPort is null) return "";
@@ -1080,6 +1099,11 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
return received;
}
void IntIPerlReader.SetNfcInterface()
{
SetNfcInterface();
}
void OptoTelegramReceived(int currentIx, bool async, Int64 volumeRawExt, Int64 timestampRawExt)
{
@@ -3,6 +3,7 @@ using System.Threading;
using System.Web.UI.WebControls;
using System.Windows.Forms;
using TBF.Rig.Sequences;
using TBF.Rig.Uni.SharedDialogs.SmartMetersCommunication;
namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
{
@@ -21,7 +22,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
InitializeComponent();
if (config == null) return;
iPerlCommunicationForm.cfg = new TestMethodCfg(null); // default values for iPerlCommunication
SmartCommunicationForm.TestMethodCfg = new TestMethodCfg_IPerl(null); // default values for iPerlCommunication
foreach(var head in ProcessData.IperlHeads)
{
@@ -12,9 +12,9 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
internal class NfcServices
{
protected static readonly ILog rfidDataLogger = LogManager.GetLogger("RfidData");
internal static int ReadRequest(TestMethodCfg cfg, IperlHead iperlHead, MCI_Protocol.StructName structName, int offset, int length, out byte[] buffer)
internal static int ReadRequest(TestMethodCfg_IPerl cfgIPerl, IperlHead iperlHead, MCI_Protocol.StructName structName, int offset, int length, out byte[] buffer)
{
for (int i = 0; i < cfg.MaxCommRetries; i++)
for (int i = 0; i < cfgIPerl.MaxCommRetries; i++)
{
NfcDataHandler _nfcDataHandler = new NfcDataHandler();
@@ -26,9 +26,9 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
try
{
rfidDataLogger.Info($"NFC COM{iperlHead.RfidComPortNr} ReadRequest : {structName}, {offset}, {length}");
OpenConnection(_nfcDataHandler, cfg, iperlHead);
OpenConnection(_nfcDataHandler, cfgIPerl, iperlHead);
buffer = MciRead(_nfcDataHandler, cfg, structName, (ushort)offset, length);
buffer = MciRead(_nfcDataHandler, cfgIPerl, structName, (ushort)offset, length);
_nfcDataHandler.RFProtocolOFF(); // turn off rf antenna due to possible interference
CloseComPort(_nfcDataHandler);
@@ -44,7 +44,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
}
catch (RfidValidationException)
{
Thread.Sleep(cfg.WaitTimeAfterFailure);
Thread.Sleep(cfgIPerl.WaitTimeAfterFailure);
}
catch (Exception ex)
{
@@ -57,7 +57,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
return 3;
}
internal static int WriteRequest(TestMethodCfg cfg, IperlHead iperlHead, MCI_Protocol.StructName structName, int offset, int length, byte[] buffer)
internal static int WriteRequest(TestMethodCfg_IPerl cfgIPerl, IperlHead iperlHead, MCI_Protocol.StructName structName, int offset, int length, byte[] buffer)
{
NfcDataHandler _nfcDataHandler = new NfcDataHandler();
MessageEventHandlers(_nfcDataHandler);
@@ -68,9 +68,9 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
try
{
rfidDataLogger.Info($"NFC COM{iperlHead.RfidComPortNr} WriteRequest : {structName}, {offset}, {length}, {ByteArrayToHexString(buffer)}");
OpenConnection(_nfcDataHandler, cfg, iperlHead);
OpenConnection(_nfcDataHandler, cfgIPerl, iperlHead);
MciWrite(_nfcDataHandler, cfg, structName, (ushort)offset, length, buffer);
MciWrite(_nfcDataHandler, cfgIPerl, structName, (ushort)offset, length, buffer);
_nfcDataHandler.RFProtocolOFF(); // turn off rf antenna due to possible interference
CloseComPort(_nfcDataHandler);
@@ -83,14 +83,14 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
}
}
private static void OpenConnection(NfcDataHandler nfcDataHandler, TestMethodCfg cfg, IperlHead iperlHead)
private static void OpenConnection(NfcDataHandler nfcDataHandler, TestMethodCfg_IPerl cfgIPerl, IperlHead iperlHead)
{
string comPort = $"COM{iperlHead.RfidComPortNr}";
int retryCount = 0 ;
Open:
nfcDataHandler.Close();
Thread.Sleep(100);
if (nfcDataHandler.OpenConnection(comPort, cfg.BaudRate, cfg.DataBits, cfg.ParityBit, cfg.StopBits))
if (nfcDataHandler.OpenConnection(comPort, cfgIPerl.BaudRate, cfgIPerl.DataBits, cfgIPerl.ParityBit, cfgIPerl.StopBits))
{
rfidDataLogger.Info($"NFC COM{iperlHead.RfidComPortNr} Port Open");
@@ -100,7 +100,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
if (!nfcDataHandler.ConnectDevice())
{
rfidDataLogger.Error($"NFC COM{iperlHead.RfidComPortNr} Error connect device.");
for (int i = 0; i < cfg.MaxCommRetries; i++)
for (int i = 0; i < cfgIPerl.MaxCommRetries; i++)
{
if (nfcDataHandler.Echo()) break;
}
@@ -110,7 +110,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
{
retryCount++;
rfidDataLogger.Error($"NFC COM{iperlHead.RfidComPortNr} Error connect reader. Reconnect comport {retryCount}");
if (retryCount < cfg.MaxCommRetries)
if (retryCount < cfgIPerl.MaxCommRetries)
{
nfcDataHandler.Close();
iperlHead.ResetNfcInterface(); // reset NFC head via optoport - switch to RFID and back to NFC interface
@@ -127,7 +127,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
nfcDataHandler.Close();
}
private static byte[] MciRead(NfcDataHandler nfcDataHandler, TestMethodCfg cfg, StructName structName, ushort offset, int length)
private static byte[] MciRead(NfcDataHandler nfcDataHandler, TestMethodCfg_IPerl cfgIPerl, StructName structName, ushort offset, int length)
{
bool isReadValues = false;
int retryCount = 0;
@@ -153,14 +153,14 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
{
rfidDataLogger.Info($"MCI Error: Unidentified");
retryCount++;
if (retryCount < cfg.MaxCommRetries)
if (retryCount < cfgIPerl.MaxCommRetries)
goto Read;
}
else
{
rfidDataLogger.Info("Last error message: " + nfcDataHandler.LastErrorMessage);
retryCount++;
if (retryCount < cfg.MaxCommRetries)
if (retryCount < cfgIPerl.MaxCommRetries)
goto Read;
}
}
@@ -168,13 +168,13 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
{
rfidDataLogger.Error("MciRead Last error message: " + ex.Message);
retryCount++;
if (retryCount < cfg.MaxCommRetries)
if (retryCount < cfgIPerl.MaxCommRetries)
goto Read;
}
return new byte[length];
}
private static void MciWrite(NfcDataHandler nfcDataHandler, TestMethodCfg cfg, MCI_Protocol.StructName structName, ushort offset, int length, byte[] payload)
private static void MciWrite(NfcDataHandler nfcDataHandler, TestMethodCfg_IPerl cfgIPerl, MCI_Protocol.StructName structName, ushort offset, int length, byte[] payload)
{
int retryCount = 0;
Write:
@@ -199,7 +199,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
{
rfidDataLogger.Error("MciWrite error message: " + ex.Message);
retryCount++;
if (retryCount < cfg.MaxCommRetries)
if (retryCount < cfgIPerl.MaxCommRetries)
goto Write;
}
}
@@ -5,24 +5,25 @@ using System;
using System.Text.RegularExpressions;
using System.Threading;
using log4net;
using TBF.Rig.Uni.SharedDialogs.SmartMetersCommunication;
namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
{
internal class RfidServices
{
protected static readonly ILog rfidDataLogger = LogManager.GetLogger("RfidData");
private static readonly ILog log = LogManager.GetLogger(typeof(iPerlCommunicationForm));
private static readonly ILog log = LogManager.GetLogger(typeof(SmartCommunicationForm));
internal static int ReadRequest(TestMethodCfg cfg, IperlHead iperlHead, MessageID messageID, int offset, int length, out byte[] buffer)
internal static int ReadRequest(TestMethodCfg_IPerl cfgIPerl, IperlHead iperlHead, MessageID messageID, int offset, int length, out byte[] buffer)
{
for (int i = 0; i < cfg.MaxCommRetries; i++)
for (int i = 0; i < cfgIPerl.MaxCommRetries; i++)
{
rfidDataLogger.Error($"{iperlHead.CommInterface} Start {i} reading: COM{iperlHead.RfidComPortNr}: ReadRequestPort ({messageID},{offset}, {length}... timeout {cfg.CommTimeout})");
rfidDataLogger.Error($"{iperlHead.CommInterface} Start {i} reading: COM{iperlHead.RfidComPortNr}: ReadRequestPort ({messageID},{offset}, {length}... timeout {cfgIPerl.CommTimeout})");
using (RfidLogic writer = new RfidLogic($"COM{iperlHead.RfidComPortNr}"))
{
try
{
byte[] response = writer.ReadRequest((byte)messageID, offset, length, cfg.CommTimeout);
byte[] response = writer.ReadRequest((byte)messageID, offset, length, cfgIPerl.CommTimeout);
string hexString = RfidHelper.ConvertByteArrayToHexString(response);
string swapHexString = RfidHelper.SwapHexcode(hexString);
string decString = RfidHelper.HexLiteral2Unsigned(RfidHelper.SwapHexcode(hexString)).ToString();
@@ -56,42 +57,42 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
if (/*RfidHelper.IsPassThrough(messageID)*/ messageID == MessageID.ASICRegisterReadTest || messageID == MessageID.RadioPassthrough)
{
rfidDataLogger.Info($"COM{iperlHead.RfidComPortNr}: ReadRequestPort ({messageID},...) {(i > 0 ? "<- Error: Invalid Pass-Through data." : "<- Info: Wait for Pass-Through data.")}");
Thread.Sleep(cfg.PassThroughWaitTime);
Thread.Sleep(cfgIPerl.PassThroughWaitTime);
}
else
{
Thread.Sleep(cfg.WaitTimeAfterFailure);
Thread.Sleep(cfgIPerl.WaitTimeAfterFailure);
}
}
catch (RfidValidationException)
{
Thread.Sleep(cfg.WaitTimeAfterFailure);
Thread.Sleep(cfgIPerl.WaitTimeAfterFailure);
}
catch (Exception ex)
{
rfidDataLogger.Error($"COM{iperlHead.RfidComPortNr}: ReadRequestPort ({messageID},...) {ex.Message}");
Thread.Sleep(cfg.WaitTimeAfterFailure);
Thread.Sleep(cfgIPerl.WaitTimeAfterFailure);
}
}
}
rfidDataLogger.Error($"{iperlHead.CommInterface} reading failed after {cfg.MaxCommRetries} retries: COM{iperlHead.RfidComPortNr}: ReadRequestPort ({messageID},...)");
log.Error($"{iperlHead.CommInterface} reading failed after {cfg.MaxCommRetries} retries: COM{iperlHead.RfidComPortNr}: ReadRequestPort ({messageID},...)");
rfidDataLogger.Error($"{iperlHead.CommInterface} reading failed after {cfgIPerl.MaxCommRetries} retries: COM{iperlHead.RfidComPortNr}: ReadRequestPort ({messageID},...)");
log.Error($"{iperlHead.CommInterface} reading failed after {cfgIPerl.MaxCommRetries} retries: COM{iperlHead.RfidComPortNr}: ReadRequestPort ({messageID},...)");
buffer = new byte[length];
return 3;
}
internal static int WriteRequest(TestMethodCfg cfg, IperlHead iperlHead, MessageID messageID, int offset, int length, byte[] buffer)
internal static int WriteRequest(TestMethodCfg_IPerl cfgIPerl, IperlHead iperlHead, MessageID messageID, int offset, int length, byte[] buffer)
{
RfidLogic writer = new RfidLogic($"COM{iperlHead.RfidComPortNr}");
string payload = RfidHelper.ConvertByteArrayToHexString(buffer);
for (var i = 0; i < cfg.MaxCommRetries; i++)
for (var i = 0; i < cfgIPerl.MaxCommRetries; i++)
{
rfidDataLogger.Error($"{iperlHead.CommInterface} Start {i} writting: COM{iperlHead.RfidComPortNr}: WriteRequest ({messageID},{offset}, {length}, {payload}... timeout {cfg.CommTimeout})");
rfidDataLogger.Error($"{iperlHead.CommInterface} Start {i} writting: COM{iperlHead.RfidComPortNr}: WriteRequest ({messageID},{offset}, {length}, {payload}... timeout {cfgIPerl.CommTimeout})");
try
{
if (writer.ClosePort()) writer.OpenPort();
writer.WriteRequest((byte)messageID, offset, length, buffer, cfg.CommTimeout, false);
writer.WriteRequest((byte)messageID, offset, length, buffer, cfgIPerl.CommTimeout, false);
writer.ClosePort();
rfidDataLogger.InfoFormat($"{iperlHead.Name}({iperlHead.SerialNr},COM{iperlHead.RfidComPortNr}): WriteRequestPort({messageID}, {offset}, {length}, {payload})");
return 0;
@@ -105,7 +106,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
else
{
rfidDataLogger.Error($"COM{iperlHead.RfidComPortNr}: Error: {ex.Message}");
Thread.Sleep(cfg.WaitTimeAfterFailure);
Thread.Sleep(cfgIPerl.WaitTimeAfterFailure);
if (i > 1)
{
rfidDataLogger.Error($"COM{iperlHead.RfidComPortNr}: Reopen the com port.");
@@ -115,8 +116,8 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
}
}
writer.ClosePort();
rfidDataLogger.Error($"RFID writing failed after {cfg.MaxCommRetries} retries: COM{iperlHead.RfidComPortNr}: WriteRequestPort ({messageID},...) {System.Text.Encoding.UTF8.GetString(buffer)}");
log.Error($"RFID writing failed after {cfg.MaxCommRetries} retries: COM{iperlHead.RfidComPortNr}: WriteRequestPort ({messageID},...) {System.Text.Encoding.UTF8.GetString(buffer)}");
rfidDataLogger.Error($"RFID writing failed after {cfgIPerl.MaxCommRetries} retries: COM{iperlHead.RfidComPortNr}: WriteRequestPort ({messageID},...) {System.Text.Encoding.UTF8.GetString(buffer)}");
log.Error($"RFID writing failed after {cfgIPerl.MaxCommRetries} retries: COM{iperlHead.RfidComPortNr}: WriteRequestPort ({messageID},...) {System.Text.Encoding.UTF8.GetString(buffer)}");
return 2;
}
}
@@ -7,7 +7,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
{
const int Q2CorrFactorsAddr = 0x1878;
internal static int ReadRequest(TestMethodCfg cfg, IperlHead iperlHead, MessageID messageID, int offset, int length, out byte[] buffer)
internal static int ReadRequest(TestMethodCfg_IPerl cfgIPerl, IperlHead iperlHead, MessageID messageID, int offset, int length, out byte[] buffer)
{
byte[] configurationBuffer = new byte[ConfigStruct.Length] { 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 160, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
byte[] calibrationBuffer = new byte[CalibrationStructV4.Length] { 3, 0, 150, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 0, 0, 150, 10 };
@@ -34,7 +34,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
return iperlHead.Name.Equals("iPerl13") ? 2 : 0; /// Simulates an error on position 13
}
internal static int WriteRequest(TestMethodCfg cfg, IperlHead iperlHead, MessageID messageID, int offset, int length, byte[] buffer)
internal static int WriteRequest(TestMethodCfg_IPerl cfgIPerl, IperlHead iperlHead, MessageID messageID, int offset, int length, byte[] buffer)
{
return 0;
}