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
@@ -19,6 +19,11 @@ namespace TBF.BenchControl.GenericDevices
/// </summary> /// </summary>
IList<MeasurementCorrection> Corrections { get; } IList<MeasurementCorrection> Corrections { get; }
/// <summary>
/// Continuosly measured level in mm (last measured level in case of ManualLevelMsrmnt)
/// </summary>
double Level { get; }
/// <summary> /// <summary>
/// Events: Busy, LevelDone, Error /// Events: Busy, LevelDone, Error
/// </summary> /// </summary>
+16 -14
View File
@@ -23,13 +23,14 @@ namespace TBF.BenchControl.Hart.Nivotrack
public class Nivotrack : ComponentBase, IDevice, ILevelMeter, IOperation public class Nivotrack : ComponentBase, IDevice, ILevelMeter, IOperation
{ {
private static readonly ILog log = LogManager.GetLogger(typeof(Nivotrack)); 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 NivotrackCfg nivotrackCfg;
private readonly IHart hart; private readonly IHart hart;
bool readingValid; bool readingValid;
double waterLevel; double rawLevel_mm;
public double Level { get { return ReadLevel(); } }
DoubleBox levelBox; DoubleBox levelBox;
@@ -64,7 +65,7 @@ namespace TBF.BenchControl.Hart.Nivotrack
{ {
if (nivotrackCfg.DebugLevel == DebugMode.Simulate) return; if (nivotrackCfg.DebugLevel == DebugMode.Simulate) return;
waterLevel = 0; rawLevel_mm = 0;
readingValid = false; readingValid = false;
} }
@@ -116,18 +117,12 @@ namespace TBF.BenchControl.Hart.Nivotrack
/// A frame with a status and a primary variable /// A frame with a status and a primary variable
/// ///
ushort state = (ushort)(256 * data[4] + data[5]); ushort state = (ushort)(256 * data[4] + data[5]);
byte unitsID = data[6]; byte unitsID = data[6];
byte[] floatData = new byte[] { data[10], data[9], data[8], data[7] };
float val = System.BitConverter.ToSingle(data, 7); rawLevel_mm = System.BitConverter.ToSingle(floatData, 0);
byte[] floatData2 = new byte[] { data[10], data[9], data[8], data[7] };
float val2 = System.BitConverter.ToSingle(floatData2, 0);
waterLevel = val;
readingValid = true; 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); Debug.WriteLine(msg);
log.Info(msg); log.Info(msg);
} }
@@ -160,9 +155,13 @@ namespace TBF.BenchControl.Hart.Nivotrack
public void StopDevice2() { } public void StopDevice2() { }
/// <summary>
/// Gets the most recent raw level measurement and applies correction table
/// </summary>
/// <returns></returns>
public double ReadLevel() public double ReadLevel()
{ {
return waterLevel; return Config.Formulas.CorrectedValue(rawLevel_mm, Corrections);
} }
/// <returns>Reference to the operation</returns> /// <returns>Reference to the operation</returns>
@@ -177,7 +176,10 @@ namespace TBF.BenchControl.Hart.Nivotrack
/// <summary>Start this operation</summary> /// <summary>Start this operation</summary>
public void Start() public void Start()
{ {
if (readingValid && (levelBox != null)) levelBox.Val = waterLevel; if (readingValid && (levelBox != null))
{
levelBox.Val = ReadLevel();
}
} }
/// <summary>Run this operation</summary> /// <summary>Run this operation</summary>
@@ -1,6 +1,7 @@
/// ///
/// Copyright (c) 2018 Sensus Slovensko a.s. /// Copyright (c) 2018 Sensus Slovensko a.s.
/// ///
using System;
using System.IO; using System.IO;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO.Ports; using System.IO.Ports;
@@ -10,7 +11,7 @@ using TBF.BenchControl.Generic;
namespace TBF.BenchControl.Hart.Nivotrack namespace TBF.BenchControl.Hart.Nivotrack
{ {
public class NivotrackCfg : ComponentCfgBase, Generic.IChildComponentCfg, Config.Entities.IParamsProvider public class NivotrackCfg : ComponentCfgBase, Generic.IChildComponentCfg, Config.Entities.IParamsProvider, GenericDevices.ICalibInfoCfg
{ {
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(NivotrackCfg) })[0]; public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(NivotrackCfg) })[0];
public override XmlSerializer GetSerializer() { return Serializer; } public override XmlSerializer GetSerializer() { return Serializer; }
@@ -34,6 +35,28 @@ namespace TBF.BenchControl.Hart.Nivotrack
public int Par1; public int Par1;
public int Par2; public int Par2;
/// Calibration info serialized parameters displayed in Metrology tab page
string calibCertificateNr;
DateTime calibDate;
DateTime calibValidDate;
public string CalibCertificateNr
{
get { return calibCertificateNr; }
set { calibCertificateNr = value; }
}
public DateTime CalibDate
{
get { return calibDate; }
set { calibDate = value; }
}
public DateTime CalibValidDate
{
get { return calibValidDate; }
set { calibValidDate = value; }
}
/// Private parameterless constructor invoked by all other (public) constructors /// Private parameterless constructor invoked by all other (public) constructors
NivotrackCfg() { } NivotrackCfg() { }
@@ -79,7 +102,7 @@ namespace TBF.BenchControl.Hart.Nivotrack
{ {
if (i == -1) if (i == -1)
{ {
return string.Format("Address={0}, Par1={1}, Par2={2}", Address, Par1, Par2); return string.Format("Address={0}", Address);
} }
switch (i) switch (i)
@@ -32,6 +32,8 @@ namespace TBF.BenchControl.Modbus.UltrasoundLevelMeter
double temperature; /// [°C] double temperature; /// [°C]
ushort state; ushort state;
public double Level { get { return level; } }
/// <summary>Measurement time stamp when MsrmntState == MsrmntState.Valid</summary> /// <summary>Measurement time stamp when MsrmntState == MsrmntState.Valid</summary>
int msrmntTimeStamp; int msrmntTimeStamp;
@@ -16,10 +16,10 @@ namespace TBF.BenchControl.Various.ManualLevelMsrmnt
readonly TestMethodCfg myCfg; readonly TestMethodCfg myCfg;
public double Level { get { return level_mm; } }
double level_mm;
DoubleBox levelBox; DoubleBox levelBox;
public double WaterLevelMm;
WaterLevelForm waterLevelForm; WaterLevelForm waterLevelForm;
bool resultSaved; /// Set in Run() when results are saved bool resultSaved; /// Set in Run() when results are saved
@@ -88,8 +88,8 @@ namespace TBF.BenchControl.Various.ManualLevelMsrmnt
if (!resultSaved && (currentOp == CurrentOp.EnterLevel) && (waterLevelForm != null)) if (!resultSaved && (currentOp == CurrentOp.EnterLevel) && (waterLevelForm != null))
{ {
/// Save the result (only once) /// Save the result (only once)
WaterLevelMm = waterLevelForm.WaterLevelMm; level_mm = waterLevelForm.Level_mm;
if (levelBox != null) levelBox.Val = WaterLevelMm; if (levelBox != null) levelBox.Val = level_mm;
resultSaved = true; resultSaved = true;
} }
@@ -17,7 +17,7 @@ namespace TBF.BenchControl.Various.ManualLevelMsrmnt
bool completed; bool completed;
/// <summary> Water level in mm entered by the user </summary> /// <summary> Water level in mm entered by the user </summary>
public double WaterLevelMm; public double Level_mm;
/// <summary> /// <summary>
@@ -28,7 +28,7 @@ namespace TBF.BenchControl.Various.ManualLevelMsrmnt
{ {
InitializeComponent(); InitializeComponent();
ControlBox = false; ControlBox = false;
WaterLevelMm = 0; Level_mm = 0;
completed = false; completed = false;
StartForceCloseHandler(); StartForceCloseHandler();
} }
@@ -57,7 +57,7 @@ namespace TBF.BenchControl.Various.ManualLevelMsrmnt
try try
{ {
WaterLevelMm = Utils.ParseUDouble(waterLevelTextBox.Text); Level_mm = Utils.ParseUDouble(waterLevelTextBox.Text);
} }
catch (Exception e) catch (Exception e)
{ {
@@ -63,6 +63,8 @@ namespace TBF.BenchControl.Various.TankWithLevelMsrmnt
public string Format { get { return "F3"; } } public string Format { get { return "F3"; } }
public double Volume { get { return Level2Volume(levelMeter.Level); } }
public Tank() public Tank()
{ {
@@ -87,9 +89,8 @@ namespace TBF.BenchControl.Various.TankWithLevelMsrmnt
if (tanksSoFar != null) for (int i = 0; i < tanksSoFar.Length; i++) Tanks[i] = tanksSoFar[i]; if (tanksSoFar != null) for (int i = 0; i < tanksSoFar.Length; i++) Tanks[i] = tanksSoFar[i];
Tanks[nextTankIdx - 1] = this; Tanks[nextTankIdx - 1] = this;
} }
currentOp = CurrentOp.None;
levelMeter = new Various.ManualLevelMsrmnt.ManualLevelMsrmnt(); currentOp = CurrentOp.None;
levelBox = new DoubleBox(); levelBox = new DoubleBox();
log.Debug(this.ToString()); log.Debug(this.ToString());
@@ -102,7 +103,12 @@ namespace TBF.BenchControl.Various.TankWithLevelMsrmnt
public void Initialize() public void Initialize()
{ {
base.Initalize(); base.Initalize();
drainValve2 = TbfComponents.FindComponent(tankCfg.DrainValve2) as IValve; drainValve2 = TbfComponents.FindComponent(tankCfg.DrainValve2) as IValve;
levelMeter = TbfComponents.FindComponent(tankCfg.LevelMeasurement) as ILevelMeter;
if (levelMeter == null) levelMeter = new Various.ManualLevelMsrmnt.ManualLevelMsrmnt();
useCalibTable = LoadCalibrationTable(tankCfg.CalibrationTable); useCalibTable = LoadCalibrationTable(tankCfg.CalibrationTable);
} }
public void RunDeviceBefore() { } public void RunDeviceBefore() { }
@@ -148,7 +148,7 @@ namespace TBF.BenchControl.Various.TankWithLevelMsrmnt
config.DrainTimeSec = int.Parse(drainTimeTextBox.Text); config.DrainTimeSec = int.Parse(drainTimeTextBox.Text);
config.DrainValve = drainValveComboBox.Text.Equals("---") ? string.Empty : drainValveComboBox.Text; config.DrainValve = drainValveComboBox.Text.Equals("---") ? string.Empty : drainValveComboBox.Text;
config.DrainValve2 = drainValve2ComboBox.Text.Equals("---") ? string.Empty : drainValve2ComboBox.Text; config.DrainValve2 = drainValve2ComboBox.Text.Equals("---") ? string.Empty : drainValve2ComboBox.Text;
config.LevelMeasurement = levelMeasurementComboBox.Text.Equals("---") ? string.Empty : drainValveComboBox.Text; config.LevelMeasurement = levelMeasurementComboBox.Text.Equals("---") ? string.Empty : levelMeasurementComboBox.Text;
config.CalibrationTable = calibrationTableTextBox.Text; config.CalibrationTable = calibrationTableTextBox.Text;
return flags; return flags;