diff --git a/TBF/Rig/TestMethods/iPerlCommunication/OpticalHeadTest.cs b/TBF/Rig/TestMethods/iPerlCommunication/OpticalHeadTest.cs index 2f23a84e4..35fef0ecd 100644 --- a/TBF/Rig/TestMethods/iPerlCommunication/OpticalHeadTest.cs +++ b/TBF/Rig/TestMethods/iPerlCommunication/OpticalHeadTest.cs @@ -1,4 +1,5 @@ -using Sensus.iPerl.RfidCom.Helper; +using log4net; +using Sensus.iPerl.RfidCom.Helper; using Sensus.iPerl.RfidCom.Services; using Sensus.iPerl.RfidCom.Structures; using System; @@ -9,6 +10,8 @@ namespace TBF.Rig.TestMethods.iPerlCommunication { internal class OpticalHeadTest { + protected static readonly ILog rfidDataLogger = LogManager.GetLogger("RfidData"); + internal static string OpenSealing(IperlHead iHead) { if (RfidCommands.OpenSealing($"COM{iHead.RfidComPortNr}")) return "OK"; @@ -25,6 +28,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication { return RfidHelper.HexLiteral2Unsigned(RfidHelper.SwapHexcode(BitConverter.ToString(pcb).Replace("-", string.Empty))).ToString(); } + rfidDataLogger.Error($"COM{iHead.RfidComPortNr}: ReadRequest_PCB ({MessageID.Configuration},16,5...) <- Error: {readRetVal}"); return "Error"; } catch (Exception ex) diff --git a/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs b/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs index 053420190..97947fef1 100644 --- a/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs +++ b/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs @@ -26,6 +26,7 @@ using System.Text.RegularExpressions; using Sensus.iPerl.RfidCom.Services; using System.Threading.Tasks; using Sensus.iPerl.RfidCom.Structures; +using Sensus.iPerl.RfidCom.Model.Enums; namespace TBF.Rig.TestMethods.iPerlCommunication { @@ -248,12 +249,19 @@ namespace TBF.Rig.TestMethods.iPerlCommunication } catch (Exception ex) { - rfidDataLogger.Error($"COM{iperlHead.RfidComPortNr}: Error: {ex.Message}"); - Thread.Sleep(cfg.WaitTimeAfterFailure); - if (i > 1) + if (messageID == MessageID.RadioPassthrough || messageID == MessageID.ASICRegisterReadTest) { - rfidDataLogger.Error($"COM{iperlHead.RfidComPortNr}: Reopen the com port."); - writer.ClosePort(); + Thread.Sleep(1500); + } + else + { + rfidDataLogger.Error($"COM{iperlHead.RfidComPortNr}: Error: {ex.Message}"); + Thread.Sleep(cfg.WaitTimeAfterFailure); + if (i > 1) + { + rfidDataLogger.Error($"COM{iperlHead.RfidComPortNr}: Reopen the com port."); + writer.ClosePort(); + } } } } @@ -2360,20 +2368,37 @@ namespace TBF.Rig.TestMethods.iPerlCommunication byte arrow = (flowDir == FlowDir.L_R) ? (byte)1 : (byte)2; /// L-R is reverse flow (=1), R-L is forward flow (=2)(default) - iPerlDataWrite[] dataToBeWritten = new iPerlDataWrite[] + List dataToBeWritten = new List { new iPerlDataWrite(MessageID.MetrologyMemory, 0x19A1, new byte[] { (byte)0xA5 }, "Open Sealing"), - new iPerlDataWrite(MessageID.RadioPassthrough, 0x1804, new byte[] { (byte)1 }, "System Status"), new iPerlDataWrite(MessageID.MetrologyMemory, 0x1985, new byte[] { arrow }, "Arrow"), new iPerlDataWrite(MessageID.MetrologyMemory, 0x199C, new byte[5], "Clear S/N"), - new iPerlDataWrite(MessageID.Command, 0x0000, new byte[] { (byte)Command.SetActiveMode }, "Set active mode"), new iPerlDataWrite(MessageID.Configuration, 0x0015, new byte[] { (byte)0xA0 }, "Test mode config = A0"), - new iPerlDataWrite(MessageID.MetrologyMemory, 0x198E, new byte[] { (byte)(2510 & 0xFF), (byte)((2510 >> 8) & 0xFF) }, "Receipt mean current"), - new iPerlDataWrite(MessageID.RadioPassthrough, 0x18A2, new byte[] { (byte)0x4A, (byte)0x53, (byte)0x3B, (byte)0x8F, + new iPerlDataWrite(MessageID.MetrologyMemory, 0x198E, new byte[] { (byte)(2510 & 0xFF), (byte)((2510 >> 8) & 0xFF) }, "Receipt mean current") + }; + + // check meter status: 1-Idle, 2-Active, 3-Test, 4-End Of Life + if (0 == ReadRequestPort(ihead, MessageID.Configuration, 1, 1, out byte[] rdData)) + { + int eMeterState = (int)((SByte)rdData[0]); + switch (eMeterState) + { + case 1: // Idle -> Test -> Active + dataToBeWritten.Add(new iPerlDataWrite(MessageID.Command, 0x0000, new byte[] { (byte)Command.SetTestMode }, "Set test mode")); + dataToBeWritten.Add(new iPerlDataWrite(MessageID.Command, 0x0000, new byte[] { (byte)Command.SetActiveMode }, "Set active mode")); + break; + case 3: // Test Mode -> Active + dataToBeWritten.Add(new iPerlDataWrite(MessageID.Command, 0x0000, new byte[] { (byte)Command.SetActiveMode }, "Set active mode")); + break; + } + } + + dataToBeWritten.Add(new iPerlDataWrite(MessageID.RadioPassthrough, 0x1804, new byte[] { (byte)1 }, "System Status")); + dataToBeWritten.Add(new iPerlDataWrite(MessageID.RadioPassthrough, 0x1898, new byte[] { (byte)3 }, "WakeUpInterval")); + dataToBeWritten.Add(new iPerlDataWrite(MessageID.RadioPassthrough, 0x18A2, new byte[] { (byte)0x4A, (byte)0x53, (byte)0x3B, (byte)0x8F, (byte)0x70, (byte)0x31, (byte)0xC2, (byte)0x5D, (byte)0x6F, (byte)0x2D, (byte)0xE8, (byte)0x07, - (byte)0x6E, (byte)0x0F, (byte)0x97, (byte)0xC3, }, "AES Key Crypted"), - }; + (byte)0x6E, (byte)0x0F, (byte)0x97, (byte)0xC3, }, "AES Key Crypted")); int successfyllyWrittenFlags = 0; /// Ones in this word represent communication failures, LSB represents the first step int mask = 1;