diff --git a/TestBenchFramework/BenchControl/TestMethods/FlyingStartCollectionMethod/FlyingStartCollectionMethodSeq.cs b/TestBenchFramework/BenchControl/TestMethods/FlyingStartCollectionMethod/FlyingStartCollectionMethodSeq.cs index 843622a78..358da05ee 100644 --- a/TestBenchFramework/BenchControl/TestMethods/FlyingStartCollectionMethod/FlyingStartCollectionMethodSeq.cs +++ b/TestBenchFramework/BenchControl/TestMethods/FlyingStartCollectionMethod/FlyingStartCollectionMethodSeq.cs @@ -456,6 +456,7 @@ namespace TBF.BenchControl.TestMethods.FlyingStartCollectionMethod WaterMeters.iPerl.WaterMeter iPerl = (sensPath.RegisterReaders[i] as WaterMeters.iPerl.WaterMeter); tstRslt.Meters[i].VolumeMeter = (float)(iPerl.VolumeLtrEnd - iPerl.VolumeLtrStart); tstRslt.Meters[i].VolumeRef = tstRslt.VolumeCTV * (float)(iPerl.TimestampSecEnd - iPerl.TimestampSecStart) / tstRslt.Time; + iPerl.VolumeLtrRef = (double)tstRslt.Meters[i].VolumeRef; } else { diff --git a/TestBenchFramework/BenchControl/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs b/TestBenchFramework/BenchControl/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs index 11cb38962..02e823347 100644 --- a/TestBenchFramework/BenchControl/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs +++ b/TestBenchFramework/BenchControl/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs @@ -805,11 +805,9 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication CommErr error = CommErr.Write; - UInt16 factor = wm.CalibrationFactor; /// Original calibration factor - /// Write the calculated calibration factor - UInt16 newCalFactor = wm.CalculatedCalibrationFactor; - byte[] data = new byte[2] { (byte)(newCalFactor & 0x00FF), (byte)((newCalFactor >> 8) & 0x00FF) }; + UInt16 newCalibFactor = wm.CalculateNewCalibFactor(wm.CalibrationFactor); + byte[] data = new byte[2] { (byte)(newCalibFactor & 0x00FF), (byte)((newCalibFactor >> 8) & 0x00FF) }; for (int j = 0; j < MaxCommRetries; j++) { if (0 == WriteRequestPort(boardNr, MessageID.Calibration, 2, 2, data, CommTimeout)) { error = CommErr.None; break; } diff --git a/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeter.cs b/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeter.cs index 31c26e1d2..d13e99afe 100644 --- a/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeter.cs +++ b/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeter.cs @@ -89,11 +89,23 @@ namespace TBF.BenchControl.WaterMeters.iPerl public ushort CalibrationFactor { get { return CalibrationStruct.Calibration; } } - public ushort CalculatedCalibrationFactor + public UInt16 CalculateNewCalibFactor(UInt16 originalCalibrationFactor) { - get + double volumeMeter = VolumeLtrEnd - VolumeLtrStart; + if (volumeMeter > 1E-2) { - return (UInt16)((double)CalibrationStruct.Calibration + 0.5); /// TODO: real calculation + UInt16 newFactor = (UInt16)((double)originalCalibrationFactor * VolumeLtrRef / volumeMeter + 0.5); + log.InfoFormat("CalculateNewCalibFactor: orig={0} new={1} V_1={2} V_2={3} Vdiff={4} Vref={5}", + originalCalibrationFactor, newFactor, + VolumeLtrStart.ToString("F3"), VolumeLtrEnd.ToString("F3"), volumeMeter.ToString("F3"), + VolumeLtrRef.ToString("F3")); + return newFactor; + } + else + { + log.ErrorFormat("CalculateNewCalibFactor: orig={0} new={0} (unchanged!) Vdiff={1}", + originalCalibrationFactor, volumeMeter.ToString("F3")); + return originalCalibrationFactor; /// Too small volume in the denominator -> no correction at all } } @@ -108,10 +120,11 @@ namespace TBF.BenchControl.WaterMeters.iPerl private double volumeLtr; /// private double volumeLtr0; - public double VolumeLtrStart; - public double VolumeLtrEnd; - double volumeLtrEnd1; - double volumeLtrEnd2; + public double VolumeLtrStart; /// Test start volume for metrology + public double VolumeLtrEnd; /// Test end volume for metrology + public double VolumeLtrRef; /// Reference volume or metrology + double volumeLtrEnd1; /// auxiliary buffer1 to keep the end volume before test stops + double volumeLtrEnd2; /// auxiliary buffer2 to keep the end volume before test stops /// /// Timestamp from the opto telegram