Everything works OK after serious changes:
- all components, componentCfg-s and parameter providers use base classes - less boilerplate code, simpler access to test/procedure parameters from code - CreateTestParams(test), CreateProcedureParams(procedure) methods added - TestBenchSim class is made static, it is not inheritted by any device anymore
This commit is contained in:
@@ -15,71 +15,63 @@ namespace TBF.BenchControl.MettlerToledo
|
||||
/// <note>
|
||||
/// Implemented and tested on 15.10.2013 by Milan Hanajik
|
||||
/// </note>
|
||||
public class BalanceDev : TestBenchSim, IComponent, IDevice, GenericDevices.IBalance
|
||||
public class BalanceDev : ComponentBase, IDevice, GenericDevices.IBalance
|
||||
{
|
||||
/// <summary>
|
||||
/// Info: StartMassMeasurement() and "Balnce response = .., Mass = ..."
|
||||
/// Warn: Start measurement when busy is true
|
||||
/// </summary>
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(BalanceDev));
|
||||
public override string ToString() { return string.Format("{0} - Mettler-Toledo Balance", balanceCfg.Name); }
|
||||
public override string ToString() { return string.Format("MettlerToledo.Balance({0})", Cfg.ToString(1)); }
|
||||
|
||||
/// <summary>
|
||||
protected readonly BalanceCfg balanceCfg;
|
||||
|
||||
/// <summary>
|
||||
/// Enumeration of balances via static fields and methods
|
||||
/// </summary>
|
||||
static int nextBalanceIdx = 0;
|
||||
public static void ResetStaticProperties() { nextBalanceIdx = 0; }
|
||||
public static new void ResetStaticProperties()
|
||||
{
|
||||
nextBalanceIdx = 0;
|
||||
}
|
||||
public static int BalancesCount { get { return nextBalanceIdx; } }
|
||||
public static BalanceDev[] Balances;
|
||||
public static float[] Masses;
|
||||
///
|
||||
protected int balanceNr; /// 0-based balance number
|
||||
|
||||
protected readonly BalanceCfg balanceCfg;
|
||||
public Generic.IComponentCfg Cfg { get { return balanceCfg; } }
|
||||
|
||||
protected SerialPort serialPort;
|
||||
protected StringBuilder stringBuilder;
|
||||
|
||||
public string Name { get { return balanceCfg.Name; } }
|
||||
public int BalanceNr { get { return balanceNr; } }
|
||||
public float Capacity { get { return balanceCfg.Capacity; } }
|
||||
public int EmptyTimeSec { get { return balanceCfg.EmptyTimeSec; } }
|
||||
public IList<Entities.MeasurementCorrection> Corrections { get { return balanceCfg.Corrections; } }
|
||||
|
||||
|
||||
/// <summary>The state of the mass measurement</summary>
|
||||
public MsrmntState MsrmntState
|
||||
{
|
||||
get { return msrmntState; }
|
||||
}
|
||||
public MsrmntState MsrmntState { get { return msrmntState; } }
|
||||
protected MsrmntState msrmntState;
|
||||
|
||||
/// <summary>The mass after StartMassMeasurement() when MsrmntState == MsrmntState.Valid</summary>
|
||||
public float Mass
|
||||
{
|
||||
get { return mass; }
|
||||
}
|
||||
public float Mass { get { return mass; } }
|
||||
protected float mass;
|
||||
|
||||
/// <summary>The time stamp after StartMassMeasurement() when MsrmntState == MsrmntState.Valid</summary>
|
||||
public int MsrmntTimeStamp
|
||||
{
|
||||
get { return msrmntTimeStamp; }
|
||||
}
|
||||
public int MsrmntTimeStamp { get { return msrmntTimeStamp; } }
|
||||
protected int msrmntTimeStamp;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="balanceEntity">Balance properties</param>
|
||||
/// <param name="cfg">Balance properties</param>
|
||||
/// <param components="cfg">A list of components loaded so far</param>
|
||||
public BalanceDev(BalanceCfg cfg, IList<Generic.IComponent> components)
|
||||
: base(cfg)
|
||||
{
|
||||
if (cfg == null) throw new ArgumentNullException("cfg");
|
||||
this.balanceCfg = cfg;
|
||||
balanceCfg = cfg;
|
||||
|
||||
balanceNr = nextBalanceIdx++;
|
||||
Masses = new float[nextBalanceIdx]; /// (re)initialize the static array of masses of all balances
|
||||
|
||||
///
|
||||
if (Balances == null || Balances.Length < nextBalanceIdx)
|
||||
{
|
||||
BalanceDev[] balancesSoFar = Balances;
|
||||
@@ -87,9 +79,11 @@ namespace TBF.BenchControl.MettlerToledo
|
||||
if (balancesSoFar != null) for (int i = 0; i < balancesSoFar.Length; i++) Balances[i] = balancesSoFar[i];
|
||||
Balances[nextBalanceIdx - 1] = this;
|
||||
}
|
||||
|
||||
log.Debug(this.ToString());
|
||||
}
|
||||
|
||||
public new void Initialize()
|
||||
public void Initialize()
|
||||
{
|
||||
msrmntState = MsrmntState.Failed; /// Data not valid yet
|
||||
|
||||
@@ -228,7 +222,7 @@ namespace TBF.BenchControl.MettlerToledo
|
||||
{
|
||||
if (balanceCfg.DebugLevel == Entities.DebugMode.Simulate)
|
||||
{
|
||||
mass = GetSimMass(balanceNr);
|
||||
mass = TestBenchSim.GetSimMass(balanceNr);
|
||||
Masses[balanceNr] = mass;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
msrmntTimeStamp = StateMachine.Time;
|
||||
|
||||
Reference in New Issue
Block a user