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
|
// Build Number
|
||||||
// Revision
|
// Revision
|
||||||
//
|
//
|
||||||
[assembly: AssemblyVersion("3.1.1740.0")]
|
[assembly: AssemblyVersion("3.1.1746.0")]
|
||||||
[assembly: AssemblyFileVersion("3.1.1740.0")]
|
[assembly: AssemblyFileVersion("3.1.1746.0")]
|
||||||
|
|||||||
@@ -85,7 +85,6 @@ namespace TBF.Rig.MettlerToledo.Standard
|
|||||||
: base(cfg)
|
: base(cfg)
|
||||||
{
|
{
|
||||||
balanceCfg = cfg as BalanceCfg;
|
balanceCfg = cfg as BalanceCfg;
|
||||||
log.Warn(this.ToString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
@@ -315,24 +314,14 @@ namespace TBF.Rig.MettlerToledo.Standard
|
|||||||
{
|
{
|
||||||
log.DebugFormat("{0} - RunDeviceBefore() received {1}", Name, justReceived);
|
log.DebugFormat("{0} - RunDeviceBefore() received {1}", Name, justReceived);
|
||||||
stringBuilder.Append(justReceived);
|
stringBuilder.Append(justReceived);
|
||||||
}
|
|
||||||
|
|
||||||
string currentBuffer = stringBuilder.ToString();
|
if (stringBuilder.ToString().EndsWith("\r\n"))
|
||||||
int eolPos = currentBuffer.IndexOf("\r\n");
|
|
||||||
if (eolPos >= 0)
|
|
||||||
{
|
{
|
||||||
msrmntTimeStamp = StateMachine.Time;
|
msrmntTimeStamp = StateMachine.Time;
|
||||||
|
|
||||||
/// Get part of the string before EOL
|
string received = stringBuilder.ToString();
|
||||||
string received = currentBuffer.Substring(0, eolPos);
|
|
||||||
|
|
||||||
/// Put the rest back to the string builder
|
|
||||||
stringBuilder.Clear();
|
|
||||||
if (currentBuffer.Length > eolPos + 2)
|
|
||||||
{
|
|
||||||
stringBuilder.Append(currentBuffer.Substring(eolPos + 2));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/// Eliminate double spaces in the received string
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
string tmp = received.Replace(" ", " ");
|
string tmp = received.Replace(" ", " ");
|
||||||
@@ -340,139 +329,114 @@ namespace TBF.Rig.MettlerToledo.Standard
|
|||||||
received = tmp;
|
received = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] field = received.Split(new char[] { ' ' });
|
string[] field = received.Substring(0, received.Length - 2).Split(new char[] { ' ' });
|
||||||
|
|
||||||
if (field.Length == 1 && field[0] == "ZA") /// Zero when stable
|
///--------
|
||||||
{
|
/// Zero
|
||||||
mass = 0;
|
///--------
|
||||||
//msrmntState = MsrmntState.Valid;
|
if (field.Length == 1 && field[0] == "ZB")
|
||||||
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))
|
|
||||||
{
|
|
||||||
mass = Common.Units.ConvertFrom(ParseUnit(field[3]), mass);
|
|
||||||
msrmntState = MsrmntState.Valid;
|
|
||||||
log.InfoFormat("{0} - Balance response = \"{1}<cr><lf>\", Mass = {2}", Name, received, mass);
|
|
||||||
}
|
|
||||||
else if (field.Length == 2 && field[1] == "-")
|
|
||||||
{
|
{
|
||||||
|
/// Zero command successful, reading is 0 now
|
||||||
mass = 0;
|
mass = 0;
|
||||||
msrmntState = MsrmntState.Valid;
|
msrmntState = MsrmntState.Valid;
|
||||||
log.InfoFormat("{0} - Balance response = \"{1}<cr><lf>\", Mass = {2}", Name, received, mass);
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
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
|
else
|
||||||
{
|
{
|
||||||
msrmntState = MsrmntState.Failed;
|
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"
|
else if (field.Length == 1 && field[0] == "T-")
|
||||||
{
|
{
|
||||||
if (field.Length >= 3 &&
|
/// Tare command cannot be executed : Below lower limit of zero set range
|
||||||
double.TryParse(field[1],
|
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,
|
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign,
|
||||||
CultureInfo.InvariantCulture,
|
CultureInfo.InvariantCulture,
|
||||||
out mass))
|
out m))
|
||||||
{
|
{
|
||||||
mass = Common.Units.ConvertFrom(ParseUnit(field[2]), mass);
|
mass = Common.Units.ConvertFrom(ParseUnit(field[2]), m);
|
||||||
msrmntState = MsrmntState.Valid;
|
msrmntState = MsrmntState.Valid;
|
||||||
log.InfoFormat("{0} - Balance response = \"{1}<cr><lf>\", Mass = {2}", Name, received, mass);
|
|
||||||
}
|
}
|
||||||
else if (field.Length == 2 && field[1] == "-")
|
else
|
||||||
{
|
{
|
||||||
|
msrmntState = MsrmntState.Failed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (field.Length == 1 && field[0] == "SI")
|
||||||
|
{
|
||||||
|
/// Invalid value
|
||||||
mass = 0;
|
mass = 0;
|
||||||
msrmntState = MsrmntState.Valid;
|
msrmntState = MsrmntState.Valid;
|
||||||
log.InfoFormat("{0} - Balance response = \"{1}<cr><lf>\", Mass = {2}", Name, received, mass);
|
|
||||||
}
|
}
|
||||||
else
|
else if (field.Length == 1 && field[0] == "SI-")
|
||||||
{
|
{
|
||||||
|
/// Invalid value : Scale is in underload range
|
||||||
|
mass = 0;
|
||||||
msrmntState = MsrmntState.Failed;
|
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] == "SI+")
|
||||||
|
{
|
||||||
|
/// Invalid value : Scale is in overload range
|
||||||
|
mass = 0;
|
||||||
|
msrmntState = MsrmntState.Overload;
|
||||||
|
}
|
||||||
|
///
|
||||||
|
/// Other responses are ignored
|
||||||
|
///
|
||||||
|
|
||||||
}
|
/// Logging
|
||||||
}
|
if (field.Length > 0)
|
||||||
else if (field[0] == "TB") /// Taring
|
|
||||||
{
|
{
|
||||||
if (field.Length >= 3 &&
|
if (msrmntState == MsrmntState.Valid || msrmntState == MsrmntState.Busy)
|
||||||
double.TryParse(field[1],
|
|
||||||
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign,
|
|
||||||
CultureInfo.InvariantCulture,
|
|
||||||
out mass))
|
|
||||||
{
|
{
|
||||||
mass = Common.Units.ConvertFrom(ParseUnit(field[2]), mass);
|
log.InfoFormat("{0} - Received \"{1}<cr><lf>\", Mass = {2}, MsrmntState = {3}", Name, received, mass, msrmntState);
|
||||||
msrmntState = MsrmntState.Valid;
|
|
||||||
log.InfoFormat("{0} - Balance response = \"{1}<cr><lf>\", Tara = {2}", Name, received, mass);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
msrmntState = MsrmntState.Failed;
|
log.ErrorFormat("{0} - Received \"{1}<cr><lf>\", Mass = {2}, MsrmntState = {3}", Name, received, mass, msrmntState);
|
||||||
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))
|
|
||||||
{
|
|
||||||
mass = Common.Units.ConvertFrom(ParseUnit(field[3]), 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
|
|
||||||
{
|
|
||||||
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
log.DebugFormat("{0} - RunDevice()", Name);
|
log.DebugFormat("{0} - RunDeviceBefore()", Name);
|
||||||
|
|
||||||
if (base.msrmntState != MsrmntState.Busy) return; /// No measurement in progress
|
if (base.msrmntState != MsrmntState.Busy) return; /// No measurement in progress
|
||||||
///
|
///
|
||||||
|
|||||||
Reference in New Issue
Block a user