Water meter pulses overflow is handled properly (only 16-bit HW counter is used)
This commit is contained in:
@@ -40,8 +40,8 @@ namespace TBF.BenchControl.Elde
|
||||
///
|
||||
public StatusP StatusP { get { return controlCom.StatusP; } }
|
||||
public float ReferenceFreq { get { return controlCom.ReferenceFreq; } } /// In [Hz] 0..2500, nom.=2000
|
||||
public int EtPulses(int wmNr0) { return controlCom.EtPulses(wmNr0); }
|
||||
public int WMeterPulses(int wmNr0) { return controlCom.WMeterPulses(wmNr0); }
|
||||
public int EtPulses(int wmNr0) { return (int)controlCom.EtPulses(wmNr0); }
|
||||
public UInt16 WMeterPulses(int wmNr0) { return controlCom.WMeterPulses(wmNr0); }
|
||||
public int WMeterReference(int wmNr0) { return controlCom.WMeterReference(wmNr0); }
|
||||
public uint RegulValveDAC { get { return controlCom.RegulValveDAC; } }
|
||||
public float Pressure(int prsNr0) { return controlCom.Pressure(prsNr0); }
|
||||
|
||||
@@ -29,8 +29,8 @@ namespace TBF.BenchControl.Elde
|
||||
float[] errFactor = new float[Program.WMsCount + 1]; /// Internal
|
||||
float[] wMeterPulsesF = new float[Program.WMsCount + 1]; /// Internal
|
||||
|
||||
int[] wMeterPulses = new int[Program.WMsCount + 1]; /// Rounded from wMeterPulsesF
|
||||
public int WMeterPulses(int wmNr1)
|
||||
UInt16[] wMeterPulses = new UInt16[Program.WMsCount + 1]; /// Rounded from wMeterPulsesF
|
||||
public UInt16 WMeterPulses(int wmNr1)
|
||||
{
|
||||
return wMeterPulses[wmNr1];
|
||||
}
|
||||
@@ -287,7 +287,7 @@ namespace TBF.BenchControl.Elde
|
||||
{
|
||||
const float wmPulsesPerLiter = 10.0f;
|
||||
wMeterPulsesF[i] += errFactor[i] * pwFactor * ((float)rand.Next(100) + 450.0f) * wmPulsesPerLiter * TestBenchSim.GetSimFlow() / 1800.0f;
|
||||
wMeterPulses[i] = (int)wMeterPulsesF[i];
|
||||
wMeterPulses[i] = (UInt16)wMeterPulsesF[i];
|
||||
}
|
||||
|
||||
if (etPulses[0] > totalRefPulses)
|
||||
|
||||
@@ -27,14 +27,8 @@ namespace TBF.BenchControl.Elde
|
||||
#else
|
||||
public float ReferenceFreq { get { return 1000.0f * ctrlBrdComponent.referenceFreq; } } /// In [Hz] 0..2500, nom.=2000
|
||||
#endif
|
||||
public int EtPulses(int wmNr0)
|
||||
{
|
||||
return (int)ctrlBrdComponent.etPulses[wmNr0];
|
||||
}
|
||||
public int WMeterPulses(int wmNr0)
|
||||
{
|
||||
return (int)ctrlBrdComponent.wMeterPuls[wmNr0];
|
||||
}
|
||||
public int EtPulses(int wmNr0) { return (int)ctrlBrdComponent.etPulses[wmNr0]; }
|
||||
public UInt16 WMeterPulses(int wmNr0) { return (UInt16)ctrlBrdComponent.wMeterPuls[wmNr0]; }
|
||||
public int WMeterReference(int wmNr0) { return (int)ctrlBrdComponent.wMeterReference[wmNr0]; }
|
||||
public uint RegulValveDAC { get { return ctrlBrdComponent.StavDA; } }
|
||||
public float Pressure(int prsNr0) { return ctrlBrdComponent.pressure[prsNr0]; }
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
///
|
||||
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
|
||||
namespace TBF.BenchControl.Elde
|
||||
{
|
||||
@@ -9,7 +10,7 @@ namespace TBF.BenchControl.Elde
|
||||
StatusP StatusP { get; }
|
||||
float ReferenceFreq { get; }
|
||||
int EtPulses(int wmNr0);
|
||||
int WMeterPulses(int wmNr0);
|
||||
UInt16 WMeterPulses(int wmNr0);
|
||||
int WMeterReference(int wmNr0);
|
||||
uint RegulValveDAC { get; }
|
||||
float Pressure(int prsNr0);
|
||||
|
||||
@@ -14,7 +14,11 @@ namespace TBF.BenchControl.Elde.RegisterReader
|
||||
|
||||
/// Set by the constructor
|
||||
readonly RegisterReader reader;
|
||||
|
||||
IntBox pulses;
|
||||
int lastPulses;
|
||||
bool lastPulsesValid;
|
||||
|
||||
IntBox refPulses;
|
||||
|
||||
/// <summary>
|
||||
@@ -28,6 +32,7 @@ namespace TBF.BenchControl.Elde.RegisterReader
|
||||
if (reader == null) throw new ArgumentNullException("reader is null or it is not Elde");
|
||||
|
||||
this.pulses = pulses;
|
||||
lastPulsesValid = false;
|
||||
log.Debug(this.ToString());
|
||||
}
|
||||
|
||||
@@ -46,7 +51,30 @@ namespace TBF.BenchControl.Elde.RegisterReader
|
||||
|
||||
private void ReadPulses()
|
||||
{
|
||||
pulses.Val = (int)reader.ControlBoard.WMeterPulses(reader.Position);
|
||||
if (!lastPulsesValid)
|
||||
{
|
||||
lastPulses = (int)reader.ControlBoard.WMeterPulses(reader.Position);
|
||||
lastPulsesValid = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
UInt16 lowerWord = reader.ControlBoard.WMeterPulses(reader.Position);
|
||||
int uncorrected = (int)(((uint)lastPulses & 0xFFFF0000) | lowerWord);
|
||||
if (Math.Abs(uncorrected - lastPulses) <= Int16.MaxValue)
|
||||
{
|
||||
lastPulses = uncorrected;
|
||||
}
|
||||
else if (Math.Abs(uncorrected + 32768 - lastPulses) <= Int16.MaxValue)
|
||||
{
|
||||
lastPulses = uncorrected + 32768;
|
||||
}
|
||||
else if (Math.Abs(uncorrected - 32768 - lastPulses) <= Int16.MaxValue)
|
||||
{
|
||||
lastPulses = uncorrected - 32768;
|
||||
}
|
||||
}
|
||||
pulses.Val = lastPulses;
|
||||
|
||||
if (refPulses != null)
|
||||
{
|
||||
refPulses.Val = (int)reader.ControlBoard.EtPulses(reader.Position);
|
||||
|
||||
Reference in New Issue
Block a user