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