using DASFactoryDb.Diagnostics; using DTS.Common.Interface.DASFactory; using DTS.Common.Interface.DASFactory.Diagnostics; using DTS.Common.Utilities.Logging; using System; using System.Data.SqlClient; using System.Linq; namespace DTS.DASLib.Service { /// /// This class holds instructions about how a single channel /// is to be diagnosed. The results from these tests will populate the /// DiagnosticsResults[] object in the IDASCommunication object. The results /// can then be compared against the hardware specifications for a sensor to /// determine if the channel is set up correctly before arming and recording. /// public class DiagnosticsActions : IDiagnosticActions { /// /// Which DAS Channel (CH# WRT entire DAS unit) are these diagnostic test /// instructions for? /// public int DASChannelNumber { get; set; } /// /// Should we measure the excitation volatge being applied to this sensor? /// public bool MeasureExcitation { get; set; } /// /// Should we measure the sensor's offset from 0? (If measured, the returned offset can /// be checked against the high and low offset limits that are properties of the /// AnalogInputDasChannel object corresponding to this sensor.) /// public bool MeasureOffset { get; set; } /// /// should we check the open/closed/low/high nature of a digital input channel? /// public bool CheckDigitalState { get; set; } public bool MeasureInternalOffset { get; set; } /// /// Should the firmware compensate for the offset from 0 of this sensor? /// public bool RemoveOffset { get; set; } /// /// Should we measure the noise floor as a percentage of full scale readings? /// public bool MeasureNoise { get; set; } /// /// Should an emulated shunt-check be performed on this sensor. /// public bool PerformShuntCheck { get; set; } /// /// should run a squib fire check on channel /// public bool SquibFireCheck { get; set; } = false; /// /// perform a voltage insertion gain check (SLICE Pro) /// public bool PerformVoltageInsertCheck { get; set; } /// /// Should a Calibration signal-check be performed on this sensor. /// public bool PerformCalSignalCheck { get; set; } /// /// Should the resistance of the bridge be measured? /// public bool MeasureBridgeResistance { get; set; } public DiagnosticsActions() { DASChannelNumber = 0; MeasureExcitation = false; MeasureOffset = false; RemoveOffset = false; MeasureNoise = false; PerformShuntCheck = false; PerformCalSignalCheck = false; PerformVoltageInsertCheck = false; MeasureInternalOffset = false; CheckDigitalState = false; } public bool AllActionsDisabled() { return !MeasureExcitation && !MeasureOffset && !RemoveOffset && !MeasureNoise && !PerformShuntCheck && !MeasureBridgeResistance && !PerformCalSignalCheck && !PerformVoltageInsertCheck && !MeasureInternalOffset && !SquibFireCheck && !CheckDigitalState; } public static void SetChannelDiagnosticActions(IDASCommunication unit, IDiagnosticActions[] actions, bool setInDb) { unit.ChannelDiagnostics = actions; if (!DASFactoryDb.DbWrapper.Connected || !setInDb) { return; } try { Diagnostics.ClearDiagnosticActionsAllChannels(unit.RecordId); } catch (Exception ex) { APILogger.Log(ex); } if (null != actions) { foreach (var action in actions) { InsertAction(unit.RecordId, action); } } } private static void InsertAction(int dasRecordId, IDiagnosticActions action) { try { Diagnostics.InsertDiagnosticAction(dasRecordId, action.DASChannelNumber, action.MeasureExcitation, action.MeasureOffset, action.CheckDigitalState, action.MeasureInternalOffset, action.RemoveOffset, action.MeasureNoise, action.PerformShuntCheck, action.SquibFireCheck, action.PerformVoltageInsertCheck, action.PerformCalSignalCheck, action.MeasureBridgeResistance); } catch (Exception ex) { APILogger.Log(ex); } } } }