99 lines
3.4 KiB
C#
99 lines
3.4 KiB
C#
///
|
|
/// Copyright (c) 2017-2021 Sensus Slovensko a.s.
|
|
///
|
|
using System.Collections.Generic;
|
|
using log4net;
|
|
using Common;
|
|
using Config.Entities;
|
|
using TBF.UiBridge;
|
|
using System.IO;
|
|
using TBF.Rig.GenericDevices;
|
|
|
|
namespace TBF.Rig.TestMethods.GrabImage
|
|
{
|
|
public class GrabImageSeq : Sequences.SequenceBase
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(GrabImageSeq));
|
|
|
|
/// <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;
|
|
}
|
|
|
|
public IList<Event> Execute( Test test, GrabImageCfg cfg)
|
|
{
|
|
IList<Event> e = new List<Event>(); /// Events from currently running operations
|
|
Event retVal = Event.Done;
|
|
|
|
ControlBoard.IControlBoard cBrd = StateMachine.ControlBoardMain;
|
|
|
|
/// Operations
|
|
checkUiOp = new Operations.CheckUIOp(true);
|
|
|
|
IList<GenericDevices.ICamera> cameras = new List<GenericDevices.ICamera>();
|
|
IList<IOperation> grabImagesOp = new List<IOperation>();
|
|
|
|
//------------------------------------------------
|
|
Bridge.OnActivity(this, test.Method);
|
|
//------------------------------------------------
|
|
State state = State.Create(string.Format("{0}({1}) : Grabbing images", test.Method, test.Name))
|
|
.AddOperation(checkUiOp);
|
|
|
|
IValve triggerValve = null;
|
|
bool triggerSend = false;
|
|
for (int i = 0; i < sensPath.RegisterReaders.Length; i++)
|
|
{
|
|
GenericDevices.IRegReaderStillCamera roi = sensPath.RegisterReaders[i] as GenericDevices.IRegReaderStillCamera;
|
|
if (roi != null)
|
|
{
|
|
///if exist valve trigger camera open
|
|
triggerValve = roi.GetValve();
|
|
if (triggerValve != null && !triggerSend)
|
|
{
|
|
OpenValveGrabImage(cBrd,null, triggerValve, e,
|
|
string.Format("{0}({1}) : Grabbing images - valve open", test.Method, test.Name));
|
|
triggerSend = true;
|
|
}
|
|
|
|
string imageName = Path.HasExtension(cfg.ImageFileName)?cfg.ImageFileName:cfg.ImageFileName+".bmp";
|
|
log.DebugFormat("GrabImage file name: {0} ", imageName);
|
|
string directory = Path.Combine(Program.ImagesDir, BatchRslts.Batch.BatchNr.ToString(), (i+1).ToString());
|
|
Directory.CreateDirectory(directory);
|
|
state.AddOperation(roi.GrabImageOp(Path.Combine(directory, imageName),
|
|
cfg.BlackAndWhite,
|
|
cfg.LowResolution,
|
|
cfg.ImageRotation));
|
|
}
|
|
}
|
|
state.EnterState();
|
|
do
|
|
{
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
|
|
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, 1, Progress.Test));
|
|
|
|
if (e.Contains(Event.Error)) { retVal = Event.Error; break; }
|
|
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; break; }
|
|
}
|
|
while (e.Contains(Event.CameraBusy));
|
|
|
|
///valve trigger camera close
|
|
if (triggerValve != null)
|
|
{
|
|
CloseValveGrabImage(cBrd,null,triggerValve, e,
|
|
string.Format("{0}({1}) : Grabbing images - valve close", test.Method, test.Name));
|
|
}
|
|
///////
|
|
|
|
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, 1, Progress.Completed));
|
|
return new List<Event> { retVal };
|
|
}
|
|
}
|
|
}
|