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