2015-08-11 06:50:32 +00:00
///
2021-07-28 09:40:45 +00:00
/// Copyright (c) 2015-2021 Sensus Slovensko a.s.
2015-08-11 06:50:32 +00:00
///
2016-10-27 12:27:37 +00:00
//#define VERIFY_ACTIVE_MODE
//#define VERIFY_Q2_CORR_RESET
2015-08-11 06:50:32 +00:00
using System ;
using System.Collections.Generic ;
using System.Drawing ;
2015-08-14 17:20:47 +00:00
using System.Globalization ;
2015-08-11 06:50:32 +00:00
using System.Runtime.InteropServices ;
2016-04-19 08:10:51 +00:00
using System.Text ;
2015-08-11 06:50:32 +00:00
using System.Threading ;
using System.Windows.Forms ;
using log4net ;
2021-09-23 09:46:40 +00:00
using Common ;
2018-04-10 14:10:44 +00:00
using Config ;
2015-12-04 16:17:20 +00:00
using Config.Entities ;
2015-08-11 06:50:32 +00:00
using TBF.Resources ;
2021-10-26 09:23:57 +00:00
using TBF.Rig.Sequences ;
using TBF.Rig.TestMethods.iPerlCommunication.iPerlHead ;
2015-08-11 06:50:32 +00:00
2021-10-26 09:23:57 +00:00
namespace TBF.Rig.TestMethods.iPerlCommunication
2015-08-11 06:50:32 +00:00
{
2015-08-17 14:02:30 +00:00
public enum CommErr
{
None = 0 ,
2017-08-22 13:11:21 +00:00
CommFailed , /// 1
OpenPort , /// 2
Read , /// 3
2017-09-06 08:25:22 +00:00
Read1 , /// 4
Read2 , /// 5
Read3 , /// 6
Read4 , /// 7
Write , /// 8
ReadAfterWrite , /// 9
2021-07-29 11:03:08 +00:00
CmdActive , /// 0AH = 10
CmdTest , /// 0BH = 11
Verify , /// 0CH = 12
WrongIPerlType , /// 0DH = 13
OutOfRange , /// 0EH = 14
Q2OutOfRange , /// 0FH = 15
2019-05-22 05:52:13 +00:00
MissingTest , /// 10H = 16
RFPowerRecordMissing , /// 11H = 17
HeadDisabledByUser , /// 12H = 18
WrongArguments , /// 13H = 19
2015-08-17 14:02:30 +00:00
}
2015-08-11 06:50:32 +00:00
public partial class iPerlCommunicationForm : Form , GenericDevices . IHasCompleted
{
2019-06-14 06:43:36 +00:00
private static readonly ILog log = LogManager . GetLogger ( typeof ( iPerlCommunicationForm ) ) ;
protected static readonly ILog rfidDataLogger = LogManager . GetLogger ( "RfidData" ) ;
2018-10-17 09:31:28 +00:00
const int Hz2CorrFactorsAddr = 0x1875 ; /// Used by Reset2HzCorrection(...) and Write2HzCorrection(...)
const int Q2CorrFactorsAddr = 0x1878 ; /// Used by ResetQ2Correction(...) and WriteQ2Correction(...)
2018-10-17 12:41:07 +00:00
const int Q2CorrFactorsAddrLR = 0x1878 ;
2019-02-04 10:12:34 +00:00
const int Q2CorrFactorsAddrRL = 0x1879 ;
2018-10-17 09:31:28 +00:00
2019-06-14 06:43:36 +00:00
public const string ReadConfigurationStr = "Read configuration" ; /// Example: "Read configuration" or "Read configuration if enabled"
public const string SetTestModeStr = "Set Test mode" ; /// Example: "Set Test mode" or "Set Test mode A0" (hexadecimal number is the required 'testModeConfig'
public const string SetActiveModeStr = "Set Active mode" ;
public const string ReadCalibrationStr = "Read calibration" ;
public const string ReadCalibrationV4Str = "Read calibration_V4" ;
public const string WriteCalibrationFactorStr = "Write calibration factor" ;
public const string WriteCalibrationV4FactorsStr = "Write calibration_V4" ;
public const string NormalizeCalibrationFactorStr = "Normalize calibration factor" ;
public const string NormalizeCalibrationV4FactorsStr = "Normalize calibration_V4" ;
2020-04-27 10:24:54 +00:00
public const string GetDefaultQ2CorrectionsStr = "Get default Q2 corrections" ;
2019-06-14 06:43:36 +00:00
public const string ReadQ2CorrectionStr = "Read Q2 corrections" ;
public const string ResetQ2CorrectionStr = "Reset Q2 correction" ;
2020-04-27 10:24:54 +00:00
public const string WriteDefaultQ2CorrectionsStr = "Write default Q2 corrections" ;
public const string InitOrReadQ2CorrectionsStr = "Init or read Q2 corrections" ;
2020-11-27 08:03:31 +00:00
public const string WriteQ2CorrectionStr = "Write Q2 correction" ; /// No arguments
public const string WriteQ2CorrectionAltStr = "Write Q2 correction Alt" ; /// No arguments
public const string WriteQ2CorrectionGreeceStr = "Write Q2 correction Greece" ; /// Arguments: test_name
public const string WriteQ2CorrectionRLStr = "Write Q2 correction R-L" ; /// Arguments: test_name
public const string WriteQ2CorrectionLRStr = "Write Q2 correction L-R" ; /// Arguments: test_name
public const string WriteQ2CorrectionIncl05Str = "Write_Q2_correction_incl.-0,5..0,5%" ; /// No arguments
public const string WriteQ2CorrectionAltIncl05Str = "Write_Q2_correction_Alt_incl.-0,5..0,5%" ; /// No arguments
public const string WriteQ2CorrectionGreeceIncl05Str = "Write_Q2_correction_Greece_incl.-0,5..0,5%" ; /// Arguments: test_name
public const string WriteQ2CorrectionRLIncl05Str = "Write_Q2_correction_R-L_incl.-0,5..0,5%" ; /// Arguments: test_name
public const string WriteQ2CorrectionLRIncl05Str = "Write_Q2_correction_L-R_incl.-0,5..0,5%" ; /// Arguments: test_name
2021-02-24 11:08:04 +00:00
public const string UpdateBothQ2FactorsTestRLOnlyStr = "Update_both_Q2_factors_Test_RL_only" ; /// No arguments
public const string UpdateBothQ2FactorsTestLROnlyStr = "Update_both_Q2_factors_Test_LR_only" ; /// No arguments
2020-11-27 08:03:31 +00:00
public const string UpdateQ2CorrectionsStr = "Update Q2 corrections" ; /// Arguments: R-L_test_name L-R_test_name
public const string ConditnlUpdateQ2CorrectionsStr = "Conditional update of Q2 corrections" ; /// Arguments: R-L_test_name L-R_test_name
2021-07-29 11:03:08 +00:00
public const string ConditnlUpdateQ2CorrRLStr = "Conditional update of Q2 correction R-L" ; /// Arguments: R-L_test_name
public const string ConditnlUpdateQ2CorrLRStr = "Conditional update of Q2 correction L-R" ; /// Arguments: L-R_test_name
2019-06-14 06:43:36 +00:00
public const string Reset2HzCorrectionStr = "Reset 2Hz correction" ;
public const string Write2HzCorrectionStr = "Write 2Hz correction" ;
2021-10-04 12:30:27 +00:00
public const string DewaReworkRLStr = "DEWA rework R-L" ;
public const string DewaReworkLRStr = "DEWA rework L-R" ;
2019-06-14 06:43:36 +00:00
2018-12-03 07:14:15 +00:00
public static Color DisabledColor = Color . DarkGray ;
public static Color OptoAndDirOKColor = Color . Green ;
public static Color OptoNokColor = Color . Orange ;
public static Color DirNokColor = Color . Red ;
2015-08-11 06:50:32 +00:00
2019-06-14 06:43:36 +00:00
#region DLL_Interface
2015-08-11 06:50:32 +00:00
2021-09-24 07:31:05 +00:00
[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 ) ;
2015-08-19 11:04:47 +00:00
[DllImport("libRfid1.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort1 ( MessageID messageId , int offset , int lenght , byte * ptr , int timeout_ms ) ;
2015-08-11 06:50:32 +00:00
2021-09-24 07:31:05 +00:00
[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 ) ;
2015-08-19 11:04:47 +00:00
[DllImport("libRfid2.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort2 ( MessageID messageId , int offset , int lenght , byte * ptr , int timeout_ms ) ;
2015-08-11 06:50:32 +00:00
2021-09-24 07:31:05 +00:00
[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 ) ;
2015-08-19 11:04:47 +00:00
[DllImport("libRfid3.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort3 ( MessageID messageId , int offset , int lenght , byte * ptr , int timeout_ms ) ;
2015-08-11 06:50:32 +00:00
2021-09-24 07:31:05 +00:00
[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 ) ;
2015-08-19 11:04:47 +00:00
[DllImport("libRfid4.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort4 ( MessageID messageId , int offset , int lenght , byte * ptr , int timeout_ms ) ;
2015-08-11 06:50:32 +00:00
2021-09-24 07:31:05 +00:00
[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 ) ;
2015-08-11 06:50:32 +00:00
2015-08-19 11:04:47 +00:00
/// <summary>
/// Wrapper function with safe interface and unsafe body
/// </summary>
2017-08-04 15:45:40 +00:00
/// <param name="iperlHead">Water meter (iPerlHead) object</param>
2015-08-19 11:04:47 +00:00
/// <returns>Value returned by openPort(...)</returns>
2021-09-24 07:31:05 +00:00
public static unsafe int OpenPort ( IperlHead iperlHead )
2015-08-19 11:04:47 +00:00
{
2017-05-31 12:51:26 +00:00
if ( iperlHead . DebugLevel ! = DebugMode . Normal ) return 0 ; /// No function in debug mode
2015-08-27 05:03:42 +00:00
2021-09-24 07:31:05 +00:00
switch ( iperlHead . Position )
2017-08-04 15:45:40 +00:00
{
default :
2021-09-24 07:31:05 +00:00
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 ) ;
2017-08-04 15:45:40 +00:00
}
2015-08-19 11:04:47 +00:00
}
2015-08-15 21:01:26 +00:00
/// <summary>
/// Wrapper function with safe interface and unsafe body
/// </summary>
2017-08-04 15:45:40 +00:00
/// <param name="iperlHead">Water meter (iPerlHead) object</param>
2015-08-15 21:01:26 +00:00
/// <returns>Value returned by openPort(...)</returns>
2021-09-24 07:31:05 +00:00
public static unsafe int ClosePort ( IperlHead iperlHead )
2015-08-15 21:01:26 +00:00
{
2017-05-31 12:51:26 +00:00
if ( iperlHead . DebugLevel ! = DebugMode . Normal ) return 0 ; /// No function in debug mode
2015-08-27 05:03:42 +00:00
2021-09-24 07:31:05 +00:00
switch ( iperlHead . Position )
2015-08-19 11:04:47 +00:00
{
2017-08-04 15:45:40 +00:00
default :
2021-09-24 07:31:05 +00:00
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 ( ) ;
2015-08-19 11:04:47 +00:00
}
2015-08-15 21:01:26 +00:00
}
2015-08-19 11:04:47 +00:00
/// <summary>
2015-08-15 21:01:26 +00:00
/// Wrapper function with safe interface and unsafe body
2015-08-11 06:50:32 +00:00
/// </summary>
2017-08-04 15:45:40 +00:00
/// <param name="iperlHead">Water meter (iPerlHead) object</param>
2015-08-11 06:50:32 +00:00
/// <returns>Value returned by readRequestPort(...)</returns>
2021-09-24 07:31:05 +00:00
public static unsafe int ReadRequestPort ( IperlHead iperlHead , MessageID messageID , int offset , int length , out byte [ ] buffer , int timeout )
2015-08-11 06:50:32 +00:00
{
2021-09-24 07:31:05 +00:00
Thread . Sleep ( Math . Max ( 250 , cfg . DelayBetweenRetries ) ) ;
2019-09-10 12:41:01 +00:00
if ( iperlHead . DebugLevel ! = DebugMode . Normal )
{
///
/// Simulation
///
if ( ( messageID = = MessageID . Configuration ) & & ( offset = = 0 ) & & ( length = = ConfigStruct . Length ) )
{
buffer = new byte [ ConfigStruct . Length ] { 3 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 2 , 3 , 4 , 5 , 160 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ;
}
else if ( ( messageID = = MessageID . Calibration ) & & ( offset = = 0 ) & & ( length = = CalibrationStruct . Length ) )
{
buffer = new byte [ CalibrationStruct . Length ] { 3 , 0 , 150 , 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 2 , 3 , 4 , 5 , 0 , 0 } ;
}
else if ( ( messageID = = MessageID . Calibration ) & & ( offset = = 0 ) & & ( length = = CalibrationStructV4 . Length ) )
{
buffer = new byte [ CalibrationStructV4 . Length ] { 3 , 0 , 150 , 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 2 , 3 , 4 , 5 , 0 , 0 , 150 , 10 } ;
}
else if ( ( messageID = = MessageID . Calibration ) & & ( offset = = 2 ) & & ( length = = 2 ) )
{
buffer = new byte [ 2 ] { 150 , 10 } ;
}
else if ( ( messageID = = MessageID . Calibration ) & & ( offset = = 34 ) & & ( length = = 2 ) )
{
buffer = new byte [ 2 ] { 150 , 10 } ;
}
else if ( ( messageID = = MessageID . MetrologyMemory ) & & ( offset = = Q2CorrFactorsAddr ) & & ( length = = 2 ) )
{
buffer = new byte [ 2 ] { 0 , 0 } ;
}
else
{
buffer = new byte [ length ] ;
}
2016-10-27 12:27:37 +00:00
2019-09-10 12:41:01 +00:00
return iperlHead . Name . Equals ( "iPerl13" ) ? 2 : 0 ; /// Simulates an error on position 13
}
2015-08-11 06:50:32 +00:00
2019-09-10 12:41:01 +00:00
buffer = new byte [ length ] ;
2016-10-27 12:27:37 +00:00
byte [ ] buf = new byte [ 200 ] ;
///
fixed ( byte * pBuf = buf )
2015-08-11 06:50:32 +00:00
{
2016-10-27 12:27:37 +00:00
int retv ;
2021-09-24 07:31:05 +00:00
switch ( iperlHead . Position )
2016-10-27 12:27:37 +00:00
{
2017-08-04 15:45:40 +00:00
default :
2021-09-24 07:31:05 +00:00
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 ;
2016-10-27 12:27:37 +00:00
}
2015-08-19 11:04:47 +00:00
2019-09-10 12:41:01 +00:00
for ( int i = 0 ; i < length ; i + + ) buffer [ i ] = buf [ i ] ;
2015-09-16 14:30:30 +00:00
2016-10-27 12:27:37 +00:00
///
/// Logging
///
2017-05-31 12:51:26 +00:00
string name = string . Format ( "{0}({1})" , iperlHead . Name , iperlHead . SerialNr ) ;
2019-09-10 12:41:01 +00:00
if ( ( messageID = = MessageID . Configuration ) & & ( offset = = 0 ) & & ( length = = ConfigStruct . Length ) )
2017-05-31 12:51:26 +00:00
rfidDataLogger . InfoFormat ( "{0}: ReadRequestPort({1},...) returned {2} {3}" , name , messageID , retv , ( retv ! = 0 ) ? "!" : ConfigStruct . FromByteArray ( buffer ) . ToString ( ) ) ;
2019-09-10 12:41:01 +00:00
else if ( ( messageID = = MessageID . Calibration ) & & ( offset = = 0 ) & & ( length = = CalibrationStruct . Length ) )
2017-05-31 12:51:26 +00:00
rfidDataLogger . InfoFormat ( "{0}: ReadRequestPort({1},...) returned {2} {3}" , name , messageID , retv , ( retv ! = 0 ) ? "!" : CalibrationStruct . FromByteArray ( buffer ) . ToString ( ) ) ;
2019-09-10 12:41:01 +00:00
else if ( ( messageID = = MessageID . Calibration ) & & ( offset = = 0 ) & & ( length = = CalibrationStructV4 . Length ) )
2018-09-20 07:05:32 +00:00
rfidDataLogger . InfoFormat ( "{0}: ReadRequestPort({1},...) returned {2} {3}" , name , messageID , retv , ( retv ! = 0 ) ? "!" : CalibrationStructV4 . FromByteArray ( buffer ) . ToString ( ) ) ;
2019-09-10 12:41:01 +00:00
else if ( ( messageID = = MessageID . Calibration ) & & ( offset = = 2 ) & & ( length = = 2 ) )
2016-10-27 12:27:37 +00:00
rfidDataLogger . InfoFormat ( "{0}: ReadRequestPort({1},2,2,...) returned {2} {3}" , name , messageID , retv , ( retv ! = 0 ) ? "!" : string . Format ( "Cal={0}" , buf [ 0 ] + 256 * buf [ 1 ] ) ) ;
2019-09-10 12:41:01 +00:00
else if ( ( messageID = = MessageID . Calibration ) & & ( offset = = 34 ) & & ( length = = 2 ) )
2018-09-20 07:05:32 +00:00
rfidDataLogger . InfoFormat ( "{0}: ReadRequestPort({1},34,2,...) returned {2} {3}" , name , messageID , retv , ( retv ! = 0 ) ? "!" : string . Format ( "CalLNA={0}" , buf [ 0 ] + 256 * buf [ 1 ] ) ) ;
2019-09-10 12:41:01 +00:00
else if ( ( messageID = = MessageID . MetrologyMemory ) & & ( offset = = Q2CorrFactorsAddr ) & & ( length = = 2 ) )
2019-02-06 09:34:43 +00:00
rfidDataLogger . InfoFormat ( "{0}: ReadRequestPort({1},6264,2,...) returned {2} {3}" , name , messageID , retv , ( retv ! = 0 ) ? "!" : string . Format ( "LR={0} RL={1}" , ( int ) buf [ 0 ] , ( int ) buf [ 1 ] ) ) ;
2016-10-27 12:27:37 +00:00
else
2019-09-10 12:41:01 +00:00
rfidDataLogger . InfoFormat ( "{0}: ReadRequestPort({1}, {2}, {3}, ...) returned {4} {5}" , name , messageID , offset , length , retv , ( retv ! = 0 ) ? "!" : "" ) ;
2015-08-11 06:50:32 +00:00
2016-10-27 12:27:37 +00:00
return retv ;
}
2015-08-11 06:50:32 +00:00
}
/// <summary>
2021-09-24 07:31:05 +00:00
/// Wrapper function with safe interface and unsafe body
2015-08-11 06:50:32 +00:00
/// </summary>
2017-08-04 15:45:40 +00:00
/// <param name="iperlHead">Water meter (iPerlHead) object</param>
2015-08-11 06:50:32 +00:00
/// <returns>Value returned by writeRequestPort(...)</returns>
2021-09-24 07:31:05 +00:00
public static unsafe int WriteRequestPort ( IperlHead iperlHead , MessageID messageID , int offset , int length , byte [ ] buffer , int timeout )
2015-08-11 06:50:32 +00:00
{
2021-09-24 07:31:05 +00:00
Thread . Sleep ( Math . Max ( 250 , cfg . DelayBetweenRetries ) ) ;
2017-05-31 12:51:26 +00:00
if ( iperlHead . DebugLevel ! = DebugMode . Normal ) return 0 ;
2016-10-27 12:27:37 +00:00
2015-08-11 06:50:32 +00:00
fixed ( byte * pBuf = buffer )
{
2016-10-27 12:27:37 +00:00
int retv ;
2021-09-24 07:31:05 +00:00
switch ( iperlHead . Position )
2016-10-27 12:27:37 +00:00
{
2017-08-04 15:45:40 +00:00
default :
2021-09-24 07:31:05 +00:00
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 ;
2016-10-27 12:27:37 +00:00
}
2015-08-19 11:04:47 +00:00
2016-10-27 12:27:37 +00:00
///
/// Logging
///
2017-05-31 12:51:26 +00:00
string name = string . Format ( "{0}({1})" , iperlHead . Name , iperlHead . SerialNr ) ;
2019-09-10 12:41:01 +00:00
if ( length = = 1 )
rfidDataLogger . InfoFormat ( "{0}: WriteRequestPort({2}, {3}, {4}, {5}) returned {1} {6}" , name , retv , messageID , offset , length , pBuf [ 0 ] . ToString ( "X2" ) , ( retv ! = 0 ) ? "!" : "" ) ;
else if ( length = = 2 )
2015-08-15 21:01:26 +00:00
{
2015-09-16 14:30:30 +00:00
if ( messageID = = MessageID . Calibration & & offset = = 2 )
{
UInt16 calibFactor = ( UInt16 ) ( pBuf [ 0 ] + 256 * pBuf [ 1 ] ) ;
2018-11-15 11:39:29 +00:00
rfidDataLogger . InfoFormat ( "{0}: WriteRequestPort(Cal={1}) returned {2} {3}" , name , calibFactor , retv , ( retv ! = 0 ) ? "!" : "" ) ;
2015-09-16 14:30:30 +00:00
}
2018-11-15 11:39:29 +00:00
else if ( messageID = = MessageID . Calibration & & offset = = 34 )
{
UInt16 calibFactor = ( UInt16 ) ( pBuf [ 0 ] + 256 * pBuf [ 1 ] ) ;
rfidDataLogger . InfoFormat ( "{0}: WriteRequestPort(CalLNA={1}) returned {2} {3}" , name , calibFactor , retv , ( retv ! = 0 ) ? "!" : "" ) ;
}
else
2019-09-10 12:41:01 +00:00
rfidDataLogger . InfoFormat ( "{0}: WriteRequestPort({2}, {3}, {4}, {5} {6}) returned {1} {7}" , name , retv , messageID , offset , length , pBuf [ 0 ] . ToString ( "X2" ) , pBuf [ 1 ] . ToString ( "X2" ) , ( retv ! = 0 ) ? "!" : "" ) ;
2015-08-15 21:01:26 +00:00
}
else
2019-09-10 12:41:01 +00:00
rfidDataLogger . InfoFormat ( "{0}: WriteRequestPort({2}, {3}, {4}, {5} {6} ...) returned {1} {7}" , name , retv , messageID , offset , length , pBuf [ 0 ] . ToString ( "X2" ) , pBuf [ 1 ] . ToString ( "X2" ) , ( retv ! = 0 ) ? "!" : "" ) ;
2016-10-27 12:27:37 +00:00
return retv ;
2015-08-15 21:01:26 +00:00
}
2015-08-11 06:50:32 +00:00
}
#endregion DLL_Interface
2017-11-03 09:57:30 +00:00
readonly bool checkBoxesEditMode ;
2016-01-08 18:18:45 +00:00
DateTime startTime ;
int startTimeSec ;
2015-08-11 06:50:32 +00:00
// Set to 'true' when the form closes
public bool Completed { get { return formCompleted ; } }
bool formCompleted ;
2018-09-18 13:23:49 +00:00
bool forcedClose ; /// Set in the forced close handler
2015-08-11 06:50:32 +00:00
/// <summary> Number of text boxes for serial numbers </summary>
2016-01-19 16:38:09 +00:00
public int WaterMetersCount ;
2015-08-11 06:50:32 +00:00
2017-11-03 09:57:30 +00:00
const int MaxTextBoxesCount = 48 ;
2015-08-11 06:50:32 +00:00
int textBoxesCount ;
Label [ ] labels ;
2016-06-27 13:24:10 +00:00
PictureBox [ ] counters ;
2015-08-11 06:50:32 +00:00
TextBox [ ] messages ;
2017-10-11 06:47:36 +00:00
CheckBoxImage [ ] checkBoxes ;
2017-10-11 07:19:55 +00:00
static int [ ] ckbIndex ;
static bool [ ] ckbState ;
2015-08-11 06:50:32 +00:00
2017-05-31 12:51:26 +00:00
static IList < IperlHead > iperlHeads ;
2017-11-03 09:57:30 +00:00
static IList < int > waterMeterPositions0 ; /// keeps original 0-based indices in RegisterReaders list
2020-04-27 10:24:54 +00:00
static int commonWMType ;
2015-09-04 11:49:04 +00:00
2015-08-11 06:50:32 +00:00
///
/// RFID multiplexer PCB / RFID serial port and worker thread related variables
///
2015-09-04 11:49:04 +00:00
static TestMethodCfg cfg ;
2016-01-19 16:38:09 +00:00
static IList < Config . Entities . Test > tests ;
2015-09-04 11:49:04 +00:00
static IList < iPerlCommunicationParams > multiTestParams ;
static int currentActivityStep ;
static int currentGroup ; /// form -> worker thread (0 = none)
2015-08-11 06:50:32 +00:00
static int lastGroup ;
2015-08-12 14:05:06 +00:00
static int completedCommCount ; /// Number of completed communication steps
2015-08-11 06:50:32 +00:00
static IList < Thread > workerThreads ;
2017-08-04 15:45:40 +00:00
static IList < int > muxBrdOrGroup14Nrs ;
2015-09-04 11:49:04 +00:00
static bool stopWorkerThreads ; /// form -> worker thread
2015-08-11 06:50:32 +00:00
2015-09-04 11:49:04 +00:00
/// <summary> Parameterless constructor (without watermeters, threads) </summary>
2015-08-11 06:50:32 +00:00
public iPerlCommunicationForm ( )
{
InitializeComponent ( ) ;
2017-11-03 09:57:30 +00:00
}
2015-08-11 06:50:32 +00:00
2017-11-03 09:57:30 +00:00
/// <summary>
/// Constructor for checkBox states (active/inactive iPerl head) editing.
/// </summary>
/// <param name="checkBoxes">Initial check box states</param>
2018-08-30 13:40:27 +00:00
public iPerlCommunicationForm ( bool isCheckBoxesEditMode )
2017-11-03 09:57:30 +00:00
: this ( )
{
2018-08-30 13:40:27 +00:00
if ( isCheckBoxesEditMode )
{
checkBoxesEditMode = true ;
saveButton . Visible = true ;
2021-07-28 09:40:45 +00:00
activityLabel . Text = Strings . Optical_heads ;
ShuffleTextBoxes ( ProcessData . WMsCount , ProcessData . LineSize ) ;
2018-08-30 13:40:27 +00:00
}
2015-08-11 06:50:32 +00:00
}
2015-09-04 11:49:04 +00:00
2015-08-11 06:50:32 +00:00
/// <summary>
2016-01-19 16:38:09 +00:00
/// Constructor for one iPerlCommunication 'test'
2015-08-11 06:50:32 +00:00
/// </summary>
/// <param name="waterMetersCount">Number of text boxes for serial numbers</param>
2016-01-19 16:38:09 +00:00
public iPerlCommunicationForm ( TestMethodCfg cfg , Test test , iPerlCommunicationParams testParams )
2019-03-28 08:33:17 +00:00
: this ( cfg , new List < Test > { test } , new List < iPerlCommunicationParams > { testParams } )
2016-01-19 16:38:09 +00:00
{
}
/// <summary>
/// Constructor for multiple iPerlCommunication 'tests'
/// </summary>
/// <param name="waterMetersCount">Number of text boxes for serial numbers</param>
public iPerlCommunicationForm ( TestMethodCfg cfg , IList < Test > tests , IList < iPerlCommunicationParams > multiTestParams )
2015-08-11 06:50:32 +00:00
: this ( )
2015-09-04 11:49:04 +00:00
{
2017-11-03 09:57:30 +00:00
checkBoxesEditMode = false ;
2015-09-06 21:36:14 +00:00
iPerlCommunicationForm . cfg = cfg ;
2016-01-19 16:38:09 +00:00
iPerlCommunicationForm . tests = tests ;
iPerlCommunicationForm . multiTestParams = multiTestParams ;
2015-09-06 21:36:14 +00:00
2016-01-19 16:38:09 +00:00
if ( multiTestParams . Count > 0 )
{
2016-02-13 15:40:26 +00:00
ProcessData . RegisterReaders = StateMachine . GetMetersPath ( tests [ 0 ] ) . RegisterReaders ;
2016-01-19 16:38:09 +00:00
activityLabel . Text = multiTestParams [ 0 ] . Activity ;
2020-04-27 10:24:54 +00:00
foreach ( var p in multiTestParams )
{
if ( p . Activity . ToLower ( ) = = GetDefaultQ2CorrectionsStr . ToLower ( ) )
{
/// Reset IsQ2PreCorrectionCalculated that is used for synchronization/to prevent double REST call
ProcessData . IsQ2PreCorrectionCalculated = false ;
commonWMType = 0 ;
break ;
}
}
2016-01-19 16:38:09 +00:00
}
2020-04-27 10:24:54 +00:00
PrepareForTestsActivities ( ) ;
2016-01-19 16:38:09 +00:00
}
2020-04-27 10:24:54 +00:00
void PrepareForTestsActivities ( )
2016-01-19 16:38:09 +00:00
{
2017-11-03 09:57:30 +00:00
startTime = DateTime . Now ;
startTimeSec = StateMachine . Time ;
/// Attach to 'CommCompleted' handler
CommCompletedHandler + = delegate ( object sender , CommCompletedEventArgs args )
{
if ( InvokeRequired )
{
Invoke ( new EventHandler < CommCompletedEventArgs > ( DoOnCommCompleted ) , sender , args ) ;
}
else DoOnCommCompleted ( sender , args ) ;
} ;
/// Attach to 'AllCompleted' handler
AllCompletedHandler + = delegate ( object sender , AllCompletedEventArgs args )
{
if ( InvokeRequired )
{
Invoke ( new EventHandler < AllCompletedEventArgs > ( DoOnAllCompleted ) , sender , args ) ;
}
else DoOnAllCompleted ( sender , args ) ;
} ;
formCompleted = false ;
StartForceCloseHandler ( ) ;
iperlHeads = new List < IperlHead > ( ) ;
waterMeterPositions0 = new List < int > ( ) ;
2017-08-04 15:45:40 +00:00
///
2017-02-14 14:41:50 +00:00
for ( int wmPos = 0 ; wmPos < ProcessData . RegisterReaders . Length ; wmPos + + )
2015-09-04 11:49:04 +00:00
{
2017-05-31 12:51:26 +00:00
IperlHead iperlHead = ProcessData . RegisterReaders [ wmPos ] as IperlHead ;
2017-02-14 14:41:50 +00:00
2017-05-31 12:51:26 +00:00
if ( iperlHead ! = null )
2016-04-19 08:10:51 +00:00
{
2017-05-31 12:51:26 +00:00
iperlHeads . Add ( iperlHead ) ;
2017-11-03 09:57:30 +00:00
waterMeterPositions0 . Add ( wmPos ) ;
2016-04-19 08:10:51 +00:00
}
2015-09-04 11:49:04 +00:00
}
2017-05-31 12:51:26 +00:00
WaterMetersCount = iperlHeads . Count ;
2021-07-28 09:40:45 +00:00
ShuffleTextBoxes ( WaterMetersCount , ProcessData . LineSize ) ;
2015-09-04 11:49:04 +00:00
///
/// Prepare worker threads, 'rfidPortNrs', 'lastGroup', etc..
///
currentActivityStep = 0 ;
currentGroup = 0 ;
completedCommCount = 0 ;
stopWorkerThreads = false ;
2017-08-04 15:45:40 +00:00
/// group numbers are >=1, lastGroup == 0 means there is no group
lastGroup = 0 ;
foreach ( var iPerl in iPerlCommunicationForm . iperlHeads )
{
if ( iPerl . Group > lastGroup ) lastGroup = iPerl . Group ;
}
2015-09-04 11:49:04 +00:00
2017-08-04 15:45:40 +00:00
workerThreads = new List < Thread > ( ) ;
for ( int i = 0 ; i < cfg . NrThreads ; i + + )
{
2020-04-27 10:24:54 +00:00
Thread thread = new Thread ( Worker ) ;
2017-10-11 07:19:55 +00:00
thread . CurrentCulture = CultureInfo . CurrentCulture ;
thread . CurrentUICulture = CultureInfo . CurrentUICulture ;
2017-08-04 15:45:40 +00:00
workerThreads . Add ( thread ) ;
}
2015-09-11 12:15:32 +00:00
2017-08-04 15:45:40 +00:00
muxBrdOrGroup14Nrs = new List < int > ( ) ;
foreach ( var iPerl in iPerlCommunicationForm . iperlHeads )
{
if ( ! muxBrdOrGroup14Nrs . Contains ( iPerl . MuxBoardNrOrGroup14 ) ) muxBrdOrGroup14Nrs . Add ( iPerl . MuxBoardNrOrGroup14 ) ;
}
2016-04-19 08:10:51 +00:00
2021-07-28 12:47:05 +00:00
log . WarnFormat ( "nrThreads = {0}" , workerThreads . Count ) ;
2015-09-04 11:49:04 +00:00
}
2015-08-11 06:50:32 +00:00
/// <summary>
/// Make sure the layout of labels/text boxes on the screen
/// corresponds to the layout of watermeters of the test bench.
/// </summary>
/// <param name="wmsCount">Number of watermeters</param>
/// <param name="lineSize">Number of watermeters in one line</param>
void ShuffleTextBoxes ( int wmsCount , int lineSize )
{
2017-11-03 09:57:30 +00:00
labels = new Label [ MaxTextBoxesCount ]
{
wmLabel1 , wmLabel2 , wmLabel3 , wmLabel4 , wmLabel5 , wmLabel6 , wmLabel7 , wmLabel8 , wmLabel9 , wmLabel10 ,
wmLabel11 , wmLabel12 , wmLabel13 , wmLabel14 , wmLabel15 , wmLabel16 , wmLabel17 , wmLabel18 , wmLabel19 , wmLabel20 ,
wmLabel21 , wmLabel22 , wmLabel23 , wmLabel24 , wmLabel25 , wmLabel26 , wmLabel27 , wmLabel28 , wmLabel29 , wmLabel30 ,
wmLabel31 , wmLabel32 , wmLabel33 , wmLabel34 , wmLabel35 , wmLabel36 , wmLabel37 , wmLabel38 , wmLabel39 , wmLabel40 ,
wmLabel41 , wmLabel42 , wmLabel43 , wmLabel44 , wmLabel45 , wmLabel46 , wmLabel47 , wmLabel48 ,
} ;
counters = new PictureBox [ MaxTextBoxesCount ]
{
pictureBox1 , pictureBox2 , pictureBox3 , pictureBox4 , pictureBox5 , pictureBox6 , pictureBox7 , pictureBox8 , pictureBox9 , pictureBox10 ,
pictureBox11 , pictureBox12 , pictureBox13 , pictureBox14 , pictureBox15 , pictureBox16 , pictureBox17 , pictureBox18 , pictureBox19 , pictureBox20 ,
pictureBox21 , pictureBox22 , pictureBox23 , pictureBox24 , pictureBox25 , pictureBox26 , pictureBox27 , pictureBox28 , pictureBox29 , pictureBox30 ,
pictureBox31 , pictureBox32 , pictureBox33 , pictureBox34 , pictureBox35 , pictureBox36 , pictureBox37 , pictureBox38 , pictureBox39 , pictureBox40 ,
pictureBox41 , pictureBox42 , pictureBox43 , pictureBox44 , pictureBox45 , pictureBox46 , pictureBox47 , pictureBox48 ,
} ;
messages = new TextBox [ MaxTextBoxesCount ]
{
wmTextBox1 , wmTextBox2 , wmTextBox3 , wmTextBox4 , wmTextBox5 , wmTextBox6 , wmTextBox7 , wmTextBox8 , wmTextBox9 , wmTextBox10 ,
wmTextBox11 , wmTextBox12 , wmTextBox13 , wmTextBox14 , wmTextBox15 , wmTextBox16 , wmTextBox17 , wmTextBox18 , wmTextBox19 , wmTextBox20 ,
wmTextBox21 , wmTextBox22 , wmTextBox23 , wmTextBox24 , wmTextBox25 , wmTextBox26 , wmTextBox27 , wmTextBox28 , wmTextBox29 , wmTextBox30 ,
wmTextBox31 , wmTextBox32 , wmTextBox33 , wmTextBox34 , wmTextBox35 , wmTextBox36 , wmTextBox37 , wmTextBox38 , wmTextBox39 , wmTextBox40 ,
wmTextBox41 , wmTextBox42 , wmTextBox43 , wmTextBox44 , wmTextBox45 , wmTextBox46 , wmTextBox47 , wmTextBox48 ,
} ;
checkBoxes = new CheckBoxImage [ MaxTextBoxesCount ]
{
checkBoxImage1 , checkBoxImage2 , checkBoxImage3 , checkBoxImage4 , checkBoxImage5 , checkBoxImage6 , checkBoxImage7 , checkBoxImage8 , checkBoxImage9 , checkBoxImage10 ,
checkBoxImage11 , checkBoxImage12 , checkBoxImage13 , checkBoxImage14 , checkBoxImage15 , checkBoxImage16 , checkBoxImage17 , checkBoxImage18 , checkBoxImage19 , checkBoxImage20 ,
checkBoxImage21 , checkBoxImage22 , checkBoxImage23 , checkBoxImage24 , checkBoxImage25 , checkBoxImage26 , checkBoxImage27 , checkBoxImage28 , checkBoxImage29 , checkBoxImage30 ,
checkBoxImage31 , checkBoxImage32 , checkBoxImage33 , checkBoxImage34 , checkBoxImage35 , checkBoxImage36 , checkBoxImage37 , checkBoxImage38 , checkBoxImage39 , checkBoxImage40 ,
checkBoxImage41 , checkBoxImage42 , checkBoxImage43 , checkBoxImage44 , checkBoxImage45 , checkBoxImage46 , checkBoxImage47 , checkBoxImage48 ,
} ;
ckbIndex = new int [ MaxTextBoxesCount ] ;
ckbState = new bool [ MaxTextBoxesCount ] ;
textBoxesCount = MaxTextBoxesCount ;
///
if ( wmsCount < textBoxesCount & & lineSize > 0 )
2015-08-11 06:50:32 +00:00
{
int nrLines = ( wmsCount + lineSize - 1 ) / lineSize ;
int gap = ( textBoxesCount - wmsCount ) / nrLines ;
2021-07-16 15:57:55 +00:00
for ( int i = 0 ; i < ckbIndex . Length ; i + + )
{
ckbIndex [ i ] = - 1 ; /// Initialize with invalid indices
}
2015-08-11 06:50:32 +00:00
int dest = 0 ;
2021-07-28 09:40:45 +00:00
for ( int l = 0 ; l < nrLines ; l + + )
2015-08-11 06:50:32 +00:00
{
for ( int i = 0 ; i < lineSize ; i + + )
{
2021-07-16 15:57:55 +00:00
int origin = l * lineSize + l * gap + i ;
labels [ dest ] = labels [ origin ] ;
counters [ dest ] = counters [ origin ] ;
messages [ dest ] = messages [ origin ] ;
checkBoxes [ dest ] = checkBoxes [ origin ] ;
ckbIndex [ origin ] = dest ;
2017-10-11 07:19:55 +00:00
dest + + ;
2015-08-11 06:50:32 +00:00
}
}
2017-11-03 09:57:30 +00:00
2015-08-11 06:50:32 +00:00
textBoxesCount = wmsCount ;
}
2016-04-23 12:32:15 +00:00
2021-07-16 09:37:14 +00:00
int count = checkBoxesEditMode ? textBoxesCount : Math . Min ( textBoxesCount , iperlHeads . Count ) ;
for ( int j = 0 ; j < count ; j + + )
2017-11-03 09:57:30 +00:00
{
2021-07-16 09:37:14 +00:00
labels [ j ] . Text = ( j + 1 ) . ToString ( ) ;
2017-11-03 09:57:30 +00:00
}
ResizeDlgToFitEnabledControls ( ) ;
}
void ResizeDlgToFitEnabledControls ( )
{
2016-04-23 12:32:15 +00:00
int xMax = 0 ;
int yMax = 0 ;
for ( int i = 0 ; i < textBoxesCount ; i + + )
{
if ( messages [ i ] . Left + messages [ i ] . Width > xMax ) xMax = messages [ i ] . Left + messages [ i ] . Width ;
if ( messages [ i ] . Top + messages [ i ] . Height > yMax ) yMax = messages [ i ] . Top + messages [ i ] . Height ;
}
2021-07-16 09:37:14 +00:00
Width = xMax + 50 ;
Height = yMax + 60 ;
2015-08-11 06:50:32 +00:00
}
2016-04-23 12:32:15 +00:00
void Localize ( )
2015-08-11 06:50:32 +00:00
{
2021-07-16 09:37:14 +00:00
Text = checkBoxesEditMode ? Strings . Optical_heads : Strings . Water_Meter_States ;
2017-11-03 09:57:30 +00:00
saveButton . Text = Strings . Save ;
2019-03-28 08:33:17 +00:00
sampleLabel1 . Text = Strings . Direction_and_pulses_are_OK ;
sampleLabel2 . Text = Strings . There_are_no_opto_pulses ;
sampleLabel3 . Text = Strings . Direction_is_NOK ;
samplePictureBox1 . BackColor = OptoAndDirOKColor ;
samplePictureBox2 . BackColor = OptoNokColor ;
samplePictureBox3 . BackColor = DirNokColor ;
2015-08-11 06:50:32 +00:00
}
2015-09-04 11:49:04 +00:00
2015-08-11 06:50:32 +00:00
private void iPerlCommunicationForm_Load ( object sender , EventArgs e )
{
Localize ( ) ;
2021-07-16 09:37:14 +00:00
if ( checkBoxesEditMode )
{
/// Check box edit mode => Hide explanation of activity colours
sampleLabel1 . Visible = false ;
sampleLabel2 . Visible = false ;
sampleLabel3 . Visible = false ;
samplePictureBox1 . Visible = false ;
samplePictureBox2 . Visible = false ;
samplePictureBox3 . Visible = false ;
}
2020-04-27 10:24:54 +00:00
///
/// Set checkbox states accroding to iPerlHeads[i].Disabled states
///
for ( int i = 0 ; i < textBoxesCount ; i + + )
2015-08-11 06:50:32 +00:00
{
2017-10-11 07:19:55 +00:00
labels [ i ] . Visible = counters [ i ] . Visible = messages [ i ] . Visible = checkBoxes [ i ] . Visible = true ;
2017-11-03 09:57:30 +00:00
if ( ! checkBoxesEditMode & & ( iperlHeads [ i ] = = null | | iperlHeads [ i ] . Disabled ) )
2015-08-11 06:50:32 +00:00
{
2020-04-27 10:24:54 +00:00
/// iPerl position i+1 is disabled
2017-10-11 07:19:55 +00:00
checkBoxes [ i ] . Enabled = checkBoxes [ i ] . Checked = ckbState [ i ] = false ;
2018-12-03 07:14:15 +00:00
counters [ i ] . BackColor = DisabledColor ;
2017-10-11 07:19:55 +00:00
messages [ i ] . Text = Strings . Head_was_disabled_by_the_user ;
}
else
{
2020-04-27 10:24:54 +00:00
/// iPerl position i+1 is enabled
2017-10-11 07:19:55 +00:00
checkBoxes [ i ] . Enabled = checkBoxes [ i ] . Checked = ckbState [ i ] = true ;
2015-08-11 06:50:32 +00:00
messages [ i ] . Text = "---" ;
}
}
2020-04-27 10:24:54 +00:00
///
/// Set location and checkbox states to values stored in local settings
///
TBF . LocalSettings ls = Program . LocalSettings ;
2015-09-05 22:09:52 +00:00
Left = ( ls . iPerlCommunicationsFormLeft ! = 0 ) ? ls . iPerlCommunicationsFormLeft : 150 ;
Top = ( ls . iPerlCommunicationsFormTop ! = 0 ) ? ls . iPerlCommunicationsFormTop : 150 ;
2021-08-19 11:49:25 +00:00
SetCheckBoxStates ( ls . OptoHeadsEnabled ) ;
2015-08-19 11:04:47 +00:00
2021-07-28 09:40:45 +00:00
if ( ! checkBoxesEditMode )
2017-08-04 15:45:40 +00:00
{
2020-04-27 10:24:54 +00:00
/// Regular activity (not a checkbox edit mode invoked from TBF menu)
2021-07-28 09:40:45 +00:00
/// Reset opto-data indication
for ( int i = 0 ; i < iperlHeads . Count ; i + + )
{
2018-12-03 07:14:15 +00:00
counters [ i ] . BackColor = OptoNokColor ;
2021-07-28 09:40:45 +00:00
}
2015-09-05 22:09:52 +00:00
2021-07-28 12:47:05 +00:00
/// Start communication process by incrementing 'currentGroup'.
2021-07-28 09:40:45 +00:00
currentGroup + + ;
2017-11-03 09:57:30 +00:00
2021-07-28 09:40:45 +00:00
int wtId = 0 ;
2020-04-27 10:24:54 +00:00
foreach ( var wt in workerThreads )
{
wt . Start ( new Boxes . IntBox ( wtId + + ) ) ; /// Start worker threads !!!
}
2021-07-28 09:40:45 +00:00
}
2017-08-04 15:45:40 +00:00
}
2015-08-11 06:50:32 +00:00
2015-09-04 11:49:04 +00:00
2015-08-11 06:50:32 +00:00
private void NormalClose ( )
{
CommCompletedHandler = null ;
AllCompletedHandler = null ;
2017-02-14 14:41:50 +00:00
if ( multiTestParams ! = null & &
multiTestParams . Count > 0 & &
! multiTestParams [ 0 ] . SimultWithNext ) /// RFID Communication at the end of the cycle does not influence the result
2016-02-08 16:03:07 +00:00
{
UpdateRfidCommResult ( tests ) ; /// TODO: Pass the test info in a correct way
}
2016-01-03 01:05:35 +00:00
2019-10-15 08:03:28 +00:00
long checkboxStates = GetCheckBoxStates ( ) ;
if ( Program . LocalSettings . iPerlCommunicationsFormLeft ! = Location . X | |
Program . LocalSettings . iPerlCommunicationsFormTop ! = Location . Y | |
2021-07-15 08:31:32 +00:00
Program . LocalSettings . OptoHeadsEnabled ! = checkboxStates )
2019-10-15 08:03:28 +00:00
{
/// Update local settings
Program . LocalSettings . iPerlCommunicationsFormLeft = Location . X ;
Program . LocalSettings . iPerlCommunicationsFormTop = Location . Y ;
2021-07-15 08:31:32 +00:00
Program . LocalSettings . OptoHeadsEnabled = checkboxStates ;
2019-10-15 08:03:28 +00:00
Program . LocalSettings . Save ( ) ;
}
2015-08-11 06:50:32 +00:00
formCompleted = true ;
DialogResult = DialogResult . OK ;
Close ( ) ;
}
#region Forced close handling
public void StartForceCloseHandler ( )
{
UiBridge . Bridge . CloseModelessFormHandler + = delegate ( object sender , EventArgs args )
{
if ( InvokeRequired ) { Invoke ( new EventHandler < EventArgs > ( OnForceClose ) , sender , args ) ; }
else OnForceClose ( sender , args ) ;
} ;
}
void OnForceClose ( object sender , EventArgs args )
{
CommCompletedHandler = null ;
AllCompletedHandler = null ;
2015-09-04 11:49:04 +00:00
stopWorkerThreads = true ;
2018-09-18 13:23:49 +00:00
forcedClose = true ;
2015-09-04 11:49:04 +00:00
2015-08-11 06:50:32 +00:00
DialogResult = DialogResult . Cancel ;
Close ( ) ;
}
#endregion
2015-08-15 15:51:54 +00:00
/// <summary>
/// Worker thread
/// </summary>
/// <param name="threadData">Thread ID (integer) wrapped into IntBox</param>
2020-04-27 10:24:54 +00:00
void Worker ( object threadData )
2015-08-11 06:50:32 +00:00
{
2017-08-04 15:45:40 +00:00
int threadID = ( threadData as Boxes . IntBox ) . Val ;
2015-08-11 06:50:32 +00:00
2015-09-04 11:49:04 +00:00
int activityStep = 0 ; /// activity step > 0 in case multiTestParams are used
2015-08-15 21:01:26 +00:00
2016-01-08 18:18:45 +00:00
for ( int i = 0 ; i < multiTestParams . Count ; i + + )
2015-09-04 11:49:04 +00:00
{
2019-03-28 08:33:17 +00:00
Test currentTest = tests [ i ] ;
iPerlCommunicationParams currentTestParams = multiTestParams [ i ] ;
string currentActivity = currentTestParams . Activity ; /// Current activity
2016-01-08 18:18:45 +00:00
2017-05-05 10:41:15 +00:00
TBF . UiBridge . TestProgressEventArgs . SetEstimatedTimes ( new int [ ] { 0 , 0 , 10 , 0 , 140 , 0 , 0 , 0 } ) ;
2021-07-28 09:40:45 +00:00
TBF . UiBridge . Bridge . OnTestProgress ( null , new TBF . UiBridge . TestProgressEventArgs ( tests [ i ] , Progress . JustStarted ) ) ;
2016-01-08 18:18:45 +00:00
2015-08-11 06:50:32 +00:00
2017-08-04 15:45:40 +00:00
if ( threadID = = 0 )
2015-09-04 11:49:04 +00:00
{
rfidDataLogger . InfoFormat ( "" ) ; /// Makes the log more readable when there is a lot of data
2019-03-28 08:33:17 +00:00
rfidDataLogger . WarnFormat ( "Activity = {0}" , currentActivity ) ;
2015-09-04 11:49:04 +00:00
rfidDataLogger . InfoFormat ( "" ) ; /// Makes the log more readable when there is a lot of data
}
2015-08-12 14:05:06 +00:00
2015-09-04 11:49:04 +00:00
for ( int group = 1 ; group < = lastGroup ; group + + )
{
/// Synchronize with QuidoRS and other threads
2015-09-05 22:09:52 +00:00
while ( ( ( group ! = currentGroup ) | | ( activityStep ! = currentActivityStep ) ) & & ! stopWorkerThreads )
2015-09-04 11:49:04 +00:00
{
Thread . Sleep ( 50 ) ;
}
if ( stopWorkerThreads ) break ;
2018-08-30 13:40:27 +00:00
#if TURA_SPECIAL
int threadIx = threadID ; /// Just one thread for TURA_SPECIAL
#else
2017-08-04 15:45:40 +00:00
for ( int threadIx = threadID ; threadIx < threadID + 4 ; threadIx + = cfg . NrThreads )
2018-08-30 13:40:27 +00:00
#endif
{
2015-09-04 11:49:04 +00:00
bool wmFound = false ;
2017-11-03 09:57:30 +00:00
for ( int wmNr0 = 0 ; wmNr0 < iperlHeads . Count ; wmNr0 + + )
2015-09-04 11:49:04 +00:00
{
2017-11-03 09:57:30 +00:00
IperlHead ihead = iperlHeads [ wmNr0 ] ;
2018-10-12 08:54:33 +00:00
if ( ( ihead . Group = = group ) & & ( threadIx < muxBrdOrGroup14Nrs . Count ) & & ( ihead . MuxBoardNrOrGroup14 = = muxBrdOrGroup14Nrs [ threadIx ] ) )
2015-09-04 11:49:04 +00:00
{
wmFound = true ;
2020-02-12 08:15:29 +00:00
Results . Entities . WaterMeter wm = null ;
if ( ProcessData . BatchRslts . Batch . WaterMeters ! = null )
{
foreach ( var w in ProcessData . BatchRslts . Batch . WaterMeters )
{
if ( w . WMPosition = = wmNr0 + 1 )
{
wm = w ;
break ;
}
}
}
2015-09-04 11:49:04 +00:00
CommErr error ;
string resultStr = string . Empty ;
2017-10-11 07:19:55 +00:00
///
/// RFID communication activity call
///
2019-04-03 14:34:05 +00:00
if ( ( ihead = = null ) | | ihead . Disabled | | ! ckbState [ wmNr0 ] ) error = CommErr . HeadDisabledByUser ;
2019-03-28 08:33:17 +00:00
#if IPERL
2020-02-12 08:15:29 +00:00
else if ( currentActivity . ToLower ( ) . Contains ( SetTestModeStr . ToLower ( ) ) ) error = SetTestMode ( threadID , ihead , ref resultStr ) ;
else if ( currentActivity . ToLower ( ) . Equals ( SetActiveModeStr . ToLower ( ) ) ) error = SetActiveMode ( threadID , ihead , ref resultStr ) ;
///
/// RFID communication functions below require a reference to water meter entity (wm != null)
///
else if ( wm = = null ) error = CommErr . CommFailed ;
2021-09-24 07:31:05 +00:00
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 ) ;
2019-03-28 08:33:17 +00:00
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 ) ;
2020-04-27 10:24:54 +00:00
else if ( currentActivity . ToLower ( ) = = NormalizeCalibrationFactorStr . ToLower ( ) ) error = NormalizeCalibrationFactor ( threadID , ihead , wm , ref resultStr ) ;
else if ( currentActivity . ToLower ( ) = = NormalizeCalibrationV4FactorsStr . ToLower ( ) ) error = NormalizeCalibrationV4Factors ( threadID , ihead , wm , ref resultStr ) ;
else if ( currentActivity . ToLower ( ) = = ReadQ2CorrectionStr . ToLower ( ) ) error = ReadQ2Correction ( threadID , ihead , wm , ref resultStr ) ;
else if ( currentActivity . ToLower ( ) = = ResetQ2CorrectionStr . ToLower ( ) ) error = ResetQ2Correction ( threadID , ihead , wm , ref resultStr ) ;
2020-04-30 12:43:53 +00:00
else if ( currentActivity . ToLower ( ) = = WriteDefaultQ2CorrectionsStr . ToLower ( ) ) error = WriteDefaultQ2Corrections ( threadID , ihead , wm , ref resultStr ) ;
else if ( currentActivity . ToLower ( ) = = InitOrReadQ2CorrectionsStr . ToLower ( ) ) error = InitOrReadQ2Corrections ( threadID , ihead , wm , ref resultStr ) ;
2021-07-29 11:03:08 +00:00
else if ( currentActivity . ToLower ( ) = = WriteQ2CorrectionStr . ToLower ( ) ) error = CalculateAndWriteQ2Corrections ( threadID , ihead , wm , currentTest , ref resultStr , Q2CorrType . Standard , null ) ;
else if ( currentActivity . ToLower ( ) = = WriteQ2CorrectionAltStr . ToLower ( ) ) error = CalculateAndWriteQ2Corrections ( threadID , ihead , wm , currentTest , ref resultStr , Q2CorrType . Dewa , null ) ;
else if ( currentActivity . ToLower ( ) . Contains ( WriteQ2CorrectionGreeceStr . ToLower ( ) ) ) error = CalculateAndWriteQ2Corrections ( threadID , ihead , wm , currentTest , ref resultStr , Q2CorrType . Greece , currentActivity . Substring ( WriteQ2CorrectionGreeceStr . Length ) . Trim ( ) ) ;
else if ( currentActivity . ToLower ( ) . Contains ( WriteQ2CorrectionRLStr . ToLower ( ) ) ) error = CalculateAndWriteQ2Corrections ( threadID , ihead , wm , currentTest , ref resultStr , Q2CorrType . RL , currentActivity . Substring ( WriteQ2CorrectionRLStr . Length ) . Trim ( ) ) ;
else if ( currentActivity . ToLower ( ) . Contains ( WriteQ2CorrectionLRStr . ToLower ( ) ) ) error = CalculateAndWriteQ2Corrections ( threadID , ihead , wm , currentTest , ref resultStr , Q2CorrType . LR , currentActivity . Substring ( WriteQ2CorrectionLRStr . Length ) . Trim ( ) ) ;
else if ( currentActivity . ToLower ( ) = = WriteQ2CorrectionIncl05Str . ToLower ( ) ) error = CalculateAndWriteQ2Corrections ( threadID , ihead , wm , currentTest , ref resultStr , Q2CorrType . Standard_incl_05 , null ) ;
else if ( currentActivity . ToLower ( ) = = WriteQ2CorrectionAltIncl05Str . ToLower ( ) ) error = CalculateAndWriteQ2Corrections ( threadID , ihead , wm , currentTest , ref resultStr , Q2CorrType . Dewa_incl_05 , null ) ;
else if ( currentActivity . ToLower ( ) . Contains ( WriteQ2CorrectionGreeceIncl05Str . ToLower ( ) ) ) error = CalculateAndWriteQ2Corrections ( threadID , ihead , wm , currentTest , ref resultStr , Q2CorrType . Greece_incl_05 , currentActivity . Substring ( WriteQ2CorrectionGreeceIncl05Str . Length ) . Trim ( ) ) ;
else if ( currentActivity . ToLower ( ) . Contains ( WriteQ2CorrectionRLIncl05Str . ToLower ( ) ) ) error = CalculateAndWriteQ2Corrections ( threadID , ihead , wm , currentTest , ref resultStr , Q2CorrType . RL_incl_05 , currentActivity . Substring ( WriteQ2CorrectionRLIncl05Str . Length ) . Trim ( ) ) ;
else if ( currentActivity . ToLower ( ) . Contains ( WriteQ2CorrectionLRIncl05Str . ToLower ( ) ) ) error = CalculateAndWriteQ2Corrections ( threadID , ihead , wm , currentTest , ref resultStr , Q2CorrType . LR_incl_05 , currentActivity . Substring ( WriteQ2CorrectionLRIncl05Str . Length ) . Trim ( ) ) ;
else if ( currentActivity . ToLower ( ) . Contains ( UpdateBothQ2FactorsTestRLOnlyStr . ToLower ( ) ) ) error = CalculateAndWriteQ2Corrections ( threadID , ihead , wm , currentTest , ref resultStr , Q2CorrType . UpdateBothQ2FactorsTestRLDir , null ) ;
else if ( currentActivity . ToLower ( ) . Contains ( UpdateBothQ2FactorsTestLROnlyStr . ToLower ( ) ) ) error = CalculateAndWriteQ2Corrections ( threadID , ihead , wm , currentTest , ref resultStr , Q2CorrType . UpdateBothQ2FactorsTestLRDir , null ) ;
else if ( currentActivity . ToLower ( ) . Contains ( UpdateQ2CorrectionsStr . ToLower ( ) ) ) error = CalculateAndWriteQ2Corrections ( threadID , ihead , wm , currentTest , ref resultStr , Q2CorrType . Update , currentActivity . Substring ( UpdateQ2CorrectionsStr . Length ) . Trim ( ) ) ;
else if ( currentActivity . ToLower ( ) . Contains ( ConditnlUpdateQ2CorrectionsStr . ToLower ( ) ) ) error = CalculateAndWriteQ2Corrections ( threadID , ihead , wm , currentTest , ref resultStr , Q2CorrType . ConditionalUpdate , currentActivity . Substring ( ConditnlUpdateQ2CorrectionsStr . Length ) . Trim ( ) ) ;
2021-08-17 10:22:19 +00:00
else if ( currentActivity . ToLower ( ) . Contains ( ConditnlUpdateQ2CorrRLStr . ToLower ( ) ) ) error = CalculateAndWriteQ2Corrections ( threadID , ihead , wm , currentTest , ref resultStr , Q2CorrType . ConditionalUpdateRL , currentActivity . Substring ( ConditnlUpdateQ2CorrRLStr . Length ) . Trim ( ) ) ;
else if ( currentActivity . ToLower ( ) . Contains ( ConditnlUpdateQ2CorrLRStr . ToLower ( ) ) ) error = CalculateAndWriteQ2Corrections ( threadID , ihead , wm , currentTest , ref resultStr , Q2CorrType . ConditionalUpdateLR , currentActivity . Substring ( ConditnlUpdateQ2CorrLRStr . Length ) . Trim ( ) ) ;
2020-04-27 10:24:54 +00:00
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 ) ;
2020-11-06 13:45:13 +00:00
else if ( currentActivity . ToLower ( ) = = GetDefaultQ2CorrectionsStr . ToLower ( ) ) error = GetQ2PreCorrectionsFormRest ( threadID , ihead , wm , ref resultStr ) ;
2021-10-04 12:30:27 +00:00
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 ) ;
2020-04-27 10:24:54 +00:00
2019-03-28 08:33:17 +00:00
#endif
2017-11-03 09:57:30 +00:00
else
{
error = CommErr . None ;
resultStr = "Invalid activity" ;
}
2015-09-05 22:09:52 +00:00
2017-10-11 07:19:55 +00:00
///
/// Process the result of RFID communication activity
///
2017-11-03 09:57:30 +00:00
if ( error = = CommErr . HeadDisabledByUser | | ! ckbState [ wmNr0 ] )
2017-10-11 07:19:55 +00:00
{
2017-11-03 09:57:30 +00:00
OnCommCompleted ( null , new CommCompletedEventArgs ( threadID , wmNr0 , ihead , wm , Strings . Head_was_disabled_by_the_user , CommErr . HeadDisabledByUser ) ) ;
2017-10-11 07:19:55 +00:00
}
else if ( error = = CommErr . None )
2015-09-05 22:09:52 +00:00
{
2019-05-22 05:52:13 +00:00
OnCommCompleted ( null , new CommCompletedEventArgs ( threadID , wmNr0 , ihead , wm , resultStr , CommErr . None ) ) ;
2015-09-05 22:09:52 +00:00
}
2019-05-22 05:52:13 +00:00
else if ( ( error = = CommErr . OutOfRange ) | | ( error = = CommErr . Q2OutOfRange ) )
{
2021-12-15 15:57:52 +00:00
OnCommCompleted ( null , new CommCompletedEventArgs ( threadID , wmNr0 , ihead , wm , resultStr , CommErr . CommFailed ) ) ;
2019-05-22 05:52:13 +00:00
}
else if ( ihead . CommFailed | | ( error = = CommErr . CommFailed ) )
{
ihead . CommFailed = true ;
2020-11-06 13:45:13 +00:00
if ( wm ! = null & & ( wm . ResultCode & ( int ) Results . Entities . ResultCode . RfidErrorCodeMask ) = = 0 )
2019-05-22 05:52:13 +00:00
{
wm . ResultCode | = ( ( ( int ) error < < 16 ) | ( ( int ) tests [ i ] . ItemNr < < 20 ) ) ;
}
2017-10-11 06:47:36 +00:00
2017-11-03 09:57:30 +00:00
OnCommCompleted ( null , new CommCompletedEventArgs ( threadID , wmNr0 , ihead , wm , Strings . RFID_communication_failed , error ) ) ;
2019-05-22 05:52:13 +00:00
}
else
{
ihead . CommFailed = true ;
2020-11-06 13:45:13 +00:00
if ( wm ! = null & & ( wm . ResultCode & ( int ) Results . Entities . ResultCode . RfidErrorCodeMask ) = = 0 )
2019-05-22 05:52:13 +00:00
{
wm . ResultCode | = ( ( ( int ) error < < 16 ) | ( ( int ) tests [ i ] . ItemNr < < 20 ) ) ;
}
2017-08-21 13:43:23 +00:00
2019-03-28 08:33:17 +00:00
string failureCauseLocal = string . Format ( Strings . failed_0_1_exclamation , currentActivity , error ) ;
2019-05-22 05:52:13 +00:00
rfidDataLogger . ErrorFormat ( "Group={0}, Board={1}, {2}" , currentGroup , ihead . MuxBoardNrOrGroup14 , failureCauseLocal ) ;
2017-11-03 09:57:30 +00:00
OnCommCompleted ( null , new CommCompletedEventArgs ( threadID , wmNr0 , ihead , wm , failureCauseLocal , error ) ) ;
2019-05-22 05:52:13 +00:00
}
2015-09-04 11:49:04 +00:00
break ;
}
2017-11-03 09:57:30 +00:00
2021-07-28 09:40:45 +00:00
TBF . UiBridge . Bridge . OnTestProgress ( null , new TBF . UiBridge . TestProgressEventArgs ( tests [ i ] , Progress . FlowSetting ) ) ;
2015-09-04 11:49:04 +00:00
}
2016-01-08 18:18:45 +00:00
if ( ! wmFound )
{
2017-10-11 06:47:36 +00:00
OnCommCompleted ( null , new CommCompletedEventArgs ( threadID , - 1 , null , null , string . Empty , CommErr . None ) ) ; /// Send negative wmNr
2016-01-08 18:18:45 +00:00
}
2015-09-04 11:49:04 +00:00
if ( stopWorkerThreads ) break ;
}
if ( stopWorkerThreads ) break ;
} /// for (int group
2021-07-28 09:40:45 +00:00
TBF . UiBridge . Bridge . OnTestProgress ( null , new TBF . UiBridge . TestProgressEventArgs ( tests [ i ] , Progress . Completed ) ) ;
2015-09-04 11:49:04 +00:00
activityStep + + ;
if ( stopWorkerThreads ) break ;
}
2015-08-11 06:50:32 +00:00
}
2018-08-30 13:40:27 +00:00
#region Communication functions
2015-08-15 15:51:54 +00:00
2019-04-03 14:34:05 +00:00
#if IPERL
2015-08-14 09:38:53 +00:00
/// <summary>
/// Read a complete configuration structure of the watermeter
/// </summary>
2020-02-12 08:15:29 +00:00
/// <param name="ihead">iPERL head object</param>
/// <param name="wm">Water meter object</param>
/// <param name="resultStr">String passed to caller</param>
2015-08-15 15:51:54 +00:00
/// <returns>true on success</returns>
2021-09-24 07:31:05 +00:00
static CommErr ReadConfiguration ( IperlHead ihead , Results . Entities . WaterMeter wm , ref string resultStr )
2015-08-11 06:50:32 +00:00
{
2015-08-14 17:20:47 +00:00
///
/// The activity is "Read configuration" (this enables the watermeter, resets error flag)
2017-12-01 10:45:26 +00:00
/// or "Read configuration if enabled" (this keeps the error flag).
2015-08-14 17:20:47 +00:00
///
2015-09-04 11:49:04 +00:00
if ( ! multiTestParams [ currentActivityStep ] . Activity . ToLower ( ) . Contains ( " if enabled" ) )
2015-08-15 15:51:54 +00:00
{
2017-05-31 12:51:26 +00:00
ihead . CommFailed = false ;
2015-08-15 15:51:54 +00:00
}
2015-08-11 06:50:32 +00:00
2017-05-31 12:51:26 +00:00
if ( ihead . CommFailed ) return CommErr . CommFailed ;
2015-08-14 09:38:53 +00:00
2017-12-01 10:45:26 +00:00
ihead . ConfigStruct = null ; /// Clear previous ConfigStruct, avoid reuse of (not anymore valid) PCB Number
2021-09-24 07:31:05 +00:00
if ( OpenPort ( ihead ) ! = 0 ) return CommErr . OpenPort ; /// Open RFID port
2015-08-11 06:50:32 +00:00
2015-08-17 14:02:30 +00:00
CommErr error = CommErr . Read ;
2017-09-06 08:25:22 +00:00
int readRetVal = 0 ;
2015-08-11 06:50:32 +00:00
2015-08-15 15:51:54 +00:00
/// Read configuration
byte [ ] config = null ;
2015-09-06 21:36:14 +00:00
for ( int j = 0 ; j < cfg . MaxCommRetries ; j + + )
2015-08-11 06:50:32 +00:00
{
2021-09-24 07:31:05 +00:00
readRetVal = ReadRequestPort ( ihead , MessageID . Configuration , 0 , ConfigStruct . Length , out config , cfg . CommTimeout ) ;
2017-09-06 08:25:22 +00:00
if ( readRetVal = = 0 )
2015-08-15 15:51:54 +00:00
{
2015-08-17 14:02:30 +00:00
error = CommErr . None ;
2017-05-31 12:51:26 +00:00
ihead . ConfigStruct = ConfigStruct . FromByteArray ( config ) ;
2017-11-03 09:57:30 +00:00
resultStr = ihead . ConfigStruct . ToString ( 1 ) ;
2015-08-15 15:51:54 +00:00
break ;
}
2019-10-25 10:53:11 +00:00
/// Delay between retries
if ( cfg . DelayBetweenRetries > 0 ) Thread . Sleep ( cfg . DelayBetweenRetries ) ;
2015-08-11 06:50:32 +00:00
}
2015-08-15 15:51:54 +00:00
2021-09-24 07:31:05 +00:00
ClosePort ( ihead ) ; /// Close RFID port
2015-08-15 15:51:54 +00:00
2017-09-06 08:25:22 +00:00
return error + Math . Max ( 0 , Math . Min ( readRetVal , 4 ) ) ;
2015-08-11 06:50:32 +00:00
}
2015-08-15 15:51:54 +00:00
2015-08-14 09:38:53 +00:00
/// <summary>
2015-08-14 12:33:36 +00:00
/// Set the watermeter to the test mode.
/// If testModeConfig is specified as a hexadeximal number appended to "set test mode ", it is verified
/// whether the testModeConfig is correctly set, if necessary it is changed to the specified value.
/// Read a part of configuration afterwards to verify the mode was set correctly.
2015-08-14 09:38:53 +00:00
/// </summary>
2020-02-12 08:15:29 +00:00
/// <param name="threadId">Thread ID passed to RFID communication functions</param>
/// <param name="ihead">iPERL head object</param>
/// <param name="resultStr">String passed to caller</param>
2015-08-15 15:51:54 +00:00
/// <returns>true on success</returns>
2020-02-12 08:15:29 +00:00
static CommErr SetTestMode ( int threadId , IperlHead ihead , ref string resultStr )
2015-08-11 06:50:32 +00:00
{
2017-12-01 10:45:26 +00:00
if ( ihead . CommFailed | | ihead . ConfigStruct = = null ) return CommErr . CommFailed ;
2015-08-15 15:51:54 +00:00
Byte testModeConfig = 0xA0 ; /// Default value
///
2015-09-04 11:49:04 +00:00
if ( multiTestParams [ currentActivityStep ] . Activity . Length > SetTestModeStr . Length )
2015-08-11 06:50:32 +00:00
{
2015-09-04 11:49:04 +00:00
string testModeConfigStr = multiTestParams [ currentActivityStep ] . Activity . Substring ( SetTestModeStr . Length + 1 ) ;
2015-08-15 15:51:54 +00:00
UInt16 byteVal ;
if ( UInt16 . TryParse ( testModeConfigStr , NumberStyles . HexNumber , CultureInfo . CurrentCulture , out byteVal ) & & byteVal < = 255 )
2015-08-11 06:50:32 +00:00
{
2015-08-15 15:51:54 +00:00
testModeConfig = ( Byte ) byteVal ; /// Update with specified value
2015-08-14 12:33:36 +00:00
}
2015-08-15 15:51:54 +00:00
}
2015-08-14 12:33:36 +00:00
2017-05-31 12:51:26 +00:00
if ( ihead . ConfigStruct . MeterState = = MeterState . Test & & ihead . ConfigStruct . TestModeConfig = = testModeConfig )
2015-08-15 15:51:54 +00:00
{
/// Already in the correct test mode
2017-05-31 12:51:26 +00:00
resultStr = "Already " + ihead . ConfigStruct . ToString ( 1 ) ;
2015-08-17 14:02:30 +00:00
return CommErr . None ;
2015-08-15 15:51:54 +00:00
}
2015-08-14 12:33:36 +00:00
2015-08-15 15:51:54 +00:00
/// Communication necessary
2021-09-24 07:31:05 +00:00
if ( OpenPort ( ihead ) ! = 0 ) return CommErr . OpenPort ; /// Open RFID port
2015-08-14 09:38:53 +00:00
2015-08-17 14:02:30 +00:00
CommErr error = CommErr . None ;
2015-08-14 17:20:47 +00:00
2017-05-31 12:51:26 +00:00
if ( error = = CommErr . None & & ( ihead . ConfigStruct . TestModeConfig ! = testModeConfig ) & & ( ihead . ConfigStruct . MeterState ! = MeterState . Active ) )
2015-08-15 15:51:54 +00:00
{
/// Switch to Active mode in order to change TestModeConfig
2015-08-17 14:02:30 +00:00
error = CommErr . CmdActive ;
2019-02-15 14:34:19 +00:00
byte [ ] cmd = new byte [ 1 ] { ( byte ) Command . SetActiveMode } ;
2015-09-06 21:36:14 +00:00
for ( int j = 0 ; j < cfg . MaxCommRetries ; j + + )
2015-08-15 15:51:54 +00:00
{
2021-09-24 07:31:05 +00:00
if ( 0 = = WriteRequestPort ( ihead , MessageID . Command , 0 , 1 , cmd , cfg . CommTimeout ) )
2019-10-25 10:53:11 +00:00
{
error = CommErr . None ;
break ;
}
/// Delay between retries
if ( cfg . DelayBetweenRetries > 0 ) Thread . Sleep ( cfg . DelayBetweenRetries ) ;
2015-08-15 15:51:54 +00:00
}
2016-02-16 14:57:30 +00:00
2019-10-25 10:53:11 +00:00
/// Delay min. 250 ms
Thread . Sleep ( Math . Max ( 250 , cfg . DelayBetweenRetries ) ) ;
2015-08-15 15:51:54 +00:00
}
2015-08-14 17:20:47 +00:00
2017-05-31 12:51:26 +00:00
if ( error = = CommErr . None & & ( ihead . ConfigStruct . TestModeConfig ! = testModeConfig ) )
2015-08-15 15:51:54 +00:00
{
/// Change the TestModeConfig if necessary
2015-08-17 14:02:30 +00:00
error = CommErr . Write ;
2015-08-15 15:51:54 +00:00
byte [ ] tstMdCfg = new byte [ 1 ] { testModeConfig } ;
2015-09-06 21:36:14 +00:00
for ( int j = 0 ; j < cfg . MaxCommRetries ; j + + )
2015-08-15 15:51:54 +00:00
{
2021-09-24 07:31:05 +00:00
if ( 0 = = WriteRequestPort ( ihead , MessageID . Configuration , 21 , 1 , tstMdCfg , cfg . CommTimeout ) )
2015-08-14 17:20:47 +00:00
{
2017-05-31 12:51:26 +00:00
ihead . ConfigStruct . Update ( 21 , tstMdCfg ) ;
2015-08-17 14:02:30 +00:00
error = CommErr . None ;
2015-08-15 15:51:54 +00:00
break ;
2015-08-14 17:20:47 +00:00
}
2019-10-25 10:53:11 +00:00
/// Delay between retries
if ( cfg . DelayBetweenRetries > 0 ) Thread . Sleep ( cfg . DelayBetweenRetries ) ;
2015-08-14 17:20:47 +00:00
}
2016-02-16 14:57:30 +00:00
2019-10-25 10:53:11 +00:00
/// Delay min. 250 ms
Thread . Sleep ( Math . Max ( 250 , cfg . DelayBetweenRetries ) ) ;
2015-08-11 06:50:32 +00:00
}
2015-08-17 14:02:30 +00:00
if ( error = = CommErr . None )
2015-08-11 06:50:32 +00:00
{
2015-08-15 15:51:54 +00:00
/// Switch to test mode
2015-08-17 14:02:30 +00:00
error = CommErr . CmdTest ;
2019-02-15 14:34:19 +00:00
byte [ ] cmd = new byte [ 1 ] { ( byte ) Command . SetTestMode } ;
2015-09-06 21:36:14 +00:00
for ( int j = 0 ; j < cfg . MaxCommRetries ; j + + )
2015-08-15 15:51:54 +00:00
{
2021-09-24 07:31:05 +00:00
if ( 0 = = WriteRequestPort ( ihead , MessageID . Command , 0 , 1 , cmd , cfg . CommTimeout ) )
2019-10-25 10:53:11 +00:00
{
error = CommErr . None ;
break ;
}
/// Delay between retries
if ( cfg . DelayBetweenRetries > 0 ) Thread . Sleep ( cfg . DelayBetweenRetries ) ;
2015-08-15 15:51:54 +00:00
}
2016-02-16 14:57:30 +00:00
2019-10-25 10:53:11 +00:00
/// Delay min. 250 ms
Thread . Sleep ( Math . Max ( 250 , cfg . DelayBetweenRetries ) ) ;
2015-08-14 09:38:53 +00:00
}
2015-08-15 15:51:54 +00:00
/// Now the meter should be in the Test mode ... verify
2015-08-17 14:02:30 +00:00
if ( error = = CommErr . None )
2015-08-14 09:38:53 +00:00
{
2015-08-15 15:51:54 +00:00
/// Verify the configuration
2015-08-17 14:02:30 +00:00
error = CommErr . Verify ;
2019-02-21 15:00:01 +00:00
byte [ ] config = null ;
2015-09-06 21:36:14 +00:00
for ( int j = 0 ; j < cfg . MaxCommRetries ; j + + )
2015-08-15 15:51:54 +00:00
{
2021-09-24 07:31:05 +00:00
if ( 0 = = ReadRequestPort ( ihead , MessageID . Configuration , 0 , ConfigStruct . Length , out config , cfg . CommTimeout ) )
2015-08-15 15:51:54 +00:00
{
2019-02-21 15:00:01 +00:00
ihead . ConfigStruct = ConfigStruct . FromByteArray ( config ) ;
if ( ( ihead . ConfigStruct . MeterState = = MeterState . Test ) & & ( ihead . ConfigStruct . TestModeConfig = = testModeConfig ) )
2015-08-17 14:02:30 +00:00
{
error = CommErr . None ;
2017-05-31 12:51:26 +00:00
resultStr = ihead . ConfigStruct . ToString ( 1 ) ;
2015-08-17 14:02:30 +00:00
break ;
}
2015-08-15 15:51:54 +00:00
}
2019-10-25 10:53:11 +00:00
/// Delay between retries
if ( cfg . DelayBetweenRetries > 0 ) Thread . Sleep ( cfg . DelayBetweenRetries ) ;
2015-08-15 15:51:54 +00:00
}
2015-08-14 09:38:53 +00:00
}
2015-08-15 15:51:54 +00:00
2021-09-24 07:31:05 +00:00
ClosePort ( ihead ) ; /// Close RFID port
2015-08-15 15:51:54 +00:00
2015-08-17 14:02:30 +00:00
return error ;
2015-08-14 09:38:53 +00:00
}
2015-08-11 06:50:32 +00:00
2015-08-15 15:51:54 +00:00
2015-08-14 09:38:53 +00:00
/// <summary>
2015-08-14 12:33:36 +00:00
/// Set the watermeter to the active mode.
2015-08-14 09:38:53 +00:00
/// Read a part of configuration afterwards to verify the mode was set correctly.
/// </summary>
2020-02-12 08:15:29 +00:00
/// <param name="ihead">iPERL head object</param>
2015-08-15 15:51:54 +00:00
/// <param name="resultStr">String passed to caller</param>
/// <returns>true on success</returns>
2020-02-12 08:15:29 +00:00
static CommErr SetActiveMode ( int threadId , IperlHead ihead , ref string resultStr )
2015-08-14 09:38:53 +00:00
{
2021-09-24 07:31:05 +00:00
if ( OpenPort ( ihead ) ! = 0 ) return CommErr . OpenPort ; /// Open RFID port
2015-08-15 15:51:54 +00:00
2015-08-17 14:02:30 +00:00
CommErr error = CommErr . CmdActive ;
2015-08-14 09:38:53 +00:00
2015-08-15 15:51:54 +00:00
/// Switch to active mode
2019-02-15 14:34:19 +00:00
byte [ ] cmd = new byte [ 1 ] { ( byte ) Command . SetActiveMode } ;
2015-09-06 21:36:14 +00:00
for ( int j = 0 ; j < cfg . MaxCommRetries ; j + + )
2015-08-14 09:38:53 +00:00
{
2021-09-24 07:31:05 +00:00
if ( 0 = = WriteRequestPort ( ihead , MessageID . Command , 0 , 1 , cmd , cfg . CommTimeout ) )
2016-02-16 14:57:30 +00:00
{
error = CommErr . None ;
break ;
}
2019-10-25 10:53:11 +00:00
/// Delay between retries
if ( cfg . DelayBetweenRetries > 0 ) Thread . Sleep ( cfg . DelayBetweenRetries ) ;
2015-08-15 15:51:54 +00:00
}
2015-08-14 09:38:53 +00:00
2016-10-27 12:27:37 +00:00
#if VERIFY_ACTIVE_MODE
2015-08-17 14:02:30 +00:00
if ( error = = CommErr . None )
2015-08-15 15:51:54 +00:00
{
2015-08-17 14:02:30 +00:00
error = CommErr . Verify ;
2015-08-11 06:50:32 +00:00
2015-08-15 15:51:54 +00:00
/// Read configuration
byte [ ] cfg_0_3 = null ;
2015-09-06 21:36:14 +00:00
for ( int j = 0 ; j < cfg . MaxCommRetries ; j + + )
2015-08-14 09:38:53 +00:00
{
2017-07-14 14:31:35 +00:00
if ( ihead . ConfigStruct = = null )
2015-08-14 09:38:53 +00:00
{
2017-08-04 15:45:40 +00:00
if ( 0 = = ReadRequestPort ( threadId , ihead , MessageID . Configuration , 0 , 4 , out cfg_0_3 , cfg . CommTimeout ) )
2015-08-17 14:02:30 +00:00
{
2017-07-14 14:31:35 +00:00
ihead . ConfigStruct . Update ( 0 , cfg_0_3 ) ;
if ( ihead . ConfigStruct . MeterState = = MeterState . Active )
2016-03-01 15:22:49 +00:00
{
error = CommErr . None ;
2017-07-14 14:31:35 +00:00
resultStr = ihead . ConfigStruct . ToString ( 1 ) ;
2016-03-01 15:22:49 +00:00
break ;
}
2015-08-17 14:02:30 +00:00
}
2015-08-14 09:38:53 +00:00
}
2019-10-25 10:53:11 +00:00
/// Delay between retries
if ( cfg . DelayBetweenRetries > 0 ) Thread . Sleep ( cfg . DelayBetweenRetries ) ;
2015-08-14 09:38:53 +00:00
}
}
2016-02-16 14:57:30 +00:00
#else
if ( error = = CommErr . None )
{
2017-05-31 12:51:26 +00:00
if ( ihead . ConfigStruct = = null )
2016-03-01 15:22:49 +00:00
resultStr = "OK (Config not available)" ;
else
2017-05-31 12:51:26 +00:00
resultStr = ihead . ConfigStruct . ToString ( 1 ) ;
2016-02-16 14:57:30 +00:00
}
#endif
2015-08-11 06:50:32 +00:00
2021-09-24 07:31:05 +00:00
ClosePort ( ihead ) ; /// Close RFID port
2015-08-15 15:51:54 +00:00
2015-08-17 14:02:30 +00:00
return error ;
2015-08-11 06:50:32 +00:00
}
2015-08-15 15:51:54 +00:00
2015-08-14 12:33:36 +00:00
/// <summary>
/// Read a complete calibration structure from the watermeter
/// </summary>
2017-05-31 12:51:26 +00:00
/// <param name="ihead">Water meter object</param>
2015-08-15 15:51:54 +00:00
/// <param name="resultStr">String passed to caller</param>
/// <returns>true on success</returns>
2021-09-24 07:31:05 +00:00
static CommErr ReadCalibration ( IperlHead ihead , Results . Entities . WaterMeter wm , ref string resultStr )
2015-08-14 12:33:36 +00:00
{
2017-05-31 12:51:26 +00:00
if ( ihead . CommFailed ) return CommErr . CommFailed ;
2015-08-14 12:33:36 +00:00
2021-09-24 07:31:05 +00:00
if ( OpenPort ( ihead ) ! = 0 ) return CommErr . OpenPort ; /// Open RFID port
2015-08-14 12:33:36 +00:00
2015-08-17 14:02:30 +00:00
CommErr error = CommErr . Read ;
2017-09-06 08:25:22 +00:00
int readRetVal = 0 ;
2015-08-14 12:33:36 +00:00
2015-08-15 15:51:54 +00:00
/// Read calibration
byte [ ] calib = null ;
2015-09-06 21:36:14 +00:00
for ( int j = 0 ; j < cfg . MaxCommRetries ; j + + )
2015-08-14 12:33:36 +00:00
{
2021-09-24 07:31:05 +00:00
readRetVal = ReadRequestPort ( ihead , MessageID . Calibration , 0 , CalibrationStruct . Length , out calib , cfg . CommTimeout ) ;
2017-09-06 08:25:22 +00:00
if ( readRetVal = = 0 )
2015-08-15 15:51:54 +00:00
{
2017-05-31 12:51:26 +00:00
ihead . CalibrationStruct = CalibrationStruct . FromByteArray ( calib ) ;
2019-04-03 14:34:05 +00:00
if ( wm . OrigCalibFactor = = 0 )
2017-06-15 11:08:31 +00:00
{
2017-07-18 06:33:20 +00:00
wm . OrigCalibFactor = ihead . CalibrationStruct . Calibration ;
2017-06-15 11:08:31 +00:00
wm . FWVersion = ihead . CalibrationStruct . FWVersionStr ( ) ;
}
2019-04-03 14:34:05 +00:00
2017-06-15 11:08:31 +00:00
resultStr = ihead . CalibrationStruct . ToString ( ) ;
2017-05-31 12:51:26 +00:00
error = ihead . VerifyIPerlType ( ) ? CommErr . None : CommErr . WrongIPerlType ;
2015-08-15 15:51:54 +00:00
break ;
}
2019-10-25 10:53:11 +00:00
/// Delay between retries
if ( cfg . DelayBetweenRetries > 0 ) Thread . Sleep ( cfg . DelayBetweenRetries ) ;
2015-08-14 12:33:36 +00:00
}
2015-08-15 15:51:54 +00:00
2021-09-24 07:31:05 +00:00
ClosePort ( ihead ) ; /// Close RFID port
2015-08-15 15:51:54 +00:00
2017-09-06 08:25:22 +00:00
return error + Math . Max ( 0 , Math . Min ( readRetVal , 4 ) ) ;
2015-08-14 12:33:36 +00:00
}
2015-08-15 15:51:54 +00:00
2018-09-20 07:05:32 +00:00
/// <summary>
/// Read a complete calibration structure from the watermeter
/// </summary>
/// <param name="ihead">Water meter object</param>
/// <param name="resultStr">String passed to caller</param>
/// <returns>true on success</returns>
2021-09-24 07:31:05 +00:00
static CommErr ReadCalibrationV4 ( IperlHead ihead , Results . Entities . WaterMeter wm , ref string resultStr )
2018-09-20 07:05:32 +00:00
{
if ( ihead . CommFailed ) return CommErr . CommFailed ;
2021-09-24 07:31:05 +00:00
if ( OpenPort ( ihead ) ! = 0 ) return CommErr . OpenPort ; /// Open RFID port
2018-09-20 07:05:32 +00:00
CommErr error = CommErr . Read ;
int readRetVal = 0 ;
/// Read calibration
byte [ ] calib = null ;
for ( int j = 0 ; j < cfg . MaxCommRetries ; j + + )
{
2021-09-24 07:31:05 +00:00
readRetVal = ReadRequestPort ( ihead , MessageID . Calibration , 0 , CalibrationStructV4 . Length , out calib , cfg . CommTimeout ) ;
2018-09-20 07:05:32 +00:00
if ( readRetVal = = 0 )
{
ihead . CalibrationStructV4 = CalibrationStructV4 . FromByteArray ( calib ) ;
2019-04-03 14:34:05 +00:00
if ( ( wm . OrigCalibFactor = = 0 ) & & ( wm . OrigCalibFactorLNA = = 0 ) )
2018-09-20 07:05:32 +00:00
{
wm . OrigCalibFactor = ihead . CalibrationStructV4 . Calibration ;
wm . OrigCalibFactorLNA = ihead . CalibrationStructV4 . CalibrationLNA ;
wm . FWVersion = ihead . CalibrationStructV4 . FWVersionStr ( ) ;
}
2019-04-03 14:34:05 +00:00
2018-09-20 07:05:32 +00:00
resultStr = ihead . CalibrationStructV4 . ToString ( ) ;
error = ihead . VerifyIPerlType ( ) ? CommErr . None : CommErr . WrongIPerlType ;
break ;
}
2019-10-25 10:53:11 +00:00
/// Delay between retries
if ( cfg . DelayBetweenRetries > 0 ) Thread . Sleep ( cfg . DelayBetweenRetries ) ;
2018-09-20 07:05:32 +00:00
}
2021-09-24 07:31:05 +00:00
ClosePort ( ihead ) ; /// Close RFID port
2018-09-20 07:05:32 +00:00
return error + Math . Max ( 0 , Math . Min ( readRetVal , 4 ) ) ;
}
2015-08-14 12:33:36 +00:00
/// <summary>
/// Write the calculated calibration factor to the water meter.
/// Read a part of CalibrationStruct afterwards to verify factor was written correctly.
/// </summary>
2018-09-20 07:05:32 +00:00
/// <param name="threadId">Thread ID</param>
/// <param name="ihead">IperlHead object</param>
/// <param name="wm">Water meter object</param>
/// <param name="resultStr">String passed to caller</param>
/// <returns>true on success</returns>
2017-08-04 15:45:40 +00:00
static CommErr WriteCalibrationFactor ( int threadId , IperlHead ihead , Results . Entities . WaterMeter wm , ref string resultStr )
2015-08-11 06:50:32 +00:00
{
2018-09-20 07:05:32 +00:00
if ( ihead . CommFailed | | ( ihead . CalibrationStruct = = null ) ) return CommErr . CommFailed ;
2015-08-15 15:51:54 +00:00
2016-11-10 13:07:11 +00:00
///
2015-10-16 09:24:03 +00:00
/// Parse calibration factor (1 argument) or calibration factor limits (2 arguments)
2016-11-10 13:07:11 +00:00
///
2015-10-16 09:24:03 +00:00
UInt16 newCalibFactor = 0 ;
2015-09-04 11:49:04 +00:00
if ( multiTestParams [ currentActivityStep ] . Activity . Length > WriteCalibrationFactorStr . Length )
2015-10-16 09:24:03 +00:00
{
UInt16 factorLimitLo ;
UInt16 factorLimitHi ;
UInt16 val ;
2015-09-04 11:49:04 +00:00
string calibFactrorStr = multiTestParams [ currentActivityStep ] . Activity . Substring ( WriteCalibrationFactorStr . Length + 1 ) ;
2015-10-16 09:24:03 +00:00
string [ ] arguments = calibFactrorStr . Split ( new char [ ] { ' ' } ) ;
if ( arguments . Length > = 2 & &
UInt16 . TryParse ( arguments [ 0 ] , out factorLimitLo ) & & factorLimitLo > 0 & &
UInt16 . TryParse ( arguments [ 1 ] , out factorLimitHi ) & & factorLimitHi > 0 )
{
2019-05-22 05:52:13 +00:00
///
/// Lower and upper limits for the calibration factor are specified as iPerlCommunication activity arguments
///
2017-07-14 14:31:35 +00:00
if ( ihead . LastTestResult = = null | | ! ihead . LastTestResult . TestDone ) return CommErr . MissingTest ;
2017-07-18 06:33:20 +00:00
newCalibFactor = ihead . CalculateNewCalibFactor ( ihead . LastTestResult , ihead . CalibFactor , factorLimitLo , factorLimitHi ) ;
2015-10-16 09:24:03 +00:00
}
else if ( arguments . Length = = 1 & & UInt16 . TryParse ( arguments [ 0 ] , out val ) & & val > 0 )
{
2019-05-22 05:52:13 +00:00
///
/// Calibration factor value is specified as an iPerlCommunication activity argument
///
newCalibFactor = val ; /// Update with specified value
2015-10-16 09:24:03 +00:00
}
2017-07-14 14:31:35 +00:00
else if ( arguments . Length = = 1 & & wm . GetTestData ( arguments [ 0 ] ) ! = null )
{
2019-05-22 05:52:13 +00:00
///
/// Adjustment test name is specified as an iPerlCommunication activity argument
///
2017-07-14 14:31:35 +00:00
Results . Entities . TestData adjustTestData = wm . GetTestData ( arguments [ 0 ] ) ;
Results . Entities . MeterTestRslt adjustTestRslt ;
if ( adjustTestData = = null )
{
return CommErr . MissingTest ;
}
else if ( adjustTestData . Repeats = = 1 )
{
/// Find a test result if Repeats == 1
adjustTestRslt = wm . GetMeterTestRslt ( arguments [ 0 ] ) ;
if ( adjustTestRslt = = null | | ! adjustTestRslt . TestDone ) return CommErr . MissingTest ;
}
else
{
/// Calculate a summarized test result if Repeats > 1
adjustTestRslt = new Results . Entities . MeterTestRslt ( ) ;
for ( int i = 1 ; i < = adjustTestData . Repeats ; i + + )
{
Results . Entities . MeterTestRslt oneMTR = wm . GetMeterTestRslt ( Utils . TestTitle ( adjustTestData , i ) ) ;
if ( oneMTR = = null | | ! oneMTR . TestDone ) return CommErr . MissingTest ;
adjustTestRslt . VolumeMeter + = oneMTR . VolumeMeter ;
adjustTestRslt . VolumeRef + = oneMTR . VolumeRef ;
}
}
2017-07-18 06:33:20 +00:00
newCalibFactor = ihead . CalculateNewCalibFactor ( adjustTestRslt , ihead . CalibFactor , ihead . FactorLimitLo , ihead . FactorLimitHi ) ;
2017-07-14 14:31:35 +00:00
}
else
2015-10-16 09:24:03 +00:00
{
2019-05-22 05:52:13 +00:00
///
/// Otherwise the last test is supposed to be an adjustment test
///
2017-07-14 14:31:35 +00:00
if ( ihead . LastTestResult = = null | | ! ihead . LastTestResult . TestDone ) return CommErr . MissingTest ;
2017-07-18 06:33:20 +00:00
newCalibFactor = ihead . CalculateNewCalibFactor ( ihead . LastTestResult , ihead . CalibFactor , ihead . FactorLimitLo , ihead . FactorLimitHi ) ;
2015-10-16 09:24:03 +00:00
}
}
else
{
2019-05-22 05:52:13 +00:00
///
/// No iPerlCommunication activity arguments --> The last test is supposed to be an adjustment test
///
2017-07-14 14:31:35 +00:00
if ( ihead . LastTestResult = = null | | ! ihead . LastTestResult . TestDone ) return CommErr . MissingTest ;
2017-07-18 06:33:20 +00:00
newCalibFactor = ihead . CalculateNewCalibFactor ( ihead . LastTestResult , ihead . CalibFactor , ihead . FactorLimitLo , ihead . FactorLimitHi ) ;
2015-10-16 09:24:03 +00:00
}
2019-03-28 08:33:17 +00:00
if ( newCalibFactor = = 0 ) return CommErr . OutOfRange ;
2017-06-07 14:22:18 +00:00
2016-11-10 13:07:11 +00:00
///
/// Start communication with iPerl
///
2021-09-24 07:31:05 +00:00
if ( OpenPort ( ihead ) ! = 0 ) return CommErr . OpenPort ; /// Open RFID port
2017-06-07 14:22:18 +00:00
2016-11-10 13:07:11 +00:00
CommErr error ;
2015-08-19 19:12:10 +00:00
byte [ ] data = new byte [ 2 ] { ( byte ) ( newCalibFactor & 0x00FF ) , ( byte ) ( ( newCalibFactor > > 8 ) & 0x00FF ) } ;
2016-11-10 13:07:11 +00:00
int writeAndVerifyRetries = 0 ;
do
2015-08-15 15:51:54 +00:00
{
2016-11-10 13:07:11 +00:00
///
/// Write the new calibration factor (up to cfg.MaxCommRetries tims)
///
error = CommErr . Write ;
2021-09-24 07:31:05 +00:00
if ( 0 = = WriteRequestPort ( ihead , MessageID . Calibration , 2 , 2 , data , cfg . CommTimeout ) )
2015-08-24 13:16:14 +00:00
{
2016-11-10 13:07:11 +00:00
///
/// Read and verify the calibration factor
///
error = CommErr . ReadAfterWrite ;
byte [ ] calib_2_3 = null ;
2021-09-24 07:31:05 +00:00
if ( 0 = = ReadRequestPort ( ihead , MessageID . Calibration , 2 , 2 , out calib_2_3 , cfg . CommTimeout ) )
2015-08-15 15:51:54 +00:00
{
2016-11-10 13:07:11 +00:00
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 ] )
{
error = CommErr . None ;
2017-05-31 12:51:26 +00:00
ihead . CalibrationStruct . Update ( data , 2 ) ;
2019-04-03 14:34:05 +00:00
wm . CalibFactor = newCalibFactor ;
2017-05-31 12:51:26 +00:00
resultStr = ihead . CalibrationStruct . ToString ( ) ;
2016-11-10 13:07:11 +00:00
break ;
}
2015-08-15 15:51:54 +00:00
}
2015-08-14 09:38:53 +00:00
}
2016-11-10 13:07:11 +00:00
2017-05-31 12:51:26 +00:00
ihead . CalibrationStruct . Update ( data , 2 ) ;
2015-08-15 15:51:54 +00:00
}
2016-11-10 13:07:11 +00:00
while ( + + writeAndVerifyRetries < = cfg . MaxCommRetries ) ;
2015-08-11 06:50:32 +00:00
2021-09-24 07:31:05 +00:00
ClosePort ( ihead ) ; /// Close RFID port
2015-08-14 09:38:53 +00:00
2015-08-17 14:02:30 +00:00
return error ;
2015-08-15 15:51:54 +00:00
}
2015-08-11 06:50:32 +00:00
2016-11-02 12:16:07 +00:00
2018-09-20 07:05:32 +00:00
/// <summary>
/// Write the calculated calibration factor to the water meter.
/// Read a part of CalibrationStruct afterwards to verify factor was written correctly.
/// </summary>
/// <param name="threadId">Thread ID</param>
/// <param name="ihead">IperlHead object</param>
/// <param name="wm">Water meter object</param>
/// <param name="resultStr">String passed to caller</param>
/// <returns>true on success</returns>
static CommErr WriteCalibrationV4Factors ( int threadId , IperlHead ihead , Results . Entities . WaterMeter wm , ref string resultStr )
{
if ( ihead . CommFailed | | ( ihead . CalibrationStructV4 = = null ) ) return CommErr . CommFailed ;
///
/// Parse calibration factor (1 argument) or calibration factor limits (2 arguments)
///
UInt16 newCalibFactor = 0 ;
UInt16 newCalibFactorLNA = 0 ;
if ( multiTestParams [ currentActivityStep ] . Activity . Length > WriteCalibrationV4FactorsStr . Length )
{
UInt16 factorLimitLo = 0 ;
UInt16 factorLimitHi = 0 ;
UInt16 lnaFactorLimitLo = 0 ;
UInt16 lnaFactorLimitHi = 0 ;
Results . Entities . TestData adjustTestData = null ;
Results . Entities . TestData lnaAdjustTestData = null ;
Results . Entities . MeterTestRslt adjustTestRslt = null ;
Results . Entities . MeterTestRslt lnaAdjustTestRslt = null ;
string calibFactrorStr = multiTestParams [ currentActivityStep ] . Activity . Substring ( WriteCalibrationV4FactorsStr . Length + 1 ) ;
string [ ] arguments = calibFactrorStr . Split ( new char [ ] { ' ' } ) ;
if ( arguments . Length = = 6 )
{
if ( ! wm . TryGetTestData ( arguments [ 0 ] , out adjustTestData ) | |
! UInt16 . TryParse ( arguments [ 1 ] , out factorLimitLo ) | | factorLimitLo < = 0 & &
! UInt16 . TryParse ( arguments [ 2 ] , out factorLimitHi ) | | factorLimitHi < = 0 & &
! wm . TryGetTestData ( arguments [ 3 ] , out lnaAdjustTestData ) | |
! UInt16 . TryParse ( arguments [ 4 ] , out lnaFactorLimitLo ) | | lnaFactorLimitLo < = 0 & &
! UInt16 . TryParse ( arguments [ 5 ] , out lnaFactorLimitHi ) | | lnaFactorLimitHi < = 0 )
{
return CommErr . WrongArguments ;
}
else
{
adjustTestRslt = GetAverageTestRslt ( wm , adjustTestData ) ;
lnaAdjustTestRslt = GetAverageTestRslt ( wm , lnaAdjustTestData ) ;
if ( ( adjustTestRslt = = null ) | | ( lnaAdjustTestRslt = = null ) )
{
return CommErr . MissingTest ;
}
newCalibFactor = ihead . CalculateNewCalibFactor ( adjustTestRslt , ihead . CalibFactor , factorLimitLo , factorLimitHi ) ;
newCalibFactorLNA = ihead . CalculateNewCalibFactor ( lnaAdjustTestRslt , ihead . CalibFactorLNA , lnaFactorLimitLo , lnaFactorLimitHi ) ;
}
}
else if ( arguments . Length = = 4 )
{
if ( ! wm . TryGetTestData ( arguments [ 0 ] , out adjustTestData ) | |
! wm . TryGetTestData ( arguments [ 1 ] , out lnaAdjustTestData ) | |
! UInt16 . TryParse ( arguments [ 2 ] , out lnaFactorLimitLo ) | | lnaFactorLimitLo < = 0 & &
! UInt16 . TryParse ( arguments [ 3 ] , out lnaFactorLimitHi ) | | lnaFactorLimitHi < = 0 )
{
return CommErr . WrongArguments ;
}
else
{
factorLimitLo = ihead . FactorLimitLo ;
factorLimitHi = ihead . FactorLimitHi ;
adjustTestRslt = GetAverageTestRslt ( wm , adjustTestData ) ;
lnaAdjustTestRslt = GetAverageTestRslt ( wm , lnaAdjustTestData ) ;
if ( ( adjustTestRslt = = null ) | | ( lnaAdjustTestRslt = = null ) )
{
return CommErr . MissingTest ;
}
newCalibFactor = ihead . CalculateNewCalibFactor ( adjustTestRslt , ihead . CalibFactor , factorLimitLo , factorLimitHi ) ;
newCalibFactorLNA = ihead . CalculateNewCalibFactor ( lnaAdjustTestRslt , ihead . CalibFactorLNA , lnaFactorLimitLo , lnaFactorLimitHi ) ;
}
}
else if ( arguments . Length = = 2 )
{
if ( ! wm . TryGetTestData ( arguments [ 0 ] , out adjustTestData ) | |
! wm . TryGetTestData ( arguments [ 1 ] , out lnaAdjustTestData ) )
{
return CommErr . WrongArguments ;
}
else
{
factorLimitLo = ihead . FactorLimitLo ;
factorLimitHi = ihead . FactorLimitHi ;
lnaFactorLimitLo = ihead . FactorLimitLo ;
lnaFactorLimitHi = ihead . FactorLimitHi ;
adjustTestRslt = GetAverageTestRslt ( wm , adjustTestData ) ;
lnaAdjustTestRslt = GetAverageTestRslt ( wm , lnaAdjustTestData ) ;
if ( ( adjustTestRslt = = null ) | | ( lnaAdjustTestRslt = = null ) )
{
return CommErr . MissingTest ;
}
newCalibFactor = ihead . CalculateNewCalibFactor ( adjustTestRslt , ihead . CalibFactor , factorLimitLo , factorLimitHi ) ;
newCalibFactorLNA = ihead . CalculateNewCalibFactor ( lnaAdjustTestRslt , ihead . CalibFactorLNA , lnaFactorLimitLo , lnaFactorLimitHi ) ;
}
}
else
{
return CommErr . WrongArguments ;
}
}
else
{
return CommErr . WrongArguments ;
}
2019-03-28 08:33:17 +00:00
if ( newCalibFactor = = 0 | | newCalibFactorLNA = = 0 ) return CommErr . OutOfRange ;
2018-09-20 07:05:32 +00:00
///
/// Start communication with iPerl
///
2021-09-24 07:31:05 +00:00
if ( OpenPort ( ihead ) ! = 0 ) return CommErr . OpenPort ; /// Open RFID port
2018-09-20 07:05:32 +00:00
CommErr error ;
byte [ ] data = new byte [ 2 ] { ( byte ) ( newCalibFactor & 0x00FF ) , ( byte ) ( ( newCalibFactor > > 8 ) & 0x00FF ) } ;
byte [ ] dataLNA = new byte [ 2 ] { ( byte ) ( newCalibFactorLNA & 0x00FF ) , ( byte ) ( ( newCalibFactorLNA > > 8 ) & 0x00FF ) } ;
int writeAndVerifyRetries = 0 ;
do
{
///
/// Write the new calibration factor (up to cfg.MaxCommRetries tims)
///
error = CommErr . Write ;
2021-09-24 07:31:05 +00:00
if ( 0 = = WriteRequestPort ( ihead , MessageID . Calibration , 2 , 2 , data , cfg . CommTimeout ) & &
0 = = WriteRequestPort ( ihead , MessageID . Calibration , 34 , 2 , dataLNA , cfg . CommTimeout ) )
2018-09-20 07:05:32 +00:00
{
///
/// Read and verify the calibration factor
///
error = CommErr . ReadAfterWrite ;
byte [ ] calib_2_3 = null ;
byte [ ] calib_34_35 = null ;
2021-09-24 07:31:05 +00:00
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 ) )
2018-09-20 07:05:32 +00:00
{
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 ] & &
calib_34_35 ! = null & & calib_34_35 . Length = = 2 & & dataLNA [ 0 ] = = calib_34_35 [ 0 ] & & dataLNA [ 1 ] = = calib_34_35 [ 1 ] )
{
error = CommErr . None ;
ihead . CalibrationStructV4 . Update ( data , 2 ) ;
ihead . CalibrationStructV4 . Update ( dataLNA , 34 ) ;
2019-04-03 14:34:05 +00:00
wm . CalibFactor = newCalibFactor ;
wm . CalibFactorLNA = newCalibFactorLNA ;
2018-09-20 07:05:32 +00:00
resultStr = ihead . CalibrationStructV4 . ToString ( ) ;
break ;
}
}
}
ihead . CalibrationStructV4 . Update ( data , 2 ) ;
ihead . CalibrationStructV4 . Update ( dataLNA , 34 ) ;
2019-10-25 10:53:11 +00:00
writeAndVerifyRetries + + ;
if ( ( writeAndVerifyRetries < = cfg . MaxCommRetries ) & & ( cfg . DelayBetweenRetries > 0 ) )
{
/// Delay between retries
Thread . Sleep ( cfg . DelayBetweenRetries ) ;
}
2018-09-20 07:05:32 +00:00
}
2019-10-25 10:53:11 +00:00
while ( writeAndVerifyRetries < = cfg . MaxCommRetries ) ;
2018-09-20 07:05:32 +00:00
2021-09-24 07:31:05 +00:00
ClosePort ( ihead ) ; /// Close RFID port
2018-09-20 07:05:32 +00:00
return error ;
}
/// <summary>
/// Get averaged meter test result using test name and repetitions from a given test data.
/// </summary>
/// <param name="wm">Water meter</param>
/// <param name="testData">TestData (name and repetitions)</param>
/// <returns>(1) selected MeterTestRslt or (2) average of repeated MTR-s or (3) null when at least one MTR is missing</returns>
static Results . Entities . MeterTestRslt GetAverageTestRslt ( Results . Entities . WaterMeter wm , Results . Entities . TestData testData )
{
Results . Entities . MeterTestRslt avgTestRslt ;
if ( testData . Repeats > 1 )
{
/// Calculate a summarized test result if Repeats > 1
avgTestRslt = new Results . Entities . MeterTestRslt ( ) ;
for ( int i = 1 ; i < = testData . Repeats ; i + + )
{
Results . Entities . MeterTestRslt oneMTR = wm . GetMeterTestRslt ( Utils . TestTitle ( testData , i ) ) ;
if ( oneMTR = = null | | ! oneMTR . TestDone ) return null ;
avgTestRslt . VolumeMeter + = oneMTR . VolumeMeter ;
avgTestRslt . VolumeRef + = oneMTR . VolumeRef ;
}
}
else
{
avgTestRslt = wm . GetMeterTestRslt ( Utils . TestTitle ( testData , 1 ) ) ;
if ( avgTestRslt = = null | | ! avgTestRslt . TestDone ) return null ;
}
return avgTestRslt ;
}
2016-11-02 12:16:07 +00:00
/// <summary>
/// Normalize calibration factor in case ti is close to value 8000.
/// </summary>
2017-05-31 12:51:26 +00:00
/// <param name="ihead">Water meter object</param>
2016-11-02 12:16:07 +00:00
/// <param name="resultStr">String passed to caller</param>
/// <returns>true on success</returns>
2017-08-04 15:45:40 +00:00
static CommErr NormalizeCalibrationFactor ( int threadId , IperlHead ihead , Results . Entities . WaterMeter wm , ref string resultStr )
2016-11-02 12:16:07 +00:00
{
2018-09-20 07:05:32 +00:00
if ( ihead . CommFailed | | ( ihead . CalibrationStruct = = null ) ) return CommErr . CommFailed ;
2016-11-02 12:16:07 +00:00
2018-04-12 13:27:29 +00:00
if ( ihead . FactorLimitLo < = ihead . CalibFactor & & ihead . CalibFactor < = ihead . FactorLimitHi )
2016-11-02 12:16:07 +00:00
{
resultStr = "Calibratin factor is OK" ;
return CommErr . None ; /// No need to update the calibration factor
}
2021-09-24 07:31:05 +00:00
if ( OpenPort ( ihead ) ! = 0 ) return CommErr . OpenPort ; /// Open RFID port
2016-11-02 12:16:07 +00:00
CommErr error = CommErr . Write ;
/// Determine the new calibration factor
2018-09-20 07:05:32 +00:00
UInt16 defaultCalibFactor ;
2017-05-31 12:51:26 +00:00
switch ( ihead . CalibrationStruct . MeterType )
2016-11-02 12:16:07 +00:00
{
2021-07-28 12:47:05 +00:00
case MeterType . DN15 :
defaultCalibFactor = 2710 ;
break ;
case MeterType . DN20 :
defaultCalibFactor = 3746 ;
break ;
case MeterType . DN25 :
defaultCalibFactor = 3300 ;
break ;
case MeterType . DN32 :
defaultCalibFactor = 2500 ;
break ;
case MeterType . DN40 :
defaultCalibFactor = 3080 ;
break ;
case MeterType . DN25_Q3_10 :
2016-11-02 12:16:07 +00:00
case MeterType . CoaxManifold :
default :
2018-09-20 07:05:32 +00:00
defaultCalibFactor = 3040 ;
2016-11-02 12:16:07 +00:00
break ;
}
2018-09-20 07:05:32 +00:00
byte [ ] data = new byte [ 2 ] { ( byte ) ( defaultCalibFactor & 0x00FF ) , ( byte ) ( ( defaultCalibFactor > > 8 ) & 0x00FF ) } ;
2016-11-02 12:16:07 +00:00
for ( int j = 0 ; j < cfg . MaxCommRetries ; j + + )
{
2021-09-24 07:31:05 +00:00
if ( 0 = = WriteRequestPort ( ihead , MessageID . Calibration , 2 , 2 , data , cfg . CommTimeout ) )
2016-11-02 12:16:07 +00:00
{
error = CommErr . None ;
2017-05-31 12:51:26 +00:00
ihead . CalibrationStruct . Update ( data , 2 ) ;
2016-11-02 12:16:07 +00:00
break ;
}
2019-10-25 10:53:11 +00:00
/// Delay between retries
if ( cfg . DelayBetweenRetries > 0 ) Thread . Sleep ( cfg . DelayBetweenRetries ) ;
2016-11-02 12:16:07 +00:00
}
if ( error = = CommErr . None )
{
error = CommErr . Verify ;
/// Read calibration
byte [ ] calib_2_3 = null ;
for ( int j = 0 ; j < cfg . MaxCommRetries ; j + + )
{
2021-09-24 07:31:05 +00:00
if ( 0 = = ReadRequestPort ( ihead , MessageID . Calibration , 2 , 2 , out calib_2_3 , cfg . CommTimeout ) )
2016-11-02 12:16:07 +00:00
{
error = CommErr . None ;
2017-05-31 12:51:26 +00:00
ihead . CalibrationStruct . Update ( calib_2_3 , 2 ) ;
resultStr = ihead . CalibrationStruct . ToString ( ) ;
2016-11-02 12:16:07 +00:00
break ;
}
2019-10-25 10:53:11 +00:00
/// Delay between retries
if ( cfg . DelayBetweenRetries > 0 ) Thread . Sleep ( cfg . DelayBetweenRetries ) ;
2016-11-02 12:16:07 +00:00
}
}
2021-09-24 07:31:05 +00:00
ClosePort ( ihead ) ; /// Close RFID port
2016-11-02 12:16:07 +00:00
return error ;
}
2018-09-20 07:05:32 +00:00
/// <summary>
/// Normalize calibration factor in case ti is close to value 8000.
/// </summary>
/// <param name="ihead">Water meter object</param>
/// <param name="resultStr">String passed to caller</param>
/// <returns>true on success</returns>
static CommErr NormalizeCalibrationV4Factors ( int threadId , IperlHead ihead , Results . Entities . WaterMeter wm , ref string resultStr )
{
if ( ihead . CommFailed | | ( ihead . CalibrationStructV4 = = null ) ) return CommErr . CommFailed ;
if ( ihead . FactorLimitLo < = ihead . CalibFactor & & ihead . CalibFactor < = ihead . FactorLimitHi )
{
resultStr = "Calibratin factor is OK" ;
return CommErr . None ; /// No need to update the calibration factor
}
2021-09-24 07:31:05 +00:00
if ( OpenPort ( ihead ) ! = 0 ) return CommErr . OpenPort ; /// Open RFID port
2018-09-20 07:05:32 +00:00
CommErr error = CommErr . Write ;
/// Determine the new calibration factor
UInt16 defaultCalibFactor ;
switch ( ihead . CalibrationStructV4 . MeterType )
{
2021-07-28 12:47:05 +00:00
case MeterType . DN15 :
defaultCalibFactor = 2710 ;
break ;
case MeterType . DN20 :
defaultCalibFactor = 3746 ;
break ;
case MeterType . DN25 :
defaultCalibFactor = 3300 ;
break ;
case MeterType . DN32 :
defaultCalibFactor = 2500 ;
break ;
case MeterType . DN40 :
defaultCalibFactor = 3080 ;
break ;
case MeterType . DN25_Q3_10 :
2018-09-20 07:05:32 +00:00
case MeterType . CoaxManifold :
default :
defaultCalibFactor = 3040 ;
break ;
}
byte [ ] data = new byte [ 2 ] { ( byte ) ( defaultCalibFactor & 0x00FF ) , ( byte ) ( ( defaultCalibFactor > > 8 ) & 0x00FF ) } ;
for ( int j = 0 ; j < cfg . MaxCommRetries ; j + + )
{
2021-09-24 07:31:05 +00:00
if ( 0 = = WriteRequestPort ( ihead , MessageID . Calibration , 2 , 2 , data , cfg . CommTimeout ) )
2018-09-20 07:05:32 +00:00
{
error = CommErr . None ;
ihead . CalibrationStructV4 . Update ( data , 2 ) ;
break ;
}
2019-10-25 10:53:11 +00:00
/// Delay between retries
if ( cfg . DelayBetweenRetries > 0 ) Thread . Sleep ( cfg . DelayBetweenRetries ) ;
2018-09-20 07:05:32 +00:00
}
if ( error = = CommErr . None )
{
error = CommErr . Verify ;
/// Read calibration
byte [ ] calib_2_3 = null ;
for ( int j = 0 ; j < cfg . MaxCommRetries ; j + + )
{
2021-09-24 07:31:05 +00:00
if ( 0 = = ReadRequestPort ( ihead , MessageID . Calibration , 2 , 2 , out calib_2_3 , cfg . CommTimeout ) )
2018-09-20 07:05:32 +00:00
{
error = CommErr . None ;
ihead . CalibrationStructV4 . Update ( calib_2_3 , 2 ) ;
resultStr = ihead . CalibrationStructV4 . ToString ( ) ;
break ;
}
2019-10-25 10:53:11 +00:00
/// Delay between retries
if ( cfg . DelayBetweenRetries > 0 ) Thread . Sleep ( cfg . DelayBetweenRetries ) ;
2018-09-20 07:05:32 +00:00
}
}
2021-09-24 07:31:05 +00:00
ClosePort ( ihead ) ; /// Close RFID port
2018-09-20 07:05:32 +00:00
return error ;
}
2019-01-23 07:34:31 +00:00
/// <summary>
/// Reset both Q2 correction factors in the memory to 0.
/// Read them back to verify factors were written correctly.
/// </summary>
/// <param name="ihead">Water meter object</param>
/// <param name="resultStr">String passed to caller</param>
/// <returns>true on success</returns>
static CommErr ReadQ2Correction ( int threadId , IperlHead ihead , Results . Entities . WaterMeter wm , ref string resultStr )
{
if ( ihead . CommFailed ) return CommErr . CommFailed ;
2021-09-24 07:31:05 +00:00
if ( OpenPort ( ihead ) ! = 0 ) return CommErr . OpenPort ; /// Open RFID port
2019-01-23 07:34:31 +00:00
CommErr error = CommErr . Read ;
/// Write zero Q2 correction
byte [ ] rdData = null ;
///
for ( int j = 0 ; j < cfg . MaxCommRetries ; j + + )
{
2021-09-24 07:31:05 +00:00
if ( 0 = = ReadRequestPort ( ihead , MessageID . MetrologyMemory , Q2CorrFactorsAddr , 2 , out rdData , cfg . CommTimeout ) )
2019-01-23 07:34:31 +00:00
{
error = CommErr . None ;
break ;
}
2019-10-25 10:53:11 +00:00
/// Delay between retries
if ( cfg . DelayBetweenRetries > 0 ) Thread . Sleep ( cfg . DelayBetweenRetries ) ;
2019-01-23 07:34:31 +00:00
}
if ( ( error = = CommErr . None ) & & ( rdData ! = null ) & & ( rdData . Length = = 2 ) )
{
resultStr = "Q2 corrections successfully read" ;
2019-04-03 14:34:05 +00:00
wm . Q2CorrLR = ihead . Q2CorrLR = ( int ) ( ( SByte ) rdData [ 0 ] ) ;
wm . Q2CorrRL = ihead . Q2CorrRL = ( int ) ( ( SByte ) rdData [ 1 ] ) ;
2019-01-23 07:34:31 +00:00
}
2021-09-24 07:31:05 +00:00
ClosePort ( ihead ) ; /// Close RFID port
2019-01-23 07:34:31 +00:00
return error ;
}
2018-10-17 09:31:28 +00:00
/// <summary>
2020-04-27 10:24:54 +00:00
/// Reset both Q2 correction factors to 0.
2015-08-15 15:51:54 +00:00
/// Read them back to verify factors were written correctly.
/// </summary>
2017-05-31 12:51:26 +00:00
/// <param name="ihead">Water meter object</param>
2015-08-15 15:51:54 +00:00
/// <param name="resultStr">String passed to caller</param>
/// <returns>true on success</returns>
2017-08-04 15:45:40 +00:00
static CommErr ResetQ2Correction ( int threadId , IperlHead ihead , Results . Entities . WaterMeter wm , ref string resultStr )
2019-03-28 08:33:17 +00:00
{
2020-04-27 10:24:54 +00:00
return WriteQ2Corrections ( threadId , ihead , wm , ref resultStr , 0 , 0 ) ;
2019-03-28 08:33:17 +00:00
}
/// <summary>
2020-04-27 10:24:54 +00:00
/// Set both Q2 correction factors to default values obtained by a REST service
/// Read them back to verify factors were written correctly.
/// </summary>
/// <param name="ihead">Water meter object</param>
/// <param name="resultStr">String passed to caller</param>
/// <returns>true on success</returns>
static CommErr WriteDefaultQ2Corrections ( int threadId , IperlHead ihead , Results . Entities . WaterMeter wm , ref string resultStr )
{
if ( ihead . CommFailed ) return CommErr . CommFailed ;
2021-07-28 09:40:45 +00:00
if ( ProcessData . IsQ2PreCorrectionCalculated )
2020-04-27 10:24:54 +00:00
{
2021-07-28 09:40:45 +00:00
return WriteQ2Corrections ( threadId , ihead , wm , ref resultStr , ProcessData . CalculatedQ2PreCorrectionLR ,
ProcessData . CalculatedQ2PreCorrectionRL ) ;
2020-04-27 10:24:54 +00:00
}
else
{
2021-07-29 10:02:49 +00:00
int q2corrRL ;
int q2corrLR ;
switch ( ihead . MeterType )
{
case MeterType . DN15 :
q2corrRL = cfg . DfltQ2c_15_rl ;
q2corrLR = cfg . DfltQ2c_15_lr ;
break ;
case MeterType . DN20 :
q2corrRL = cfg . DfltQ2c_20_rl ;
q2corrLR = cfg . DfltQ2c_20_lr ;
break ;
case MeterType . DN25 :
q2corrRL = cfg . DfltQ2c_25_63_rl ;
q2corrLR = cfg . DfltQ2c_25_63_lr ;
break ;
case MeterType . DN25_Q3_10 :
q2corrRL = cfg . DfltQ2c_25_10_rl ;
q2corrLR = cfg . DfltQ2c_25_10_lr ;
break ;
case MeterType . DN32 :
q2corrRL = cfg . DfltQ2c_32_rl ;
q2corrLR = cfg . DfltQ2c_32_lr ;
break ;
case MeterType . DN40 :
q2corrRL = cfg . DfltQ2c_40_rl ;
q2corrLR = cfg . DfltQ2c_40_lr ;
break ;
default :
q2corrRL = 0 ;
q2corrLR = 0 ;
break ;
}
return WriteQ2Corrections ( threadId , ihead , wm , ref resultStr , q2corrLR , q2corrRL ) ;
2020-04-27 10:24:54 +00:00
}
}
/// <summary>
/// Write both Q2 correction factors to given values.
2019-03-28 08:33:17 +00:00
/// Read them back to verify factors were written correctly.
/// </summary>
/// <param name="ihead">Water meter object</param>
/// <param name="resultStr">String passed to caller</param>
/// <returns>true on success</returns>
2020-04-27 10:24:54 +00:00
static CommErr WriteQ2Corrections ( int threadId , IperlHead ihead , Results . Entities . WaterMeter wm , ref string resultStr , int factorLR , int factorRL )
2015-08-14 12:33:36 +00:00
{
2017-05-31 12:51:26 +00:00
if ( ihead . CommFailed ) return CommErr . CommFailed ;
2015-08-15 15:51:54 +00:00
2021-09-24 07:31:05 +00:00
if ( OpenPort ( ihead ) ! = 0 ) return CommErr . OpenPort ; /// Open RFID port
2015-08-15 15:51:54 +00:00
2015-08-17 14:02:30 +00:00
CommErr error = CommErr . Write ;
2015-08-15 15:51:54 +00:00
/// Write zero Q2 correction
2019-03-28 08:33:17 +00:00
byte [ ] wrData = new byte [ 2 ] { ( byte ) factorLR , ( byte ) factorRL } ;
2015-08-22 11:58:55 +00:00
///
2015-09-06 21:36:14 +00:00
for ( int j = 0 ; j < cfg . MaxCommRetries ; j + + )
2015-08-15 15:51:54 +00:00
{
2021-09-24 07:31:05 +00:00
if ( 0 = = WriteRequestPort ( ihead , MessageID . MetrologyMemory , Q2CorrFactorsAddr , wrData . Length , wrData , cfg . CommTimeout ) )
2016-02-16 13:44:10 +00:00
{
2019-04-03 14:34:05 +00:00
wm . Q2CorrRL = ihead . Q2CorrRL = factorRL ;
wm . Q2CorrLR = ihead . Q2CorrLR = factorLR ;
2019-03-28 08:33:17 +00:00
error = CommErr . None ;
2016-02-16 13:44:10 +00:00
break ;
}
2019-10-25 10:53:11 +00:00
/// Delay between retries
if ( cfg . DelayBetweenRetries > 0 ) Thread . Sleep ( cfg . DelayBetweenRetries ) ;
}
2015-08-15 15:51:54 +00:00
2016-02-16 13:44:10 +00:00
///
/// Verification disabled on 16.02.2016
2016-10-27 12:27:37 +00:00
///
#if VERIFY_Q2_CORR_RESET
2015-08-22 11:58:55 +00:00
/// Verify the correction factors
2015-08-17 14:02:30 +00:00
if ( error = = CommErr . None )
2015-08-15 15:51:54 +00:00
{
2015-08-17 14:02:30 +00:00
error = CommErr . Verify ;
2015-08-15 15:51:54 +00:00
/// Read calibration
byte [ ] rdData = null ;
2015-09-06 21:36:14 +00:00
for ( int j = 0 ; j < cfg . MaxCommRetries ; j + + )
2015-08-15 15:51:54 +00:00
{
2017-08-04 15:45:40 +00:00
if ( ( 0 = = ReadRequestPort ( threadId , ihead , MessageID . MetrologyMemory , Q2CorrFactorsAddr , 2 , out rdData , cfg . CommTimeout ) ) & &
2015-08-15 15:51:54 +00:00
( rdData ! = null ) & & ( rdData . Length = = 2 ) & & ( rdData [ 0 ] = = 0 ) & & ( rdData [ 1 ] = = 0 ) )
{
2015-08-17 14:02:30 +00:00
error = CommErr . None ;
2019-08-15 15:10:09 +00:00
resultStr = string . Format ( "Q2 correction set to LR={0}, RL={1}" , factorLR , factorRL ) ;
2016-02-16 13:44:10 +00:00
break ;
}
2019-10-25 10:53:11 +00:00
/// Delay between retries
if ( cfg . DelayBetweenRetries > 0 ) Thread . Sleep ( cfg . DelayBetweenRetries ) ;
2016-02-16 13:44:10 +00:00
}
}
#else
2019-08-15 15:10:09 +00:00
if ( error = = CommErr . None )
2016-02-16 13:44:10 +00:00
{
2019-08-15 15:10:09 +00:00
resultStr = string . Format ( "Q2 correction set to LR={0}, RL={1}" , factorLR , factorRL ) ;
2016-02-16 13:44:10 +00:00
}
#endif
2021-09-24 07:31:05 +00:00
ClosePort ( ihead ) ; /// Close RFID port
2016-02-16 13:44:10 +00:00
return error ;
}
2020-04-27 10:24:54 +00:00
static CommErr InitOrReadQ2Corrections ( int threadId , IperlHead ihead , Results . Entities . WaterMeter wm , ref string resultStr )
2019-03-28 08:33:17 +00:00
{
if ( ihead . CommFailed ) return CommErr . CommFailed ;
if ( wm . Pruefindex = = 1 )
{
2021-07-29 11:03:08 +00:00
int q2corrRL ;
int q2corrLR ;
2021-07-28 09:40:45 +00:00
if ( ProcessData . IsQ2PreCorrectionCalculated )
2019-08-15 06:59:51 +00:00
{
2021-07-29 11:03:08 +00:00
q2corrRL = ProcessData . CalculatedQ2PreCorrectionRL ;
q2corrLR = ProcessData . CalculatedQ2PreCorrectionLR ;
}
else
{
switch ( ihead . MeterType )
{
case MeterType . DN15 :
q2corrRL = cfg . DfltQ2c_15_rl ;
q2corrLR = cfg . DfltQ2c_15_lr ;
break ;
case MeterType . DN20 :
q2corrRL = cfg . DfltQ2c_20_rl ;
q2corrLR = cfg . DfltQ2c_20_lr ;
break ;
case MeterType . DN25 :
q2corrRL = cfg . DfltQ2c_25_63_rl ;
q2corrLR = cfg . DfltQ2c_25_63_lr ;
break ;
case MeterType . DN25_Q3_10 :
q2corrRL = cfg . DfltQ2c_25_10_rl ;
q2corrLR = cfg . DfltQ2c_25_10_lr ;
break ;
case MeterType . DN32 :
q2corrRL = cfg . DfltQ2c_32_rl ;
q2corrLR = cfg . DfltQ2c_32_lr ;
break ;
case MeterType . DN40 :
q2corrRL = cfg . DfltQ2c_40_rl ;
q2corrLR = cfg . DfltQ2c_40_lr ;
break ;
default :
q2corrRL = 0 ;
q2corrLR = 0 ;
break ;
}
2019-08-15 06:59:51 +00:00
}
2021-07-29 11:03:08 +00:00
return WriteQ2Corrections ( threadId , ihead , wm , ref resultStr , q2corrLR , q2corrRL ) ;
2019-03-28 08:33:17 +00:00
}
2021-07-29 11:03:08 +00:00
else
2019-03-28 08:33:17 +00:00
{
return ReadQ2Correction ( threadId , ihead , wm , ref resultStr ) ;
}
}
2016-02-16 13:44:10 +00:00
/// <summary>
/// Reset 2Hz correction factor in the memory to 0.
/// </summary>
2017-05-31 12:51:26 +00:00
/// <param name="ihead">Water meter object</param>
2016-02-16 13:44:10 +00:00
/// <param name="resultStr">String passed to caller</param>
/// <returns>true on success</returns>
2017-08-04 15:45:40 +00:00
static CommErr Reset2HzCorrection ( int threadId , IperlHead ihead , Results . Entities . WaterMeter wm , ref string resultStr )
2016-02-16 13:44:10 +00:00
{
2017-05-31 12:51:26 +00:00
if ( ihead . CommFailed ) return CommErr . CommFailed ;
2016-02-16 13:44:10 +00:00
2021-09-24 07:31:05 +00:00
if ( OpenPort ( ihead ) ! = 0 ) return CommErr . OpenPort ; /// Open RFID port
2016-02-16 13:44:10 +00:00
CommErr error = CommErr . Write ;
/// Write zero Q2 correction
byte [ ] wrData = new byte [ 1 ] { 0 } ;
///
for ( int j = 0 ; j < cfg . MaxCommRetries ; j + + )
{
2021-09-24 07:31:05 +00:00
if ( 0 = = WriteRequestPort ( ihead , MessageID . MetrologyMemory , Hz2CorrFactorsAddr , wrData . Length , wrData , cfg . CommTimeout ) )
2016-02-16 13:44:10 +00:00
{
error = CommErr . None ;
break ;
}
2019-10-25 10:53:11 +00:00
/// Delay between retries
if ( cfg . DelayBetweenRetries > 0 ) Thread . Sleep ( cfg . DelayBetweenRetries ) ;
}
2016-02-16 13:44:10 +00:00
///
/// Verification disabled on 16.02.2016
///
#if false
/// Verify the correction factors
if ( error = = CommErr . None )
{
error = CommErr . Verify ;
/// Read calibration
byte [ ] rdData = null ;
for ( int j = 0 ; j < cfg . MaxCommRetries ; j + + )
{
2017-08-04 15:45:40 +00:00
if ( ( 0 = = ReadRequestPort ( threadId , ihead , MessageID . MetrologyMemory , Hz2CorrFactorsAddr , 1 , out rdData , cfg . CommTimeout ) ) & &
2016-02-16 13:44:10 +00:00
( rdData ! = null ) & & ( rdData . Length = = 2 ) & & ( rdData [ 0 ] = = 0 ) & & ( rdData [ 1 ] = = 0 ) )
{
error = CommErr . None ;
resultStr = "2Hz correction reset to 0" ;
2017-07-14 14:31:35 +00:00
ihead . Q2CorrectionFactor = 0 ;
2015-08-15 15:51:54 +00:00
break ;
}
2019-10-25 10:53:11 +00:00
/// Delay between retries
if ( cfg . DelayBetweenRetries > 0 ) Thread . Sleep ( cfg . DelayBetweenRetries ) ;
2015-08-15 15:51:54 +00:00
}
}
2016-02-16 13:44:10 +00:00
#else
2019-10-25 10:53:11 +00:00
if ( error = = CommErr . None )
2016-02-16 13:44:10 +00:00
{
resultStr = "2Hz correction reset to 0" ;
2017-07-18 06:33:20 +00:00
ihead . Hz2Correction = 0 ;
2016-02-16 13:44:10 +00:00
}
#endif
2015-08-14 12:33:36 +00:00
2021-09-24 07:31:05 +00:00
ClosePort ( ihead ) ; /// Close RFID port
2015-08-15 15:51:54 +00:00
2015-08-17 14:02:30 +00:00
return error ;
2015-08-15 15:51:54 +00:00
}
/// <summary>
/// Write the calculated Q2 correction factors to the memory.
/// Read them back to verify factors were written correctly.
2019-03-28 08:33:17 +00:00
///
/// Write Q2 correction
/// Write Q2 correction Alt
/// Write Q2 correction [Greece | R-L | L-R] testname
/// Update Q2 corrections
/// Conditional update of Q2 corrections
2015-08-15 15:51:54 +00:00
/// </summary>
2017-05-31 12:51:26 +00:00
/// <param name="ihead">Water meter object</param>
2015-08-15 15:51:54 +00:00
/// <param name="resultStr">String passed to caller</param>
/// <returns>true on success</returns>
2021-07-29 11:03:08 +00:00
static CommErr CalculateAndWriteQ2Corrections ( int threadId , IperlHead ihead , Results . Entities . WaterMeter wm ,
Test test , ref string resultStr , Q2CorrType q2CorrType , string restOfLine )
2015-08-14 12:33:36 +00:00
{
2021-08-19 18:05:42 +00:00
var args = string . IsNullOrEmpty ( restOfLine ) ? new string [ 0 ] : restOfLine . Split ( new char [ ] { ' ' } ) ;
2019-04-03 14:34:05 +00:00
Results . Entities . MeterTestRslt q2adjResult ; /// The only test or the 1st test (the test in R-L direction)
Results . Entities . TestData q2adjTestData ;
///
2019-03-28 08:33:17 +00:00
if ( args . Length = = 0 )
2017-07-14 14:31:35 +00:00
{
2018-09-20 07:05:32 +00:00
/// In case of no test name argument, ihead.LastTestResult is used (if it exists)
2021-07-29 11:03:08 +00:00
if ( ihead . LastTestResult = = null | | ! ihead . LastTestResult . TestDone ) return CommErr . MissingTest ;
2019-03-28 08:33:17 +00:00
q2adjResult = ihead . LastTestResult ;
q2adjTestData = q2adjResult . TestRslt . TestData ;
2017-07-14 14:31:35 +00:00
}
2019-03-28 08:33:17 +00:00
else // if (args.Length >= 1)
2017-07-14 14:31:35 +00:00
{
2019-03-28 08:33:17 +00:00
/// Get test data from (the 1st) test name
q2adjTestData = wm . GetTestData ( args [ 0 ] ) ;
if ( q2adjTestData = = null ) return CommErr . MissingTest ;
if ( q2adjTestData . Repeats = = 1 )
2017-07-14 14:31:35 +00:00
{
/// Find a test result if Repets == 1
2019-03-28 08:33:17 +00:00
q2adjResult = wm . GetMeterTestRslt ( args [ 0 ] ) ;
2017-07-14 14:31:35 +00:00
if ( q2adjResult = = null | | ! q2adjResult . TestDone ) return CommErr . MissingTest ;
}
else
{
/// Calculate a summarized test result if Repeats > 1
q2adjResult = new Results . Entities . MeterTestRslt ( ) ;
for ( int i = 1 ; i < = q2adjTestData . Repeats ; i + + )
{
2019-03-28 08:33:17 +00:00
Results . Entities . MeterTestRslt oneMTR = wm . GetMeterTestRslt ( string . Format ( "{0} ({1}/{2})" , args [ 0 ] , i , q2adjTestData . Repeats ) ) ;
2017-07-14 14:31:35 +00:00
if ( oneMTR = = null | | ! oneMTR . TestDone ) return CommErr . MissingTest ;
2015-08-15 15:51:54 +00:00
2017-07-14 14:31:35 +00:00
q2adjResult . VolumeMeter + = oneMTR . VolumeMeter ;
q2adjResult . VolumeRef + = oneMTR . VolumeRef ;
2021-07-29 11:03:08 +00:00
if ( i = = 1 )
{
q2adjResult . CalibFactor = oneMTR . CalibFactor ;
q2adjResult . CalibFactorLNA = oneMTR . CalibFactorLNA ;
q2adjResult . Q2CorrRL = oneMTR . Q2CorrRL ;
q2adjResult . Q2CorrLR = oneMTR . Q2CorrLR ;
}
2017-07-14 14:31:35 +00:00
}
2019-03-28 08:33:17 +00:00
2018-04-10 14:10:44 +00:00
q2adjResult . Error = Config . Formulas . ErrorFromVolumes ( q2adjResult . VolumeMeter , q2adjResult . VolumeRef ) ;
2017-07-14 14:31:35 +00:00
}
}
2019-04-03 14:34:05 +00:00
Results . Entities . MeterTestRslt q2adjResult2 = null ; /// 2nd test name for a test in L-R direction
Results . Entities . TestData q2adjTestData2 = null ;
///
2019-03-28 08:33:17 +00:00
if ( args . Length > = 2 )
{
/// Get the 2nd test data from the 2nd test name
q2adjTestData2 = wm . GetTestData ( args [ 1 ] ) ;
if ( q2adjTestData2 = = null ) return CommErr . MissingTest ;
2016-02-16 13:44:10 +00:00
2019-03-28 08:33:17 +00:00
if ( q2adjTestData2 . Repeats = = 1 )
{
/// Find a test result if Repets == 1
q2adjResult2 = wm . GetMeterTestRslt ( args [ 1 ] ) ;
if ( q2adjResult2 = = null | | ! q2adjResult2 . TestDone ) return CommErr . MissingTest ;
}
else
{
/// Calculate a summarized test result if Repeats > 1
q2adjResult2 = new Results . Entities . MeterTestRslt ( ) ;
for ( int i = 1 ; i < = q2adjTestData2 . Repeats ; i + + )
{
Results . Entities . MeterTestRslt oneMTR = wm . GetMeterTestRslt ( string . Format ( "{0} ({1}/{2})" , args [ 1 ] , i , q2adjTestData2 . Repeats ) ) ;
if ( oneMTR = = null | | ! oneMTR . TestDone ) return CommErr . MissingTest ;
q2adjResult2 . VolumeMeter + = oneMTR . VolumeMeter ;
q2adjResult2 . VolumeRef + = oneMTR . VolumeRef ;
2021-07-29 11:03:08 +00:00
if ( i = = 1 )
{
q2adjResult2 . CalibFactor = oneMTR . CalibFactor ;
q2adjResult2 . CalibFactorLNA = oneMTR . CalibFactorLNA ;
q2adjResult2 . Q2CorrRL = oneMTR . Q2CorrRL ;
q2adjResult2 . Q2CorrLR = oneMTR . Q2CorrLR ;
}
2019-03-28 08:33:17 +00:00
}
q2adjResult2 . Error = Config . Formulas . ErrorFromVolumes ( q2adjResult2 . VolumeMeter , q2adjResult2 . VolumeRef ) ;
}
}
2021-08-19 18:05:42 +00:00
if ( q2adjResult = = null | |
( ( q2CorrType = = Q2CorrType . Update | | q2CorrType = = Q2CorrType . ConditionalUpdate ) & & q2adjResult2 = = null ) )
2019-04-03 14:34:05 +00:00
{
2021-08-19 18:05:42 +00:00
return CommErr . MissingTest ; /// Procedure configuration error
2019-04-03 14:34:05 +00:00
}
2021-08-19 18:05:42 +00:00
if ( ( q2CorrType = = Q2CorrType . ConditionalUpdate & & q2adjResult . Passed & & q2adjResult2 . Passed ) | |
( ( q2CorrType = = Q2CorrType . ConditionalUpdateRL | | q2CorrType = = Q2CorrType . ConditionalUpdateLR ) & & q2adjResult . Passed ) )
{
resultStr = string . Format ( "No Q2 correction update" ) ;
rfidDataLogger . InfoFormat ( "{0}({1}): No Q2 correction update" , ihead . Name , ihead . SerialNr ) ;
return CommErr . None ; /// No Q2 correction when doing conditional update and WM passed
}
double errLimitLo = test . ErrLimLo + test . Uncertainty ;
double errLimitHi = test . ErrLimHi - test . Uncertainty ;
///
if ( q2adjResult . Error < errLimitLo | | errLimitHi < q2adjResult . Error | |
( q2adjResult2 ! = null & & ( q2adjResult2 . Error < errLimitLo | | errLimitHi < q2adjResult2 . Error ) ) )
2019-03-28 08:33:17 +00:00
{
2021-08-19 18:05:42 +00:00
/// At least one of Q2 errors is out of range for Q2 correction
log . WarnFormat ( "OoR => no Q2 correction: Pos={0}, PCB#={1}, ***Q2_RL err={2}%***, ***Q2_LR err={3}%***, CalTarget={4}%, [Lo={5}%, Hi={6}%]" ,
ihead . Name ,
ihead . SerialNr ,
q2adjResult . Error . ToString ( "F2" ) ,
q2adjResult2 ! = null ? q2adjResult2 . Error . ToString ( "F2" ) : string . Empty ,
ihead . CalibTargetQ2 . ToString ( "F1" ) ,
errLimitLo . ToString ( "F2" ) ,
errLimitHi . ToString ( "F2" ) ) ;
resultStr = string . Format ( "Q2 error is out of range => no Q2 correction" ) ;
rfidDataLogger . InfoFormat ( "{0}({1}): Q2 error ({2},{3}) is out of range ({4}..{5}) => Failed" ,
ihead . Name ,
ihead . SerialNr ,
q2adjResult . Error . ToString ( "F2" ) ,
q2adjResult2 ! = null ? q2adjResult2 . Error . ToString ( "F2" ) : string . Empty ,
errLimitLo . ToString ( "F2" ) ,
errLimitHi . ToString ( "F2" ) ) ;
return CommErr . Q2OutOfRange ;
2019-03-28 08:33:17 +00:00
}
2015-08-14 12:33:36 +00:00
2019-04-03 14:34:05 +00:00
2018-10-12 08:54:33 +00:00
///
2019-03-28 08:33:17 +00:00
/// Calculate Q2 correction factor(s) from an error measured at Q2
2018-10-12 08:54:33 +00:00
///
2019-03-28 08:33:17 +00:00
double q2Correction = 0 ;
2019-04-25 11:53:08 +00:00
double q2Correction2 = 0 ; /// L-R direction in case of Q2CorrType.Update and Q2CorrType.ConditionalUpdate
2019-03-28 08:33:17 +00:00
///
2021-07-29 11:03:08 +00:00
if ( q2CorrType = = Q2CorrType . Update | | q2CorrType = = Q2CorrType . ConditionalUpdate )
2018-10-12 08:54:33 +00:00
{
2021-08-19 18:05:42 +00:00
/// Calculate two Q2 correction factors from two tests done in both directions
q2Correction = ihead . CalculateQ2CorrectionFactor ( q2adjResult , ihead . CalibTargetQ2 , q2adjTestData . Qfrom , q2adjResult . Q2CorrRL ) ;
q2Correction2 = ihead . CalculateQ2CorrectionFactor ( q2adjResult2 , ihead . CalibTargetQ2 , q2adjTestData2 . Qfrom , q2adjResult2 . Q2CorrLR ) ;
2018-10-12 08:54:33 +00:00
}
2019-03-28 08:33:17 +00:00
else
{
2021-08-19 18:05:42 +00:00
/// Calculate Q2 correction factors from a single test
q2Correction = ihead . CalculateQ2CorrectionFactor ( q2adjResult , ihead . CalibTargetQ2 , q2adjTestData . Qfrom , q2adjResult . Q2CorrRL ) ;
q2Correction2 = ihead . CalculateQ2CorrectionFactor ( q2adjResult , ihead . CalibTargetQ2 , q2adjTestData . Qfrom , q2adjResult . Q2CorrLR ) ;
2019-03-28 08:33:17 +00:00
}
2021-08-19 18:05:42 +00:00
2021-07-29 11:03:43 +00:00
int q2CorrRL = 0 ;
int q2CorrLR = 0 ;
2019-03-28 08:33:17 +00:00
///
2021-02-24 11:08:04 +00:00
if ( q2CorrType = = Q2CorrType . Standard | | q2CorrType = = Q2CorrType . Standard_incl_05 | | q2CorrType = = Q2CorrType . UpdateBothQ2FactorsTestRLDir )
2017-03-31 12:17:18 +00:00
{
///
/// Standard process
///
2020-11-27 08:03:31 +00:00
if ( q2CorrType = = Q2CorrType . Standard & & Math . Abs ( q2adjResult . Error - ihead . CalibTargetQ2 ) < = 0.5 )
2017-03-31 12:17:18 +00:00
{
resultStr = string . Format ( "Q2 correction = 0 (writing bypassed)" ) ;
return CommErr . None ;
}
2015-08-11 06:50:32 +00:00
2021-07-29 11:03:43 +00:00
q2CorrRL = ( int ) Math . Round ( 1.1 * q2Correction ) ;
q2CorrLR = ( int ) Math . Round ( 0.5 * q2Correction ) ;
2017-03-31 12:17:18 +00:00
}
2020-11-27 08:03:31 +00:00
else if ( q2CorrType = = Q2CorrType . Dewa | | q2CorrType = = Q2CorrType . Dewa_incl_05 )
2017-03-31 12:17:18 +00:00
{
///
2017-07-14 14:31:35 +00:00
/// Process for DEWA
2017-03-31 12:17:18 +00:00
///
2020-11-27 08:03:31 +00:00
if ( q2CorrType = = Q2CorrType . Dewa & & Math . Abs ( q2adjResult . Error - ihead . CalibTargetQ2 ) < = 0.5 )
2017-03-31 12:17:18 +00:00
{
resultStr = string . Format ( "Q2 correction = 0 (writing bypassed)" ) ;
return CommErr . None ;
}
2017-03-19 21:03:31 +00:00
2019-04-15 06:24:37 +00:00
/// Use the same correction factor in both directions
2021-07-29 11:03:43 +00:00
q2CorrRL = ( int ) Math . Round ( 1.0 * q2Correction2 ) ;
q2CorrLR = ( int ) Math . Round ( 1.0 * q2Correction2 ) ;
2017-03-31 12:17:18 +00:00
}
2021-02-24 11:08:04 +00:00
else if ( q2CorrType = = Q2CorrType . Greece | | q2CorrType = = Q2CorrType . Greece_incl_05 | | q2CorrType = = Q2CorrType . UpdateBothQ2FactorsTestLRDir )
2017-07-14 14:31:35 +00:00
{
2019-06-14 06:43:36 +00:00
///
/// Process for Greece
///
2020-11-27 08:03:31 +00:00
if ( q2CorrType = = Q2CorrType . Greece & & Math . Abs ( q2adjResult . Error - ihead . CalibTargetQ2 ) < = 0.5 )
2019-06-14 06:43:36 +00:00
{
resultStr = string . Format ( "Q2 correction = 0 (writing bypassed)" ) ;
return CommErr . None ;
}
2021-07-29 11:03:43 +00:00
q2CorrRL = ( int ) Math . Round ( 2.0 * q2Correction2 ) ;
q2CorrLR = ( int ) Math . Round ( 1.0 * q2Correction2 ) ;
2017-07-14 14:31:35 +00:00
}
2021-07-29 11:03:08 +00:00
else if ( q2CorrType = = Q2CorrType . RL | | q2CorrType = = Q2CorrType . RL_incl_05 | | q2CorrType = = Q2CorrType . ConditionalUpdateRL ) /// RL only
2018-09-17 10:52:55 +00:00
{
2020-11-27 08:03:31 +00:00
if ( q2CorrType = = Q2CorrType . RL & & Math . Abs ( q2adjResult . Error - ihead . CalibTargetQ2 ) < = 0.5 )
2018-11-09 14:56:22 +00:00
{
resultStr = string . Format ( "Q2 correction = 0 (writing bypassed)" ) ;
return CommErr . None ;
}
2021-07-29 11:03:43 +00:00
q2CorrRL = ( int ) Math . Round ( q2Correction ) ;
2018-09-17 10:52:55 +00:00
}
2021-07-29 11:03:08 +00:00
else if ( q2CorrType = = Q2CorrType . LR | | q2CorrType = = Q2CorrType . LR_incl_05 | | q2CorrType = = Q2CorrType . ConditionalUpdateLR ) /// LR only
2018-09-17 10:52:55 +00:00
{
2020-11-27 08:03:31 +00:00
if ( q2CorrType = = Q2CorrType . LR & & Math . Abs ( q2adjResult . Error - ihead . CalibTargetQ2 ) < = 0.5 )
2018-11-09 14:56:22 +00:00
{
resultStr = string . Format ( "Q2 correction = 0 (writing bypassed)" ) ;
return CommErr . None ;
}
2021-07-29 11:03:43 +00:00
q2CorrLR = ( int ) Math . Round ( q2Correction2 ) ;
2018-09-17 10:52:55 +00:00
}
2019-03-28 08:33:17 +00:00
else if ( ( q2CorrType = = Q2CorrType . Update ) | | ( q2CorrType = = Q2CorrType . ConditionalUpdate ) )
{
2021-07-29 11:03:43 +00:00
q2CorrRL = ( int ) Math . Round ( q2Correction ) ;
q2CorrLR = ( int ) Math . Round ( q2Correction2 ) ;
2019-03-28 08:33:17 +00:00
}
2017-03-19 21:03:31 +00:00
2019-04-08 07:44:13 +00:00
///
/// Write calculated Q2 correction factors into the water meter
2019-05-22 05:52:13 +00:00
///
if ( ihead . CommFailed ) return CommErr . CommFailed ;
2021-09-24 07:31:05 +00:00
if ( OpenPort ( ihead ) ! = 0 ) return CommErr . OpenPort ; /// Open RFID port
2017-03-19 21:03:31 +00:00
CommErr error = CommErr . Write ;
2021-07-29 11:03:08 +00:00
if ( q2CorrType = = Q2CorrType . RL | | q2CorrType = = Q2CorrType . RL_incl_05 | | q2CorrType = = Q2CorrType . ConditionalUpdateRL )
2018-09-17 10:52:55 +00:00
{
2019-03-28 08:33:17 +00:00
///
/// Write R-L Q2 correction factor only
///
2021-07-29 11:03:43 +00:00
byte [ ] wrData = new byte [ 1 ] { ( byte ) q2CorrRL } ;
2018-09-17 10:52:55 +00:00
for ( int j = 0 ; j < cfg . MaxCommRetries ; j + + )
{
2021-09-24 07:31:05 +00:00
if ( 0 = = WriteRequestPort ( ihead , MessageID . MetrologyMemory , Q2CorrFactorsAddrRL , wrData . Length , wrData , cfg . CommTimeout ) )
2018-09-17 10:52:55 +00:00
{
error = CommErr . None ;
2021-07-29 11:03:08 +00:00
wm . Q2CorrRL = ihead . Q2CorrRL = q2CorrRL ;
2018-09-17 10:52:55 +00:00
break ;
}
2019-10-25 10:53:11 +00:00
/// Delay between retries
if ( cfg . DelayBetweenRetries > 0 ) Thread . Sleep ( cfg . DelayBetweenRetries ) ;
2018-09-17 10:52:55 +00:00
}
}
2021-07-29 11:03:08 +00:00
else if ( q2CorrType = = Q2CorrType . LR | | q2CorrType = = Q2CorrType . LR_incl_05 | | q2CorrType = = Q2CorrType . ConditionalUpdateLR )
2018-09-17 10:52:55 +00:00
{
2019-03-28 08:33:17 +00:00
///
/// Write L-R Q2 correction factor only
///
2021-07-29 11:03:43 +00:00
byte [ ] wrData = new byte [ 1 ] { ( byte ) q2CorrLR } ;
2018-09-17 10:52:55 +00:00
for ( int j = 0 ; j < cfg . MaxCommRetries ; j + + )
{
2021-09-24 07:31:05 +00:00
if ( 0 = = WriteRequestPort ( ihead , MessageID . MetrologyMemory , Q2CorrFactorsAddrLR , wrData . Length , wrData , cfg . CommTimeout ) )
2018-09-17 10:52:55 +00:00
{
error = CommErr . None ;
2021-07-29 11:03:08 +00:00
wm . Q2CorrLR = ihead . Q2CorrLR = q2CorrLR ;
2018-09-17 10:52:55 +00:00
break ;
}
2019-10-25 10:53:11 +00:00
/// Delay between retries
if ( cfg . DelayBetweenRetries > 0 ) Thread . Sleep ( cfg . DelayBetweenRetries ) ;
2018-09-17 10:52:55 +00:00
}
}
else
{
2019-03-28 08:33:17 +00:00
///
2018-09-17 10:52:55 +00:00
/// Write both Q2 correction factors
2019-03-28 08:33:17 +00:00
///
2021-07-29 11:03:43 +00:00
byte [ ] wrData = new byte [ 2 ] { ( byte ) q2CorrLR , ( byte ) q2CorrRL } ;
2018-09-17 10:52:55 +00:00
for ( int j = 0 ; j < cfg . MaxCommRetries ; j + + )
{
2021-09-24 07:31:05 +00:00
if ( 0 = = WriteRequestPort ( ihead , MessageID . MetrologyMemory , Q2CorrFactorsAddr , wrData . Length , wrData , cfg . CommTimeout ) )
2018-09-17 10:52:55 +00:00
{
error = CommErr . None ;
2021-07-29 11:03:08 +00:00
wm . Q2CorrRL = ihead . Q2CorrRL = q2CorrRL ;
wm . Q2CorrLR = ihead . Q2CorrLR = q2CorrLR ;
2018-09-17 10:52:55 +00:00
break ;
}
2019-10-25 10:53:11 +00:00
/// Delay between retries
if ( cfg . DelayBetweenRetries > 0 ) Thread . Sleep ( cfg . DelayBetweenRetries ) ;
2018-09-17 10:52:55 +00:00
}
}
2017-03-19 21:03:31 +00:00
///
/// Verification disabled on 16.02.2016
///
#if false
if ( error = = CommErr . None )
{
error = CommErr . Verify ;
/// Read calibration
byte [ ] rdData = null ;
for ( int j = 0 ; j < cfg . MaxCommRetries ; j + + )
{
2017-08-04 15:45:40 +00:00
if ( ( 0 = = ReadRequestPort ( threadId , ihead , MessageID . MetrologyMemory , Q2CorrFactorsAddr , 2 , out rdData , cfg . CommTimeout ) ) & &
2017-03-19 21:03:31 +00:00
( rdData ! = null ) & & ( rdData . Length = = 2 ) & & ( rdData [ 0 ] = = q2CorrRFlow ) & & ( rdData [ 1 ] = = q2CorrLFlow ) )
{
error = CommErr . None ;
resultStr = string . Format ( "Q2 factors: R-flow={0}, L-flow={1}" , ( SByte ) q2CorrRFlow , ( SByte ) q2CorrLFlow ) ;
2017-05-31 12:51:26 +00:00
rfidDataLogger . Warn ( ihead . Name + ": " + resultStr ) ;
2019-03-28 08:33:17 +00:00
wm . Q2ErrWOCorrection = ihead . Q2ErrorWOCorrection ;
if ( q2CorrType ! = Q2CorrType . LR ) wm . Q2CorrRFlow = ihead . Q2CorrRFlow = ( int ) ( sbyte ) q2CorrRFlow ;
if ( q2CorrType ! = Q2CorrType . RL ) wm . Q2CorrLFlow = ihead . Q2CorrLFlow = ( int ) ( sbyte ) q2CorrLFlow ;
2017-03-19 21:03:31 +00:00
break ;
}
2019-10-25 10:53:11 +00:00
/// Delay between retries
if ( cfg . DelayBetweenRetries > 0 ) Thread . Sleep ( cfg . DelayBetweenRetries ) ;
2017-03-19 21:03:31 +00:00
}
}
#else
2019-04-08 07:44:13 +00:00
///
/// Update WaterMeter entity and IperlHead
///
2018-09-17 10:52:55 +00:00
if ( error = = CommErr . None )
2017-03-19 21:03:31 +00:00
{
2018-09-17 10:52:55 +00:00
if ( q2CorrType = = Q2CorrType . RL )
{
2021-07-29 11:03:43 +00:00
resultStr = string . Format ( "Q2 correction: RL={0}" , q2CorrRL ) ;
2018-09-17 10:52:55 +00:00
}
else if ( q2CorrType = = Q2CorrType . LR )
{
2021-07-29 11:03:43 +00:00
resultStr = string . Format ( "Q2 correction: LR={0}" , q2CorrLR ) ;
2018-09-17 10:52:55 +00:00
}
else
{
2021-07-29 11:03:43 +00:00
resultStr = string . Format ( "Q2 correction: RL={0}, LR={1}" , q2CorrRL , q2CorrLR ) ;
2018-09-17 10:52:55 +00:00
}
2018-10-17 07:52:08 +00:00
rfidDataLogger . WarnFormat ( "{0}: {1}" , ihead . Name , resultStr ) ;
2019-04-04 12:39:16 +00:00
if ( ( q2CorrType ! = Q2CorrType . Update ) & & ( q2CorrType ! = Q2CorrType . ConditionalUpdate ) )
{
wm . Q2ErrWOCorrection = ihead . Q2ErrWOCorrection = q2adjResult . Error ;
}
2017-03-31 12:17:18 +00:00
}
2017-03-19 21:03:31 +00:00
#endif
2021-09-24 07:31:05 +00:00
ClosePort ( ihead ) ; /// Close RFID port
2017-03-19 21:03:31 +00:00
return error ;
}
2016-02-15 14:16:44 +00:00
/// <summary>
/// Write the calculated 2Hz correction factor to the memory.
/// </summary>
2017-05-31 12:51:26 +00:00
/// <param name="ihead">Water meter object</param>
2016-02-15 14:16:44 +00:00
/// <param name="resultStr">String passed to caller</param>
/// <returns>true on success</returns>
2017-08-04 15:45:40 +00:00
static CommErr Write2HzCorrection ( int threadId , IperlHead ihead , Results . Entities . WaterMeter wm , ref string resultStr )
2016-02-15 14:16:44 +00:00
{
2017-05-31 12:51:26 +00:00
if ( ihead . CommFailed ) return CommErr . CommFailed ;
2016-02-15 14:16:44 +00:00
2016-02-16 13:44:10 +00:00
/// Calculate the correction
2017-05-31 12:51:26 +00:00
ihead . Hz2CorrectionDone = false ;
2016-02-16 13:44:10 +00:00
int hz2CorrectionFactor ;
2017-05-31 12:51:26 +00:00
bool wmOK = ihead . Calculate2HzCorrectionFactor ( ihead . LastTestResult2 , ihead . LastTestResult , out ihead . Diff2Hz8Hz , out hz2CorrectionFactor ) ;
2016-02-16 13:44:10 +00:00
2016-02-15 14:16:44 +00:00
if ( hz2CorrectionFactor = = 0 )
{
2016-02-16 13:44:10 +00:00
resultStr = string . Format ( "2Hz correction = 0 (writing bypassed)" ) ;
2016-02-15 14:16:44 +00:00
return CommErr . None ;
}
2021-09-24 07:31:05 +00:00
if ( OpenPort ( ihead ) ! = 0 ) return CommErr . OpenPort ; /// Open RFID port
2016-02-15 14:16:44 +00:00
CommErr error = CommErr . Write ;
2016-02-16 13:44:10 +00:00
Byte hz2CorrectionByte = ( byte ) ( hz2CorrectionFactor & 0x000000FF ) ;
2016-02-15 14:16:44 +00:00
byte [ ] wrData = new byte [ 1 ] { hz2CorrectionByte } ;
///
for ( int j = 0 ; j < cfg . MaxCommRetries ; j + + )
{
2021-09-24 07:31:05 +00:00
if ( 0 = = WriteRequestPort ( ihead , MessageID . MetrologyMemory , Hz2CorrFactorsAddr , wrData . Length , wrData , cfg . CommTimeout ) )
2016-02-16 13:44:10 +00:00
{
error = CommErr . None ;
2019-04-03 14:34:05 +00:00
wm . Hz2Correction = ihead . Hz2Correction = hz2CorrectionFactor ;
wm . Hz2CorrectionDone = ihead . Hz2CorrectionDone = true ;
2019-03-28 08:33:17 +00:00
break ;
2016-02-16 13:44:10 +00:00
}
2019-10-25 10:53:11 +00:00
/// Delay between retries
if ( cfg . DelayBetweenRetries > 0 ) Thread . Sleep ( cfg . DelayBetweenRetries ) ;
}
2016-02-15 14:16:44 +00:00
2016-02-16 13:44:10 +00:00
///
/// Verification disabled on 16.02.2016
///
#if false
2016-02-15 14:16:44 +00:00
if ( error = = CommErr . None )
{
error = CommErr . Verify ;
/// Read calibration
byte [ ] rdData = null ;
for ( int j = 0 ; j < cfg . MaxCommRetries ; j + + )
{
if ( ( 0 = = ReadRequestPort ( wm , MessageID . MetrologyMemory , Hz2CorrFactorsAddr , 1 , out rdData , cfg . CommTimeout ) ) & &
( rdData ! = null ) & & ( rdData . Length = = 2 ) & & ( rdData [ 0 ] = = hz2CorrectionByte ) )
{
error = CommErr . None ;
resultStr = string . Format ( "2Hz factor = {0}" , ( SByte ) hz2CorrectionByte ) ;
2017-07-14 14:31:35 +00:00
rfidDataLogger . Warn ( ihead . Name + ": " + resultStr ) ;
2019-04-03 14:34:05 +00:00
wm . Hz2Correction = ihead . Hz2CorrectionFactor = hz2CorrectionFactor ;
wm . Diff2Hz8Hz = ihead . Diff2Hz8Hz ;
wm . Hz2CorrectionDone = ihead . Hz2CorrectionDone ;
2019-03-28 08:33:17 +00:00
break ;
2016-02-15 14:16:44 +00:00
}
2019-10-25 10:53:11 +00:00
/// Delay between retries
if ( cfg . DelayBetweenRetries > 0 ) Thread . Sleep ( cfg . DelayBetweenRetries ) ;
2016-02-15 14:16:44 +00:00
}
}
2016-02-16 13:44:10 +00:00
#else
2019-04-03 14:34:05 +00:00
if ( error = = CommErr . None )
2016-02-16 13:44:10 +00:00
{
resultStr = string . Format ( "2Hz correction = {0}" , ( SByte ) hz2CorrectionByte ) ;
2017-05-31 12:51:26 +00:00
rfidDataLogger . Warn ( ihead . Name + ": " + resultStr ) ;
2019-04-03 14:34:05 +00:00
wm . Diff2Hz8Hz = ihead . Diff2Hz8Hz ;
wm . Hz2CorrectionDone = ihead . Hz2CorrectionDone = true ;
wm . Hz2Correction = ihead . Hz2Correction = hz2CorrectionFactor ;
2016-02-16 13:44:10 +00:00
}
#endif
2016-02-15 14:16:44 +00:00
2021-09-24 07:31:05 +00:00
ClosePort ( ihead ) ; /// Close RFID port
2016-02-15 14:16:44 +00:00
return error ;
}
2019-04-03 14:34:05 +00:00
2021-09-16 12:20:26 +00:00
/// <summary>
/// DEWA rework.
/// </summary>
/// <param name="ihead">iPERL head object</param>
/// <param name="wm">Water meter object</param>
/// <param name="resultStr">String passed to caller</param>
/// <returns>true on success</returns>
2021-10-04 12:30:27 +00:00
static CommErr DewaRework ( IperlHead ihead , Results . Entities . WaterMeter wm , FlowDir flowDir , ref string resultStr )
2021-09-16 12:20:26 +00:00
{
2021-09-24 07:31:05 +00:00
if ( ihead . CommFailed ) return CommErr . CommFailed ;
2021-10-04 12:30:27 +00:00
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)
2021-09-24 07:31:05 +00:00
2021-09-16 12:20:26 +00:00
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" ) ,
2021-10-04 12:30:27 +00:00
new iPerlDataWrite ( MessageID . MetrologyMemory , 0x1985 , new byte [ ] { arrow } , "Arrow" ) ,
2021-09-16 12:20:26 +00:00
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 + + )
{
2021-09-24 07:31:05 +00:00
if ( 0 = = WriteRequestPort ( ihead , wData . MessageID , wData . Offset , wData . Data . Length , wData . Data , cfg . CommTimeout ) )
2021-09-16 12:20:26 +00:00
{
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
}
2021-09-24 07:31:05 +00:00
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 ;
}
2021-09-16 12:20:26 +00:00
}
2020-04-27 10:24:54 +00:00
static CommErr GetQ2PreCorrectionsFormRest ( int threadId , IperlHead ihead , Results . Entities . WaterMeter wm , ref string resultStr )
{
if ( ! ProcessData . IsQ2PreCorrectionCalculated )
{
ProcessData . IsQ2PreCorrectionCalculated = true ;
commonWMType = ihead . WMType_ID ;
bool success = iPerlCommunicationSeq . GetQ2PreCorrectionsOrBackups ( cfg , commonWMType ,
out ProcessData . CalculatedQ2PreCorrectionLR ,
out ProcessData . CalculatedQ2PreCorrectionRL ) ;
}
else if ( ihead . WMType_ID ! = commonWMType )
{
resultStr = string . Format ( "Different WZ_Typ: {0} ({1} expected)" , ihead . WMType_ID , commonWMType ) ;
return CommErr . WrongIPerlType ;
}
resultStr = string . Format ( "Q2 pre-corrections: LR={0} RL={1}" , ProcessData . CalculatedQ2PreCorrectionLR , ProcessData . CalculatedQ2PreCorrectionRL ) ;
return CommErr . None ;
}
2019-03-28 08:33:17 +00:00
#endif /// IPERL
2019-04-03 14:34:05 +00:00
2018-08-30 13:40:27 +00:00
#endregion
2016-02-15 14:16:44 +00:00
2015-08-11 06:50:32 +00:00
/// <summary>
/// Called when communication with one watermeter is completed
/// </summary>
public static void OnCommCompleted ( object sender , CommCompletedEventArgs data )
{
if ( CommCompletedHandler = = null ) return ;
try { CommCompletedHandler ( sender , data ) ; }
catch ( Exception e ) { log . Error ( "CommCompletedHandler(...) failed" , e ) ; }
}
public static event EventHandler < CommCompletedEventArgs > CommCompletedHandler ;
void DoOnCommCompleted ( object sender , CommCompletedEventArgs data )
{
2019-02-25 15:15:26 +00:00
try
2017-10-11 07:19:55 +00:00
{
2019-02-25 15:15:26 +00:00
///
/// Update the text message
///
if ( data . WMNr0 > = 0 ) messages [ data . WMNr0 ] . Text = data . CommMessage ;
2015-09-21 14:29:12 +00:00
2019-02-25 15:15:26 +00:00
///
/// Update head active/inactive switch
///
if ( data . WMNr0 > = 0 & & data . CommErr = = CommErr . HeadDisabledByUser )
2017-11-03 09:57:30 +00:00
{
2019-02-25 15:15:26 +00:00
/// iPerl head was disabled by the user
ckbState [ data . WMNr0 ] = false ;
checkBoxes [ data . WMNr0 ] . Checked = false ;
checkBoxes [ data . WMNr0 ] . Enabled = false ;
if ( data . Ihead ! = null ) data . Ihead . Disabled = true ;
if ( data . Wm ! = null ) data . Wm . Disabled = true ;
2017-11-03 09:57:30 +00:00
}
2019-02-25 15:15:26 +00:00
else if ( data . WMNr0 > = 0 & & data . CommErr = = CommErr . None )
{
/// One RFID communication successful => iPerl cannot be disabled by the user anymore
ckbState [ data . WMNr0 ] = true ;
checkBoxes [ data . WMNr0 ] . Checked = true ;
checkBoxes [ data . WMNr0 ] . Enabled = false ;
}
///
/// Update opto-communication indication
///
for ( int i = 0 ; i < iperlHeads . Count ; i + + )
2017-11-03 09:57:30 +00:00
{
2019-02-25 15:15:26 +00:00
if ( iperlHeads [ i ] = = null | | iperlHeads [ i ] . Disabled )
2018-12-03 07:14:15 +00:00
{
2019-02-25 15:15:26 +00:00
counters [ i ] . BackColor = DisabledColor ;
}
else
{
switch ( iperlHeads [ i ] . CheckFlowDirection ( ) )
{
case OptoHeadState . OptoAndDirOK :
counters [ i ] . BackColor = OptoAndDirOKColor ;
break ;
case OptoHeadState . DirNok :
counters [ i ] . BackColor = DirNokColor ;
break ;
2018-12-03 07:14:15 +00:00
2019-02-25 15:15:26 +00:00
default :
case OptoHeadState . OptoNok :
counters [ i ] . BackColor = OptoNokColor ;
break ;
}
2018-12-03 07:14:15 +00:00
}
2017-11-03 09:57:30 +00:00
}
2018-08-30 13:40:27 +00:00
#if ! TURA_SPECIAL
2019-02-25 15:15:26 +00:00
///
/// Branch
///
lock ( this )
{
2021-07-28 12:47:05 +00:00
if ( + + completedCommCount < 4 ) return ;
2019-02-25 15:15:26 +00:00
completedCommCount = 0 ;
}
2018-08-30 13:40:27 +00:00
#endif
2015-08-11 06:50:32 +00:00
2019-02-25 15:15:26 +00:00
if ( currentGroup < lastGroup )
2015-08-11 06:50:32 +00:00
{
2019-02-25 15:15:26 +00:00
/// Go to the next step / next group
currentGroup + + ;
2015-08-11 06:50:32 +00:00
}
2019-02-25 15:15:26 +00:00
else if ( currentActivityStep + 1 < multiTestParams . Count )
{
currentGroup = 0 ;
currentActivityStep + + ;
activityLabel . Text = multiTestParams [ currentActivityStep ] . Activity ;
currentGroup + + ;
}
else
{
/// Wait until all threads are finished
workerThreads [ data . ThreadId ] . Join ( 2000 ) ;
NormalClose ( ) ;
}
}
catch ( Exception e )
2015-08-11 06:50:32 +00:00
{
2019-02-25 15:15:26 +00:00
log . ErrorFormat ( "DoOnCommCompleted({0}) failed: {1}" , data , e . Message ) ;
log . FatalFormat ( "StackTrace : {0}{1}" , Environment . NewLine , e . StackTrace ) ;
2015-08-11 06:50:32 +00:00
}
}
/// <summary>
/// Called when communication with all watermeters is completed
/// </summary>
public static void OnAllCompleted ( object sender , AllCompletedEventArgs data )
{
if ( AllCompletedHandler = = null ) return ;
try { AllCompletedHandler ( sender , data ) ; }
catch ( Exception e ) { log . Error ( "AllCompletedHandler(...) failed" , e ) ; }
}
public static event EventHandler < AllCompletedEventArgs > AllCompletedHandler ;
void DoOnAllCompleted ( object sender , AllCompletedEventArgs data )
{
Text = data . CommMessage ;
}
2015-09-11 17:36:37 +00:00
/// <summary>
2016-01-03 01:05:35 +00:00
/// Update test result representing RFID communication success/failure
2015-09-11 17:36:37 +00:00
/// </summary>
/// <param name="test"></param>
2016-01-19 16:38:09 +00:00
void UpdateRfidCommResult ( IList < Config . Entities . Test > tests )
2015-09-11 17:36:37 +00:00
{
2016-01-08 18:18:45 +00:00
DateTime endTime = DateTime . Now ;
int testTime = StateMachine . Time - startTimeSec ;
2015-09-11 17:36:37 +00:00
2021-01-21 14:00:55 +00:00
if ( ! tests . Contains ( StateMachine . TestInstances [ 0 ] . Test ) )
2016-01-03 01:05:35 +00:00
{
2021-01-21 14:00:55 +00:00
tests . Insert ( 0 , StateMachine . TestInstances [ 0 ] . Test ) ; /// Add RFID test as the 1st item
2016-01-08 18:18:45 +00:00
}
2016-01-03 01:05:35 +00:00
2016-01-19 16:38:09 +00:00
foreach ( var test in tests )
2016-01-08 18:18:45 +00:00
{
2016-01-19 16:38:09 +00:00
Results . Entities . TestRslt tstRslt = ProcessData . BatchRslts . GetTestRslt ( test . Name , test . Part ) ;
2016-01-08 18:18:45 +00:00
if ( tstRslt ! = null )
{
2020-01-22 12:51:47 +00:00
Results . Utils . GetCounterStates ( tstRslt , Program . LocalSettings . Counters ) ;
2016-01-08 18:18:45 +00:00
/// Auxiliary results ... not required
/// Main results
2020-02-06 12:35:56 +00:00
tstRslt . MethodClass = TbfComponents . FindComponent ( test . Method ) . ClassName ;
tstRslt . TestDone = true ;
tstRslt . StartTime = tstRslt . Batch . StartTime ;
tstRslt . EndTime = endTime ;
tstRslt . FlowSetTime = 0 ;
2021-01-29 09:46:21 +00:00
tstRslt . MassOfEvapWater = 0 ;
2020-02-06 12:35:56 +00:00
tstRslt . TestTime + = testTime ; /// [s] total communication time of all tests
2016-01-08 18:18:45 +00:00
2017-05-31 12:51:26 +00:00
for ( int i = 0 ; i < iperlHeads . Count ; i + + )
{
Results . Entities . MeterTestRslt meterRslt =
2021-09-23 09:46:40 +00:00
ProcessData . BatchRslts . GetMeterTestRslt ( test . Name , waterMeterPositions0 [ i ] , CompoundMeterId . Single ) ;
2016-01-08 18:18:45 +00:00
2017-05-31 12:51:26 +00:00
if ( meterRslt ! = null & & iperlHeads [ i ] ! = null )
{
2017-11-12 14:27:21 +00:00
#if ORACLE_DB
2017-11-10 09:32:43 +00:00
meterRslt . WaterMeter . WaterMeterData . WMTypeId = iperlHeads [ i ] . WMType_ID ;
2017-11-12 14:27:21 +00:00
#endif
meterRslt . WaterMeter . SerialNr = iperlHeads [ i ] . SerialNr ;
2017-11-10 09:32:43 +00:00
meterRslt . Passed = ( ! iperlHeads [ i ] . CommFailed & & ! iperlHeads [ i ] . Disabled ) ;
2017-05-31 12:51:26 +00:00
meterRslt . TestDone = true ;
}
}
2016-01-08 18:18:45 +00:00
}
2016-01-03 01:05:35 +00:00
}
2018-05-21 12:49:27 +00:00
UiBridge . Bridge . OnTestCompleted ( this , new UiBridge . TestCompletedEventArgs ( string . Empty , null ) ) ;
2015-09-11 17:36:37 +00:00
}
2017-10-11 07:19:55 +00:00
2018-08-30 13:40:27 +00:00
#region Check boxes edit mode support
2017-10-11 07:19:55 +00:00
private void checkBoxImage1_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 0 ] ] = checkBoxImage1 . Checked ; }
private void checkBoxImage2_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 1 ] ] = checkBoxImage2 . Checked ; }
private void checkBoxImage3_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 2 ] ] = checkBoxImage3 . Checked ; }
private void checkBoxImage4_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 3 ] ] = checkBoxImage4 . Checked ; }
private void checkBoxImage5_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 4 ] ] = checkBoxImage5 . Checked ; }
private void checkBoxImage6_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 5 ] ] = checkBoxImage6 . Checked ; }
private void checkBoxImage7_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 6 ] ] = checkBoxImage7 . Checked ; }
private void checkBoxImage8_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 7 ] ] = checkBoxImage8 . Checked ; }
private void checkBoxImage9_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 8 ] ] = checkBoxImage9 . Checked ; }
private void checkBoxImage10_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 9 ] ] = checkBoxImage10 . Checked ; }
private void checkBoxImage11_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 10 ] ] = checkBoxImage11 . Checked ; }
private void checkBoxImage12_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 11 ] ] = checkBoxImage12 . Checked ; }
private void checkBoxImage13_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 12 ] ] = checkBoxImage13 . Checked ; }
private void checkBoxImage14_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 13 ] ] = checkBoxImage14 . Checked ; }
private void checkBoxImage15_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 14 ] ] = checkBoxImage15 . Checked ; }
private void checkBoxImage16_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 15 ] ] = checkBoxImage16 . Checked ; }
private void checkBoxImage17_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 16 ] ] = checkBoxImage17 . Checked ; }
private void checkBoxImage18_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 17 ] ] = checkBoxImage18 . Checked ; }
private void checkBoxImage19_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 18 ] ] = checkBoxImage19 . Checked ; }
private void checkBoxImage20_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 19 ] ] = checkBoxImage20 . Checked ; }
private void checkBoxImage21_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 20 ] ] = checkBoxImage21 . Checked ; }
private void checkBoxImage22_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 21 ] ] = checkBoxImage22 . Checked ; }
private void checkBoxImage23_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 22 ] ] = checkBoxImage23 . Checked ; }
private void checkBoxImage24_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 23 ] ] = checkBoxImage24 . Checked ; }
private void checkBoxImage25_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 24 ] ] = checkBoxImage25 . Checked ; }
private void checkBoxImage26_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 25 ] ] = checkBoxImage26 . Checked ; }
private void checkBoxImage27_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 26 ] ] = checkBoxImage27 . Checked ; }
private void checkBoxImage28_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 27 ] ] = checkBoxImage28 . Checked ; }
private void checkBoxImage29_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 28 ] ] = checkBoxImage29 . Checked ; }
private void checkBoxImage30_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 29 ] ] = checkBoxImage30 . Checked ; }
private void checkBoxImage31_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 30 ] ] = checkBoxImage31 . Checked ; }
private void checkBoxImage32_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 31 ] ] = checkBoxImage32 . Checked ; }
private void checkBoxImage33_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 32 ] ] = checkBoxImage33 . Checked ; }
private void checkBoxImage34_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 33 ] ] = checkBoxImage34 . Checked ; }
private void checkBoxImage35_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 34 ] ] = checkBoxImage35 . Checked ; }
private void checkBoxImage36_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 35 ] ] = checkBoxImage36 . Checked ; }
private void checkBoxImage37_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 36 ] ] = checkBoxImage37 . Checked ; }
private void checkBoxImage38_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 37 ] ] = checkBoxImage38 . Checked ; }
private void checkBoxImage39_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 38 ] ] = checkBoxImage39 . Checked ; }
private void checkBoxImage40_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 39 ] ] = checkBoxImage40 . Checked ; }
private void checkBoxImage41_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 40 ] ] = checkBoxImage41 . Checked ; }
private void checkBoxImage42_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 41 ] ] = checkBoxImage42 . Checked ; }
private void checkBoxImage43_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 42 ] ] = checkBoxImage43 . Checked ; }
private void checkBoxImage44_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 43 ] ] = checkBoxImage44 . Checked ; }
private void checkBoxImage45_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 44 ] ] = checkBoxImage45 . Checked ; }
private void checkBoxImage46_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 45 ] ] = checkBoxImage46 . Checked ; }
private void checkBoxImage47_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 46 ] ] = checkBoxImage47 . Checked ; }
private void checkBoxImage48_Click ( object sender , EventArgs e ) { ckbState [ ckbIndex [ 47 ] ] = checkBoxImage48 . Checked ; }
2017-11-03 09:57:30 +00:00
2020-04-27 10:24:54 +00:00
/// <summary>
/// Get states of checkboxes as one bitfield (long)
/// </summary>
/// <returns>Long bitfield</returns>
2017-11-03 09:57:30 +00:00
private long GetCheckBoxStates ( )
{
long result = 0 ;
for ( int i = 0 ; i < 48 ; i + + )
{
2021-08-19 11:49:25 +00:00
int wmNr0 = ckbIndex [ i ] ;
if ( wmNr0 > = 0 & & ckbState [ wmNr0 ] )
2021-07-16 15:57:55 +00:00
{
2021-08-19 11:49:25 +00:00
result + = ( 1L < < wmNr0 ) ;
2021-07-16 15:57:55 +00:00
}
2017-11-03 09:57:30 +00:00
}
return result ;
}
2020-04-27 10:24:54 +00:00
/// <summary>
/// Set checkboxes to states stored in a bitfield (long)
/// </summary>
2017-11-03 09:57:30 +00:00
private void SetCheckBoxStates ( long state )
{
CheckBoxImage [ ] chkBoxes = new CheckBoxImage [ 48 ]
{
checkBoxImage1 , checkBoxImage2 , checkBoxImage3 , checkBoxImage4 , checkBoxImage5 ,
checkBoxImage6 , checkBoxImage7 , checkBoxImage8 , checkBoxImage9 , checkBoxImage10 ,
checkBoxImage11 , checkBoxImage12 , checkBoxImage13 , checkBoxImage14 , checkBoxImage15 ,
checkBoxImage16 , checkBoxImage17 , checkBoxImage18 , checkBoxImage19 , checkBoxImage20 ,
checkBoxImage21 , checkBoxImage22 , checkBoxImage23 , checkBoxImage24 , checkBoxImage25 ,
checkBoxImage26 , checkBoxImage27 , checkBoxImage28 , checkBoxImage29 , checkBoxImage30 ,
checkBoxImage31 , checkBoxImage32 , checkBoxImage33 , checkBoxImage34 , checkBoxImage35 ,
checkBoxImage36 , checkBoxImage37 , checkBoxImage38 , checkBoxImage39 , checkBoxImage40 ,
checkBoxImage41 , checkBoxImage42 , checkBoxImage43 , checkBoxImage44 , checkBoxImage45 ,
checkBoxImage46 , checkBoxImage47 , checkBoxImage48 ,
} ;
for ( int i = 0 ; i < 48 ; i + + )
{
2021-08-19 11:49:25 +00:00
int wmNr0 = ckbIndex [ i ] ;
if ( wmNr0 > = 0 )
2021-07-16 15:57:55 +00:00
{
2021-08-19 11:49:25 +00:00
chkBoxes [ i ] . Checked = ckbState [ wmNr0 ] = ( ( state & ( 1L < < wmNr0 ) ) ! = 0 ) ;
2021-07-16 15:57:55 +00:00
}
2017-11-03 09:57:30 +00:00
}
}
private void saveButton_Click ( object sender , EventArgs e )
{
2021-07-15 08:31:32 +00:00
Program . LocalSettings . OptoHeadsEnabled = GetCheckBoxStates ( ) ;
2021-08-19 11:49:25 +00:00
Program . LocalSettings . Save ( ) ;
2017-11-03 09:57:30 +00:00
DialogResult = DialogResult . OK ;
Close ( ) ;
2018-08-30 13:40:27 +00:00
}
#endregion
2018-09-06 15:27:35 +00:00
private void iPerlCommunicationForm_FormClosing ( object sender , FormClosingEventArgs e )
{
2018-09-18 13:23:49 +00:00
if ( ! forcedClose & & ! formCompleted & & ! checkBoxesEditMode )
2018-09-11 09:31:00 +00:00
{
e . Cancel = true ;
}
2018-09-06 15:27:35 +00:00
}
2015-08-11 06:50:32 +00:00
}
}