common/Hardware/WaterMeter/WaterMeterCore/IMeter.cs
2026-04-23 17:50:07 +02:00

289 lines
11 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Xylem.Common.Hardware.WaterMeter.WaterMeterCore.Consts;
using Xylem.Common.Metrology.Measurements;
using Xylem.Common.Metrology.Measurements.Consts;
namespace Xylem.Common.Hardware.WaterMeter.WaterMeterCore
{
/// <inheritdoc />
/// <summary>
/// IMeter is the highest level interface between a meter with direct communication to a test bench.
/// has general things like calibration, measurement and set up routines.
/// no specific meter stuff in here!
/// it is always disposable
/// </summary>
[Guid("7BD20046-DF8C-44A6-8F6B-687FAA26FA71")
, ComVisible(true)
, InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IMeter : IDisposable
{
#region events
/// <summary>
/// occurs when ProcessState has changed
/// </summary>
event EventHandler OnProcessStatusChanged;
/// <summary>
/// occurs when ErrorState has changed
/// </summary>
event EventHandler OnErrorStatusChanged;
/// <summary>
/// occurs when Init is completed
/// </summary>
event EventHandler OnInitCompleted;
/// <summary>
/// occurs when the initialization for Measurement is completed
/// </summary>
event EventHandler OnMeasurementInitCompleted;
/// <summary>
/// occurs when the Measurement is completed
/// </summary>
event EventHandler OnMeasurementCompleted;
/// <summary>
/// occurs when the initialization for calibration is completed
/// </summary>
event EventHandler OnCalibInitCompleted;
/// <summary>
/// occurs when the calibration is completed
/// </summary>
event EventHandler OnCalibCompleted;
/// <summary>
/// occurs when meter gets disposed
/// </summary>
event EventHandler OnDisposeCompleted;
#endregion
#region properties
/// <summary>
/// unique meter identification
/// </summary>
String SerialNumber { get; set; }
/// <summary>
/// read-only to see current Process state <see cref="ProcessState" />
/// </summary>
ProcessState ProcessStatus { get; }
/// <summary>
/// the current slot in test-bench
/// </summary>
Int32 Slot { get; set; }
/// <summary>
/// Setup of intermediate update time for measurement updates and overflow detections,
/// has to be calculated depending on flow-rate and nominal diameter (DN)
/// </summary>
Int32 IntermediateUpdateTimeS { get; set; }
/// <summary>
/// Skip the test bench preparation process
/// </summary>
Boolean SkipPreparationForTestBench { get; set; }
/// <summary>
/// Set the current action test
/// </summary>
String CurrentActionText { get; set; }
#endregion
#region method
/// <summary>
/// Read the PcbId from IMeter, if device has no readable PcbId simulate one
/// </summary>
/// <returns></returns>
String GetPcbId();
/// <summary>
/// Open Com ports, try some communication, login
/// </summary>
void ConnectMeter();
/// <summary>
/// Setup up meter from config file. just a workaround for vb6 calls. please do not use if your working with .net
/// </summary>
/// <param name="slot">Slot Number for Test bench</param>
/// <param name="ignoreCorruptedData">don´t send CRC error or telegrams with error flag to caller</param>
/// <param name="useRequest"></param>
/// <param name="useStreaming"></param>
void SetupFromConfigFile(Int32 slot, Boolean ignoreCorruptedData = true, Boolean useRequest = true, Boolean useStreaming = true);
/// <summary>
/// Logout from device
/// </summary>
Boolean Logout();
/// <summary>
/// Start Login with password service
/// </summary>
Boolean Login();
/// <summary>
/// Start Login without password service and a fixed password
/// </summary>
/// <param name="password">password for login</param>
/// <param name="runImmediately">execute immediately</param>
/// <param name="skipReadMeterFwAndAssignRegisters">skip app readout and register generation to speed up
/// the initial connection process</param>
Boolean Login(String password, Boolean runImmediately = true, Boolean skipReadMeterFwAndAssignRegisters = false);
/// <summary>
/// set up measurement parameter and set meter into test-mode
/// </summary>
void InitMeasurement();
/// <summary>
/// Starting a Measurement
/// Meter must be initialized <see cref="InitMeasurement" />
/// Start to receive record from meter and decode this record into <code>MeasurementRecord</code>
/// <see cref="IMeasurementRecord" />
/// </summary>
[ComVisible(false)]
void StartMeasurement();
/// <summary>
/// Meter must have a active measurement <see cref="StartMeasurement" />
/// Stop receive record from meter and decode record
/// </summary>
void StopMeasurement();
/// <remarks date="2018JAN09" author="drabesch">
/// - simplify the measurement results handling
/// - getting the main measurement of the entire device (combination of all paths)
/// - add MeasurementResult
/// - remove all other methods
/// </remarks>
/// <summary>
/// After a completed measurement , you can grab <see cref="MeasurementResults"/>
/// </summary>
/// <returns>Calculated results</returns>
MeasurementResults GetMainMeasurementResult(Double? refVolume, Double? refTimeS, Boolean intermediateMeasurement = false, MeasurementDirection dir = MeasurementDirection.TakeBoth);
/// <summary>
/// The first measurement is ALWAYS a FlowTestRecord.
/// </summary>
List<MeasurementResults> GetAllMeasurementResults(Double? refVolume, Double? refTimeS,
Boolean intermediateMeasurement = false, Int32? channel = null, MeasurementDirection dir = MeasurementDirection.TakeBoth);
/// <summary>
/// get current state of the running measurement
/// </summary>
/// <param name="onlyChannelNr">leave empty for an aggregate state for all measurements or pass the channel number to check</param>
/// <returns></returns>
MeasurementStates GetMeasurementState(Int32? onlyChannelNr = null );
/// <summary>
/// Request for intermediate measurement state.
/// </summary>
/// <param name="onlyChannelNr"></param>
/// <returns></returns>
Boolean RequestIntermediateMeasurementState(Int32? onlyChannelNr = null);
/// <summary>
/// set up calibration parameter (calibration factor to default) and set meter into calibration mode
/// </summary>
void InitCalibration();
/// <summary>
/// Starting a Calibration
/// Meter must be initialized <see cref="InitCalibration" />
/// Start to receive record from meter, decode and store this record
/// no <see cref="IMeasurementRecord" /> available
/// To finish calibration process run <see cref="StopCalibration" />
/// </summary>
[ComVisible(false)]
void StartCalibration();
/// <summary>
/// Meter must have an active Stop Record for calibration
/// </summary>
void StopCalibration();
/// <summary>
/// Get current state of the running calibration
/// </summary>
/// <returns></returns>
MeasurementStates GetCalibrationState();
/// <summary>
/// Calculate calibration factor for static and flying start / stop
/// Results kept internal and not being saved to meter.
/// if you want to store them on meter use <see cref="SetCalibFactorsAllChannels" />
/// </summary>
/// <param name="refVolumeCm">the reference volume is essential for calculation of calibration factor</param>
/// <param name="refTimeS">the reference time is needed for flying start/stop</param>
/// <param name="reqDeviationPercent">the required deviation to set the scale apart from 0</param>
/// <param name="maxCalibFactorTolerancePercent"> override the default max calibration factor tolerance</param>
void BuildAndCheckCalibFactorsAllChannels(Double refVolumeCm, Double? refTimeS = null, Double reqDeviationPercent = 0.0, Double maxCalibFactorTolerancePercent = 0.0);
/// <summary>
/// Save calculated calibration on meter if no calibration results available an exception occurred
/// </summary>
void SetCalibFactorsAllChannels(Boolean justLog = false);
/// <summary>
/// To control the LCD from meter for status information etc.
/// </summary>
/// <param name="release">if set to true the meter will show his normal screen, if set to false the next parameter will shown in display</param>
/// <param name="textInHex">test shown in LCD in byte array as hex value (0x33,0xFF shows 33FF on screen)</param>
void SetLcdText(Boolean release, Byte[] textInHex);
/// <summary>
/// Sets Display text and update production database
/// </summary>
/// <param name="newState">New ProductionState</param>
/// <param name="webRequest">web logging required per default true, for offline usage set to false</param>
void SetProcessState(DisplayCodes newState, Boolean webRequest = true);
/// <summary>
/// Get last Process State
/// </summary>
DisplayCodes GetLastProcessState();
/// <summary>
/// Add external text to internal log file handling
/// </summary>
/// <param name="text">text to log</param>
void WriteLog(String text);
/// <summary>
/// Enable/Disable Raw record Logging
/// </summary>
/// <param name="on">True = Write Raw record into log/ false = Stop write raw record into log </param>
void LogRawData(Boolean on);
/// <summary>
/// Check if the meter has any errors that can occur on a measurement
/// the error reason has find out in the log files
/// </summary>
/// <returns>false = everything is good, detect at least one error</returns>
Boolean CheckStateAfterMeasurement();
#endregion
/// <summary>
/// Clear all object set up on runtime
/// </summary>
void DisposeMeter();
/// <summary>
/// Dispose the entire test bench
/// </summary>
void TestBenchDispose();
}
}