init
This commit is contained in:
@@ -0,0 +1,158 @@
|
||||
using DTS.Common.Interface.DASFactory;
|
||||
using DTS.Common.Interface.DASFactory.Diagnostics;
|
||||
using DTS.Common.Utilities.Logging;
|
||||
using System;
|
||||
|
||||
namespace DTS.DASLib.Service.Classes.Diagnostics
|
||||
{
|
||||
public static class DiagnosticsResultActions
|
||||
{
|
||||
/// <summary>
|
||||
/// clears all diagnostics from all events and channels, and optionally clears from db
|
||||
/// </summary>
|
||||
/// <param name="unit"></param>
|
||||
/// <param name="bClearDb"></param>
|
||||
public static void ClearChannelDiagnosticsResults(IDASCommunication unit, bool bClearDb = true)
|
||||
{
|
||||
unit.ChannelDiagnosticsResults = new IDiagnosticResult[0];
|
||||
unit.ChannelDiagnostics = new IDiagnosticActions[0];
|
||||
|
||||
if (!DASFactoryDb.DbWrapper.Connected || !bClearDb) { return; }
|
||||
|
||||
try
|
||||
{
|
||||
DASFactoryDb.Diagnostics.Diagnostics.ClearExistingDiagnosticsAllChannels(unit.RecordId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
APILogger.Log(ex);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// sets the channel diagnostics, optionally writes to the db
|
||||
/// </summary>
|
||||
/// <param name="unit"></param>
|
||||
/// <param name="results"></param>
|
||||
/// <param name="setInDb"></param>
|
||||
public static void SetChannelDiagnosticsResults(IDASCommunication unit, IDiagnosticResult[] results, bool setInDb)
|
||||
{
|
||||
unit.ChannelDiagnosticsResults = results;
|
||||
if (!DASFactoryDb.DbWrapper.Connected || !setInDb) { return; }
|
||||
try
|
||||
{
|
||||
foreach (var result in results)
|
||||
{
|
||||
var moduleNumber = unit.DASInfo.MapDASChannelNumber2ModuleArrayIndex(result.DASChannelNumber);
|
||||
var channelIndex = unit.DASInfo.MapDASChannelNumber2ModuleChannelNumber(result.DASChannelNumber);
|
||||
var channel = unit.ConfigData.Modules[moduleNumber].Channels[channelIndex];
|
||||
if (channel is AnalogInputDASChannel aic)
|
||||
{
|
||||
if (aic.DigitalInputChannel)
|
||||
{
|
||||
InsertDiagnosticsResultDigital(unit, aic, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
InsertDiagnosticsResultAnalog(unit, aic, result);
|
||||
}
|
||||
}
|
||||
else if (channel is OutputSquibChannel squib)
|
||||
{
|
||||
InsertDiagnosticsResultsSquib(unit, squib, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { APILogger.Log(ex); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// writes a single digital result to the db
|
||||
/// </summary>
|
||||
/// <param name="das"></param>
|
||||
/// <param name="aic"></param>
|
||||
/// <param name="result"></param>
|
||||
private static void InsertDiagnosticsResultDigital(IDASCommunication das, AnalogInputDASChannel aic,
|
||||
IDiagnosticResult result)
|
||||
{
|
||||
try
|
||||
{
|
||||
DASFactoryDb.Diagnostics.Diagnostics.InsertDigitalDiagnosticResult(das.RecordId,
|
||||
result.DASChannelNumber,
|
||||
result.EventNumber,
|
||||
result.DigitalInputActiveState);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
APILogger.Log(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// writes a single analog result to the db
|
||||
/// </summary>
|
||||
/// <param name="das"></param>
|
||||
/// <param name="aic"></param>
|
||||
/// <param name="result"></param>
|
||||
private static void InsertDiagnosticsResultAnalog(IDASCommunication das, AnalogInputDASChannel aic,
|
||||
IDiagnosticResult result)
|
||||
{
|
||||
try
|
||||
{
|
||||
DASFactoryDb.Diagnostics.Diagnostics.InsertAnalogDiagnosticResult(
|
||||
das.RecordId,
|
||||
result.DASChannelNumber,
|
||||
result.EventNumber,
|
||||
result.ScalefactorMilliVoltsPerADC,
|
||||
result.ExpectedExcitationMilliVolts,
|
||||
result.MeasuredExcitationMilliVolts,
|
||||
result.NegativeExcitation,
|
||||
result.MeasuredOffsetMilliVolts,
|
||||
result.MeasuredInternalOffsetMilliVolts,
|
||||
result.AutoZeroPercentDeviation,
|
||||
result.FinalOffsetADC,
|
||||
result.RemovedOffsetADC,
|
||||
result.RemovedInternalOffsetADC,
|
||||
result.NoisePercentFullScale,
|
||||
result.ShuntDeflectionFailed,
|
||||
result.CalSignalCheckFailed,
|
||||
result.MeasuredShuntDeflectionMv,
|
||||
result.MeasuredCalSignalMv,
|
||||
result.TargetCalSignalMv,
|
||||
result.TargetGain,
|
||||
result.MeasuredGain,
|
||||
result.QueriedGain,
|
||||
result.TargetShuntDeflectionMv,
|
||||
result.BridgeResistance,
|
||||
result.ZeroMVInADC,
|
||||
result.WindowAverageADC);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
APILogger.Log(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// writes a single squib diagnostic to the db
|
||||
/// </summary>
|
||||
/// <param name="das"></param>
|
||||
/// <param name="squib"></param>
|
||||
/// <param name="result"></param>
|
||||
private static void InsertDiagnosticsResultsSquib(IDASCommunication das, OutputSquibChannel squib,
|
||||
IDiagnosticResult result)
|
||||
{
|
||||
try
|
||||
{
|
||||
DASFactoryDb.Diagnostics.Diagnostics.InsertSquibDiagnosticResult(das.RecordId,
|
||||
result.DASChannelNumber, result.EventNumber, result.SquibFireCurrentData,
|
||||
result.SquibFireVoltageData, result.SquibFireTimeAxis, result.MeasuredDurationMS,
|
||||
result.MeasuredDelayMS, result.SquibFirePassed, result.SquibDurationPassed, result.SquibDelayPassed,
|
||||
result.SquibThreshold, result.SquibVoltageScaler, result.SquibCurrentScaler);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//for now just skip the logging
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user