61 lines
1.8 KiB
C#
61 lines
1.8 KiB
C#
///
|
|
/// Copyright (c) 2016-2021 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using log4net;
|
|
using TBF.Boxes;
|
|
|
|
namespace TBF.Rig.Modbus.Meret.AdjustableScale
|
|
{
|
|
public class ReadValueOp : IOperation
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(ReadValueOp));
|
|
public override string ToString() { return string.Format("ReadPressureOp(.,{0},.)", eventDone); }
|
|
|
|
/// Set by the constructor
|
|
readonly AdjustableMeter _adjustableMeter;
|
|
readonly DoubleBox value; /// Box for the measured value
|
|
readonly Event eventDone;
|
|
|
|
/// <summary>
|
|
/// Events: PressureDone or Error
|
|
/// </summary>
|
|
/// <param name="adjustableMeter">Pressure meter reference</param>
|
|
/// <param name="value">Reference to the measured pressure variable, value is in bar</param>
|
|
/// <param name="eventDone">Event to be returned by Run() when completed OK</param>
|
|
public ReadValueOp(AdjustableMeter adjustableMeter, ref DoubleBox value, Event eventDone)
|
|
{
|
|
if (adjustableMeter == null) throw new ArgumentNullException("adjustableMeter");
|
|
this._adjustableMeter = adjustableMeter;
|
|
this.value = value;
|
|
this.eventDone = eventDone;
|
|
|
|
log.Debug(this.ToString());
|
|
}
|
|
public ReadValueOp(AdjustableMeter adjustableMeter, ref DoubleBox value)
|
|
: this(adjustableMeter, ref value, Event.PressureDone)
|
|
{
|
|
}
|
|
|
|
|
|
/// <summary>Start this operation</summary>
|
|
public void Start()
|
|
{
|
|
if (value != null) value.Val = _adjustableMeter.ReadPressure();
|
|
}
|
|
|
|
/// <summary>Run this operation</summary>
|
|
/// <returns>
|
|
/// Event.PressureInDone or Event.PressureOutDone
|
|
/// </returns>
|
|
public Event Run()
|
|
{
|
|
if (value != null) value.Val = _adjustableMeter.ReadPressure();
|
|
return eventDone;
|
|
}
|
|
|
|
/// <summary>Stop this operation</summary>
|
|
public void Stop() { }
|
|
}
|
|
}
|