tbf/TBF/Rig/TestMethods/StandingStartMassCollectionAdvanceCollect/StandingStartMassCollectionAdvanceCollectSeq.cs

255 lines
12 KiB
C#

///
/// Copyright (c) 2013-2021 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using System.IO;
using log4net;
using Common;
using Config.Entities;
using TBF.Boxes;
using TBF.Resources;
using TBF.Rig.GenericDevices;
using TBF.Rig.Network.RestAPI;
using TBF.Rig.Sequences;
using TBF.UiBridge;
namespace TBF.Rig.TestMethods.StandingStartMassCollectionAdvanceCollect
{
public class StandingStartMassCollectionAdvanceCollectSeq : Sequences.SequenceBase, ISequence
{
private static readonly ILog log = LogManager.GetLogger(typeof(StandingStartMassCollectionAdvanceCollectSeq));
private Procedure parentProcedure;
/// <summary>
/// Check capabilities of devces in the output path required for this test method
/// </summary>
/// <param name="devices">Devices</param>
/// <returns>true when capabilities of devices are OK</returns>
public static bool CheckDeviceCaps(Config.Entities.Test test, OutputPath devices, out string message)
{
message = string.Empty;
return true;
}
/// <summary>
/// Fixed start mass collection method sequence
/// </summary>
/// <param name="test">Test entity</param>
/// <returns>
/// Event.Done . . . . . . . OK
/// Event.MakeSecondPass . . OK, 2nd pass (=evaluation) required
/// 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>
public IList<Event> Execute(Config.Entities.Test test, int repetitionNr, bool isLastRepetition,
Common.DebugMode debugLevel)
{
IList<Event> e; /// Events from currently running operations
int waterMetersCount = Math.Min(BenchInfo.WaterMetersCount, sensPath.RegisterReaders.Length);
checkUiOp = new Operations.CheckUIOp(true); /// Runs in more then one state
processDataLoggingOp = new TBF.Rig.Operations.ProcessDataLoggingOp(processDataLogger, this, false);
e = StateMachine.WaitRunDevsRunOps();
log.DebugFormat("WaitRunDevsRunOps - initialisation done");
Event retVal = Event.Done;
///============================================================================================
/// Start the test, initialize test results
Bridge.OnTestSelected(this, new TestSelectedEventArgs(test, repetitionNr, inPath, benchPath, outPath, sensPath, heatMetersPath));
string testName = Results.Utils.GetTestName(test.Name, test.Repeats, repetitionNr);
log.DebugFormat("Start the test - testName: {0}, test -> name: {1} -> Repeats: {2} -> repetitionNr: {3}", testName, test.Name, test.Repeats, repetitionNr);
Results.Entities.TestRslt tstRslt = BatchRslts.GetTestRslt(testName, test.Part);
///
/// Enter water meter begin states and read the start mass at the same time
///
GenericDevices.IHasWMStatesForm dataEntryCmpnt = TbfComponents.FindComponent(StateMachine.Procedure.DataEntry) as GenericDevices.IHasWMStatesForm;
log.DebugFormat("Collect process - Enter watermeter end states here");
///
/// Enter watermeter start - end states here
///
if (dataEntryCmpnt != null)
{
IValve triggerValve = null;
bool triggerSend = false;
if (dataEntryCmpnt is GenericDevices.IDataEntryForCamera)
{
string[] startImages = new string[sensPath.RegisterReaders.Length];
string[] endImages = new string[sensPath.RegisterReaders.Length];
log.Debug("Save images EndWMState...");
/// SaveImages==true ... copy images to the directory that will be archived at the end of the cycle
for (int i = 0; i < sensPath.RegisterReaders.Length; i++)
{
var roi = sensPath.RegisterReaders[i] as IRegReaderStillCamera;
if (roi != null)
{
string pathImage= Path.Combine(Program.ImagesDir, BatchRslts.Batch.BatchNr.ToString(), (i + 1).ToString());
string endTestdestFName = (dataEntryCmpnt as IDataEntryForCamera).TestEndImgName(i, testName).Replace(' ','_').Replace('/','_');
log.DebugFormat("End test image {1} - destination file name to fileName: {0} filepath: {2}", endTestdestFName,i, pathImage);
endImages[i] = pathImage +"\\"+ endTestdestFName;
string startTestdestFName = (dataEntryCmpnt as IDataEntryForCamera).TestStartImgName(i, testName).Replace(' ','_').Replace('/','_');;
log.DebugFormat("Start test image {1} - destination file name to filePath: {0} filePath: {2}", startTestdestFName,i, pathImage);
startImages[i] = pathImage +"\\"+ startTestdestFName;
}
}
(dataEntryCmpnt as GenericDevices.IDataEntryForCamera).EndImages = endImages;
(dataEntryCmpnt as GenericDevices.IDataEntryForCamera).StartImages = startImages;
}
Bridge.OnActivity(this, Strings.Enter_water_meter_data);
State state = State.Create(string.Format("{0}({1}) : Entering the end-state", test.Method, test.Name));
{
state.AddOperation(dataEntryCmpnt.ShowTestCollectFormOp(sensPath.RegisterReaders,
0, test.ErrLimLo + test.Uncertainty, test.ErrLimHi - test.Uncertainty));
}
state.AddOperation(checkUiOp)
//.AddOperations(readTempPressOps)
//.AddOperation(testInProgress)
.EnterState();
do {
e = StateMachine.WaitRunDevsRunOps();
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
}
while (!e.Contains(Event.ModelessFormClosed));
{
for (int i = 0; i < waterMetersCount; i++)
{
GenericDevices.IRegReader rr = sensPath.RegisterReaders[i];
if (rr is Rig.RegisterReaders.StandingStartStop.RegisterReader)
{
(rr as Rig.RegisterReaders.StandingStartStop.RegisterReader).EndWMState = dataEntryCmpnt.WMEndState(i);
(rr as Rig.RegisterReaders.StandingStartStop.RegisterReader).BeginWMState = dataEntryCmpnt.WMStartState(i);
}
if (rr is Rig.Network.Camera.RoiForFixedStart.Roi)
{
(rr as Rig.Network.Camera.RoiForFixedStart.Roi).EndWMState = dataEntryCmpnt.WMEndState(i);
(rr as Rig.Network.Camera.RoiForFixedStart.Roi).BeginWMState = dataEntryCmpnt.WMStartState(i);
}
if (rr is Rig.Network.Camera.RoiForFixedStartKeyence.Roi)
{
(rr as Rig.Network.Camera.RoiForFixedStartKeyence.Roi).EndWMState =
dataEntryCmpnt.WMEndState(i);
(rr as Rig.Network.Camera.RoiForFixedStartKeyence.Roi).BeginWMState =
dataEntryCmpnt.WMStartState(i);
log.DebugFormat(" StandingStartMassCollectionAdvanceSeq.cs - BeginWMState [{0}], EndWMState [{1}] -> RoiForFixedStartKeyence.Roi",dataEntryCmpnt.WMStartState(i),dataEntryCmpnt.WMEndState(i));
}
}
}
}
//------------------------------------------------
Bridge.OnActivity(this, Strings.Test_completed);
//------------------------------------------------
/// Make sure the CycleBeginForm is closed so that water meter data (s/n) can be copied into results
if (UIFlowControl.Stop == WaitBeginFormClosed()) goto stopTest;
///
/// Populate TestResult data entity with data
///
//Results.Entities.TestRslt tstRslt = BatchRslts.GetTestRslt(testName, test.Part);
bool stopCycle = false;
if (tstRslt != null)
{
{
///
/// Single meters
///
for (int i = 0; i < BatchRslts.WMPositionsCount; i++)
{
if (!test.IsPartCompatible(Utils.PartNr(i + 1, BatchRslts.Batch.Compound))) continue;
Results.Entities.MeterTestRslt meterRslt = BatchRslts.GetMeterTestRslt(testName, i, Common.CompoundMeterId.Single);
GenericDevices.IRegReader regReader = sensPath.RegisterReaders[i];
if (meterRslt != null && regReader != null)
{
meterRslt.VolumeStart = regReader.BeginWMState;
meterRslt.VolumeEnd = regReader.EndWMState;
meterRslt.VolumeMeter = Math.Abs(meterRslt.VolumeEnd - meterRslt.VolumeStart);
meterRslt.PulsesMeter = meterRslt.VolumeMeter;
meterRslt.Error = Formulas.ErrorFromVolumes(meterRslt.VolumeMeter, meterRslt.VolumeRef);
meterRslt.Passed = (meterRslt.Error >= test.GetErrLimLo(tstRslt.VolumeCTV, tstRslt.TestTime) + test.Uncertainty)
&& (meterRslt.Error <= test.GetErrLimHi(tstRslt.VolumeCTV, tstRslt.TestTime) - test.Uncertainty)
&& (tstRslt.ErrorFlags == 0);
}
}
}
/// Update water meter error flags
if (ErrorFlagsComp != null)
{
if (BatchRslts.Batch != null && BatchRslts.Batch.WaterMeters != null)
{
for (int i = 0; i < BatchRslts.WMPositionsCount; i++)
{
if (BatchRslts.Batch.WaterMeters[i] != null && !BatchRslts.Batch.WaterMeters[i].Disabled)
{
long wmInfoFlags;
BatchRslts.Batch.WaterMeters[i].ErrorFlags = ErrorFlagsComp.GetWMtrErrorFlags(BatchRslts.Batch.WaterMeters[i].MeterTestRslts, out wmInfoFlags);
BatchRslts.Batch.WaterMeters[i].InfoFlags = wmInfoFlags;
}
}
}
}
/// Update results
Bridge.OnTestCompleted(this, new TestCompletedEventArgs(testName, tstRslt));
}
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.TransitionAfter));
/// Append the results to the CSV-file
allResults.Info(TestResult2CsvLine(testName, test.Part));
if (stopCycle) retVal = Event.ErrorFlagsStop;
stopTest:
StopRecordingStatistics();
return new List<Event> { retVal };
}
public void DefineParentProcess(Procedure parentProcedure)
{
this.parentProcedure = parentProcedure;
}
}
}