Files
DP44/DataPRO/IService/.svn/pristine/ae/aeac0bfe1a5e6cd20f7b651b10a59125b9ba66d6.svn-base
2026-04-17 14:55:32 -04:00

2203 lines
111 KiB
Plaintext

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using DTS.Common.DASResource;
using DTS.Common.Enums;
using DTS.Common.ICommunication;
using DTS.Common.Utilities.Logging;
using DTS.Common.Enums.Sensors;
using DTS.Common.Interface.Connection;
using DTS.Common.Enums.DASFactory;
using DTS.Common.Interface.DASFactory.Config;
using DTS.Common.Interface.DASFactory;
using DTS.Common.Interface.StatusAndProgressBar;
using System.IO.Ports;
using DTS.Common.Classes.DSP;
using DTS.Common.SerialConnection;
using DTS.Common;
using DTS.DASLib.Command.TDAS;
namespace DTS.DASLib.Service
{
public partial class TDAS<T> : Communication<T>,
IDASCommunication,
IConfigurationActions,
IDiagnosticsActions,
ITriggerCheckActions,
IRealTimeActions,
IArmActions,
IDownloadActions where T : IConnection, new()
{
/// <summary>
/// indicates date of first use
/// null indicates the hardware has not been used since calibration
/// only valid when IsFirstUseDateSupported is true
/// 15524 DAS "First Use Date"
/// </summary>
public DateTime? FirstUseDate { get; set; } = null;
/// <summary>
/// returns whether the hardware supports first use or not
/// for hardware to support first use the hardware must support
/// storage for user attributes in firmware and also have been
/// calibrated by software support hardware first use
/// 15524 DAS "First Use Date"
/// </summary>
public bool IsFirstUseDateSupported { get; set; } = false;
/// <summary>
/// indicates whether or not streaming is supported
/// 30429 TSR AIRs can enable/disable streaming via the DISABLE_STREAMING_FEATURE system attribute
/// </summary>
public bool IsStreamingSupported { get; set; } = false;
public int RecordId { get; set; } = Common.Enums.Hardware.HardwareConstants.INVALID_IDASCOMMUNICATION_RECORD_ID;
public string MACAddress { get; set; }
public string[] DownstreamMACAddresses { get; set; }
/// <summary>
/// right now these are coded in the tdas control .ini file. we may want to leave these variable, but for now lets
/// not surface them
/// this code comes from tdas_setup.c in tdascontrol
/// </summary>
public double[] G5GainOptions = new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 16.0, 18.0, 20.0, 22.0, 24.0, 26.0, 28.0, 30.0, 32.0, 36.0, 40.0, 44.0, 48.0, 52.0, 56.0, 60.0, 128.0, 192.0, 256.0, 320.0, 384.0, 448.0, 512.0, 576.0, 640.0, 704.0, 768.0, 832.0, 896.0, 960.0, 1024.0, 2048.0, 4096.0 };
public double[] ProGainOptions = new double[] { 0.8, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 16.0, 18.0, 20.0, 22.0, 24.0, 26.0, 28.0, 30.0, 32.0, 36.0, 40.0, 44.0, 48.0, 52.0, 56.0, 60.0, 64.0, 72.0, 80.0, 88.0, 96.0, 104.0, 112.0, 120.0, 128.0, 144.0, 160.0, 176.0, 192.0, 208.0, 224.0, 240.0, 256.0, 288.0, 320.0, 352.0, 384.0, 426.0, 468.0, 512.0, 598.0, 682.0, 768.0, 854.0, 938.0, 1024.0, 1194.0, 1364.0, 1536.0, 1892.0, 2000.0 };
private const ushort TDAS_HALFBRIDGE_RESISTANCE = 1000;
/// <summary>
/// this is mostly stolen from tdas_setup.c for the purpose of calculating the max gain given
/// a max input range, a desired range, voltage, and overhead percentage
/// </summary>
/// <param name="G5"></param>
/// <param name="maxInputRange"></param>
/// <param name="bProportialToExcitation"></param>
/// <param name="sensitivity"></param>
/// <param name="desiredRange"></param>
/// <param name="excitationVoltage"></param>
/// <returns></returns>
private double CalculateMaxRangeAndGain(bool G5, double maxInputRange, bool bProportialToExcitation,
double sensitivity, double desiredRange, double? excitationVoltage, bool bAtCapacity, double capacityOutputIsBasedOn,
SensorConstants.SensUnits sensitiviyUnits)
{
double[] array = G5 ? G5GainOptions : ProGainOptions;
for (int i = array.Length - 1; i >= 0; i--)
{
double actualRange;
if (bProportialToExcitation && sensitiviyUnits != DTS.Common.Enums.Sensors.SensorConstants.SensUnits.mVperEU)
{
if (bAtCapacity)
{
actualRange = maxInputRange / (array[i] * System.Math.Abs(sensitivity) * (double)excitationVoltage / (double)capacityOutputIsBasedOn);
}
else
{
actualRange = maxInputRange / (array[i] * System.Math.Abs(sensitivity) * (double)excitationVoltage);
}
}
else
{
if (bAtCapacity)
{
actualRange = maxInputRange / (array[i] * System.Math.Abs(sensitivity) / (double)capacityOutputIsBasedOn);
}
else
{
actualRange = maxInputRange / (array[i] * System.Math.Abs(sensitivity));
}
}
if (actualRange > desiredRange)
{//passes
return array[i];
}
}
return array[0];
}
bool IConfiguration.SupportsAutoDetect => false;
void IConfigurationActions.AutoDetect(bool QueryConfiguration, ServiceCallback callback, object userData)
{
var info = new TDASServiceAsyncInfo(callback, userData);
LaunchAsyncWorker("TDAS.AutoDetect", AutoDetect, info);
}
void IConfigurationActions.SetFirstUseDate(DateTime firstUseDate, ServiceCallback callback, object userData)
{
var info = new TDASServiceAsyncInfo(callback, userData);
info.Error("Not supported");
}
private void AutoDetect(object o)
{
if (!(o is TDASServiceAsyncInfo info)) { return; }
info.Success();
}
void IConfigurationActions.CheckAAFilterRate(ServiceCallback callback, object userData)
{
var info = new TDASServiceAsyncInfo(callback, userData);
// look thru all the config data and make sure it's fit to be used
// our caller have already checked for null, but...
if (ConfigData == null)
{
// "TDAS.VerifyConfig: ConfigData is null"
throw new ArgumentException(Strings.Slice_VerifyConfig_Err1);
}
if (ConfigData.Modules == null || ConfigData.Modules.Length == 0 || ConfigData.Modules.Length > DASInfo.Modules.Length)
{
// "Slice.VerifyConfig: ConfigData.Modules is null, empty or too long"
throw new ArgumentException(Strings.Slice_VerifyConfig_Err4);
}
var AAFilterRateReducedToMax = false;
for (var moduleIdx = 0; moduleIdx < ConfigData.Modules.Length; moduleIdx++)
{
var module = ConfigData.Modules[moduleIdx];
if (module.IsClock()) continue;
if (module.ModuleArrayIndex != moduleIdx)
{
// "Slice.VerifyConfig: ConfigData.Module[{0}].ModuleNumber doesn't mach index"
throw new ArgumentException(string.Format(Strings.Slice_VerifyConfig_Err5, moduleIdx));
}
if (module.AAFilterRateHz > MaxAAFilterRateHz)
{
module.AAFilterRateHz = MaxAAFilterRateHz;
AAFilterRateReducedToMax = true;
}
}
if (AAFilterRateReducedToMax)
{
info.Error(SerialNumber);
}
else
{
info.Success();
}
}
void IConfigurationActions.VerifyConfig(bool DoStrictCheck)
{
VerifyConfig(DoStrictCheck, null);
}
void IConfigurationActions.ResetHardwareLines(ServiceCallback callback, object userData)
{
var info = new TDASServiceAsyncInfo(callback, userData);
LaunchAsyncWorker("TDAS.ResetHardwareLines", AsyncResetHardwareLines, info);
}
private void AsyncResetHardwareLines(object asyncInfo)
{
if (!(asyncInfo is TDASServiceAsyncInfo info))
{
return;
}
if (!IsCommandSupported(DFConstantsAndEnums.ProtocolLimitedCommands.InitHardwareInputLines))
{
info.Success();
return;
}
try
{
var armOff = new Command.TDAS.ARMOFF(this);
armOff.SyncExecute();
}
catch (Exception ex)
{
APILogger.Log(ex);
}
info.Success();
}
void IConfigurationActions.VerifyConfig(bool DoStrictCheck, ErrorCallback failedChallengeFunc)
{
VerifyConfig(DoStrictCheck, failedChallengeFunc);
}
void VerifyConfig(bool DoStrictCheck, ErrorCallback failedChallengeFunc)
{
// look thru all the config data and make sure it's fit to be used
// our caller have already checked for null, but...
if (ConfigData == null)
{
// "Slice.VerifyConfig: ConfigData is null"
throw new ArgumentException(Strings.Slice_VerifyConfig_Err1);
}
if (string.IsNullOrEmpty(ConfigData.Description))
{
// "Slice.VerifyConfig: ConfigData.Description is null"
//throw new ArgumentException(Strings.Slice_VerifyConfig_Err2);
ConfigData.Description = "";
}
if (string.IsNullOrEmpty(ConfigData.TestID))
{
// "Slice.VerifyConfig: ConfigData.TestID is null"
//throw new ArgumentException(Strings.Slice_VerifyConfig_Err3);
APILogger.Log("ConfigData.TestID null, replacing with default");
ConfigData.TestID = "Default Test ID";
}
// we don't care about EID's here
if (ConfigData.Modules == null || ConfigData.Modules.Length == 0 || ConfigData.Modules.Length > DASInfo.Modules.Length)
{
// "Slice.VerifyConfig: ConfigData.Modules is null, empty or too long"
throw new ArgumentException(Strings.Slice_VerifyConfig_Err4);
}
// SLICE have only DAS storage
if (DASInfo.MaxEventStorageSpaceInBytes != null)
{
if (DASInfo.NumberOfBytesPerSampleClock == null)
{
throw new ArgumentException("TDAS.VerifyConfig: DAS is missing NumberOfBytesPerSampleClock");
}
// if data is stored on DAS all modules must have same samplerate and pre/post
if (ConfigData.Modules.Select(module => module.SampleRateHz).Distinct().Count() != 1)
{
for (int i = 1; i < ConfigData.Modules.Length; i++)
{
ConfigData.Modules[i].SampleRateHz = ConfigData.Modules[0].SampleRateHz;
}
//throw new ArgumentException("Slice.VerifyConfig: DAS modules have more than one unique samplerate");
}
if (ConfigData.Modules.Select(module => module.PreTriggerSeconds).Distinct().Count() != 1)
{
for (int i = 1; i < ConfigData.Modules.Length; i++)
{
ConfigData.Modules[i].PreTriggerSeconds = ConfigData.Modules[0].PreTriggerSeconds;
}
}
if (ConfigData.Modules.Select(module => module.PostTriggerSeconds).Distinct().Count() != 1)
{
for (int i = 1; i < ConfigData.Modules.Length; i++)
{
ConfigData.Modules[i].PostTriggerSeconds = ConfigData.Modules[0].PostTriggerSeconds;
}
}
var secondsToRecord = ConfigData.Modules[0].PreTriggerSeconds + ConfigData.Modules[0].PostTriggerSeconds;
var sampleClocksToRecord = (UInt64)(secondsToRecord * ConfigData.Modules[0].SampleRateHz + 1);
var bytesToRecord = sampleClocksToRecord * (UInt64)DASInfo.NumberOfBytesPerSampleClock;
if (bytesToRecord > (UInt64)DASInfo.MaxEventStorageSpaceInBytes)
{
throw new ArgumentException(
string.Format("TDAS.VerifyConfig: {0} has {1} bytes available and needs {2} to record requested {3} samples",
SerialNumber, (UInt64)DASInfo.MaxEventStorageSpaceInBytes, bytesToRecord, sampleClocksToRecord));
}
}
else
{
var sufficientMemory = SufficientStorageSpace();
if (false == sufficientMemory)
{
APILogger.Log($"SufficientStorageSpace() returns {sufficientMemory}");
throw new ArgumentException(
string.Format("TDAS.VerifyConfig: {0} has insufficient storage space to record.", SerialNumber));
}
}
bool bModuleAAFChallenge = false;
for (int moduleIdx = 0; moduleIdx < ConfigData.Modules.Length; moduleIdx++)
{
var module = ConfigData.Modules[moduleIdx];
/*
* a TDAS rack could have missing modules, so the module index and moduleindex might not match
* the modulearrayindex
* if (module.ModuleArrayIndex != moduleIdx)
{
throw new ArgumentException(string.Format(Strings.Slice_VerifyConfig_Err5, moduleIdx));
}*/
// we don't care about EID's here
if (module.AAFilterRateHz > MaxAAFilterRateHz)
{
APILogger.Log("configured AAF is out of range: " + module.SerialNumber() + " [" + module.AAFilterRateHz.ToString() + ">" + MaxAAFilterRateHz.ToString() + "]");
module.AAFilterRateHz = MaxAAFilterRateHz;
bModuleAAFChallenge = true;
}
if (module.RecordingMode != DFConstantsAndEnums.RecordingMode.CircularBuffer &&
module.RecordingMode != DFConstantsAndEnums.RecordingMode.RecorderMode &&
module.RecordingMode != DFConstantsAndEnums.RecordingMode.CircularBufferPlusUART &&
module.RecordingMode != DFConstantsAndEnums.RecordingMode.RecorderModePlusUART &&
module.RecordingMode != DFConstantsAndEnums.RecordingMode.AutoCircularBufferMode &&
module.RecordingMode != DFConstantsAndEnums.RecordingMode.AutoRecorderMode
)
{
throw new ArgumentException(string.Format(Strings.Slice_VerifyConfig_Err7, moduleIdx));
}
if (module.SampleRateHz > MaxSampleRateHz && module.SampleRateHz != uint.MaxValue)
{
throw new ArgumentException(string.Format(Strings.Slice_VerifyConfig_Err8, moduleIdx, MaxSampleRateHz));
}
// module.MaxRecordingSamples is null for SLICE
if (module.Channels == null || ((module.Channels.Length == 0) && (DASInfo.Modules[moduleIdx].TypeOfModule != DFConstantsAndEnums.ModuleType.EMPTYBANK)) || module.Channels.Length > DASInfo.Modules[moduleIdx].NumberOfChannels)
{
throw new ArgumentException(string.Format(Strings.Slice_VerifyConfig_Err10, moduleIdx));
}
for (int channelIdx = 0; channelIdx < module.Channels.Length; channelIdx++)
{
var channel = (DASChannel)module.Channels[channelIdx];
// hack to allow dummy load testing during calibration
if (channel.DiagnosticsMode && !string.Equals(ConfigData.Description, "calstation2", StringComparison.OrdinalIgnoreCase)) { throw new ArgumentException("No Diagnostics mode support in TDAS"); }
if (channel.ConfigurationMode == DFConstantsAndEnums.ConfigMode.Disabled)
continue;
if (channel.OwningModule != module)
{
throw new ArgumentException(string.Format(Strings.Slice_VerifyConfig_Err11, moduleIdx, channelIdx));
}
if (channel.ModuleChannelNumber != channelIdx)
{
// "Slice.VerifyConfig: ConfigData.Module[{0}].Channels[{1}].ChannelNumber doesn't mach index"
throw new ArgumentException(string.Format(Strings.Slice_VerifyConfig_Err12, moduleIdx, channelIdx));
}
if (channel.ConfigurationMode != DFConstantsAndEnums.ConfigMode.Normal &&
channel.ConfigurationMode != DFConstantsAndEnums.ConfigMode.DummyArm &&
channel.ConfigurationMode != DFConstantsAndEnums.ConfigMode.Disabled)
{
channel.ConfigurationMode = DFConstantsAndEnums.ConfigMode.Disabled;
//throw new ArgumentException(string.Format(Strings.Slice_VerifyConfig_Err13, moduleIdx, channelIdx));
}
var analog = channel as AnalogInputDASChannel;
OutputTOMDigitalChannel digital = channel as OutputTOMDigitalChannel;
OutputSquibChannel squib = channel as OutputSquibChannel;
if (null != analog)
{
if (analog.TypeOfBridge == SensorConstants.BridgeType.DigitalInput) { }
else
{
if (analog.TypeOfBridge != SensorConstants.BridgeType.FullBridge &&
analog.TypeOfBridge != SensorConstants.BridgeType.HalfBridge &&
analog.TypeOfBridge != SensorConstants.BridgeType.HalfBridge_SigPlus)
{
throw new ArgumentException(string.Format(Strings.Slice_VerifyConfig_Err15, moduleIdx, channelIdx));
}
if (analog.ShuntIsEnabled)
{
if (analog.BridgeResistanceOhms < SensorConstants.MIN_BRIDGE_RESISTANCE_OHMS) { analog.BridgeResistanceOhms = SensorConstants.MIN_BRIDGE_RESISTANCE_OHMS; }
if (analog.BridgeResistanceOhms > SensorConstants.MAX_BRIDGE_RESISTANCE_OHMS) { analog.BridgeResistanceOhms = SensorConstants.MAX_BRIDGE_RESISTANCE_OHMS; }
}
//if (analog.BypassAAFilter)
//{
// throw new ArgumentException(string.Format(Strings.Slice_VerifyConfig_Err17, moduleIdx, channelIdx));
//}
if (analog.DesiredRangeWithHeadroomEU < 0)
{
throw new ArgumentException(string.Format(Strings.Slice_VerifyConfig_Err18, moduleIdx, channelIdx));
}
if (DoStrictCheck && string.IsNullOrEmpty(analog.EngineeringUnits))
{
throw new ArgumentException(string.Format(Strings.Slice_VerifyConfig_Err19, moduleIdx, channelIdx));
}
//if (analog.Excitation != DTS.Common.DAS.Concepts.Test.Module.Channel.Sensor.ExcitationVoltageOption.Volt5)
//{
// throw new ArgumentException(string.Format(Strings.Slice_VerifyConfig_Err20, moduleIdx, channelIdx));
//}
if (analog.ZeroMethod != ZeroMethodType.AverageOverTime &&
analog.ZeroMethod != ZeroMethodType.UsePreEventDiagnosticsZero &&
analog.ZeroMethod != ZeroMethodType.None)
{
throw new ArgumentException(string.Format(Strings.Slice_VerifyConfig_Err22, moduleIdx, channelIdx));
}
if (DoStrictCheck && analog.ZeroMethod == ZeroMethodType.AverageOverTime)
{
if (analog.ZeroAverageStartSeconds >= analog.ZeroAverageStopSeconds)
{
throw new ArgumentException(string.Format(Strings.Slice_VerifyConfig_Err23, moduleIdx, channelIdx));
}
if (analog.ZeroAverageStopSeconds > module.PostTriggerSeconds)
{
throw new ArgumentException(string.Format(Strings.Slice_VerifyConfig_Err25, moduleIdx, channelIdx));
}
}
}
}
else if (null != digital)
{
}
else if (null != squib)
{
}
}
}
if (bModuleAAFChallenge)
{
DialogResult dr;
string err = string.Format("Default hardware filter frequency for {0} is out of range. Press OK to continue and use the max hardware rate or cancel to cancel.", SerialNumber);
if (null != failedChallengeFunc)
{
dr = failedChallengeFunc(ConfigurationConstants.VerifyConfig_Errors.DefaultHardwareFilterRateOutOfRange.ToString(), SerialNumber);
}
else
{
dr = DialogResult.Cancel;
}
APILogger.Log("MessageBox", err, dr);
if (dr == DialogResult.Cancel) { throw new ArgumentOutOfRangeException(DASModule.AAFilterRateHzTag); }
}
}
bool SufficientStorageSpace()
{
bool result = false;
double rackSecondsAvailableToRecord = ulong.MaxValue;
var secondsToRecord = ConfigData.Modules[0].PreTriggerSeconds + ConfigData.Modules[0].PostTriggerSeconds;
APILogger.Log($"SufficientStorageSpace() - Seconds Pre:{ConfigData.Modules[0].PreTriggerSeconds} Seconds Post: {ConfigData.Modules[0].PostTriggerSeconds}");
foreach (InfoResult.Module module in DASInfo.Modules)
{
if (module.SerialNumber != "EMPTY")
{
uint bytesPerClock = 16;
var configModule = ConfigData.Modules.Where(x => string.Equals(x.SerialNumber(), module.SerialNumber)).FirstOrDefault();
if (configModule.NumberOfConfiguredChannels() == 0) { continue; }
switch (module.TypeOfModule)
{
case DFConstantsAndEnums.ModuleType.ProSIM:
// 2 bytes per configured analog channel
bytesPerClock = (uint)(configModule.NumberOfConfiguredChannels() * 2);
break;
case DFConstantsAndEnums.ModuleType.ProTOM:
if (configModule.NumberOfConfiguredTOMChannels() == 0) { continue; } //FB16066: we've only configured digital outs, no data will be collected
// 2 bytes per each configured channel; each squib configured will give you two channels; 4 bytes total per squib
bytesPerClock = (uint)(configModule.NumberOfConfiguredTOMChannels() * 2);
break;
default:
// Assumed to not be allocated dynamically; ie. DIM device
bytesPerClock = (uint)module.NumberOfBytesPerSampleClock;
break;
}
double moduleSecondsAvailableToRecord = (double)(module.MaxEventStorageSpaceInBytes / bytesPerClock) / ConfigData.Modules[0].SampleRateHz + 1;
APILogger.Log($"SufficientStorageSpace() - {module.SerialNumber} - module.MaxEventStorageSpaceInBytes:{module.MaxEventStorageSpaceInBytes}, bytesPerClock:{bytesPerClock}, ConfigData.Modules[0].SampleRateHz{ConfigData.Modules[0].SampleRateHz}");
rackSecondsAvailableToRecord = Math.Min(rackSecondsAvailableToRecord, moduleSecondsAvailableToRecord);
}
}
if (secondsToRecord <= rackSecondsAvailableToRecord)
{
result = true;
}
APILogger.Log($"SufficientStorageSpace() - seconds to record:{secondsToRecord}, max event seconds available:{rackSecondsAvailableToRecord}");
return result;
}
//note, the file I had originally copied code from (QA_TDAS_CAL.c v1.66??) had 3500 .... but everything seems to indicate it should be 4300 ...
protected uint MaxAAFilterRateHz = DTS.Common.Constant.DASSpecific.TDAS.MaxAAFilterRateHz;
const uint MaxSampleRateHz = 304000;
public const int MaxG5InputRange = 2500;
public const int MaxPROInputRange = 5000;//6250, but only at gain .8
private Dictionary<DFConstantsAndEnums.ProtocolLimitedCommands, byte> TDAS_MinimumProtocols = new Dictionary<DFConstantsAndEnums.ProtocolLimitedCommands, byte>();
public override void InitMinProto()
{
// Ribeye Protocol Limitations
MinimumProtocols = TDAS_MinimumProtocols;
}
void IConfigurationActions.UpdateConfigurationFromFile(ServiceCallback callback, object userData,
string filePath)
{
var info = new TDASServiceAsyncInfo(callback, userData);
LaunchAsyncWorker("TDAS.UpdateConfigurationFromFile", new WaitCallback(AsyncUpdateConfigurationFromFile),
info);
}
private void AsyncUpdateConfigurationFromFile(object asyncInfo)
{
var info = asyncInfo as TDASServiceAsyncInfo;
info.Error("Not supported yet");
return;
}
/// <summary>
/// Retrieve the info to fill in the ConfigData property
/// </summary>
/// <param name="callback">The delegate to report to</param>
/// <param name="userData">User supplied data that we pass along</param>
void IConfigurationActions.QueryConfiguration(ServiceCallback callback, object userData, uint crc, string strConfig, bool bReadIds, bool bDeviceScaleFactors,
bool differentModuleCountsAreOK)
{
var info = new TDASServiceQueryConfigAsyncInfo(bReadIds, callback, userData);
LaunchAsyncWorker("TDAS.QueryConfiguration", new WaitCallback(AsyncQueryConfiguration), info);
}
//FB 29528 Query the DAS modules
private IEnumerable<string> QueryDASModules()
{
try
{
var qm = new Command.TDAS.QueryModules(this);
qm.SyncExecute();
return qm.SerialNumbers;
}
catch
{
return Enumerable.Empty<string>();
}
}
private void AsyncQueryConfiguration(object configAsyncInfo)
{
var info = configAsyncInfo as TDASServiceQueryConfigAsyncInfo;
try
{
//calstation would like it if serial connections wouldn't be marked as no channel/empty string
if (!IsG5() && !(this.Transport is SerialConnection))
{
var updatedModules = QueryDASModules();
//FB 29528 Mark the missing modules as EMPTYBANK and set the channels to 0
foreach (var m in DASInfo.Modules.Where(x => !updatedModules.Contains(x.SerialNumber)))
{
m.SerialNumber = "EMPTY";
m.TypeOfModule = DFConstantsAndEnums.ModuleType.EMPTYBANK;
m.NumberOfChannels = 0;
}
}
ConfigData = new ConfigurationData();
ConfigData.Modules = new DASModule[DASInfo.Modules.Length];
int validModuleIndex = 0;
//Assume that validModuleIndex will be changed, possibly more than once, to the index of a valid module,
//so that ConfigData.Modules[0] will have the correct RecordingMode, PreTriggerSeconds, and PostTriggerSeconds
for (int i = 0; i < DASInfo.Modules.Length; i++)
{
TDASModuleConfig tConfig = new TDASModuleConfig(DASInfo.Modules[i].SerialNumber + ".xml");
if (DASInfo.Modules[i].TypeOfModule == DFConstantsAndEnums.ModuleType.EMPTYBANK)
{
ConfigData.Modules[i] = new DASModule(DASInfo.Modules[i].ModuleArrayIndex, ((InfoResult)DASInfo).OwningDAS);
ConfigData.Modules[i].Channels = new DASChannel[DASInfo.Modules[i].NumberOfChannels];
for (int z = 0; z < ConfigData.Modules[i].Channels.Length; z++)
{
AnalogInputDASChannel aic = new AnalogInputDASChannel((DASModule)ConfigData.Modules[i], DASInfo.MapModuleArrayIndexAndChannelNum2DASChannel(i, z));
if (IsG5())
{
aic.SupportedBridges = new SensorConstants.BridgeType[]
{
SensorConstants.BridgeType.FullBridge,
SensorConstants.BridgeType.HalfBridge,
SensorConstants.BridgeType.HalfBridge_SigPlus,
};
if (G5Mode == G5Modes.VDS)
{
aic.SupportedExcitation = new ExcitationVoltageOptions.ExcitationVoltageOption[] { ExcitationVoltageOptions.ExcitationVoltageOption.Volt2, ExcitationVoltageOptions.ExcitationVoltageOption.Volt5 };
}
else { aic.SupportedExcitation = new ExcitationVoltageOptions.ExcitationVoltageOption[] { ExcitationVoltageOptions.ExcitationVoltageOption.Volt5 }; }
}
else
{
aic.SupportedExcitation = new ExcitationVoltageOptions.ExcitationVoltageOption[] { ExcitationVoltageOptions.ExcitationVoltageOption.Volt5, ExcitationVoltageOptions.ExcitationVoltageOption.Volt10 };
}
aic.ModuleChannelNumber = z;
ConfigData.Modules[i].Channels[z] = tConfig.GetChannel(aic);
}
if (tConfig.TestId.Length > 0) { ConfigData.TestID = tConfig.TestId; }
if (tConfig.TestDescription.Length > 0) { ConfigData.Description = tConfig.TestDescription; }
}
else
{
//TDC is not making this call and since we aren't using the results, lets eliminate it, it could save
//8 seconds on a 8 module rack ...
if (string.Equals(ConfigData.Description, "calstation2", StringComparison.OrdinalIgnoreCase))
{
try
{
if (!IsG5() && DASInfo.Modules[i].TypeOfModule != DFConstantsAndEnums.ModuleType.ProDIM
&& (!IsTom(DASInfo.Modules[i].TypeOfModule)) && (!DASInfo.Modules[i].RackIsUnreadable))
{
Command.TDAS.QueryAAFMax f1 = new DTS.DASLib.Command.TDAS.QueryAAFMax(this);
f1.ModuleIndex = DASInfo.Modules[i].ModuleArrayIndex;
f1.SyncExecute();
}
}
catch (Exception ex)
{
APILogger.Log("Failed to retrieve max filter rate - ", ex);
}
}
ConfigData.Modules[i] = new DASModule(DASInfo.Modules[i].ModuleArrayIndex, ((InfoResult)DASInfo).OwningDAS);
ConfigData.Modules[i].Channels = new DASChannel[DASInfo.Modules[i].NumberOfChannels];
for (int z = 0; z < ConfigData.Modules[i].Channels.Length; z++)
{
if (IsTom((DASModule)ConfigData.Modules[i]))
{
if (z >= 8)
{
OutputTOMDigitalChannel c = new OutputTOMDigitalChannel((DASModule)ConfigData.Modules[i], DASInfo.MapModuleArrayIndexAndChannelNum2DASChannel(i, z));
c.ModuleChannelNumber = z;
ConfigData.Modules[i].Channels[z] = tConfig.GetChannel(c);
}
else
{
OutputSquibChannel c = new OutputSquibChannel((DASModule)ConfigData.Modules[i], DASInfo.MapModuleArrayIndexAndChannelNum2DASChannel(i, z));
if (0 != z % 2) { c.MeasurementType = SquibMeasurementType.CURRENT; }
c.ModuleChannelNumber = z;
ConfigData.Modules[i].Channels[z] = tConfig.GetChannel(c);
}
}
else if (IsG5() && i >= 4)
{
AnalogInputDASChannel aic = new AnalogInputDASChannel((DASModule)ConfigData.Modules[i], DASInfo.MapModuleArrayIndexAndChannelNum2DASChannel(i, z));
aic.ModuleChannelNumber = z;
ConfigData.Modules[i].Channels[z] = tConfig.GetChannel(aic);
aic = ConfigData.Modules[i].Channels[z] as AnalogInputDASChannel;
aic.SupportedBridges = new SensorConstants.BridgeType[] { SensorConstants.BridgeType.DigitalInput };
aic.TypeOfBridge = SensorConstants.BridgeType.DigitalInput;
aic.DigitalInputChannel = true;
//g5 only supports CCNO for digital channels
aic.SupportedDigitalInputModes = new[] { DigitalInputModes.CCNO };
}
else if (DASInfo.Modules[i].TypeOfModule == DFConstantsAndEnums.ModuleType.ProDIM)
{
AnalogInputDASChannel aic = new AnalogInputDASChannel((DASModule)ConfigData.Modules[i],
DASInfo.MapModuleArrayIndexAndChannelNum2DASChannel(i, z));
aic.ModuleChannelNumber = z;
ConfigData.Modules[i].Channels[z] = tConfig.GetChannel(aic);
aic = ConfigData.Modules[i].Channels[z] as AnalogInputDASChannel;
aic.SupportedBridges = new SensorConstants.BridgeType[]
{SensorConstants.BridgeType.DigitalInput};
aic.TypeOfBridge = SensorConstants.BridgeType.DigitalInput;
aic.DigitalInputChannel = true;
aic.SupportedDigitalInputModes = new[]
{
DigitalInputModes.CCNO,
DigitalInputModes.CCNC,
DigitalInputModes.THL,
DigitalInputModes.TLH
};
}
else
{
AnalogInputDASChannel aic = new AnalogInputDASChannel((DASModule)ConfigData.Modules[i],
DASInfo.MapModuleArrayIndexAndChannelNum2DASChannel(i, z));
//per CPB and rihito, assume G5 is in a rack and supports 2 v
//http://fogbugz/fogbugz/default.asp?4150#21991
if (IsG5())
{
aic.SupportedBridges = new SensorConstants.BridgeType[]
{
SensorConstants.BridgeType.FullBridge,
SensorConstants.BridgeType.HalfBridge,
SensorConstants.BridgeType.HalfBridge_SigPlus,
};
if (G5Mode == G5Modes.VDS)
{
aic.SupportedExcitation = new ExcitationVoltageOptions.ExcitationVoltageOption
[]
{
ExcitationVoltageOptions.ExcitationVoltageOption.Volt5,
ExcitationVoltageOptions.ExcitationVoltageOption.Volt2
};
}
else
{
aic.SupportedExcitation = new ExcitationVoltageOptions.ExcitationVoltageOption
[]
{
ExcitationVoltageOptions.ExcitationVoltageOption.Volt5
};
}
}
else
{
aic.SupportedExcitation = new ExcitationVoltageOptions.ExcitationVoltageOption[]
{
ExcitationVoltageOptions.ExcitationVoltageOption.Volt5,
ExcitationVoltageOptions.ExcitationVoltageOption.Volt10
};
}
aic.ModuleChannelNumber = z;
ConfigData.Modules[i].Channels[z] = tConfig.GetChannel(aic);
if (!Matches(aic, (DASChannel)ConfigData.Modules[i].Channels[z]))
{
APILogger.Log($"CONFIGURATION MISMATCH ON CHANNEL {i}-{z}, using default");
ConfigData.Modules[i].Channels[z] = aic;
}
}
}
ConfigData.Modules[i].RecordingMode = tConfig.RecordingMode;
ConfigData.Modules[i].AAFilterRateHz = tConfig.AAFilterRateHz;
ConfigData.Modules[i].PreTriggerSeconds = tConfig.PreTriggerSeconds;
ConfigData.Modules[i].PostTriggerSeconds = tConfig.PostTriggerSeconds;
ConfigData.Modules[i].FirmwareVersion = tConfig.FirmwareVersion;
ConfigData.Modules[i].MaxEventStorageSpaceInBytes = tConfig.MaxEventStorageSpaceInBytes;
validModuleIndex = i;
if (tConfig.TestId.Length > 0) { ConfigData.TestID = tConfig.TestId; }
if (tConfig.TestDescription.Length > 0) { ConfigData.Description = tConfig.TestDescription; }
}
}
// get sensor ID's
if (ConfigData.Modules != null)
{
foreach (var module in ConfigData.Modules)
{
if (DASInfo.Modules[module.ModuleArrayIndex].TypeOfModule == DFConstantsAndEnums.ModuleType.EMPTYBANK)
{
module.RecordingMode = ConfigData.Modules[validModuleIndex].RecordingMode;
module.PreTriggerSeconds = ConfigData.Modules[validModuleIndex].PreTriggerSeconds;
module.PostTriggerSeconds = ConfigData.Modules[validModuleIndex].PostTriggerSeconds;
continue;
}
if (DASInfo.Modules[module.ModuleArrayIndex].TypeOfModule == DFConstantsAndEnums.ModuleType.G5Digital)
{
// Digitals have not IDS, but still need to do this house keeping. Probably should be moved elsewhere.
for (int i = 0; i < module.Channels.Length; i++)
{
var channel = (DASChannel)module.Channels[i];
channel.OwningModule = (DASModule)module;
}
}
else
{
for (int i = 0; i < module.Channels.Length; i++)
{
var channel = (DASChannel)module.Channels[i];
channel.OwningModule = (DASModule)module;
}
if (info.ReadIds && !IsG5()) //g5 will be handled separately at the end all at once
{
EID[] ids = null;
if (!DASInfo.Modules[module.ModuleArrayIndex].RackIsUnreadable)
{
ids = EIDReader.RetriveEIDs(this, module.ModuleArrayIndex);
for (int i = 0; i < module.Channels.Length; i++)
{
if (null != ids && i < ids.Length && ids[i].IsValid())
{
if (IsTom(module))
{
module.Channels[i * 2].IDs = new EID[] { ids[i] };
}
else
{
module.Channels[i].IDs = new EID[] { ids[i] };
}
}
}
}
}
}
}
if (IsG5() && info.ReadIds)
{
GetEIDSG5();
}
}
info.Success();
}
catch (CanceledException) { info.Cancel(); }
catch (System.Exception ex) { info.Error(ex.Message, ex); }
}
/// <summary>
/// Checks that the channel from the written xml configuration matches
/// what we've queried from the hardware.
/// </summary>
/// <param name="queried"></param>
/// <param name="fromConfig"></param>
/// <returns></returns>
private bool Matches(AnalogInputDASChannel queried, DASChannel fromConfig)
{
var aicFromConfig = fromConfig as AnalogInputDASChannel;
if (null == aicFromConfig)
{
return false;
}
var supportedExcitationFromConfig = 0;
foreach (var se in aicFromConfig.SupportedExcitation)
{
supportedExcitationFromConfig |= (int)se;
}
var supportedExcitationQueried = 0;
foreach (var se in queried.SupportedExcitation)
{
supportedExcitationQueried += (int)se;
}
if (supportedExcitationQueried != supportedExcitationFromConfig)
{
return false;
}
return true;
}
/// <summary>
/// Calculate the EU to mV conversion factor for the specified channel.
/// </summary>
///
/// <param name="analog">
/// The <see cref="DTS.DASLib.Service.AnalogInputDASChannel"/> whose property is being converted from
/// EU to mV.
/// </param>
///
/// <returns>
/// The mV equivalent of 1 EU on the specified channel.
/// </returns>
///
private double GetMvPerEu(AnalogInputDASChannel analog)
{
try
{
return Math.Abs(analog.SensitivityMilliVoltsPerEU);/*
* (analog.IsProportionalToExcitation
? DTS.Common.DAS.Concepts.Test.Module.Channel.Sensor.GetExcitationVoltageMagnitudeFromEnum(analog.Excitation)
: 1.0);*/
}
catch (System.Exception ex)
{
throw new ApplicationException("encountered problem getting EU to MV conversion factor for channel " + (null != analog && null != analog.SerialNumber ? analog.SerialNumber : "<NULL>"), ex);
}
}
private double GetMvPerEuNormalized(AnalogInputDASChannel analog)
{
try
{
return Math.Abs(analog.SensitivityMilliVoltsPerEU)
* (analog.IsProportionalToExcitation && analog.SensitivityUnits != DTS.Common.Enums.Sensors.SensorConstants.SensUnits.mVperEU
? DTS.Common.DAS.Concepts.Test.Module.Channel.Sensor.GetExcitationVoltageMagnitudeFromEnum(analog.Excitation)
: 1.0)
/ (double)(analog.AtCapacity ? analog.CapacityOutputIsBasedOn : 1.0);
}
catch (System.Exception ex)
{
throw new ApplicationException("encountered problem getting EU to MV conversion factor for channel " + (null != analog && null != analog.SerialNumber ? analog.SerialNumber : "<NULL>"), ex);
}
}
#region Set configuration
/// <summary>
/// Checks whether the das safety switch is currently in the armed state or not
/// </summary>
/// <param name="bArmed"></param>
/// <param name="callback"></param>
/// <param name="userData"></param>
void IConfigurationActions.CheckSafetyState(bool bArmed, ServiceCallback callback, object userData)
{
var info = new TDASServiceAsyncInfo(callback, userData);
info.functionData = bArmed;
LaunchAsyncWorker("TDAS.CheckSafetyState", new WaitCallback(AsyncCheckSafetyState), info);
}
private class ConfigurePacket : TDASServiceAsyncInfo
{
public ConfigurePacket(ServiceCallback callback, object userData) : base(callback, userData) { }
public bool DummyArm { get; set; }
public Dictionary<IDASCommunication, ushort> TimeChannelIds { get; set; }
public Dictionary<IDASCommunication, ushort> DataChannelIds { get; set; }
public bool ConfigureDigitalOutputs { get; set; }
public bool DiscardDiagnostics { get; set; }
/// <summary>
/// max aaf from config for devices
/// index 0 is PRO, index 1 is G5
/// </summary>
public double[] MaxAAF { get; set; }
}
void IConfigurationActions.Configure(ServiceCallback callback, object userData, bool EventConfig, bool DummyArm, double [] maxAAF, bool configureDigitalOutputs, uint crc, bool turnOffAAFRealtime,
IStreamingFilterProfile dspFilterType, bool discardDiagnostics, Dictionary<IDASCommunication, ushort> timeChannelIds, Dictionary<IDASCommunication, ushort> dataChannelIds,
Dictionary<IDASCommunication, UDPStreamProfile> streamProfiles, Dictionary<IDASCommunication, int> streamADCPerPacket, Dictionary<IDASCommunication, ushort> irigTDPIntervals,
Dictionary<IDASCommunication, string> addresses, Dictionary<IDASCommunication, uint[]> tmnsConfigs,
Dictionary<IDASCommunication, uint> baudRates, Dictionary<IDASCommunication, uint> dataBits, Dictionary<IDASCommunication, StopBits> stopBits,
Dictionary<IDASCommunication, Parity> parities, Dictionary<IDASCommunication, Handshake> flowControls, Dictionary<IDASCommunication, UartDataFormat> dataFormats,
Dictionary<IDASCommunication, ushort> tmatsIntervals
)
{
var info = new ConfigurePacket(callback, userData);
info.ConfigureDigitalOutputs = configureDigitalOutputs || !DummyArm;
info.DummyArm = false;
info.DataChannelIds = dataChannelIds;
info.TimeChannelIds = timeChannelIds;
info.MaxAAF = maxAAF;
info.DiscardDiagnostics = discardDiagnostics;
LaunchAsyncWorker("TDAS.Configure", new WaitCallback(AsyncConfigure), info);
}
void IConfigurationActions.ApplyLevelTriggers(ServiceCallback callback, object userData)
{
var info = new TDASServiceAsyncInfo(callback, userData);
LaunchAsyncWorker("TDAS.ApplyLevelTriggers", AsyncApplyLevelTriggers, info);
}
private void AsyncApplyLevelTriggers(object asyncInfo)
{
var info = (TDASServiceAsyncInfo)asyncInfo;
info.Success();
}
public double[] GetNominalRanges(SensorConstants.BridgeType bridgeType)
{
//get the gains and calculate the max input ranges backwards from the max input range and the gain
int maxInput;
double[] gains;
switch (GetHardwareType())
{
case Common.Enums.Hardware.HardwareTypes.G5INDUMMY:
case Common.Enums.Hardware.HardwareTypes.G5VDS:
maxInput = MaxG5InputRange;
gains = G5GainOptions;
break;
default:
maxInput = MaxPROInputRange;
gains = ProGainOptions;
break;
}
var inputRanges = new List<double>();
foreach (var gain in gains)
{
inputRanges.Add(maxInput / gain);
}
return inputRanges.ToArray();
}
private bool ContainsTOM()
{
foreach (var mod in DASInfo.Modules)
{
if (IsTom(mod.TypeOfModule)) { return true; }
}
return false;
}
private void AsyncCheckSafetyState(object configAsyncInfo)
{
var info = configAsyncInfo as TDASServiceAsyncInfo;
if (null == ConfigData || null == ConfigData.Modules)
{
ManualResetEvent finished = new ManualResetEvent(false);
(this as IConfigurationActions).QueryConfiguration(
delegate (ServiceCallbackData data)
{
switch (data.Status)
{
case ServiceCallbackData.CallbackStatus.Success:
case ServiceCallbackData.CallbackStatus.Failure:
case ServiceCallbackData.CallbackStatus.Canceled:
finished.Set();
break;
default:
break;
}
}, null, 0, string.Empty, false);
while (false == finished.WaitOne(50)) { System.Threading.Thread.Sleep(10); }
}
bool bArmed = (bool)info.functionData;
bool bHaveResistances = false;
bool bNotSafe = false;
foreach (DASModule module in ConfigData.Modules)
{
if (IsTom(module))
{
// Do not put the Arm/Safe switch in the armed position for unused TOMs!
if (bArmed && module.NumberOfConfiguredChannels() < 1) { continue; }
try
{
Command.TDAS.GetTOMSwitch gts = new DTS.DASLib.Command.TDAS.GetTOMSwitch(this);
gts.ModuleIndex = module.ModuleArrayIndex;
gts.SyncExecute();
switch (gts.SwitchMode)
{
case DTS.DASLib.Command.TDAS.GetTOMSwitch.TomSwitchMode.Armed:
if (!bArmed)
{
bNotSafe = true;
try
{
Command.TDAS.TestSquibArray tsa = new Command.TDAS.TestSquibArray(this);
tsa.ModuleIndex = module.ModuleArrayIndex;
tsa.SyncExecute();
foreach (var d in tsa.ResistanceOhms) { if (d >= 1 && d <= 8) { bHaveResistances = true; break; } }
}
catch (System.Exception ex) { APILogger.Log(ex); }
}
break;
case DTS.DASLib.Command.TDAS.GetTOMSwitch.TomSwitchMode.Fail:
info.Error("");
return;
case DTS.DASLib.Command.TDAS.GetTOMSwitch.TomSwitchMode.Safe:
if (bArmed)
{
info.Error("");
return;
}
break;
}
}
catch (System.Exception ex)
{
APILogger.Log("failed to get checksafetystate, ", ex);
info.Error("SAFETYSWITCH_EXCEPTION", ex);
}
}
}
if (bHaveResistances) { info.Error("SQUIB_RESISTANCE"); }
else if (bNotSafe) { info.Error("SAFETYSWITCH_STATE"); }
else { info.Success(); }
}
/// <summary>
/// if we have only digital channels on a g5, we still want to arm normally and not dummy arm, but to do this
/// we need setupdasload to operate properly, which means we need atleast one analog dummy channel
/// this function scans for and fixes this condition if prsent.
/// </summary>
private void G5DigitalOnlyCheck()
{
bool bAddDummyChannel = true;
if (IsG5())
{
foreach (var m in ConfigData.Modules)
{
foreach (var c in m.Channels)
{
if (c is AnalogInputDASChannel)
{
if (c.ConfigurationMode == DFConstantsAndEnums.ConfigMode.Normal
&& !(c as AnalogInputDASChannel).DigitalInputChannel)
{
bAddDummyChannel = false;
break;
}
if (c.ConfigurationMode == DFConstantsAndEnums.ConfigMode.DummyArm) { break; }
}
}
if (!bAddDummyChannel) { break; }
}
if (bAddDummyChannel)
{
bool bHaveSetDummy = false;
foreach (var m in ConfigData.Modules)
{
foreach (var c in m.Channels)
{
if (c is AnalogInputDASChannel)
{
AnalogInputDASChannel aic = c as AnalogInputDASChannel;
aic.ConfigurationMode = DFConstantsAndEnums.ConfigMode.DummyArm;
aic.Description = "DummyArm";
aic.DesiredRangeWithHeadroomEU = 1;
aic.EngineeringUnits = "g";
aic.Excitation = ExcitationVoltageOptions.ExcitationVoltageOption.Volt5;
aic.HardwareChannelName = "DummyArm";
aic.IsProportionalToExcitation = false;
aic.ScalefactorMilliVoltsPerADC = 1;
aic.ScalefactorEngineeringUnitsPerADC = 1;
aic.SensitivityMilliVoltsPerEU = 1;
aic.SensorCapacityEU = 1;
aic.SensorCapacity = 0;
aic.SensorPolarity = "";
aic.SerialNumber = "";
aic.ShuntIsEnabled = false;
aic.TypeOfBridge = SensorConstants.BridgeType.FullBridge;
aic.UpdateChannelFromDatabase = false;
aic.VerifyOffset = false;
aic.RemoveOffset = false;
aic.ZeroMethod = ZeroMethodType.None;
aic.AtCapacity = false;
aic.CapacityOutputIsBasedOn = 1.000;
aic.SensitivityUnits = SensorConstants.SensUnits.NONE;
bHaveSetDummy = true;
break;
}
}
if (bHaveSetDummy)
{
break;
}
}
}
}
}
/// <summary>
/// scan through all modules, make sure all modules have atleast one channel or dummy channel set
/// </summary>
private void RackDummyChannelCheck()
{
if (IsG5()) { return; }
foreach (var m in ConfigData.Modules)
{
bool bGoodToGo = false;
foreach (var channel in m.Channels)
{
if (((channel.ConfigurationMode == DFConstantsAndEnums.ConfigMode.Normal) && (!(channel is DTS.DASLib.Service.OutputTOMDigitalChannel))) ||
(channel.ConfigurationMode == DFConstantsAndEnums.ConfigMode.DummyArm))
{
bGoodToGo = true; break;
}
}
if (!bGoodToGo && (m.Channels.Length > 0))
{
AnalogInputDASChannel aic = m.Channels[0] as AnalogInputDASChannel;
OutputSquibChannel squib = m.Channels[0] as OutputSquibChannel;
if (null != squib)
{
squib.ConfigurationMode = DFConstantsAndEnums.ConfigMode.DummyArm;
squib.SquibToleranceLow = 0;
squib.SquibToleranceHigh = 8;
squib.FireMode = SquibFireMode.NONE;
squib.DurationMS = 0;
}
else if (null != aic)
{
aic.ConfigurationMode = DFConstantsAndEnums.ConfigMode.DummyArm;
aic.DesiredRangeWithHeadroomEU = 1;
aic.SensorCapacityEU = 1;
aic.SensorCapacity = 0;
aic.SerialNumber = "";
aic.ShuntIsEnabled = false;
aic.RemoveOffset = false;
aic.VoltageInsertionCheckEnabled = false;
aic.ChannelName2 = "";
aic.ChannelId = "-1";
aic.ChannelGroupName = "";
aic.VerifyOffset = false;
aic.UpdateChannelFromDatabase = false;
aic.TypeOfBridge = SensorConstants.BridgeType.FullBridge;
}
}
}
}
private void AsyncConfigure(object configAsyncInfo)
{
var info = configAsyncInfo as ConfigurePacket;
try
{
if (IsG5()) { MaxAAFilterRateHz = Convert.ToUInt32(info.MaxAAF[1]); }
else
{
//for sim, we want to cut off at 650 below the max .., so we just do that here
//see notes attached to http://fogbugz/fogbugz/default.asp?5978
uint max = Convert.ToUInt32(info.MaxAAF[0]);
if (max > 650) { max = max - 650; }
MaxAAFilterRateHz = max;
}
}
catch (System.Exception ex) { APILogger.Log(ex); }
float MaxSquibDurationMS = 40; //Kids need limits, so do unlimited-duration squibs
try
{
//we can dummy arm as long as there's no digital channels, if there's a digital channel,
//we have to arm as normal and add a dummy channel so the SDL works
G5DigitalOnlyCheck();
RackDummyChannelCheck();
if (ContainsTOM() && string.Equals(ConfigData.Description, "calstation2", StringComparison.OrdinalIgnoreCase))
{
foreach (var m in DASInfo.Modules)
{
if (m.SerialNumber != "EMPTY" &&
IsTom(m.TypeOfModule)) { TurnOffExcitation(m.ModuleArrayIndex); }
}
foreach (var m in DASInfo.Modules)
{
if (m.TypeOfModule == DFConstantsAndEnums.ModuleType.EMPTYBANK) { continue; }
var qsnb = new Command.TDAS.QuerySerialNumberBroadcast(this, m.ModuleArrayIndex);
qsnb.SyncExecute();
break;
}
}
// loop thru the modules (slices) and configure the channels
long numChannels = DASInfo.Modules.Sum(mod => mod.NumberOfChannels);
int currentChannel = 0;
info.Progress(50);
var tEntireConfig = new TDASConfig(((InfoResult)DASInfo).OwningDAS + ".xml", true);
//avoid doing this on Serial TDAS
if (this is TDAS<EthernetConnection>)
{
try
{
//added this to clear latched rackfaults ...
Command.TDAS.ARMOFF ao = new Command.TDAS.ARMOFF(this);
ao.SyncExecute();
}
catch (System.Exception)
{
//no logging requested
}
}
bool rackCleared = false;
int firstRackModule = 0;
for (int i = 0; i < ConfigData.Modules.Length; i++)
{
var tConfig = new TDASModuleConfig(DASInfo.Modules[i].SerialNumber + ".xml");
//only wipe out the existing setup if we have to ...
if (ConfigData.ClearSetup /*||ContainsTOM()*/)
{
if (IsG5() && i > 0)
{
//only want to clear once with a G5 ...
}
else if (DASInfo.Modules[i].TypeOfModule == DFConstantsAndEnums.ModuleType.EMPTYBANK) { continue; }
else
{
if (IsG5())
{
Command.TDAS.SetupClear sClear = new DTS.DASLib.Command.TDAS.SetupClear(this);
sClear.ModuleIndex = ConfigData.Modules[i].ModuleArrayIndex;
sClear.SyncExecute();
}
else
{
if (string.Equals(ConfigData.Description, "calstation2", StringComparison.OrdinalIgnoreCase))
{
if (this is TDAS<EthernetConnection>)
{
if (!rackCleared)
{
Command.TDAS.SetupClearBroadcast scb = new Command.TDAS.SetupClearBroadcast(this, i, 10 * 1000);
scb.SyncExecute();
Thread.Sleep(1000);
rackCleared = true;
firstRackModule = i;
}
}
else
{
Command.TDAS.SetupClear sClear = new DTS.DASLib.Command.TDAS.SetupClear(this);
sClear.ModuleIndex = ConfigData.Modules[i].ModuleArrayIndex;
sClear.SyncExecute();
}
}
else if (!rackCleared)
{
var qsn = new Command.TDAS.QuerySerialNumberBroadcast(this, i);
qsn.SyncExecute();
var scb = new Command.TDAS.SetupClearBroadcast(this, i, 10 * 1000);
scb.SyncExecute();
rackCleared = true;
}
}
}
}
if (DASInfo.Modules[i].TypeOfModule == DFConstantsAndEnums.ModuleType.EMPTYBANK) { continue; }
else
{
DASModule module = (DASModule)ConfigData.Modules[i];
tConfig.RecordingMode = module.RecordingMode;
tConfig.AAFilterRateHz = module.AAFilterRateHz;
tConfig.PreTriggerSeconds = module.PreTriggerSeconds;
tConfig.PostTriggerSeconds = module.PostTriggerSeconds;
tConfig.SerialNumber = module.SerialNumber();
tConfig.FirmwareVersion = module.FirmwareVersion;
tConfig.MaxEventStorageSpaceInBytes = module.MaxEventStorageSpaceInBytes;
tConfig.ModuleArrayIndex = module.ModuleArrayIndex;
for (int z = 0; z < ConfigData.Modules[i].Channels.Length; z++)
{
AnalogInputDASChannel channel = ConfigData.Modules[i].Channels[z] as AnalogInputDASChannel;
OutputSquibChannel squib = ConfigData.Modules[i].Channels[z] as OutputSquibChannel;
OutputTOMDigitalChannel digital = ConfigData.Modules[i].Channels[z] as OutputTOMDigitalChannel;
if (null != channel)
{
tConfig.SetChannel(channel);
}
else if (null != squib)
{
tConfig.SetChannel(squib);
}
else if (null != digital)
{
tConfig.SetChannel(digital);
}
}
tEntireConfig.SetModule(tConfig);
if (IsTom(module))
{
try
{
if (!ConfigData.ClearSetup /*||ContainsTOM()*/)
{
Command.TDAS.SetupTOMDASRead sdr = new DTS.DASLib.Command.TDAS.SetupTOMDASRead(this);
sdr.ModuleIndex = module.ModuleArrayIndex;
sdr.SyncExecute();
string[] tokens = sdr.TestConfig.Split(new char[] { SETUPDASREAD_SENTINEL });
}
}
catch (System.Exception)
{
//no logging requested
}
}
else
{
try
{
if (!ConfigData.ClearSetup /*||ContainsTOM()*/)
{
if (DASInfo.Modules[module.ModuleArrayIndex].TypeOfModule ==
DFConstantsAndEnums.ModuleType.ProDIM && !IsG5())
{
Command.TDAS.SetupDASReadDIM sdr = new Command.TDAS.SetupDASReadDIM(this);
sdr.ModuleIndex = module.ModuleArrayIndex;
sdr.SyncExecute();
string[] tokens = sdr.TestConfig.Split(new char[] { SETUPDASREAD_SENTINEL });
if (tokens.Last() == module.GetCRC32().ToString())
{
continue;
}
}
else
{
Command.TDAS.SetupDASRead sdr = new DTS.DASLib.Command.TDAS.SetupDASRead(this);
sdr.ModuleIndex = module.ModuleArrayIndex;
sdr.SyncExecute();
string[] tokens = sdr.TestConfig.Split(new char[] { SETUPDASREAD_SENTINEL });
if (tokens.Last() == module.GetCRC32().ToString())
{
continue;
}
}
}
}
catch (System.Exception) { }
}
}
for (int z = 0; z < ConfigData.Modules[i].Channels.Length; z++)
{
AnalogInputDASChannel channel = ConfigData.Modules[i].Channels[z] as AnalogInputDASChannel;
OutputSquibChannel squib = ConfigData.Modules[i].Channels[z] as OutputSquibChannel;
OutputTOMDigitalChannel digital = ConfigData.Modules[i].Channels[z] as OutputTOMDigitalChannel;
if (null != channel)
{
tConfig.SetChannel(channel);
if (channel.DigitalInputChannel)
{
if (DASInfo.Modules[i].TypeOfModule == DFConstantsAndEnums.ModuleType.ProDIM && !IsG5())
{
Command.TDAS.SetupDIMChannel dim = new Command.TDAS.SetupDIMChannel(this);
dim.ModuleIndex = ConfigData.Modules[i].ModuleArrayIndex;
dim.ChannelNumber = z + 1;
switch (channel.DigitalMode)
{
case DigitalInputModes.THL:
dim.InputMode = Command.TDAS.SetupDIMChannel.InputModes.VMHL;
break;
case DigitalInputModes.TLH:
dim.InputMode = Command.TDAS.SetupDIMChannel.InputModes.VMLH;
break;
case DigitalInputModes.CCNC:
dim.InputMode = Command.TDAS.SetupDIMChannel.InputModes.CCNC;
break;
case DigitalInputModes.CCNO:
dim.InputMode = Command.TDAS.SetupDIMChannel.InputModes.CCNO;
break;
}
if (channel.ConfigurationMode != DFConstantsAndEnums.ConfigMode.Disabled &&
(channel.SerialNumber.Length > 0 ||
channel.ConfigurationMode == DFConstantsAndEnums.ConfigMode.DummyArm))
{
dim.SyncExecute();
}
}
continue;
}
var scl = new SetupChannelLoad(this, IsG5());
if(string.Equals(ConfigData.Description, "calstation2", StringComparison.OrdinalIgnoreCase)) // TDAS Bridge Completion (Shunt) test.
{
scl.ShuntPosition = Convert.ToInt32(channel.BridgeResistanceOhms);
}
else
{
switch (channel.TypeOfBridge)
{
case SensorConstants.BridgeType.HalfBridge:
case SensorConstants.BridgeType.HalfBridge_SigPlus:
scl.ShuntPosition = Convert.ToInt32(TDAS_HALFBRIDGE_RESISTANCE);
break;
default:
scl.ShuntPosition = Convert.ToInt32(channel.BridgeResistanceOhms);
break;
}
}
if (DASInfo.Modules[i].TypeOfModule == DFConstantsAndEnums.ModuleType.EMPTYBANK) { continue; }
scl.ModuleIndex = ConfigData.Modules[i].ModuleArrayIndex;
scl.Channel = z + 1;
if (SensorConstants.BridgeType.FullBridge == channel.TypeOfBridge)
{
scl.ChannelType = Command.TDAS.SetupChannelLoad.ChannelTypes.FullBridge;
}
else if (SensorConstants.BridgeType.HalfBridge == channel.TypeOfBridge
|| SensorConstants.BridgeType.HalfBridge_SigPlus == channel.TypeOfBridge)
{
// this property is being re-purposed for TDAS SIM Diagnostics mode for cal station 2. (CLH) 5/25/2017
if (channel.VoltageInsertionCheckEnabled)
{ scl.ChannelType = Command.TDAS.SetupChannelLoad.ChannelTypes.Diagnostic; }
else
{ scl.ChannelType = Command.TDAS.SetupChannelLoad.ChannelTypes.HalfBridge; }
}
else
{
throw new Exception("TDAS only supports full or half bridge sensors. " + channel.TypeOfBridge.ToString() + " was requested for " + channel.Description);
}
scl.EUUnit = channel.EngineeringUnits;
switch (channel.Excitation)
{
case ExcitationVoltageOptions.ExcitationVoltageOption.Undefined:
scl.ExcitationSetting = 0D;
break;
case ExcitationVoltageOptions.ExcitationVoltageOption.Volt2:
scl.ExcitationSetting = 2D;
break;
case ExcitationVoltageOptions.ExcitationVoltageOption.Volt10:
scl.ExcitationSetting = 10D;
break;
case ExcitationVoltageOptions.ExcitationVoltageOption.Volt5:
scl.ExcitationSetting = 5D;
break;
default: throw new Exception("TDAS only supports 2,5,10 excitation values");
}
scl.FilterOption = channel.BypassAAFilter ? DTS.DASLib.Command.TDAS.SetupChannelLoad.FilterOptions.BypassFilter : DASLib.Command.TDAS.SetupChannelLoad.FilterOptions.Filter;
var desiredRange = GetRequestedRange(channel, GetMvPerEu(channel));
if (IsG5())
{
scl.Gain = CalculateMaxRangeAndGain(true,
MaxG5InputRange,
channel.IsProportionalToExcitation,
channel.SensitivityMilliVoltsPerEU,
desiredRange,
scl.ExcitationSetting,
channel.AtCapacity,
channel.CapacityOutputIsBasedOn,
channel.SensitivityUnits);
}
else
{
scl.Gain = CalculateMaxRangeAndGain(false,
MaxPROInputRange,
channel.IsProportionalToExcitation,
channel.SensitivityMilliVoltsPerEU,
desiredRange,
scl.ExcitationSetting,
channel.AtCapacity,
channel.CapacityOutputIsBasedOn,
channel.SensitivityUnits);
}
scl.OffsetOption = channel.RemoveOffset ? DTS.DASLib.Command.TDAS.SetupChannelLoad.OffsetOptions.AutoOffset : DASLib.Command.TDAS.SetupChannelLoad.OffsetOptions.DoNotOffset;
scl.Sensitivity = channel.SensitivityMilliVoltsPerEU;
scl.SensitivityUnit = DTS.DASLib.Command.TDAS.SetupChannelLoad.SensitivityUnits.Volts;
if (channel.ShuntIsEnabled) { scl.ShuntMode = DTS.DASLib.Command.TDAS.SetupChannelLoad.ShuntModes.EmulateShunt; }
else { scl.ShuntMode = DTS.DASLib.Command.TDAS.SetupChannelLoad.ShuntModes.None; }
if (channel.ShuntIsEnabled && string.Equals(ConfigData.Description, "calstation2", StringComparison.OrdinalIgnoreCase))
{
if (scl.ShuntPosition > 0 && scl.ShuntPosition < 9) // internal shunt positions are 1 thru 7, and external shunt is position 8.
{
scl.ShuntMode = DTS.DASLib.Command.TDAS.SetupChannelLoad.ShuntModes.ShuntResistance;
}
else { scl.ShuntMode = DTS.DASLib.Command.TDAS.SetupChannelLoad.ShuntModes.EmulateShunt; }
}
if (channel.ConfigurationMode != DFConstantsAndEnums.ConfigMode.Disabled && (channel.SerialNumber.Length > 0 || channel.ConfigurationMode == DFConstantsAndEnums.ConfigMode.DummyArm))
{
//only send to the unit if there is a sensor on the channel...
try
{
if (!IsG5() && this is TDAS<EthernetConnection> && string.Equals(ConfigData.Description, "calstation2", StringComparison.OrdinalIgnoreCase))
{
if (firstRackModule == i) // Send same config to all SIM's in Rack!
{
var sclb = new DTS.DASLib.Command.TDAS.SetupChannelLoadBroadcast(this, i, false);
sclb.Channel = scl.Channel;
sclb.ChannelNumber = scl.ChannelNumber;
sclb.ChannelType = scl.ChannelType;
sclb.EUUnit = scl.EUUnit;
sclb.ExcitationSetting = scl.ExcitationSetting;
sclb.FilterOption = scl.FilterOption;
sclb.Gain = scl.Gain;
sclb.Location = scl.Location;
sclb.OffsetOption = scl.OffsetOption;
sclb.Sensitivity = scl.Sensitivity;
sclb.SensitivityUnit = scl.SensitivityUnit;
sclb.ShuntEUValue = scl.ShuntEUValue;
sclb.ShuntMode = scl.ShuntMode;
sclb.ShuntPosition = scl.ShuntPosition;
sclb.SyncExecute();
channel.ShuntTargetADC = sclb.TargetADC;
}
}
//SCL will cause offsets to be removed or applied, calling SCL after diagnostics has been run has
//implications
else if (!DiagnosticsHasBeenRun)
{
scl.SyncExecute();
channel.ShuntTargetADC = scl.TargetADC;
}
}
catch (System.Exception ex)
{
throw new System.Exception(string.Format("Could not set channel configuration: {0} - {1} - {2}", SerialNumber, ConfigData.Modules[i].SerialNumber(), ex.Message));
}
}
}
else if (null != squib)
{
tConfig.SetChannel(squib);
if (squib.MeasurementType == SquibMeasurementType.CURRENT) { continue; }
if (squib.IsConfigured() || squib.ConfigurationMode == DFConstantsAndEnums.ConfigMode.DummyArm)
{
Command.TDAS.SetupSquibLoad ssl = new DTS.DASLib.Command.TDAS.SetupSquibLoad(this);
ssl.ModuleIndex = ConfigData.Modules[i].ModuleArrayIndex;
ssl.ChannelNumber = 1 + (z / 2);
//20k cutoff based on http://fogbugz/fogbugz/default.asp?6090
ssl.BypassCurrentFilter = ConfigData.Modules[i].SampleRateHz > 20000 ? true : false;
ssl.DelayMS = squib.DelayMS;
if (squib.LimitDuration)
{
ssl.DurationMS = squib.DurationMS;
}
else
{
ssl.DurationMS = 0;
ssl.DurationMS = MaxSquibDurationMS;
}
switch (squib.FireMode)
{
case SquibFireMode.CAP:
ssl.FireMode = DTS.DASLib.Command.TDAS.SetupSquibLoad.FireModes.CapacitorDischarge;
break;
case SquibFireMode.CONSTANT:
ssl.FireMode = DTS.DASLib.Command.TDAS.SetupSquibLoad.FireModes.ConstantCurrent;
ssl.OutputCurrent = squib.SquibOutputCurrent;
break;
case SquibFireMode.AC:
default:
ssl.FireMode = DTS.DASLib.Command.TDAS.SetupSquibLoad.FireModes.AlternatingCurrent;
break;
}
ssl.Location = "";
ssl.MeasurementType = squib.MeasurementType == SquibMeasurementType.INIT_SIGNAL ? Command.TDAS.SetupSquibLoad.MeasurementTypes.Insertion : DTS.DASLib.Command.TDAS.SetupSquibLoad.MeasurementTypes.Voltage;
ssl.SquibResistanceMax = squib.SquibToleranceHigh;
ssl.SquibResistanceMin = squib.SquibToleranceLow;
//20k cutoff based on http://fogbugz/fogbugz/default.asp?6090
ssl.BypassVoltageFilter = ConfigData.Modules[i].SampleRateHz > 20000 ? true : false;
ssl.SyncExecute();
}
}
else if (null != digital)
{
tConfig.SetChannel(digital);
if (digital.IsConfigured() && info.ConfigureDigitalOutputs)
{
Command.TDAS.SetupDigitalLoad ssl = new DTS.DASLib.Command.TDAS.SetupDigitalLoad(this);
ssl.ChannelNumber = z - 7;
ssl.ModuleIndex = ConfigData.Modules[i].ModuleArrayIndex;
switch (digital.OutputMode)
{
case DigitalOutputModes.CCNC:
ssl.OutputMode = DTS.DASLib.Command.TDAS.SetupDigitalLoad.OutputModes.CCNC;
break;
case DigitalOutputModes.CCNO:
ssl.OutputMode = DTS.DASLib.Command.TDAS.SetupDigitalLoad.OutputModes.CCNO;
break;
case DigitalOutputModes.FVHL:
ssl.OutputMode = DTS.DASLib.Command.TDAS.SetupDigitalLoad.OutputModes.VHL;
break;
case DigitalOutputModes.FVLH:
default:
ssl.OutputMode = DTS.DASLib.Command.TDAS.SetupDigitalLoad.OutputModes.VLH;
break;
}
ssl.DelayMS = digital.DelayMS;
ssl.DurationMS = digital.DurationMS;
//ssl.Location = "";
ssl.SyncExecute();
}
}
info.Progress(Convert.ToInt32(100 * currentChannel++ / (2 * numChannels)));
}
using (StreamWriter sw = new StreamWriter(tConfig.FileName))
{
tConfig.WriteXml(System.Xml.XmlWriter.Create(sw));
sw.Flush();
sw.Close();
}
tEntireConfig.SetModule(tConfig);
}
info.Progress(100);
using (StreamWriter sw = new StreamWriter(tEntireConfig.FileName))
{
tEntireConfig.WriteXml(System.Xml.XmlWriter.Create(sw));
sw.Flush();
sw.Close();
}
ConfigurationData.SetConfiguration(this, File.ReadAllText(tEntireConfig.FileName), ConfigurationData.DIAGNOSTIC_FILESTORE);
ConfigureHasBeenRun = true;
if (info.DiscardDiagnostics) { DiagnosticsHasBeenRun = false; }
info.Success();
ConfigData.ClearSetup = false;
}
catch (CanceledException)
{
info.Cancel();
}
catch (System.Exception ex)
{
info.Error(ex.Message, ex);
}
}
private double GetRequestedRange(AnalogInputDASChannel analog, double MvPerEu)
{
if (null != analog.LinearizationFormula && analog.LinearizationFormula.IsValid())
{
switch(analog.LinearizationFormula.NonLinearStyle)
{
case NonLinearStyles.Polynomial:
//don't do anything different for polynomial
break;
default:
if (MvPerEu.Equals(1D)) { return GetRequestedRangeFull(); }
else { return analog.DesiredRangeWithHeadroomEU* MvPerEu; }
}
}
return analog.DesiredRangeWithHeadroomEU;
}
private double GetRequestedRangeFull()
{
return IsG5() ? MaxG5InputRange : MaxPROInputRange;
}
#endregion
void IConfigurationActions.Reboot(ServiceCallback callback, object userData)
{
var info = new TDASServiceAsyncInfo(callback, userData);
info.Success();
}
#region Update sensor IDs
/// <summary>
/// Retrieve the info to fill in the ConfigData property
/// </summary>
/// <param name="callback">The delegate to report to</param>
/// <param name="userData">User supplied data that we pass along</param>
void IConfigurationActions.UpdateIDs(ServiceCallback callback, object userData)
{
var info = new TDASServiceAsyncInfo(callback, userData);
LaunchAsyncWorker("TDAS.UpdateIDs", new WaitCallback(AsyncUpdateIDs), info);
}
private class UpdateIDSInfo : TDASServiceAsyncInfo
{
public DASModule Module { get; set; }
public DASChannel Channel { get; set; }
public UpdateIDSInfo(ServiceCallback callback, object userData, DASModule module, DASChannel channel)
: base(callback, userData)
{
Module = module;
Channel = channel;
}
}
void IConfigurationActions.UpdateId(ServiceCallback callback, object userData, DASModule module, DASChannel channel)
{
//var info = new UpdateIDSInfo(callback, userData, module, channel);
//LaunchAsyncWorker("TDAS.UpdateId", new WaitCallback(AsyncUpdateId), info);
//I don't know if it's possible to retrieve a single channel id yet, so for now just do the UpdateIds
var info = new TDASServiceAsyncInfo(callback, userData);
LaunchAsyncWorker("TDAS.UpdateIDs", new WaitCallback(AsyncUpdateIDs), info);
}
private void AsyncUpdateIDs(object configAsyncInfo)
{
var info = configAsyncInfo as TDASServiceAsyncInfo;
if (ConfigData == null)
{
info.Error("DAS doesn't have any ConfigData");
return;
}
try
{
// get sensor ID's
if (ConfigData.Modules != null)
{
if (IsG5())
{
GetEIDSG5();
}
else
{
GetEIDsByModules();
}
}
info.Success();
}
catch (CanceledException)
{
info.Cancel();
}
catch (System.Exception ex)
{
info.Error(ex.Message, ex);
}
}
/// <summary>
/// retrieves all non AUX EIDs on a G5 and populates channels with those EIDs
/// </summary>
private void GetEIDSG5()
{
if (RunTestVariables.BypassEIDRead)
{
RunTestVariables.BlankIds(ConfigData);
return;
}
var EIDs = EIDReader.RetrieveEIDsG5(this);
var eidIDX = 0;
for (var moduleIdx = 0; moduleIdx < ConfigData.Modules.Length; moduleIdx++)
{
var module = ConfigData.Modules[moduleIdx];
for (var channelIdx = 0; channelIdx < module.Channels.Length; channelIdx++)
{
var eid = new EID[] { new EID() };
if (eidIDX < EIDs.Length)
{
eid = EIDs[eidIDX++];
}
module.Channels[channelIdx].IDs = eid;
}
}
}
/// <summary>
/// goes module by module and populate channel EIDs G5 should use G5 version.
/// </summary>
private void GetEIDsByModules()
{
if (RunTestVariables.BypassEIDRead)
{
RunTestVariables.BlankIds(ConfigData);
return;
}
foreach (var module in ConfigData.Modules)
{
if (DASInfo.Modules[module.ModuleArrayIndex].TypeOfModule == DFConstantsAndEnums.ModuleType.EMPTYBANK) { continue; }
EID[] ids = EIDReader.RetriveEIDs(this, module.ModuleArrayIndex);
if (null != ids && ids.Length > 0)
{
for (int i = 0; i < module.Channels.Length; i++)
{
if (null != ids && i < ids.Length)
{
int channelIdx = i;
if (IsTom((DASModule)module)) { channelIdx = i * 2; }
if (ids[i].IsValid())
{
module.Channels[channelIdx].IDs = new EID[] { ids[i] };
}
else
{
module.Channels[channelIdx].IDs = new EID[] { new EID() };
}
}
else
{
module.Channels[i].IDs = new EID[] { new EID() };
}
}
}
}
}
#endregion
#region Arm attribute helpers
/*
private void SetArmAttribute(AttributeTypes.ArmAndEventAttributes key, object value, bool ShouldOverwrite)
{
var set = new SetArmAttribute(this);
set.SetValue(key, value, ShouldOverwrite);
set.SyncExecute();
}
*/
/*
private void SetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes key,
Test.Module.RecordingMode value)
{
SetArmAttribute(key, (byte)value, true);
}
*/
/*
private void SetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes key, UInt32 value)
{
SetArmAttribute(key, value, true);
}
*/
/*
private void SetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes key, float value)
{
SetArmAttribute(key, value, true);
}
*/
/*
private void SetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes key, string value)
{
SetArmAttribute(key, value, true);
}
*/
/*
private void SetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes key, UInt64 value)
{
SetArmAttribute(key, value, true);
}
*/
/*
private void SetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes key,
object value)
{
var set = new SetArmAttribute(this);
set.SetValue(key, value, true);
set.SyncExecute();
}
*/
/*
private void GetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes key, out Test.Module.RecordingMode value)
{
var query = new QueryArmAttribute(this);
query.Key = key;
query.SyncExecute();
if ((AttributeTypes.AttributeDataTypes)query.DataType != AttributeTypes.AttributeDataTypes.UInt8)
throw new System.Exception("ConfigurationService.GetArmAttribute.RecordingMode: Found type " + (AttributeTypes.AttributeDataTypes)query.DataType);
value = (Test.Module.RecordingMode)query.Value;
}
*/
/*
private void GetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes key, out UInt32 value)
{
var query = new QueryArmAttribute(this);
query.Key = key;
query.SyncExecute();
if ((AttributeTypes.AttributeDataTypes)query.DataType != AttributeTypes.AttributeDataTypes.UInt32)
throw new System.Exception("ConfigurationService.GetArmAttribute.UInt32: Found type " + (AttributeTypes.AttributeDataTypes)query.DataType);
value = (UInt32)query.Value;
}
*/
/*
private void GetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes key, out float value)
{
var query = new QueryArmAttribute(this);
query.Key = key;
query.SyncExecute();
if ((AttributeTypes.AttributeDataTypes)query.DataType != AttributeTypes.AttributeDataTypes.Float32)
throw new System.Exception("ConfigurationService.GetArmAttribute.float: Found type " + (AttributeTypes.AttributeDataTypes)query.DataType);
value = (float)query.Value;
}
*/
/*
private void GetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes key, out string value)
{
var query = new QueryArmAttribute(this);
query.Key = key;
query.SyncExecute();
if ((AttributeTypes.AttributeDataTypes)query.DataType != AttributeTypes.AttributeDataTypes.Ascii)
throw new System.Exception("ConfigurationService.GetArmAttribute.string: Found type " + (AttributeTypes.AttributeDataTypes)query.DataType);
value = (string)query.Value;
}
*/
/*
private void GetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes key, out UInt64 value)
{
var query = new QueryArmAttribute(this);
query.Key = key;
query.SyncExecute();
if ((AttributeTypes.AttributeDataTypes)query.DataType != AttributeTypes.AttributeDataTypes.UInt64)
throw new System.Exception("ConfigurationService.GetArmAttribute.UInt64: Found type " + (AttributeTypes.AttributeDataTypes)query.DataType);
value = (UInt64)query.Value;
}
*/
#endregion
#region XML attributes
/*
private void StoreAttributes(string data, SliceServiceAsyncInfo info, double ProgressSteps)
{
// first calc how many we need
var NumBlocks = data.Length / DTS.Slice.Service.Attribute.MaxSingleAttributeSize;
if ((data.Length % DTS.Slice.Service.Attribute.MaxSingleAttributeSize) != 0)
NumBlocks++;
// write the blocks
// for progress, assume that we'll have about 40 blocks to write
var blockWeight = 40.0 / (double)NumBlocks;
for (int BlockIdx = 0; BlockIdx < NumBlocks; BlockIdx++)
{
int blockLength = data.Length - (BlockIdx * DTS.Slice.Service.Attribute.MaxSingleAttributeSize);
if (blockLength > DTS.Slice.Service.Attribute.MaxSingleAttributeSize)
blockLength = DTS.Slice.Service.Attribute.MaxSingleAttributeSize;
string block = data.Substring(BlockIdx * DTS.Slice.Service.Attribute.MaxSingleAttributeSize, blockLength);
var AttrSet = new SetArmAttribute(this);
AttrSet.SetValue((AttributeTypes.ArmAndEventAttributes)(DTS.Slice.Service.Attribute.BulkAttributeStartNumber + BlockIdx),
block, AttributeTypes.AttributeDataTypes.Ascii, true);
AttrSet.SyncExecute();
info.Progress((int)((12.0 + blockWeight * (double)BlockIdx) / ProgressSteps * 100.0));
}
// write our speacial header attribute
StringBuilder BlockList = new StringBuilder(DTS.Slice.Service.Attribute.BulkAttributeStartNumber.ToString(),
DTS.Slice.Service.Attribute.MaxSingleAttributeSize);
for (int BlockIdx = 1; BlockIdx < NumBlocks; BlockIdx++)
BlockList.Append("," + (DTS.Slice.Service.Attribute.BulkAttributeStartNumber + BlockIdx).ToString());
var HeaderAttrSet = new SetArmAttribute(this);
HeaderAttrSet.SetValue(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes.StoredConfigIndex,
BlockList.ToString(), AttributeTypes.AttributeDataTypes.Ascii, true);
HeaderAttrSet.SyncExecute();
}
*/
/*
private string RetrieveAttributes()
{
// first get our special header attribute
var AttrGet = new QueryArmAttribute(this);
AttrGet.Key = DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes.StoredConfigIndex;
AttrGet.SyncExecute();
// make sure we have something
//if(AttrGet.Value == null || AttrGet.Value.Length == 0)
//{
// // "Slice.RetrieveAttributes: Header attribute is empty"
// throw new Exception(Strings.Slice_RetrieveAttributes_Err1);
//}
// parse the result
//System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
var BlockListStr = AttrGet.Value as string;
// still there?
if (string.IsNullOrEmpty(BlockListStr))
{
// "Slice.RetrieveAttributes: Header attribute as string is empty"
throw new System.Exception(Strings.Slice_RetrieveAttributes_Err2);
}
var BlockListStrArr = BlockListStr.Split(',');
var BlockList = new List<int>();
foreach (string NumStr in BlockListStrArr)
{
int Number = 0;
if (!int.TryParse(NumStr, out Number))
{
// "Slice.RetrieveAttributes: Header attribute is invalid"
throw new System.Exception(Strings.Slice_RetrieveAttributes_Err3);
}
BlockList.Add(Number);
}
StringBuilder AllStrings = new StringBuilder(BlockList.Count * DTS.Slice.Service.Attribute.MaxSingleAttributeSize);
foreach (int AttrNumber in BlockList)
{
AttrGet.Key = (AttributeTypes.ArmAndEventAttributes)AttrNumber;
AttrGet.SyncExecute();
var str = AttrGet.Value as string;
AllStrings.Append(str);
}
var WholeStr = AllStrings.ToString();
if (string.IsNullOrEmpty(WholeStr))
{
// "Slice.RetrieveAttributes: Attributes are empty"
throw new System.Exception(Strings.Slice_RetrieveAttributes_Err4);
}
return WholeStr;
}
*/
#endregion
#region Attributes
/*
private UInt32 SampleRate
{
get
{
UInt32 Value;
GetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes.SampleRate, out Value);
return Value;
}
set
{
SetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes.SampleRate, value);
}
}
*/
/*
private float AAFilter
{
get
{
float Value;
GetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes.AAFilterFrequency, out Value);
return Value;
}
set
{
SetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes.AAFilterFrequency, value);
}
}
*/
/*
private string TestID
{
get
{
string Value;
GetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes.Name, out Value);
return Value;
}
set
{
SetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes.Name, value);
}
}
*/
/*
private string TestDescription
{
get
{
string Value;
GetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes.Description, out Value);
return Value;
}
set
{
SetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes.Description, value);
}
}
*/
/*private uint SliceCount
{
get
{
var CountAttr = new SliceCountAttribute();
CountAttr.ReadFromRecorder(this);
return CountAttr.Value;
}
set
{
var CountAttr = new SliceCountAttribute();
if(value == 0)
{
CountAttr.Value = 1;
}
else
{
CountAttr.Value = (byte)value;
}
CountAttr.SaveToRecorder(this);
}
}*/
/*
private UInt64 PreTriggerSamples
{
get
{
UInt64 Value;
GetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes.PreTriggerSamplesRequested, out Value);
return Value;
}
set
{
SetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes.PreTriggerSamplesRequested, value);
}
}
*/
/*
private ulong PostTriggerSamples
{
get
{
UInt64 Value;
GetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes.PostTriggerSamplesRequested, out Value);
return Value;
}
set
{
SetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes.PostTriggerSamplesRequested, value);
}
}
*/
/*
private Test.Module.RecordingMode TestType
{
get
{
Test.Module.RecordingMode Value;
GetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes.ArmMode, out Value);
return Value;
}
set
{
SetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes.ArmMode, value);
}
}
*/
#endregion
#region EID functions
#endregion
}
}