469 lines
21 KiB
Plaintext
469 lines
21 KiB
Plaintext
|
|
using DbAPI.Errors;
|
||
|
|
using DbAPIUI.Logging;
|
||
|
|
using DTS.Common.Classes.Channels;
|
||
|
|
using DTS.Common.Classes.Groups;
|
||
|
|
using DTS.Common.Classes.Hardware;
|
||
|
|
using DTS.Common.Classes.Sensors;
|
||
|
|
using DTS.Common.Classes.TestSetups;
|
||
|
|
using DTS.Common.Interface.Channels;
|
||
|
|
using DTS.Common.Interface.Database;
|
||
|
|
using DTS.Common.Interface.DataRecorders;
|
||
|
|
using DTS.Common.Interface.Groups;
|
||
|
|
using DTS.Common.Interface.Sensors;
|
||
|
|
using DTS.Common.Interface.TestSetups.TestSetupsList;
|
||
|
|
using System;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using System.Diagnostics;
|
||
|
|
using System.IO;
|
||
|
|
using System.Linq;
|
||
|
|
using System.Threading.Tasks;
|
||
|
|
using static DTS.Common.Enums.ExcitationVoltageOptions;
|
||
|
|
|
||
|
|
namespace DbAPIUI
|
||
|
|
{
|
||
|
|
public class DoEverythingSample
|
||
|
|
{
|
||
|
|
public void Start()
|
||
|
|
{
|
||
|
|
Task.Run(() => { Connect(); });
|
||
|
|
}
|
||
|
|
private ConnectionDetailsEx _connection;
|
||
|
|
private const string DB_FILES_LOCATION = "db";
|
||
|
|
private const string SQL_FILES_LOCATION = "SQL Server Scripts";
|
||
|
|
private void LogStub(params object[] paramList) { }
|
||
|
|
private void Connect()
|
||
|
|
{
|
||
|
|
//step 1, look for an mdb file and a scripts directory, we need them to mount the db
|
||
|
|
//and connect. The db api will connect, but we'll have to provide it information
|
||
|
|
_connection = new ConnectionDetailsEx() { SqlDbPath = ConnectionDetailsEx.GetSqlServerLocalDbPath(),
|
||
|
|
ODBCToolsPath = DTS.Common.Utils.Database.GetODBCToolsPath(LogStub) };
|
||
|
|
|
||
|
|
if(Directory.Exists(DB_FILES_LOCATION))
|
||
|
|
{
|
||
|
|
var di = new DirectoryInfo(DB_FILES_LOCATION);
|
||
|
|
_connection.DbFolderPath = di.FullName;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (Directory.Exists(SQL_FILES_LOCATION))
|
||
|
|
{
|
||
|
|
var di = new DirectoryInfo(SQL_FILES_LOCATION);
|
||
|
|
_connection.AttachDbsBatPath = Path.Combine(di.FullName, "AttachDBs.bat");
|
||
|
|
}
|
||
|
|
|
||
|
|
var hr = DbAPI.DbAPI.Connections.ConnectToDb(_connection);
|
||
|
|
if( 0 == hr)
|
||
|
|
{
|
||
|
|
LogManager.Log(TraceEventType.Information,
|
||
|
|
LogManager.LogEvents.Connections, $"Success fully connected: {_connection}");
|
||
|
|
Login();
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
LogManager.Log(TraceEventType.Information,
|
||
|
|
LogManager.LogEvents.Connections, $"Failed to connect: {_connection} - {ErrorCodes.ResultToString(hr)}");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
private IUserDbRecord _user;
|
||
|
|
private void Login()
|
||
|
|
{
|
||
|
|
var hr = DbAPI.DbAPI.Connections.LoginUser(_connection, "Admin", "DTSAdmin", out var user);
|
||
|
|
if( 0 == hr)
|
||
|
|
{
|
||
|
|
_user = user;
|
||
|
|
LogManager.Log(TraceEventType.Information, LogManager.LogEvents.Connections,
|
||
|
|
$"Login successful: {user.DisplayName}");
|
||
|
|
AddSensors();
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.Connections,
|
||
|
|
$"Login failed: {user.DisplayName} {ErrorCodes.ResultToString(hr)}");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
private List<IAnalogDbRecord> _sensors = new List<IAnalogDbRecord>();
|
||
|
|
private Dictionary<IAnalogDbRecord, ISensorCalDbRecord> _calRecords = new Dictionary<IAnalogDbRecord, ISensorCalDbRecord>();
|
||
|
|
private void AddSensors()
|
||
|
|
{
|
||
|
|
_sensors.Clear();
|
||
|
|
_calRecords.Clear();
|
||
|
|
|
||
|
|
var failed = false;
|
||
|
|
for( var i = 0; i < 3; i++)
|
||
|
|
{
|
||
|
|
if( !CreateSensorAndCal($"Sensor {i + 1:000}", "Generic Analog Sensor", 2400))
|
||
|
|
{
|
||
|
|
failed = true;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if(failed) { return; }
|
||
|
|
CreateDAS();
|
||
|
|
}
|
||
|
|
private void CreateDAS()
|
||
|
|
{
|
||
|
|
var failed = false;
|
||
|
|
|
||
|
|
var hr = DbAPI.DbAPI.DAS.DASGet(_user, _connection, _connection.ClientDbVersion, "SLICEPRO Prototype", "Prototype", out var records);
|
||
|
|
if( 0 != hr || null == records || 0 == records.Length)
|
||
|
|
{
|
||
|
|
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.DAS, $"Failed to retrieve SPS prototype");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
LogManager.Log(TraceEventType.Information, LogManager.LogEvents.DAS, $"DASGet success");
|
||
|
|
|
||
|
|
var newDAS = new DASDBRecord(records.First());
|
||
|
|
|
||
|
|
|
||
|
|
hr = DbAPI.DbAPI.DAS.DASChannelsGet(_user, _connection, $"{newDAS.SerialNumber}_{newDAS.DASType}", out var channelRecords);
|
||
|
|
|
||
|
|
if( 0 != hr || null == channelRecords || 0 == channelRecords.Length)
|
||
|
|
{
|
||
|
|
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.DAS, "DASChannelsGet Error - {hr}");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
LogManager.Log(TraceEventType.Information, LogManager.LogEvents.DAS, "DASChannelsGet success");
|
||
|
|
|
||
|
|
newDAS.SerialNumber = "SPS0001";
|
||
|
|
newDAS.Position = "";
|
||
|
|
newDAS.DASId = -1;
|
||
|
|
newDAS.CalDate = DateTime.Today;
|
||
|
|
hr = DbAPI.DbAPI.DAS.DASInsert(_user, _connection, newDAS);
|
||
|
|
if( 0 != hr)
|
||
|
|
{
|
||
|
|
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.DAS, $"DASInsert - Error - {hr}");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
LogManager.Log(TraceEventType.Information, LogManager.LogEvents.DAS, $"DASInsert {newDAS.SerialNumber} - success");
|
||
|
|
_Das = newDAS;
|
||
|
|
|
||
|
|
foreach( var channelRecord in channelRecords)
|
||
|
|
{
|
||
|
|
channelRecord.DaschannelId = -1;
|
||
|
|
channelRecord.Dasid = newDAS.DASId;
|
||
|
|
var iCh = (IDASChannelDBRecord)channelRecord;
|
||
|
|
hr = DbAPI.DbAPI.DAS.DASChannelsInsert(_user, _connection, $"{newDAS.SerialNumber}_{newDAS.DASType}",
|
||
|
|
ref iCh);
|
||
|
|
if( 0 != hr)
|
||
|
|
{
|
||
|
|
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.DAS, $"DASChannelsInsert - Error {hr}");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!failed) { CreateGroups(); }
|
||
|
|
}
|
||
|
|
private IDASDBRecord _Das = null;
|
||
|
|
private List<IGroupDbRecord> _groups = new List<IGroupDbRecord>();
|
||
|
|
private Dictionary<IGroupDbRecord, IChannelDbRecord[]> _channels = new Dictionary<IGroupDbRecord, IChannelDbRecord[]>();
|
||
|
|
private void CreateGroups()
|
||
|
|
{
|
||
|
|
_groups.Clear();
|
||
|
|
_channels.Clear();
|
||
|
|
|
||
|
|
var group = CreateGroup("MyStaticGroup", "MyStaticGroup", false);
|
||
|
|
var hr = DbAPI.DbAPI.Groups.GroupsInsert(_user, _connection, ref group);
|
||
|
|
if( 0 != hr)
|
||
|
|
{
|
||
|
|
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.TestSetups, $"GroupsInsert - Error - {hr}");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
LogManager.Log(TraceEventType.Information, LogManager.LogEvents.TestSetups, $"GroupsInsert static {group.DisplayName} success");
|
||
|
|
|
||
|
|
hr = DbAPI.DbAPI.GroupHardware.GroupHardwareInsert(_user, _connection,
|
||
|
|
new GroupHardwareDbRecord() { DASId = _Das.DASId, GroupId = group.Id, Id = -1, SerialNumber = _Das.SerialNumber },
|
||
|
|
out var newId, out var errorMessage);
|
||
|
|
if( 0 != hr)
|
||
|
|
{
|
||
|
|
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.DAS, $"GroupHardwareInsert - Error - {hr}");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
LogManager.Log(TraceEventType.Information, LogManager.LogEvents.DAS, $"GroupHardwareInsert success");
|
||
|
|
|
||
|
|
if (!CreateGroupChannels(ref group, out var groupChannels))
|
||
|
|
{
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!InsertGroupAndChannels(ref group, groupChannels))
|
||
|
|
{
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
var id = group.Id;
|
||
|
|
group = CreateGroup(Guid.NewGuid().ToString(), "MyStaticGroup", true);
|
||
|
|
group.StaticGroupId = id;
|
||
|
|
if (!CreateTestSetup()) { return; }
|
||
|
|
if (!InsertGroupAndChannels(ref group, groupChannels)) { return; }
|
||
|
|
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsInsert(_user, _connection,
|
||
|
|
new TestSetupGroupRecord()
|
||
|
|
{
|
||
|
|
DisplayOrder = 0,
|
||
|
|
GroupId = group.Id,
|
||
|
|
Position = "?",
|
||
|
|
TestObjectType = "?",
|
||
|
|
TestSetupId = _test.Id
|
||
|
|
});
|
||
|
|
if( 0 == hr)
|
||
|
|
{
|
||
|
|
LogManager.Log(TraceEventType.Information, LogManager.LogEvents.TestSetups, $"TestSetupGroupsInsert inserted {group.DisplayName} in test setup: {_test.Name}");
|
||
|
|
}
|
||
|
|
else { LogManager.Log(TraceEventType.Error, LogManager.LogEvents.TestSetups, $"TestSetupGroupInsert - Error - {hr}"); }
|
||
|
|
|
||
|
|
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareInsert(_user, _connection, new TestSetupHardwareRecord()
|
||
|
|
{
|
||
|
|
AddDAS = true,
|
||
|
|
AntiAliasFilterRate = 2000,
|
||
|
|
DASId = _Das.DASId,
|
||
|
|
IsClockMaster = false,
|
||
|
|
SamplesPerSecond = Convert.ToInt32(_test.SamplesPerSecondAggregate),
|
||
|
|
TestSetupId = _test.Id
|
||
|
|
});
|
||
|
|
if (0 != hr)
|
||
|
|
{
|
||
|
|
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.TestSetups, $"TestSetupHardwareInsert - Error - {ErrorCodes.ResultToString(hr)}");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
LogManager.Log(TraceEventType.Information, LogManager.LogEvents.TestSetups, $"TestSetupHardwareInsert - success");
|
||
|
|
}
|
||
|
|
private bool CreateTestSetup()
|
||
|
|
{
|
||
|
|
var test = new TestSetupRecord();
|
||
|
|
test.AllowMissingSensors = true;
|
||
|
|
test.AllowSensorIdToBlankChannel = true;
|
||
|
|
var iTest = (ITestSetupRecord)test;
|
||
|
|
SetTSRAirProperties(ref iTest);
|
||
|
|
test.AutomaticProgression = false;
|
||
|
|
test.AutomaticProgressionDelayMS = 5;
|
||
|
|
test.AutoVerifyChannels = false;
|
||
|
|
test.CalibrationBehavior = DTS.Common.Enums.Sensors.CalibrationBehaviors.LinearIfAvailable;
|
||
|
|
test.CheckoutMode = false;
|
||
|
|
test.CommonStatusLine = true;
|
||
|
|
test.CustomerDetails = "";
|
||
|
|
test.DefaultNumberRealtimeGraphs = 6;
|
||
|
|
test.Description = "A fine test setup";
|
||
|
|
test.DoAutoArm = false;
|
||
|
|
test.DoROIDownload = true;
|
||
|
|
test.DoStreaming = false;
|
||
|
|
test.DownloadAll = true;
|
||
|
|
test.ExportFormats = DTS.Common.Enums.SupportedExportFormatBitFlags.none;
|
||
|
|
test.InvertStartRecordCompletion = false;
|
||
|
|
test.InvertTriggerCompletion = false;
|
||
|
|
test.ISFFile = "";
|
||
|
|
test.LabDetails = "";
|
||
|
|
test.LastModified = DateTime.Today;
|
||
|
|
test.LastModifiedBy = _user.UserName;
|
||
|
|
test.LocalOnly = false;
|
||
|
|
test.MeasureSquibResistancesStep = false;
|
||
|
|
test.Name = "MyTestSetup";
|
||
|
|
test.NumberOfEvents = 1;
|
||
|
|
test.PostTestDiagnosticsLevel = false;
|
||
|
|
test.PostTriggerSeconds = 10;
|
||
|
|
test.PreTriggerSeconds = 1;
|
||
|
|
test.QuitTestWithoutWarning = false;
|
||
|
|
test.RecordingMode = DTS.Common.Enums.RecordingModes.CircularBuffer;
|
||
|
|
test.RequireUserConfirmationOnErrors = true;
|
||
|
|
test.ROIStart = -.5;
|
||
|
|
test.ROIEnd = .5;
|
||
|
|
test.SamplesPerSecondAggregate = 20000;
|
||
|
|
test.StrictDiagnostics = false;
|
||
|
|
test.SuppressMissingSensorsWarning = false;
|
||
|
|
test.TestEngineerDetails = "";
|
||
|
|
test.TriggerCheckStep = true;
|
||
|
|
test.TurnOffExcitation = false;
|
||
|
|
test.UploadData = false;
|
||
|
|
test.UseCustomerDetails = false;
|
||
|
|
test.UseLabratoryDetails = false;
|
||
|
|
test.UseTestEngineerDetails = false;
|
||
|
|
test.VerifyChannels = true;
|
||
|
|
test.ViewDiagnostics = true;
|
||
|
|
test.ViewDownloadAll = false;
|
||
|
|
test.ViewExport = false;
|
||
|
|
test.ViewRealtime = true;
|
||
|
|
test.ViewROIDownload = true;
|
||
|
|
test.WarnOnFailedBattery = true;
|
||
|
|
var hr = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, _connection, _connection.ClientDbVersion, ref iTest);
|
||
|
|
if (0 != hr)
|
||
|
|
{
|
||
|
|
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.TestSetups, $"TestSetupsInsert failed: {ErrorCodes.ResultToString(hr)}");
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
LogManager.Log(TraceEventType.Information, LogManager.LogEvents.TestSetups, $"TestSetupInsert Success");
|
||
|
|
_test = test;
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
private ITestSetupRecord _test;
|
||
|
|
private void SetTSRAirProperties(ref ITestSetupRecord test)
|
||
|
|
{
|
||
|
|
test.BatterySaverModeOn = false;
|
||
|
|
test.AngularAccelLevelTriggerOn = false;
|
||
|
|
test.AngularRateLevelTriggerOn = false;
|
||
|
|
test.HighgLevelTriggerOn = false;
|
||
|
|
test.HumidityLevelTriggerOn = false;
|
||
|
|
test.LowgLevelTriggerOn = false;
|
||
|
|
test.PressureLevelTriggerOn = false;
|
||
|
|
test.RTCScheduleDuration = new TimeSpan(0);
|
||
|
|
test.RTCScheduleStartDateTime = DateTime.Today;
|
||
|
|
test.RTCScheduleTriggerOn = false;
|
||
|
|
test.TemperatureLevelTriggerOn = false;
|
||
|
|
test.WakeUpAndArmTriggerOn = false;
|
||
|
|
test.WakeUpTimeDuration = new TimeSpan(0);
|
||
|
|
test.WakeUpTimeSessionStart = DateTime.Today;
|
||
|
|
}
|
||
|
|
private bool InsertGroupAndChannels(ref IGroupDbRecord group, IChannelDbRecord [] channels)
|
||
|
|
{
|
||
|
|
var hr = DbAPI.DbAPI.Groups.GroupsInsert(_user, _connection, ref group);
|
||
|
|
if (0 != hr)
|
||
|
|
{
|
||
|
|
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.TestSetups, $"Failed to insert group: {ErrorCodes.ResultToString(hr)}");
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
else { LogManager.Log(TraceEventType.Information, LogManager.LogEvents.TestSetups, $"Created group: {group.SerialNumber}"); }
|
||
|
|
|
||
|
|
hr = DbAPI.DbAPI.GroupHardware.GroupHardwareInsert(_user, _connection,
|
||
|
|
new GroupHardwareDbRecord()
|
||
|
|
{
|
||
|
|
DASId = _Das.DASId,
|
||
|
|
GroupId = group.Id,
|
||
|
|
SerialNumber = _Das.SerialNumber
|
||
|
|
}, out var newId, out var errorMessage);
|
||
|
|
|
||
|
|
if( 0 != hr)
|
||
|
|
{
|
||
|
|
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.DAS, $"GroupHardwareInsert - Error - {ErrorCodes.ResultToString(hr)}");
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
LogManager.Log(TraceEventType.Information, LogManager.LogEvents.DAS, $"GroupHardwareInsert - success");
|
||
|
|
_groups.Add(group);
|
||
|
|
for (var i = 0; i < channels.Length; i++)
|
||
|
|
{
|
||
|
|
var channel = channels[i];
|
||
|
|
channel.GroupId = group.Id;
|
||
|
|
channel.DASId = _Das.DASId;
|
||
|
|
channel.DASChannelIndex = i;
|
||
|
|
hr = DbAPI.DbAPI.Channels.ChannelsInsert(_user, _connection, ref channel);
|
||
|
|
if (0 != hr)
|
||
|
|
{
|
||
|
|
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.TestSetups, $"Failed to insert channel: {group.SerialNumber}:{i:00} {ErrorCodes.ResultToString(hr)}");
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
LogManager.Log(TraceEventType.Information, LogManager.LogEvents.TestSetups, $"Created channel: {group.SerialNumber}:{i:00}");
|
||
|
|
}
|
||
|
|
_channels[group] = channels;
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
private bool CreateGroupChannels(ref IGroupDbRecord group, out IChannelDbRecord [] channels)
|
||
|
|
{
|
||
|
|
var list = new List<IChannelDbRecord>();
|
||
|
|
for (int i = 0; i < _sensors.Count; i++)
|
||
|
|
{
|
||
|
|
list.Add(CreateChannel(i));
|
||
|
|
}
|
||
|
|
channels = list.ToArray();
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
private IChannelDbRecord CreateChannel(int index)
|
||
|
|
{
|
||
|
|
var channel = new ChannelDbRecord();
|
||
|
|
channel.DASChannelIndex = index;
|
||
|
|
channel.DASId = _Das.DASId;
|
||
|
|
channel.GroupChannelOrder = index;
|
||
|
|
channel.IsoChannelName = $"CHANNEL {index + 1:0000}";
|
||
|
|
channel.IsoCode = $"??{index:0000}??????????";
|
||
|
|
channel.LastModified = DateTime.Now;
|
||
|
|
channel.LastModifiedBy = _user.UserName;
|
||
|
|
channel.SensorId = _sensors[index].Id;
|
||
|
|
channel.TestSetupOrder = index;
|
||
|
|
channel.UserChannelName = channel.IsoChannelName;
|
||
|
|
channel.UserCode = channel.IsoCode;
|
||
|
|
return channel;
|
||
|
|
}
|
||
|
|
private IGroupDbRecord CreateGroup(string serialNumber, string displayname, bool embedded )
|
||
|
|
{
|
||
|
|
var group = new GroupDbRecord();
|
||
|
|
group.DisplayName = displayname;
|
||
|
|
group.SerialNumber = serialNumber;
|
||
|
|
group.Embedded = embedded;
|
||
|
|
group.Description = "Generic Group";
|
||
|
|
group.ExtraProperties = "";
|
||
|
|
group.LastModified = DateTime.Today;
|
||
|
|
group.LastModifiedBy = _user.UserName;
|
||
|
|
group.Picture = "";
|
||
|
|
return group;
|
||
|
|
}
|
||
|
|
private bool CreateSensorAndCal(string serialNumber, string comment, int capacity)
|
||
|
|
{
|
||
|
|
var sensor = CreateAnalogSensor(serialNumber, comment, capacity);
|
||
|
|
var hr = DbAPI.DbAPI.Sensors.SensorsAnalogUpdateInsert(_user, _connection, sensor);
|
||
|
|
if( 0 != hr)
|
||
|
|
{
|
||
|
|
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.Sensors, $"Failed to insert sensor {ErrorCodes.ResultToString(hr)}");
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
else { LogManager.Log(TraceEventType.Information, LogManager.LogEvents.Sensors, $"Created sensor {serialNumber}"); }
|
||
|
|
_sensors.Add(sensor);
|
||
|
|
var sc = CreateAnalogSensorCalibration(sensor);
|
||
|
|
hr = DbAPI.DbAPI.Sensors.SensorCalibrationsInsert(_user, _connection, sc, 0, true);
|
||
|
|
if( 0 != hr)
|
||
|
|
{
|
||
|
|
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.Sensors, $"Failed to insert sensor calibration {ErrorCodes.ResultToString(hr)}");
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
else { LogManager.Log(TraceEventType.Information, LogManager.LogEvents.Sensors, $"Created SensorCalibration {serialNumber}"); }
|
||
|
|
|
||
|
|
_calRecords[sensor] = sc;
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
private ISensorCalDbRecord CreateAnalogSensorCalibration(IAnalogDbRecord sensor)
|
||
|
|
{
|
||
|
|
var sc = new SensorCalDbRecord();
|
||
|
|
sc.SerialNumber = sensor.SerialNumber;
|
||
|
|
sc.CalibrationDate = DateTime.Today;
|
||
|
|
sc.InitialOffsets = new InitialOffsets(new InitialOffset((double)sensor.InitialEu));
|
||
|
|
sc.IsProportional = true;
|
||
|
|
sc.NonLinear = false;
|
||
|
|
sc.RemoveOffset = true;
|
||
|
|
sc.ModifyDate = DateTime.Now;
|
||
|
|
sc.ZeroMethods = new ZeroMethods(new ZeroMethod(DTS.Common.Enums.Sensors.ZeroMethodType.AverageOverTime, -.5, .5));
|
||
|
|
sc.Records = new CalibrationRecords() { Records = new[] { GenerateCalibrationRecord() } };
|
||
|
|
return sc;
|
||
|
|
}
|
||
|
|
private ICalibrationRecord GenerateCalibrationRecord()
|
||
|
|
{
|
||
|
|
var record = new CalibrationRecord();
|
||
|
|
record.AtCapacity = false;
|
||
|
|
record.EngineeringUnits = "G";
|
||
|
|
record.Excitation = ExcitationVoltageOption.Volt5;
|
||
|
|
record.InitialOffsetMethod = DTS.Common.Enums.Sensors.InitialOffsetTypes.EU;
|
||
|
|
record.Sensitivity = .2;
|
||
|
|
record.SensitivityUnits = DTS.Common.Enums.Sensors.SensorConstants.SensUnits.mVperVperEU;
|
||
|
|
record.ZeroPoint = 0;
|
||
|
|
return record;
|
||
|
|
}
|
||
|
|
private IAnalogDbRecord CreateAnalogSensor(string serialNumber, string description, int capacity)
|
||
|
|
{
|
||
|
|
var sensor = new AnalogDbRecord() { SerialNumber = serialNumber, Comment = description, Capacity = capacity };
|
||
|
|
sensor.Bridge = DTS.Common.Enums.Sensors.SensorConstants.BridgeType.FullBridge;
|
||
|
|
sensor.BridgeResistance = 350;
|
||
|
|
sensor.CalInterval = 365;
|
||
|
|
sensor.CheckOffset = true;
|
||
|
|
sensor.Created = DateTime.Today;
|
||
|
|
sensor.DiagnosticsMode = false;
|
||
|
|
sensor.DisplayUnit = "G";
|
||
|
|
sensor.Filter = new FilterClass(DTS.Common.Enums.Sensors.FilterClassType.CFC1000);
|
||
|
|
sensor.FirstUseDate = null;
|
||
|
|
sensor.InitialEu = 0;
|
||
|
|
sensor.ISOChannelName = "";
|
||
|
|
sensor.ISOCode = "";
|
||
|
|
sensor.LastModified = DateTime.Today;
|
||
|
|
sensor.Manufacturer = "DTS";
|
||
|
|
sensor.Model = "Generic Sensor";
|
||
|
|
sensor.ModifiedBy = _user.UserName;
|
||
|
|
sensor.OffsetToleranceHigh = 1000;
|
||
|
|
sensor.OffsetToleranceLow = -1000;
|
||
|
|
sensor.Shunt = 1;
|
||
|
|
sensor.SupportedExcitation = new[] { ExcitationVoltageOption.Volt5 };
|
||
|
|
return sensor;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|