Completed MettlerToledo.Multi changes - ready for tests.
This commit is contained in:
@@ -133,6 +133,11 @@ namespace TBF.BenchControl.Elde
|
||||
for (int i = 0; i < MettlerToledo.Standard.BalanceDev.BalancesCount; i++)
|
||||
{
|
||||
controlCom.SetWeight(i, MettlerToledo.Standard.BalanceDev.Masses[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < MettlerToledo.Multi.BalanceDev.BalancesCount; i++)
|
||||
{
|
||||
controlCom.SetWeight(i, MettlerToledo.Multi.BalanceDev.Masses[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ namespace TBF.BenchControl.MettlerToledo.Multi
|
||||
/// Enumeration of balances via static fields and methods
|
||||
/// </summary>
|
||||
static int nextBalanceIdx = 0;
|
||||
static int currentBalanceIdx = 0;
|
||||
public static new void ResetStaticProperties()
|
||||
{
|
||||
nextBalanceIdx = 0;
|
||||
@@ -56,8 +57,7 @@ namespace TBF.BenchControl.MettlerToledo.Multi
|
||||
protected MsrmntState msrmntState;
|
||||
|
||||
/// <summary>The mass after StartMassMeasurement() when MsrmntState == MsrmntState.Valid</summary>
|
||||
public float Mass { get { return mass; } }
|
||||
protected float mass;
|
||||
public float Mass { get { return Masses[balanceNr]; } }
|
||||
|
||||
/// <summary>The time stamp after StartMassMeasurement() when MsrmntState == MsrmntState.Valid</summary>
|
||||
public int MsrmntTimeStamp { get { return msrmntTimeStamp; } }
|
||||
@@ -91,7 +91,7 @@ namespace TBF.BenchControl.MettlerToledo.Multi
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
msrmntState = MsrmntState.Failed; /// Data not valid yet
|
||||
msrmntState = MsrmntState.Busy; /// Data not valid yet
|
||||
|
||||
if (balanceCfg.DebugLevel == Entities.DebugMode.Simulate) return;
|
||||
|
||||
@@ -129,63 +129,6 @@ namespace TBF.BenchControl.MettlerToledo.Multi
|
||||
serialPort.Write("Z\r\n");
|
||||
}
|
||||
|
||||
public void Taring()
|
||||
{
|
||||
if (balanceCfg.DebugLevel == Entities.DebugMode.Simulate) return;
|
||||
|
||||
if (msrmntState == MsrmntState.Busy)
|
||||
{
|
||||
log.Warn("Taring() returns without starting taring the scale because measurementState == MeasurementState.Busy");
|
||||
return;
|
||||
}
|
||||
|
||||
log.Info("Taring()");
|
||||
|
||||
msrmntState = MsrmntState.Busy;
|
||||
stringBuilder.Clear();
|
||||
serialPort.Write("T\r\n");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a stable mass measurement
|
||||
/// </summary>
|
||||
public void GetStableMassMeasurement()
|
||||
{
|
||||
if (balanceCfg.DebugLevel == Entities.DebugMode.Simulate) return;
|
||||
|
||||
if (msrmntState == MsrmntState.Busy)
|
||||
{
|
||||
log.Warn("GetStableMassMeasurement() returns without starting a measurement because measurementState == MeasurementState.Busy");
|
||||
return;
|
||||
}
|
||||
|
||||
log.Info("GetStableMassMeasurement()");
|
||||
|
||||
msrmntState = MsrmntState.Busy;
|
||||
stringBuilder.Clear();
|
||||
serialPort.Write("S\r\n");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get an immediate mass measurement
|
||||
/// </summary>
|
||||
public void GetImmediateMassMeasurement()
|
||||
{
|
||||
if (balanceCfg.DebugLevel == Entities.DebugMode.Simulate) return;
|
||||
|
||||
if (msrmntState == MsrmntState.Busy)
|
||||
{
|
||||
log.Warn("GetImmediateMassMeasurement() returns without starting a measurement because measurementState == MeasurementState.Busy");
|
||||
return;
|
||||
}
|
||||
|
||||
log.Info("GetImmediateMassMeasurement()");
|
||||
|
||||
msrmntState = MsrmntState.Busy;
|
||||
stringBuilder.Clear();
|
||||
serialPort.Write("SI\r\n");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse characters received from the serial port
|
||||
/// </summary>
|
||||
@@ -193,8 +136,7 @@ namespace TBF.BenchControl.MettlerToledo.Multi
|
||||
{
|
||||
if (balanceCfg.DebugLevel == Entities.DebugMode.Simulate)
|
||||
{
|
||||
mass = TestBenchSim.GetSimMass(balanceNr);
|
||||
Masses[balanceNr] = mass;
|
||||
Masses[balanceNr] = TestBenchSim.GetSimMass(balanceNr);
|
||||
msrmntState = MsrmntState.Valid;
|
||||
msrmntTimeStamp = StateMachine.Time;
|
||||
return;
|
||||
@@ -204,8 +146,6 @@ namespace TBF.BenchControl.MettlerToledo.Multi
|
||||
|
||||
log.Debug("RunDevice()");
|
||||
|
||||
if (msrmntState != MsrmntState.Busy) return; /// No measurement in progress
|
||||
|
||||
string justReceived = serialPort.ReadExisting();
|
||||
if (justReceived != null && justReceived.Length > 0)
|
||||
{
|
||||
@@ -238,119 +178,37 @@ namespace TBF.BenchControl.MettlerToledo.Multi
|
||||
|
||||
string[] fields = received.Split(new char[] { ' ' });
|
||||
|
||||
if (fields.Length == 1 && fields[0].Equals("ZA")) /// Zero when stable
|
||||
if (fields.Length == 2 && fields[0].Equals("&")) /// Zero when stable
|
||||
{
|
||||
mass = 0;
|
||||
Masses[balanceNr] = mass;
|
||||
//msrmntState = MsrmntState.Valid;
|
||||
msrmntState = MsrmntState.Failed;
|
||||
log.InfoFormat("Balance response = \"{0}<cr><lf>\"", received);
|
||||
return;
|
||||
}
|
||||
else if (fields.Length < 2)
|
||||
else if (fields.Length == 3)
|
||||
{
|
||||
float tmpMass;
|
||||
if (float.TryParse(fields[1],
|
||||
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign,
|
||||
CultureInfo.InvariantCulture,
|
||||
out tmpMass))
|
||||
{
|
||||
Masses[currentBalanceIdx] = tmpMass / 100.0f;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("Balance response = \"{0}<cr><lf>\", Mass = {1}", received, tmpMass);
|
||||
}
|
||||
|
||||
msrmntState = MsrmntState.Failed;
|
||||
log.WarnFormat("Balance response = \"{0}<cr><lf>\", Unexpected error !!!", received);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fields[0].Equals("Z")) /// Zero when stable
|
||||
{
|
||||
if (fields.Length == 2 && fields[1].Equals("A"))
|
||||
{
|
||||
mass = 0;
|
||||
Masses[balanceNr] = mass;
|
||||
//msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("Balance response = \"{0}<cr><lf>\"", received);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
msrmntState = MsrmntState.Failed;
|
||||
log.WarnFormat("Balance response = \"{0}<cr><lf>\", error !!!", received);
|
||||
}
|
||||
}
|
||||
else if (fields[0].Equals("S")) /// Stable mass: field[1] = <mass> field[2] = "kg"
|
||||
{
|
||||
if (fields.Length >= 3 &&
|
||||
float.TryParse(fields[1],
|
||||
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign,
|
||||
CultureInfo.InvariantCulture,
|
||||
out mass))
|
||||
{
|
||||
if (fields[2].Equals("g")) mass /= 1000.0f;
|
||||
if (fields[2].Equals("t")) mass *= 1000.0f;
|
||||
Masses[balanceNr] = mass;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("Balance response = \"{0}<cr><lf>\", Mass = {1}", received, mass);
|
||||
}
|
||||
else if (fields.Length == 2 && fields[1].Equals("-"))
|
||||
{
|
||||
mass = 0;
|
||||
Masses[balanceNr] = mass;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("Balance response = \"{0}<cr><lf>\", Mass = {1}", received, mass);
|
||||
}
|
||||
else
|
||||
{
|
||||
msrmntState = MsrmntState.Failed;
|
||||
log.WarnFormat("Balance response = \"{0}<cr><lf>\", Overload or and unexpected error !!!", received);
|
||||
bool b = float.TryParse(fields[1], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out mass);
|
||||
|
||||
}
|
||||
}
|
||||
else if (fields[0].Equals("SD")) /// Dynamic mass: field[1] = <mass> field[2] = "kg"
|
||||
{
|
||||
if (fields.Length >= 3 &&
|
||||
float.TryParse(fields[1],
|
||||
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign,
|
||||
CultureInfo.InvariantCulture,
|
||||
out mass))
|
||||
{
|
||||
if (fields[2].Equals("g")) mass /= 1000.0f;
|
||||
if (fields[2].Equals("t")) mass *= 1000.0f;
|
||||
Masses[balanceNr] = mass;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("Balance response = \"{0}<cr><lf>\", Mass = {1}", received, mass);
|
||||
}
|
||||
else if (fields.Length == 2 && fields[1].Equals("-"))
|
||||
{
|
||||
mass = 0;
|
||||
Masses[balanceNr] = mass;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("Balance response = \"{0}<cr><lf>\", Mass = {1}", received, mass);
|
||||
}
|
||||
else
|
||||
{
|
||||
msrmntState = MsrmntState.Failed;
|
||||
log.WarnFormat("Balance response = \"{0}<cr><lf>\", Overload or and unexpected error !!!", received);
|
||||
bool b = float.TryParse(fields[1], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out mass);
|
||||
|
||||
}
|
||||
}
|
||||
else if (fields[0].Equals("TB")) /// Taring
|
||||
{
|
||||
if (fields.Length >= 3 &&
|
||||
float.TryParse(fields[1],
|
||||
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign,
|
||||
CultureInfo.InvariantCulture,
|
||||
out mass))
|
||||
{
|
||||
if (fields[2].Equals("g")) mass /= 1000.0f;
|
||||
if (fields[2].Equals("t")) mass *= 1000.0f;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("Balance response = \"{0}<cr><lf>\", Tara = {1}", received, mass);
|
||||
}
|
||||
else
|
||||
{
|
||||
msrmntState = MsrmntState.Failed;
|
||||
log.WarnFormat("Balance response = \"{0}<cr><lf>\", Overload or and unexpected error !!!", received);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
msrmntState = MsrmntState.Failed;
|
||||
log.WarnFormat("Balance response = \"{0}<cr><lf>\", Unexpected error !!!", received);
|
||||
}
|
||||
|
||||
if (++currentBalanceIdx >= nextBalanceIdx)
|
||||
{
|
||||
currentBalanceIdx = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ namespace TBF.BenchControl.MettlerToledo.Multi
|
||||
public void Start()
|
||||
{
|
||||
done = false;
|
||||
balanceDev.GetImmediateMassMeasurement();
|
||||
}
|
||||
|
||||
/// <summary>Run this operation</summary>
|
||||
@@ -55,7 +54,6 @@ namespace TBF.BenchControl.MettlerToledo.Multi
|
||||
result.Val = balanceDev.Mass;
|
||||
done = true;
|
||||
log.InfoFormat("ReadMassOp.Run() ... mass={0} ... returning Event.BalanceDone", balanceDev.Mass);
|
||||
balanceDev.GetImmediateMassMeasurement(); /// Start another measurement
|
||||
return Event.BalanceDone; /// Mass read OK
|
||||
}
|
||||
else if (done)
|
||||
@@ -64,7 +62,7 @@ namespace TBF.BenchControl.MettlerToledo.Multi
|
||||
}
|
||||
else
|
||||
{
|
||||
return Event.None;
|
||||
return Event.Busy;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,6 @@ namespace TBF.BenchControl.MettlerToledo.Multi
|
||||
{
|
||||
currentReadingsCount = 0;
|
||||
massReadings = new float[totalReadingsCount];
|
||||
balanceDev.GetStableMassMeasurement();
|
||||
}
|
||||
|
||||
/// <summary>Run this operation</summary>
|
||||
@@ -83,7 +82,6 @@ namespace TBF.BenchControl.MettlerToledo.Multi
|
||||
}
|
||||
}
|
||||
|
||||
balanceDev.GetStableMassMeasurement();
|
||||
return Event.None;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ namespace TBF.BenchControl.MettlerToledo.Multi
|
||||
public void Start()
|
||||
{
|
||||
done = false;
|
||||
balanceDev.Taring();
|
||||
}
|
||||
|
||||
/// <summary>Run this operation</summary>
|
||||
@@ -67,7 +66,6 @@ namespace TBF.BenchControl.MettlerToledo.Multi
|
||||
return Event.BalanceDone; /// Taring completed
|
||||
}
|
||||
|
||||
balanceDev.Taring(); /// Failed -> repeat taring
|
||||
return Event.Busy;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,10 +32,6 @@ namespace TBF.BenchControl.MettlerToledo
|
||||
for (int i = 0; i < Standard.BalanceDev.BalancesCount; i++)
|
||||
{
|
||||
Standard.BalanceDev.Balances[i].GetImmediateMassMeasurement();
|
||||
}
|
||||
for (int i = 0; i < Multi.BalanceDev.BalancesCount; i++)
|
||||
{
|
||||
Multi.BalanceDev.Balances[i].GetImmediateMassMeasurement();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user