From c18f06af07dc9de44b38cd9a9af8ade00166194c Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Tue, 25 Jan 2022 16:16:12 +0100 Subject: [PATCH] TM.iPerlCommunication and IperlHead synced with v.2.27, ISessionDataMngmnt replaces IHasClearSessionData and IHasTestName. --- .../GenericDevices/IHasClearSessionData.cs | 12 - TBF/Rig/GenericDevices/IHasTestName.cs | 14 - .../GenericDevices/IRegReaderDatastream.cs | 3 + TBF/Rig/GenericDevices/ISessionDataMngmnt.cs | 27 + .../DataStream/Reader/Reader.cs | 11 + .../RegisterReaders/S640Stream/S640Stream.cs | 39 +- .../SerialStream/FrameFormat.cs | 9 +- .../SerialStream/ProcParams.cs | 16 +- .../SerialStream/SerialStream.cs | 74 +- TBF/Rig/Sequences/MainSeq.cs | 71 +- TBF/Rig/Sequences/MainSeqUtils.cs | 2 +- TBF/Rig/Sequences/Plotter.cs | 8 +- .../DiverterTest/DiverterTestSeq.cs | 16 +- TBF/Rig/TestMethods/Endurance/EnduranceSeq.cs | 16 +- .../TestMethods/FlyingStart/FlyingStartSeq.cs | 16 +- .../FlyingStartFirstRepetWithMassCollSeq.cs | 15 +- .../FlyingStartMassCollComparativeSeq.cs | 17 +- .../FlyingStartMassCollProlongedSeq.cs | 17 +- .../FlyingStartMassCollectionSeq.cs | 44 +- .../FlyingStartTankCollectionSeq.cs | 17 +- .../iPerlCommunication/TestMethodCfg.cs | 2 - .../iPerlCommunication/TestMethodFactory.cs | 2 +- .../iPerlCommunicationForm.cs | 687 ++++++++++++++--- .../iPerlCommunicationParams.cs | 8 +- .../iPerlCommunicationSeq.cs | 286 +++++-- .../iPerlCommunication/iPerlDataWrite.cs | 23 + .../iPerlCommunication/iPerlHead/Enums.cs | 6 +- .../iPerlCommunication/iPerlHead/IperlHead.cs | 715 +++++++++++------- .../iPerlHead/IperlHeadCfg.cs | 5 - TBF/TBF.csproj | 3 +- 30 files changed, 1460 insertions(+), 721 deletions(-) delete mode 100644 TBF/Rig/GenericDevices/IHasClearSessionData.cs delete mode 100644 TBF/Rig/GenericDevices/IHasTestName.cs create mode 100644 TBF/Rig/GenericDevices/ISessionDataMngmnt.cs create mode 100644 TBF/Rig/TestMethods/iPerlCommunication/iPerlDataWrite.cs diff --git a/TBF/Rig/GenericDevices/IHasClearSessionData.cs b/TBF/Rig/GenericDevices/IHasClearSessionData.cs deleted file mode 100644 index 96261e30a..000000000 --- a/TBF/Rig/GenericDevices/IHasClearSessionData.cs +++ /dev/null @@ -1,12 +0,0 @@ -/// -/// Copyright (c) 2021 Sensus Slovensko a.s. -/// -using System; - -namespace TBF.Rig.GenericDevices -{ - public interface IHasClearSessionData - { - void ClearSessionData(); - } -} diff --git a/TBF/Rig/GenericDevices/IHasTestName.cs b/TBF/Rig/GenericDevices/IHasTestName.cs deleted file mode 100644 index 817f3b6dc..000000000 --- a/TBF/Rig/GenericDevices/IHasTestName.cs +++ /dev/null @@ -1,14 +0,0 @@ -/// -/// Copyright (c) 2018 Sensus Slovensko a.s. -/// -using System; - -namespace TBF.Rig.GenericDevices -{ - public interface IHasTestName - { - string TestName { set; } - int TestRepeats { set; } - int RepetitionNr { set; } - } -} diff --git a/TBF/Rig/GenericDevices/IRegReaderDatastream.cs b/TBF/Rig/GenericDevices/IRegReaderDatastream.cs index f32cfa6fe..10d3c0d44 100644 --- a/TBF/Rig/GenericDevices/IRegReaderDatastream.cs +++ b/TBF/Rig/GenericDevices/IRegReaderDatastream.cs @@ -2,6 +2,7 @@ /// Copyright (c) 2018 Sensus Slovensko a.s. /// using System; +using Config.Entities; namespace TBF.Rig.GenericDevices { @@ -9,6 +10,8 @@ namespace TBF.Rig.GenericDevices { IOperation ReadDatastreamOp(); + void TestIsGoingToStartSoon(Test test, int repetitionNr); + bool NoSamples { get; } double VolumeLtrStart { get; } double VolumeLtrEnd { get; } diff --git a/TBF/Rig/GenericDevices/ISessionDataMngmnt.cs b/TBF/Rig/GenericDevices/ISessionDataMngmnt.cs new file mode 100644 index 000000000..ea39708e1 --- /dev/null +++ b/TBF/Rig/GenericDevices/ISessionDataMngmnt.cs @@ -0,0 +1,27 @@ +/// +/// Copyright (c) 2021 Sensus Slovensko a.s. +/// +using System; + +namespace TBF.Rig.GenericDevices +{ + public interface ISessionDataMngmnt + { + /// + /// Called when a new session is started + /// + /// File name for the log file + void StartSession(); + + /// + /// Called when a mark inside a session nees to be saved + /// + /// Arbitrary object, ToString() method is used to show marks in log files + void SaveMark(object mark); + + /// + /// Called when a new session is completed + /// + void EndSession(); + } +} diff --git a/TBF/Rig/RegisterReaders/DataStream/Reader/Reader.cs b/TBF/Rig/RegisterReaders/DataStream/Reader/Reader.cs index de24b271b..a9baed566 100644 --- a/TBF/Rig/RegisterReaders/DataStream/Reader/Reader.cs +++ b/TBF/Rig/RegisterReaders/DataStream/Reader/Reader.cs @@ -91,6 +91,17 @@ namespace TBF.Rig.RegisterReaders.DataStream.Reader public double EndWMState { get { return endWMState; } } /// Test end state of the water meter + /// + /// Store/update values to be used as a part of the opto-data log file name. + /// + /// Currently executed test + /// Currently executed repetition number + public void TestIsGoingToStartSoon(Config.Entities.Test test, int repetitionNr) + { + /// Nothing needs to be updated + } + + /// To be used at the beginning of a test public void Clear() { diff --git a/TBF/Rig/RegisterReaders/S640Stream/S640Stream.cs b/TBF/Rig/RegisterReaders/S640Stream/S640Stream.cs index 5f71e84d7..33a9a8ce9 100644 --- a/TBF/Rig/RegisterReaders/S640Stream/S640Stream.cs +++ b/TBF/Rig/RegisterReaders/S640Stream/S640Stream.cs @@ -14,7 +14,7 @@ namespace TBF.Rig.RegisterReaders.S640Stream /// /// This component = instance of this class is a placeholder for a combined main watermeter /// - public class S640Stream : ComponentBase, IDevice, IRegReaderDatastream, IHasTestName, IHasClearSessionData, IOperation + public class S640Stream : ComponentBase, IDevice, IRegReaderDatastream, ISessionDataMngmnt, IOperation { private static readonly ILog log = LogManager.GetLogger(typeof(S640Stream)); public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); } @@ -51,11 +51,19 @@ namespace TBF.Rig.RegisterReaders.S640Stream double wmTestTime; - /// Name set by the test, to be used as a part of the opto-data log file name - public string TestName { set { testName = value; } } - public int TestRepeats { set { testRepeats = value; } } - public int RepetitionNr { set { repetitionNr = value; } } - /// + /// + /// Store/update values to be used as a part of the opto-data log file name. + /// + /// Currently executed test + /// Currently executed repetition number + public void TestIsGoingToStartSoon(Config.Entities.Test test, int repetitionNr) + { + /// Store/update values to be used as a part of the opto-data log file name + testName = test.Name; + testRepeats = test.Repeats; + this.repetitionNr = repetitionNr; + } + /// string testName; int testRepeats; int repetitionNr; @@ -170,7 +178,7 @@ namespace TBF.Rig.RegisterReaders.S640Stream /// /// Clear data related to a specific water meter /// - public void ClearSessionData() + public void StartSession() { currentRawVolumeUnwrapped = 0; currentRawTimeUnwrapped = 0; @@ -194,9 +202,17 @@ namespace TBF.Rig.RegisterReaders.S640Stream partOfTelegram = string.Empty; } + public void SaveMark(object mark) + { + } + + public void EndSession() + { + datastreamParsingEnabled = false; + } + public override void Initialize() { - ClearSessionData(); datastreamParsingEnabled = false; /// Allocate memory for opto-data from iPerl @@ -312,6 +328,11 @@ namespace TBF.Rig.RegisterReaders.S640Stream ReadPulses(); } + public void TestCompleted() + { + /// TODO: Implement + } + int timeFromStart; /// This is to determine when the test start sample should be taken @@ -473,7 +494,7 @@ namespace TBF.Rig.RegisterReaders.S640Stream beginWMState = volumeLtr0; endWMState = volumeLtr; wmVolume = Math.Abs(endWMState - beginWMState); - wmPulses = (int)(wmVolume * (double)PulsesPerLtr + 0.5); + wmPulses = Convert.ToInt32(Math.Round(wmVolume * PulsesPerLtr)); wmRefPulses = StateMachine.ControlBoard.RefPulses; wmTestTime = timestampSec - timestampSec0; } diff --git a/TBF/Rig/RegisterReaders/SerialStream/FrameFormat.cs b/TBF/Rig/RegisterReaders/SerialStream/FrameFormat.cs index 71babd5c5..ed500ad1d 100644 --- a/TBF/Rig/RegisterReaders/SerialStream/FrameFormat.cs +++ b/TBF/Rig/RegisterReaders/SerialStream/FrameFormat.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using Common; namespace TBF.Rig.RegisterReaders.SerialStream { @@ -10,13 +11,13 @@ namespace TBF.Rig.RegisterReaders.SerialStream public readonly int FrameLength; /// Frame length in characters/bytes, 0 = unknown public readonly double FrameFrequency; /// Number of frames per second (Hz) - public readonly Common.Unit VolumeUnits; + public readonly Unit VolumeUnits; public readonly double VolumeScaleFactor; /// Volume in VolumeInits = volmeRaw / VolumeScaleFactor public readonly int VolumeFieldStart; /// Start of the volume field: 0-based index of the first character, -1 = no volume field in the frame public readonly int VolumeFieldEnd; /// End of the volume field: 0-based index of the last character public readonly FieldFormat VolumeFieldFormat; /// Hexadecimal or Decimal - public readonly Common.Unit TimeUnits; + public readonly Unit TimeUnits; public readonly double TimeScaleFactor; /// Time in TimeUnits = timeRaw / TimeScaleFactor public readonly int TimeFieldStart; /// Start of the time field: 0-based index of the first character, -1 = no time field in the frame public readonly int TimeFieldEnd; /// End of the time field: 0-based index of the last character @@ -38,9 +39,9 @@ namespace TBF.Rig.RegisterReaders.SerialStream public readonly long RawTimeIncrementPerFrame; public FrameFormat(int frameLength, double frameFrequency, - Common.Unit volumeUnits, double volumeScaleFactor, + Unit volumeUnits, double volumeScaleFactor, int volumeFieldStart, int volumeFieldEnd, FieldFormat volumeFieldFormat, - Common.Unit timeUnits, double timeScaleFactor, + Unit timeUnits, double timeScaleFactor, int timeFieldStart, int timeFieldEnd, FieldFormat timeFieldFormat) { FrameLength = frameLength; diff --git a/TBF/Rig/RegisterReaders/SerialStream/ProcParams.cs b/TBF/Rig/RegisterReaders/SerialStream/ProcParams.cs index 7a07966ee..89e88135a 100644 --- a/TBF/Rig/RegisterReaders/SerialStream/ProcParams.cs +++ b/TBF/Rig/RegisterReaders/SerialStream/ProcParams.cs @@ -112,9 +112,9 @@ namespace TBF.Rig.RegisterReaders.SerialStream case 2: FrameFrequency = Utils.ParseUDouble(strValue); return CfgUpdateFlags.None; case 3: - for (Common.Unit u = 0; u < Common.Unit.Count; u++) + for (Unit u = 0; u < Unit.Count; u++) { - if (Common.Units.IsQuantity(u, Quantity.Volume) && u.ToDescription().Equals(strValue)) + if (Units.IsQuantity(u, Quantity.Volume) && u.ToDescription().Equals(strValue)) { VolumeUnits = u; return CfgUpdateFlags.None; @@ -132,9 +132,9 @@ namespace TBF.Rig.RegisterReaders.SerialStream break; case 8: - for (Common.Unit u = 0; u < Common.Unit.Count; u++) + for (Unit u = 0; u < Unit.Count; u++) { - if (Common.Units.IsQuantity(u, Quantity.Time) && u.ToDescription().Equals(strValue)) + if (Units.IsQuantity(u, Quantity.Time) && u.ToDescription().Equals(strValue)) { TimeUnits = u; return CfgUpdateFlags.None; @@ -180,9 +180,9 @@ namespace TBF.Rig.RegisterReaders.SerialStream break; case 3: - for (Common.Unit u = 0; u < Common.Unit.Count; u++) + for (Unit u = 0; u < Unit.Count; u++) { - if (Common.Units.IsQuantity(u, Quantity.Volume) && u.ToDescription().Equals(strValue)) + if (Units.IsQuantity(u, Quantity.Volume) && u.ToDescription().Equals(strValue)) { return true; } @@ -199,9 +199,9 @@ namespace TBF.Rig.RegisterReaders.SerialStream break; case 8: - for (Common.Unit u = 0; u < Common.Unit.Count; u++) + for (Unit u = 0; u < Unit.Count; u++) { - if (Common.Units.IsQuantity(u, Quantity.Time) && u.ToDescription().Equals(strValue)) + if (Units.IsQuantity(u, Quantity.Time) && u.ToDescription().Equals(strValue)) { return true; } diff --git a/TBF/Rig/RegisterReaders/SerialStream/SerialStream.cs b/TBF/Rig/RegisterReaders/SerialStream/SerialStream.cs index 3df723fba..7c2659011 100644 --- a/TBF/Rig/RegisterReaders/SerialStream/SerialStream.cs +++ b/TBF/Rig/RegisterReaders/SerialStream/SerialStream.cs @@ -16,7 +16,7 @@ namespace TBF.Rig.RegisterReaders.SerialStream /// /// This component = instance of this class is a placeholder for a combined main watermeter /// - public class SerialStream : ComponentBase, IDevice, IRegReaderDatastream, IHasTestName, IHasClearSessionData, IOperation + public class SerialStream : ComponentBase, IDevice, IRegReaderDatastream, ISessionDataMngmnt, IOperation { private static readonly ILog log = LogManager.GetLogger(typeof(SerialStream)); public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); } @@ -92,18 +92,24 @@ namespace TBF.Rig.RegisterReaders.SerialStream double wmTestTime; - - /// Name set by the test, to be used as a part of the opto-data log file name - public string TestName { set { testName = value; } } - public int TestRepeats { set { testRepeats = value; } } - public int RepetitionNr { set { repetitionNr = value; } } + /// + /// Store/update values to be used as a part of the opto-data log file name. + /// Stop data stream processing and saving, if it is enabled. + /// + /// Currently executed test + /// Currently executed repetition number + public void TestIsGoingToStartSoon(Config.Entities.Test test, int repetitionNr) + { + /// Store/update values to be used as a part of the opto-data log file name + testName = test.Name; + testRepeats = test.Repeats; + this.repetitionNr = repetitionNr; + } /// string testName; int testRepeats; int repetitionNr; - /// Name set by the test, to be used as a part of the opto-data log file name - public string BenchName; /// /// Volume of water from the opto telegram @@ -123,6 +129,7 @@ namespace TBF.Rig.RegisterReaders.SerialStream /// /// Timestamp from the opto telegram /// + bool lastTimestampValid; private Int64 lastTimestamp; private double timestampSec; private double timestampSec0; @@ -183,22 +190,10 @@ namespace TBF.Rig.RegisterReaders.SerialStream : base(cfg) { myCfg = cfg as SerialStreamCfg; - log.Warn(this.ToString()); - } - - /// - /// Clear data related to a specific water meter - /// - public void ClearSessionData() - { - commFailed = false; - datastreamFramesCount = 0; } public override void Initialize() { - ClearSessionData(); - datastreamParsingEnabled = false; currentFrameFormat = new FrameFormat(FrameLength, FrameFrequency, VolumeUnits, VolumeScaleFactor, @@ -228,7 +223,8 @@ namespace TBF.Rig.RegisterReaders.SerialStream myCfg.StopBits); serialPort.Handshake = myCfg.Handshake; - serialPort.Open(); + serialPort.Open(); + log.FatalFormat("{0} initialized: {1}", Name, this); } else if (DebugLevel == DebugMode.Simulate) { @@ -240,7 +236,32 @@ namespace TBF.Rig.RegisterReaders.SerialStream { MessageBox.Show("Missing file C:\\TBF\\Simulate\\seriastream.txt"); } + log.FatalFormat("{0} simulated: {1}", Name, this); } + else + { + serialPort = null; + log.FatalFormat("{0} in other mode: {1}", Name, this); + } + } + + /// + /// Clear data related to a specific water meter + /// + public void StartSession() + { + commFailed = false; + datastreamFramesCount = 0; + } + + public void SaveMark(object mark) + { + /// TODO + } + + public void EndSession() + { + datastreamParsingEnabled = false; } public void RunDeviceBefore() @@ -313,6 +334,11 @@ namespace TBF.Rig.RegisterReaders.SerialStream ReadPulses(); } + public void TestCompleted() + { + /// TODO: Implement + } + int sampleNr; /// This is to determine when the test start sample should be taken @@ -426,8 +452,8 @@ namespace TBF.Rig.RegisterReaders.SerialStream beginWMState = volumeLtr0; endWMState = volumeLtr; wmVolume = Math.Abs(endWMState - beginWMState); - wmPulses = (int)(wmVolume * (double)PulsesPerLtr + 0.5); - wmRefPulses = StateMachine.ControlBoard.RefPulses; + wmPulses = Convert.ToInt32(Math.Round(wmVolume * PulsesPerLtr)); + wmRefPulses = StateMachine.ControlBoard.RefPulses; wmTestTime = timestampSec - timestampSec0; } @@ -610,7 +636,7 @@ namespace TBF.Rig.RegisterReaders.SerialStream public static double UnitVolume(Common.Unit units, double scaleFactor) { - if (Common.Units.IsQuantity(units, Quantity.Volume)) + if (Units.IsQuantity(units, Quantity.Volume)) { return Common.Units.ConvertFrom(units, 1.0) * scaleFactor; } diff --git a/TBF/Rig/Sequences/MainSeq.cs b/TBF/Rig/Sequences/MainSeq.cs index 97ed032c5..79e4471b2 100644 --- a/TBF/Rig/Sequences/MainSeq.cs +++ b/TBF/Rig/Sequences/MainSeq.cs @@ -551,11 +551,15 @@ namespace TBF.Rig.Sequences /// Open iPerlCommunicationForm ProcessData.RegisterReaders = StateMachine.GetMetersPath(simultWithPurgingTests[0]).RegisterReaders; -#if IPERL - Program.MainWnd.Invoke(new CommunicationFormDlgt(OpenIPerlCommForm), new object[] { this, simultWithPurgingCfg, simultWithPurgingProcParams, simultWithPurgingTests, simultWithPurgingTestParams }); -#else - Program.MainWnd.Invoke(new CommunicationFormDlgt(OpenS640CommForm), new object[] { this, simultWithPurgingCfg, simultWithPurgingProcParams, simultWithPurgingTests, simultWithPurgingTestParams }); -#endif + var firstRR = ProcessData.RegisterReaders.FirstOrDefault(x => x != null); + if (firstRR is TBF.Rig.TestMethods.iPerlCommunication.iPerlHead.IperlHead) + { + Program.MainWnd.Invoke(new CommunicationFormDlgt(OpenIPerlCommForm), new object[] { this, simultWithPurgingCfg, simultWithPurgingProcParams, simultWithPurgingTests, simultWithPurgingTestParams }); + } + else if (firstRR is TBF.Rig.RegisterReaders.S640Stream.S640Stream) + { + Program.MainWnd.Invoke(new CommunicationFormDlgt(OpenS640CommForm), new object[] { this, simultWithPurgingCfg, simultWithPurgingProcParams, simultWithPurgingTests, simultWithPurgingTestParams }); + } } /// @@ -565,10 +569,10 @@ namespace TBF.Rig.Sequences switch (evt) { case Event.Error: - if (simultWithPurgingCount > 0) CloseCommunicationForm(); + if (simultWithPurgingCount > 0) CloseCommunicationForm(); goto error; case Event.UiCmdStop: - if (simultWithPurgingCount > 0) CloseCommunicationForm(); + if (simultWithPurgingCount > 0) CloseCommunicationForm(); goto stop; default: break; @@ -929,22 +933,7 @@ namespace TBF.Rig.Sequences goto select_cycle_or_test; } StateMachine.ControlBoard.Devices = outPath; - - if ((sensPath != null) && (sensPath.RegisterReaders != null)) - { - ProcessData.RegisterReaders = sensPath.RegisterReaders; - foreach (var rr in sensPath.RegisterReaders) - { - if ((rr is TestMethods.iPerlCommunication.iPerlHead.IperlHead) && (BenchInfo != null)) - { - (rr as TestMethods.iPerlCommunication.iPerlHead.IperlHead).BenchName = BenchInfo.TestBenchName; - } - } - } - else - { - ProcessData.RegisterReaders = null; - } + ProcessData.RegisterReaders = (sensPath != null && sensPath.RegisterReaders != null) ? sensPath.RegisterReaders : null; /// /// Execute one test (single repetition of a repeated test) @@ -1064,22 +1053,7 @@ namespace TBF.Rig.Sequences StateMachine.LoadTestParams(dfrrdData.Test); StateMachine.ControlBoard.Devices = outPath; - - if ((sensPath != null) && (sensPath.RegisterReaders != null)) - { - ProcessData.RegisterReaders = sensPath.RegisterReaders; - foreach (var rr in sensPath.RegisterReaders) - { - if ((rr is TestMethods.iPerlCommunication.iPerlHead.IperlHead) && (BenchInfo != null)) - { - (rr as TestMethods.iPerlCommunication.iPerlHead.IperlHead).BenchName = BenchInfo.TestBenchName; - } - } - } - else - { - ProcessData.RegisterReaders = null; - } + ProcessData.RegisterReaders = (sensPath != null && sensPath.RegisterReaders != null) ? sensPath.RegisterReaders : null; e = testMethod.Execute2ndPass(dfrrdData.Test, dfrrdData.RepetNr, dfrrdData.IntermediateData); @@ -1141,7 +1115,6 @@ namespace TBF.Rig.Sequences if (testMethod != null && testMethod.CanTest(StateMachine.Procedure.MetersKind)) { StateMachine.LoadTestParams(test); - string errMsg; if (!testMethod.CheckDeviceCaps(test, outPath, out errMsg)) { @@ -1149,22 +1122,7 @@ namespace TBF.Rig.Sequences goto select_cycle_or_test; } StateMachine.ControlBoard.Devices = outPath; - - if ((sensPath != null) && (sensPath.RegisterReaders != null)) - { - ProcessData.RegisterReaders = sensPath.RegisterReaders; - foreach (var rr in sensPath.RegisterReaders) - { - if ((rr is TestMethods.iPerlCommunication.iPerlHead.IperlHead) && (BenchInfo != null)) - { - (rr as TestMethods.iPerlCommunication.iPerlHead.IperlHead).BenchName = BenchInfo.TestBenchName; - } - } - } - else - { - ProcessData.RegisterReaders = null; - } + ProcessData.RegisterReaders = (sensPath != null && sensPath.RegisterReaders != null) ? sensPath.RegisterReaders : null; Event rsltTransBefore = Event.Done; Event rsltTransAfter = Event.Done; @@ -1224,7 +1182,6 @@ namespace TBF.Rig.Sequences } ///------------------------------------------------------------------------------------------------------------ - /// Cycle or test completed goto select_cycle_or_test; diff --git a/TBF/Rig/Sequences/MainSeqUtils.cs b/TBF/Rig/Sequences/MainSeqUtils.cs index 778a653d0..16d542d5c 100644 --- a/TBF/Rig/Sequences/MainSeqUtils.cs +++ b/TBF/Rig/Sequences/MainSeqUtils.cs @@ -270,7 +270,7 @@ namespace TBF.Rig.Sequences /// foreach (var cmpnt in StateMachine.Components) { - if (cmpnt is IHasClearSessionData) (cmpnt as IHasClearSessionData).ClearSessionData(); + if (cmpnt is ISessionDataMngmnt) (cmpnt as ISessionDataMngmnt).StartSession(); } IsQ2PreCorrectionCalculated = false; diff --git a/TBF/Rig/Sequences/Plotter.cs b/TBF/Rig/Sequences/Plotter.cs index 95951190c..d19ffef42 100644 --- a/TBF/Rig/Sequences/Plotter.cs +++ b/TBF/Rig/Sequences/Plotter.cs @@ -25,13 +25,7 @@ namespace TBF.Rig.Sequences } - /// - /// - /// - /// - /// - /// - /// Graph ID + public int StartGraph(int batchNr, string testName, int repetition) { try diff --git a/TBF/Rig/TestMethods/DiverterTest/DiverterTestSeq.cs b/TBF/Rig/TestMethods/DiverterTest/DiverterTestSeq.cs index 8a029ca57..5f979f0d1 100644 --- a/TBF/Rig/TestMethods/DiverterTest/DiverterTestSeq.cs +++ b/TBF/Rig/TestMethods/DiverterTest/DiverterTestSeq.cs @@ -164,17 +164,6 @@ namespace TBF.Rig.TestMethods.DiverterTest string testName = Results.Utils.GetTestName(test.Name, test.Repeats, repetitionNr); TestStartTime = DateTime.Now; - foreach (var rr in sensPath.RegisterReaders) - { - GenericDevices.IHasTestName readerWithTstName = rr as GenericDevices.IHasTestName; - if (readerWithTstName != null) - { - readerWithTstName.TestName = test.Name; - readerWithTstName.TestRepeats = test.Repeats; - readerWithTstName.RepetitionNr = repetitionNr; - } - } - //------------------------------------------------ Bridge.OnActivity(this, Strings.Checking_tank_capacity); @@ -476,6 +465,11 @@ namespace TBF.Rig.TestMethods.DiverterTest { LogProcessDataHeader(processDataLogger, string.Format("Measurement {0}", divRepetNr)); + foreach (var rr in sensPath.RegisterReaders) + { + if (rr is IRegReaderDatastream) (rr as IRegReaderDatastream).TestIsGoingToStartSoon(test, repetitionNr); + } + int remainingRepetitions = testParams.DivRepetitions - divRepetNr + 1; int pulsesNow = (remainingPulses + remainingRepetitions - 1) / remainingRepetitions; remainingPulses -= pulsesNow; diff --git a/TBF/Rig/TestMethods/Endurance/EnduranceSeq.cs b/TBF/Rig/TestMethods/Endurance/EnduranceSeq.cs index 4dbd18143..b792a5b97 100644 --- a/TBF/Rig/TestMethods/Endurance/EnduranceSeq.cs +++ b/TBF/Rig/TestMethods/Endurance/EnduranceSeq.cs @@ -163,18 +163,6 @@ namespace TBF.Rig.TestMethods.Endurance string testName = Results.Utils.GetTestName(test.Name, test.Repeats, repetitionNr); TestStartTime = DateTime.Now; - foreach (var rr in sensPath.RegisterReaders) - { - GenericDevices.IHasTestName readerWithTstName = rr as GenericDevices.IHasTestName; - if (readerWithTstName != null) - { - readerWithTstName.TestName = test.Name; - readerWithTstName.TestRepeats = test.Repeats; - readerWithTstName.RepetitionNr = repetitionNr; - } - } - - //------------------------------------------------ Bridge.OnActivity(this, Strings.Starting_the_pump); //------------------------------------------------ @@ -298,6 +286,10 @@ namespace TBF.Rig.TestMethods.Endurance IList measureOperations = new List(); foreach (var camera in cameras) measureOperations.Add(camera.MeasurementOp()); + foreach (var rr in sensPath.RegisterReaders) + { + if (rr is IRegReaderDatastream) (rr as IRegReaderDatastream).TestIsGoingToStartSoon(test, repetitionNr); + } //------------------------------------------------ diff --git a/TBF/Rig/TestMethods/FlyingStart/FlyingStartSeq.cs b/TBF/Rig/TestMethods/FlyingStart/FlyingStartSeq.cs index 2a4d35d7c..824ee2440 100644 --- a/TBF/Rig/TestMethods/FlyingStart/FlyingStartSeq.cs +++ b/TBF/Rig/TestMethods/FlyingStart/FlyingStartSeq.cs @@ -149,17 +149,6 @@ namespace TBF.Rig.TestMethods.FlyingStart string testName = Results.Utils.GetTestName(test.Name, test.Repeats, repetitionNr); TestStartTime = DateTime.Now; - foreach (var rr in sensPath.RegisterReaders) - { - GenericDevices.IHasTestName readerWithTstName = rr as GenericDevices.IHasTestName; - if (readerWithTstName != null) - { - readerWithTstName.TestName = test.Name; - readerWithTstName.TestRepeats = test.Repeats; - readerWithTstName.RepetitionNr = repetitionNr; - } - } - /// /// Optionally display prompt to emerge temperature meters to appropriate baths for heat meters test /// @@ -384,6 +373,11 @@ namespace TBF.Rig.TestMethods.FlyingStart IList cameraMeasurementOps = new List(); foreach (var camera in cameras) cameraMeasurementOps.Add(camera.MeasurementOp()); + foreach (var rr in sensPath.RegisterReaders) + { + if (rr is IRegReaderDatastream) (rr as IRegReaderDatastream).TestIsGoingToStartSoon(test, repetitionNr); + } + //------------------------------------------------ Bridge.OnActivity(this, Strings.Test_in_progress); diff --git a/TBF/Rig/TestMethods/FlyingStartFirstRepetWithMassColl/FlyingStartFirstRepetWithMassCollSeq.cs b/TBF/Rig/TestMethods/FlyingStartFirstRepetWithMassColl/FlyingStartFirstRepetWithMassCollSeq.cs index ea307d412..d2050cfff 100644 --- a/TBF/Rig/TestMethods/FlyingStartFirstRepetWithMassColl/FlyingStartFirstRepetWithMassCollSeq.cs +++ b/TBF/Rig/TestMethods/FlyingStartFirstRepetWithMassColl/FlyingStartFirstRepetWithMassCollSeq.cs @@ -187,17 +187,6 @@ namespace TBF.Rig.TestMethods.FlyingStartFirstRepetWithMassColl string testName = Results.Utils.GetTestName(test.Name, test.Repeats, repetitionNr); TestStartTime = DateTime.Now; - foreach (var rr in sensPath.RegisterReaders) - { - GenericDevices.IHasTestName readerWithTstName = rr as GenericDevices.IHasTestName; - if (readerWithTstName != null) - { - readerWithTstName.TestName = test.Name; - readerWithTstName.TestRepeats = test.Repeats; - readerWithTstName.RepetitionNr = repetitionNr; - } - } - bool drainTheTank = false; if (repetitionNr == 1) @@ -531,6 +520,10 @@ namespace TBF.Rig.TestMethods.FlyingStartFirstRepetWithMassColl log.WarnFormat("Start mass = {0}kg", StartMass); } + foreach (var rr in sensPath.RegisterReaders) + { + if (rr is IRegReaderDatastream) (rr as IRegReaderDatastream).TestIsGoingToStartSoon(test, repetitionNr); + } if (heatMetersPath == null) LogProcessDataHeader(processDataLogger, "Measurement"); else LogProcessDataHeaderHeatMeters(processDataLogger, "Measurement"); diff --git a/TBF/Rig/TestMethods/FlyingStartMassCollComparative/FlyingStartMassCollComparativeSeq.cs b/TBF/Rig/TestMethods/FlyingStartMassCollComparative/FlyingStartMassCollComparativeSeq.cs index e77006d7f..3f8b30dd7 100644 --- a/TBF/Rig/TestMethods/FlyingStartMassCollComparative/FlyingStartMassCollComparativeSeq.cs +++ b/TBF/Rig/TestMethods/FlyingStartMassCollComparative/FlyingStartMassCollComparativeSeq.cs @@ -202,17 +202,6 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollComparative string testName = Results.Utils.GetTestName(test.Name, test.Repeats, repetitionNr); TestStartTime = DateTime.Now; - foreach (var rr in sensPath.RegisterReaders) - { - GenericDevices.IHasTestName readerWithTstName = rr as GenericDevices.IHasTestName; - if (readerWithTstName != null) - { - readerWithTstName.TestName = test.Name; - readerWithTstName.TestRepeats = test.Repeats; - readerWithTstName.RepetitionNr = repetitionNr; - } - } - //------------------------------------------------ Bridge.OnActivity(this, Strings.Checking_tank_capacity); @@ -627,6 +616,12 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollComparative } + foreach (var rr in sensPath.RegisterReaders) + { + if (rr is IRegReaderDatastream) (rr as IRegReaderDatastream).TestIsGoingToStartSoon(test, repetitionNr); + } + + if (heatMetersPath == null) LogProcessDataHeader(processDataLogger, "Measurement"); else LogProcessDataHeaderHeatMeters(processDataLogger, "Measurement"); diff --git a/TBF/Rig/TestMethods/FlyingStartMassCollProlonged/FlyingStartMassCollProlongedSeq.cs b/TBF/Rig/TestMethods/FlyingStartMassCollProlonged/FlyingStartMassCollProlongedSeq.cs index 314908843..3e0d5a1dd 100644 --- a/TBF/Rig/TestMethods/FlyingStartMassCollProlonged/FlyingStartMassCollProlongedSeq.cs +++ b/TBF/Rig/TestMethods/FlyingStartMassCollProlonged/FlyingStartMassCollProlongedSeq.cs @@ -181,17 +181,6 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollProlonged string testName = Results.Utils.GetTestName(test.Name, test.Repeats, repetitionNr); TestStartTime = DateTime.Now; - foreach (var rr in sensPath.RegisterReaders) - { - GenericDevices.IHasTestName readerWithTstName = rr as GenericDevices.IHasTestName; - if (readerWithTstName != null) - { - readerWithTstName.TestName = test.Name; - readerWithTstName.TestRepeats = test.Repeats; - readerWithTstName.RepetitionNr = repetitionNr; - } - } - //------------------------------------------------ Bridge.OnActivity(this, Strings.Checking_tank_capacity); @@ -530,6 +519,12 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollProlonged log.WarnFormat("Start mass = {0}kg", StartMass); + foreach (var rr in sensPath.RegisterReaders) + { + if (rr is IRegReaderDatastream) (rr as IRegReaderDatastream).TestIsGoingToStartSoon(test, repetitionNr); + } + + if (heatMetersPath == null) LogProcessDataHeader(processDataLogger, "Measurement"); else LogProcessDataHeaderHeatMeters(processDataLogger, "Measurement"); diff --git a/TBF/Rig/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs b/TBF/Rig/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs index 29d66e055..eddcff561 100644 --- a/TBF/Rig/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs +++ b/TBF/Rig/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs @@ -417,27 +417,6 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection temperature_set: - /// - /// Prepare datastream read operations - /// - IList readDatastreamOps = new List(); - if (sensPath != null && sensPath.RegisterReaders != null) - { - foreach (var rr in sensPath.RegisterReaders) - { - var rrWithTestName = rr as GenericDevices.IHasTestName; - if (rrWithTestName != null) - { - rrWithTestName.TestName = test.Name; - rrWithTestName.TestRepeats = test.Repeats; - rrWithTestName.RepetitionNr = repetitionNr; - } - - var datastreamRR = rr as GenericDevices.IRegReaderDatastream; - if (datastreamRR != null) readDatastreamOps.Add(datastreamRR.ReadDatastreamOp()); - } - } - /// /// Prepare cameras, ROI-s and measurementOperations /// @@ -474,6 +453,21 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection cameraMeasurementOps.Add(camera.MeasurementOp()); } + /// Prepare datastream read operations + IList readDatastreamOps = new List(); + if (sensPath != null && sensPath.RegisterReaders != null) + { + foreach (var rr in sensPath.RegisterReaders) + { + var datastreamRR = rr as GenericDevices.IRegReaderDatastream; + if (datastreamRR != null) + { + datastreamRR.TestIsGoingToStartSoon(test, repetitionNr); + readDatastreamOps.Add(datastreamRR.ReadDatastreamOp()); + } + } + } + if (drainTheTank) { @@ -1097,13 +1091,7 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection foreach (var rr in sensPath.RegisterReaders) { - GenericDevices.IHasTestName readerWithTstName = rr as GenericDevices.IHasTestName; - if (readerWithTstName != null) - { - readerWithTstName.TestName = test.Name; - readerWithTstName.TestRepeats = test.Repeats; - readerWithTstName.RepetitionNr = repetitionNr; - } + if (rr is IRegReaderDatastream) (rr as IRegReaderDatastream).TestIsGoingToStartSoon(test, repetitionNr); } State.Create(string.Format("{0}({1}) : Reading watermeters", test.Method, test.Name)) diff --git a/TBF/Rig/TestMethods/FlyingStartTankCollection/FlyingStartTankCollectionSeq.cs b/TBF/Rig/TestMethods/FlyingStartTankCollection/FlyingStartTankCollectionSeq.cs index 7a3b062d9..3af766acc 100644 --- a/TBF/Rig/TestMethods/FlyingStartTankCollection/FlyingStartTankCollectionSeq.cs +++ b/TBF/Rig/TestMethods/FlyingStartTankCollection/FlyingStartTankCollectionSeq.cs @@ -186,18 +186,6 @@ namespace TBF.Rig.TestMethods.FlyingStartTankCollection string testName = Results.Utils.GetTestName(test.Name, test.Repeats, repetitionNr); TestStartTime = DateTime.Now; - foreach (var rr in sensPath.RegisterReaders) - { - GenericDevices.IHasTestName readerWithTstName = rr as GenericDevices.IHasTestName; - if (readerWithTstName != null) - { - readerWithTstName.TestName = test.Name; - readerWithTstName.TestRepeats = test.Repeats; - readerWithTstName.RepetitionNr = repetitionNr; - } - } - - /// /// Optionally drain the water tank /// @@ -377,6 +365,11 @@ namespace TBF.Rig.TestMethods.FlyingStartTankCollection IList cameraMeasurementOps = new List(); foreach (var camera in cameras) cameraMeasurementOps.Add(camera.MeasurementOp()); + foreach (var rr in sensPath.RegisterReaders) + { + if (rr is IRegReaderDatastream) (rr as IRegReaderDatastream).TestIsGoingToStartSoon(test, repetitionNr); + } + LogProcessDataTestInfo(processDataLogger, test.Procedure.Name, test.Name); LogProcessDataHeader(processDataLogger, "Measurement"); diff --git a/TBF/Rig/TestMethods/iPerlCommunication/TestMethodCfg.cs b/TBF/Rig/TestMethods/iPerlCommunication/TestMethodCfg.cs index c07f025f7..971cea8b5 100644 --- a/TBF/Rig/TestMethods/iPerlCommunication/TestMethodCfg.cs +++ b/TBF/Rig/TestMethods/iPerlCommunication/TestMethodCfg.cs @@ -1,9 +1,7 @@ /// /// Copyright (c) 2015-2021 Sensus Slovensko a.s. /// -using System; using System.Collections.Generic; -using System.IO; using System.Xml.Serialization; using Common; using Config.Entities; diff --git a/TBF/Rig/TestMethods/iPerlCommunication/TestMethodFactory.cs b/TBF/Rig/TestMethods/iPerlCommunication/TestMethodFactory.cs index 0ab831dca..4b49c83a5 100644 --- a/TBF/Rig/TestMethods/iPerlCommunication/TestMethodFactory.cs +++ b/TBF/Rig/TestMethods/iPerlCommunication/TestMethodFactory.cs @@ -8,7 +8,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication { public class TestMethodFactory : IComponentFactory { - public string ClassName { get { return this.GetType().Namespace.Substring(8); } } + public string ClassName { get { return GetType().Namespace.Substring(8); } } public override string ToString() { return ClassName; } public IComponent DummyComponent() { return new TestMethod(); } diff --git a/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs b/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs index a134e65bb..aa9a9ac6c 100644 --- a/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs +++ b/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs @@ -88,6 +88,8 @@ namespace TBF.Rig.TestMethods.iPerlCommunication public const string ConditnlUpdateQ2CorrLRStr = "Conditional update of Q2 correction L-R"; /// Arguments: L-R_test_name public const string Reset2HzCorrectionStr = "Reset 2Hz correction"; public const string Write2HzCorrectionStr = "Write 2Hz correction"; + public const string DewaReworkRLStr = "DEWA rework R-L"; + public const string DewaReworkLRStr = "DEWA rework L-R"; public static Color DisabledColor = Color.DarkGray; public static Color OptoAndDirOKColor = Color.Green; @@ -97,79 +99,366 @@ namespace TBF.Rig.TestMethods.iPerlCommunication #region DLL_Interface - [DllImport("libRfid1.dll", EntryPoint = "getDllVersion")] static extern unsafe int getDllVersion1(); - [DllImport("libRfid1.dll", EntryPoint = "openPort")] static extern unsafe int openPort1(int comPort); - [DllImport("libRfid1.dll", EntryPoint = "closePort")] static extern unsafe int closePort1(); - [DllImport("libRfid1.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort1(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid1.dll", EntryPoint = "getDllVersion")] static extern unsafe int getDllVersion1(); + [DllImport("libRfid1.dll", EntryPoint = "openPort")] static extern unsafe int openPort1(int comPort); + [DllImport("libRfid1.dll", EntryPoint = "closePort")] static extern unsafe int closePort1(); + [DllImport("libRfid1.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort1(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); [DllImport("libRfid1.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort1(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); - [DllImport("libRfid2.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion2(); - [DllImport("libRfid2.dll", EntryPoint = "openPort")] static extern unsafe int openPort2(int comPort); - [DllImport("libRfid2.dll", EntryPoint = "closePort")] static extern unsafe int closePort2(); - [DllImport("libRfid2.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort2(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid2.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion2(); + [DllImport("libRfid2.dll", EntryPoint = "openPort")] static extern unsafe int openPort2(int comPort); + [DllImport("libRfid2.dll", EntryPoint = "closePort")] static extern unsafe int closePort2(); + [DllImport("libRfid2.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort2(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); [DllImport("libRfid2.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort2(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); - [DllImport("libRfid3.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion3(); - [DllImport("libRfid3.dll", EntryPoint = "openPort")] static extern unsafe int openPort3(int comPort); - [DllImport("libRfid3.dll", EntryPoint = "closePort")] static extern unsafe int closePort3(); - [DllImport("libRfid3.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort3(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid3.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion3(); + [DllImport("libRfid3.dll", EntryPoint = "openPort")] static extern unsafe int openPort3(int comPort); + [DllImport("libRfid3.dll", EntryPoint = "closePort")] static extern unsafe int closePort3(); + [DllImport("libRfid3.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort3(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); [DllImport("libRfid3.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort3(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); - [DllImport("libRfid4.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion4(); - [DllImport("libRfid4.dll", EntryPoint = "openPort")] static extern unsafe int openPort4(int comPort); - [DllImport("libRfid4.dll", EntryPoint = "closePort")] static extern unsafe int closePort4(); - [DllImport("libRfid4.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort4(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid4.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion4(); + [DllImport("libRfid4.dll", EntryPoint = "openPort")] static extern unsafe int openPort4(int comPort); + [DllImport("libRfid4.dll", EntryPoint = "closePort")] static extern unsafe int closePort4(); + [DllImport("libRfid4.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort4(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); [DllImport("libRfid4.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort4(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid5.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion5(); + [DllImport("libRfid5.dll", EntryPoint = "openPort")] static extern unsafe int openPort5(int comPort); + [DllImport("libRfid5.dll", EntryPoint = "closePort")] static extern unsafe int closePort5(); + [DllImport("libRfid5.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort5(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid5.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort5(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid6.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion6(); + [DllImport("libRfid6.dll", EntryPoint = "openPort")] static extern unsafe int openPort6(int comPort); + [DllImport("libRfid6.dll", EntryPoint = "closePort")] static extern unsafe int closePort6(); + [DllImport("libRfid6.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort6(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid6.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort6(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid7.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion7(); + [DllImport("libRfid7.dll", EntryPoint = "openPort")] static extern unsafe int openPort7(int comPort); + [DllImport("libRfid7.dll", EntryPoint = "closePort")] static extern unsafe int closePort7(); + [DllImport("libRfid7.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort7(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid7.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort7(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid8.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion8(); + [DllImport("libRfid8.dll", EntryPoint = "openPort")] static extern unsafe int openPort8(int comPort); + [DllImport("libRfid8.dll", EntryPoint = "closePort")] static extern unsafe int closePort8(); + [DllImport("libRfid8.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort8(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid8.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort8(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid9.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion9(); + [DllImport("libRfid9.dll", EntryPoint = "openPort")] static extern unsafe int openPort9(int comPort); + [DllImport("libRfid9.dll", EntryPoint = "closePort")] static extern unsafe int closePort9(); + [DllImport("libRfid9.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort9(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid9.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort9(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid10.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion10(); + [DllImport("libRfid10.dll", EntryPoint = "openPort")] static extern unsafe int openPort10(int comPort); + [DllImport("libRfid10.dll", EntryPoint = "closePort")] static extern unsafe int closePort10(); + [DllImport("libRfid10.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort10(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid10.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort10(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid11.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion11(); + [DllImport("libRfid11.dll", EntryPoint = "openPort")] static extern unsafe int openPort11(int comPort); + [DllImport("libRfid11.dll", EntryPoint = "closePort")] static extern unsafe int closePort11(); + [DllImport("libRfid11.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort11(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid11.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort11(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid12.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion12(); + [DllImport("libRfid12.dll", EntryPoint = "openPort")] static extern unsafe int openPort12(int comPort); + [DllImport("libRfid12.dll", EntryPoint = "closePort")] static extern unsafe int closePort12(); + [DllImport("libRfid12.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort12(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid12.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort12(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid13.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion13(); + [DllImport("libRfid13.dll", EntryPoint = "openPort")] static extern unsafe int openPort13(int comPort); + [DllImport("libRfid13.dll", EntryPoint = "closePort")] static extern unsafe int closePort13(); + [DllImport("libRfid13.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort13(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid13.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort13(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid14.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion14(); + [DllImport("libRfid14.dll", EntryPoint = "openPort")] static extern unsafe int openPort14(int comPort); + [DllImport("libRfid14.dll", EntryPoint = "closePort")] static extern unsafe int closePort14(); + [DllImport("libRfid14.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort14(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid14.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort14(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid15.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion15(); + [DllImport("libRfid15.dll", EntryPoint = "openPort")] static extern unsafe int openPort15(int comPort); + [DllImport("libRfid15.dll", EntryPoint = "closePort")] static extern unsafe int closePort15(); + [DllImport("libRfid15.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort15(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid15.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort15(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid16.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion16(); + [DllImport("libRfid16.dll", EntryPoint = "openPort")] static extern unsafe int openPort16(int comPort); + [DllImport("libRfid16.dll", EntryPoint = "closePort")] static extern unsafe int closePort16(); + [DllImport("libRfid16.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort16(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid16.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort16(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid17.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion17(); + [DllImport("libRfid17.dll", EntryPoint = "openPort")] static extern unsafe int openPort17(int comPort); + [DllImport("libRfid17.dll", EntryPoint = "closePort")] static extern unsafe int closePort17(); + [DllImport("libRfid17.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort17(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid17.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort17(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid18.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion18(); + [DllImport("libRfid18.dll", EntryPoint = "openPort")] static extern unsafe int openPort18(int comPort); + [DllImport("libRfid18.dll", EntryPoint = "closePort")] static extern unsafe int closePort18(); + [DllImport("libRfid18.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort18(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid18.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort18(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid19.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion19(); + [DllImport("libRfid19.dll", EntryPoint = "openPort")] static extern unsafe int openPort19(int comPort); + [DllImport("libRfid19.dll", EntryPoint = "closePort")] static extern unsafe int closePort19(); + [DllImport("libRfid19.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort19(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid19.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort19(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid20.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion20(); + [DllImport("libRfid20.dll", EntryPoint = "openPort")] static extern unsafe int openPort20(int comPort); + [DllImport("libRfid20.dll", EntryPoint = "closePort")] static extern unsafe int closePort20(); + [DllImport("libRfid20.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort20(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid20.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort20(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid21.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion21(); + [DllImport("libRfid21.dll", EntryPoint = "openPort")] static extern unsafe int openPort21(int comPort); + [DllImport("libRfid21.dll", EntryPoint = "closePort")] static extern unsafe int closePort21(); + [DllImport("libRfid21.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort21(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid21.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort21(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid22.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion22(); + [DllImport("libRfid22.dll", EntryPoint = "openPort")] static extern unsafe int openPort22(int comPort); + [DllImport("libRfid22.dll", EntryPoint = "closePort")] static extern unsafe int closePort22(); + [DllImport("libRfid22.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort22(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid22.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort22(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid23.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion23(); + [DllImport("libRfid23.dll", EntryPoint = "openPort")] static extern unsafe int openPort23(int comPort); + [DllImport("libRfid23.dll", EntryPoint = "closePort")] static extern unsafe int closePort23(); + [DllImport("libRfid23.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort23(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid23.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort23(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid24.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion24(); + [DllImport("libRfid24.dll", EntryPoint = "openPort")] static extern unsafe int openPort24(int comPort); + [DllImport("libRfid24.dll", EntryPoint = "closePort")] static extern unsafe int closePort24(); + [DllImport("libRfid24.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort24(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid24.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort24(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid25.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion25(); + [DllImport("libRfid25.dll", EntryPoint = "openPort")] static extern unsafe int openPort25(int comPort); + [DllImport("libRfid25.dll", EntryPoint = "closePort")] static extern unsafe int closePort25(); + [DllImport("libRfid25.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort25(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid25.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort25(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid26.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion26(); + [DllImport("libRfid26.dll", EntryPoint = "openPort")] static extern unsafe int openPort26(int comPort); + [DllImport("libRfid26.dll", EntryPoint = "closePort")] static extern unsafe int closePort26(); + [DllImport("libRfid26.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort26(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid26.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort26(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid27.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion27(); + [DllImport("libRfid27.dll", EntryPoint = "openPort")] static extern unsafe int openPort27(int comPort); + [DllImport("libRfid27.dll", EntryPoint = "closePort")] static extern unsafe int closePort27(); + [DllImport("libRfid27.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort27(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid27.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort27(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid28.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion28(); + [DllImport("libRfid28.dll", EntryPoint = "openPort")] static extern unsafe int openPort28(int comPort); + [DllImport("libRfid28.dll", EntryPoint = "closePort")] static extern unsafe int closePort28(); + [DllImport("libRfid28.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort28(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid28.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort28(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid29.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion29(); + [DllImport("libRfid29.dll", EntryPoint = "openPort")] static extern unsafe int openPort29(int comPort); + [DllImport("libRfid29.dll", EntryPoint = "closePort")] static extern unsafe int closePort29(); + [DllImport("libRfid29.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort29(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid29.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort29(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid30.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion30(); + [DllImport("libRfid30.dll", EntryPoint = "openPort")] static extern unsafe int openPort30(int comPort); + [DllImport("libRfid30.dll", EntryPoint = "closePort")] static extern unsafe int closePort30(); + [DllImport("libRfid30.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort30(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid30.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort30(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid31.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion31(); + [DllImport("libRfid31.dll", EntryPoint = "openPort")] static extern unsafe int openPort31(int comPort); + [DllImport("libRfid31.dll", EntryPoint = "closePort")] static extern unsafe int closePort31(); + [DllImport("libRfid31.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort31(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid31.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort31(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid32.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion32(); + [DllImport("libRfid32.dll", EntryPoint = "openPort")] static extern unsafe int openPort32(int comPort); + [DllImport("libRfid32.dll", EntryPoint = "closePort")] static extern unsafe int closePort32(); + [DllImport("libRfid32.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort32(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid32.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort32(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid33.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion33(); + [DllImport("libRfid33.dll", EntryPoint = "openPort")] static extern unsafe int openPort33(int comPort); + [DllImport("libRfid33.dll", EntryPoint = "closePort")] static extern unsafe int closePort33(); + [DllImport("libRfid33.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort33(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid33.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort33(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid34.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion34(); + [DllImport("libRfid34.dll", EntryPoint = "openPort")] static extern unsafe int openPort34(int comPort); + [DllImport("libRfid34.dll", EntryPoint = "closePort")] static extern unsafe int closePort34(); + [DllImport("libRfid34.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort34(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid34.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort34(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid35.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion35(); + [DllImport("libRfid35.dll", EntryPoint = "openPort")] static extern unsafe int openPort35(int comPort); + [DllImport("libRfid35.dll", EntryPoint = "closePort")] static extern unsafe int closePort35(); + [DllImport("libRfid35.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort35(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid35.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort35(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid36.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion36(); + [DllImport("libRfid36.dll", EntryPoint = "openPort")] static extern unsafe int openPort36(int comPort); + [DllImport("libRfid36.dll", EntryPoint = "closePort")] static extern unsafe int closePort36(); + [DllImport("libRfid36.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort36(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid36.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort36(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid37.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion37(); + [DllImport("libRfid37.dll", EntryPoint = "openPort")] static extern unsafe int openPort37(int comPort); + [DllImport("libRfid37.dll", EntryPoint = "closePort")] static extern unsafe int closePort37(); + [DllImport("libRfid37.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort37(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid37.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort37(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid38.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion38(); + [DllImport("libRfid38.dll", EntryPoint = "openPort")] static extern unsafe int openPort38(int comPort); + [DllImport("libRfid38.dll", EntryPoint = "closePort")] static extern unsafe int closePort38(); + [DllImport("libRfid38.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort38(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid38.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort38(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid39.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion39(); + [DllImport("libRfid39.dll", EntryPoint = "openPort")] static extern unsafe int openPort39(int comPort); + [DllImport("libRfid39.dll", EntryPoint = "closePort")] static extern unsafe int closePort39(); + [DllImport("libRfid39.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort39(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid39.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort39(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + + [DllImport("libRfid40.dll", EntryPoint = "getDllVersion")] public static extern unsafe int getDllVersion40(); + [DllImport("libRfid40.dll", EntryPoint = "openPort")] static extern unsafe int openPort40(int comPort); + [DllImport("libRfid40.dll", EntryPoint = "closePort")] static extern unsafe int closePort40(); + [DllImport("libRfid40.dll", EntryPoint = "readRequestPort")] static extern unsafe int readRequestPort40(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + [DllImport("libRfid40.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort40(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + /// /// Wrapper function with safe interface and unsafe body /// - /// 0..3 /// Water meter (iPerlHead) object /// Value returned by openPort(...) - public static unsafe int OpenPort(int threadID, IperlHead iperlHead) + public static unsafe int OpenPort(IperlHead iperlHead) { if (iperlHead.DebugLevel != DebugMode.Normal) return 0; /// No function in debug mode - switch (threadID) + switch (iperlHead.Position) { default: - case 0: return openPort1(iperlHead.RfidComPortNr); - case 1: return openPort2(iperlHead.RfidComPortNr); - case 2: return openPort3(iperlHead.RfidComPortNr); - case 3: return openPort4(iperlHead.RfidComPortNr); + case 1: return openPort1(iperlHead.RfidComPortNr); + case 2: return openPort2(iperlHead.RfidComPortNr); + case 3: return openPort3(iperlHead.RfidComPortNr); + case 4: return openPort4(iperlHead.RfidComPortNr); + case 5: return openPort5(iperlHead.RfidComPortNr); + case 6: return openPort6(iperlHead.RfidComPortNr); + case 7: return openPort7(iperlHead.RfidComPortNr); + case 8: return openPort8(iperlHead.RfidComPortNr); + case 9: return openPort9(iperlHead.RfidComPortNr); + case 10: return openPort10(iperlHead.RfidComPortNr); + case 11: return openPort11(iperlHead.RfidComPortNr); + case 12: return openPort12(iperlHead.RfidComPortNr); + case 13: return openPort13(iperlHead.RfidComPortNr); + case 14: return openPort14(iperlHead.RfidComPortNr); + case 15: return openPort15(iperlHead.RfidComPortNr); + case 16: return openPort16(iperlHead.RfidComPortNr); + case 17: return openPort17(iperlHead.RfidComPortNr); + case 18: return openPort18(iperlHead.RfidComPortNr); + case 19: return openPort19(iperlHead.RfidComPortNr); + case 20: return openPort20(iperlHead.RfidComPortNr); + case 21: return openPort21(iperlHead.RfidComPortNr); + case 22: return openPort22(iperlHead.RfidComPortNr); + case 23: return openPort23(iperlHead.RfidComPortNr); + case 24: return openPort24(iperlHead.RfidComPortNr); + case 25: return openPort25(iperlHead.RfidComPortNr); + case 26: return openPort26(iperlHead.RfidComPortNr); + case 27: return openPort27(iperlHead.RfidComPortNr); + case 28: return openPort28(iperlHead.RfidComPortNr); + case 29: return openPort29(iperlHead.RfidComPortNr); + case 30: return openPort30(iperlHead.RfidComPortNr); + case 31: return openPort31(iperlHead.RfidComPortNr); + case 32: return openPort32(iperlHead.RfidComPortNr); + case 33: return openPort33(iperlHead.RfidComPortNr); + case 34: return openPort34(iperlHead.RfidComPortNr); + case 35: return openPort35(iperlHead.RfidComPortNr); + case 36: return openPort36(iperlHead.RfidComPortNr); + case 37: return openPort37(iperlHead.RfidComPortNr); + case 38: return openPort38(iperlHead.RfidComPortNr); + case 39: return openPort39(iperlHead.RfidComPortNr); + case 40: return openPort40(iperlHead.RfidComPortNr); } } /// /// Wrapper function with safe interface and unsafe body /// - /// 0..3 /// Water meter (iPerlHead) object /// Value returned by openPort(...) - public static unsafe int ClosePort(int threadID, IperlHead iperlHead) + public static unsafe int ClosePort(IperlHead iperlHead) { if (iperlHead.DebugLevel != DebugMode.Normal) return 0; /// No function in debug mode - switch (threadID) + switch (iperlHead.Position) { default: - case 0: return closePort1(); - case 1: return closePort2(); - case 2: return closePort3(); - case 3: return closePort4(); + case 1: return closePort1(); + case 2: return closePort2(); + case 3: return closePort3(); + case 4: return closePort4(); + case 5: return closePort5(); + case 6: return closePort6(); + case 7: return closePort7(); + case 8: return closePort8(); + case 9: return closePort9(); + case 10: return closePort10(); + case 11: return closePort11(); + case 12: return closePort12(); + case 13: return closePort13(); + case 14: return closePort14(); + case 15: return closePort15(); + case 16: return closePort16(); + case 17: return closePort17(); + case 18: return closePort18(); + case 19: return closePort19(); + case 20: return closePort20(); + case 21: return closePort21(); + case 22: return closePort22(); + case 23: return closePort23(); + case 24: return closePort24(); + case 25: return closePort25(); + case 26: return closePort26(); + case 27: return closePort27(); + case 28: return closePort28(); + case 29: return closePort29(); + case 30: return closePort30(); + case 31: return closePort31(); + case 32: return closePort32(); + case 33: return closePort33(); + case 34: return closePort34(); + case 35: return closePort35(); + case 36: return closePort36(); + case 37: return closePort37(); + case 38: return closePort38(); + case 39: return closePort39(); + case 40: return closePort40(); } } /// /// Wrapper function with safe interface and unsafe body /// - /// 0..3 /// Water meter (iPerlHead) object /// Value returned by readRequestPort(...) - public static unsafe int ReadRequestPort(int threadID, IperlHead iperlHead, MessageID messageID, int offset, int length, out byte[] buffer, int timeout) + public static unsafe int ReadRequestPort(IperlHead iperlHead, MessageID messageID, int offset, int length, out byte[] buffer, int timeout) { + Thread.Sleep(Math.Max(250, cfg.DelayBetweenRetries)); + if (iperlHead.DebugLevel != DebugMode.Normal) { /// @@ -214,13 +503,49 @@ namespace TBF.Rig.TestMethods.iPerlCommunication { int retv; - switch (threadID) + switch (iperlHead.Position) { default: - case 0: retv = readRequestPort1(messageID, offset, length, pBuf, timeout); break; - case 1: retv = readRequestPort2(messageID, offset, length, pBuf, timeout); break; - case 2: retv = readRequestPort3(messageID, offset, length, pBuf, timeout); break; - case 3: retv = readRequestPort4(messageID, offset, length, pBuf, timeout); break; + case 1: retv = readRequestPort1(messageID, offset, length, pBuf, timeout); break; + case 2: retv = readRequestPort2(messageID, offset, length, pBuf, timeout); break; + case 3: retv = readRequestPort3(messageID, offset, length, pBuf, timeout); break; + case 4: retv = readRequestPort4(messageID, offset, length, pBuf, timeout); break; + case 5: retv = readRequestPort5(messageID, offset, length, pBuf, timeout); break; + case 6: retv = readRequestPort6(messageID, offset, length, pBuf, timeout); break; + case 7: retv = readRequestPort7(messageID, offset, length, pBuf, timeout); break; + case 8: retv = readRequestPort8(messageID, offset, length, pBuf, timeout); break; + case 9: retv = readRequestPort9(messageID, offset, length, pBuf, timeout); break; + case 10: retv = readRequestPort10(messageID, offset, length, pBuf, timeout); break; + case 11: retv = readRequestPort11(messageID, offset, length, pBuf, timeout); break; + case 12: retv = readRequestPort12(messageID, offset, length, pBuf, timeout); break; + case 13: retv = readRequestPort13(messageID, offset, length, pBuf, timeout); break; + case 14: retv = readRequestPort14(messageID, offset, length, pBuf, timeout); break; + case 15: retv = readRequestPort15(messageID, offset, length, pBuf, timeout); break; + case 16: retv = readRequestPort16(messageID, offset, length, pBuf, timeout); break; + case 17: retv = readRequestPort17(messageID, offset, length, pBuf, timeout); break; + case 18: retv = readRequestPort18(messageID, offset, length, pBuf, timeout); break; + case 19: retv = readRequestPort19(messageID, offset, length, pBuf, timeout); break; + case 20: retv = readRequestPort20(messageID, offset, length, pBuf, timeout); break; + case 21: retv = readRequestPort21(messageID, offset, length, pBuf, timeout); break; + case 22: retv = readRequestPort22(messageID, offset, length, pBuf, timeout); break; + case 23: retv = readRequestPort23(messageID, offset, length, pBuf, timeout); break; + case 24: retv = readRequestPort24(messageID, offset, length, pBuf, timeout); break; + case 25: retv = readRequestPort25(messageID, offset, length, pBuf, timeout); break; + case 26: retv = readRequestPort26(messageID, offset, length, pBuf, timeout); break; + case 27: retv = readRequestPort27(messageID, offset, length, pBuf, timeout); break; + case 28: retv = readRequestPort28(messageID, offset, length, pBuf, timeout); break; + case 29: retv = readRequestPort29(messageID, offset, length, pBuf, timeout); break; + case 30: retv = readRequestPort30(messageID, offset, length, pBuf, timeout); break; + case 31: retv = readRequestPort31(messageID, offset, length, pBuf, timeout); break; + case 32: retv = readRequestPort32(messageID, offset, length, pBuf, timeout); break; + case 33: retv = readRequestPort33(messageID, offset, length, pBuf, timeout); break; + case 34: retv = readRequestPort34(messageID, offset, length, pBuf, timeout); break; + case 35: retv = readRequestPort35(messageID, offset, length, pBuf, timeout); break; + case 36: retv = readRequestPort36(messageID, offset, length, pBuf, timeout); break; + case 37: retv = readRequestPort37(messageID, offset, length, pBuf, timeout); break; + case 38: retv = readRequestPort38(messageID, offset, length, pBuf, timeout); break; + case 39: retv = readRequestPort39(messageID, offset, length, pBuf, timeout); break; + case 40: retv = readRequestPort40(messageID, offset, length, pBuf, timeout); break; } for (int i = 0; i < length; i++) buffer[i] = buf[i]; @@ -249,31 +574,65 @@ namespace TBF.Rig.TestMethods.iPerlCommunication } /// - /// Wrapper function with safe interface adn unsafe body + /// Wrapper function with safe interface and unsafe body /// - /// 0..3 /// Water meter (iPerlHead) object /// Value returned by writeRequestPort(...) - public static unsafe int WriteRequestPort(int threadID, IperlHead iperlHead, MessageID messageID, int offset, int length, byte[] buffer, int timeout) + public static unsafe int WriteRequestPort(IperlHead iperlHead, MessageID messageID, int offset, int length, byte[] buffer, int timeout) { + Thread.Sleep(Math.Max(250, cfg.DelayBetweenRetries)); + if (iperlHead.DebugLevel != DebugMode.Normal) return 0; fixed (byte* pBuf = buffer) { int retv; - switch (threadID) + switch (iperlHead.Position) { default: - case 0: retv = writeRequestPort1(messageID, offset, length, pBuf, timeout); break; - case 1: retv = writeRequestPort2(messageID, offset, length, pBuf, timeout); break; - case 2: retv = writeRequestPort3(messageID, offset, length, pBuf, timeout); break; - case 3: retv = writeRequestPort4(messageID, offset, length, pBuf, timeout); break; + case 1: retv = writeRequestPort1(messageID, offset, length, pBuf, timeout); break; + case 2: retv = writeRequestPort2(messageID, offset, length, pBuf, timeout); break; + case 3: retv = writeRequestPort3(messageID, offset, length, pBuf, timeout); break; + case 4: retv = writeRequestPort4(messageID, offset, length, pBuf, timeout); break; + case 5: retv = writeRequestPort5(messageID, offset, length, pBuf, timeout); break; + case 6: retv = writeRequestPort6(messageID, offset, length, pBuf, timeout); break; + case 7: retv = writeRequestPort7(messageID, offset, length, pBuf, timeout); break; + case 8: retv = writeRequestPort8(messageID, offset, length, pBuf, timeout); break; + case 9: retv = writeRequestPort9(messageID, offset, length, pBuf, timeout); break; + case 10: retv = writeRequestPort10(messageID, offset, length, pBuf, timeout); break; + case 11: retv = writeRequestPort11(messageID, offset, length, pBuf, timeout); break; + case 12: retv = writeRequestPort12(messageID, offset, length, pBuf, timeout); break; + case 13: retv = writeRequestPort13(messageID, offset, length, pBuf, timeout); break; + case 14: retv = writeRequestPort14(messageID, offset, length, pBuf, timeout); break; + case 15: retv = writeRequestPort15(messageID, offset, length, pBuf, timeout); break; + case 16: retv = writeRequestPort16(messageID, offset, length, pBuf, timeout); break; + case 17: retv = writeRequestPort17(messageID, offset, length, pBuf, timeout); break; + case 18: retv = writeRequestPort18(messageID, offset, length, pBuf, timeout); break; + case 19: retv = writeRequestPort19(messageID, offset, length, pBuf, timeout); break; + case 20: retv = writeRequestPort20(messageID, offset, length, pBuf, timeout); break; + case 21: retv = writeRequestPort21(messageID, offset, length, pBuf, timeout); break; + case 22: retv = writeRequestPort22(messageID, offset, length, pBuf, timeout); break; + case 23: retv = writeRequestPort23(messageID, offset, length, pBuf, timeout); break; + case 24: retv = writeRequestPort24(messageID, offset, length, pBuf, timeout); break; + case 25: retv = writeRequestPort25(messageID, offset, length, pBuf, timeout); break; + case 26: retv = writeRequestPort26(messageID, offset, length, pBuf, timeout); break; + case 27: retv = writeRequestPort27(messageID, offset, length, pBuf, timeout); break; + case 28: retv = writeRequestPort28(messageID, offset, length, pBuf, timeout); break; + case 29: retv = writeRequestPort29(messageID, offset, length, pBuf, timeout); break; + case 30: retv = writeRequestPort30(messageID, offset, length, pBuf, timeout); break; + case 31: retv = writeRequestPort31(messageID, offset, length, pBuf, timeout); break; + case 32: retv = writeRequestPort32(messageID, offset, length, pBuf, timeout); break; + case 33: retv = writeRequestPort33(messageID, offset, length, pBuf, timeout); break; + case 34: retv = writeRequestPort34(messageID, offset, length, pBuf, timeout); break; + case 35: retv = writeRequestPort35(messageID, offset, length, pBuf, timeout); break; + case 36: retv = writeRequestPort36(messageID, offset, length, pBuf, timeout); break; + case 37: retv = writeRequestPort37(messageID, offset, length, pBuf, timeout); break; + case 38: retv = writeRequestPort38(messageID, offset, length, pBuf, timeout); break; + case 39: retv = writeRequestPort39(messageID, offset, length, pBuf, timeout); break; + case 40: retv = writeRequestPort40(messageID, offset, length, pBuf, timeout); break; } - /// Delay min. 250 ms - Thread.Sleep(Math.Max(250, cfg.DelayBetweenRetries)); - /// /// Logging /// @@ -756,9 +1115,34 @@ namespace TBF.Rig.TestMethods.iPerlCommunication if (threadID == 0) { - rfidDataLogger.InfoFormat(""); /// Makes the log more readable when there is a lot of data + /// Check whether previous activity was 'Set test mode A0' or 'A4' + if (i > 0 && multiTestParams[i - 1].Activity.ToLower().Contains(SetTestModeStr.ToLower()) && !multiTestParams[i - 1].Activity.Contains("80")) + { + /// Start processing of opto-datastreams from all iPERL-s + int count = 0; + for (int wmNr0 = 0; wmNr0 < iperlHeads.Count; wmNr0++) + { + Results.Entities.WaterMeter wm = (ProcessData.BatchRslts.Batch.WaterMeters != null && ProcessData.BatchRslts.Batch.WaterMeters.Count > wmNr0) + ? ProcessData.BatchRslts.Batch.WaterMeters[wmNr0] : null; + + IperlHead ihead = iperlHeads[wmNr0]; + + if (ihead != null && wm != null && !wm.Disabled) + { + lock (ihead) + { + ihead.StartDataStreamProcessing(); + count++; + } + } + } + log.WarnFormat("End of activity '{0}', StartDataStreamProcessing() of {1} heads was called.", multiTestParams[i - 1].Activity, count); + } + + /// A new activity starts - information into RFID data log + rfidDataLogger.InfoFormat(""); rfidDataLogger.WarnFormat("Activity = {0}", currentActivity); - rfidDataLogger.InfoFormat(""); /// Makes the log more readable when there is a lot of data + rfidDataLogger.InfoFormat(""); } for (int group = 1; group <= lastGroup; group++) @@ -813,9 +1197,9 @@ namespace TBF.Rig.TestMethods.iPerlCommunication /// RFID communication functions below require a reference to water meter entity (wm != null) /// else if (wm == null) error = CommErr.CommFailed; - else if (currentActivity.ToLower().Contains(ReadConfigurationStr.ToLower())) error = ReadConfiguration(threadID, ihead, wm, ref resultStr); - else if (currentActivity.ToLower() == ReadCalibrationStr.ToLower()) error = ReadCalibration(threadID, ihead, wm, ref resultStr); - else if (currentActivity.ToLower() == ReadCalibrationV4Str.ToLower()) error = ReadCalibrationV4(threadID, ihead, wm, ref resultStr); + else if (currentActivity.ToLower().Contains(ReadConfigurationStr.ToLower())) error = ReadConfiguration(ihead, wm, ref resultStr); + else if (currentActivity.ToLower() == ReadCalibrationStr.ToLower()) error = ReadCalibration(ihead, wm, ref resultStr); + else if (currentActivity.ToLower() == ReadCalibrationV4Str.ToLower()) error = ReadCalibrationV4(ihead, wm, ref resultStr); else if (currentActivity.ToLower().Contains(WriteCalibrationFactorStr.ToLower())) error = WriteCalibrationFactor(threadID, ihead, wm, ref resultStr); else if (currentActivity.ToLower().Contains(WriteCalibrationV4FactorsStr.ToLower())) error = WriteCalibrationV4Factors(threadID, ihead, wm, ref resultStr); else if (currentActivity.ToLower() == NormalizeCalibrationFactorStr.ToLower()) error = NormalizeCalibrationFactor(threadID, ihead, wm, ref resultStr); @@ -843,6 +1227,8 @@ namespace TBF.Rig.TestMethods.iPerlCommunication else if (currentActivity.ToLower() == Reset2HzCorrectionStr.ToLower()) error = Reset2HzCorrection(threadID, ihead, wm, ref resultStr); else if (currentActivity.ToLower() == Write2HzCorrectionStr.ToLower()) error = Write2HzCorrection(threadID, ihead, wm, ref resultStr); else if (currentActivity.ToLower() == GetDefaultQ2CorrectionsStr.ToLower()) error = GetQ2PreCorrectionsFormRest(threadID, ihead, wm, ref resultStr); + else if (currentActivity.ToLower() == DewaReworkRLStr.ToLower()) error = DewaRework(ihead, wm, FlowDir.R_L, ref resultStr); + else if (currentActivity.ToLower() == DewaReworkLRStr.ToLower()) error = DewaRework(ihead, wm, FlowDir.L_R, ref resultStr); #endif else @@ -864,7 +1250,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication } else if ((error == CommErr.OutOfRange) || (error == CommErr.Q2OutOfRange)) { - OnCommCompleted(null, new CommCompletedEventArgs(threadID, wmNr0, ihead, wm, resultStr, CommErr.None)); + OnCommCompleted(null, new CommCompletedEventArgs(threadID, wmNr0, ihead, wm, resultStr, CommErr.CommFailed)); } else if (ihead.CommFailed || (error == CommErr.CommFailed)) { @@ -923,12 +1309,11 @@ namespace TBF.Rig.TestMethods.iPerlCommunication /// /// Read a complete configuration structure of the watermeter /// - /// Thread ID passed to RFID communication functions /// iPERL head object /// Water meter object /// String passed to caller /// true on success - static CommErr ReadConfiguration(int threadId, IperlHead ihead, Results.Entities.WaterMeter wm, ref string resultStr) + static CommErr ReadConfiguration(IperlHead ihead, Results.Entities.WaterMeter wm, ref string resultStr) { /// /// The activity is "Read configuration" (this enables the watermeter, resets error flag) @@ -943,7 +1328,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication ihead.ConfigStruct = null; /// Clear previous ConfigStruct, avoid reuse of (not anymore valid) PCB Number - if (OpenPort(threadId, ihead) != 0) return CommErr.OpenPort; /// Open RFID port + if (OpenPort(ihead) != 0) return CommErr.OpenPort; /// Open RFID port CommErr error = CommErr.Read; int readRetVal = 0; @@ -952,7 +1337,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication byte[] config = null; for (int j = 0; j < cfg.MaxCommRetries; j++) { - readRetVal = ReadRequestPort(threadId, ihead, MessageID.Configuration, 0, ConfigStruct.Length, out config, cfg.CommTimeout); + readRetVal = ReadRequestPort(ihead, MessageID.Configuration, 0, ConfigStruct.Length, out config, cfg.CommTimeout); if (readRetVal == 0) { error = CommErr.None; @@ -965,7 +1350,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication if (cfg.DelayBetweenRetries > 0) Thread.Sleep(cfg.DelayBetweenRetries); } - ClosePort(threadId, ihead); /// Close RFID port + ClosePort(ihead); /// Close RFID port return error + Math.Max(0, Math.Min(readRetVal, 4)); } @@ -1005,7 +1390,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication } /// Communication necessary - if (OpenPort(threadId, ihead) != 0) return CommErr.OpenPort; /// Open RFID port + if (OpenPort(ihead) != 0) return CommErr.OpenPort; /// Open RFID port CommErr error = CommErr.None; @@ -1016,7 +1401,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication byte[] cmd = new byte[1] { (byte)Command.SetActiveMode }; for (int j = 0; j < cfg.MaxCommRetries; j++) { - if (0 == WriteRequestPort(threadId, ihead, MessageID.Command, 0, 1, cmd, cfg.CommTimeout)) + if (0 == WriteRequestPort(ihead, MessageID.Command, 0, 1, cmd, cfg.CommTimeout)) { error = CommErr.None; break; @@ -1037,7 +1422,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication byte[] tstMdCfg = new byte[1] { testModeConfig }; for (int j = 0; j < cfg.MaxCommRetries; j++) { - if (0 == WriteRequestPort(threadId, ihead, MessageID.Configuration, 21, 1, tstMdCfg, cfg.CommTimeout)) + if (0 == WriteRequestPort(ihead, MessageID.Configuration, 21, 1, tstMdCfg, cfg.CommTimeout)) { ihead.ConfigStruct.Update(21, tstMdCfg); error = CommErr.None; @@ -1059,7 +1444,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication byte[] cmd = new byte[1] { (byte)Command.SetTestMode }; for (int j = 0; j < cfg.MaxCommRetries; j++) { - if (0 == WriteRequestPort(threadId, ihead, MessageID.Command, 0, 1, cmd, cfg.CommTimeout)) + if (0 == WriteRequestPort(ihead, MessageID.Command, 0, 1, cmd, cfg.CommTimeout)) { error = CommErr.None; break; @@ -1081,7 +1466,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication byte[] config = null; for (int j = 0; j < cfg.MaxCommRetries; j++) { - if (0 == ReadRequestPort(threadId, ihead, MessageID.Configuration, 0, ConfigStruct.Length, out config, cfg.CommTimeout)) + if (0 == ReadRequestPort(ihead, MessageID.Configuration, 0, ConfigStruct.Length, out config, cfg.CommTimeout)) { ihead.ConfigStruct = ConfigStruct.FromByteArray(config); if ((ihead.ConfigStruct.MeterState == MeterState.Test) && (ihead.ConfigStruct.TestModeConfig == testModeConfig)) @@ -1097,7 +1482,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication } } - ClosePort(threadId, ihead); /// Close RFID port + ClosePort(ihead); /// Close RFID port return error; } @@ -1112,7 +1497,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication /// true on success static CommErr SetActiveMode(int threadId, IperlHead ihead, ref string resultStr) { - if (OpenPort(threadId, ihead) != 0) return CommErr.OpenPort; /// Open RFID port + if (OpenPort(ihead) != 0) return CommErr.OpenPort; /// Open RFID port CommErr error = CommErr.CmdActive; @@ -1120,7 +1505,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication byte[] cmd = new byte[1] { (byte)Command.SetActiveMode }; for (int j = 0; j < cfg.MaxCommRetries; j++) { - if (0 == WriteRequestPort(threadId, ihead, MessageID.Command, 0, 1, cmd, cfg.CommTimeout)) + if (0 == WriteRequestPort(ihead, MessageID.Command, 0, 1, cmd, cfg.CommTimeout)) { error = CommErr.None; break; @@ -1167,7 +1552,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication } #endif - ClosePort(threadId, ihead); /// Close RFID port + ClosePort(ihead); /// Close RFID port return error; } @@ -1179,11 +1564,11 @@ namespace TBF.Rig.TestMethods.iPerlCommunication /// Water meter object /// String passed to caller /// true on success - static CommErr ReadCalibration(int threadId, IperlHead ihead, Results.Entities.WaterMeter wm, ref string resultStr) + static CommErr ReadCalibration(IperlHead ihead, Results.Entities.WaterMeter wm, ref string resultStr) { if (ihead.CommFailed) return CommErr.CommFailed; - if (OpenPort(threadId, ihead) != 0) return CommErr.OpenPort; /// Open RFID port + if (OpenPort(ihead) != 0) return CommErr.OpenPort; /// Open RFID port CommErr error = CommErr.Read; int readRetVal = 0; @@ -1192,7 +1577,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication byte[] calib = null; for (int j = 0; j < cfg.MaxCommRetries; j++) { - readRetVal = ReadRequestPort(threadId, ihead, MessageID.Calibration, 0, CalibrationStruct.Length, out calib, cfg.CommTimeout); + readRetVal = ReadRequestPort(ihead, MessageID.Calibration, 0, CalibrationStruct.Length, out calib, cfg.CommTimeout); if (readRetVal == 0) { ihead.CalibrationStruct = CalibrationStruct.FromByteArray(calib); @@ -1212,7 +1597,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication if (cfg.DelayBetweenRetries > 0) Thread.Sleep(cfg.DelayBetweenRetries); } - ClosePort(threadId, ihead); /// Close RFID port + ClosePort(ihead); /// Close RFID port return error + Math.Max(0, Math.Min(readRetVal, 4)); } @@ -1224,11 +1609,11 @@ namespace TBF.Rig.TestMethods.iPerlCommunication /// Water meter object /// String passed to caller /// true on success - static CommErr ReadCalibrationV4(int threadId, IperlHead ihead, Results.Entities.WaterMeter wm, ref string resultStr) + static CommErr ReadCalibrationV4(IperlHead ihead, Results.Entities.WaterMeter wm, ref string resultStr) { if (ihead.CommFailed) return CommErr.CommFailed; - if (OpenPort(threadId, ihead) != 0) return CommErr.OpenPort; /// Open RFID port + if (OpenPort(ihead) != 0) return CommErr.OpenPort; /// Open RFID port CommErr error = CommErr.Read; int readRetVal = 0; @@ -1237,7 +1622,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication byte[] calib = null; for (int j = 0; j < cfg.MaxCommRetries; j++) { - readRetVal = ReadRequestPort(threadId, ihead, MessageID.Calibration, 0, CalibrationStructV4.Length, out calib, cfg.CommTimeout); + readRetVal = ReadRequestPort(ihead, MessageID.Calibration, 0, CalibrationStructV4.Length, out calib, cfg.CommTimeout); if (readRetVal == 0) { ihead.CalibrationStructV4 = CalibrationStructV4.FromByteArray(calib); @@ -1258,7 +1643,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication if (cfg.DelayBetweenRetries > 0) Thread.Sleep(cfg.DelayBetweenRetries); } - ClosePort(threadId, ihead); /// Close RFID port + ClosePort(ihead); /// Close RFID port return error + Math.Max(0, Math.Min(readRetVal, 4)); } @@ -1367,7 +1752,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication /// /// Start communication with iPerl /// - if (OpenPort(threadId, ihead) != 0) return CommErr.OpenPort; /// Open RFID port + if (OpenPort(ihead) != 0) return CommErr.OpenPort; /// Open RFID port CommErr error; byte[] data = new byte[2] { (byte)(newCalibFactor & 0x00FF), (byte)((newCalibFactor >> 8) & 0x00FF) }; @@ -1378,14 +1763,14 @@ namespace TBF.Rig.TestMethods.iPerlCommunication /// Write the new calibration factor (up to cfg.MaxCommRetries tims) /// error = CommErr.Write; - if (0 == WriteRequestPort(threadId, ihead, MessageID.Calibration, 2, 2, data, cfg.CommTimeout)) + if (0 == WriteRequestPort(ihead, MessageID.Calibration, 2, 2, data, cfg.CommTimeout)) { /// /// Read and verify the calibration factor /// error = CommErr.ReadAfterWrite; byte[] calib_2_3 = null; - if (0 == ReadRequestPort(threadId, ihead, MessageID.Calibration, 2, 2, out calib_2_3, cfg.CommTimeout)) + if (0 == ReadRequestPort(ihead, MessageID.Calibration, 2, 2, out calib_2_3, cfg.CommTimeout)) { error = CommErr.Verify; if (calib_2_3 != null && calib_2_3.Length == 2 && data[0] == calib_2_3[0] && data[1] == calib_2_3[1]) @@ -1403,7 +1788,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication } while (++writeAndVerifyRetries <= cfg.MaxCommRetries); - ClosePort(threadId, ihead); /// Close RFID port + ClosePort(ihead); /// Close RFID port return error; } @@ -1533,7 +1918,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication /// /// Start communication with iPerl /// - if (OpenPort(threadId, ihead) != 0) return CommErr.OpenPort; /// Open RFID port + if (OpenPort(ihead) != 0) return CommErr.OpenPort; /// Open RFID port CommErr error; byte[] data = new byte[2] { (byte)(newCalibFactor & 0x00FF), (byte)((newCalibFactor >> 8) & 0x00FF) }; @@ -1545,8 +1930,8 @@ namespace TBF.Rig.TestMethods.iPerlCommunication /// Write the new calibration factor (up to cfg.MaxCommRetries tims) /// error = CommErr.Write; - if (0 == WriteRequestPort(threadId, ihead, MessageID.Calibration, 2, 2, data, cfg.CommTimeout) && - 0 == WriteRequestPort(threadId, ihead, MessageID.Calibration, 34, 2, dataLNA, cfg.CommTimeout)) + if (0 == WriteRequestPort(ihead, MessageID.Calibration, 2, 2, data, cfg.CommTimeout) && + 0 == WriteRequestPort(ihead, MessageID.Calibration, 34, 2, dataLNA, cfg.CommTimeout)) { /// /// Read and verify the calibration factor @@ -1554,8 +1939,8 @@ namespace TBF.Rig.TestMethods.iPerlCommunication error = CommErr.ReadAfterWrite; byte[] calib_2_3 = null; byte[] calib_34_35 = null; - if (0 == ReadRequestPort(threadId, ihead, MessageID.Calibration, 2, 2, out calib_2_3, cfg.CommTimeout) && - 0 == ReadRequestPort(threadId, ihead, MessageID.Calibration, 34, 2, out calib_34_35, cfg.CommTimeout)) + if (0 == ReadRequestPort(ihead, MessageID.Calibration, 2, 2, out calib_2_3, cfg.CommTimeout) && + 0 == ReadRequestPort(ihead, MessageID.Calibration, 34, 2, out calib_34_35, cfg.CommTimeout)) { error = CommErr.Verify; if (calib_2_3 != null && calib_2_3.Length == 2 && data[0] == calib_2_3[0] && data[1] == calib_2_3[1] && @@ -1585,7 +1970,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication } while (writeAndVerifyRetries <= cfg.MaxCommRetries); - ClosePort(threadId, ihead); /// Close RFID port + ClosePort(ihead); /// Close RFID port return error; } @@ -1639,7 +2024,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication return CommErr.None; /// No need to update the calibration factor } - if (OpenPort(threadId, ihead) != 0) return CommErr.OpenPort; /// Open RFID port + if (OpenPort(ihead) != 0) return CommErr.OpenPort; /// Open RFID port CommErr error = CommErr.Write; @@ -1672,7 +2057,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication byte[] data = new byte[2] { (byte)(defaultCalibFactor & 0x00FF), (byte)((defaultCalibFactor >> 8) & 0x00FF) }; for (int j = 0; j < cfg.MaxCommRetries; j++) { - if (0 == WriteRequestPort(threadId, ihead, MessageID.Calibration, 2, 2, data, cfg.CommTimeout)) + if (0 == WriteRequestPort(ihead, MessageID.Calibration, 2, 2, data, cfg.CommTimeout)) { error = CommErr.None; ihead.CalibrationStruct.Update(data, 2); @@ -1691,7 +2076,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication byte[] calib_2_3 = null; for (int j = 0; j < cfg.MaxCommRetries; j++) { - if (0 == ReadRequestPort(threadId, ihead, MessageID.Calibration, 2, 2, out calib_2_3, cfg.CommTimeout)) + if (0 == ReadRequestPort(ihead, MessageID.Calibration, 2, 2, out calib_2_3, cfg.CommTimeout)) { error = CommErr.None; ihead.CalibrationStruct.Update(calib_2_3, 2); @@ -1704,7 +2089,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication } } - ClosePort(threadId, ihead); /// Close RFID port + ClosePort(ihead); /// Close RFID port return error; } @@ -1726,7 +2111,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication return CommErr.None; /// No need to update the calibration factor } - if (OpenPort(threadId, ihead) != 0) return CommErr.OpenPort; /// Open RFID port + if (OpenPort(ihead) != 0) return CommErr.OpenPort; /// Open RFID port CommErr error = CommErr.Write; @@ -1759,7 +2144,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication byte[] data = new byte[2] { (byte)(defaultCalibFactor & 0x00FF), (byte)((defaultCalibFactor >> 8) & 0x00FF) }; for (int j = 0; j < cfg.MaxCommRetries; j++) { - if (0 == WriteRequestPort(threadId, ihead, MessageID.Calibration, 2, 2, data, cfg.CommTimeout)) + if (0 == WriteRequestPort(ihead, MessageID.Calibration, 2, 2, data, cfg.CommTimeout)) { error = CommErr.None; ihead.CalibrationStructV4.Update(data, 2); @@ -1778,7 +2163,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication byte[] calib_2_3 = null; for (int j = 0; j < cfg.MaxCommRetries; j++) { - if (0 == ReadRequestPort(threadId, ihead, MessageID.Calibration, 2, 2, out calib_2_3, cfg.CommTimeout)) + if (0 == ReadRequestPort(ihead, MessageID.Calibration, 2, 2, out calib_2_3, cfg.CommTimeout)) { error = CommErr.None; ihead.CalibrationStructV4.Update(calib_2_3, 2); @@ -1791,7 +2176,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication } } - ClosePort(threadId, ihead); /// Close RFID port + ClosePort(ihead); /// Close RFID port return error; } @@ -1808,7 +2193,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication { if (ihead.CommFailed) return CommErr.CommFailed; - if (OpenPort(threadId, ihead) != 0) return CommErr.OpenPort; /// Open RFID port + if (OpenPort(ihead) != 0) return CommErr.OpenPort; /// Open RFID port CommErr error = CommErr.Read; @@ -1817,7 +2202,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication /// for (int j = 0; j < cfg.MaxCommRetries; j++) { - if (0 == ReadRequestPort(threadId, ihead, MessageID.MetrologyMemory, Q2CorrFactorsAddr, 2, out rdData, cfg.CommTimeout)) + if (0 == ReadRequestPort(ihead, MessageID.MetrologyMemory, Q2CorrFactorsAddr, 2, out rdData, cfg.CommTimeout)) { error = CommErr.None; break; @@ -1834,7 +2219,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication wm.Q2CorrRL = ihead.Q2CorrRL = (int)((SByte)rdData[1]); } - ClosePort(threadId, ihead); /// Close RFID port + ClosePort(ihead); /// Close RFID port return error; } @@ -1918,7 +2303,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication { if (ihead.CommFailed) return CommErr.CommFailed; - if (OpenPort(threadId, ihead) != 0) return CommErr.OpenPort; /// Open RFID port + if (OpenPort(ihead) != 0) return CommErr.OpenPort; /// Open RFID port CommErr error = CommErr.Write; @@ -1927,7 +2312,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication /// for (int j = 0; j < cfg.MaxCommRetries; j++) { - if (0 == WriteRequestPort(threadId, ihead, MessageID.MetrologyMemory, Q2CorrFactorsAddr, wrData.Length, wrData, cfg.CommTimeout)) + if (0 == WriteRequestPort(ihead, MessageID.MetrologyMemory, Q2CorrFactorsAddr, wrData.Length, wrData, cfg.CommTimeout)) { wm.Q2CorrRL = ihead.Q2CorrRL = factorRL; wm.Q2CorrLR = ihead.Q2CorrLR = factorLR; @@ -1971,7 +2356,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication } #endif - ClosePort(threadId, ihead); /// Close RFID port + ClosePort(ihead); /// Close RFID port return error; } @@ -2044,7 +2429,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication { if (ihead.CommFailed) return CommErr.CommFailed; - if (OpenPort(threadId, ihead) != 0) return CommErr.OpenPort; /// Open RFID port + if (OpenPort(ihead) != 0) return CommErr.OpenPort; /// Open RFID port CommErr error = CommErr.Write; @@ -2053,7 +2438,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication /// for (int j = 0; j < cfg.MaxCommRetries; j++) { - if (0 == WriteRequestPort(threadId, ihead, MessageID.MetrologyMemory, Hz2CorrFactorsAddr, wrData.Length, wrData, cfg.CommTimeout)) + if (0 == WriteRequestPort(ihead, MessageID.MetrologyMemory, Hz2CorrFactorsAddr, wrData.Length, wrData, cfg.CommTimeout)) { error = CommErr.None; break; @@ -2097,7 +2482,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication } #endif - ClosePort(threadId, ihead); /// Close RFID port + ClosePort(ihead); /// Close RFID port return error; } @@ -2352,7 +2737,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication /// if (ihead.CommFailed) return CommErr.CommFailed; - if (OpenPort(threadId, ihead) != 0) return CommErr.OpenPort; /// Open RFID port + if (OpenPort(ihead) != 0) return CommErr.OpenPort; /// Open RFID port CommErr error = CommErr.Write; if (q2CorrType == Q2CorrType.RL || q2CorrType == Q2CorrType.RL_incl_05 || q2CorrType == Q2CorrType.ConditionalUpdateRL) { @@ -2362,7 +2747,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication byte[] wrData = new byte[1] { (byte)q2CorrRL }; for (int j = 0; j < cfg.MaxCommRetries; j++) { - if (0 == WriteRequestPort(threadId, ihead, MessageID.MetrologyMemory, Q2CorrFactorsAddrRL, wrData.Length, wrData, cfg.CommTimeout)) + if (0 == WriteRequestPort(ihead, MessageID.MetrologyMemory, Q2CorrFactorsAddrRL, wrData.Length, wrData, cfg.CommTimeout)) { error = CommErr.None; wm.Q2CorrRL = ihead.Q2CorrRL = q2CorrRL; @@ -2381,7 +2766,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication byte[] wrData = new byte[1] { (byte)q2CorrLR }; for (int j = 0; j < cfg.MaxCommRetries; j++) { - if (0 == WriteRequestPort(threadId, ihead, MessageID.MetrologyMemory, Q2CorrFactorsAddrLR, wrData.Length, wrData, cfg.CommTimeout)) + if (0 == WriteRequestPort(ihead, MessageID.MetrologyMemory, Q2CorrFactorsAddrLR, wrData.Length, wrData, cfg.CommTimeout)) { error = CommErr.None; wm.Q2CorrLR = ihead.Q2CorrLR = q2CorrLR; @@ -2400,7 +2785,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication byte[] wrData = new byte[2] { (byte)q2CorrLR, (byte)q2CorrRL }; for (int j = 0; j < cfg.MaxCommRetries; j++) { - if (0 == WriteRequestPort(threadId, ihead, MessageID.MetrologyMemory, Q2CorrFactorsAddr, wrData.Length, wrData, cfg.CommTimeout)) + if (0 == WriteRequestPort(ihead, MessageID.MetrologyMemory, Q2CorrFactorsAddr, wrData.Length, wrData, cfg.CommTimeout)) { error = CommErr.None; wm.Q2CorrRL = ihead.Q2CorrRL = q2CorrRL; @@ -2470,7 +2855,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication } #endif - ClosePort(threadId, ihead); /// Close RFID port + ClosePort(ihead); /// Close RFID port return error; } @@ -2497,7 +2882,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication return CommErr.None; } - if (OpenPort(threadId, ihead) != 0) return CommErr.OpenPort; /// Open RFID port + if (OpenPort(ihead) != 0) return CommErr.OpenPort; /// Open RFID port CommErr error = CommErr.Write; @@ -2506,7 +2891,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication /// for (int j = 0; j < cfg.MaxCommRetries; j++) { - if (0 == WriteRequestPort(threadId, ihead, MessageID.MetrologyMemory, Hz2CorrFactorsAddr, wrData.Length, wrData, cfg.CommTimeout)) + if (0 == WriteRequestPort(ihead, MessageID.MetrologyMemory, Hz2CorrFactorsAddr, wrData.Length, wrData, cfg.CommTimeout)) { error = CommErr.None; wm.Hz2Correction = ihead.Hz2Correction = hz2CorrectionFactor; @@ -2557,11 +2942,89 @@ namespace TBF.Rig.TestMethods.iPerlCommunication } #endif - ClosePort(threadId, ihead); /// Close RFID port + ClosePort(ihead); /// Close RFID port return error; } + + /// + /// DEWA rework. + /// + /// iPERL head object + /// Water meter object + /// String passed to caller + /// true on success + static CommErr DewaRework(IperlHead ihead, Results.Entities.WaterMeter wm, FlowDir flowDir, ref string resultStr) + { + if (ihead.CommFailed) return CommErr.CommFailed; + + if (OpenPort(ihead) != 0) return CommErr.OpenPort; /// Open RFID port + + 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[] + { + 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, + (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"), + }; + + int successfyllyWrittenFlags = 0; /// Ones in this word represent communication failures, LSB represents the first step + int mask = 1; + foreach (var wData in dataToBeWritten) + { + bool isSuccessfullyWritten = false; + for (int j = 0; j < cfg.MaxCommRetries; j++) + { + if (0 == WriteRequestPort(ihead, wData.MessageID, wData.Offset, wData.Data.Length, wData.Data, cfg.CommTimeout)) + { + isSuccessfullyWritten = true; + break; + } + + /// Delay between retries + if (cfg.DelayBetweenRetries > 0) Thread.Sleep(cfg.DelayBetweenRetries); + } + + if (!isSuccessfullyWritten) + { + /// Communication failed in this step + successfyllyWrittenFlags = (successfyllyWrittenFlags | mask); + } + + mask = (mask << 1); /// Adjust the mask for the next step + } + + ClosePort(ihead); /// Close RFID port + + if (successfyllyWrittenFlags == 0) + { + /// Success + if (ihead.ConfigStruct != null) + { + ihead.ConfigStruct.MeterState = MeterState.Active; + ihead.ConfigStruct.TestModeConfig = (byte)0xA0; + } + + resultStr = "OK"; + return CommErr.None; + } + else + { + return CommErr.Write; + } + } + + static CommErr GetQ2PreCorrectionsFormRest(int threadId, IperlHead ihead, Results.Entities.WaterMeter wm, ref string resultStr) { if (!ProcessData.IsQ2PreCorrectionCalculated) @@ -2745,7 +3208,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication for (int i = 0; i < iperlHeads.Count; i++) { Results.Entities.MeterTestRslt meterRslt = - ProcessData.BatchRslts.GetMeterTestRslt(test.Name, waterMeterPositions0[i], Common.CompoundMeterId.Single); + ProcessData.BatchRslts.GetMeterTestRslt(test.Name, waterMeterPositions0[i], CompoundMeterId.Single); if (meterRslt != null && iperlHeads[i] != null) { diff --git a/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationParams.cs b/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationParams.cs index 817f59f35..663e44287 100644 --- a/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationParams.cs +++ b/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationParams.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2015 Sensus Metering Systems +/// Copyright (c) 2015-2021 Sensus Slovensko a.s. /// using System; using System.IO; @@ -68,6 +68,10 @@ namespace TBF.Rig.TestMethods.iPerlCommunication retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionGreeceIncl05Str); retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionRLIncl05Str); retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionLRIncl05Str); + retVal.Add(iPerlCommunicationSeq.Q2correctedFromCmd + "Qx"); + retVal.Add(iPerlCommunicationSeq.StrictQ2ErrorCheckStr + "Qx"); + retVal.Add(iPerlCommunicationSeq.Q2correctionCheckCmd); + retVal.Add(iPerlCommunicationSeq.IperlCheckCmd); retVal.Add(iPerlCommunicationForm.UpdateBothQ2FactorsTestRLOnlyStr); retVal.Add(iPerlCommunicationForm.UpdateBothQ2FactorsTestLROnlyStr); retVal.Add(iPerlCommunicationForm.UpdateQ2CorrectionsStr); @@ -80,6 +84,8 @@ namespace TBF.Rig.TestMethods.iPerlCommunication retVal.Add("---"); retVal.Add(iPerlCommunicationForm.Reset2HzCorrectionStr); retVal.Add(iPerlCommunicationForm.Write2HzCorrectionStr); + retVal.Add(iPerlCommunicationForm.DewaReworkRLStr); + retVal.Add(iPerlCommunicationForm.DewaReworkLRStr); retVal.Add(string.Format("{0} if enabled", iPerlCommunicationForm.ReadConfigurationStr)); retVal.Add(string.Format("{0} 80", iPerlCommunicationForm.SetTestModeStr)); retVal.Add("iPerl_check prevWorkStep direction q2factors"); diff --git a/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationSeq.cs b/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationSeq.cs index b7c659b0b..aa584bfcc 100644 --- a/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationSeq.cs +++ b/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationSeq.cs @@ -18,6 +18,11 @@ namespace TBF.Rig.TestMethods.iPerlCommunication { private static readonly ILog log = LogManager.GetLogger(typeof(iPerlCommunicationSeq)); + public const string Q2correctedFromCmd = "q2 corrected from "; + public const string StrictQ2ErrorCheckStr = "strict Q2 error check "; + public const string Q2correctionCheckCmd = "q2 correction check "; + public const string IperlCheckCmd = "iperl_check "; + System.Windows.Forms.Form modelessDlg; /// @@ -55,10 +60,6 @@ namespace TBF.Rig.TestMethods.iPerlCommunication processDataLoggingOp = new TBF.Rig.Operations.ProcessDataLoggingOp(processDataLogger, this, false); - const string Q2correctedFromCmd = "q2 corrected from "; - const string Q2correctionCheckCmd = "q2 correction check "; - const string IperlCheckCmd = "iperl_check "; - if (testParams.Activity.ToLower().Equals(iPerlCommunicationForm.GetDefaultQ2CorrectionsStr.ToLower())) { TestProgressEventArgs.SetEstimatedTimes(new int[] { 0, 0, 0, 30, 0, 30, 0, 0 }); @@ -129,6 +130,22 @@ namespace TBF.Rig.TestMethods.iPerlCommunication return new List { Event.Done }; } + else if (testParams.Activity.ToLower().Contains(StrictQ2ErrorCheckStr)) + { + TestProgressEventArgs.SetEstimatedTimes(new int[] { 0, 0, 0, 30, 0, 30, 0, 0 }); + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, Progress.JustStarted)); + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, Progress.FlowSetting)); + + string fromTestName = testParams.Activity.Substring(Q2correctedFromCmd.Length); + + StrictQ2ErrorCheck(test.Name, fromTestName); + + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, Progress.Completed)); + Bridge.OnTestCompleted(this, new TestCompletedEventArgs(test.Name, ProcessData.BatchRslts.GetTestRslt(test.Name, 0))); + allResults.Info(TestResult2CsvLine(test.Name, 0)); /// Append the results to the CSV-file + + return new List { Event.Done }; + } else if (testParams.Activity.ToLower().Contains(Q2correctionCheckCmd)) { TestProgressEventArgs.SetEstimatedTimes(new int[] { 0, 0, 0, 30, 0, 30, 0, 0 }); @@ -159,7 +176,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication int maxTestIndex = (ProcessData.BenchInfo is DataContainer.iPerlBenchInfo.Component) ? (ProcessData.BenchInfo as DataContainer.iPerlBenchInfo.Component).MaxTestIndex : int.MaxValue; - + Results.Entities.TestRslt tstRslt = ProcessData.BatchRslts.GetTestRslt(test.Name, 0); if (tstRslt != null) @@ -267,77 +284,77 @@ namespace TBF.Rig.TestMethods.iPerlCommunication return new List { Event.Done }; } - else if (testParams.Activity.ToLower().Contains("simulate ")) - { - TestProgressEventArgs.SetEstimatedTimes(new int[] { 0, 0, 0, 30, 0, 30, 0, 0 } ); - Bridge.OnTestProgress(this, new TestProgressEventArgs(test, Progress.JustStarted)); - Bridge.OnTestProgress(this, new TestProgressEventArgs(test, Progress.FlowSetting)); + else if (testParams.Activity.ToLower().Contains("simulate ")) + { + TestProgressEventArgs.SetEstimatedTimes(new int[] { 0, 0, 0, 30, 0, 30, 0, 0 }); + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, Progress.JustStarted)); + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, Progress.FlowSetting)); - if (testParams.Activity.ToLower().Contains("q3")) MakeSimulated(test, 1, 0, -0.5f); - else if (testParams.Activity.ToLower().Contains("q2")) MakeSimulated(test, 1, 0, 0.5f); - else if (testParams.Activity.ToLower().Contains("q1")) MakeSimulated(test, 1, 0, -5.1f); - else if (testParams.Activity.ToLower().Contains("compound ok")) MakeSimulatedCompound(test, 1, 0, 0.7f, 1.0f); - else if (testParams.Activity.ToLower().Contains("compound nok")) MakeSimulatedCompound(test, 1, 0, 4.7f, 0.9f); - else if (testParams.Activity.ToLower().Contains("compound rise")) MakeSimulatedCompound(test, 1, 0, 0.7f, 0.0f); - else if (testParams.Activity.ToLower().Contains("compound fall")) MakeSimulatedCompound(test, 1, 0, 0.7f, 0.9f); + if (testParams.Activity.ToLower().Contains("q3")) MakeSimulated(test, 1, 0, -0.5f); + else if (testParams.Activity.ToLower().Contains("q2")) MakeSimulated(test, 1, 0, 0.5f); + else if (testParams.Activity.ToLower().Contains("q1")) MakeSimulated(test, 1, 0, -5.1f); + else if (testParams.Activity.ToLower().Contains("compound ok")) MakeSimulatedCompound(test, 1, 0, 0.7f, 1.0f); + else if (testParams.Activity.ToLower().Contains("compound nok")) MakeSimulatedCompound(test, 1, 0, 4.7f, 0.9f); + else if (testParams.Activity.ToLower().Contains("compound rise")) MakeSimulatedCompound(test, 1, 0, 0.7f, 0.0f); + else if (testParams.Activity.ToLower().Contains("compound fall")) MakeSimulatedCompound(test, 1, 0, 0.7f, 0.9f); - Bridge.OnTestProgress(this, new TestProgressEventArgs(test, Progress.Completed)); - Bridge.OnTestCompleted(this, new TestCompletedEventArgs(test.Name, ProcessData.BatchRslts.GetTestRslt(Results.Utils.GetTestName(test.Name, 1, 1), 0))); - allResults.Info(TestResult2CsvLine(test.Name, 0)); /// Append the results to the CSV-file + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, Progress.Completed)); + Bridge.OnTestCompleted(this, new TestCompletedEventArgs(test.Name, ProcessData.BatchRslts.GetTestRslt(Results.Utils.GetTestName(test.Name, 1, 1), 0))); + allResults.Info(TestResult2CsvLine(test.Name, 0)); /// Append the results to the CSV-file - //------------------------------------------------ - Bridge.OnActivity(this, testParams.Activity); - //------------------------------------------------ + //------------------------------------------------ + Bridge.OnActivity(this, testParams.Activity); + //------------------------------------------------ - State.Create(string.Format("iPerlCommunicationSeq : {0}", testParams.Activity)) - .AddOperation(checkUiOp) - .EnterState(); - e = StateMachine.WaitRunDevsRunOps(); + State.Create(string.Format("iPerlCommunicationSeq : {0}", testParams.Activity)) + .AddOperation(checkUiOp) + .EnterState(); + e = StateMachine.WaitRunDevsRunOps(); if (TestAndLogUiCmdStop(test, e)) { return new List { Event.UiCmdStop }; } - } - else - { - /// - /// Show the modeless dialog with error indication - /// - Program.MainWnd.Invoke(new iPerlCommFormDlgt(OpenIPerlCommForm), new object[] { this, cfg, test, testParams }); + } + else + { + /// + /// Show the modeless dialog with error indication + /// + Program.MainWnd.Invoke(new iPerlCommFormDlgt(OpenIPerlCommForm), new object[] { this, cfg, test, testParams }); - //------------------------------------------------ - Bridge.OnActivity(this, Strings.iPerl_Communication_in_progress); - //------------------------------------------------ + //------------------------------------------------ + Bridge.OnActivity(this, Strings.iPerl_Communication_in_progress); + //------------------------------------------------ - bool stopPressed = false; /// true when STOP button pressed - bool completed = false; + bool stopPressed = false; /// true when STOP button pressed + bool completed = false; - State.Create("iPerlCommunicationSeq : Wait until the entry form is closed") - .AddOperation(checkUiOp) - .EnterState(); - do - { - e = StateMachine.WaitRunDevsRunOps(); - stopPressed = TestAndLogUiCmdStop(test,e); - completed = (modelessDlg is GenericDevices.IHasCompleted) - && (modelessDlg as GenericDevices.IHasCompleted).Completed; - } - while (!stopPressed && !completed); + State.Create("iPerlCommunicationSeq : Wait until the entry form is closed") + .AddOperation(checkUiOp) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + stopPressed = TestAndLogUiCmdStop(test, e); + completed = (modelessDlg is GenericDevices.IHasCompleted) + && (modelessDlg as GenericDevices.IHasCompleted).Completed; + } + while (!stopPressed && !completed); - if (stopPressed) - { - CloseIPerlCommForm(); - return new List { Event.UiCmdStop }; - } - else - { - TBF.UiBridge.Bridge.OnTestProgress(null, new TBF.UiBridge.TestProgressEventArgs(test.Name, Progress.Completed)); - } + if (stopPressed) + { + CloseIPerlCommForm(); + return new List { Event.UiCmdStop }; + } + else + { + TBF.UiBridge.Bridge.OnTestProgress(null, new TBF.UiBridge.TestProgressEventArgs(test.Name, Progress.Completed)); + } - /// Test 'Quit' - modelessDlg = null; /// Modeless dialog is closed now - } + /// Test 'Quit' + modelessDlg = null; /// Modeless dialog is closed now + } return new List { Event.Done }; } @@ -603,6 +620,151 @@ namespace TBF.Rig.TestMethods.iPerlCommunication } } + /// + /// Evaluate a given Q2 test result agains stricter error limits when Oruefindex == 1. + /// + /// This test name + /// Name of Q2 test done before Q2 correction (Q2adj) + /// Assuming this test does not have multiple parts (part = 0) + void StrictQ2ErrorCheck(string testName, string oriTestName) + { + Results.Entities.TestRslt oriTestRslt = ProcessData.BatchRslts.GetTestRslt(oriTestName, 0); + Results.Entities.TestRslt tstRslt = ProcessData.BatchRslts.GetTestRslt(testName, 0); + + if (oriTestRslt == null || tstRslt == null) return; + + tstRslt.Components = oriTestRslt.Components; + + /// Auxiliary results, as in SequenceBase.UpdateTemoPressDensAmb() + tstRslt.AmbTempMean = oriTestRslt.AmbTempMean; + tstRslt.AmbTempStart = oriTestRslt.AmbTempStart; + tstRslt.AmbTempEnd = oriTestRslt.AmbTempEnd; + tstRslt.AmbTempMin = oriTestRslt.AmbTempMin; + tstRslt.AmbTempMax = oriTestRslt.AmbTempMax; + tstRslt.AmbPressMean = oriTestRslt.AmbPressMean; + tstRslt.AmbPressStart = oriTestRslt.AmbPressStart; + tstRslt.AmbPressEnd = oriTestRslt.AmbPressEnd; + tstRslt.AmbPressMin = oriTestRslt.AmbPressMin; + tstRslt.AmbPressMax = oriTestRslt.AmbPressMax; + tstRslt.AmbHumiMean = oriTestRslt.AmbHumiMean; + tstRslt.AmbHumiStart = oriTestRslt.AmbHumiStart; + tstRslt.AmbHumiEnd = oriTestRslt.AmbHumiEnd; + tstRslt.AmbHumiMin = oriTestRslt.AmbHumiMin; + tstRslt.AmbHumiMax = oriTestRslt.AmbHumiMax; + tstRslt.PressUpMean = oriTestRslt.PressUpMean; + tstRslt.PressUpStart = oriTestRslt.PressUpStart; + tstRslt.PressUpEnd = oriTestRslt.PressUpEnd; + tstRslt.PressUpMin = oriTestRslt.PressUpMin; + tstRslt.PressUpMax = oriTestRslt.PressUpMax; + tstRslt.PressDownMean = oriTestRslt.PressDownMean; + tstRslt.PressDownStart = oriTestRslt.PressDownStart; + tstRslt.PressDownEnd = oriTestRslt.PressDownEnd; + tstRslt.PressDownMin = oriTestRslt.PressDownMin; + tstRslt.PressDownMax = oriTestRslt.PressDownMax; + tstRslt.PressDeltaMean = oriTestRslt.PressDeltaMean; + tstRslt.PressDeltaStart = oriTestRslt.PressDeltaStart; + tstRslt.PressDeltaEnd = oriTestRslt.PressDeltaEnd; + tstRslt.PressDeltaMin = oriTestRslt.PressDeltaMin; + tstRslt.PressDeltaMax = oriTestRslt.PressDeltaMax; + tstRslt.ConductMean = oriTestRslt.ConductMean; + tstRslt.ConductStart = oriTestRslt.ConductStart; + tstRslt.ConductEnd = oriTestRslt.ConductEnd; + tstRslt.ConductMin = oriTestRslt.ConductMin; + tstRslt.ConductMax = oriTestRslt.ConductMax; + tstRslt.TempUpMean = oriTestRslt.TempUpMean; + tstRslt.TempUpStart = oriTestRslt.TempUpStart; + tstRslt.TempUpEnd = oriTestRslt.TempUpEnd; + tstRslt.TempUpMin = oriTestRslt.TempUpMin; + tstRslt.TempUpMax = oriTestRslt.TempUpMax; + tstRslt.TempDownMean = oriTestRslt.TempDownMean; + tstRslt.TempDownStart = oriTestRslt.TempDownStart; + tstRslt.TempDownEnd = oriTestRslt.TempDownEnd; + tstRslt.TempDownMin = oriTestRslt.TempDownMin; + tstRslt.TempDownMax = oriTestRslt.TempDownMax; + tstRslt.TempDivMean = oriTestRslt.TempDivMean; + tstRslt.TempDivStart = oriTestRslt.TempDivStart; + tstRslt.TempDivEnd = oriTestRslt.TempDivEnd; + tstRslt.TempDivMin = oriTestRslt.TempDivMin; + tstRslt.TempDivMax = oriTestRslt.TempDivMax; + tstRslt.DensityIn = oriTestRslt.DensityIn; + tstRslt.DensityLine = oriTestRslt.DensityLine; + tstRslt.DensityDiv = oriTestRslt.DensityDiv; + + tstRslt.StartTime = oriTestRslt.StartTime; + tstRslt.EndTime = oriTestRslt.EndTime; + tstRslt.FlowSetTime = oriTestRslt.FlowSetTime; + tstRslt.TestTime = oriTestRslt.TestTime; + tstRslt.PulsesMaster = oriTestRslt.PulsesMaster; + tstRslt.ConstMasterRaw = oriTestRslt.ConstMasterRaw; + tstRslt.ConstMaster = oriTestRslt.ConstMaster; + tstRslt.MassStartRaw = oriTestRslt.MassStartRaw; + tstRslt.MassStart = oriTestRslt.MassStart; + tstRslt.MassEndRaw = oriTestRslt.MassEndRaw; + tstRslt.MassEnd = oriTestRslt.MassEnd; + tstRslt.MassOfEvapWater = oriTestRslt.MassOfEvapWater; + tstRslt.FlowMass = oriTestRslt.FlowMass; + tstRslt.FlowVolume = oriTestRslt.FlowVolume; + tstRslt.VolumeCTV = oriTestRslt.VolumeCTV; + tstRslt.VolumeMaster = oriTestRslt.VolumeMaster; + tstRslt.ErrorMaster = oriTestRslt.ErrorMaster; + + tstRslt.FlowMean = oriTestRslt.FlowMean; + tstRslt.FlowMin = oriTestRslt.FlowMin; + tstRslt.FlowMax = oriTestRslt.FlowMax; + + tstRslt.Custom1 = oriTestRslt.Custom1; + tstRslt.Custom2 = oriTestRslt.Custom2; + tstRslt.Custom3 = oriTestRslt.Custom3; + tstRslt.Custom4 = oriTestRslt.Custom4; + tstRslt.Custom5 = oriTestRslt.Custom5; + tstRslt.Custom6 = oriTestRslt.Custom6; + tstRslt.Custom7 = oriTestRslt.Custom7; + tstRslt.Custom8 = oriTestRslt.Custom8; + + for (int i = 0; i < ProcessData.BatchRslts.WMPositionsCount; i++) + { + Results.Entities.MeterTestRslt oriMeterRslt = ProcessData.BatchRslts.GetMeterTestRslt(oriTestName, i, CompoundMeterId.Single); + Results.Entities.MeterTestRslt meterRslt = ProcessData.BatchRslts.GetMeterTestRslt(testName, i, CompoundMeterId.Single); + + /// Reference to iPerl water meter or null: + TestMethods.iPerlCommunication.iPerlHead.IperlHead iPerl = ((sensPath != null) && (sensPath.RegisterReaders != null) && (i < sensPath.RegisterReaders.Length)) + ? (sensPath.RegisterReaders[i] as TestMethods.iPerlCommunication.iPerlHead.IperlHead) + : null; + +#if ORACLE_DB + meterRslt.ErrorBC = oriMeterRslt.Error; +#endif + meterRslt.PulsesMeter = oriMeterRslt.PulsesMeter; + meterRslt.PulsesMaster = oriMeterRslt.PulsesMaster; + meterRslt.PulsesPerLiter = oriMeterRslt.PulsesPerLiter; + meterRslt.VolumeRef = oriMeterRslt.VolumeRef; + meterRslt.TestTime = oriMeterRslt.TestTime; + + if (iPerl != null && ProcessData.BatchRslts.Batch.WaterMeters[i] != null && + !ProcessData.BatchRslts.Batch.WaterMeters[i].Disabled) + { + /// Either no iPerl head or no Q2 correction + meterRslt.Error = oriMeterRslt.Error; + meterRslt.VolumeMeter = oriMeterRslt.VolumeMeter; + meterRslt.VolumeStart = oriMeterRslt.VolumeStart; + meterRslt.VolumeEnd = oriMeterRslt.VolumeEnd; +#if ORACLE_DB + if (ProcessData.BatchRslts.Batch.WaterMeters[i].Pruefindex == 1) + { + meterRslt.Passed = (oriMeterRslt.Error >= tstRslt.ErrLimLo() + tstRslt.ErrLimMargin() + && oriMeterRslt.Error <= tstRslt.ErrLimHi() - tstRslt.ErrLimMargin()); + } + else +#endif + { + meterRslt.Passed = oriMeterRslt.Passed; + } + meterRslt.TestDone = true; + tstRslt.TestDone = true; + } + } + } + /// /// Check results of 2 tests: before Q2 correction and after Q2 correction. diff --git a/TBF/Rig/TestMethods/iPerlCommunication/iPerlDataWrite.cs b/TBF/Rig/TestMethods/iPerlCommunication/iPerlDataWrite.cs new file mode 100644 index 000000000..d47e86266 --- /dev/null +++ b/TBF/Rig/TestMethods/iPerlCommunication/iPerlDataWrite.cs @@ -0,0 +1,23 @@ +/// +/// Copyright (c) 2021 Sensus Slovensko a.s. +/// +using TBF.Rig.TestMethods.iPerlCommunication.iPerlHead; + +namespace TBF.Rig.TestMethods.iPerlCommunication +{ + public class iPerlDataWrite + { + public MessageID MessageID; + public int Offset; + public byte[] Data; + public string Description; + + public iPerlDataWrite(MessageID mesageID, int offset, byte[] data, string description) + { + MessageID = mesageID; + Offset = offset; + Data = data; + Description = description; + } + } +} diff --git a/TBF/Rig/TestMethods/iPerlCommunication/iPerlHead/Enums.cs b/TBF/Rig/TestMethods/iPerlCommunication/iPerlHead/Enums.cs index 01965939e..0069eb96a 100644 --- a/TBF/Rig/TestMethods/iPerlCommunication/iPerlHead/Enums.cs +++ b/TBF/Rig/TestMethods/iPerlCommunication/iPerlHead/Enums.cs @@ -99,9 +99,9 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead Count /// Number of flow states } - public enum OptoState + public enum DataStreamState { - Read, - Flush, + Flush = 0, + ProcessAndSave, } } diff --git a/TBF/Rig/TestMethods/iPerlCommunication/iPerlHead/IperlHead.cs b/TBF/Rig/TestMethods/iPerlCommunication/iPerlHead/IperlHead.cs index 3184766e6..f2d9c948a 100644 --- a/TBF/Rig/TestMethods/iPerlCommunication/iPerlHead/IperlHead.cs +++ b/TBF/Rig/TestMethods/iPerlCommunication/iPerlHead/IperlHead.cs @@ -11,25 +11,26 @@ using Config.Entities; using TBF.Rig.Generic; using TBF.Rig.GenericDevices; using TBF.Rig.Output; +using TBF.Rig.Sequences; namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead { /// /// This component = instance of this class is a placeholder for a combined main watermeter /// - public class IperlHead : ComponentBase, IDevice, IRegReaderDatastream, IHasTestName, IHasClearSessionData, IOperation + public class IperlHead : ComponentBase, IDevice, IRegReaderDatastream, ISessionDataMngmnt, IOperation { private static readonly ILog log = LogManager.GetLogger(typeof(IperlHead)); public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); } #if TURA_SPECIAL - public const int MaxOptoDataCount = 250000; + public const int OptoDataBufferSize = 250000; #else - public const int MaxOptoDataCount = 40000; + public const int OptoDataBufferSize = 40000; /// Opto data count is not limitted by the buffer size #endif public const string OptoDataDirectory = "C:\\TBF\\ProcessData"; - public const int StartOptoDataCount = MaxOptoDataCount / 2; - public const int EndOptoDataCount = MaxOptoDataCount - StartOptoDataCount; + public const int StartOptoDataCount = OptoDataBufferSize / 2; + public const int EndOptoDataCount = OptoDataBufferSize - StartOptoDataCount; public const int StartEndFilterSamplesCount2 = 20; /// StartEndFilterSamplesCount = 2 * StartEndFilterSamplesCount2 + 1 public const int FeatureVectorSize = 9; @@ -212,7 +213,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead /// Calculated Q2 correction factor public double CalculateQ2CorrectionFactor(Results.Entities.MeterTestRslt q2adjResult, double calibTarget, double nominalFlow, int currentFactor = 0) { - double nominalTestFlowLph = Common.Units.ConvertTo(Common.Unit.lph, nominalFlow); + double nominalTestFlowLph = Units.ConvertTo(Common.Unit.lph, nominalFlow); double volumeRefShiftedToTarget = q2adjResult.VolumeRef * (1.0 + calibTarget / 100.0); double q2adjErrorShiftedToTarget = Formulas.ErrorFromVolumes(q2adjResult.VolumeMeter, volumeRefShiftedToTarget); @@ -273,18 +274,57 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead } - /// Name set by the test, to be used as a part of the opto-data log file name - public string TestName { set { testName = value; } } - public int TestRepeats { set { testRepeats = value; } } - public int RepetitionNr { set { repetitionNr = value; } } + /// + /// Store/update values to be used as a part of the opto-data log file name. + /// Stop data stream processing and saving, if it is enabled. + /// + /// Currently executed test + /// Currently executed repetition number + public void TestIsGoingToStartSoon(Test test, int repetitionNr) + { + /// Store/update values to be used as a part of the opto-data log file name + testName = test.Name; + testRepeats = test.Repeats; + this.repetitionNr = repetitionNr; + + if (IsDataStreamProcessing()) + { + StopDataStreamProcessing(); + + /// Dummy '#### start test ####' and '#### end of test ####' marks are added + /// to the raw data file on request of Joern Goege + if (optoDataCount >= 100 && optoDataCount <= optoData.Length && + optoData[40].Flags == OptoTelegramFlags.OK && + optoData[optoDataCount - 40].Flags == OptoTelegramFlags.OK) + { + optoData[40].Flags = OptoTelegramFlags.OK_TestStart; + optoData[optoDataCount - 40].Flags = OptoTelegramFlags.OK_TestEnd; + } + + DataStreamPostProcessing(); + + string pcbNr = (ConfigStruct != null) ? ConfigStruct.GetPcbNrString() : "UnknownPcbNr"; + string wmPosition = Name.Substring(5); /// WMPosition is extracted from a component name in form 'iPerl#' + if (wmPosition.Length == 1) wmPosition = "0" + wmPosition; + string cycleStartTime = StateMachine.CycleStartTimeStamp.ToString("HH_mm_ss"); + /// + string relativeDirectory = Path.Combine(StateMachine.CycleStartTimeStamp.ToString("yy"), + StateMachine.CycleStartTimeStamp.ToString("MM"), + StateMachine.CycleStartTimeStamp.ToString("dd")); + string directory = Path.Combine(OptoDataDirectory, relativeDirectory); + string fileName = string.Format("{0}_{1}_{2}_{3}.txt", pcbNr, wmPosition, "WM", cycleStartTime); + + if (SaveOptoDataToFile(directory, fileName)) + { + extraDataPath = Path.Combine(relativeDirectory, fileName); + } + } + } /// string testName; int testRepeats; int repetitionNr; - /// Name set by the test, to be used as a part of the opto-data log file name - public string BenchName; - /// /// Indices to determine centers of start / end samples @@ -341,8 +381,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead OptoTelegramRaw[] optoData; - int optoDataCount; - string optoDataLogFileName; + int optoDataCount; /// Real opto deta count, can be larger then optoData.Length /// OptoTelegramRaw toBeFlushed; @@ -363,26 +402,25 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead public override void Initialize() { - ClearSessionData(); flowDirectionDetection = new FlowDirectionDetection(); /// Allocate memory for opto-data from iPerl - optoData = new OptoTelegramRaw[MaxOptoDataCount]; - for (int i = 0; i < MaxOptoDataCount; i++) + optoData = new OptoTelegramRaw[OptoDataBufferSize]; + for (int i = 0; i < OptoDataBufferSize; i++) { optoData[i] = new OptoTelegramRaw(); } toBeFlushed = new OptoTelegramRaw(); - optoSerialPortParsingEnabled = false; + dataStreamState = DataStreamState.Flush; synchronized = false; synchronized2 = false; partOfTelegram = string.Empty; if (DebugLevel == DebugMode.Normal) { - /// Prepare serial port + /// Open serial port: 9600 Bd, 8 data bits, 1 stop bit, no parity string portName = string.Format("COM{0}", iperlHeadCfg.OptoComPortNr); optoSerialPort = new SerialPort(portName, 9600, Parity.None, 8, StopBits.One); optoSerialPort.Handshake = Handshake.None; @@ -399,7 +437,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead /// /// Clear data related to a specific water meter /// - public void ClearSessionData() + public void StartSession() { ResultCode = 0; @@ -418,12 +456,20 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead Q2ErrWOCorrection = 0; Q2CorrRL = 0; Q2CorrLR = 0; - - /// Clear the data buffer - optoDataCount = 0; + + dataStreamState = DataStreamState.Flush; currentFlowDir = InitFlowDir; - if (flowDirectionDetection != null) flowDirectionDetection.ClearFifo(); /// Clear FIFO for flow direction detection + } + + public void SaveMark(object mark) + { + /// TODO + } + + public void EndSession() + { + StopDataStreamProcessing(); } @@ -462,7 +508,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead { try { - ReadOptoData(optoSerialPortParsingEnabled ? OptoState.Read : OptoState.Flush); + ReadOptoData(dataStreamState); } catch (Exception e) { @@ -520,137 +566,107 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead timestampSec = 0; timestampSec0 = 0; - /// Clear the feature vector - for (int i = 0; i < FeatureVectorSize; i++) x[i] = 0; + extraDataPath = null; - ReadPulses(); + /// Clear the feature vector + for (int i = 0; i < FeatureVectorSize; i++) + { + x[i] = 0; + } + } + + public void TestCompleted() + { + /// TODO: Implement } int timeFromStart; /// [s] Time from test start to determine when the test start sample should be taken - /// Start this operation + /// + /// Start this operation + /// public void Start() { - Clear(); - - /// Reset opto data, etc. - timeFromStart = 0; - optoDataCount = 0; - currentTelegramIx = -1; - startSampleAcquired = false; - TestStartTelegramIx = 0; - endTelegramIdx1 = 0; - endTelegramIdx2 = 0; - endTelegramIdx3 = 0; - TestEndTelegramIx = 0; - - - /// - /// Determine opto data file name: PCB_AA_BB_HH_MI_SS..txt - /// - Results.Output.SensusTestInfo[] localTestInfos = Sequences.ProcessData.CompleteTestInfos; - if (localTestInfos == null && StateMachine.Procedure != null) + lock (this) { - localTestInfos = Results.Output.SensusTestInfo.CreateFromProcedure(StateMachine.Procedure); + Clear(); + ReadPulses(); + StartDataStreamProcessing(); } - /// - string fullTestName = Results.Utils.GetTestName(testName, testRepeats, repetitionNr); - string qBezeichnungOpto = null; /// To be determined from TestInfo-s (if there are any) - if (localTestInfos != null) - { - foreach (var ti in localTestInfos) - { - if ((ti.PruefungsNrOpto != 0) && (ti.TestName == fullTestName)) - { - qBezeichnungOpto = string.IsNullOrEmpty(ti.QBezeichnungOpto) ? ti.PruefungsNrOpto.ToString("D2") : ti.QBezeichnungOpto; - break; - } - } - } - if (qBezeichnungOpto == null) - { - qBezeichnungOpto = fullTestName; /// No appropriate TestInfo found => set default opto data file name - } - /// - string pcbNr = (ConfigStruct != null) ? ConfigStruct.GetPcbNrString() : "UnknownPcbNr"; - string wmPosition = Name.Substring(5); /// WMPosition is extracted from a component name in form 'iPerl#' - if (wmPosition.Length == 1) wmPosition = "0" + wmPosition; - string cycleStartTime = StateMachine.CycleStartTimeStamp.ToString("HH_mm_ss"); - /// - optoDataLogFileName = string.Format("{0}_{1}_{2}_{3}.txt", pcbNr, wmPosition, qBezeichnungOpto, cycleStartTime); - - extraDataPath = null; - - StartParsingOptoSerialPort(); } - /// Run this operation + /// + /// Run this operation + /// /// eventDone public Event Run() { - timeFromStart += StateMachine.Period; - ReadPulses(); + lock (this) + { + timeFromStart += StateMachine.Period; + ReadPulses(); - if (!startSampleAcquired && (timeFromStart >= 8) && (currentTelegramIx >= 0)) - { - /// Take the test start sample - startSampleAcquired = true; - TestStartTelegramIx = currentTelegramIx; - } - else if (startSampleAcquired) - { - /// Shift data in pipelines - TestEndTelegramIx = endTelegramIdx3; - endTelegramIdx3 = endTelegramIdx2; - endTelegramIdx2 = endTelegramIdx1; - endTelegramIdx1 = currentTelegramIx; + if (!startSampleAcquired && (timeFromStart >= 8) && (currentTelegramIx >= 0)) + { + /// Take the test start sample + startSampleAcquired = true; + TestStartTelegramIx = currentTelegramIx; + } + else if (startSampleAcquired) + { + /// Shift data in pipelines + TestEndTelegramIx = endTelegramIdx3; + endTelegramIdx3 = endTelegramIdx2; + endTelegramIdx2 = endTelegramIdx1; + endTelegramIdx1 = currentTelegramIx; + } } return Event.ReadRegisterDone; } - /// Stop this operation + /// + /// Stop this operation + /// public void Stop() { - int startIx = BufferIdx(TestStartTelegramIx); - int endIx = BufferIdx(TestEndTelegramIx); - - log.WarnFormat("IperlHeadd.Stop() startIx={0} endIx={1} optoData.Len={2} filename={3}", startIx, endIx, optoData.Length, !string.IsNullOrEmpty(optoDataLogFileName) ? optoDataLogFileName : ""); - - if ((startIx > 0) && (startIx < StartOptoDataCount) && (optoData[startIx].Flags == OptoTelegramFlags.OK)) - { - optoData[startIx].Flags = OptoTelegramFlags.OK_TestStart; - OptoTelegramRaw.TestStartTimestampDec = optoData[startIx].TimestampDec(); - } - - if ((endIx > 0) && (optoData[endIx].Flags == OptoTelegramFlags.OK)) - { - optoData[endIx].Flags = OptoTelegramFlags.OK_TestEnd; - } - - log.DebugFormat("Flow filtering start: {0:HH:mm:ss.fff}", DateTime.Now); - - StopParsingOptoSerialPort(); - if (optoDataCount <= MaxOptoDataCount) - { - FIRFilterFlow(optoData, 0, optoDataCount - 1); - } - else - { - FIRFilterFlow(optoData, 0, StartOptoDataCount - 1); - FIRFilterFlow(optoData, (optoDataCount - EndOptoDataCount), optoDataCount - 1); - } - log.DebugFormat("Flow filtering end, feature vector calculation start: {0:HH:mm:ss.fff}", DateTime.Now); - Common.Utils.CalculateFeatureVector(optoData, optoDataCount, startIx, endIx, ref x); + int startIx; + int endIx; - log.DebugFormat("Feature vector calculation end, save opto-file start: {0:HH:mm:ss.fff}", DateTime.Now); + lock (this) + { + StopDataStreamProcessing(); + AddTestStartEndMarksToData(out startIx, out endIx); + } - extraDataPath = SaveOptoData(); + DataStreamPostProcessing(); - log.DebugFormat("Save opto-file end: {0:HH:mm:ss.fff}", DateTime.Now); + // TODO: Enable when calculations completed + // + // float[] offsetV, kOhmsR, kOhmsC, dutFlow, refFlow, flowRatio, magField, emfV; + // x = Common.StatisticalMetrics.Calculate(optoData, optoDataCount, startIx, endIx, true, + // out offsetV, out kOhmsR, out kOhmsC, out dutFlow, + // out refFlow, out flowRatio, out magField, out emfV); + // + // log.DebugFormat("Feature vector calculation end, save opto-file start: {0:HH:mm:ss.fff}", DateTime.Now); + + string relativeDirectory = Path.Combine(StateMachine.CycleStartTimeStamp.ToString("yy"), + StateMachine.CycleStartTimeStamp.ToString("MM"), + StateMachine.CycleStartTimeStamp.ToString("dd")); + string directory = Path.Combine(OptoDataDirectory, relativeDirectory); + string fileName = DetermineExtraDataFileName(); + if (!string.IsNullOrEmpty(fileName)) + { + if (SaveOptoDataToFile(directory, fileName)) + { + extraDataPath = Path.Combine(relativeDirectory, fileName); + } + } + + log.WarnFormat("IperlHeadd.Stop() startIx={0} endIx={1} optoData.Len={2} filename={3}", startIx, endIx, optoData.Length, !string.IsNullOrEmpty(fileName) ? fileName : ""); if (TestStartTelegramIx == 0 || optoDataCount < 100) { @@ -662,73 +678,163 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead } } - /// - /// Save opto data to a file. - /// - string SaveOptoData() - { - if (!string.IsNullOrEmpty(optoDataLogFileName)) + void AddTestStartEndMarksToData(out int startIx, out int endIx) + { + startIx = BufferIdx(TestStartTelegramIx); + if ((startIx > 0) && (startIx < StartOptoDataCount) && (optoData[startIx].Flags == OptoTelegramFlags.OK)) { - string relativeDirectory = Path.Combine(StateMachine.CycleStartTimeStamp.ToString("yy"), - StateMachine.CycleStartTimeStamp.ToString("MM"), - StateMachine.CycleStartTimeStamp.ToString("dd")); - string fullFileName = Path.Combine(OptoDataDirectory, relativeDirectory, optoDataLogFileName); - - log.WarnFormat("Saving {0} opto data to {1}", Name, fullFileName); - - try + optoData[startIx].Flags = OptoTelegramFlags.OK_TestStart; + OptoTelegramRaw.TestStartTimestampDec = optoData[startIx].TimestampDec(); + } + else + { + for (int ix = 0; ix < StartOptoDataCount; ix++) { - Directory.CreateDirectory(Path.Combine(OptoDataDirectory, relativeDirectory)); - - double scalFact = ScalingFactor(); - - using (TextWriter optoLogFile = new StreamWriter(fullFileName)) + if (optoData[ix].Flags == OptoTelegramFlags.OK) { - if (optoDataCount <= MaxOptoDataCount) - { - /// Telegrams are stored continuously, save them. - optoLogFile.WriteLine(optoData[0].ToString(scalFact, null)); - for (int i = 1; i < optoDataCount; i++) - { - optoLogFile.WriteLine(optoData[i].ToString(scalFact, optoData[i - 1])); - } - } - else /// if (optoDataCount > MaxOptoDataCount) - { - /// Buffer overflow - /// First part of the buffer is saved as is - optoLogFile.WriteLine(optoData[0].ToString(scalFact, null)); - for (int i = 1; i < StartOptoDataCount; i++) - { - optoLogFile.WriteLine(optoData[i].ToString(scalFact, optoData[i - 1])); - } - - optoLogFile.WriteLine(" ..."); - - /// Second part of the buffer is an overflowed circular buffer - optoLogFile.WriteLine(optoData[BufferIdx(optoDataCount)].ToString(scalFact, null)); - for (int i = optoDataCount - EndOptoDataCount + 1; i < optoDataCount; i++) - { - optoLogFile.WriteLine(optoData[BufferIdx(i)].ToString(scalFact, optoData[BufferIdx(i - 1)])); - } - } - - log.WarnFormat("{0} opto data successfully saved: {1} lines", Name, optoDataCount); - - optoLogFile.Close(); + /// This is the first correct opto-telegram received + OptoTelegramRaw.TestStartTimestampDec = optoData[ix].TimestampDec(); + break; } - - return Path.Combine(relativeDirectory, optoDataLogFileName); - } - catch (Exception exc) - { - File.Delete(fullFileName); - log.ErrorFormat(string.Format("Error writing into file {0}", fullFileName)); - log.ErrorFormat(string.Format("Exception message: {0}", exc.Message)); } } - return null; + endIx = BufferIdx(TestEndTelegramIx); + if ((endIx > 0) && (optoData[endIx].Flags == OptoTelegramFlags.OK)) + { + optoData[endIx].Flags = OptoTelegramFlags.OK_TestEnd; + } + } + + /// + /// Data stream post processing: + /// Flow from a reference flowmeter is FIR filtered + /// + void DataStreamPostProcessing() + { + if (optoDataCount <= OptoDataBufferSize) + { + FIRFilterFlow(optoData, 0, optoDataCount - 1); + } + else + { + FIRFilterFlow(optoData, 0, StartOptoDataCount - 1); + FIRFilterFlow(optoData, (optoDataCount - EndOptoDataCount), optoDataCount - 1); + } + } + + /// + /// Determine opto data file name: PCB_AA_BB_HH_MI_SS..txt + /// + /// Test name + /// Test repeats count (>= 1) + /// Repetition number (1 .. testRepeats) + /// + string DetermineExtraDataFileName() + { + /// + /// Select or create appropriate test infos + /// + Results.Output.SensusTestInfo[] testInfos = Sequences.ProcessData.CompleteTestInfos; + /// + if ((ProcessData.OracleDB != null && ProcessData.OracleDB.DesigMode == Output.DB.SensusOracle.DesigMode.Based_on_procedure) || + (testInfos == null && StateMachine.Procedure != null)) + { + testInfos = Results.Output.SensusTestInfo.CreateFromProcedure(StateMachine.Procedure); + } + + /// + /// Select or create appropriate 'qBezeichnung' + /// + string fullTestName = Results.Utils.GetTestName(testName, testRepeats, repetitionNr); + string qBezeichnungOpto = null; /// To be determined from TestInfo-s (if there are any) + foreach (var ti in testInfos) + { + if ((ti.PruefungsNrOpto != 0) && (ti.TestName == fullTestName)) + { + qBezeichnungOpto = string.IsNullOrEmpty(ti.QBezeichnungOpto) ? ti.PruefungsNrOpto.ToString("D2") : ti.QBezeichnungOpto; + break; + } + } + if (qBezeichnungOpto == null) + { + qBezeichnungOpto = fullTestName; /// No appropriate TestInfo found => set default opto data file name + } + + /// + /// Get other required pieces of information + /// + string pcbNr = (ConfigStruct != null) ? ConfigStruct.GetPcbNrString() : "UnknownPcbNr"; + string wmPosition = Name.Substring(5); /// WMPosition is extracted from a component name in form 'iPerl#' + if (wmPosition.Length == 1) wmPosition = "0" + wmPosition; + string cycleStartTime = StateMachine.CycleStartTimeStamp.ToString("HH_mm_ss"); + + /// + /// Return the file name + /// + return string.Format("{0}_{1}_{2}_{3}.txt", pcbNr, wmPosition, qBezeichnungOpto, cycleStartTime); + } + + + /// + /// Save opto data to a file. + /// + bool SaveOptoDataToFile(string directory, string fileName) + { + string fullFileName = Path.Combine(directory, fileName); + log.WarnFormat("Saving {0} opto data to {1}", Name, fullFileName); + + try + { + Directory.CreateDirectory(directory); + + double scalFact = ScalingFactor(); + + using (TextWriter optoLogFile = new StreamWriter(fullFileName)) + { + if (optoDataCount <= OptoDataBufferSize) + { + /// Telegrams are stored continuously, save them. + optoLogFile.WriteLine(optoData[0].ToString(scalFact, null)); + for (int i = 1; i < optoDataCount; i++) + { + optoLogFile.WriteLine(optoData[i].ToString(scalFact, optoData[i - 1])); + } + } + else /// if (optoDataCount > MaxOptoDataCount) + { + /// Buffer overflow + /// First part of the buffer is saved as is + optoLogFile.WriteLine(optoData[0].ToString(scalFact, null)); + for (int i = 1; i < StartOptoDataCount; i++) + { + optoLogFile.WriteLine(optoData[i].ToString(scalFact, optoData[i - 1])); + } + + optoLogFile.WriteLine(" ..."); + + /// Second part of the buffer is an overflowed circular buffer + optoLogFile.WriteLine(optoData[BufferIdx(optoDataCount)].ToString(scalFact, null)); + for (int i = optoDataCount - EndOptoDataCount + 1; i < optoDataCount; i++) + { + optoLogFile.WriteLine(optoData[BufferIdx(i)].ToString(scalFact, optoData[BufferIdx(i - 1)])); + } + } + + log.WarnFormat("{0} opto data successfully saved: {1} lines", Name, optoDataCount); + + optoLogFile.Close(); + } + + return true; + } + catch (Exception exc) + { + File.Delete(fullFileName); + log.ErrorFormat(string.Format("Error writing into file {0}", fullFileName)); + log.ErrorFormat(string.Format("Exception message: {0}", exc.Message)); + return false; + } } void ReadPulses() @@ -742,18 +848,46 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead } - bool optoSerialPortParsingEnabled; + DataStreamState dataStreamState; - /// Flush internal buffers and start parsing the opto serial port data - void StartParsingOptoSerialPort() + /// + /// Reset counters / indices / time and start processing and saving datastream data + /// + public void StartDataStreamProcessing() { - optoSerialPortParsingEnabled = true; + /// Reset opto-data, etc. + optoDataCount = 0; + timeFromStart = 0; + currentTelegramIx = -1; + startSampleAcquired = false; + TestStartTelegramIx = 0; + endTelegramIdx1 = 0; + endTelegramIdx2 = 0; + endTelegramIdx3 = 0; + TestEndTelegramIx = 0; + + if (optoSerialPort != null && optoSerialPort.IsOpen) optoSerialPort.DiscardInBuffer(); + + if (flowDirectionDetection != null) flowDirectionDetection.ClearFifo(); /// Clear FIFO for flow direction detection + + /// Enable opto-data parsing and saving + dataStreamState = DataStreamState.ProcessAndSave; } - /// Stop parsig the opto serial port data - void StopParsingOptoSerialPort() + /// + /// Returns true when processing and saving datastream data is in progress + /// + bool IsDataStreamProcessing() { - optoSerialPortParsingEnabled = false; + return dataStreamState == DataStreamState.ProcessAndSave; + } + + /// + /// Stop processing and saving datastream data + /// + void StopDataStreamProcessing() + { + dataStreamState = DataStreamState.Flush; } /// @@ -764,110 +898,111 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead string partOfTelegram; /// - /// 9600 Bd, 8 data bits, 1 stop bit, no parity - /// + /// Reads opto-datastream via serual port. Invoked from RunDeviceBefore() + /// /// Telegram description: - /// - /// AAAAAA[tab]BBBB[tab]CCCC[tab]DDDDDD[tab]EEEE[tab]FFFFFFFF[tab]GG[cr][lf] (42 bytes) - /// + /// AAAAAA[tab]BBBB[tab]CCCC[tab]DDDDDD[tab]EEEE[tab]FFFFFFFF[tab]GG[cr][lf] (42 bytes) /// Example: - /// FFFFFE 51EA 0000 65324E 0087 F6319DFF 86 - /// FFDD3A 51F9 0000 65324E 0088 F631A60B 45 + /// FFFFFE 51EA 0000 65324E 0087 F6319DFF 86 + /// FFDD3A 51F9 0000 65324E 0088 F631A60B 45 /// ... /// /// OptoState.Read or OptoState.Flush - void ReadOptoData(OptoState optoState) + void ReadOptoData(DataStreamState optoState) { - int nrBytes = optoSerialPort.BytesToRead; - if (nrBytes > 0) - { - char[] buffer = new char[nrBytes]; - optoSerialPort.Read(buffer, 0, nrBytes); - string received = new string(buffer); + lock (this) + { + int nrBytes = optoSerialPort.BytesToRead; + if (nrBytes > 0) + { + char[] buffer = new char[nrBytes]; + optoSerialPort.Read(buffer, 0, nrBytes); + string received = new string(buffer); - string allRcvd = partOfTelegram + received; + string allRcvd = partOfTelegram + received; - while (true) - { - int pos = allRcvd.IndexOf("\r\n"); + while (true) + { + int pos = allRcvd.IndexOf("\r\n"); - if (pos < 0) - { - /// No CR+LF found, wait for more characters in the next invocation - partOfTelegram = allRcvd; - return; - } - else - { - /// CR+LF found - if (optoState == OptoState.Read) - { - int bufferIx = BufferIdx(optoDataCount); + if (pos < 0) + { + /// No CR+LF found, wait for more characters in the next invocation + partOfTelegram = allRcvd; + return; + } + else + { + /// CR+LF found + if (optoState == DataStreamState.ProcessAndSave) + { + int bufferIx = BufferIdx(optoDataCount); - if (pos < OptoTelegramRaw.Length - 2) - { - /// CR+LF found too early, truncate the beginning incl CR+LF and keep scanning in this loop - allRcvd = allRcvd.Substring(pos + 2); - if (synchronized) - { - optoData[bufferIx].Counter = optoDataCount; - optoData[bufferIx].SetFlags(OptoTelegramFlags.SyncError); - } - synchronized = true; - } - else if (optoData[bufferIx].UpdateFromString(allRcvd.Substring(pos - OptoTelegramRaw.Length + 2), - optoDataCount, - Convert.ToSingle(Sequences.ProcessData.RefFlow.Val), - ref volumeRawExtLast, ref timestampExtLast)) - { - /// CR+LF was found && (pos >= OptoTelegramRaw.Length - 2) && the telegram is OK - flowDirectionDetection.WriteToFifo(volumeRawExtLast, timestampExtLast); - OptoTelegramRreceived(optoDataCount, synchronized2, volumeRawExtLast, timestampExtLast); - synchronized2 = synchronized; - allRcvd = allRcvd.Substring(pos + 2); - } - else - { - /// CR+LF was found && (pos >= OptoTelegramRaw.Length - 2) but the telgram was not OK - optoData[bufferIx].Counter = optoDataCount; - optoDataCount++; - allRcvd = allRcvd.Substring(pos + 2); - } + if (pos < OptoTelegramRaw.Length - 2) + { + /// CR+LF found too early, truncate the beginning incl CR+LF and keep scanning in this loop + allRcvd = allRcvd.Substring(pos + 2); + if (synchronized) + { + optoData[bufferIx].Counter = optoDataCount; + optoData[bufferIx].SetFlags(OptoTelegramFlags.SyncError); + } + synchronized = true; + } + else if (optoData[bufferIx].UpdateFromString(allRcvd.Substring(pos - OptoTelegramRaw.Length + 2), + optoDataCount, + Convert.ToSingle(Sequences.ProcessData.RefFlow.Val), + ref volumeRawExtLast, ref timestampExtLast)) + { + /// CR+LF was found && (pos >= OptoTelegramRaw.Length - 2) && the telegram is OK + flowDirectionDetection.WriteToFifo(volumeRawExtLast, timestampExtLast); + OptoTelegramRreceived(optoDataCount, synchronized2, volumeRawExtLast, timestampExtLast); + synchronized2 = synchronized; + allRcvd = allRcvd.Substring(pos + 2); + } + else + { + /// CR+LF was found && (pos >= OptoTelegramRaw.Length - 2) but the telgram was not OK + optoData[bufferIx].Counter = optoDataCount; + optoDataCount++; + allRcvd = allRcvd.Substring(pos + 2); + } - optoDataCount++; - } - else /// optoState == OptoState.Flush - { - if (pos < OptoTelegramRaw.Length - 2) - { - /// CR+LF found too early, truncate the beginning incl CR+LF and keep scanning in this loop - allRcvd = allRcvd.Substring(pos + 2); - synchronized = true; - } - // CR+LF found and (pos >= OptoTelegram.Length - 2) - else if (toBeFlushed.UpdateFromString(allRcvd.Substring(pos - OptoTelegramRaw.Length + 2), - 0, - Convert.ToSingle(Sequences.ProcessData.RefFlow.Val), - ref volumeRawExtLast, ref timestampExtLast)) - { - flowDirectionDetection.WriteToFifo(volumeRawExtLast, timestampExtLast); - synchronized2 = synchronized; - allRcvd = allRcvd.Substring(pos + 2); - } - else - { - allRcvd = allRcvd.Substring(pos + 2); - } - } - } - } + optoDataCount++; + } + else /// optoState == OptoState.Flush + { + if (pos < OptoTelegramRaw.Length - 2) + { + /// CR+LF found too early, truncate the beginning incl CR+LF and keep scanning in this loop + allRcvd = allRcvd.Substring(pos + 2); + synchronized = true; + } + // CR+LF found and (pos >= OptoTelegram.Length - 2) + else if (toBeFlushed.UpdateFromString(allRcvd.Substring(pos - OptoTelegramRaw.Length + 2), + 0, + Convert.ToSingle(Sequences.ProcessData.RefFlow.Val), + ref volumeRawExtLast, ref timestampExtLast)) + { + flowDirectionDetection.WriteToFifo(volumeRawExtLast, timestampExtLast); + synchronized2 = synchronized; + allRcvd = allRcvd.Substring(pos + 2); + } + else + { + allRcvd = allRcvd.Substring(pos + 2); + } + } + } + } - //OnOptoReceived(this, new OptoReceivedEventArgs(s)); - } - else - { - //OnOptoReceived(this, new OptoReceivedEventArgs(".")); - } + //OnOptoReceived(this, new OptoReceivedEventArgs(s)); + } + else + { + //OnOptoReceived(this, new OptoReceivedEventArgs(".")); + } + } } @@ -1113,13 +1248,13 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead /// Index to the buffer public static int BufferIdx(int index) { - if (index < IperlHead.MaxOptoDataCount) + if (index < IperlHead.OptoDataBufferSize) { return index; } else { - return IperlHead.StartOptoDataCount + (index - IperlHead.MaxOptoDataCount) % IperlHead.EndOptoDataCount; + return IperlHead.StartOptoDataCount + (index - IperlHead.OptoDataBufferSize) % IperlHead.EndOptoDataCount; } } diff --git a/TBF/Rig/TestMethods/iPerlCommunication/iPerlHead/IperlHeadCfg.cs b/TBF/Rig/TestMethods/iPerlCommunication/iPerlHead/IperlHeadCfg.cs index d5c3591ef..eff628942 100644 --- a/TBF/Rig/TestMethods/iPerlCommunication/iPerlHead/IperlHeadCfg.cs +++ b/TBF/Rig/TestMethods/iPerlCommunication/iPerlHead/IperlHeadCfg.cs @@ -1,15 +1,10 @@ /// /// Copyright (c) 2015-2017 Sensus Metering Systems /// -using System; using System.Collections.Generic; -using System.IO; -using System.Net; -using System.Net.Sockets; using System.Xml.Serialization; using Common; using TBF.Rig.Generic; -using TBF.Resources; namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead { diff --git a/TBF/TBF.csproj b/TBF/TBF.csproj index c1906c02c..86f40371c 100644 --- a/TBF/TBF.csproj +++ b/TBF/TBF.csproj @@ -586,14 +586,13 @@ - + -