using System; using System.Collections.Generic; using System.Linq; using System.Text; using DTS.DASLib.Command.SLICE; using DTS.DASLib.Command; using DTS.DASLib.Service; using DTS.Slice.Service; using DTS.Common.DAS.Concepts; using DTS.Common.ICommunication; using DTS.Common.Interface.Connection; using DTS.Common.Interface.DASFactory; namespace DTS.DASLib.Service { public partial class TDAS : Communication, IDASCommunication, IConfigurationActions, IDiagnosticsActions, ITriggerCheckActions, IRealTimeActions, IArmActions, IDownloadActions where T : IConnection, new() { long IDASCommunication.MaxMemory() { long result = 0; if ((DASInfo.MaxEventStorageSpaceInBytes == null) && (DASInfo.Modules.Count() > 0)) { result = long.MaxValue; foreach (InfoResult.Module module in DASInfo.Modules) { if (module.SerialNumber != "EMPTY") { result = (long)Math.Min(result, (decimal)(module.MaxEventStorageSpaceInBytes / module.NumberOfBytesPerSampleClock)); } } } else if ((DASInfo.MaxEventStorageSpaceInBytes != null) && (DASInfo.NumberOfBytesPerSampleClock != null)) { result = (long)(DASInfo.MaxEventStorageSpaceInBytes / DASInfo.NumberOfBytesPerSampleClock); } return result; } uint IDASCommunication.MinSampleRate() { return 50; } private const double _MaxG5SamplingRate = 100000.0; private const double _MaxSamplingRate = 305000.0; //FB16312 changed to 305kHz to match TDC "Version 5.1B" uint IDASCommunication.MaxSampleRate(int numberOfConfiguredChannels) { return MaxSampleRate(IsG5(), numberOfConfiguredChannels); } uint IDASCommunication.MaxAAFilterRate() { return MaxAAFilterRateHz; } //FB16312: surface calculation for generic use public static uint MaxSampleRate(bool isG5, int numberOfConfiguredChannels) { if (isG5) { //return Convert.ToUInt32(System.Math.Floor(_MaxSamplingRate / 32D)); return Convert.ToUInt32(_MaxG5SamplingRate); } else { return (numberOfConfiguredChannels > 0) ? Convert.ToUInt32(Math.Floor(_MaxSamplingRate / numberOfConfiguredChannels)) : Convert.ToUInt32(Math.Floor(_MaxSamplingRate / 1)); } } /* private class ConfigAttributes { ICommunication com { get; set; } public ConfigAttributes(DTS.Common.Interface.DASFactory.ICommunication _com) { com = _com; } public void PurgeStaleData(IDASCommunication das) { var cmd = new SetArmAttributesToDefaults(com); cmd.SyncExecute(); // get bridge stuff var dacValues = new UInt16[das.ConfigData.NumberOfChannels()]; foreach (var module in das.DASInfo.Modules) { var odQuery = new QuerySystemAttribute_Bridge(com); odQuery.DeviceID = (byte)(module.ModuleArrayIndex + 1); odQuery.Key = AttributeTypes.SystemAttributes_Bridge.OffsetDACA_Midscale; odQuery.SyncExecute(); dacValues[module.ModuleArrayIndex * 3 + 0] = (UInt16)odQuery.Value; odQuery.Key = AttributeTypes.SystemAttributes_Bridge.OffsetDACB_Midscale; odQuery.SyncExecute(); dacValues[module.ModuleArrayIndex * 3 + 1] = (UInt16)odQuery.Value; odQuery.Key = AttributeTypes.SystemAttributes_Bridge.OffsetDACC_Midscale; odQuery.SyncExecute(); dacValues[module.ModuleArrayIndex * 3 + 2] = (UInt16)odQuery.Value; } // set base stuff var odSet = new SetArmAttribute(com); odSet.SetValue(AttributeTypes.ArmAndEventAttributes.StackChannelOffsetDACSettings, dacValues, true); odSet.SyncExecute(); } #region Arm attribute helpers private void SetArmAttribute(AttributeTypes.ArmAndEventAttributes key, object value, bool ShouldOverwrite) { var set = new SetArmAttribute(com); set.SetValue(key, value, ShouldOverwrite); set.SyncExecute(); } public void SetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes key, Test.Module.RecordingMode value) { SetArmAttribute(key, (byte)value, true); } public void SetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes key, UInt32 value) { SetArmAttribute(key, value, true); } public void SetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes key, float value) { SetArmAttribute(key, value, true); } public void SetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes key, string value) { var set = new SetArmAttribute(com); var ByteArrayData = Encoding.UTF8.GetBytes(value); set.SetValue(key, ByteArrayData, true); set.SyncExecute(); } public void SetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes key, UInt64 value) { SetArmAttribute(key, value, true); } public void GetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes key, out Test.Module.RecordingMode value) { var query = new QueryArmAttribute(com); 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; } public void GetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes key, out UInt32 value) { var query = new QueryArmAttribute(com); 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; } public void GetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes key, out float value) { var query = new QueryArmAttribute(com); 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; } public void GetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes key, out string value) { var query = new QueryArmAttribute(com); query.Key = key; query.SyncExecute(); if ((AttributeTypes.AttributeDataTypes)query.DataType != AttributeTypes.AttributeDataTypes.Unicode) { throw new System.Exception("ConfigurationService.GetArmAttribute.string: Found type " + (AttributeTypes.AttributeDataTypes)query.DataType); } var values = query.Value as byte[]; value = Encoding.UTF8.GetString(values); } public void GetArmAttribute(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes key, out UInt64 value) { var query = new QueryArmAttribute(com); 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 public void StoreXMLConfig(string data, SliceServiceAsyncInfo info, double ProgressSteps) { if (string.IsNullOrEmpty(data)) { return; } // since this might contain multi byte characters, we need to convert it to a byte array first var ByteArrayData = Encoding.UTF8.GetBytes(data); // calc how many we need var NumBlocks = ByteArrayData.Length / DTS.Slice.Service.Attribute.MaxSingleAttributeSize; if ((ByteArrayData.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++) { // contruct the current block int blockLength = ByteArrayData.Length - (BlockIdx * DTS.Slice.Service.Attribute.MaxSingleAttributeSize); if (blockLength > DTS.Slice.Service.Attribute.MaxSingleAttributeSize) { blockLength = DTS.Slice.Service.Attribute.MaxSingleAttributeSize; } var block = new byte[blockLength]; Array.Copy(ByteArrayData, BlockIdx * DTS.Slice.Service.Attribute.MaxSingleAttributeSize, block, 0, blockLength); // write it to firmware var AttrSet = new SetArmAttribute(com); var attrNum = (AttributeTypes.ArmAndEventAttributes)(DTS.Slice.Service.Attribute.BulkAttributeStartNumber + BlockIdx); AttrSet.SetValue(attrNum, block, AttributeTypes.AttributeDataTypes.Unicode, true); AttrSet.SyncExecute(); info.Progress((int)((12.0 + blockWeight * (double)BlockIdx) / ProgressSteps * 100.0)); } // write our speacial header attribute var InvariantCulture = new System.Globalization.CultureInfo(""); var BlockList = new StringBuilder(DTS.Slice.Service.Attribute.BulkAttributeStartNumber.ToString(InvariantCulture), DTS.Slice.Service.Attribute.MaxSingleAttributeSize); for (int BlockIdx = 1; BlockIdx < NumBlocks; BlockIdx++) { BlockList.Append("," + (DTS.Slice.Service.Attribute.BulkAttributeStartNumber + BlockIdx).ToString(InvariantCulture)); } var HeaderAttrSet = new SetArmAttribute(com); // this attribute only contains digits and commas so it's OK to keep it as Ascii HeaderAttrSet.SetValue(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes.StoredConfigIndex, BlockList.ToString(), AttributeTypes.AttributeDataTypes.Ascii, true); HeaderAttrSet.SyncExecute(); } public string RetrieveXMLConfig() { // first get our special header attribute var AttrGet = new QueryArmAttribute(com); AttrGet.Key = AttributeTypes.ArmAndEventAttributes.StoredConfigIndex; AttrGet.SyncExecute(); // this attribute only contains digits and commas so it's OK to keep it as Ascii (see above) 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 InvariantCulture = new System.Globalization.CultureInfo(""); var BlockListStrArr = BlockListStr.Split(','); var BlockList = new List(); foreach (string NumStr in BlockListStrArr) { ushort Number = 0; if (!ushort.TryParse(NumStr, System.Globalization.NumberStyles.Integer, InvariantCulture, out Number)) { // "Slice.RetrieveAttributes: Header attribute is invalid" throw new System.Exception(Strings.Slice_RetrieveAttributes_Err3); } BlockList.Add(Number); } var AllStrings = new StringBuilder(BlockList.Count * DTS.Slice.Service.Attribute.MaxSingleAttributeSize); foreach (var AttrNumber in BlockList) { AttrGet.Key = (AttributeTypes.ArmAndEventAttributes)AttrNumber; AttrGet.SyncExecute(); // old version stored the data as Ascii if (AttrGet.DataType == AttributeTypes.AttributeDataTypes.Ascii) { var values = AttrGet.Value as string; AllStrings.Append(values); } // new version uses Unicode (basically byte[]) else if (AttrGet.DataType == AttributeTypes.AttributeDataTypes.Unicode) { var values = AttrGet.Value as byte[]; var str = Encoding.UTF8.GetString(values); AllStrings.Append(str); } else { // this is really bad! throw new System.Exception(string.Format("RetrieveXMLConfig: Unknown datatype {0}", AttrGet.DataType.ToString())); } } var WholeStr = AllStrings.ToString(); if (string.IsNullOrEmpty(WholeStr)) { // "Slice.RetrieveAttributes: Attributes are empty" throw new System.Exception(Strings.Slice_RetrieveAttributes_Err4); } return WholeStr; } /// /// Retrieve the XML string that was split and stored in the Arm attributes /// /// The event number to get it from /// /// The combined XML string public string RetrieveEventXMLConfig(int eventNum, QueryDownloadProgress progress) { // first get our special header attribute var AttrGet = new QueryEventAttribute(com); AttrGet.EventNumber = (ushort)eventNum; AttrGet.Key = AttributeTypes.ArmAndEventAttributes.StoredConfigIndex; AttrGet.SyncExecute(); progress.Step(); var BlockListStr = AttrGet.Value as string; // still there? if (string.IsNullOrEmpty(BlockListStr)) { // "Slice.RetrieveEventAttributes: Header attribute is empty" throw new System.Exception(Strings.Slice_RetrieveEventAttributes_Err1); } var InvariantCulture = new System.Globalization.CultureInfo(""); var BlockListStrArr = BlockListStr.Split(','); var BlockList = new List(); foreach (string NumStr in BlockListStrArr) { ushort Number = 0; if (!ushort.TryParse(NumStr, System.Globalization.NumberStyles.Integer, InvariantCulture, out Number)) { // "Slice.RetrieveEventAttributes: Header attribute is invalid" throw new System.Exception(Strings.Slice_RetrieveEventAttributes_Err2); } BlockList.Add(Number); } var AllStrings = new StringBuilder(BlockList.Count * DTS.Slice.Service.Attribute.MaxSingleAttributeSize); foreach (var AttrNumber in BlockList) { AttrGet.Key = (AttributeTypes.ArmAndEventAttributes)AttrNumber; AttrGet.SyncExecute(); progress.Step(); // old version stored the data as Ascii if (AttrGet.DataType == AttributeTypes.AttributeDataTypes.Ascii) { var values = AttrGet.Value as string; AllStrings.Append(values); } // new version uses Unicode (basically byte[]) else if (AttrGet.DataType == AttributeTypes.AttributeDataTypes.Unicode) { var values = AttrGet.Value as byte[]; var str = Encoding.UTF8.GetString(values); AllStrings.Append(str); } else { // this is really bad! throw new System.Exception(string.Format("RetrieveEventXMLConfig(event={0}): Unknown datatype {1}", eventNum, AttrGet.DataType.ToString())); } } var WholeStr = AllStrings.ToString(); if (string.IsNullOrEmpty(WholeStr)) { // "Slice.RetrieveEventAttributes: Attributes are empty" throw new System.Exception(Strings.Slice_RetrieveEventAttributes_Err3); } return WholeStr; } #endregion public void ConfigureRange(float[] ranges) { // this function shall just set the range attribute for channel var set = new SetArmAttribute(com); set.SetValue(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes.StackChannelRangesMillivolts, ranges, true); set.SyncExecute(); } public void ConfigureBridge(bool[] IsHalfBridgeArray) { // we need to construct a byte array, true==1, false==0 var byteArray = new byte[IsHalfBridgeArray.Length]; for (int idx = 0; idx < IsHalfBridgeArray.Length; idx++) { byteArray[idx] = (byte)(IsHalfBridgeArray[idx] ? 1 : 0); } var set = new SetArmAttribute(com); set.SetValue(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes.StackChannelBridgeCompletionEnable, byteArray, true); set.SyncExecute(); } public void ConfigureBridgeResistance(UInt16[] BridgeResistanceArray) { // this function shall just set the bridge resistance for the channels var set = new SetArmAttribute(com); set.SetValue(DTS.DASLib.Command.SLICE.AttributeTypes.ArmAndEventAttributes.StackChannelBridgeResistanceOhms, BridgeResistanceArray, true); set.SyncExecute(); } public float[] GetScaleFactors() { // this function shall just set the range attribute for channel var query = new QueryArmAttribute(com); query.Key = AttributeTypes.ArmAndEventAttributes.StackChannelScaleFactorsMillivoltsPerADC; query.SyncExecute(); return query.Value as float[]; } #region Attributes public 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); } } public 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); } } public 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); } } public 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); } } public 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); } } public 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); } } public 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 Helper functions public uint CalculateNumberOfModules(ConfigurationData config, uint numChannels) { // this is a shortcut for now return numChannels / 3; } public UInt64 GetEventTotalSamples(int eventNum) { ulong samples = 0L; var eventSamples = new QueryEventAttribute(com); eventSamples.EventNumber = (ushort)eventNum; eventSamples.Key = AttributeTypes.ArmAndEventAttributes.TotalSamplesRecorded; try { eventSamples.SyncExecute(); samples = (ulong)eventSamples.Value; } catch (System.Exception) { try { // // Try to get enough info to proceed with a rump download. // var preSamplesRequested = new QueryEventAttribute(com); preSamplesRequested.EventNumber = (ushort)eventNum; preSamplesRequested.Key = AttributeTypes.ArmAndEventAttributes.PreTriggerSamplesRequested; preSamplesRequested.SyncExecute(); var postSamplesRequested = new QueryEventAttribute(com); postSamplesRequested.EventNumber = (ushort)eventNum; postSamplesRequested.Key = AttributeTypes.ArmAndEventAttributes.PostTriggerSamplesRequested; postSamplesRequested.SyncExecute(); samples = (ulong)preSamplesRequested.Value + (ulong)postSamplesRequested.Value + 1L; var totalSamplesRecorded = new SetEventAttribute(com); totalSamplesRecorded.EventNumber = (ushort)eventNum; totalSamplesRecorded.SetValue(AttributeTypes.ArmAndEventAttributes.TotalSamplesRecorded, samples, true); totalSamplesRecorded.SyncExecute(); } catch (System.Exception ex) { throw new System.ApplicationException("encountered problem re-querying pre/post samples after initial total sample request failure", ex); } } return samples; } public UInt64 GetEventTriggerSampleNumber(int eventNum) { var eventTSN = new QueryEventAttribute(com); eventTSN.EventNumber = (ushort)eventNum; eventTSN.Key = AttributeTypes.ArmAndEventAttributes.TriggerSampleNumber; try { eventTSN.SyncExecute(); } catch (System.Exception) { return (ulong)0; } return (ulong)eventTSN.Value; } public void SetEventTriggerSampleNumber(int eventNum, UInt64 sampleNumber) { var eventTSN = new SetEventAttribute(com); eventTSN.EventNumber = (ushort)eventNum; eventTSN.SetValue(AttributeTypes.ArmAndEventAttributes.TriggerSampleNumber, sampleNumber, true); eventTSN.SyncExecute(); } public UInt64 GetEventStartRecordSampleNumber(int eventNum) { var eventSRSN = new QueryEventAttribute(com); eventSRSN.EventNumber = (ushort)eventNum; eventSRSN.Key = AttributeTypes.ArmAndEventAttributes.StartRecordSampleNumber; try { eventSRSN.SyncExecute(); } catch (System.Exception) { return (ulong)0; } return (ulong)eventSRSN.Value; } public uint GetEventSamplerate(int eventNum) { var eventSR = new QueryEventAttribute(com); eventSR.EventNumber = (ushort)eventNum; eventSR.Key = AttributeTypes.ArmAndEventAttributes.SampleRate; eventSR.SyncExecute(); return (uint)eventSR.Value; } public uint GetEventTotalChannels(int eventNum) { var eventTC = new QueryEventAttribute(com); eventTC.EventNumber = (ushort)eventNum; eventTC.Key = AttributeTypes.ArmAndEventAttributes.TotalChannels; eventTC.SyncExecute(); return (uint)(byte)eventTC.Value; } public DateTime GetEventStartTime(int eventNum) { var eventST = new QueryEventAttribute(com); eventST.EventNumber = (ushort)eventNum; eventST.Key = AttributeTypes.ArmAndEventAttributes.StartTime; try { eventST.SyncExecute(); } catch (System.Exception) { return new DateTime(0); } DateTime rv = new DateTime(0).AddSeconds((double)((uint)eventST.Value)); return rv; } public double GetEventAAFilter(int eventNum) { var eventFF = new QueryEventAttribute(com); eventFF.EventNumber = (ushort)eventNum; eventFF.Key = AttributeTypes.ArmAndEventAttributes.AAFilterFrequency; eventFF.SyncExecute(); float aafilter = (float)eventFF.Value; return (double)aafilter; } public double GetEventExcitation(int eventNum) { var eventExc = new QueryEventAttribute(com); eventExc.EventNumber = (ushort)eventNum; throw new ApplicationException("GetEventExcitation needs to be implemented by channel ..."); //return (double)eventExc.Value; } /// /// Get the number of "level triggered" samples required for a level trigger to be declared by the DAS. /// /// /// /// The event number for which we want level trigger qualification sample information. /// /// /// /// The number of contiguous "level triggered" samples required for a level trigger event. /// /// private int[] GetLevelTriggerQualificationSamples(int eventNum) { try { var eventLevTrigQlfSamps = new QueryEventAttribute(com); eventLevTrigQlfSamps.Key = AttributeTypes.ArmAndEventAttributes.LevelTriggerQualificationSamples; eventLevTrigQlfSamps.SyncExecute(); return (int[])(eventLevTrigQlfSamps.Value); } catch (System.Exception ex) { throw new ApplicationException("encountered problem getting number of level trigger qualification samples from hardware for event " + eventNum.ToString(), ex); } } /// /// Get determination from hardware whether or not the associated DAS has directly experienced a level trigger event. /// /// /// /// The event number for which we want level trigger seen information. /// /// /// /// True if the associated DAS has experienced a level trigger event; False otherwise. /// /// private bool[] GetLevelTriggerSeen(int eventNum) { try { var eventLevTrigSeen = new QueryEventAttribute(com); eventLevTrigSeen.Key = AttributeTypes.ArmAndEventAttributes.LevelTriggerSeen; eventLevTrigSeen.SyncExecute(); return (bool[])(eventLevTrigSeen.Value); } catch (System.Exception ex) { throw new ApplicationException("encountered problem getting \"level trigger seen\" condition from hardware for event " + eventNum.ToString(), ex); } } /// /// Get number of samples that the associated hardware adjusted its level trigger time value from the time it /// actually issued a trigger fault. This adjustment is necessary because several contiguous level-triggered /// samples are necessary before some flavors of DAS will declare an actual level trigger. Once the hardware has /// determined that a trigger has occured, it must "backdate" the T0 to match the time of the first /// level-triggered sample. This number only exists for hardware that has directly experienced a level trigger /// condition. /// /// /// /// The number of the event we want the adjustment samples for. /// /// /// /// The number of samples that this DAS' trigger time value has been adjusted to compensate for time required /// by the hardware for level trigger evaluation. If the associated hardware did not directly experience the /// level trigger, this value will be null. /// /// public int?[] GetEventLevelTriggerT0AdjustmentSamples(int eventNum) { try { var eventLevTrigT0AdjSamp = new QueryEventAttribute(com); eventLevTrigT0AdjSamp.EventNumber = (ushort)eventNum; eventLevTrigT0AdjSamp.Key = AttributeTypes.ArmAndEventAttributes.LevelTriggerT0AdjustmentSamples; eventLevTrigT0AdjSamp.SyncExecute(); var levelTriggerAdjSamples = (int[])(eventLevTrigT0AdjSamp.Value); var levelTriggerSeen = GetLevelTriggerSeen(eventNum); var finalAdjustment = new int?[levelTriggerAdjSamples.Length]; for (int channel = 0; channel < finalAdjustment.Length; channel++) { finalAdjustment[channel] = levelTriggerSeen[channel] ? levelTriggerAdjSamples[channel] : (int?)null; } return finalAdjustment; } catch (System.Exception) { // CGO // This is a hacked change for now to support 00G8 and prior firmware // in the 1.04 release of SLICEWare. This and the other CGO commented // block of code need more general cleanup before 1.05. return (int?[])null; //throw new ApplicationException( "encountered problem getting event level trigger T0 adjustment samples from hardware for event " + eventNum.ToString( ), ex ); } } public bool EventHasBeenDownloaded(int eventNum, out uint flag) { try { var eventDLFlag = new QueryEventAttribute(com); eventDLFlag.EventNumber = (ushort)eventNum; eventDLFlag.Key = AttributeTypes.ArmAndEventAttributes.EventHasBeenDownloaded; eventDLFlag.SyncExecute(); flag = (uint)eventDLFlag.Value; return true; } catch (System.Exception) { flag = 0; return false; } } public void SetEventDownloaded(int eventNum, uint flag) { var eventDLFlag = new SetEventAttribute(com); eventDLFlag.EventNumber = (ushort)eventNum; eventDLFlag.SetValue(AttributeTypes.ArmAndEventAttributes.EventHasBeenDownloaded, flag, true); eventDLFlag.SyncExecute(); } public string GetEventID(int eventNum) { var eventName = new QueryEventAttribute(com); eventName.EventNumber = (ushort)eventNum; eventName.Key = AttributeTypes.ArmAndEventAttributes.Name; eventName.SyncExecute(); var values = eventName.Value as byte[]; if (null == values) { return eventName.Value as string; } else { var value = Encoding.UTF8.GetString(values); return value; } } public Guid GetEventGuid(int eventNum) { var eventGuid = new QueryEventAttribute(com); eventGuid.EventNumber = (ushort)eventNum; eventGuid.Key = AttributeTypes.ArmAndEventAttributes.EventGuid; eventGuid.SyncExecute(); return new Guid(eventGuid.Value as string); } public string GetEventDescription(int eventNum) { var eventDescr = new QueryEventAttribute(com); eventDescr.EventNumber = (ushort)eventNum; eventDescr.Key = AttributeTypes.ArmAndEventAttributes.Description; eventDescr.SyncExecute(); var values = eventDescr.Value as byte[]; if (values == null || values.Length == 0) return eventDescr.Value as string; var value = Encoding.UTF8.GetString(values); return value; } #endregion } */ } }