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:
@@ -17,8 +17,8 @@ namespace TBF.BenchControl.MettlerToledo
|
||||
public float Empty; /// 'Empty' water mass in 'kg' or volume in 'l'
|
||||
public int EmptyTimeSec; /// s
|
||||
|
||||
/// Parameterless constructor
|
||||
public BalanceCfg()
|
||||
/// Private parameterless constructor invoked by all other (public) constructors
|
||||
BalanceCfg()
|
||||
{
|
||||
Name = "Balance";
|
||||
ParentName = string.Empty;
|
||||
@@ -41,7 +41,7 @@ namespace TBF.BenchControl.MettlerToledo
|
||||
|
||||
public string ToString(int i)
|
||||
{
|
||||
return string.Format("Name={0}, COM{1}, {2}Bd, {3}-bits, parity={4}, stopBits={5}, {6}, capacity={7}kg, empty={8}kg, emptyTime={9}s",
|
||||
return string.Format("Name={0}, Com{1}, {2}Bd, {3}-bits, parity={4}, stopBits={5}, {6}, capacity={7}kg, empty={8}kg, emptyTime={9}s",
|
||||
Name, ComPortNr, BaudRate, DataBits, Parity, StopBits, Handshake, Capacity, Empty, EmptyTimeSec);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -6,10 +6,6 @@ namespace TBF.BenchControl.MettlerToledo
|
||||
public class BalanceFactory : IComponentFactory
|
||||
{
|
||||
public string ClassName { get { return "MettlerToledo Balance"; } }
|
||||
public bool HasProcedureParams { get { return false; } }
|
||||
public bool HasTestParams { get { return false; } }
|
||||
public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; }
|
||||
public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; }
|
||||
|
||||
/// <summary>Max. number of components of this class in the system</summary>
|
||||
public int MaxCount { get { return 5; } }
|
||||
|
||||
@@ -14,28 +14,24 @@ namespace TBF.BenchControl.MettlerToledo
|
||||
/// <note>
|
||||
/// Implemented and tested on 15.10.2013 by Milan Hanajik
|
||||
/// </note>
|
||||
public class BalanceNewDev : BalanceDev, IComponent, IDevice, GenericDevices.IBalance2
|
||||
public class BalanceNewDev : BalanceDev, IDevice, GenericDevices.IBalance2
|
||||
{
|
||||
/// <summary>
|
||||
/// Info: StartMassMeasurement() and "Balnce response = .., Mass = ..."
|
||||
/// Warn: Start measurement when busy is true
|
||||
/// </summary>
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(BalanceNewDev));
|
||||
public override string ToString() { return string.Format("{0} - Mettler-Toledo Balance with SN", balanceCfg.Name); }
|
||||
|
||||
public static void ResetStaticProperties() { }
|
||||
public override string ToString() { return string.Format("MettlerToledo.BalanceNew({0})", Cfg.ToString(1)); }
|
||||
|
||||
/// <summary>Serial number after GetSerialNumber() when MsrmntState == MsrmntState.Valid</summary>
|
||||
public string SerialNumber
|
||||
{
|
||||
get { return serialNumber; }
|
||||
}
|
||||
public string SerialNumber { get { return serialNumber; } }
|
||||
string serialNumber;
|
||||
|
||||
public BalanceNewDev(BalanceCfg cfg, IList<Generic.IComponent> components)
|
||||
: base(cfg, components)
|
||||
{
|
||||
}
|
||||
log.Debug(this.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the serial number
|
||||
@@ -64,7 +60,7 @@ namespace TBF.BenchControl.MettlerToledo
|
||||
{
|
||||
if (balanceCfg.DebugLevel == Entities.DebugMode.Simulate)
|
||||
{
|
||||
mass = GetSimMass(balanceNr);
|
||||
mass = TestBenchSim.GetSimMass(balanceNr);
|
||||
Masses[balanceNr] = mass;
|
||||
serialNumber = "1234567890";
|
||||
msrmntState = MsrmntState.Valid;
|
||||
|
||||
@@ -6,10 +6,6 @@ namespace TBF.BenchControl.MettlerToledo
|
||||
public class BalanceNewFactory : IComponentFactory
|
||||
{
|
||||
public string ClassName { get { return "MettlerToledoBalanceSN"; } }
|
||||
public bool HasProcedureParams { get { return false; } }
|
||||
public bool HasTestParams { get { return false; } }
|
||||
public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; }
|
||||
public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; }
|
||||
|
||||
/// <summary>Max. number of components of this class in the system</summary>
|
||||
public int MaxCount { get { return 5; } }
|
||||
|
||||
Reference in New Issue
Block a user