(1) Timeout when setting flow handled as UiCmdStop, (2) RegValve.SetFlowOp cleanup, (3) minor change in RegReaders.SerStream, ver. 2.18.914

This commit is contained in:
Milan Hanajik 2018-06-05 11:16:13 +02:00
parent e20a95029c
commit d0cddd072c
20 changed files with 84 additions and 105 deletions

View File

@ -14,20 +14,17 @@ namespace TBF.BenchControl.Elde.RegulValve
private static readonly ILog log = LogManager.GetLogger(typeof(SetFlowOp));
public override string ToString()
{
return string.Format("SetFlowOp({0}, Qfrom={1}, Qto={2}, PID={3})", regulValve.Name, finalReqFlowLo, finalReqFlowHi, pidCoef);
return string.Format("SetFlowOp({0}, Qfrom={1}, Qto={2}, PID={3})", regulValve.Name, requiredFlowLo, requiredFlowHi, pidCoef);
}
const int CoaxValveNr = 7; /// Coax. valve has number 7
/// Set by the constructor
readonly ControlBoardDev controlBoard;
readonly Elde.RegulValve.RegulValve regulValve;
readonly int regulValveNr;
readonly IFlowMeter flowMeter;
readonly float finalReqFlowLo;
readonly float finalReqFlowHi;
readonly float reqFlowAve;
readonly float requiredFlowLo;
readonly float requiredFlowHi;
readonly float requiredFlowAve;
readonly float pidCoef;
readonly int timeout;
readonly bool leaveMeasurementRunning;
@ -95,9 +92,9 @@ namespace TBF.BenchControl.Elde.RegulValve
nominalFlow = flowMeter.NominalFlow;
this.finalReqFlowLo = requiredFlowLo;
this.finalReqFlowHi = requiredFlowHi;
this.reqFlowAve = (requiredFlowLo + requiredFlowHi) / 2.0f;
this.requiredFlowLo = requiredFlowLo;
this.requiredFlowHi = requiredFlowHi;
this.requiredFlowAve = (requiredFlowLo + requiredFlowHi) / 2.0f;
this.pidCoef = pidCoef;
if (flowBox == null) throw new ArgumentNullException("flowBox");
@ -158,7 +155,7 @@ namespace TBF.BenchControl.Elde.RegulValve
void StoreTargetPosition(float avgReqFlow, float actPosition)
{
if (!regulValve.Dict.ContainsKey(reqFlowAve))
if (!regulValve.Dict.ContainsKey(requiredFlowAve))
{
regulValve.Dict.Add(new KeyValuePair<float, float>(avgReqFlow, actPosition));
}
@ -169,25 +166,20 @@ namespace TBF.BenchControl.Elde.RegulValve
public void Start()
{
double flowMtrFreq = flowMeter.ReadFrequency();
currentReqFlowLo = reqFlowAve;
currentReqFlowHi = reqFlowAve;
double flow = flowMeter.ReadFlow();
///
currentReqFlowLo = requiredFlowLo; /// Default lower limit
currentReqFlowHi = requiredFlowHi; /// Default upper limit
if (flow != 0)
{
flowBox.Val = flow;
if (flow >= reqFlowAve) currentReqFlowLo = finalReqFlowLo;
if (flow <= reqFlowAve) currentReqFlowHi = finalReqFlowHi;
}
else
{
currentReqFlowLo = finalReqFlowLo; /// Unexpected case when flowMtrFreq==0
currentReqFlowHi = finalReqFlowHi;
if (flow >= requiredFlowAve) currentReqFlowHi = requiredFlowAve; /// Decrease upper limit
if (flow <= requiredFlowAve) currentReqFlowLo = requiredFlowAve; /// Increase lower limit
}
flowWithinBoundsTime = 0;
if (regulValve.RegulValveCfg.StoredPositionReuse && FetchTargetPosition(reqFlowAve, out targetPositionLo, out targetPositionHi))
if (regulValve.RegulValveCfg.StoredPositionReuse && FetchTargetPosition(requiredFlowAve, out targetPositionLo, out targetPositionHi))
{
log.InfoFormat("SetFlowOp:Start() rv#={0} flowMtr#={1} TARGET: flowLo={2} flowHi={3} FETCHED: posLo={4} posHi={5}",
regulValveNr, flowMeter.Idx1, currentReqFlowLo, currentReqFlowHi, targetPositionLo, targetPositionHi);
@ -226,19 +218,20 @@ namespace TBF.BenchControl.Elde.RegulValve
if (flow != 0)
{
flowBox.Val = flow;
if (flow >= reqFlowAve) currentReqFlowLo = finalReqFlowLo;
if (flow <= reqFlowAve) currentReqFlowHi = finalReqFlowHi;
}
log.InfoFormat("SetFlowOp:Run() rv#={0} pos={1}% freq={2} flow={3} opState={4}",
regulValveNr, rvPosition.ToString("F1"), flowMtrFreq, flow, opState);
log.InfoFormat("SetFlowOp:Run(T={0}) rv#={1} pos={2}% freq={3} flow={4} opState={5}",
StateMachine.Time - expireTime + timeout, regulValveNr, rvPosition.ToString("F1"), flowMtrFreq, flow, opState);
if (opState == OpState.SendCommandAgain)
if (StateMachine.Time > expireTime)
{
return Event.RegulValveTimeOut;
}
else if (opState == OpState.SendCommandAgain)
{
flowWithinBoundsTime = 0;
if (regulValve.RegulValveCfg.StoredPositionReuse && FetchTargetPosition(reqFlowAve, out targetPositionLo, out targetPositionHi))
if (regulValve.RegulValveCfg.StoredPositionReuse && FetchTargetPosition(requiredFlowAve, out targetPositionLo, out targetPositionHi))
{
log.InfoFormat("Run(): rv#={0} flowMtr#={1} TARGET: flowLo={2} flowHi={3} FETCHED: posLo={4} posHi={5}",
regulValveNr, flowMeter.Idx1, currentReqFlowLo, currentReqFlowHi, targetPositionLo, targetPositionHi);
@ -253,9 +246,6 @@ namespace TBF.BenchControl.Elde.RegulValve
opState = OpState.ValveMoveToFlow1;
}
expireTime = StateMachine.Time + timeout;
if (expireTime < 0) expireTime = int.MaxValue;
TestMethods tm = 0;
StopDevs sd = 0;
// '_regulValve.RegulValveCfg.PidCoef' replaced by a casted operation parameter 'pidCoef'
@ -298,20 +288,7 @@ namespace TBF.BenchControl.Elde.RegulValve
opState = OpState.SendCommandAgain;
return Event.None;
}
else if (regulValveNr == CoaxValveNr && ((ulong)controlBoard.StatusP & (ulong)StatusP.CoaxRegValveBusy) == 0)
{
/// Repeat appropriate ValveMove(...) command
controlBoard.ValveMove(regulValveNr, RegulValveMode.TargetPosition,
new float[2] { (targetPositionLo + targetPositionHi) / 2, (targetPositionLo + targetPositionHi) / 2 },
regulValve.StableTime);
log.InfoFormat("SetFlowOp: ValveMove({0}, Position, {1}, {2}, {3})",
regulValveNr, (targetPositionLo + targetPositionHi) / 2, (targetPositionLo + targetPositionHi) / 2, regulValve.StableTime);
opState = OpState.ValveMoveToPosition3;
return Event.None;
}
else if (regulValveNr < 6 && controlBoard.RegulValveState(regulValveNr) != RegulValveState.DacValueRegul)
else if (controlBoard.RegulValveState(regulValveNr) != RegulValveState.DacValueRegul)
{
/// Repeat appropriate ValveMove(...) command
controlBoard.ValveMove(regulValveNr, RegulValveMode.TargetPosition,
@ -380,28 +357,13 @@ namespace TBF.BenchControl.Elde.RegulValve
}
else if (opState == OpState.CheckStateFlow) /// Verify the flow setting
{
if (regulValveNr != CoaxValveNr && (((ulong)controlBoard.StatusP & (ulong)StatusP.RefPulsesMsrmnt) == 0 ||
(controlBoard.RegulValveState(regulValveNr) & RegulValveState.PwOrFreqRegul) != RegulValveState.PwOrFreqRegul))
if ( ((ulong)controlBoard.StatusP & (ulong)StatusP.RefPulsesMsrmnt) == 0 ||
(controlBoard.RegulValveState(regulValveNr) & RegulValveState.PwOrFreqRegul) != RegulValveState.PwOrFreqRegul)
{
opState = OpState.SendCommandAgain;
return Event.None;
}
else if (regulValveNr == CoaxValveNr && ((ulong)controlBoard.StatusP & (ulong)StatusP.CoaxRegValveBusy) == 0)
{
/// Done once, issues an appropriate ValveMove(...) command
float freqLo = 2000.0f * currentReqFlowLo / nominalFlow;
float freqHi = 2000.0f * currentReqFlowHi / nominalFlow;
controlBoard.ValveMove(regulValveNr, RegulValveMode.TargetFrequency,
new float[2] { (freqLo + freqHi) / 2.0f, (freqLo + freqHi) / 2.0f },
regulValve.StableTime);
log.InfoFormat("SetFlowOp: ValveMove({0}, Frequency, {1}, {2}, {3})",
regulValveNr, (freqLo + freqHi) / 2.0f, (freqLo + freqHi) / 2.0f, regulValve.StableTime);
opState = OpState.ValveMoveToFlow3;
return Event.None;
}
else if (regulValveNr < 6 && controlBoard.RegulValveState(regulValveNr) != RegulValveState.PwOrFreqRegul)
else if (controlBoard.RegulValveState(regulValveNr) != RegulValveState.PwOrFreqRegul)
{
/// Done once, issues an appropriate ValveMove(...) command
float freqLo = 2000.0f * currentReqFlowLo / nominalFlow;
@ -434,19 +396,19 @@ namespace TBF.BenchControl.Elde.RegulValve
if (regulValve.RegulValveCfg.StoredPositionReuse)
{
float storedPosition;
if (regulValve.Dict.TryGetValue(reqFlowAve, out storedPosition))
if (regulValve.Dict.TryGetValue(requiredFlowAve, out storedPosition))
{
/// update the stored valve position
StoreTargetPosition(reqFlowAve, (rvPosition + storedPosition) / 2.0f);
StoreTargetPosition(requiredFlowAve, (rvPosition + storedPosition) / 2.0f);
log.InfoFormat("Run(): rv#={0} reqFlow={1} pos={2}% stored={3} <--- Updating a stored position",
regulValveNr, reqFlowAve, rvPosition.ToString("F1"), storedPosition);
regulValveNr, requiredFlowAve, rvPosition.ToString("F1"), storedPosition);
}
else
{
/// store the valve position
StoreTargetPosition(reqFlowAve, rvPosition);
StoreTargetPosition(requiredFlowAve, rvPosition);
log.InfoFormat("Run(): rv#={0} reqFlow={1} pos={2}% <--- Storing a new position",
regulValveNr, reqFlowAve, rvPosition.ToString("F1"));
regulValveNr, requiredFlowAve, rvPosition.ToString("F1"));
}
}

View File

@ -7,8 +7,8 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
{
public class FrameFormat
{
public int FrameLength; /// Frame length in characters/bytes, 0 = unknown
public double FrameFrequency; /// Number of frames per second (Hz)
public readonly int FrameLength; /// Frame length in characters/bytes, 0 = unknown
public readonly double FrameFrequency; /// Number of frames per second (Hz)
public readonly Config.Unit VolumeUnits;
public readonly double VolumeScaleFactor; /// Volume in VolumeInits = volmeRaw / VolumeScaleFactor

View File

@ -719,9 +719,9 @@ namespace TBF.BenchControl.Sequences
}
currentTestFinished = (rsltTransBefore == Event.Done && !e.Contains(Event.Error)
&& !e.Contains(Event.ConfigurationError)
&& !e.Contains(Event.OpArgumentError)
&& !e.Contains(Event.UiCmdStop));
&& !e.Contains(Event.ConfigurationError)
&& !e.Contains(Event.OpArgumentError)
&& !e.Contains(Event.UiCmdStop));
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetNr, currentTestFinished ? Config.Entities.Progress.Completed
: Config.Entities.Progress.Aborted));
@ -734,7 +734,7 @@ namespace TBF.BenchControl.Sequences
if (currentTestFinished && !isOuterLoopMode && repetNr > test.Repeats) repetNr = 1; /// Reset repetNr
}
if (testMethod.DoTransitions())
if (currentTestFinished && testMethod.DoTransitions())
{
TransitionContext endContext = currentTestFinished ? TransitionContext.AfterTest : TransitionContext.Stop;
rsltTransAfter = Transition(transitionAfter, endContext); /// Transition or SetRoute - end of test
@ -908,13 +908,15 @@ namespace TBF.BenchControl.Sequences
}
}
bool testFinished = (rsltTransBefore == Event.Done && !e.Contains(Event.Error) && !e.Contains(Event.ConfigurationError)
&& !e.Contains(Event.OpArgumentError) && !e.Contains(Event.UiCmdStop));
bool testFinished = (rsltTransBefore == Event.Done && !e.Contains(Event.Error)
&& !e.Contains(Event.ConfigurationError)
&& !e.Contains(Event.OpArgumentError)
&& !e.Contains(Event.UiCmdStop));
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetNr, testFinished ? Config.Entities.Progress.Completed
: Config.Entities.Progress.Aborted));
if (testMethod.DoTransitions())
if (testFinished && testMethod.DoTransitions())
{
TransitionContext endContext = testFinished ? TransitionContext.AfterTest : TransitionContext.Stop;
rsltTransAfter = Transition(transitionAfter, endContext); /// Transition or SetRoute - end of test

View File

@ -201,8 +201,8 @@ namespace TBF.BenchControl.TestMethods.Adjustment
if (TestAndLogUiCmdStop(test,e)) { retVal = Event.UiCmdStop; goto stopTest; }
if (e.Contains(Event.RegulValveTimeOut))
{
Bridge.OnError(this, Strings.Timeout);
retVal = Event.Done;
Bridge.OnError(this, Strings.Flow_adjustment_failed);
retVal = Event.UiCmdStop;
goto stopTest;
}
if (e.Contains(Event.Next)) goto flow_set;

View File

@ -233,7 +233,7 @@ namespace TBF.BenchControl.TestMethods.CombinedWithDetection
if (TestAndLogUiCmdStop(test,e)) goto stopTest;
if (e.Contains(Event.RegulValveTimeOut))
{
Bridge.OnError(this, Strings.Timeout);
Bridge.OnError(this, Strings.Flow_adjustment_failed);
goto error;
}
}
@ -420,7 +420,7 @@ namespace TBF.BenchControl.TestMethods.CombinedWithDetection
if (TestAndLogUiCmdStop(test,e)) goto stopTest;
if (e.Contains(Event.RegulValveTimeOut))
{
Bridge.OnError(this, Strings.Timeout);
Bridge.OnError(this, Strings.Flow_adjustment_failed);
goto error;
}
}

View File

@ -134,8 +134,8 @@ namespace TBF.BenchControl.TestMethods.Endurance
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
if (e.Contains(Event.RegulValveTimeOut))
{
Bridge.OnError(this, Strings.Timeout);
retVal = Event.Done;
Bridge.OnError(this, Strings.Flow_adjustment_failed);
retVal = Event.UiCmdStop;
goto stopTest;
}
if (e.Contains(Event.Next)) goto flow_set;

View File

@ -291,8 +291,8 @@ namespace TBF.BenchControl.TestMethods.FixedStart
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
if (e.Contains(Event.RegulValveTimeOut))
{
Bridge.OnError(this, Strings.Timeout);
retVal = Event.Done;
Bridge.OnError(this, Strings.Flow_adjustment_failed);
retVal = Event.UiCmdStop;
goto stopTest;
}
if (e.Contains(Event.Next)) goto flow_set;

View File

@ -165,8 +165,8 @@ namespace TBF.BenchControl.TestMethods.FixedStartAdvanced
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
if (e.Contains(Event.RegulValveTimeOut))
{
Bridge.OnError(this, Strings.Timeout);
retVal = Event.Done;
Bridge.OnError(this, Strings.Flow_adjustment_failed);
retVal = Event.UiCmdStop;
goto stopTest;
}
if (e.Contains(Event.Next)) goto flow_set;

View File

@ -298,8 +298,8 @@ namespace TBF.BenchControl.TestMethods.FixedStartDeferredEvaluation
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
if (e.Contains(Event.RegulValveTimeOut))
{
Bridge.OnError(this, Strings.Timeout);
retVal = Event.Done;
Bridge.OnError(this, Strings.Flow_adjustment_failed);
retVal = Event.UiCmdStop;
goto stopTest;
}
if (e.Contains(Event.Next)) goto flow_set;

View File

@ -280,8 +280,8 @@ namespace TBF.BenchControl.TestMethods.FixedStartMassCollection
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
if (e.Contains(Event.RegulValveTimeOut))
{
Bridge.OnError(this, Strings.Timeout);
retVal = Event.Done;
Bridge.OnError(this, Strings.Flow_adjustment_failed);
retVal = Event.UiCmdStop;
goto stopTest;
}
if (e.Contains(Event.Next)) goto flow_set;

View File

@ -246,8 +246,8 @@ namespace TBF.BenchControl.TestMethods.FlyingStart
if (TestAndLogUiCmdStop(test,e)) { retVal = Event.UiCmdStop; goto stopTest; }
if (e.Contains(Event.RegulValveTimeOut))
{
Bridge.OnError(this, Strings.Timeout);
retVal = Event.Done;
Bridge.OnError(this, Strings.Flow_adjustment_failed);
retVal = Event.UiCmdStop;
goto stopTest;
}
if (e.Contains(Event.Next)) goto flow_set;

View File

@ -306,8 +306,8 @@ namespace TBF.BenchControl.TestMethods.FlyingStartFirstRepetWithMassColl
if (TestAndLogUiCmdStop(test,e)) { retVal = Event.UiCmdStop; goto stopTest; }
if (e.Contains(Event.RegulValveTimeOut))
{
Bridge.OnError(this, Strings.Timeout);
retVal = Event.Done;
Bridge.OnError(this, Strings.Flow_adjustment_failed);
retVal = Event.UiCmdStop;
goto stopTest;
}
if (e.Contains(Event.Next)) goto flow_set;

View File

@ -312,8 +312,8 @@ namespace TBF.BenchControl.TestMethods.FlyingStartMassCollProlonged
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
if (e.Contains(Event.RegulValveTimeOut))
{
Bridge.OnError(this, Strings.Timeout);
retVal = Event.Done;
Bridge.OnError(this, Strings.Flow_adjustment_failed);
retVal = Event.UiCmdStop;
goto stopTest;
}
if (e.Contains(Event.Next)) goto flow_set;

View File

@ -362,8 +362,8 @@ namespace TBF.BenchControl.TestMethods.FlyingStartMassCollection
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
if (e.Contains(Event.RegulValveTimeOut))
{
Bridge.OnError(this, Strings.Timeout);
retVal = Event.Done;
Bridge.OnError(this, Strings.Flow_adjustment_failed);
retVal = Event.UiCmdStop;
goto stopTest;
}
if (e.Contains(Event.Next)) goto flow_set;

View File

@ -138,8 +138,8 @@ namespace TBF.BenchControl.TestMethods.RoiDetection
if (TestAndLogUiCmdStop(test,e)) { retVal = Event.UiCmdStop; goto stopTest; }
if (e.Contains(Event.RegulValveTimeOut))
{
Bridge.OnError(this, Strings.Timeout);
retVal = Event.Done;
Bridge.OnError(this, Strings.Flow_adjustment_failed);
retVal = Event.UiCmdStop;
goto stopTest;
}
if (e.Contains(Event.Next)) goto flow_set;

View File

@ -239,7 +239,7 @@ namespace TBF.BenchControl.TestMethods.SensitivityTest
if (TestAndLogUiCmdStop(test,e)) goto stopTest;
if (e.Contains(Event.RegulValveTimeOut))
{
Bridge.OnError(this, Strings.Timeout);
Bridge.OnError(this, Strings.Flow_adjustment_failed);
goto error;
}
}

View File

@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Build Number
// Revision
//
[assembly: AssemblyVersion("2.18.913.0")]
[assembly: AssemblyFileVersion("2.18.913.0")]
[assembly: AssemblyVersion("2.18.914.0")]
[assembly: AssemblyFileVersion("2.18.914.0")]

View File

@ -1662,6 +1662,15 @@ namespace TBF.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Flow adjustment failed.
/// </summary>
internal static string Flow_adjustment_failed {
get {
return ResourceManager.GetString("Flow_adjustment_failed", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Flow meter temperature range does not fit this test conditions.
/// </summary>

View File

@ -1749,4 +1749,7 @@
<data name="Start_the_test_bench" xml:space="preserve">
<value>Avvio del banco prova</value>
</data>
<data name="Flow_adjustment_failed" xml:space="preserve">
<value>Errore impostazione del flusso</value>
</data>
</root>

View File

@ -1834,4 +1834,7 @@
<data name="String1" xml:space="preserve">
<value />
</data>
<data name="Flow_adjustment_failed" xml:space="preserve">
<value>Flow adjustment failed</value>
</data>
</root>