Refactorization : BenchControl -> Rig
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
///
|
||||
/// Copyright (c) 2013-2021 Sensus Slovensko a.s.
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using log4net;
|
||||
|
||||
namespace TBF.Rig.MettlerToledo.Standard
|
||||
{
|
||||
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
|
||||
BalanceDev scale;
|
||||
Config.Unit units;
|
||||
bool activityStarted;
|
||||
|
||||
/// <summary>
|
||||
/// Events: BalanceDone, Error
|
||||
/// </summary>
|
||||
/// <param name="scale">Balance device instance</param>
|
||||
/// <param name="result">Reference to the serialNumber</param>
|
||||
public SetUnitsOp(BalanceDev scale, Config.Unit units)
|
||||
{
|
||||
if (scale == null) throw new ArgumentNullException("balanceDev");
|
||||
this.scale = scale;
|
||||
this.units = units;
|
||||
|
||||
log.Debug(this.ToString());
|
||||
}
|
||||
|
||||
/// <summary>Start this operation</summary>
|
||||
public void Start()
|
||||
{
|
||||
log.DebugFormat("{0} - SetUnitsOp - Start()", scale.Name);
|
||||
|
||||
if (scale.Activity == Activity.Idle)
|
||||
{
|
||||
scale.SendSetUnitsCmd(units);
|
||||
activityStarted = true;
|
||||
scale.Activity = Activity.RunningOperation;
|
||||
}
|
||||
else
|
||||
{
|
||||
activityStarted = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Run this operation</summary>
|
||||
/// <returns>
|
||||
/// Event.None
|
||||
/// Event.BalanceDone
|
||||
/// </returns>
|
||||
public Event Run()
|
||||
{
|
||||
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
|
||||
return Event.None; /// No result yet
|
||||
}
|
||||
|
||||
/// <summary>Stop this operation</summary>
|
||||
public void Stop()
|
||||
{
|
||||
if (scale.MsrmntState == MsrmntState.Busy) scale.MsrmntState = MsrmntState.Failed;
|
||||
scale.Activity = Activity.Idle;
|
||||
log.DebugFormat("{0} - SetUnitsOp - Stop()", scale.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user