579 lines
22 KiB
C#
579 lines
22 KiB
C#
///
|
|
/// Copyright (c) 2013-2021 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Text;
|
|
using System.IO.Ports;
|
|
using log4net;
|
|
using Config.Entities;
|
|
using SchematicDrawing;
|
|
using TBF.Rig.Generic;
|
|
using TBF.Rig.GenericDevices;
|
|
using TBF.Boxes;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.Rig.MettlerToledo.Standard
|
|
{
|
|
public enum Activity
|
|
{
|
|
Idle,
|
|
ImmediateMeasurement,
|
|
RunningOperation,
|
|
}
|
|
|
|
/// <summary>
|
|
/// Mettler Toledo ICS4_5 Weighting terminal connected via serial interface (RS232)
|
|
/// </summary>
|
|
/// <note>
|
|
/// Implemented and tested on 15.10.2013 by Milan Hanajik
|
|
/// </note>
|
|
public class BalanceDev : TankDraining, IDevice, GenericDevices.IScale, GenericDevices.IHasCalendarEvents, IDrawingItCmpntWithMeasuredVal
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(BalanceDev));
|
|
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
|
|
|
|
/// Configuration and wrappers
|
|
protected readonly BalanceCfg balanceCfg;
|
|
///
|
|
public double Capacity { get { return balanceCfg.Capacity; } }
|
|
public int EmptyTimeSec { get { return balanceCfg.DrainTimeSec; } }
|
|
public IValve DrainValve2 { get { return null; } }
|
|
public float BuoyancyTemp { get { return balanceCfg.BuoyancyTemp; } }
|
|
public float BuoyancyPress { get { return balanceCfg.BuoyancyPress; } }
|
|
public float BuoyancyHumi { get { return balanceCfg.BuoyancyHumi; } }
|
|
public double WeightStandardDensity { get { return balanceCfg.WeightStandardDensity; } }
|
|
///
|
|
public IDrawingItem DrawingItem { get { return balanceCfg as IDrawingItem; } }
|
|
|
|
protected SerialPort serialPort;
|
|
protected StringBuilder stringBuilder;
|
|
|
|
/// <summary>The state of the mass measurement</summary>
|
|
public Activity Activity;
|
|
public MsrmntState MsrmntState { get { return msrmntState; } set { msrmntState = value; } }
|
|
protected MsrmntState msrmntState;
|
|
|
|
/// <summary>Time since the last serial command in seconds</summary>
|
|
public int MsrmntTime;
|
|
|
|
/// <summary>The mass after StartMassMeasurement() when MsrmntState == MsrmntState.Valid</summary>
|
|
public double Mass { get { return mass; } }
|
|
protected double mass;
|
|
|
|
public bool MsrmntAvailable { get { return true; } }
|
|
public double MeasuredVal { get { return mass; } }
|
|
public string AltString { get { return string.Empty; } }
|
|
|
|
/// <summary>The time stamp after StartMassMeasurement() when MsrmntState == MsrmntState.Valid</summary>
|
|
public int MsrmntTimeStamp { get { return msrmntTimeStamp; } }
|
|
protected int msrmntTimeStamp;
|
|
|
|
public string Format { get { return balanceCfg.MsrdFormat; } }
|
|
|
|
|
|
public BalanceDev() { }
|
|
|
|
/// <summary>
|
|
/// Constructor
|
|
/// </summary>
|
|
/// <param name="cfg">Balance properties</param>
|
|
/// <param components="cfg">A list of components loaded so far</param>
|
|
public BalanceDev(Generic.IComponentCfg cfg)
|
|
: base(cfg)
|
|
{
|
|
balanceCfg = cfg as BalanceCfg;
|
|
log.Warn(this.ToString());
|
|
}
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initalize(); /// Initializes DrainValve, etc., should be called in DebugMode.Simulate
|
|
|
|
Activity = Activity.Idle;
|
|
msrmntState = MsrmntState.Failed; /// Data not valid yet
|
|
MsrmntTime = 0;
|
|
stringBuilder = new StringBuilder(40);
|
|
|
|
if (balanceCfg.CalibValidDate != DateTime.MinValue && balanceCfg.CalibValidDate.Date < DateTime.Now.Date)
|
|
{
|
|
throw new Exception(string.Format("{0}: {1}", Name, Strings.Calibration_certificate_validity_expired));
|
|
}
|
|
|
|
if (balanceCfg.DebugLevel == DebugMode.Normal)
|
|
{
|
|
string comPortName = "COM" + balanceCfg.ComPortNr.ToString();
|
|
serialPort = new SerialPort(comPortName, balanceCfg.BaudRate, balanceCfg.Parity, balanceCfg.DataBits, balanceCfg.StopBits);
|
|
serialPort.Handshake = balanceCfg.Handshake;
|
|
serialPort.Open();
|
|
log.FatalFormat("{0} - Device successfully initialized", Name);
|
|
}
|
|
else
|
|
{
|
|
serialPort = null;
|
|
log.FatalFormat("{0} - Device simulated", Name);
|
|
}
|
|
}
|
|
|
|
|
|
public IList<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
|
|
{
|
|
DateTime calibrationDue = balanceCfg.CalibValidDate;
|
|
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = new List<Config.CalendarEvent.ICalendarEvent>();
|
|
|
|
if (calibrationDue > TBF.UI.Constants.MinDate)
|
|
{
|
|
/// Calibration due date calendar event
|
|
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name,
|
|
string.Format(Strings.Calibration_due_date_is_0,
|
|
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
|
|
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
|
|
{
|
|
/// Weekly reminders (last 5 weeks)
|
|
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name,
|
|
string.Format(Strings.Calibration_due_date_is_0,
|
|
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
|
|
false));
|
|
}
|
|
if (DateTime.Now.Date <= calibrationDue.Date)
|
|
{
|
|
/// Daily reminders (last 5 days)
|
|
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name,
|
|
string.Format(Strings.Calibration_due_date_is_0,
|
|
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
|
|
true));
|
|
}
|
|
}
|
|
return calendarEvents;
|
|
}
|
|
|
|
|
|
public override bool IsEmpty()
|
|
{
|
|
return DrainValve.State ? (mass <= balanceCfg.Empty) : (mass <= balanceCfg.EmptyUp);
|
|
}
|
|
|
|
public override bool ContainsMoreThen(float thld)
|
|
{
|
|
return (mass >= thld);
|
|
}
|
|
|
|
public virtual void SendZeroWhenStableCmd()
|
|
{
|
|
if (balanceCfg.DebugLevel == DebugMode.Simulate) return;
|
|
|
|
if (msrmntState == MsrmntState.Busy)
|
|
{
|
|
log.WarnFormat("{0} - ZeroWhenStable() returns without starting zeroing the scale because measurementState == MeasurementState.Busy", Name);
|
|
return;
|
|
}
|
|
|
|
log.InfoFormat("{0} - SendZeroWhenStableCmd() - \"Z\\r\\n\"", Name);
|
|
|
|
msrmntState = MsrmntState.Busy;
|
|
MsrmntTime = 0;
|
|
stringBuilder.Clear();
|
|
serialPort.Write("Z\r\n");
|
|
}
|
|
|
|
public virtual void SendTaraCmd()
|
|
{
|
|
if (balanceCfg.DebugLevel == DebugMode.Simulate) return;
|
|
|
|
if (msrmntState == MsrmntState.Busy)
|
|
{
|
|
log.WarnFormat("{0} - Taring() returns without starting taring the scale because measurementState == MeasurementState.Busy", Name);
|
|
return;
|
|
}
|
|
|
|
log.InfoFormat("{0} - SendTaraCmd() - - \"T\\r\\n\"", Name);
|
|
|
|
msrmntState = MsrmntState.Busy;
|
|
MsrmntTime = 0;
|
|
stringBuilder.Clear();
|
|
serialPort.Write("T\r\n");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get a stable mass measurement
|
|
/// </summary>
|
|
public void SendStableMeasurementCmd()
|
|
{
|
|
if (balanceCfg.DebugLevel == DebugMode.Simulate) return;
|
|
|
|
if (msrmntState == MsrmntState.Busy)
|
|
{
|
|
log.WarnFormat("{0} - GetStableMassMeasurement() returns without starting a measurement because measurementState == MeasurementState.Busy", Name);
|
|
return;
|
|
}
|
|
|
|
log.InfoFormat("{0} - SendStableMeasurementCmd() - \"S\\r\\n\"", Name);
|
|
|
|
msrmntState = MsrmntState.Busy;
|
|
MsrmntTime = 0;
|
|
stringBuilder.Clear();
|
|
serialPort.Write("S\r\n");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get an immediate mass measurement
|
|
/// </summary>
|
|
public void SendImmediateMeasurementCmd()
|
|
{
|
|
if (balanceCfg.DebugLevel == DebugMode.Simulate || serialPort == null) return;
|
|
|
|
if (msrmntState == MsrmntState.Busy)
|
|
{
|
|
log.WarnFormat("{0} - GetImmediateMassMeasurement() returns without starting a measurement because measurementState == MeasurementState.Busy", Name);
|
|
return;
|
|
}
|
|
|
|
log.InfoFormat("{0} - SendImmediateMeasurementCmd() - \"SI\\r\\n\"", Name);
|
|
|
|
msrmntState = MsrmntState.Busy;
|
|
MsrmntTime = 0;
|
|
stringBuilder.Clear();
|
|
serialPort.Write("SI\r\n");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the serial number
|
|
/// </summary>
|
|
/// <remarks>After a successful SetUnits(kg) mass is still sent in g. MH 15.10.2013</remarks>
|
|
public void SendSetUnitsCmd(Config.Unit unit)
|
|
{
|
|
if (balanceCfg.DebugLevel == DebugMode.Simulate) return;
|
|
|
|
if (msrmntState == MsrmntState.Busy)
|
|
{
|
|
log.WarnFormat("{0} - SetUnits() returns without setting the units because measurementState == MeasurementState.Busy", Name);
|
|
return;
|
|
}
|
|
|
|
msrmntState = MsrmntState.Busy;
|
|
stringBuilder.Clear();
|
|
switch (unit)
|
|
{
|
|
case Config.Unit.g:
|
|
log.InfoFormat("{0} - SetUnits({1}) - \"U g\\r\\n\"", Name, unit);
|
|
serialPort.Write("U g\r\n");
|
|
break;
|
|
case Config.Unit.t:
|
|
log.InfoFormat("{0} - SetUnits({1}) - \"U t\\r\\n\"", Name, unit);
|
|
serialPort.Write("U t\r\n");
|
|
break;
|
|
case Config.Unit.lb:
|
|
log.InfoFormat("{0} - SetUnits({1}) - \"U lb\\r\\n\"", Name, unit);
|
|
serialPort.Write("U lb\r\n");
|
|
break;
|
|
case Config.Unit.oz:
|
|
log.InfoFormat("{0} - SetUnits({1}) - \"U oz\\r\\n\"", Name, unit);
|
|
serialPort.Write("U oz\r\n");
|
|
break;
|
|
case Config.Unit.kg:
|
|
default:
|
|
log.InfoFormat("{0} - SetUnits({1}) - \"U kg\\r\\n\"", Name, unit);
|
|
serialPort.Write("U kg\r\n");
|
|
break;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Parse characters received from the serial port
|
|
/// </summary>
|
|
public virtual void RunDeviceBefore()
|
|
{
|
|
base.RunBefore();
|
|
|
|
if (balanceCfg.DebugLevel == DebugMode.Simulate)
|
|
{
|
|
mass = 123.456;
|
|
msrmntState = MsrmntState.Valid;
|
|
msrmntTimeStamp = StateMachine.Time;
|
|
return;
|
|
}
|
|
|
|
if (serialPort == null)
|
|
{
|
|
log.ErrorFormat("{0} - RunDevice() - serial port closed", Name);
|
|
return;
|
|
}
|
|
|
|
log.DebugFormat("{0} - RunDeviceBefore()", Name);
|
|
|
|
if (msrmntState != MsrmntState.Busy) return; /// No measurement in progress
|
|
///
|
|
if (Activity == Activity.ImmediateMeasurement)
|
|
{
|
|
Activity = Activity.Idle;
|
|
}
|
|
|
|
string justReceived = serialPort.ReadExisting();
|
|
if (justReceived != null && justReceived.Length > 0)
|
|
{
|
|
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)
|
|
{
|
|
stringBuilder.Append(currentBuffer.Substring(eolPos + 2));
|
|
}
|
|
|
|
while (true)
|
|
{
|
|
string tmp = received.Replace(" ", " ");
|
|
if (tmp.Length == received.Length) break;
|
|
received = tmp;
|
|
}
|
|
|
|
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 = Config.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 = Config.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] == "-")
|
|
{
|
|
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 = Config.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] == "-")
|
|
{
|
|
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] == "TB") /// Taring
|
|
{
|
|
if (field.Length >= 3 &&
|
|
double.TryParse(field[1],
|
|
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign,
|
|
CultureInfo.InvariantCulture,
|
|
out mass))
|
|
{
|
|
mass = Config.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))
|
|
{
|
|
mass = Config.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);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>Run this device</summary>
|
|
public void RunDeviceAfter()
|
|
{
|
|
if (Activity == Activity.Idle)
|
|
{
|
|
SendImmediateMeasurementCmd();
|
|
Activity = Activity.ImmediateMeasurement;
|
|
}
|
|
base.RunAfter();
|
|
}
|
|
|
|
/// <summary>Stop this device</summary>
|
|
public void StopDevice()
|
|
{
|
|
if ((balanceCfg.DebugLevel != DebugMode.Simulate) && (serialPort != null))
|
|
{
|
|
serialPort.Close();
|
|
serialPort = null;
|
|
}
|
|
}
|
|
|
|
public void StopDevice2() { }
|
|
|
|
/// <summary>
|
|
/// Events: BalanceDone, Error
|
|
/// </summary>
|
|
/// <returns>ZeroOp reference</returns>
|
|
public IOperation ZeroOp()
|
|
{
|
|
switch (balanceCfg.ActionAfter1stDraining)
|
|
{
|
|
case ActionA1D.Zero:
|
|
return new ZeroOp(this);
|
|
case ActionA1D.Tara:
|
|
DoubleBox dummy = new DoubleBox();
|
|
return new TaringOp(this, ref dummy);
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Events: BalanceDone, Error
|
|
/// </summary>
|
|
/// <param name="result">Reference to a variable for 'tara' in kg</param>
|
|
/// <returns>TaringOp reference</returns>
|
|
public IOperation TaringOp(ref DoubleBox tara)
|
|
{
|
|
return new TaringOp(this, ref tara);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Events: BalanceDone, Error
|
|
/// </summary>
|
|
/// <param name="result">Reference to a variable for the measured mass in kg</param>
|
|
/// <returns>ReadMassOp instance reference casted to IOperaton</returns>
|
|
public IOperation ReadMassOp(ref DoubleBox mass)
|
|
{
|
|
return new ReadMassOp(this, ref mass);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Events: BalanceDone, Error
|
|
/// </summary>
|
|
/// <param name="result">Reference to a variable for the measured mass in kg</param>
|
|
/// <param name="readingsCount">Required mass readings count (>= 3)</param>
|
|
/// <param name="maxSpread">Maximum spread of measurements in kg (otherwise the measurement continues)</param>
|
|
/// <param name="method">Method: false = slow (precise), true = fast (immediate)</param>
|
|
/// <returns>ReadMassAverageOp instance reference casted to IOperaton</returns>
|
|
public IOperation ReadStableMassOp(ref DoubleBox mass, int delayBefore, Config.Entities.MassMethod method, int readingsCount, double maxSpread)
|
|
{
|
|
return new ReadStableMassOp(this, ref mass, delayBefore, method, readingsCount, maxSpread);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Events: BalanceDone, Error
|
|
/// </summary>
|
|
/// <param name="serialNumber">Reference to the serialNumber</param>
|
|
/// <returns>GetBalanceSNOp instance reference casted to IOperaton</returns>
|
|
public virtual IOperation GetSerNumOp(ref string serialNumber)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Parse a string representing mass units.
|
|
/// Defaults to 'kg'in case unitStr not recognized.
|
|
/// </summary>
|
|
/// <param name="unitStr">String: "kg", "g", "t", "lb" or "oz" expected</param>
|
|
/// <returns></returns>
|
|
protected Config.Unit ParseUnit(string unitStr)
|
|
{
|
|
if (unitStr == "g") return Config.Unit.g;
|
|
if (unitStr == "t") return Config.Unit.t;
|
|
if (unitStr == "lb") return Config.Unit.lb;
|
|
if (unitStr == "oz") return Config.Unit.oz;
|
|
return Config.Unit.kg;
|
|
}
|
|
}
|
|
}
|