2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
2021-02-15 10:02:28 +00:00
|
|
|
|
/// Copyright (c) 2013-2021 Sensus Slovensko a.s.
|
2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
|
|
|
|
|
using System;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using log4net;
|
|
|
|
|
|
|
2021-10-26 09:23:57 +00:00
|
|
|
|
namespace TBF.Rig.MettlerToledo.Standard
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
public class SetUnitsOp : IOperation
|
|
|
|
|
|
{
|
|
|
|
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(SetUnitsOp));
|
|
|
|
|
|
public override string ToString() { return string.Format("SetUnitsOp({0})", units); }
|
|
|
|
|
|
|
|
|
|
|
|
/// Set by the constructor
|
2020-10-29 09:29:32 +00:00
|
|
|
|
BalanceDev scale;
|
2021-02-15 10:02:28 +00:00
|
|
|
|
Config.Unit units;
|
2020-10-29 09:29:32 +00:00
|
|
|
|
bool activityStarted;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Events: BalanceDone, Error
|
|
|
|
|
|
/// </summary>
|
2020-10-29 09:29:32 +00:00
|
|
|
|
/// <param name="scale">Balance device instance</param>
|
2014-07-28 07:54:35 +00:00
|
|
|
|
/// <param name="result">Reference to the serialNumber</param>
|
2021-02-15 10:02:28 +00:00
|
|
|
|
public SetUnitsOp(BalanceDev scale, Config.Unit units)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2020-10-29 09:29:32 +00:00
|
|
|
|
if (scale == null) throw new ArgumentNullException("balanceDev");
|
|
|
|
|
|
this.scale = scale;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
this.units = units;
|
|
|
|
|
|
|
|
|
|
|
|
log.Debug(this.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>Start this operation</summary>
|
|
|
|
|
|
public void Start()
|
|
|
|
|
|
{
|
2020-10-29 09:29:32 +00:00
|
|
|
|
log.DebugFormat("{0} - SetUnitsOp - Start()", scale.Name);
|
|
|
|
|
|
|
|
|
|
|
|
if (scale.Activity == Activity.Idle)
|
|
|
|
|
|
{
|
|
|
|
|
|
scale.SendSetUnitsCmd(units);
|
|
|
|
|
|
activityStarted = true;
|
|
|
|
|
|
scale.Activity = Activity.RunningOperation;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
activityStarted = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
/// <summary>Run this operation</summary>
|
|
|
|
|
|
/// <returns>
|
|
|
|
|
|
/// Event.None
|
|
|
|
|
|
/// Event.BalanceDone
|
|
|
|
|
|
/// </returns>
|
|
|
|
|
|
public Event Run()
|
|
|
|
|
|
{
|
2020-10-29 09:29:32 +00:00
|
|
|
|
if (!activityStarted && scale.Activity == Activity.Idle)
|
|
|
|
|
|
{
|
|
|
|
|
|
scale.SendSetUnitsCmd(units);
|
|
|
|
|
|
activityStarted = true;
|
|
|
|
|
|
scale.Activity = Activity.RunningOperation;
|
|
|
|
|
|
return Event.None;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (scale.MsrmntState == MsrmntState.Valid) return Event.BalanceDone; /// Units set
|
|
|
|
|
|
if (scale.MsrmntState == MsrmntState.Failed) return Event.Error; /// Failed
|
2014-07-28 07:54:35 +00:00
|
|
|
|
return Event.None; /// No result yet
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>Stop this operation</summary>
|
|
|
|
|
|
public void Stop()
|
|
|
|
|
|
{
|
2020-10-29 09:29:32 +00:00
|
|
|
|
if (scale.MsrmntState == MsrmntState.Busy) scale.MsrmntState = MsrmntState.Failed;
|
|
|
|
|
|
scale.Activity = Activity.Idle;
|
|
|
|
|
|
log.DebugFormat("{0} - SetUnitsOp - Stop()", scale.Name);
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|