iPerlSpecial: larger scale (WT1) serial protocol fix, TODO: fix WT2 serial protocol.

This commit is contained in:
Milan Hanajik 2016-04-20 15:07:25 +02:00
parent e09aad2a6d
commit e88c34e2f4

View File

@ -313,7 +313,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
}
else if (fields[0].Equals("S")) /// Stable mass: field[1] = <mass> field[2] = "kg"
{
if (fields.Length >= 3 &&
if (fields.Length == 3 &&
float.TryParse(fields[1],
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign,
CultureInfo.InvariantCulture,
@ -325,7 +325,19 @@ namespace TBF.BenchControl.MettlerToledo.Standard
msrmntState = MsrmntState.Valid;
log.InfoFormat("{0} - Balance response = \"{1}<cr><lf>\", Mass = {2}", Name, received, mass);
}
else if (fields.Length == 2 && fields[1].Equals("-"))
else if (fields.Length == 4 && fields[1].Equals("S") &&
float.TryParse(fields[2],
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign,
CultureInfo.InvariantCulture,
out mass))
{
if (fields[3].Equals("g")) mass /= 1000.0f;
if (fields[3].Equals("t")) mass *= 1000.0f;
Masses[balanceNr] = mass;
msrmntState = MsrmntState.Valid;
log.InfoFormat("{0} - Balance response = \"{1}<cr><lf>\", Mass = {2}", Name, received, mass);
}
else if (fields.Length == 2 && fields[1].Equals("-"))
{
mass = 0;
Masses[balanceNr] = mass;
@ -388,7 +400,26 @@ namespace TBF.BenchControl.MettlerToledo.Standard
log.WarnFormat("{0} - Balance response = \"{1}<cr><lf>\", Overload or and unexpected error !!!", Name, received);
}
}
else
else if (fields[0].Equals("T")) /// Taring
{
if (fields.Length >= 4 && fields[1].Equals("S") &&
float.TryParse(fields[2],
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign,
CultureInfo.InvariantCulture,
out mass))
{
if (fields[3].Equals("g")) mass /= 1000.0f;
if (fields[3].Equals("t")) mass *= 1000.0f;
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);