82 lines
2.3 KiB
C#
82 lines
2.3 KiB
C#
///
|
|
/// Copyright (c) 2013-2020 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using log4net;
|
|
|
|
namespace TBF.BenchControl.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;
|
|
BalanceDev.Units 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, BalanceDev.Units 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);
|
|
}
|
|
}
|
|
}
|