- Part field (int) added to Test and TestResult, shown and processed in UI in ProcedureDlg
146 lines
5.9 KiB
C#
146 lines
5.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using log4net;
|
|
using TBF.BenchControl.Generic;
|
|
using TBF.Boxes;
|
|
|
|
namespace TBF.BenchControl.Elde.RegulValve
|
|
{
|
|
public class RegulValve : ComponentBase, GenericDevices.IRegulValve
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(RegulValve));
|
|
public override string ToString() { return string.Format("RegulValve({0})", Cfg.ToString(1)); }
|
|
|
|
public readonly RegulValveCfg RegulValveCfg;
|
|
|
|
IDictionary<float, float> dict;
|
|
public IDictionary<float, float> Dict { get { return dict; } }
|
|
|
|
readonly ControlBoardDev controlBoard;
|
|
|
|
public int Idx1 { get { return RegulValveCfg.Idx1; } } /// 1..7
|
|
public int DacValueClosed { get { return RegulValveCfg.DacValueClosed; } } /// 0..1023
|
|
public int DacValueOpen { get { return RegulValveCfg.DacValueOpen; } } /// 0..1023
|
|
public int StableTime { get { return RegulValveCfg.StableTime; } } /// 0=200ms, step=50ms, max. 1500ms (max.26)
|
|
public int FlowStableSec { get { return RegulValveCfg.FlowStableSec; } } /// 0..60 sec
|
|
///
|
|
public float Position
|
|
{
|
|
get { return controlBoard.RValvePosition(Idx1); }
|
|
}
|
|
|
|
|
|
#region Configuration Change Handling
|
|
|
|
public static void OnCfgChange(object sender, CfgChangeArgs args)
|
|
{
|
|
if (CfgChangeHandler == null) return;
|
|
try { CfgChangeHandler(sender, args); }
|
|
catch (Exception e) { log.Error("CfgChangeHandler(...) failed", e); }
|
|
}
|
|
|
|
public static event EventHandler<CfgChangeArgs> CfgChangeHandler;
|
|
|
|
public override void StartChangeHandler()
|
|
{
|
|
CfgChangeHandler += delegate(object sender, CfgChangeArgs args)
|
|
{
|
|
RegulValveCfg tmpcfg = args.Cfg as RegulValveCfg;
|
|
if (tmpcfg != null && tmpcfg.Name.Equals(Name))
|
|
{
|
|
if (args.Command == CfgChangeCmd.CfgChange)
|
|
{
|
|
RegulValveCfg.StableTimeMs = tmpcfg.StableTimeMs;
|
|
RegulValveCfg.FlowStableSec = tmpcfg.FlowStableSec;
|
|
}
|
|
else if (args.Command == CfgChangeCmd.RVOpenStep)
|
|
{
|
|
controlBoard.ValveMove(Idx1, RegulValveMode.PulseWidth, new float[2] { 0.05f, 0.05f }, StableTime);
|
|
// TODO: avoid conflicts
|
|
// TOTEST
|
|
}
|
|
else if (args.Command == CfgChangeCmd.RVCloseStep)
|
|
{
|
|
controlBoard.ValveMove(Idx1, RegulValveMode.PulseWidth, new float[2] { -0.05f, -0.05f }, StableTime);
|
|
// TODO: avoid conflicts
|
|
// TOTEST
|
|
}
|
|
else if (args.Command == CfgChangeCmd.GetRVAdc1 || args.Command == CfgChangeCmd.GetRVAdc2)
|
|
{
|
|
int adc = (int)controlBoard.AnalogInputRaw(Idx1, 0);
|
|
// TOTEST
|
|
RegulValveCfgCtrl.OnCmdResponse(this, new CmdResponseArgs(args.Command, adc));
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
#endregion Configuration Change Handling
|
|
|
|
|
|
public RegulValve(RegulValveCfg cfg, IList<Generic.IComponent> components)
|
|
: base(cfg)
|
|
{
|
|
RegulValveCfg = cfg;
|
|
|
|
controlBoard = (ControlBoardDev)TbfComponents.FindComponent(cfg.ParentName, components);
|
|
if (controlBoard == null) throw new Exception("Cannot find " + Name + " parent");
|
|
|
|
this.dict = new Dictionary<float, float>();
|
|
|
|
this.controlBoard.RegValveCalib[Idx1 - 1, 0] = (uint)DacValueClosed;
|
|
this.controlBoard.RegValveCalib[Idx1 - 1, 1] = (uint)DacValueOpen;
|
|
|
|
log.Debug(this.ToString());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Operation to set the water flow within tolerances
|
|
/// Events: Event.None, Event.FlowReached, Event.FlowTimeOut
|
|
/// </summary>
|
|
/// <param name="flowMeter">Flowmeter component</param>
|
|
/// <param name="requiredFlowLo">Lower limit of the required flow [m3/h]</param>
|
|
/// <param name="requiredFlowHi">Higher limit of the required flow [m3/h]</param>
|
|
/// <param name="pidCoef">PID coefficient (float)</param>
|
|
/// <param name="measuredFlow">Measured flow [m3/h]</param>
|
|
/// <param name="timeout">Timeout in [s]</param>
|
|
/// <returns>SetFlowOp instance</returns>
|
|
public IOperation SetFlowOp(GenericDevices.IFlowMeter flowMeter, float requiredFlowLo, float requiredFlowHi, float pidCoef, FloatBox measuredFlow, int timeout)
|
|
{
|
|
return new SetFlowOp(controlBoard, this, flowMeter, requiredFlowLo, requiredFlowHi, pidCoef, measuredFlow, timeout);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Operation to set the water flow within tolerances. Leave the measurement running.
|
|
/// Events: Event.None, Event.FlowReached, Event.FlowTimeOut
|
|
/// </summary>
|
|
/// <param name="flowMeter">Flowmeter component</param>
|
|
/// <param name="requiredFlowLo">Lower limit of the required flow [m3/h]</param>
|
|
/// <param name="requiredFlowHi">Higher limit of the required flow [m3/h]</param>
|
|
/// <param name="measuredFlow">Measured flow [m3/h]</param>
|
|
/// <param name="timeout">Timeout in [s]</param>
|
|
/// <returns>SetFlowOp instance</returns>
|
|
public IOperation SetFlowAndMeasureOp(GenericDevices.IFlowMeter flowMeter, float requiredFlowLo, float requiredFlowHi, float pidCoef, FloatBox measuredFlow, int timeout, float filterConstant)
|
|
{
|
|
return new SetFlowOp(controlBoard, this, flowMeter, requiredFlowLo, requiredFlowHi, pidCoef, measuredFlow, timeout, true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Operation to set the regulation valve to a required position
|
|
/// Events: Event.None
|
|
/// </summary>
|
|
/// <param name="flowLo">Lower limit of the required valve position in [%]</param>
|
|
/// <param name="flowLo">Higher limit of the required valve position in [%]</param>
|
|
/// <returns>SetPositionOp instance</returns>
|
|
public IOperation SetRegulValvePositionOp(float pctLo, float pctHi, int timeoutMs)
|
|
{
|
|
return new SetRegulValvePositionOp(controlBoard, this, pctLo, pctHi, timeoutMs);
|
|
}
|
|
|
|
public IOperation ChangeRegulValvePositionOp(float timePulseSec)
|
|
{
|
|
return new ChangeRegulValvePositionOp(controlBoard, this, timePulseSec);
|
|
}
|
|
}
|
|
}
|