2015-08-11 06:50:32 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Copyright (c) 2015 Sensus Metering Systems
|
|
|
|
|
|
///
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using log4net;
|
|
|
|
|
|
using TBF.BenchControl;
|
|
|
|
|
|
using TBF.Boxes;
|
|
|
|
|
|
using TBF.Resources;
|
|
|
|
|
|
using TBF.UiBridge;
|
|
|
|
|
|
|
|
|
|
|
|
namespace TBF.BenchControl.TestMethods.iPerlCommunication
|
|
|
|
|
|
{
|
|
|
|
|
|
public class iPerlCommunicationSeq : Sequences.SequenceBase
|
|
|
|
|
|
{
|
|
|
|
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(iPerlCommunicationSeq));
|
|
|
|
|
|
|
2015-09-04 11:49:04 +00:00
|
|
|
|
|
2015-08-11 06:50:32 +00:00
|
|
|
|
System.Windows.Forms.Form modelessDlg;
|
|
|
|
|
|
///
|
2015-09-04 11:49:04 +00:00
|
|
|
|
delegate void iPerlCommFormDlgt(iPerlCommunicationSeq myRef, TestMethodCfg cfg, iPerlCommunicationParams testParams);
|
2015-08-11 06:50:32 +00:00
|
|
|
|
///
|
2015-09-04 11:49:04 +00:00
|
|
|
|
void OpenIPerlCommForm(iPerlCommunicationSeq myRef, TestMethodCfg cfg, iPerlCommunicationParams testParams)
|
2015-08-11 06:50:32 +00:00
|
|
|
|
{
|
2015-08-19 11:04:47 +00:00
|
|
|
|
IList<GenericDevices.IWaterMeter> wMtrs = new List<GenericDevices.IWaterMeter>();
|
|
|
|
|
|
foreach (var rr in sensPath.RegisterReaders)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (rr is GenericDevices.IWaterMeter) wMtrs.Add(rr as GenericDevices.IWaterMeter);
|
|
|
|
|
|
}
|
2015-09-04 11:49:04 +00:00
|
|
|
|
myRef.modelessDlg = new iPerlCommunicationForm(wMtrs, cfg, testParams);
|
|
|
|
|
|
myRef.modelessDlg.Show();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CloseIPerlCommForm()
|
|
|
|
|
|
{
|
|
|
|
|
|
UiBridge.Bridge.OnCloseModelessForm(this, null);
|
|
|
|
|
|
modelessDlg = null;
|
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>
|
|
|
|
|
|
/// Flying start mass collection method sequence
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="test">Test entity</param>
|
|
|
|
|
|
/// <returns>
|
|
|
|
|
|
/// Event.Done . . . . . . . OK
|
|
|
|
|
|
/// Event.UiCmdStop . . . . Stopped by the user using the on-screen button STOP
|
|
|
|
|
|
/// Event.OpArgumentError . Target flow is out of range
|
|
|
|
|
|
/// Event.Error . . . . . . Unspecified error
|
|
|
|
|
|
/// </returns>
|
2015-08-21 18:52:10 +00:00
|
|
|
|
public IList<Event> Execute(Entities.Test test, TestMethodCfg cfg, iPerlCommunicationParams testParams)
|
2015-08-11 06:50:32 +00:00
|
|
|
|
{
|
|
|
|
|
|
IList<Event> e = new List<Event>(); /// Events from currently running operations
|
|
|
|
|
|
Event retVal = Event.Done;
|
|
|
|
|
|
checkUiOp = new Operations.CheckUIOp(true); /// Runs in more then one state
|
2015-09-04 11:49:04 +00:00
|
|
|
|
modelessDlg = null;
|
2015-08-11 06:50:32 +00:00
|
|
|
|
|
|
|
|
|
|
processDataLoggingOp = new TBF.BenchControl.Operations.ProcessDataLoggingOp(processDataLogger, this);
|
|
|
|
|
|
|
2015-09-06 20:21:54 +00:00
|
|
|
|
const string Q2correctedFromCmd = "q2 corrected from ";
|
2015-08-25 09:47:21 +00:00
|
|
|
|
|
2015-09-06 20:21:54 +00:00
|
|
|
|
if (testParams.Activity.ToLower().Contains(Q2correctedFromCmd))
|
2015-08-25 09:47:21 +00:00
|
|
|
|
{
|
|
|
|
|
|
string fromTestName = testParams.Activity.Substring(Q2correctedFromCmd.Length);
|
|
|
|
|
|
|
|
|
|
|
|
Entities.TestResult oriTestResult = null;
|
|
|
|
|
|
foreach (var tr in results)
|
|
|
|
|
|
{
|
2015-08-25 15:02:58 +00:00
|
|
|
|
if ((tr.TestName == fromTestName)) { oriTestResult = tr; break; }
|
2015-08-25 09:47:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-08-26 16:00:46 +00:00
|
|
|
|
Entities.TestResult tstRslt = MakeCorrectedFrom(test, oriTestResult);
|
|
|
|
|
|
|
|
|
|
|
|
AddOrOverwriteResult(tstRslt);
|
|
|
|
|
|
Bridge.OnTestCompleted(this, new TestCompletedEventArgs(tstRslt));
|
|
|
|
|
|
allResults.Info(TestResult2CsvLine(tstRslt)); /// Append the results to the CSV-file
|
2015-08-25 09:47:21 +00:00
|
|
|
|
|
2015-08-25 15:02:58 +00:00
|
|
|
|
IList<Event> rList = new List<Event>(1);
|
|
|
|
|
|
rList.Add(Event.Done);
|
|
|
|
|
|
return rList;
|
2015-08-25 09:47:21 +00:00
|
|
|
|
}
|
2015-09-06 20:21:54 +00:00
|
|
|
|
else if (testParams.Activity.ToLower().Contains("simulate "))
|
2015-08-11 06:50:32 +00:00
|
|
|
|
{
|
2015-08-26 16:00:46 +00:00
|
|
|
|
Entities.TestResult tstRslt;
|
2015-08-11 06:50:32 +00:00
|
|
|
|
|
2015-09-24 06:54:59 +00:00
|
|
|
|
if (testParams.Activity.ToLower().Contains("q3")) tstRslt = MakeSimulated(test, 1, 0.5f);
|
|
|
|
|
|
else if (testParams.Activity.ToLower().Contains("q2")) tstRslt = MakeSimulated(test, 1, 1.7f);
|
|
|
|
|
|
else if (testParams.Activity.ToLower().Contains("q1")) tstRslt = MakeSimulated(test, 1, 2.2f);
|
|
|
|
|
|
else if (testParams.Activity.ToLower().Contains("compound ok")) tstRslt = MakeSimulatedCompound(test, CompoundTestType.Regular, 1, 0.7f);
|
|
|
|
|
|
else if (testParams.Activity.ToLower().Contains("compound nok")) tstRslt = MakeSimulatedCompound(test, CompoundTestType.Regular, 1, 4.7f);
|
|
|
|
|
|
else if (testParams.Activity.ToLower().Contains("compound rise")) tstRslt = MakeSimulatedCompound(test, CompoundTestType.DetectionRise, 1, 0.7f);
|
|
|
|
|
|
else if (testParams.Activity.ToLower().Contains("compound fall")) tstRslt = MakeSimulatedCompound(test, CompoundTestType.DetectionFall, 1, 0.7f);
|
|
|
|
|
|
else tstRslt = null;
|
2015-08-26 16:00:46 +00:00
|
|
|
|
|
|
|
|
|
|
AddOrOverwriteResult(tstRslt);
|
|
|
|
|
|
Bridge.OnTestCompleted(this, new TestCompletedEventArgs(tstRslt));
|
|
|
|
|
|
allResults.Info(TestResult2CsvLine(tstRslt)); /// Append the results to the CSV-file
|
2015-08-11 06:50:32 +00:00
|
|
|
|
|
2015-08-27 05:03:42 +00:00
|
|
|
|
for (int i = 0; i < Program.WMsCount; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
WaterMeters.iPerl.WaterMeter iPerl = ((sensPath.RegisterReaders != null) && (i < sensPath.RegisterReaders.Length))
|
|
|
|
|
|
? (sensPath.RegisterReaders[i] as WaterMeters.iPerl.WaterMeter)
|
|
|
|
|
|
: null;
|
|
|
|
|
|
if (iPerl != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
iPerl.LastTestResult = tstRslt.Meters[i]; /// Save this water meter test result to iPerl WM
|
|
|
|
|
|
iPerl.NominalTestFlow = 500.0 * (double)(test.Qfrom + test.Qto); /// Ave. + convert to liter/hour
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-09-06 20:21:54 +00:00
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
|
|
Bridge.OnActivity(this, testParams.Activity);
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
State.Create(string.Format("iPerlCommunicationSeq : {0}", testParams.Activity))
|
|
|
|
|
|
.AddOperation(checkUiOp)
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
|
|
|
|
|
|
|
|
|
|
if (e.Contains(Event.UiCmdStop)) retVal = Event.UiCmdStop;
|
2015-08-11 06:50:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Show the modeless dialog with error indication
|
|
|
|
|
|
///
|
2015-09-04 11:49:04 +00:00
|
|
|
|
Program.MainWnd.Invoke(new iPerlCommFormDlgt(OpenIPerlCommForm), new object[] { this, cfg, testParams });
|
2015-08-11 06:50:32 +00:00
|
|
|
|
|
2015-09-04 11:49:04 +00:00
|
|
|
|
//------------------------------------------------
|
|
|
|
|
|
Bridge.OnActivity(this, Strings.iPerl_Communication_in_progress);
|
|
|
|
|
|
//------------------------------------------------
|
2015-08-11 06:50:32 +00:00
|
|
|
|
|
2015-09-04 11:49:04 +00:00
|
|
|
|
bool stopPressed = false; /// true when STOP button pressed
|
|
|
|
|
|
bool completed = false;
|
2015-08-11 06:50:32 +00:00
|
|
|
|
|
2015-09-04 11:49:04 +00:00
|
|
|
|
State.Create("iPerlCommunicationSeq : Wait until the entry form is closed")
|
|
|
|
|
|
.AddOperation(checkUiOp)
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
|
|
|
|
stopPressed = e.Contains(Event.UiCmdStop);
|
|
|
|
|
|
completed = (modelessDlg is GenericDevices.IHasCompleted)
|
|
|
|
|
|
&& (modelessDlg as GenericDevices.IHasCompleted).Completed;
|
|
|
|
|
|
}
|
|
|
|
|
|
while (!stopPressed && !completed);
|
2015-08-11 06:50:32 +00:00
|
|
|
|
|
2015-09-04 11:49:04 +00:00
|
|
|
|
if (stopPressed)
|
|
|
|
|
|
{
|
|
|
|
|
|
CloseIPerlCommForm();
|
|
|
|
|
|
retVal = Event.UiCmdStop;
|
|
|
|
|
|
}
|
2015-08-11 06:50:32 +00:00
|
|
|
|
|
2015-09-04 11:49:04 +00:00
|
|
|
|
/// Test 'Quit'
|
|
|
|
|
|
modelessDlg = null; /// Modeless dialog is closed now
|
2015-08-11 06:50:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Create a list with one item 'retVal' (default is Event.Done) and return it
|
|
|
|
|
|
IList<Event> retList = new List<Event>(1);
|
|
|
|
|
|
retList.Add(retVal);
|
|
|
|
|
|
return retList;
|
|
|
|
|
|
}
|
2015-08-25 15:02:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Virtually apply Q2 correction to a test used for the correction calculation.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="oriTestRslt">Q2Adj test result</param>
|
|
|
|
|
|
/// <returns>Virtual Q2 test result</returns>
|
|
|
|
|
|
Entities.TestResult MakeCorrectedFrom(Entities.Test test, Entities.TestResult oriTestRslt)
|
|
|
|
|
|
{
|
|
|
|
|
|
Entities.TestResult tstRslt = new Entities.TestResult(test, 1, Entities.MetersKind.Single);
|
|
|
|
|
|
|
|
|
|
|
|
tstRslt.BatchNr = Program.LocalSettings.BatchNr;
|
|
|
|
|
|
tstRslt.MassStart = oriTestRslt.MassStart;
|
|
|
|
|
|
tstRslt.MassEnd = oriTestRslt.MassEnd;
|
|
|
|
|
|
tstRslt.MassDiff = oriTestRslt.MassEnd;
|
|
|
|
|
|
tstRslt.DensityIn = oriTestRslt.DensityIn;
|
|
|
|
|
|
tstRslt.DensityOut = oriTestRslt.DensityOut;
|
|
|
|
|
|
tstRslt.DensityDiv = oriTestRslt.DensityDiv;
|
|
|
|
|
|
tstRslt.Time = oriTestRslt.Time;
|
|
|
|
|
|
tstRslt.FlowMass = oriTestRslt.FlowMass;
|
|
|
|
|
|
tstRslt.FlowVolume = oriTestRslt.FlowVolume;
|
|
|
|
|
|
tstRslt.VolumeCTV = oriTestRslt.VolumeCTV;
|
|
|
|
|
|
tstRslt.VolumeMaster = oriTestRslt.VolumeMaster;
|
|
|
|
|
|
tstRslt.PulsesMaster = oriTestRslt.PulsesMaster;
|
|
|
|
|
|
tstRslt.ConstMaster = oriTestRslt.ConstMaster;
|
|
|
|
|
|
tstRslt.ErrorMaster = oriTestRslt.ErrorMaster;
|
|
|
|
|
|
tstRslt.TimeDivStart0 = oriTestRslt.TimeDivStart0;
|
|
|
|
|
|
tstRslt.TimeDivStart1 = oriTestRslt.TimeDivStart1;
|
|
|
|
|
|
tstRslt.TimeDivStart2 = oriTestRslt.TimeDivStart2;
|
|
|
|
|
|
tstRslt.TimeDivStart3 = oriTestRslt.TimeDivStart3;
|
|
|
|
|
|
tstRslt.TimeDivStart4 = oriTestRslt.TimeDivStart4;
|
|
|
|
|
|
tstRslt.TimeDivStart5 = oriTestRslt.TimeDivStart5;
|
|
|
|
|
|
tstRslt.TimeDivEnd0 = oriTestRslt.TimeDivEnd0;
|
|
|
|
|
|
tstRslt.TimeDivEnd1 = oriTestRslt.TimeDivEnd1;
|
|
|
|
|
|
tstRslt.TimeDivEnd2 = oriTestRslt.TimeDivEnd2;
|
|
|
|
|
|
tstRslt.TimeDivEnd3 = oriTestRslt.TimeDivEnd3;
|
|
|
|
|
|
tstRslt.TimeDivEnd4 = oriTestRslt.TimeDivEnd4;
|
|
|
|
|
|
tstRslt.TimeDivEnd5 = oriTestRslt.TimeDivEnd5;
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < Math.Min(tstRslt.Meters.Count, oriTestRslt.Meters.Count); i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Reference to iPerl water meter or null:
|
|
|
|
|
|
WaterMeters.iPerl.WaterMeter iPerl = ((sensPath.RegisterReaders != null) && (i < sensPath.RegisterReaders.Length))
|
|
|
|
|
|
? (sensPath.RegisterReaders[i] as WaterMeters.iPerl.WaterMeter)
|
|
|
|
|
|
: null;
|
|
|
|
|
|
|
|
|
|
|
|
tstRslt.Meters[i].SerialNr = oriTestRslt.Meters[i].SerialNr;
|
|
|
|
|
|
tstRslt.Meters[i].PulsesPerLiter = oriTestRslt.Meters[i].PulsesPerLiter;
|
|
|
|
|
|
tstRslt.Meters[i].VolumeRef = oriTestRslt.Meters[i].VolumeRef;
|
|
|
|
|
|
tstRslt.Meters[i].Time = oriTestRslt.Meters[i].Time;
|
|
|
|
|
|
tstRslt.Meters[i].TimeStart = oriTestRslt.Meters[i].TimeStart;
|
|
|
|
|
|
tstRslt.Meters[i].TimeEnd = oriTestRslt.Meters[i].TimeEnd;
|
|
|
|
|
|
tstRslt.Meters[i].PulsesMeter = oriTestRslt.Meters[i].PulsesMeter;
|
|
|
|
|
|
tstRslt.Meters[i].PulsesMaster = oriTestRslt.Meters[i].PulsesMaster;
|
|
|
|
|
|
tstRslt.Meters[i].Disabled = oriTestRslt.Meters[i].Disabled;
|
|
|
|
|
|
|
2015-09-11 17:36:37 +00:00
|
|
|
|
if ((iPerl == null) || (Math.Abs(oriTestRslt.Meters[i].VolumeErrorPct) <= 0.5f))
|
2015-08-25 15:02:58 +00:00
|
|
|
|
{
|
2015-08-25 15:45:46 +00:00
|
|
|
|
/// Normal meter or iPerl without correction
|
2015-08-25 15:02:58 +00:00
|
|
|
|
tstRslt.Meters[i].VolumeStart = oriTestRslt.Meters[i].VolumeStart;
|
|
|
|
|
|
tstRslt.Meters[i].VolumeEnd = oriTestRslt.Meters[i].VolumeEnd;
|
|
|
|
|
|
tstRslt.Meters[i].VolumeMeter = oriTestRslt.Meters[i].VolumeMeter;
|
|
|
|
|
|
tstRslt.Meters[i].VolumeErrorPct = oriTestRslt.Meters[i].VolumeErrorPct;
|
|
|
|
|
|
tstRslt.Meters[i].Passed = oriTestRslt.Meters[i].Passed;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2015-08-25 15:45:46 +00:00
|
|
|
|
/// corrected iPerl
|
2015-08-25 15:02:58 +00:00
|
|
|
|
tstRslt.Meters[i].VolumeStart = 0;
|
|
|
|
|
|
tstRslt.Meters[i].VolumeEnd = 0;
|
|
|
|
|
|
tstRslt.Meters[i].VolumeMeter = oriTestRslt.Meters[i].VolumeRef;
|
|
|
|
|
|
tstRslt.Meters[i].VolumeErrorPct = 0;
|
|
|
|
|
|
tstRslt.Meters[i].Passed = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return tstRslt;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-08-11 06:50:32 +00:00
|
|
|
|
}
|