88 lines
3.4 KiB
C#
88 lines
3.4 KiB
C#
namespace Common.Hardware.WaterMeter.OmniPlus.Programming
|
|
{
|
|
using Common.Hardware.WaterMeter.OmniPlus.Features;
|
|
using Common.Hardware.WaterMeter.OmniPlus.Features.Enums;
|
|
|
|
using System;
|
|
|
|
internal class ProgrammingState
|
|
{
|
|
public String PortName { get; set; }
|
|
|
|
public OmniConnection Connection { get; set; }
|
|
|
|
public OMNI OMNI { get; set; }
|
|
|
|
public void ConnectToIrda() => this.Connection.UseIrda(this.PortName);
|
|
|
|
public void ConnectToUniPro() => this.Connection.UseUniPro(this.PortName);
|
|
|
|
public void ViewSystemParameters()
|
|
{
|
|
var systemParameters = this.Connection.ViewSystemParameters();
|
|
|
|
this.OMNI.LastCmdStatus = systemParameters.Status;
|
|
this.OMNI.LastCmdCompleted = systemParameters.Completed;
|
|
this.OMNI.LastCmdMessage = systemParameters.Status.ToString();
|
|
this.OMNI.HasValidSystem = systemParameters.Completed && systemParameters.IsValid;
|
|
this.OMNI.SystemValidationMessage = systemParameters.ValidationMessage;
|
|
this.OMNI.Pcb = systemParameters.BuildInfo.Value;
|
|
this.OMNI.ManifacturingDate = systemParameters.ManifacturingTime.DateTime;
|
|
|
|
this.OMNI.NotifyStateHasChanged();
|
|
}
|
|
|
|
public void SetCalibrationParameters(CalibrationParameters parameters)
|
|
{
|
|
var setInputVolumeResponse = this.Connection.Set(new InputVolume
|
|
{
|
|
Direction = parameters.Direction,
|
|
Fraction = parameters.Fraction,
|
|
IntPart = parameters.IntPart,
|
|
Range = parameters.Range,
|
|
Size = parameters.Size
|
|
});
|
|
|
|
this.OMNI.LastCmdStatus = setInputVolumeResponse.Status;
|
|
this.OMNI.LastCmdCompleted = setInputVolumeResponse.Completed;
|
|
this.OMNI.LastCmdMessage = setInputVolumeResponse.Status.ToString();
|
|
|
|
this.OMNI.NotifyStateHasChanged();
|
|
}
|
|
|
|
public void StartCalibration(StartCalibrationParameters parameters)
|
|
{
|
|
var startCalibrationResponse = this.Connection.StartChamberCalibration(
|
|
parameters.Rotations,
|
|
parameters.Duration);
|
|
|
|
this.OMNI.LastCmdStatus = startCalibrationResponse.Status;
|
|
this.OMNI.LastCmdCompleted = startCalibrationResponse.Completed;
|
|
this.OMNI.LastCmdMessage = startCalibrationResponse.Status.ToString();
|
|
|
|
this.OMNI.NotifyStateHasChanged();
|
|
}
|
|
|
|
public void StopCalibration()
|
|
{
|
|
var viewCalibrationResponse = this.Connection.ViewChamberCalibration();
|
|
|
|
this.OMNI.LastCmdStatus = viewCalibrationResponse.Status;
|
|
this.OMNI.LastCmdCompleted = viewCalibrationResponse.Completed;
|
|
this.OMNI.LastCmdMessage = viewCalibrationResponse.Status.ToString();
|
|
this.OMNI.LastCalibrationRotations = viewCalibrationResponse.Rotations;
|
|
this.OMNI.LastCalibrationDuration = viewCalibrationResponse.DurationSec;
|
|
|
|
this.OMNI.NotifyStateHasChanged();
|
|
}
|
|
|
|
internal void AddException(Exception exception)
|
|
{
|
|
this.OMNI.LastCmdCompleted = false;
|
|
this.OMNI.LastCmdStatus = Status.Exception;
|
|
this.OMNI.LastCmdMessage = $"{this.OMNI.LastCmdMessage}{Environment.NewLine}{Status.Exception}{Environment.NewLine}{exception}";
|
|
|
|
this.OMNI.NotifyStateHasChanged();
|
|
}
|
|
}
|
|
} |