MettlerToledo.Standard.BalanceDev processes ID1 commands (only), ver. 3.1.1746
This commit is contained in:
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("3.1.1740.0")]
|
||||
[assembly: AssemblyFileVersion("3.1.1740.0")]
|
||||
[assembly: AssemblyVersion("3.1.1746.0")]
|
||||
[assembly: AssemblyFileVersion("3.1.1746.0")]
|
||||
|
||||
@@ -85,7 +85,6 @@ namespace TBF.Rig.MettlerToledo.Standard
|
||||
: base(cfg)
|
||||
{
|
||||
balanceCfg = cfg as BalanceCfg;
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
@@ -315,164 +314,129 @@ namespace TBF.Rig.MettlerToledo.Standard
|
||||
{
|
||||
log.DebugFormat("{0} - RunDeviceBefore() received {1}", Name, justReceived);
|
||||
stringBuilder.Append(justReceived);
|
||||
}
|
||||
|
||||
string currentBuffer = stringBuilder.ToString();
|
||||
int eolPos = currentBuffer.IndexOf("\r\n");
|
||||
if (eolPos >= 0)
|
||||
{
|
||||
msrmntTimeStamp = StateMachine.Time;
|
||||
|
||||
/// Get part of the string before EOL
|
||||
string received = currentBuffer.Substring(0, eolPos);
|
||||
|
||||
/// Put the rest back to the string builder
|
||||
stringBuilder.Clear();
|
||||
if (currentBuffer.Length > eolPos + 2)
|
||||
if (stringBuilder.ToString().EndsWith("\r\n"))
|
||||
{
|
||||
stringBuilder.Append(currentBuffer.Substring(eolPos + 2));
|
||||
}
|
||||
msrmntTimeStamp = StateMachine.Time;
|
||||
|
||||
while (true)
|
||||
{
|
||||
string tmp = received.Replace(" ", " ");
|
||||
if (tmp.Length == received.Length) break;
|
||||
received = tmp;
|
||||
}
|
||||
string received = stringBuilder.ToString();
|
||||
|
||||
string[] field = received.Split(new char[] { ' ' });
|
||||
|
||||
if (field.Length == 1 && field[0] == "ZA") /// Zero when stable
|
||||
{
|
||||
mass = 0;
|
||||
//msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("{0} - Balance response = \"{1}<cr><lf>\"", Name, received);
|
||||
return;
|
||||
}
|
||||
else if (field.Length < 2)
|
||||
{
|
||||
msrmntState = MsrmntState.Failed;
|
||||
log.WarnFormat("{0} - Balance response = \"{1}<cr><lf>\", Unexpected error !!!", Name, received);
|
||||
return;
|
||||
}
|
||||
|
||||
if (field[0] == "Z") /// Zero when stable
|
||||
{
|
||||
if (field.Length == 2 && field[1] == "A")
|
||||
{
|
||||
mass = 0;
|
||||
//msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("{0} - Balance response = \"{1}<cr><lf>\"", Name, received);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
msrmntState = MsrmntState.Failed;
|
||||
log.WarnFormat("{0} - Balance response = \"{1}<cr><lf>\", error !!!", Name, received);
|
||||
}
|
||||
}
|
||||
else if (field[0] == "S") /// Stable mass: field[1] = <mass> field[2] = "kg"
|
||||
{
|
||||
if (field.Length == 3 &&
|
||||
double.TryParse(field[1],
|
||||
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign,
|
||||
CultureInfo.InvariantCulture,
|
||||
out mass))
|
||||
{
|
||||
mass = Common.Units.ConvertFrom(ParseUnit(field[2]), mass);
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("{0} - Balance response = \"{1}<cr><lf>\", Mass = {2}", Name, received, mass);
|
||||
}
|
||||
else if (field.Length == 4 && (field[1] == "S" || field[1] == "D") &&
|
||||
double.TryParse(field[2],
|
||||
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign,
|
||||
CultureInfo.InvariantCulture,
|
||||
out mass))
|
||||
/// Eliminate double spaces in the received string
|
||||
while (true)
|
||||
{
|
||||
mass = Common.Units.ConvertFrom(ParseUnit(field[3]), mass);
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("{0} - Balance response = \"{1}<cr><lf>\", Mass = {2}", Name, received, mass);
|
||||
string tmp = received.Replace(" ", " ");
|
||||
if (tmp.Length == received.Length) break;
|
||||
received = tmp;
|
||||
}
|
||||
else if (field.Length == 2 && field[1] == "-")
|
||||
{
|
||||
mass = 0;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("{0} - Balance response = \"{1}<cr><lf>\", Mass = {2}", Name, received, mass);
|
||||
}
|
||||
else
|
||||
{
|
||||
msrmntState = MsrmntState.Failed;
|
||||
log.WarnFormat("{0} Balance response = \"{1}<cr><lf>\", Overload or and unexpected error !!!", Name, received);
|
||||
bool b = double.TryParse(field[1], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out mass);
|
||||
|
||||
}
|
||||
}
|
||||
else if (field[0] == "SD") /// Dynamic mass: field[1] = <mass> field[2] = "kg"
|
||||
{
|
||||
if (field.Length >= 3 &&
|
||||
double.TryParse(field[1],
|
||||
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign,
|
||||
CultureInfo.InvariantCulture,
|
||||
out mass))
|
||||
{
|
||||
mass = Common.Units.ConvertFrom(ParseUnit(field[2]), mass);
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("{0} - Balance response = \"{1}<cr><lf>\", Mass = {2}", Name, received, mass);
|
||||
}
|
||||
else if (field.Length == 2 && field[1] == "-")
|
||||
string[] field = received.Substring(0, received.Length - 2).Split(new char[] { ' ' });
|
||||
|
||||
///--------
|
||||
/// Zero
|
||||
///--------
|
||||
if (field.Length == 1 && field[0] == "ZB")
|
||||
{
|
||||
/// Zero command successful, reading is 0 now
|
||||
mass = 0;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("{0} - Balance response = \"{1}<cr><lf>\", Mass = {2}", Name, received, mass);
|
||||
}
|
||||
else
|
||||
else if (field.Length == 1 && field[0] == "Z-")
|
||||
{
|
||||
/// Zero command cannot be executed : Below lower limit of zero set range
|
||||
mass = 0;
|
||||
msrmntState = MsrmntState.Failed;
|
||||
log.WarnFormat("{0} - Balance response = \"{1}<cr><lf>\", Overload or and unexpected error !!!", Name, received);
|
||||
bool b = double.TryParse(field[1], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out mass);
|
||||
}
|
||||
else if (field.Length == 1 && field[0] == "Z+")
|
||||
{
|
||||
/// Zero command cannot be executed : Above upper limit of zero set range
|
||||
mass = 0;
|
||||
msrmntState = MsrmntState.Overload;
|
||||
}
|
||||
///--------
|
||||
/// Tare
|
||||
///--------
|
||||
else if (field.Length >= 3 && field[0] == "TB")
|
||||
{
|
||||
/// Tare command successful : response is "TB value unit\r\n"
|
||||
double m;
|
||||
if (double.TryParse(field[1],
|
||||
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign,
|
||||
CultureInfo.InvariantCulture,
|
||||
out m))
|
||||
{
|
||||
mass = Common.Units.ConvertFrom(ParseUnit(field[2]), m);
|
||||
msrmntState = MsrmntState.Valid;
|
||||
}
|
||||
else
|
||||
{
|
||||
msrmntState = MsrmntState.Failed;
|
||||
}
|
||||
}
|
||||
else if (field.Length == 1 && field[0] == "T-")
|
||||
{
|
||||
/// Tare command cannot be executed : Below lower limit of zero set range
|
||||
mass = 0;
|
||||
msrmntState = MsrmntState.Failed;
|
||||
}
|
||||
else if (field.Length == 1 && field[0] == "T+")
|
||||
{
|
||||
/// Tare command cannot be executed : Above upper limit of zero set range
|
||||
mass = 0;
|
||||
msrmntState = MsrmntState.Overload;
|
||||
}
|
||||
///--------------------
|
||||
/// Mass measurement
|
||||
///--------------------
|
||||
else if (field.Length >= 3 && (field[0] == "S" || field[0] == "SD")) /// Stable mass: field[1] = <mass> field[2] = "kg"
|
||||
{
|
||||
double m;
|
||||
if (double.TryParse(field[1],
|
||||
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign,
|
||||
CultureInfo.InvariantCulture,
|
||||
out m))
|
||||
{
|
||||
mass = Common.Units.ConvertFrom(ParseUnit(field[2]), m);
|
||||
msrmntState = MsrmntState.Valid;
|
||||
}
|
||||
else
|
||||
{
|
||||
msrmntState = MsrmntState.Failed;
|
||||
}
|
||||
}
|
||||
else if (field.Length == 1 && field[0] == "SI")
|
||||
{
|
||||
/// Invalid value
|
||||
mass = 0;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
}
|
||||
else if (field.Length == 1 && field[0] == "SI-")
|
||||
{
|
||||
/// Invalid value : Scale is in underload range
|
||||
mass = 0;
|
||||
msrmntState = MsrmntState.Failed;
|
||||
}
|
||||
else if (field.Length == 1 && field[0] == "SI+")
|
||||
{
|
||||
/// Invalid value : Scale is in overload range
|
||||
mass = 0;
|
||||
msrmntState = MsrmntState.Overload;
|
||||
}
|
||||
///
|
||||
/// Other responses are ignored
|
||||
///
|
||||
|
||||
}
|
||||
}
|
||||
else if (field[0] == "TB") /// Taring
|
||||
{
|
||||
if (field.Length >= 3 &&
|
||||
double.TryParse(field[1],
|
||||
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign,
|
||||
CultureInfo.InvariantCulture,
|
||||
out mass))
|
||||
{
|
||||
mass = Common.Units.ConvertFrom(ParseUnit(field[2]), mass);
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("{0} - Balance response = \"{1}<cr><lf>\", Tara = {2}", Name, received, mass);
|
||||
}
|
||||
else
|
||||
{
|
||||
msrmntState = MsrmntState.Failed;
|
||||
log.WarnFormat("{0} - Balance response = \"{1}<cr><lf>\", Overload or and unexpected error !!!", Name, received);
|
||||
}
|
||||
}
|
||||
else if (field[0] == "T") /// Taring
|
||||
{
|
||||
if (field.Length >= 4 && field[1] == "S" &&
|
||||
double.TryParse(field[2],
|
||||
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign,
|
||||
CultureInfo.InvariantCulture,
|
||||
out mass))
|
||||
/// Logging
|
||||
if (field.Length > 0)
|
||||
{
|
||||
mass = Common.Units.ConvertFrom(ParseUnit(field[3]), mass);
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("{0} - Balance response = \"{1}<cr><lf>\", Tara = {2}", Name, received, mass);
|
||||
if (msrmntState == MsrmntState.Valid || msrmntState == MsrmntState.Busy)
|
||||
{
|
||||
log.InfoFormat("{0} - Received \"{1}<cr><lf>\", Mass = {2}, MsrmntState = {3}", Name, received, mass, msrmntState);
|
||||
}
|
||||
else
|
||||
{
|
||||
log.ErrorFormat("{0} - Received \"{1}<cr><lf>\", Mass = {2}, MsrmntState = {3}", Name, received, mass, msrmntState);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
msrmntState = MsrmntState.Failed;
|
||||
log.WarnFormat("{0} - Balance response = \"{1}<cr><lf>\", Overload or and unexpected error !!!", Name, received);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
msrmntState = MsrmntState.Failed;
|
||||
log.WarnFormat("{0} - Balance response = \"{1}<cr><lf>\", Unexpected error !!!", Name, received);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace TBF.Rig.MettlerToledo.Standard
|
||||
return;
|
||||
}
|
||||
|
||||
log.DebugFormat("{0} - RunDevice()", Name);
|
||||
log.DebugFormat("{0} - RunDeviceBefore()", Name);
|
||||
|
||||
if (base.msrmntState != MsrmntState.Busy) return; /// No measurement in progress
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user