New RR.DataStream.MefImport and RR.DataStream.Reader components.
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
///
|
||||
/// Copyright (c) 2021 Sensus Slovensko a.s.
|
||||
///
|
||||
using System.Collections.Generic;
|
||||
using TBF.Rig.Generic;
|
||||
|
||||
namespace TBF.Rig.RegisterReaders.DataStream.MefImport
|
||||
{
|
||||
public class Factory : IComponentFactory
|
||||
{
|
||||
public string ClassName { get { return GetType().Namespace.Substring(8); } }
|
||||
public override string ToString() { return ClassName; }
|
||||
|
||||
public IComponent DummyComponent() { return new MefImport(); }
|
||||
|
||||
public IComponent GetComponent(IComponentCfg cfg, IList<IComponent> components) { return new MefImport(cfg); }
|
||||
|
||||
public IComponentCfg DefaultConfig() { return new MefImportCfg(this); }
|
||||
|
||||
public IComponentCfg CmpntCfgFromCmpntEntity(Config.Entities.Component component)
|
||||
{
|
||||
return ComponentCfgBase.CreateFromDbEntity(MefImportCfg.Serializer, component, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
///
|
||||
/// Copyright (c) 2021 Sensus Slovensko a.s.
|
||||
///
|
||||
using System;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.ComponentModel.Composition.Hosting;
|
||||
using log4net;
|
||||
using Common;
|
||||
using DataStreamInterface;
|
||||
|
||||
namespace TBF.Rig.RegisterReaders.DataStream.MefImport
|
||||
{
|
||||
/// <summary>
|
||||
/// MEF interface to an external data stream reader component.
|
||||
/// </summary>
|
||||
public class MefImport : ComponentBase
|
||||
{
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(MefImport));
|
||||
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
|
||||
|
||||
public Int64 MinSamplesCount { get { return 10; } }
|
||||
|
||||
|
||||
[Import(typeof(IDataStreamMeter))]
|
||||
public IDataStreamMeter DataStreamIFace;
|
||||
|
||||
|
||||
readonly MefImportCfg myCfg;
|
||||
public string CatalogDir { get { return myCfg.CatalogDir; } }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Size of this array is DataStreamIFace.GetMetersCount()
|
||||
/// 'true' in this array represents an open connection to the water meter with the same index
|
||||
/// </summary>
|
||||
bool[] isConnectedArray;
|
||||
|
||||
|
||||
public MefImport() { }
|
||||
|
||||
public MefImport(Generic.IComponentCfg cfg)
|
||||
: base(cfg)
|
||||
{
|
||||
myCfg = cfg as MefImportCfg;
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
if (DebugLevel == DebugMode.Normal)
|
||||
{
|
||||
var catalog = new AggregateCatalog();
|
||||
catalog.Catalogs.Add(new AssemblyCatalog(typeof(DataStreamInterface.IDataStreamMeter).Assembly));
|
||||
catalog.Catalogs.Add(new DirectoryCatalog(CatalogDir));
|
||||
(new CompositionContainer(catalog)).ComposeParts(this);
|
||||
|
||||
isConnectedArray = new bool[DataStreamIFace.GetMetersCount()];
|
||||
|
||||
log.FatalFormat("{0} initialized: {1}", Name, this);
|
||||
log.FatalFormat(" Meters count = {0}", DataStreamIFace.GetMetersCount());
|
||||
log.FatalFormat(" Time unit = {0}", DataStreamIFace.GetTimeUnits().ToString());
|
||||
log.FatalFormat(" Volume unit = {0}", DataStreamIFace.GetVolumeUnits().ToString());
|
||||
for (int i = 0; i < DataStreamIFace.GetQuantitiesCount(); i++)
|
||||
{
|
||||
log.FatalFormat(" Quantity_{0} = {1}, unit = {2}", i + 1,
|
||||
DataStreamIFace.GetQuantityCaption(i),
|
||||
DataStreamIFace.GetQuantityUnits(i).ToString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
log.FatalFormat("{0} simulated: {1}", Name, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool IsConnected(int ix)
|
||||
{
|
||||
return (isConnectedArray != null && ix >= 0 && ix < isConnectedArray.Length) ? isConnectedArray[ix] : false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper for DataStreamIFace.OpenConnection() that updates bool[] isConnected array.
|
||||
/// </summary>
|
||||
/// <param name="ix">0-based water meter index</param>
|
||||
/// <param name="connectionParameters">Connection parameters</param>
|
||||
/// <param name="meterId">Water meter ID (serial number)</param>
|
||||
/// <returns>true = Successfully connected</returns>
|
||||
public bool OpenConnection(int ix, string connectionParameters, out string meterId)
|
||||
{
|
||||
if (isConnectedArray != null && ix >= 0 && ix < isConnectedArray.Length)
|
||||
{
|
||||
isConnectedArray[ix] = DataStreamIFace.OpenConnection(ix, connectionParameters, out meterId);
|
||||
return isConnectedArray[ix];
|
||||
}
|
||||
else
|
||||
{
|
||||
meterId = string.Empty;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper for DataStreamIFace.CloseConnection() called in a loop for all connected water meters
|
||||
/// </summary>
|
||||
public bool CloseConnectionAll()
|
||||
{
|
||||
if (isConnectedArray != null)
|
||||
{
|
||||
for (int ix = 0; ix < isConnectedArray.Length; ix++)
|
||||
{
|
||||
if (isConnectedArray[ix])
|
||||
{
|
||||
DataStreamIFace.CloseConnection(ix);
|
||||
isConnectedArray[ix] = false; /// reset IsConnected flag regardless of returned value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper for DataStreamIFace.StartMeasurement(), starts only connected water meters
|
||||
/// </summary>
|
||||
public bool StartMeasurement(int ix)
|
||||
{
|
||||
if (isConnectedArray != null && ix >= 0 && ix < isConnectedArray.Length && isConnectedArray[ix])
|
||||
{
|
||||
return DataStreamIFace.StartMeasurement(ix);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper that bypasses DataStreamIFace.StartMeasurementAll(), starts only connected water meters
|
||||
/// </summary>
|
||||
public bool StartMeasurementAll()
|
||||
{
|
||||
if (isConnectedArray != null)
|
||||
{
|
||||
for (int ix = 0; ix < isConnectedArray.Length; ix++)
|
||||
{
|
||||
if (isConnectedArray[ix]) DataStreamIFace.StartMeasurement(ix);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper for DataStreamIFace.StopMeasurement(), stops only connected water meters
|
||||
/// </summary>
|
||||
public bool StopMeasurement(int ix, out Int64 storedFramesCount)
|
||||
{
|
||||
if (isConnectedArray != null && ix >= 0 && ix < isConnectedArray.Length && isConnectedArray[ix])
|
||||
{
|
||||
return DataStreamIFace.StopMeasurement(ix, out storedFramesCount);
|
||||
}
|
||||
|
||||
storedFramesCount = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper that bypasses DataStreamIFace.StopMeasurementAll(), stops only connected water meters
|
||||
/// </summary>
|
||||
public bool StopMeasurementAll(out Int64[] storedFramesCounts)
|
||||
{
|
||||
if (isConnectedArray != null)
|
||||
{
|
||||
storedFramesCounts = new Int64[isConnectedArray.Length];
|
||||
for (int ix = 0; ix < isConnectedArray.Length; ix++)
|
||||
{
|
||||
if (isConnectedArray[ix])
|
||||
DataStreamIFace.StopMeasurement(ix, out storedFramesCounts[ix]);
|
||||
else
|
||||
storedFramesCounts[ix] = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
storedFramesCounts = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
///
|
||||
/// Copyright (c) 2021 Sensus Slovensko a.s.
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
using Common;
|
||||
using Config.Entities;
|
||||
using TBF.Rig.Generic;
|
||||
|
||||
namespace TBF.Rig.RegisterReaders.DataStream.MefImport
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds information identifying the test bench - serializable configuration.
|
||||
/// </summary>
|
||||
public class MefImportCfg : ComponentCfgBase, Generic.IComponentCfg, IParamsProvider
|
||||
{
|
||||
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(MefImportCfg) })[0];
|
||||
public override XmlSerializer GetSerializer() { return Serializer; }
|
||||
|
||||
public IComponentCfgCtrl GetControl(IList<Config.Entities.Component> cmpntEntities)
|
||||
{
|
||||
return new Configs.ParamsProvider.ComponentCfgCtrl(this, null);
|
||||
}
|
||||
|
||||
///
|
||||
/// Serialized parameters
|
||||
///
|
||||
public string CatalogDir;
|
||||
|
||||
|
||||
/// Private parameterless constructor invoked by all other (public) constructors
|
||||
MefImportCfg() {}
|
||||
|
||||
public MefImportCfg(IComponentFactory factory)
|
||||
: this()
|
||||
{
|
||||
Factory = factory;
|
||||
Name = "MefImport";
|
||||
ParentName = string.Empty;
|
||||
InitializeAll();
|
||||
}
|
||||
|
||||
public string ComponentName { get { return Name; } }
|
||||
|
||||
public void InitializeAll()
|
||||
{
|
||||
CatalogDir = "..\\..\\..\\DataStreamMeter\\bin";
|
||||
}
|
||||
|
||||
string[] paramNames = new string[]
|
||||
{
|
||||
"Catalog directory",
|
||||
};
|
||||
public string ParamName(int i) { return paramNames[i]; }
|
||||
public int ParamsCount() { return paramNames.Length; }
|
||||
|
||||
public ICollection<string> ParamValues(int i)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
return null;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public string ToString(int i)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
return CatalogDir;
|
||||
default:
|
||||
return string.Format("{0}: CatalogDir = {1}", Name, CatalogDir);
|
||||
}
|
||||
}
|
||||
|
||||
public CfgUpdateFlags UpdateParam(int i, string strValue)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
CatalogDir = strValue;
|
||||
return CfgUpdateFlags.RestartRqrd;
|
||||
default:
|
||||
return CfgUpdateFlags.None;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ValidateParam(int i, string strValue, out string message)
|
||||
{
|
||||
message = string.Empty;
|
||||
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
return true;
|
||||
default:
|
||||
message = "Invalid index";
|
||||
return false;
|
||||
}
|
||||
|
||||
message = ParamName(i) + " is invalid";
|
||||
return false;
|
||||
}
|
||||
|
||||
void CopyContentTo(MefImportCfg prms)
|
||||
{
|
||||
prms.CatalogDir = this.CatalogDir;
|
||||
}
|
||||
|
||||
public IParamsProvider Clone()
|
||||
{
|
||||
MefImportCfg pars = new MefImportCfg();
|
||||
CopyContentTo(pars);
|
||||
return pars;
|
||||
}
|
||||
|
||||
public bool UpdateEmbeddedDbEntity()
|
||||
{
|
||||
return true; /// =OK, do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
///
|
||||
/// Copyright (c) 2021 Sensus Slovensko a.s.
|
||||
///
|
||||
using System.Collections.Generic;
|
||||
using TBF.Rig.Generic;
|
||||
|
||||
namespace TBF.Rig.RegisterReaders.DataStream.Reader
|
||||
{
|
||||
public class Factory : IComponentFactory
|
||||
{
|
||||
public string ClassName { get { return GetType().Namespace.Substring(8); } }
|
||||
public override string ToString() { return ClassName; }
|
||||
|
||||
public IComponent DummyComponent() { return new Reader(); }
|
||||
|
||||
public IComponent GetComponent(IComponentCfg cfg, IList<IComponent> components) { return new Reader(cfg, components); }
|
||||
|
||||
public IComponentCfg DefaultConfig() { return new ReaderCfg(this); }
|
||||
|
||||
public IComponentCfg CmpntCfgFromCmpntEntity(Config.Entities.Component component)
|
||||
{
|
||||
return ComponentCfgBase.CreateFromDbEntity(ReaderCfg.Serializer, component, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
///
|
||||
/// Copyright (c) 2021 Sensus Slovensko a.s.
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.ComponentModel.Composition.Hosting;
|
||||
using System.Xml.Serialization;
|
||||
using log4net;
|
||||
using Common;
|
||||
using DataStreamInterface;
|
||||
using TBF.Rig;
|
||||
using TBF.Rig.Generic;
|
||||
using TBF.Rig.RegisterReaders.DataStream;
|
||||
|
||||
namespace TBF.Rig.RegisterReaders.DataStream.Reader
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds information identifying the test bench.
|
||||
/// </summary>
|
||||
public class Reader : ComponentBase, IOperation, GenericDevices.IRegReaderDatastream
|
||||
{
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(Reader));
|
||||
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
|
||||
|
||||
MefImport.MefImport mefImport;
|
||||
Int64 minSamplesCount { get { return mefImport.MinSamplesCount; } }
|
||||
|
||||
///
|
||||
/// IRegReader interface part 1
|
||||
///
|
||||
readonly ReaderCfg myCfg;
|
||||
public RegisterReaderType RegisterReaderType { get { return RegisterReaderType.DataStream; } }
|
||||
public int Position { get { return (myCfg != null) ? myCfg.Position : 1; } }
|
||||
public double PulsesPerLtr { get { return 1.0; } }
|
||||
public double LtrsPerPulse { get { return 1.0; } }
|
||||
|
||||
string waterMeterID;
|
||||
Int64 storedFramesCount;
|
||||
Int64 startIx;
|
||||
Int64 endIx;
|
||||
Dictionary<Int64, DataFrame> samplesDict;
|
||||
DataStreamInterface.Unit timeUnit;
|
||||
DataStreamInterface.Unit volumeUnit;
|
||||
|
||||
|
||||
public Reader() { }
|
||||
|
||||
public Reader(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
|
||||
: base(cfg)
|
||||
{
|
||||
myCfg = cfg as ReaderCfg;
|
||||
|
||||
mefImport = TbfComponents.FindComponent(cfg.ParentName, components) as MefImport.MefImport;
|
||||
if (mefImport == null) throw new Exception("Cannot find " + Name + " parent");
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
if (DebugLevel == DebugMode.Normal)
|
||||
{
|
||||
if (Position < 1 || Position > Math.Min(Data.WMsCount, mefImport.DataStreamIFace.GetMetersCount()))
|
||||
{
|
||||
throw new ArgumentException("Position is out of range");
|
||||
}
|
||||
|
||||
samplesDict = new Dictionary<Int64, DataFrame>();
|
||||
|
||||
log.FatalFormat("{0} initialized: {1}", Name, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
log.FatalFormat("{0} simulated: {1}", Name, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// IRegReader interface part 2
|
||||
///
|
||||
int wmPulses;
|
||||
int wmRefPulses;
|
||||
double wmVolume;
|
||||
double beginWMState;
|
||||
double endWMState;
|
||||
///
|
||||
public int WMPulses { get { return wmPulses; } } /// Counted pulses of the water meter
|
||||
public int WMRefPulses { get { return wmRefPulses; } } /// 'Gated' reference pulses of the water meters
|
||||
public double WMVolume { get { return wmVolume; } } /// Counted volume of the water meter
|
||||
public double BeginWMState { get { return beginWMState; } } /// Test begin state of the water meter
|
||||
public double EndWMState { get { return endWMState; } } /// Test end state of the water meter
|
||||
|
||||
|
||||
/// To be used at the beginning of a test
|
||||
public void Clear()
|
||||
{
|
||||
storedFramesCount = 0;
|
||||
startIx = -1;
|
||||
endIx = -1;
|
||||
beginWMState = 0;
|
||||
endWMState = 0;
|
||||
wmVolume = 0;
|
||||
wmPulses = 0;
|
||||
wmRefPulses = 0;
|
||||
samplesDict.Clear();
|
||||
timeUnit = DataStreamInterface.Unit.s;
|
||||
volumeUnit = DataStreamInterface.Unit.l;
|
||||
}
|
||||
|
||||
/// To be used when the test is completed ...
|
||||
public void TestCompleted()
|
||||
{
|
||||
mefImport.DataStreamIFace.CloseConnection(Position - 1);
|
||||
}
|
||||
|
||||
public IOperation ReadDatastreamOp()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
///
|
||||
/// IOperation interface
|
||||
///
|
||||
public void Start()
|
||||
{
|
||||
Clear();
|
||||
|
||||
if (TBF.Rig.Sequences.ProcessData.BatchRslts.Batch.WaterMeters.Count >= Position &&
|
||||
TBF.Rig.Sequences.ProcessData.BatchRslts.Batch.WaterMeters[Position - 1] != null &&
|
||||
!TBF.Rig.Sequences.ProcessData.BatchRslts.Batch.WaterMeters[Position - 1].Disabled)
|
||||
{
|
||||
timeUnit = mefImport.DataStreamIFace.GetTimeUnits();
|
||||
volumeUnit = mefImport.DataStreamIFace.GetVolumeUnits();
|
||||
log.DebugFormat("timeUnit = {0}, volumeUnit = {1}", timeUnit, volumeUnit);
|
||||
|
||||
bool started = mefImport.StartMeasurement(Position - 1);
|
||||
log.DebugFormat("{0} : mefImport.StartMeasurement({1}) in Start() returned {2}", Name, Position - 1, started);
|
||||
}
|
||||
}
|
||||
|
||||
public Event Run()
|
||||
{
|
||||
log.DebugFormat("Run() name={0} position={1}", Name, Position - 1);
|
||||
return Event.ReadRegisterDone;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
|
||||
if (TBF.Rig.Sequences.ProcessData.BatchRslts.Batch.WaterMeters.Count >= Position &&
|
||||
TBF.Rig.Sequences.ProcessData.BatchRslts.Batch.WaterMeters[Position - 1] != null &&
|
||||
!TBF.Rig.Sequences.ProcessData.BatchRslts.Batch.WaterMeters[Position - 1].Disabled)
|
||||
{
|
||||
bool stopped = mefImport.StopMeasurement(Position - 1, out storedFramesCount);
|
||||
log.DebugFormat("{0} : mefImport.StopMeasurement({1}) in Stop() returned {2}, storedFramesCount = {3}", Name, Position - 1, stopped, storedFramesCount);
|
||||
|
||||
if (storedFramesCount >= minSamplesCount)
|
||||
{
|
||||
startIx = storedFramesCount / minSamplesCount;
|
||||
endIx = (storedFramesCount * (minSamplesCount - 1) / minSamplesCount) - 1;
|
||||
|
||||
beginWMState = VolumeLtrStart;
|
||||
endWMState = VolumeLtrEnd;
|
||||
wmVolume = Math.Abs(VolumeLtrEnd - VolumeLtrStart);
|
||||
wmPulses = (int)Math.Round(wmVolume * PulsesPerLtr);
|
||||
wmRefPulses = StateMachine.ControlBoard.RefPulses;
|
||||
log.DebugFormat("Stop() ... Position={0}, wmVolume={1}, wmPulses={2}, wmRefPulses={3}", Position, wmVolume, wmPulses, wmRefPulses);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// ... for more accurate WMPulses, WMRefPulses calculation
|
||||
|
||||
|
||||
///
|
||||
/// IRegReaderDatastream interface
|
||||
///
|
||||
public bool NoSamples { get { return storedFramesCount < minSamplesCount || startIx < 0 || endIx < 0; } }
|
||||
public double VolumeLtrStart { get { return (startIx >= 0) ? GetVolumeFromSamples(startIx) : 0; } }
|
||||
public double VolumeLtrEnd { get { return (endIx >= 0) ? GetVolumeFromSamples(endIx) : 0; } }
|
||||
public double TimestampSecStart { get { return (startIx >= 0) ? GetTimeFromSamples(startIx) : 0; } }
|
||||
public double TimestampSecEnd { get { return (endIx >= 0) ? GetTimeFromSamples(endIx) : 0; } }
|
||||
|
||||
double GetTimeFromSamples(Int64 ix)
|
||||
{
|
||||
DataFrame oneFrame;
|
||||
DataFrame[] frames;
|
||||
|
||||
if (samplesDict.TryGetValue(ix, out oneFrame))
|
||||
{
|
||||
double time = DataStreamInterface.Units.ConvertFrom(timeUnit, oneFrame.Time);
|
||||
log.DebugFormat("GetTimeFromSamples({0}) returns {1} ... value from dictionary", ix, time);
|
||||
return time;
|
||||
}
|
||||
else if ((frames = mefImport.DataStreamIFace.GetFrames(Position - 1, ix, 1)).Length == 1)
|
||||
{
|
||||
samplesDict.Add(ix, frames[0]);
|
||||
double time = DataStreamInterface.Units.ConvertFrom(timeUnit, frames[0].Time);
|
||||
log.DebugFormat("GetTimeFromSamples({0}) returns {1} ... value obtained by DataStreamIFace.GetFrames({2}, {0}, 1)", ix, time, Position - 1);
|
||||
return time;
|
||||
}
|
||||
else
|
||||
{
|
||||
log.DebugFormat("GetTimeFromSamples({0}) returns 0", ix);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
double GetVolumeFromSamples(Int64 ix)
|
||||
{
|
||||
DataFrame oneFrame;
|
||||
DataFrame[] frames;
|
||||
|
||||
if (samplesDict.TryGetValue(ix, out oneFrame))
|
||||
{
|
||||
double volume = DataStreamInterface.Units.ConvertFrom(volumeUnit, oneFrame.Volume);
|
||||
log.DebugFormat("GetVolumeFromSamples({0}) returns {1} ... value from dictionary", ix, volume);
|
||||
return volume;
|
||||
}
|
||||
else if ((frames = mefImport.DataStreamIFace.GetFrames(Position - 1, ix, 1)).Length == 1)
|
||||
{
|
||||
samplesDict.Add(ix, frames[0]);
|
||||
double volume = DataStreamInterface.Units.ConvertFrom(volumeUnit, frames[0].Volume);
|
||||
log.DebugFormat("GetVolumeFromSamples({0}) returns {1} ... value obtained by DataStreamIFace.GetFrames({2}, {0}, 1)", ix, volume, Position - 1);
|
||||
return volume;
|
||||
}
|
||||
else
|
||||
{
|
||||
log.DebugFormat("GetVolumeFromSamples({0}) returns 0", ix);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
///
|
||||
/// Copyright (c) 2021 Sensus Slovensko a.s.
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Serialization;
|
||||
using Common;
|
||||
using Config.Entities;
|
||||
using TBF.Rig.Generic;
|
||||
|
||||
namespace TBF.Rig.RegisterReaders.DataStream.Reader
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds information identifying the test bench - serializable configuration.
|
||||
/// </summary>
|
||||
public class ReaderCfg : ComponentCfgBase, Generic.IChildComponentCfg, IParamsProvider
|
||||
{
|
||||
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(ReaderCfg) })[0];
|
||||
public override XmlSerializer GetSerializer() { return Serializer; }
|
||||
|
||||
public IComponentCfgCtrl GetControl(IList<Component> cmpntEntities)
|
||||
{
|
||||
var parents = cmpntEntities.Where(x => x.ClassName == "RegisterReaders.DataStream.MefImport");
|
||||
|
||||
return new Configs.ParamsProvider.ComponentCfgCtrl(this, parents);
|
||||
}
|
||||
|
||||
///
|
||||
/// Serialized parameters
|
||||
///
|
||||
public int Position;
|
||||
|
||||
|
||||
/// Private parameterless constructor invoked by all other (public) constructors
|
||||
ReaderCfg() {}
|
||||
|
||||
public ReaderCfg(IComponentFactory factory)
|
||||
: this()
|
||||
{
|
||||
Factory = factory;
|
||||
Name = "Reader";
|
||||
ParentName = "MefImport";
|
||||
InitializeAll();
|
||||
}
|
||||
|
||||
public string ComponentName { get { return Name; } }
|
||||
|
||||
public void InitializeAll()
|
||||
{
|
||||
Position = 1;
|
||||
}
|
||||
|
||||
string[] paramNames = new string[]
|
||||
{
|
||||
"Position",
|
||||
};
|
||||
public string ParamName(int i) { return paramNames[i]; }
|
||||
public int ParamsCount() { return paramNames.Length; }
|
||||
|
||||
public ICollection<string> ParamValues(int i)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
IList<string> retv = new List<string>();
|
||||
for (int j = 1; j <= Data.WMsCount; j++) retv.Add(j.ToString());
|
||||
return retv;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public string ToString(int i)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
return Position.ToString();
|
||||
default:
|
||||
return string.Format("{0}: Position = {1}", Name, Position);
|
||||
}
|
||||
}
|
||||
|
||||
public CfgUpdateFlags UpdateParam(int i, string strValue)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
Position = int.Parse(strValue);
|
||||
return CfgUpdateFlags.RestartRqrd;
|
||||
default:
|
||||
return CfgUpdateFlags.None;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ValidateParam(int i, string strValue, out string message)
|
||||
{
|
||||
message = string.Empty;
|
||||
int idummy;
|
||||
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
if (int.TryParse(strValue, out idummy) && idummy > 0 && idummy <= Data.WMsCount) return true;
|
||||
break;
|
||||
default:
|
||||
message = "Invalid index";
|
||||
return false;
|
||||
}
|
||||
|
||||
message = ParamName(i) + " is invalid";
|
||||
return false;
|
||||
}
|
||||
|
||||
void CopyContentTo(ReaderCfg prms)
|
||||
{
|
||||
prms.Position = this.Position;
|
||||
}
|
||||
|
||||
public IParamsProvider Clone()
|
||||
{
|
||||
ReaderCfg pars = new ReaderCfg();
|
||||
CopyContentTo(pars);
|
||||
return pars;
|
||||
}
|
||||
|
||||
public bool UpdateEmbeddedDbEntity()
|
||||
{
|
||||
return true; /// =OK, do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -113,6 +113,8 @@ namespace TBF.Rig
|
||||
Factories.Add(new BuiltIn.Pump.PumpFactory());
|
||||
Factories.Add(new Danfoss.VLT2800.PumpFactory());
|
||||
Factories.Add(new BuiltIn.PumpTandem.PumpFactory());
|
||||
Factories.Add(new RegisterReaders.DataStream.MefImport.Factory()); /// 'Interface for data stream stream via MEF'
|
||||
Factories.Add(new RegisterReaders.DataStream.Reader.Factory()); /// 'RegisterReader for data stream stream via MEF'
|
||||
Factories.Add(new RegisterReaders.PulsesFromUniCB.Factory()); /// 'RegisterReader'
|
||||
Factories.Add(new RegisterReaders.StandingStartStop.Factory()); /// 'RegisterReader for standing start/stop'
|
||||
Factories.Add(new TestMethods.iPerlCommunication.iPerlHead.Factory()); /// 'RegisterReader for iPerl'
|
||||
|
||||
Reference in New Issue
Block a user