iPerlCommunicationSeq/Form: 'Get default Q2 corrections' and 'Write default Q2 corrections' activities, ver. 2.26.1456

This commit is contained in:
Milan Hanajik 2020-04-27 12:24:54 +02:00
parent f16f5f9544
commit 8cffe8328f
14 changed files with 523 additions and 106 deletions

View File

@ -41,6 +41,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="SerializableDictionary.cs" />
<Compile Include="UIControls\CoolButtonCtrl.cs">
<SubType>UserControl</SubType>
</Compile>

View File

@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
namespace Common
{
[XmlRoot("dictionary")]
public class SerializableDictionary<TKey, TValue>
: Dictionary<TKey, TValue>, IXmlSerializable
{
public System.Xml.Schema.XmlSchema GetSchema()
{
return null;
}
public void ReadXml(System.Xml.XmlReader reader)
{
XmlSerializer keySerializer = new XmlSerializer(typeof(TKey));
XmlSerializer valueSerializer = new XmlSerializer(typeof(TValue));
bool wasEmpty = reader.IsEmptyElement;
reader.Read();
if (wasEmpty)
return;
while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
{
reader.ReadStartElement("item");
reader.ReadStartElement("key");
TKey key = (TKey)keySerializer.Deserialize(reader);
reader.ReadEndElement();
reader.ReadStartElement("value");
TValue value = (TValue)valueSerializer.Deserialize(reader);
reader.ReadEndElement();
this.Add(key, value);
reader.ReadEndElement();
reader.MoveToContent();
}
reader.ReadEndElement();
}
public void WriteXml(System.Xml.XmlWriter writer)
{
XmlSerializer keySerializer = new XmlSerializer(typeof(TKey));
XmlSerializer valueSerializer = new XmlSerializer(typeof(TValue));
foreach (TKey key in this.Keys)
{
writer.WriteStartElement("item");
writer.WriteStartElement("key");
keySerializer.Serialize(writer, key);
writer.WriteEndElement();
writer.WriteStartElement("value");
TValue value = this[key];
valueSerializer.Serialize(writer, value);
writer.WriteEndElement();
writer.WriteEndElement();
}
}
}
}

View File

@ -8,7 +8,7 @@ using Config.Entities;
namespace TBF.BenchControl.TestMethods.Q2CorrectionFromHistory
{
public class Component : ComponentBase, GenericDevices.ISimultTestMethod, GenericDevices.ITestMethod
public class Component : ComponentBase, GenericDevices.ISimultTestMethod
{
private static readonly ILog log = LogManager.GetLogger(typeof(Component));
public override string ToString() { return string.Format("TestMethods.GrabImage({0})", Cfg.ToString(1)); }
@ -41,11 +41,14 @@ namespace TBF.BenchControl.TestMethods.Q2CorrectionFromHistory
{
if (args.Command == CfgChangeCmd.CfgChange)
{
cfg.UseWebService = tmpcfg.UseWebService;
cfg.BaseUrl = tmpcfg.BaseUrl;
cfg.RelativeUrl = tmpcfg.RelativeUrl;
cfg.UseLocalDB = tmpcfg.UseLocalDB;
cfg.ProcedureName = tmpcfg.ProcedureName;
cfg.ProcedureNameAlt1 = tmpcfg.ProcedureNameAlt1;
cfg.ProcedureNameAlt2 = tmpcfg.ProcedureNameAlt2;
cfg.UseWebService = tmpcfg.UseWebService;
cfg.UseDefaultValues = tmpcfg.UseDefaultValues;
}
}
};
@ -68,7 +71,7 @@ namespace TBF.BenchControl.TestMethods.Q2CorrectionFromHistory
public IList<Event> Execute(Test test, int repetitionNr, bool isLastRepetition)
{
return (new FromHistorySeq()).Execute(test, repetitionNr, isLastRepetition, cfg);
return (new FromHistorySeq()).Execute(test, repetitionNr, cfg);
}
}
}

View File

@ -36,8 +36,8 @@ namespace TBF.BenchControl.TestMethods.Q2CorrectionFromHistory
ParentName = string.Empty;
UseWebService = false;
BaseUrl = "https://tludockerhost1:5011/api/";
RelativeUrl = "q2correction";
BaseUrl = "https://api-operations.pemek.sms-esaap.com/core/metrology/";
RelativeUrl = "q2correction/Locations/4/Wztyp/{0}";
UseLocalDB = true;
ProcedureName = "iPERL Smart Suez DN15 Q3_2.5 R800";
ProcedureNameAlt1 = "iPERL Suez DN15 Q3_2.5 R800";

View File

@ -17,7 +17,7 @@ namespace TBF.BenchControl.TestMethods.Q2CorrectionFromHistory
private static readonly ILog log = LogManager.GetLogger(typeof(FromHistorySeq));
public IList<Event> Execute(Config.Entities.Test test, int repetitionNr, bool isLastRepetition, FromHistoryCfg cfg)
public IList<Event> Execute(Config.Entities.Test test, int repetitionNr, FromHistoryCfg cfg)
{
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, 1, Config.Entities.Progress.Test));

View File

@ -1,6 +1,5 @@
///
/// Copyright (c) 2015-2016 Sensus Metering Systems
/// Author: Milan Hanajík
/// Copyright (c) 2015-2020 Sensus Slovensko a.s.
///
using System;
using System.IO.Ports;
@ -26,6 +25,41 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
public bool SimultWithPrevious { get { return testMethodCfg.TestParams.SimultWithPrevious; } }
public bool SimultWithNext { get { return testMethodCfg.TestParams.SimultWithNext; } }
#region Configuration Change Handling
public static void OnCfgChange(object sender, CfgChangeArgs args)
{
if (CfgChangeHandler == null) return;
try { CfgChangeHandler(sender, args); }
catch (Exception e) { log.Error("CfgChangeHandler(...) failed", e); }
}
public static event EventHandler<CfgChangeArgs> CfgChangeHandler;
public override void StartChangeHandler()
{
CfgChangeHandler += delegate(object sender, CfgChangeArgs args)
{
TestMethodCfg tmpCfg = args.Cfg as TestMethodCfg;
if (tmpCfg != null && tmpCfg.Name.Equals(Name))
{
if (args.Command == CfgChangeCmd.CfgChange)
{
testMethodCfg.CommTimeout = tmpCfg.CommTimeout;
testMethodCfg.DelayBetweenRetries = tmpCfg.DelayBetweenRetries;
testMethodCfg.MaxCommRetries = tmpCfg.MaxCommRetries;
testMethodCfg.IperlCheckErrorsToStop = tmpCfg.IperlCheckErrorsToStop;
testMethodCfg.UseWebService = tmpCfg.UseWebService;
testMethodCfg.BaseUrl = tmpCfg.BaseUrl;
testMethodCfg.RelativeUrl = tmpCfg.RelativeUrl;
}
}
};
}
#endregion Configuration Change Handling
public TestMethod()
{
}
@ -34,9 +68,11 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
: base(cfg)
{
testMethodCfg = cfg as TestMethodCfg;
StartChangeHandler();
log.Debug(this.ToString());
}
/// IDevice interface - only Initialize() is used
public void Initialize()
{
if (DebugLevel == DebugMode.Normal)
@ -74,8 +110,9 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
rfidDataLogger.Fatal("------------------------------------------------------------------------");
rfidDataLogger.FatalFormat("Test Bench Framework ver. {0}", Program.Version);
}
}
/// IDevice interface - only Initialize() is used
public void RunDeviceBefore() { }
public void RunDeviceAfter() { }
public void StopDevice() { }

View File

@ -30,7 +30,9 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
public int RfidPortNrBoard3;
public int RfidPortNrBoard4;
public int IperlCheckErrorsToStop;
public bool UseWebService;
public string BaseUrl;
public string RelativeUrl;
/// <summary> Test parameters </summary>
[XmlIgnore]

View File

@ -1,5 +1,5 @@
///
/// Copyright (c) 2015-2019 Sensus Slovensko a.s.
/// Copyright (c) 2015-2020 Sensus Slovensko a.s.
///
using System;
using System.Windows.Forms;
@ -9,7 +9,7 @@ using TBF.Resources;
namespace TBF.BenchControl.TestMethods.iPerlCommunication
{
public partial class TestMethodCfgCtrl : UserControl, IComponentCfgCtrl
public partial class TestMethodCfgCtrl : Configs.ConfigCtrlUtils, IComponentCfgCtrl
{
public bool ShowMore { get { return false; } }
@ -53,7 +53,10 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
delayBetweenRetriesTextBox.Text = config.DelayBetweenRetries.ToString();
nrThreadsTextBox.Text = config.NrThreads.ToString();
iperlCheckErrorsToStopTextBox.Text = config.IperlCheckErrorsToStop.ToString();
}
useWebServiceCheckBox.Checked = config.UseWebService;
baseUrlTextBox.Text = config.BaseUrl;
relativeUrlTextBox.Text = config.RelativeUrl;
}
public void Unlock()
{
@ -68,7 +71,10 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
delayBetweenRetriesTextBox.Enabled = true;
nrThreadsTextBox.Enabled = true;
iperlCheckErrorsToStopTextBox.Enabled = true;
}
useWebServiceCheckBox.Enabled = true;
baseUrlTextBox.Enabled = true;
relativeUrlTextBox.Enabled = true;
}
public CfgUpdateFlags VerifyCfg(ref string message)
{
@ -126,42 +132,38 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
public CfgUpdateFlags UpdateCfg()
{
CfgUpdateFlags flags = CfgUpdateFlags.None; /// <------------------- !!!
CfgUpdateFlags flags = CfgUpdateFlags.None;
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
if (config.Name != nameTextBox.Text) { config.Name = nameTextBox.Text; flags = CfgUpdateFlags.RestartRqrd; }
if (config.Name != nameTextBox.Text)
{
config.Name = nameTextBox.Text;
flags |= (CfgUpdateFlags.AnyChange | CfgUpdateFlags.RestartRqrd);
}
int tmp = int.Parse(rfidPortBoard1TextBox.Text);
if (config.RfidPortNrBoard1 != tmp) { config.RfidPortNrBoard1 = tmp; flags = CfgUpdateFlags.RestartRqrd; }
tmp = int.Parse(rfidPortBoard2TextBox.Text);
if (config.RfidPortNrBoard2 != tmp) { config.RfidPortNrBoard2 = tmp; flags = CfgUpdateFlags.RestartRqrd; }
tmp = int.Parse(rfidPortBoard3TextBox.Text);
if (config.RfidPortNrBoard3 != tmp) { config.RfidPortNrBoard3 = tmp; flags = CfgUpdateFlags.RestartRqrd; }
tmp = int.Parse(rfidPortBoard4TextBox.Text);
if (config.RfidPortNrBoard4 != tmp) { config.RfidPortNrBoard4 = tmp; flags = CfgUpdateFlags.RestartRqrd; }
flags |= UpdateDifferent(ref config.CommTimeout, commTimeoutTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref config.MaxCommRetries, maxCommRetriesTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref config.DelayBetweenRetries, delayBetweenRetriesTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref config.IperlCheckErrorsToStop, iperlCheckErrorsToStopTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref config.UseWebService, useWebServiceCheckBox.Checked, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref config.BaseUrl, baseUrlTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref config.RelativeUrl, relativeUrlTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
tmp = int.Parse(commTimeoutTextBox.Text);
if (config.CommTimeout != tmp) { config.CommTimeout = tmp; flags = CfgUpdateFlags.RestartRqrd; }
flags |= UpdateDifferent(ref config.NrThreads, nrThreadsTextBox.Text, CfgUpdateFlags.RestartRqrd | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref config.UseMuxBoards, useMuxBrdsCheckBox.Checked, CfgUpdateFlags.RestartRqrd | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref config.RfidPortNrBoard1, rfidPortBoard1TextBox.Text, CfgUpdateFlags.RestartRqrd | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref config.RfidPortNrBoard2, rfidPortBoard2TextBox.Text, CfgUpdateFlags.RestartRqrd | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref config.RfidPortNrBoard3, rfidPortBoard3TextBox.Text, CfgUpdateFlags.RestartRqrd | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref config.RfidPortNrBoard4, rfidPortBoard4TextBox.Text, CfgUpdateFlags.RestartRqrd | CfgUpdateFlags.AnyChange);
tmp = int.Parse(maxCommRetriesTextBox.Text);
if (config.MaxCommRetries != tmp) { config.MaxCommRetries = tmp; flags = CfgUpdateFlags.RestartRqrd; }
tmp = int.Parse(delayBetweenRetriesTextBox.Text);
if (config.DelayBetweenRetries != tmp) { config.DelayBetweenRetries = tmp; flags = CfgUpdateFlags.RestartRqrd; }
tmp = int.Parse(nrThreadsTextBox.Text);
if (config.NrThreads != tmp) { config.NrThreads = tmp; flags = CfgUpdateFlags.RestartRqrd; }
if (config.UseMuxBoards != useMuxBrdsCheckBox.Checked) { config.UseMuxBoards = useMuxBrdsCheckBox.Checked; flags = CfgUpdateFlags.RestartRqrd; }
tmp = int.Parse(iperlCheckErrorsToStopTextBox.Text);
if (config.IperlCheckErrorsToStop != tmp) { config.IperlCheckErrorsToStop = tmp; flags = CfgUpdateFlags.RestartRqrd; }
return flags;
if ((flags & CfgUpdateFlags.InvokeCfgChange) != 0)
{
TestMethod.OnCfgChange(this, new CfgChangeArgs(CfgChangeCmd.CfgChange, config));
}
return flags;
}
}
}

View File

@ -55,13 +55,18 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
this.iperlCheckErrorsToStopLabel = new System.Windows.Forms.Label();
this.delayBetweenRetriesTextBox = new System.Windows.Forms.TextBox();
this.delayBetweenRetriesLabel = new System.Windows.Forms.Label();
this.relativeUrlTextBox = new System.Windows.Forms.TextBox();
this.relativeUrlLabel = new System.Windows.Forms.Label();
this.baseUrlTextBox = new System.Windows.Forms.TextBox();
this.baseUrlLabel = new System.Windows.Forms.Label();
this.useWebServiceCheckBox = new System.Windows.Forms.CheckBox();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// nameTextBox
//
this.nameTextBox.Enabled = false;
this.nameTextBox.Location = new System.Drawing.Point(165, 25);
this.nameTextBox.Location = new System.Drawing.Point(88, 31);
this.nameTextBox.Name = "nameTextBox";
this.nameTextBox.Size = new System.Drawing.Size(130, 20);
this.nameTextBox.TabIndex = 2;
@ -69,7 +74,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
// nameLabel
//
this.nameLabel.AutoSize = true;
this.nameLabel.Location = new System.Drawing.Point(23, 28);
this.nameLabel.Location = new System.Drawing.Point(23, 34);
this.nameLabel.Name = "nameLabel";
this.nameLabel.Size = new System.Drawing.Size(35, 13);
this.nameLabel.TabIndex = 1;
@ -78,7 +83,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
// classNameLabel
//
this.classNameLabel.AutoSize = true;
this.classNameLabel.Location = new System.Drawing.Point(164, 7);
this.classNameLabel.Location = new System.Drawing.Point(24, 7);
this.classNameLabel.Name = "classNameLabel";
this.classNameLabel.Size = new System.Drawing.Size(83, 13);
this.classNameLabel.TabIndex = 0;
@ -87,7 +92,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
// rfidPortBoard1TextBox
//
this.rfidPortBoard1TextBox.Enabled = false;
this.rfidPortBoard1TextBox.Location = new System.Drawing.Point(289, 20);
this.rfidPortBoard1TextBox.Location = new System.Drawing.Point(130, 38);
this.rfidPortBoard1TextBox.Name = "rfidPortBoard1TextBox";
this.rfidPortBoard1TextBox.Size = new System.Drawing.Size(45, 20);
this.rfidPortBoard1TextBox.TabIndex = 2;
@ -95,7 +100,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
// rfidPortBoard1Label
//
this.rfidPortBoard1Label.AutoSize = true;
this.rfidPortBoard1Label.Location = new System.Drawing.Point(171, 23);
this.rfidPortBoard1Label.Location = new System.Drawing.Point(12, 41);
this.rfidPortBoard1Label.Name = "rfidPortBoard1Label";
this.rfidPortBoard1Label.Size = new System.Drawing.Size(96, 13);
this.rfidPortBoard1Label.TabIndex = 1;
@ -104,7 +109,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
// rfidPortBoard2TextBox
//
this.rfidPortBoard2TextBox.Enabled = false;
this.rfidPortBoard2TextBox.Location = new System.Drawing.Point(289, 42);
this.rfidPortBoard2TextBox.Location = new System.Drawing.Point(130, 60);
this.rfidPortBoard2TextBox.Name = "rfidPortBoard2TextBox";
this.rfidPortBoard2TextBox.Size = new System.Drawing.Size(45, 20);
this.rfidPortBoard2TextBox.TabIndex = 4;
@ -112,7 +117,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
// rfidPortBoard2Label
//
this.rfidPortBoard2Label.AutoSize = true;
this.rfidPortBoard2Label.Location = new System.Drawing.Point(171, 45);
this.rfidPortBoard2Label.Location = new System.Drawing.Point(12, 63);
this.rfidPortBoard2Label.Name = "rfidPortBoard2Label";
this.rfidPortBoard2Label.Size = new System.Drawing.Size(96, 13);
this.rfidPortBoard2Label.TabIndex = 3;
@ -121,7 +126,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
// rfidPortBoard3TextBox
//
this.rfidPortBoard3TextBox.Enabled = false;
this.rfidPortBoard3TextBox.Location = new System.Drawing.Point(289, 64);
this.rfidPortBoard3TextBox.Location = new System.Drawing.Point(130, 82);
this.rfidPortBoard3TextBox.Name = "rfidPortBoard3TextBox";
this.rfidPortBoard3TextBox.Size = new System.Drawing.Size(45, 20);
this.rfidPortBoard3TextBox.TabIndex = 6;
@ -129,7 +134,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
// rfidPortBoard3Label
//
this.rfidPortBoard3Label.AutoSize = true;
this.rfidPortBoard3Label.Location = new System.Drawing.Point(171, 67);
this.rfidPortBoard3Label.Location = new System.Drawing.Point(12, 85);
this.rfidPortBoard3Label.Name = "rfidPortBoard3Label";
this.rfidPortBoard3Label.Size = new System.Drawing.Size(96, 13);
this.rfidPortBoard3Label.TabIndex = 5;
@ -138,7 +143,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
// rfidPortBoard4TextBox
//
this.rfidPortBoard4TextBox.Enabled = false;
this.rfidPortBoard4TextBox.Location = new System.Drawing.Point(289, 86);
this.rfidPortBoard4TextBox.Location = new System.Drawing.Point(130, 104);
this.rfidPortBoard4TextBox.Name = "rfidPortBoard4TextBox";
this.rfidPortBoard4TextBox.Size = new System.Drawing.Size(45, 20);
this.rfidPortBoard4TextBox.TabIndex = 8;
@ -146,7 +151,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
// rfidPortBoard4Label
//
this.rfidPortBoard4Label.AutoSize = true;
this.rfidPortBoard4Label.Location = new System.Drawing.Point(171, 89);
this.rfidPortBoard4Label.Location = new System.Drawing.Point(12, 107);
this.rfidPortBoard4Label.Name = "rfidPortBoard4Label";
this.rfidPortBoard4Label.Size = new System.Drawing.Size(96, 13);
this.rfidPortBoard4Label.TabIndex = 7;
@ -155,7 +160,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
// commTimeoutTextBox
//
this.commTimeoutTextBox.Enabled = false;
this.commTimeoutTextBox.Location = new System.Drawing.Point(165, 47);
this.commTimeoutTextBox.Location = new System.Drawing.Point(173, 53);
this.commTimeoutTextBox.Name = "commTimeoutTextBox";
this.commTimeoutTextBox.Size = new System.Drawing.Size(45, 20);
this.commTimeoutTextBox.TabIndex = 4;
@ -163,7 +168,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
// commTimeoutLabel
//
this.commTimeoutLabel.AutoSize = true;
this.commTimeoutLabel.Location = new System.Drawing.Point(23, 50);
this.commTimeoutLabel.Location = new System.Drawing.Point(23, 56);
this.commTimeoutLabel.Name = "commTimeoutLabel";
this.commTimeoutLabel.Size = new System.Drawing.Size(98, 13);
this.commTimeoutLabel.TabIndex = 3;
@ -172,7 +177,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
// maxCommRetriesTextBox
//
this.maxCommRetriesTextBox.Enabled = false;
this.maxCommRetriesTextBox.Location = new System.Drawing.Point(165, 69);
this.maxCommRetriesTextBox.Location = new System.Drawing.Point(173, 75);
this.maxCommRetriesTextBox.Name = "maxCommRetriesTextBox";
this.maxCommRetriesTextBox.Size = new System.Drawing.Size(45, 20);
this.maxCommRetriesTextBox.TabIndex = 6;
@ -180,7 +185,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
// maxNrRetriesLabel
//
this.maxNrRetriesLabel.AutoSize = true;
this.maxNrRetriesLabel.Location = new System.Drawing.Point(23, 72);
this.maxNrRetriesLabel.Location = new System.Drawing.Point(23, 78);
this.maxNrRetriesLabel.Name = "maxNrRetriesLabel";
this.maxNrRetriesLabel.Size = new System.Drawing.Size(61, 13);
this.maxNrRetriesLabel.TabIndex = 5;
@ -189,7 +194,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
// nrThreadsTextBox
//
this.nrThreadsTextBox.Enabled = false;
this.nrThreadsTextBox.Location = new System.Drawing.Point(165, 113);
this.nrThreadsTextBox.Location = new System.Drawing.Point(173, 119);
this.nrThreadsTextBox.Name = "nrThreadsTextBox";
this.nrThreadsTextBox.Size = new System.Drawing.Size(45, 20);
this.nrThreadsTextBox.TabIndex = 10;
@ -197,7 +202,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
// nrThreadsLabel
//
this.nrThreadsLabel.AutoSize = true;
this.nrThreadsLabel.Location = new System.Drawing.Point(23, 116);
this.nrThreadsLabel.Location = new System.Drawing.Point(23, 122);
this.nrThreadsLabel.Name = "nrThreadsLabel";
this.nrThreadsLabel.Size = new System.Drawing.Size(59, 13);
this.nrThreadsLabel.TabIndex = 9;
@ -207,7 +212,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
//
this.useMuxBrdsCheckBox.AutoSize = true;
this.useMuxBrdsCheckBox.Enabled = false;
this.useMuxBrdsCheckBox.Location = new System.Drawing.Point(15, 22);
this.useMuxBrdsCheckBox.Location = new System.Drawing.Point(15, 18);
this.useMuxBrdsCheckBox.Name = "useMuxBrdsCheckBox";
this.useMuxBrdsCheckBox.Size = new System.Drawing.Size(132, 17);
this.useMuxBrdsCheckBox.TabIndex = 0;
@ -225,17 +230,17 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
this.groupBox1.Controls.Add(this.rfidPortBoard3TextBox);
this.groupBox1.Controls.Add(this.rfidPortBoard4Label);
this.groupBox1.Controls.Add(this.rfidPortBoard4TextBox);
this.groupBox1.Location = new System.Drawing.Point(26, 142);
this.groupBox1.Location = new System.Drawing.Point(231, 7);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(363, 117);
this.groupBox1.Size = new System.Drawing.Size(184, 134);
this.groupBox1.TabIndex = 11;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Multiplexer boards connected to USB ports";
this.groupBox1.Text = "Mux. boards connected via USB";
//
// iperlCheckErrorsToStopTextBox
//
this.iperlCheckErrorsToStopTextBox.Enabled = false;
this.iperlCheckErrorsToStopTextBox.Location = new System.Drawing.Point(239, 267);
this.iperlCheckErrorsToStopTextBox.Location = new System.Drawing.Point(361, 152);
this.iperlCheckErrorsToStopTextBox.Name = "iperlCheckErrorsToStopTextBox";
this.iperlCheckErrorsToStopTextBox.Size = new System.Drawing.Size(45, 20);
this.iperlCheckErrorsToStopTextBox.TabIndex = 13;
@ -243,7 +248,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
// iperlCheckErrorsToStopLabel
//
this.iperlCheckErrorsToStopLabel.AutoSize = true;
this.iperlCheckErrorsToStopLabel.Location = new System.Drawing.Point(23, 270);
this.iperlCheckErrorsToStopLabel.Location = new System.Drawing.Point(23, 155);
this.iperlCheckErrorsToStopLabel.Name = "iperlCheckErrorsToStopLabel";
this.iperlCheckErrorsToStopLabel.Size = new System.Drawing.Size(202, 13);
this.iperlCheckErrorsToStopLabel.TabIndex = 12;
@ -252,7 +257,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
// delayBetweenRetriesTextBox
//
this.delayBetweenRetriesTextBox.Enabled = false;
this.delayBetweenRetriesTextBox.Location = new System.Drawing.Point(165, 91);
this.delayBetweenRetriesTextBox.Location = new System.Drawing.Point(173, 97);
this.delayBetweenRetriesTextBox.Name = "delayBetweenRetriesTextBox";
this.delayBetweenRetriesTextBox.Size = new System.Drawing.Size(45, 20);
this.delayBetweenRetriesTextBox.TabIndex = 8;
@ -260,16 +265,66 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
// delayBetweenRetriesLabel
//
this.delayBetweenRetriesLabel.AutoSize = true;
this.delayBetweenRetriesLabel.Location = new System.Drawing.Point(23, 94);
this.delayBetweenRetriesLabel.Location = new System.Drawing.Point(23, 100);
this.delayBetweenRetriesLabel.Name = "delayBetweenRetriesLabel";
this.delayBetweenRetriesLabel.Size = new System.Drawing.Size(131, 13);
this.delayBetweenRetriesLabel.TabIndex = 7;
this.delayBetweenRetriesLabel.Text = "Delay between retries [ms]";
//
// relativeUrlTextBox
//
this.relativeUrlTextBox.Enabled = false;
this.relativeUrlTextBox.Location = new System.Drawing.Point(108, 229);
this.relativeUrlTextBox.Name = "relativeUrlTextBox";
this.relativeUrlTextBox.Size = new System.Drawing.Size(298, 20);
this.relativeUrlTextBox.TabIndex = 18;
//
// relativeUrlLabel
//
this.relativeUrlLabel.AutoSize = true;
this.relativeUrlLabel.Location = new System.Drawing.Point(24, 232);
this.relativeUrlLabel.Name = "relativeUrlLabel";
this.relativeUrlLabel.Size = new System.Drawing.Size(71, 13);
this.relativeUrlLabel.TabIndex = 17;
this.relativeUrlLabel.Text = "Relative URL";
//
// baseUrlTextBox
//
this.baseUrlTextBox.Enabled = false;
this.baseUrlTextBox.Location = new System.Drawing.Point(108, 206);
this.baseUrlTextBox.Name = "baseUrlTextBox";
this.baseUrlTextBox.Size = new System.Drawing.Size(298, 20);
this.baseUrlTextBox.TabIndex = 16;
//
// baseUrlLabel
//
this.baseUrlLabel.AutoSize = true;
this.baseUrlLabel.Location = new System.Drawing.Point(24, 209);
this.baseUrlLabel.Name = "baseUrlLabel";
this.baseUrlLabel.Size = new System.Drawing.Size(56, 13);
this.baseUrlLabel.TabIndex = 15;
this.baseUrlLabel.Text = "Base URL";
//
// useWebServiceCheckBox
//
this.useWebServiceCheckBox.AutoSize = true;
this.useWebServiceCheckBox.Enabled = false;
this.useWebServiceCheckBox.Location = new System.Drawing.Point(25, 184);
this.useWebServiceCheckBox.Name = "useWebServiceCheckBox";
this.useWebServiceCheckBox.Size = new System.Drawing.Size(189, 17);
this.useWebServiceCheckBox.TabIndex = 14;
this.useWebServiceCheckBox.Text = "Use web service for default values";
this.useWebServiceCheckBox.UseVisualStyleBackColor = true;
//
// TestMethodCfgCtrl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.relativeUrlTextBox);
this.Controls.Add(this.relativeUrlLabel);
this.Controls.Add(this.baseUrlTextBox);
this.Controls.Add(this.baseUrlLabel);
this.Controls.Add(this.useWebServiceCheckBox);
this.Controls.Add(this.delayBetweenRetriesTextBox);
this.Controls.Add(this.delayBetweenRetriesLabel);
this.Controls.Add(this.iperlCheckErrorsToStopTextBox);
@ -319,5 +374,10 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
private System.Windows.Forms.Label iperlCheckErrorsToStopLabel;
private System.Windows.Forms.TextBox delayBetweenRetriesTextBox;
private System.Windows.Forms.Label delayBetweenRetriesLabel;
private System.Windows.Forms.TextBox relativeUrlTextBox;
private System.Windows.Forms.Label relativeUrlLabel;
private System.Windows.Forms.TextBox baseUrlTextBox;
private System.Windows.Forms.Label baseUrlLabel;
private System.Windows.Forms.CheckBox useWebServiceCheckBox;
}
}

View File

@ -1,5 +1,5 @@
///
/// Copyright (c) 2015-2019 Sensus Slovensko a.s.
/// Copyright (c) 2015-2020 Sensus Slovensko a.s.
///
//#define VERIFY_ACTIVE_MODE
//#define VERIFY_Q2_CORR_RESET
@ -65,9 +65,11 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
public const string WriteCalibrationV4FactorsStr = "Write calibration_V4";
public const string NormalizeCalibrationFactorStr = "Normalize calibration factor";
public const string NormalizeCalibrationV4FactorsStr = "Normalize calibration_V4";
public const string GetDefaultQ2CorrectionsStr = "Get default Q2 corrections";
public const string ReadQ2CorrectionStr = "Read Q2 corrections";
public const string ResetQ2CorrectionStr = "Reset Q2 correction";
public const string InitOrReadQ2CorrectionStr = "Init or read Q2 corrections";
public const string WriteDefaultQ2CorrectionsStr = "Write default Q2 corrections";
public const string InitOrReadQ2CorrectionsStr = "Init or read Q2 corrections";
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
@ -339,6 +341,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
static IList<IperlHead> iperlHeads;
static IList<int> waterMeterPositions0; /// keeps original 0-based indices in RegisterReaders list
static int commonWMType;
Modbus.QuidoRS.QuidoRS quido;
@ -409,13 +412,23 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
{
ProcessData.RegisterReaders = StateMachine.GetMetersPath(tests[0]).RegisterReaders;
activityLabel.Text = multiTestParams[0].Activity;
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;
}
}
}
ConstructorCommon();
PrepareForTestsActivities();
}
void ConstructorCommon()
void PrepareForTestsActivities()
{
startTime = DateTime.Now;
startTimeSec = StateMachine.Time;
@ -494,7 +507,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
workerThreads = new List<Thread>();
for (int i = 0; i < cfg.NrThreads; i++)
{
Thread thread = new Thread(iPerlCommunicationForm.Worker);
Thread thread = new Thread(Worker);
thread.CurrentCulture = CultureInfo.CurrentCulture;
thread.CurrentUICulture = CultureInfo.CurrentUICulture;
workerThreads.Add(thread);
@ -633,37 +646,46 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
{
Localize();
for (int i = 0; i < textBoxesCount; i++)
///
/// Set checkbox states accroding to iPerlHeads[i].Disabled states
///
for (int i = 0; i < textBoxesCount; i++)
{
labels[i].Visible = counters[i].Visible = messages[i].Visible = checkBoxes[i].Visible = true;
if (!checkBoxesEditMode && (iperlHeads[i] == null || iperlHeads[i].Disabled))
{
/// iPerl position i+1 is disabled
checkBoxes[i].Enabled = checkBoxes[i].Checked = ckbState[i] = false;
counters[i].BackColor = DisabledColor;
messages[i].Text = Strings.Head_was_disabled_by_the_user;
}
else
{
/// iPerl position i+1 is enabled
checkBoxes[i].Enabled = checkBoxes[i].Checked = ckbState[i] = true;
messages[i].Text = "---";
}
}
TBF.LocalSettings ls = Program.LocalSettings;
///
/// Set location and checkbox states to values stored in local settings
///
TBF.LocalSettings ls = Program.LocalSettings;
Left = (ls.iPerlCommunicationsFormLeft != 0) ? ls.iPerlCommunicationsFormLeft : 150;
Top = (ls.iPerlCommunicationsFormTop != 0) ? ls.iPerlCommunicationsFormTop : 150;
if (ls.iPerlCommunicationsFormCheckboxes != 0) SetCheckBoxStates(ls.iPerlCommunicationsFormCheckboxes);
if (!checkBoxesEditMode)
{
/// Regular activity (not a checkbox edit mode invoked from TBF menu)
/// Reset opto-data indication
for (int i = 0; i < iperlHeads.Count; i++)
{
counters[i].BackColor = OptoNokColor;
}
///
/// Set QuidoRS outputs and start the whole communication process
/// by incrementing 'currentGroup'.
///
@ -675,9 +697,11 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
currentGroup++;
/// Start worker threads
int wtId = 0;
foreach (var wt in workerThreads) wt.Start(new Boxes.IntBox(wtId++));
foreach (var wt in workerThreads)
{
wt.Start(new Boxes.IntBox(wtId++)); /// Start worker threads !!!
}
}
}
@ -743,7 +767,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
/// Worker thread
/// </summary>
/// <param name="threadData">Thread ID (integer) wrapped into IntBox</param>
static void Worker(object threadData)
void Worker(object threadData)
{
int threadID = (threadData as Boxes.IntBox).Val;
@ -821,24 +845,27 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
///
else if (wm == null) error = CommErr.CommFailed;
else if (currentActivity.ToLower().Contains(ReadConfigurationStr.ToLower())) error = ReadConfiguration(threadID, ihead, wm, ref resultStr);
else if (currentActivity.ToLower().Equals(ReadCalibrationStr.ToLower())) error = ReadCalibration(threadID, ihead, wm, ref resultStr);
else if (currentActivity.ToLower().Equals(ReadCalibrationV4Str.ToLower())) error = ReadCalibrationV4(threadID, ihead, wm, ref resultStr);
else if (currentActivity.ToLower() == ReadCalibrationStr.ToLower()) error = ReadCalibration(threadID, ihead, wm, ref resultStr);
else if (currentActivity.ToLower() == ReadCalibrationV4Str.ToLower()) error = ReadCalibrationV4(threadID, ihead, wm, ref resultStr);
else if (currentActivity.ToLower().Contains(WriteCalibrationFactorStr.ToLower())) error = WriteCalibrationFactor(threadID, ihead, wm, ref resultStr);
else if (currentActivity.ToLower().Contains(WriteCalibrationV4FactorsStr.ToLower())) error = WriteCalibrationV4Factors(threadID, ihead, wm, ref resultStr);
else if (currentActivity.ToLower().Equals(NormalizeCalibrationFactorStr.ToLower())) error = NormalizeCalibrationFactor(threadID, ihead, wm, ref resultStr);
else if (currentActivity.ToLower().Equals(NormalizeCalibrationV4FactorsStr.ToLower())) error = NormalizeCalibrationV4Factors(threadID, ihead, wm, ref resultStr);
else if (currentActivity.ToLower().Equals(ReadQ2CorrectionStr.ToLower())) error = ReadQ2Correction(threadID, ihead, wm, ref resultStr);
else if (currentActivity.ToLower().Equals(ResetQ2CorrectionStr.ToLower())) error = ResetQ2Correction(threadID, ihead, wm, ref resultStr);
else if (currentActivity.ToLower().Equals(InitOrReadQ2CorrectionStr.ToLower())) error = InitOrReadQ2Correction(threadID, ihead, wm, ref resultStr);
else if (currentActivity.ToLower().Equals(WriteQ2CorrectionStr.ToLower())) error = WriteQ2Correction(threadID, ihead, wm, currentTest, ref resultStr, Q2CorrType.Standard, null);
else if (currentActivity.ToLower().Equals(WriteQ2CorrectionAltStr.ToLower())) error = WriteQ2Correction(threadID, ihead, wm, currentTest, ref resultStr, Q2CorrType.Dewa, null);
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);
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);
else if (currentActivity.ToLower() == WriteQ2CorrectionStr.ToLower()) error = WriteQ2Correction(threadID, ihead, wm, currentTest, ref resultStr, Q2CorrType.Standard, null);
else if (currentActivity.ToLower() == WriteQ2CorrectionAltStr.ToLower()) error = WriteQ2Correction(threadID, ihead, wm, currentTest, ref resultStr, Q2CorrType.Dewa, null);
else if (currentActivity.ToLower().Contains(WriteQ2CorrectionGreeceStr.ToLower())) error = WriteQ2Correction(threadID, ihead, wm, currentTest, ref resultStr, Q2CorrType.Greece, currentActivity.Substring(WriteQ2CorrectionGreeceStr.Length).Trim());
else if (currentActivity.ToLower().Contains(WriteQ2CorrectionRLStr.ToLower())) error = WriteQ2Correction(threadID, ihead, wm, currentTest, ref resultStr, Q2CorrType.RL, currentActivity.Substring(WriteQ2CorrectionRLStr.Length).Trim());
else if (currentActivity.ToLower().Contains(WriteQ2CorrectionLRStr.ToLower())) error = WriteQ2Correction(threadID, ihead, wm, currentTest, ref resultStr, Q2CorrType.LR, currentActivity.Substring(WriteQ2CorrectionLRStr.Length).Trim());
else if (currentActivity.ToLower().Contains(UpdateQ2CorrectionsStr.ToLower())) error = WriteQ2Correction(threadID, ihead, wm, currentTest, ref resultStr, Q2CorrType.Update, currentActivity.Substring(UpdateQ2CorrectionsStr.Length).Trim());
else if (currentActivity.ToLower().Contains(ConditnlUpdateQ2CorrectionsStr.ToLower())) error = WriteQ2Correction(threadID, ihead, wm, currentTest, ref resultStr, Q2CorrType.ConditionalUpdate, currentActivity.Substring(ConditnlUpdateQ2CorrectionsStr.Length).Trim());
else if (currentActivity.ToLower().Equals(Reset2HzCorrectionStr.ToLower())) error = Reset2HzCorrection(threadID, ihead, wm, ref resultStr);
else if (currentActivity.ToLower().Equals(Write2HzCorrectionStr.ToLower())) error = Write2HzCorrection(threadID, ihead, wm, ref resultStr);
else if (currentActivity.ToLower() == Reset2HzCorrectionStr.ToLower()) error = Reset2HzCorrection(threadID, ihead, wm, ref resultStr);
else if (currentActivity.ToLower() == Write2HzCorrectionStr.ToLower()) error = Write2HzCorrection(threadID, ihead, wm, ref resultStr);
else if (currentActivity.ToLower() == GetDefaultQ2CorrectionsStr.ToLower()) error = GetQ2PreCorrectionsFormRest(threadID, ihead, wm, ref resultStr);
#endif
else
{
@ -1816,9 +1843,8 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
return error;
}
/// <summary>
/// Reset both Q2 correction factors in the memory to 0.
/// Reset both Q2 correction factors to 0.
/// Read them back to verify factors were written correctly.
/// </summary>
/// <param name="ihead">Water meter object</param>
@ -1826,17 +1852,39 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
/// <returns>true on success</returns>
static CommErr ResetQ2Correction(int threadId, IperlHead ihead, Results.Entities.WaterMeter wm, ref string resultStr)
{
return SetQ2Correction(threadId, ihead, wm, ref resultStr, 0, 0);
return WriteQ2Corrections(threadId, ihead, wm, ref resultStr, 0, 0);
}
/// <summary>
/// Reset both Q2 correction factors in the memory to 0.
/// 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;
if (TBF.BenchControl.Sequences.ProcessData.IsQ2PreCorrectionCalculated)
{
return WriteQ2Corrections(threadId, ihead, wm, ref resultStr, TBF.BenchControl.Sequences.ProcessData.CalculatedQ2PreCorrectionLR,
TBF.BenchControl.Sequences.ProcessData.CalculatedQ2PreCorrectionRL);
}
else
{
return WriteQ2Corrections(threadId, ihead, wm, ref resultStr, 0, 0);
}
}
/// <summary>
/// Write both Q2 correction factors to given values.
/// 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 SetQ2Correction(int threadId, IperlHead ihead, Results.Entities.WaterMeter wm, ref string resultStr, int factorLR, int factorRL)
static CommErr WriteQ2Corrections(int threadId, IperlHead ihead, Results.Entities.WaterMeter wm, ref string resultStr, int factorLR, int factorRL)
{
if (ihead.CommFailed) return CommErr.CommFailed;
@ -1899,7 +1947,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
}
static CommErr InitOrReadQ2Correction(int threadId, IperlHead ihead, Results.Entities.WaterMeter wm, ref string resultStr)
static CommErr InitOrReadQ2Corrections(int threadId, IperlHead ihead, Results.Entities.WaterMeter wm, ref string resultStr)
{
if (ihead.CommFailed) return CommErr.CommFailed;
@ -1907,12 +1955,12 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
{
if (TBF.BenchControl.Sequences.ProcessData.IsQ2PreCorrectionCalculated)
{
return SetQ2Correction(threadId, ihead, wm, ref resultStr, TBF.BenchControl.Sequences.ProcessData.CalculatedQ2PreCorrectionLR,
TBF.BenchControl.Sequences.ProcessData.CalculatedQ2PreCorrectionRL);
return WriteQ2Corrections(threadId, ihead, wm, ref resultStr, TBF.BenchControl.Sequences.ProcessData.CalculatedQ2PreCorrectionLR,
TBF.BenchControl.Sequences.ProcessData.CalculatedQ2PreCorrectionRL);
}
else
{
return SetQ2Correction(threadId, ihead, wm, ref resultStr, ihead.Q2PreCorrectionLR, ihead.Q2PreCorrectionRL);
return WriteQ2Corrections(threadId, ihead, wm, ref resultStr, ihead.Q2PreCorrectionLR, ihead.Q2PreCorrectionRL);
}
}
else
@ -2458,6 +2506,26 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
return error;
}
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;
}
#endif /// IPERL
#endregion
@ -2702,7 +2770,10 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
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; }
/// <summary>
/// Get states of checkboxes as one bitfield (long)
/// </summary>
/// <returns>Long bitfield</returns>
private long GetCheckBoxStates()
{
long result = 0;
@ -2713,6 +2784,9 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
return result;
}
/// <summary>
/// Set checkboxes to states stored in a bitfield (long)
/// </summary>
private void SetCheckBoxStates(long state)
{
CheckBoxImage[] chkBoxes = new CheckBoxImage[48]

View File

@ -51,9 +51,11 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
retVal.Add(iPerlCommunicationForm.ReadCalibrationV4Str);
retVal.Add(iPerlCommunicationForm.NormalizeCalibrationFactorStr);
retVal.Add(iPerlCommunicationForm.NormalizeCalibrationV4FactorsStr);
retVal.Add(iPerlCommunicationForm.GetDefaultQ2CorrectionsStr);
retVal.Add(iPerlCommunicationForm.ReadQ2CorrectionStr);
retVal.Add(iPerlCommunicationForm.ResetQ2CorrectionStr);
retVal.Add(iPerlCommunicationForm.InitOrReadQ2CorrectionStr);
retVal.Add(iPerlCommunicationForm.WriteDefaultQ2CorrectionsStr);
retVal.Add(iPerlCommunicationForm.InitOrReadQ2CorrectionsStr);
retVal.Add(iPerlCommunicationForm.WriteCalibrationFactorStr);
retVal.Add(iPerlCommunicationForm.WriteCalibrationV4FactorsStr);
retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionStr);

View File

@ -1,10 +1,12 @@
///
/// Copyright (c) 2015-2019 Sensus Slovensko a.s.
/// Copyright (c) 2015-2020 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using System.Drawing; /// Point definition
using log4net;
using Config.Entities;
using RestClient;
using TBF.BenchControl.Sequences;
using TBF.Resources;
using TBF.UiBridge;
@ -56,7 +58,58 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
const string Q2correctionCheckCmd = "q2 correction check ";
const string IperlCheckCmd = "iperl_check ";
if (testParams.Activity.ToLower().Contains(Q2correctedFromCmd))
if (testParams.Activity.ToLower().Equals(iPerlCommunicationForm.GetDefaultQ2CorrectionsStr.ToLower()))
{
TestProgressEventArgs.SetEstimatedTimes(new int[] { 0, 0, 0, 30, 0, 30, 0, 0 });
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, Config.Entities.Progress.JustStarted));
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, Config.Entities.Progress.FlowSetting));
/// Get 'wmType' from IperlHead procedure parameters
int wmType = 0;
if (IperlHeads != null)
{
foreach (var ih in IperlHeads)
{
if (ih.WMType_ID > 0)
{
wmType = ih.WMType_ID;
break;
}
}
}
IsQ2PreCorrectionCalculated = GetQ2PreCorrectionsOrBackups(cfg, wmType, out CalculatedQ2PreCorrectionLR, out CalculatedQ2PreCorrectionRL);
/// Generate test results
Results.Entities.TestRslt tstRslt = BatchRslts.GetTestRslt(test.Name, 0);
if (tstRslt != null)
{
tstRslt.StartTime = DateTime.Now;
tstRslt.TestDone = true;
foreach (var wm in BatchRslts.Batch.WaterMeters)
{
if (!wm.Disabled)
{
foreach(var mtr in wm.MeterTestRslts)
{
if (mtr.TestRslt == tstRslt)
{
mtr.Passed = IsQ2PreCorrectionCalculated;
mtr.TestDone = true;
break;
}
}
}
}
}
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, Config.Entities.Progress.Completed));
Bridge.OnTestCompleted(this, new TestCompletedEventArgs(test.Name, ProcessData.BatchRslts.GetTestRslt(test.Name, 0)));
allResults.Info(TestResult2CsvLine(test.Name, 0)); /// Append the results to the CSV-file
return new List<Event> { Event.Done };
}
else if (testParams.Activity.ToLower().Contains(Q2correctedFromCmd))
{
TestProgressEventArgs.SetEstimatedTimes(new int[] { 0, 0, 0, 30, 0, 30, 0, 0 });
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, Config.Entities.Progress.JustStarted));
@ -285,6 +338,114 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
return new List<Event> { Event.Done };
}
/// <summary>
/// Read default Q2 correction factors from a REST service (= Web service).
/// </summary>
/// <param name="cfg">iPerlCommunication component configuration</param>
/// <param name="wmType">Water meter type (WZ Typ)</param>
/// <param name="q2PreCorrectionLR">Default Q2 correction LR</param>
/// <param name="q2PreCorrectionRL">Default Q2 correction RL</param>
/// <returns>true when successful</returns>
static bool ReadCorrectionsFromWebService(TestMethodCfg cfg, int wmType, out int q2PreCorrectionLR, out int q2PreCorrectionRL)
{
if (wmType == 0)
{
/// No REST service call when wmType == 0, factors are 0
q2PreCorrectionLR = 0;
q2PreCorrectionRL = 0;
return true;
}
try
{
GetQ2PreCorrectionClient client = new GetQ2PreCorrectionClient(cfg.BaseUrl);
client.GetToken("ReadUser", "sensus", "https://sluprimadev/SensusCore/api/v1/Locations/1/Login2").Wait();
Q2PreCorrection response = client.GetQ2Correction(string.Format(cfg.RelativeUrl, wmType)).Result;
if (response != null && response.AreDataCalculated)
{
q2PreCorrectionLR = response.CorrLR;
q2PreCorrectionRL = response.CorrRL;
log.WarnFormat("Q2 corrections from a REST client for WM Type = {0} are: LR = {1}, RL = {2}", wmType, q2PreCorrectionLR, q2PreCorrectionRL);
return true;
}
else
{
log.ErrorFormat("Failed to obtain Q2 corrections from a REST client for WM Type = {0}", wmType);
q2PreCorrectionLR = 0;
q2PreCorrectionRL = 0;
return false;
}
}
catch (Exception exc)
{
log.ErrorFormat("Failed to obtain Q2 corrections from a REST client for WM Type = {0}: {1}", wmType, exc.Message);
q2PreCorrectionLR = 0;
q2PreCorrectionRL = 0;
return false;
}
}
/// <summary>
/// Obtain Q2 correction factors from a REST service or from local settings (stored backup values)
/// </summary>
/// <param name="cfg">iPerlCommunication component configuration</param>
/// <param name="wmType">Water meter type (WZ Typ)</param>
/// <param name="q2PreCorrectionLR">Default Q2 correction LR</param>
/// <param name="q2PreCorrectionRL">Default Q2 correction RL</param>
/// <returns>true when successful</returns>
public static bool GetQ2PreCorrectionsOrBackups(TestMethodCfg cfg, int wmType, out int q2PreCorrectionLR, out int q2PreCorrectionRL)
{
/// Get Q2 pre-correction values from REST service
bool restOK = ReadCorrectionsFromWebService(cfg, wmType, out q2PreCorrectionLR, out q2PreCorrectionRL);
/// Store / load Q2 pre-correction values
Point storedValue;
if (restOK)
{
/// Q2 pre-correction values were successfully obtained from a REST service for the specified wmType
if (!Program.LocalSettings.Q2PreCorrections.TryGetValue(wmType, out storedValue))
{
/// No Q2 pre-correction values in the dictionary for the specified wmType => save them
Program.LocalSettings.Q2PreCorrections.Add(wmType, new Point(q2PreCorrectionLR, q2PreCorrectionRL));
log.WarnFormat("Q2 corrections added to dictionary for WM Type = {0}: LR = {1}, RL = {2}", wmType, q2PreCorrectionLR, q2PreCorrectionRL);
}
else if (storedValue.X != q2PreCorrectionLR || storedValue.Y != q2PreCorrectionRL)
{
/// Different Q2 pre-correction values in the dictionary for the specified wmType => overwrite them with ones from the REST service
Program.LocalSettings.Q2PreCorrections[wmType] = new Point(q2PreCorrectionLR, q2PreCorrectionRL);
log.WarnFormat("Q2 corrections modified in dictionary for WM Type = {0}: LR = {1}, RL = {2}", wmType, q2PreCorrectionLR, q2PreCorrectionRL);
}
else
{
/// Q2 pre-correction values in the dictionary are the same and were not changed
log.WarnFormat("Q2 corrections in dictionary for WM Type = {0} are the same and were not changed", wmType, q2PreCorrectionLR, q2PreCorrectionRL);
}
}
else
{
/// No Q2 pre-correction values from a REST service => read the dictionary
if (Program.LocalSettings.Q2PreCorrections.TryGetValue(wmType, out storedValue))
{
/// Q2 pre-correction values successfully read from the dictionary
q2PreCorrectionLR = storedValue.X;
q2PreCorrectionRL = storedValue.Y;
log.WarnFormat("Q2 corrections loaded from dictionary for WM Type = {0}: LR = {1}, RL = {2}", wmType, q2PreCorrectionLR, q2PreCorrectionRL);
}
else
{
/// Q2 pre-correction values not found in the dictionary => use zeros
q2PreCorrectionLR = 0;
q2PreCorrectionRL = 0;
log.ErrorFormat("Q2 corrections not found in the dictionary for WM Type = {0}, using zeros", wmType, q2PreCorrectionLR, q2PreCorrectionRL);
/// Everything failed => using zero values
return false;
}
}
/// Q2 pre-corections were obtained from REST service or stored backup values were used
return true;
}
/// <summary>
/// Virtually apply Q2 correction to a test used for the correction calculation.

View File

@ -2,6 +2,7 @@
/// Copyright (c) 2013-2019 Sensus Slovensko a.s.
///
using System;
using System.Drawing;
using System.IO;
using System.Security.Cryptography;
using System.Text;
@ -204,7 +205,7 @@ namespace TBF
/// iPerlCommunicationsForm
public int iPerlCommunicationsFormLeft;
public int iPerlCommunicationsFormTop;
public long iPerlCommunicationsFormCheckboxes;
public long iPerlCommunicationsFormCheckboxes; /// Bit field with iPerlCommunicationForm checkboxes states
/// Serial numbers
public string[] LastSNTexts;
@ -274,6 +275,9 @@ namespace TBF
public bool Graph8_On;
public GraphLib.PlotterGraphPaneEx.LayoutMode GraphsLayoutMode;
/// Backup values of Q2 pre-corrections from REST services (point.X = LR, point.Y = RL)
public TracingDB.SerializableDictionary<int, Point> Q2PreCorrections;
[XmlArrayAttribute("RsltsClmnWidths")]
public int[] RsltsClmnWidths;
[XmlIgnore]
@ -290,6 +294,8 @@ namespace TBF
{
AlwaysAskPasswdWhenUnlocking = false;
RestoreUserWhenLeavingDialog = true;
Q2PreCorrections = new TracingDB.SerializableDictionary<int, Point>();
}
/// <summary>

View File

@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Build Number
// Revision
//
[assembly: AssemblyVersion("2.26.1453.0")]
[assembly: AssemblyFileVersion("2.26.1453.0")]
[assembly: AssemblyVersion("2.26.1456.0")]
[assembly: AssemblyFileVersion("2.26.1456.0")]