Files
DP44/Common/DTS.Common.Import/CalibrationImport.cs

81 lines
3.4 KiB
C#
Raw Permalink Normal View History

2026-04-17 14:55:32 -04:00
using DTS.Common.Classes.Sensors;
using DTS.Common.Enums;
using DTS.Common.Enums.Sensors;
using DTS.Common.Interface.Sensors;
using DTS.SensorDB;
using System.Collections.Generic;
namespace DTS.Common.Import
{
public class CalibrationImport : ICalibrationImport
{
public SensorCalibration CheckForExcitationCalibration(SensorCalibration sc, double sensitivity, ExcitationVoltageOptions.ExcitationVoltageOption excitation, string EU)
{
//we may have already handled this, so check
if (sc.Records.Records[0].Excitation == excitation)
{
return sc;
}
var records = new List<ICalibrationRecord>(sc.Records.Records);
var r = new CalibrationRecord
{
AtCapacity = false,
EngineeringUnits = EU,
Excitation = excitation,
Sensitivity = sensitivity,
CapacityOutputIsBasedOn = 1.000
};
records.Add(r);
sc.Records.Records = records.ToArray();
return sc;
}
public SensorCalibration AddLinearCalRecordIfNeeded(SensorCalibration sc, bool savedIsProportional, bool savedRemoveOffset)
{
if (sc.Records.Records.Length == 1)
{
//Since sc.Records.Records is an array and not a List, make a list of two records - the existing
//non-linear and a new linear - and replace the existing array of length 1 with a new array of length 2.
var records = new List<ICalibrationRecord>();
//Add the existing non-linear
records.AddRange(sc.Records.Records);
//Add a new record for linear
var newSc = new SensorCalibration();
newSc.Records.Records[0].Poly.MarkValid(false);
records.Add(newSc.Records.Records[0]);
//Replace the existing single record with two
sc.Records.Records = records.ToArray();
//Since there is both a linear and non-linear calibration, IsProportional and RemoveOffset
//should apply to the linear, and were set to False when the sensor was set to NonLinear
sc.IsProportional = savedIsProportional;
sc.RemoveOffset = savedRemoveOffset;
}
return sc;
}
public SensorCalibration AddLinearZeroMethodIfNeeded(SensorCalibration sc, ZeroMethodType zeroMethodType, double zeroMethodStart, double zeroMethodEnd)
{
if (sc.ZeroMethods.Methods.Length == 1)
{
//Since sc.ZeroMethods.Methods is an array and not a List, make a list of two records - the existing
//non-linear and a new linear - and replace the existing array of length 1 with a new array of length 2.
var methods = new List<ZeroMethod>();
//Add the existing non-linear
methods.AddRange(sc.ZeroMethods.Methods);
//Add a new record for linear
var newZm = new ZeroMethod(zeroMethodType, zeroMethodStart, zeroMethodEnd);
methods.Add(newZm);
//Replace the existing single record with two
sc.ZeroMethods.Methods = methods.ToArray();
}
return sc;
}
}
}