ILevelMeter.Level (immediate measurement), Nivotrack uses correction table, etc.

This commit is contained in:
Milan Hanajik
2018-11-13 10:00:09 +01:00
parent 872409870e
commit 2a98c485ef
8 changed files with 68 additions and 30 deletions
+16 -14
View File
@@ -23,13 +23,14 @@ namespace TBF.BenchControl.Hart.Nivotrack
public class Nivotrack : ComponentBase, IDevice, ILevelMeter, IOperation
{
private static readonly ILog log = LogManager.GetLogger(typeof(Nivotrack));
public override string ToString() { return string.Format("Nivotrack({0})", Cfg.ToString(1)); }
public override string ToString() { return string.Format("{0}({1})", Cfg.Name, Cfg.ToString(-1)); }
private readonly NivotrackCfg nivotrackCfg;
private readonly IHart hart;
bool readingValid;
double waterLevel;
double rawLevel_mm;
public double Level { get { return ReadLevel(); } }
DoubleBox levelBox;
@@ -64,7 +65,7 @@ namespace TBF.BenchControl.Hart.Nivotrack
{
if (nivotrackCfg.DebugLevel == DebugMode.Simulate) return;
waterLevel = 0;
rawLevel_mm = 0;
readingValid = false;
}
@@ -116,18 +117,12 @@ namespace TBF.BenchControl.Hart.Nivotrack
/// A frame with a status and a primary variable
///
ushort state = (ushort)(256 * data[4] + data[5]);
byte unitsID = data[6];
float val = System.BitConverter.ToSingle(data, 7);
byte[] floatData2 = new byte[] { data[10], data[9], data[8], data[7] };
float val2 = System.BitConverter.ToSingle(floatData2, 0);
waterLevel = val;
byte[] floatData = new byte[] { data[10], data[9], data[8], data[7] };
rawLevel_mm = System.BitConverter.ToSingle(floatData, 0);
readingValid = true;
string msg = string.Format("{0} : Received water level = {1} mm / {2} mm, State = {3}", Name, val, val2, state.ToString("X4"));
string msg = string.Format("{0} : Received water level = {1} mm, State = {2}", Name, rawLevel_mm, state.ToString("X4"));
Debug.WriteLine(msg);
log.Info(msg);
}
@@ -160,9 +155,13 @@ namespace TBF.BenchControl.Hart.Nivotrack
public void StopDevice2() { }
/// <summary>
/// Gets the most recent raw level measurement and applies correction table
/// </summary>
/// <returns></returns>
public double ReadLevel()
{
return waterLevel;
return Config.Formulas.CorrectedValue(rawLevel_mm, Corrections);
}
/// <returns>Reference to the operation</returns>
@@ -177,7 +176,10 @@ namespace TBF.BenchControl.Hart.Nivotrack
/// <summary>Start this operation</summary>
public void Start()
{
if (readingValid && (levelBox != null)) levelBox.Val = waterLevel;
if (readingValid && (levelBox != null))
{
levelBox.Val = ReadLevel();
}
}
/// <summary>Run this operation</summary>