MettlerToledo.Stabdard.Balance clean-up, shared static properties eliminated.
This commit is contained in:
@@ -299,24 +299,24 @@ namespace TBF.Rig.ControlBoard.Legacy
|
||||
public void UpdateWeights()
|
||||
{
|
||||
/// Mettler-Toledo scales
|
||||
for (int i = 0; i < MettlerToledo.Standard.BalanceDev.BalancesCount; i++)
|
||||
{
|
||||
controlCom.SetWeight(i, MettlerToledo.Standard.BalanceDev.Masses[i]);
|
||||
}
|
||||
//for (int i = 0; i < MettlerToledo.Standard.BalanceDev.BalancesCount; i++)
|
||||
//{
|
||||
// controlCom.SetWeight(i, MettlerToledo.Standard.BalanceDev.Masses[i]);
|
||||
//}
|
||||
|
||||
/// Mettler-Toledo-multi scales (Badger Brno, ...)
|
||||
for (int i = 0; i < MettlerToledo.Multi.BalanceDev.BalancesCount; i++)
|
||||
{
|
||||
controlCom.SetWeight(i, MettlerToledo.Multi.BalanceDev.Masses[i]);
|
||||
}
|
||||
///// Mettler-Toledo-multi scales (Badger Brno, ...)
|
||||
//for (int i = 0; i < MettlerToledo.Multi.BalanceDev.BalancesCount; i++)
|
||||
//{
|
||||
// controlCom.SetWeight(i, MettlerToledo.Multi.BalanceDev.Masses[i]);
|
||||
//}
|
||||
|
||||
/// Tanks (CEVAK, ...)
|
||||
int firstTankIx = Math.Max(MettlerToledo.Standard.BalanceDev.BalancesCount, MettlerToledo.Multi.BalanceDev.BalancesCount);
|
||||
///// Tanks (CEVAK, ...)
|
||||
//int firstTankIx = Math.Max(MettlerToledo.Standard.BalanceDev.BalancesCount, MettlerToledo.Multi.BalanceDev.BalancesCount);
|
||||
|
||||
for (int i = 0; i < Various.TankWithLevelMsrmnt.Tank.TanksCount; i++)
|
||||
{
|
||||
controlCom.SetWeight(firstTankIx + i, Various.TankWithLevelMsrmnt.Tank.Tanks[i].Volume);
|
||||
}
|
||||
//for (int i = 0; i < Various.TankWithLevelMsrmnt.Tank.TanksCount; i++)
|
||||
//{
|
||||
// controlCom.SetWeight(firstTankIx + i, Various.TankWithLevelMsrmnt.Tank.Tanks[i].Volume);
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -31,44 +31,24 @@ namespace TBF.Rig.MettlerToledo.Standard
|
||||
/// </note>
|
||||
public class BalanceDev : TankDraining, IDevice, GenericDevices.IScale, GenericDevices.IHasCalendarEvents, IDrawingItCmpntWithMeasuredVal
|
||||
{
|
||||
/// <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("MettlerToledo.Standard.Balance({0})", Cfg.ToString(-1)); }
|
||||
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
|
||||
|
||||
/// Configuration and wrappers
|
||||
protected readonly BalanceCfg balanceCfg;
|
||||
public IDrawingItem DrawingItem { get { return balanceCfg as IDrawingItem; } }
|
||||
|
||||
/// <summary>
|
||||
/// Enumeration of balances via static fields and methods
|
||||
/// </summary>
|
||||
static int nextBalanceIdx = 0;
|
||||
public static new void ResetStaticProperties()
|
||||
{
|
||||
nextBalanceIdx = 0;
|
||||
}
|
||||
public static int BalancesCount { get { return nextBalanceIdx; } }
|
||||
public static BalanceDev[] Balances;
|
||||
public static double[] Masses;
|
||||
///
|
||||
protected int balanceNr; /// 0-based balance number
|
||||
|
||||
protected SerialPort serialPort;
|
||||
protected StringBuilder stringBuilder;
|
||||
|
||||
public int ScaleNr { get { return balanceNr; } }
|
||||
///
|
||||
public double Capacity { get { return balanceCfg.Capacity; } }
|
||||
public int EmptyTimeSec { get { return balanceCfg.DrainTimeSec; } }
|
||||
public IValve DrainValve2 { get { return null; } }
|
||||
|
||||
/// Buoyancy
|
||||
public IValve DrainValve2 { get { return null; } }
|
||||
public float BuoyancyTemp { get { return balanceCfg.BuoyancyTemp; } }
|
||||
public float BuoyancyPress { get { return balanceCfg.BuoyancyPress; } }
|
||||
public float BuoyancyHumi { get { return balanceCfg.BuoyancyHumi; } }
|
||||
public double WeightStandardDensity { get { return balanceCfg.WeightStandardDensity; } }
|
||||
///
|
||||
public IDrawingItem DrawingItem { get { return balanceCfg as IDrawingItem; } }
|
||||
|
||||
protected SerialPort serialPort;
|
||||
protected StringBuilder stringBuilder;
|
||||
|
||||
/// <summary>The state of the mass measurement</summary>
|
||||
public Activity Activity;
|
||||
@@ -104,18 +84,6 @@ namespace TBF.Rig.MettlerToledo.Standard
|
||||
: base(cfg)
|
||||
{
|
||||
balanceCfg = cfg as BalanceCfg;
|
||||
|
||||
balanceNr = nextBalanceIdx++;
|
||||
Masses = new double[nextBalanceIdx]; /// (re)initialize the static array of masses of all balances
|
||||
///
|
||||
if (Balances == null || Balances.Length < nextBalanceIdx)
|
||||
{
|
||||
BalanceDev[] balancesSoFar = Balances;
|
||||
Balances = new BalanceDev[nextBalanceIdx];
|
||||
if (balancesSoFar != null) for (int i = 0; i < balancesSoFar.Length; i++) Balances[i] = balancesSoFar[i];
|
||||
Balances[nextBalanceIdx - 1] = this;
|
||||
}
|
||||
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
@@ -123,24 +91,29 @@ namespace TBF.Rig.MettlerToledo.Standard
|
||||
{
|
||||
base.Initalize(); /// Initializes DrainValve, etc., should be called in DebugMode.Simulate
|
||||
|
||||
if (balanceCfg.DebugLevel == DebugMode.Simulate) return;
|
||||
Activity = Activity.Idle;
|
||||
msrmntState = MsrmntState.Failed; /// Data not valid yet
|
||||
MsrmntTime = 0;
|
||||
stringBuilder = new StringBuilder(40);
|
||||
|
||||
if (balanceCfg.CalibValidDate != DateTime.MinValue && balanceCfg.CalibValidDate.Date < DateTime.Now.Date)
|
||||
{
|
||||
throw new Exception(string.Format("{0}: {1}", Name, Strings.Calibration_certificate_validity_expired));
|
||||
}
|
||||
|
||||
Activity = Activity.Idle;
|
||||
msrmntState = MsrmntState.Failed; /// Data not valid yet
|
||||
MsrmntTime = 0;
|
||||
|
||||
stringBuilder = new StringBuilder(40);
|
||||
string comPortName = "COM" + balanceCfg.ComPortNr.ToString();
|
||||
serialPort = new SerialPort(comPortName, balanceCfg.BaudRate, balanceCfg.Parity, balanceCfg.DataBits, balanceCfg.StopBits);
|
||||
serialPort.Handshake = balanceCfg.Handshake;
|
||||
serialPort.Open();
|
||||
|
||||
log.FatalFormat("Successfully initialized device {0}", Name);
|
||||
if (balanceCfg.DebugLevel == DebugMode.Normal)
|
||||
{
|
||||
string comPortName = "COM" + balanceCfg.ComPortNr.ToString();
|
||||
serialPort = new SerialPort(comPortName, balanceCfg.BaudRate, balanceCfg.Parity, balanceCfg.DataBits, balanceCfg.StopBits);
|
||||
serialPort.Handshake = balanceCfg.Handshake;
|
||||
serialPort.Open();
|
||||
log.FatalFormat("{0} - Device successfully initialized", Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
serialPort = null;
|
||||
log.FatalFormat("{0} - Device simulated", Name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -315,7 +288,7 @@ namespace TBF.Rig.MettlerToledo.Standard
|
||||
|
||||
if (balanceCfg.DebugLevel == DebugMode.Simulate)
|
||||
{
|
||||
Masses[balanceNr] = 123.456;
|
||||
mass = 123.456;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
msrmntTimeStamp = StateMachine.Time;
|
||||
return;
|
||||
@@ -371,7 +344,6 @@ namespace TBF.Rig.MettlerToledo.Standard
|
||||
if (field.Length == 1 && field[0] == "ZA") /// Zero when stable
|
||||
{
|
||||
mass = 0;
|
||||
Masses[balanceNr] = mass;
|
||||
//msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("{0} - Balance response = \"{1}<cr><lf>\"", Name, received);
|
||||
return;
|
||||
@@ -388,7 +360,6 @@ namespace TBF.Rig.MettlerToledo.Standard
|
||||
if (field.Length == 2 && field[1] == "A")
|
||||
{
|
||||
mass = 0;
|
||||
Masses[balanceNr] = mass;
|
||||
//msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("{0} - Balance response = \"{1}<cr><lf>\"", Name, received);
|
||||
return;
|
||||
@@ -408,7 +379,6 @@ namespace TBF.Rig.MettlerToledo.Standard
|
||||
out mass))
|
||||
{
|
||||
mass = Config.Units.ConvertFrom(ParseUnit(field[2]), mass);
|
||||
Masses[balanceNr] = mass;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("{0} - Balance response = \"{1}<cr><lf>\", Mass = {2}", Name, received, mass);
|
||||
}
|
||||
@@ -419,14 +389,12 @@ namespace TBF.Rig.MettlerToledo.Standard
|
||||
out mass))
|
||||
{
|
||||
mass = Config.Units.ConvertFrom(ParseUnit(field[3]), mass);
|
||||
Masses[balanceNr] = mass;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("{0} - Balance response = \"{1}<cr><lf>\", Mass = {2}", Name, received, mass);
|
||||
}
|
||||
else if (field.Length == 2 && field[1] == "-")
|
||||
{
|
||||
mass = 0;
|
||||
Masses[balanceNr] = mass;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("{0} - Balance response = \"{1}<cr><lf>\", Mass = {2}", Name, received, mass);
|
||||
}
|
||||
@@ -447,14 +415,12 @@ namespace TBF.Rig.MettlerToledo.Standard
|
||||
out mass))
|
||||
{
|
||||
mass = Config.Units.ConvertFrom(ParseUnit(field[2]), mass);
|
||||
Masses[balanceNr] = mass;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("{0} - Balance response = \"{1}<cr><lf>\", Mass = {2}", Name, received, mass);
|
||||
}
|
||||
else if (field.Length == 2 && field[1] == "-")
|
||||
{
|
||||
mass = 0;
|
||||
Masses[balanceNr] = mass;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("{0} - Balance response = \"{1}<cr><lf>\", Mass = {2}", Name, received, mass);
|
||||
}
|
||||
|
||||
@@ -17,25 +17,19 @@ namespace TBF.Rig.MettlerToledo.Standard
|
||||
/// </note>
|
||||
public class BalanceNewDev : BalanceDev, IDevice, GenericDevices.IScale
|
||||
{
|
||||
/// <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("MettlerToledo.Standard.BalanceNew({0})", Cfg.ToString(-1)); }
|
||||
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
|
||||
|
||||
/// <summary>Serial number after GetSerialNumber() when MsrmntState == MsrmntState.Valid</summary>
|
||||
public string SerialNumber { get { return serialNumber; } }
|
||||
string serialNumber;
|
||||
|
||||
public BalanceNewDev()
|
||||
{
|
||||
}
|
||||
|
||||
public BalanceNewDev() { }
|
||||
|
||||
public BalanceNewDev(Generic.IComponentCfg cfg)
|
||||
: base(cfg)
|
||||
{
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -68,7 +62,6 @@ namespace TBF.Rig.MettlerToledo.Standard
|
||||
if (balanceCfg.DebugLevel == DebugMode.Simulate)
|
||||
{
|
||||
mass = 0.456;
|
||||
Masses[balanceNr] = mass;
|
||||
serialNumber = "1234567890";
|
||||
msrmntState = MsrmntState.Valid;
|
||||
msrmntTimeStamp = StateMachine.Time;
|
||||
@@ -140,7 +133,6 @@ namespace TBF.Rig.MettlerToledo.Standard
|
||||
if (field.Length == 2 && field[1] == "A")
|
||||
{
|
||||
mass = 0;
|
||||
Masses[balanceNr] = mass;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.WarnFormat("{0} - Balance response = {1}", Name,
|
||||
received.Replace("\r", "<cr>").Replace("\n", "<lf>"));
|
||||
@@ -159,7 +151,6 @@ namespace TBF.Rig.MettlerToledo.Standard
|
||||
CultureInfo.InvariantCulture, out mass))
|
||||
{
|
||||
mass = Config.Units.ConvertFrom(ParseUnit(field[3]), mass);
|
||||
Masses[balanceNr] = mass;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("{0} - Balance response = {1}, Mass = {2}", Name,
|
||||
received.Replace("\r", "<cr>").Replace("\n", "<lf>"), mass);
|
||||
@@ -240,7 +231,6 @@ namespace TBF.Rig.MettlerToledo.Standard
|
||||
if (field.Length >= 2 && field[1] == "I")
|
||||
{
|
||||
mass = balanceCfg.Capacity;
|
||||
Masses[balanceNr] = mass;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
//msrmntState = MsrmntState.Overload;
|
||||
log.WarnFormat("{0} - Balance response = \"{1}\", Overload.", Name,
|
||||
|
||||
@@ -20,19 +20,15 @@ namespace TBF.Rig.MettlerToledo.Standard
|
||||
/// </note>
|
||||
public class BalanceOld : BalanceDev, IDevice, GenericDevices.IScale
|
||||
{
|
||||
/// <summary>
|
||||
/// Info: StartMassMeasurement() and "Balnce response = .., Mass = ..."
|
||||
/// Warn: Start measurement when busy is true
|
||||
/// </summary>
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(BalanceOld));
|
||||
public override string ToString() { return string.Format("MettlerToledo.Standard.BalanceOld({0})", Cfg.ToString(-1)); }
|
||||
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
|
||||
|
||||
|
||||
public BalanceOld() { }
|
||||
|
||||
public BalanceOld(Generic.IComponentCfg cfg)
|
||||
: base(cfg)
|
||||
{
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +48,6 @@ namespace TBF.Rig.MettlerToledo.Standard
|
||||
if (balanceCfg.DebugLevel == DebugMode.Simulate)
|
||||
{
|
||||
mass = 123.456;
|
||||
Masses[balanceNr] = mass;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
msrmntTimeStamp = StateMachine.Time;
|
||||
return;
|
||||
@@ -105,7 +100,6 @@ namespace TBF.Rig.MettlerToledo.Standard
|
||||
if (field.Length == 2 && field[1] == "A")
|
||||
{
|
||||
mass = 0;
|
||||
Masses[balanceNr] = mass;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("{0} - Balance response = {1}", Name,
|
||||
received.Replace("\r", "<cr>").Replace("\n", "<lf>"));
|
||||
@@ -124,7 +118,6 @@ namespace TBF.Rig.MettlerToledo.Standard
|
||||
CultureInfo.InvariantCulture, out mass))
|
||||
{
|
||||
mass = Config.Units.ConvertFrom(ParseUnit(field[3]), mass);
|
||||
Masses[balanceNr] = mass;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("{0} - Balance response = {1}, Mass = {2}", Name,
|
||||
received.Replace("\r", "<cr>").Replace("\n", "<lf>"), mass);
|
||||
@@ -134,7 +127,6 @@ namespace TBF.Rig.MettlerToledo.Standard
|
||||
CultureInfo.InvariantCulture, out mass))
|
||||
{
|
||||
mass = Config.Units.ConvertFrom(ParseUnit(field[3]), mass);
|
||||
Masses[balanceNr] = mass;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("{0} - Balance response = {1}, Mass = {2}", Name,
|
||||
received.Replace("\r", "<cr>").Replace("\n", "<lf>"), mass);
|
||||
@@ -142,7 +134,6 @@ namespace TBF.Rig.MettlerToledo.Standard
|
||||
else if (field.Length == 2 && field[1] == "-")
|
||||
{
|
||||
mass = 0;
|
||||
Masses[balanceNr] = mass;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("{0} - Balance response = {1}, Mass = {2}", Name,
|
||||
received.Replace("\r", "<cr>").Replace("\n", "<lf>"), mass);
|
||||
@@ -150,7 +141,6 @@ namespace TBF.Rig.MettlerToledo.Standard
|
||||
else if (field.Length == 2 && field[1] == "+")
|
||||
{
|
||||
mass = Capacity;
|
||||
Masses[balanceNr] = mass;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("{0} - Balance response = {1}, Overload", Name,
|
||||
received.Replace("\r", "<cr>").Replace("\n", "<lf>"));
|
||||
@@ -158,7 +148,6 @@ namespace TBF.Rig.MettlerToledo.Standard
|
||||
else if (field.Length >= 2 && field[1] == "I")
|
||||
{
|
||||
mass = balanceCfg.Capacity;
|
||||
Masses[balanceNr] = mass;
|
||||
msrmntState = MsrmntState.Overload;
|
||||
log.InfoFormat("{0} - Balance response = {1}, Overload", Name,
|
||||
received.Replace("\r", "<cr>").Replace("\n", "<lf>"), mass);
|
||||
@@ -215,7 +204,6 @@ namespace TBF.Rig.MettlerToledo.Standard
|
||||
if (field.Length >= 2 && field[1] == "I")
|
||||
{
|
||||
mass = balanceCfg.Capacity;
|
||||
Masses[balanceNr] = mass;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
//msrmntState = MsrmntState.Overload;
|
||||
log.WarnFormat("{0} - Balance response = \"{1}\", Overload.", Name,
|
||||
|
||||
+4
-3
@@ -322,9 +322,10 @@ namespace TBF.UI
|
||||
|
||||
/// Initialize bench control user interface(s)
|
||||
BenchControlPanel = new BenchControlPanel();
|
||||
BenchControlPanel.BalancesCount = TBF.Rig.MettlerToledo.Standard.BalanceDev.BalancesCount
|
||||
+ TBF.Rig.MettlerToledo.Multi.BalanceDev.BalancesCount
|
||||
+ TBF.Rig.Various.TankWithLevelMsrmnt.Tank.TanksCount;
|
||||
BenchControlPanel.BalancesCount = TBF.Rig.StateMachine.Tank3 != null ? 3
|
||||
: TBF.Rig.StateMachine.Tank2 != null ? 2
|
||||
: TBF.Rig.StateMachine.Tank1 != null ? 1
|
||||
: 0;
|
||||
new System.ComponentModel.ComponentResourceManager(typeof(MainWnd)).ApplyResources(BenchControlPanel, "benchControlPanel");
|
||||
BenchControlPanel.Name = "benchControlPanel";
|
||||
rightHorizSplitContainer.Panel2.Controls.Add(BenchControlPanel);
|
||||
|
||||
Reference in New Issue
Block a user