Files
DP44/DataPRO/IService/Classes/SLICE/SLICERecorder.cs

855 lines
34 KiB
C#
Raw Normal View History

2026-04-17 14:55:32 -04:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Threading;
using System.Xml.Serialization;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using DTS.DASLib.Command.SLICE;
using DTS.DASLib.Service;
using DTS.Common.DAS.Concepts;
using DTS.Common.Interface.DASFactory;
using DTS.Common.Utilities;
using DTS.Common.Utils;
using DTS.DASLib.Command.SLICE.DownloadCommands;
using DTS.DASLib.Command.SLICE.RealtimeCommands;
using DTS.Common.Enums.DASFactory;
namespace DTS.DASLib.Service.FirmwareUtility
{
#region SLICE Recorder class
public class SLICERecorder
{
private ICommunication unit;
public delegate void SetAttributeMethod(object val);
public SLICERecorder(DTS.Common.Interface.DASFactory.ICommunication _unit)
{
unit = _unit;
}
public ushort EventNumber { get; set; }
public void QueryFirmwareVersion(out string firmwareversion)
{
var fvq = new QueryFirmwareVersion(unit);
fvq.SyncExecute();
firmwareversion = fvq.Version;
}
public void QuerySerialNumber(out string serialnumber)
{
var snq = new QuerySerialNumber(unit);
snq.SyncExecute();
serialnumber = snq.SerialNumber;
}
public void RunFlashSelfTest(UInt32 BlocksToTest, out double[] BlockTimingMicroSeconds)
{
const UInt32 skip = 4;
const UInt32 FirstSector = 827392 + skip;
// Have the recorder run the test
var fstest = new SelfTestFlash(unit);
fstest.BlocksToTest = BlocksToTest;
fstest.SyncExecute();
// Pick up the results, skipping skip
BlocksToTest -= skip;
BlockTimingMicroSeconds = new double[BlocksToTest - 1];
ulong[] ticks = new ulong[BlocksToTest];
var flashread = new ReadArbitraryFlash(unit);
for (UInt32 CurrentSector = 0; CurrentSector < BlocksToTest; CurrentSector++)
{
flashread.Address = (CurrentSector + FirstSector) * 512;
flashread.Length = 16;
flashread.SyncExecute();
byte[] u64 = new byte[8];
for (int i = 0; i < 8; i++)
{
u64[i] = flashread.Data[2 * i + 1];
}
ByteConvertor.Convert(u64, 0, out ticks[(int)CurrentSector]);
}
for (UInt32 CurrentSector = 0; CurrentSector < BlocksToTest - 1; CurrentSector++)
{
BlockTimingMicroSeconds[(int)CurrentSector] = (ticks[(int)CurrentSector + 1] - ticks[(int)CurrentSector]) / 10.0;
}
}
public void QuerySystemAttributes(out Dictionary<AttributeTypes.SystemAttributes, object> attributes, out List<SetAttributeMethod> setmethods, out List<int> keys)
{
var getKeys = new QuerySystemAttributeKeys(unit);
getKeys.SyncExecute();
keys = new List<int>();
attributes = new Dictionary<AttributeTypes.SystemAttributes, object>();
setmethods = new List<SetAttributeMethod>();
foreach (ushort key in getKeys.Keys)
{
var CurrentAttribute = (AttributeTypes.SystemAttributes)key;
var query = new QuerySystemAttribute(unit);
query.Key = CurrentAttribute;
query.SyncExecute();
attributes.Add(CurrentAttribute, query.Value);
keys.Add(key);
setmethods.Add(delegate (object val)
{
var attrSet = new SetSystemAttribute(unit);
attrSet.SetValue(CurrentAttribute, val, true);
attrSet.SyncExecute();
});
}
}
public void QuerySystemAttributes_SLICE6DB(out Dictionary<AttributeTypes.SystemAttributesSLICE6DB, object> attributes, out List<SetAttributeMethod> setmethods, out List<int> keys)
{
var getKeys = new QuerySystemAttributeKeys(unit);
getKeys.SyncExecute();
keys = new List<int>();
attributes = new Dictionary<AttributeTypes.SystemAttributesSLICE6DB, object>();
setmethods = new List<SetAttributeMethod>();
foreach (ushort key in getKeys.Keys)
{
var CurrentAttribute = (AttributeTypes.SystemAttributesSLICE6DB)key;
var query = new QuerySystemAttributeSLICE6DB(unit);
query.Key = CurrentAttribute;
query.SyncExecute();
attributes.Add(CurrentAttribute, query.Value);
keys.Add(key);
setmethods.Add(delegate (object val)
{
var attrSet = new SetSystemAttributeSLICE6DB(unit);
attrSet.SetValue(CurrentAttribute, val, true);
attrSet.SyncExecute();
});
}
}
public void QuerySystemAttributes_SLICE6AIR(out Dictionary<AttributeTypes.SystemAttributesSLICE6AIR, object> attributes, out List<SetAttributeMethod> setmethods, out List<int> keys)
{
var getKeys = new QuerySystemAttributeKeys(unit);
getKeys.SyncExecute();
keys = new List<int>();
attributes = new Dictionary<AttributeTypes.SystemAttributesSLICE6AIR, object>();
setmethods = new List<SetAttributeMethod>();
foreach (ushort key in getKeys.Keys)
{
var CurrentAttribute = (AttributeTypes.SystemAttributesSLICE6AIR)key;
var query = new QuerySystemAttributeSLICE6AIR(unit);
query.Key = CurrentAttribute;
query.SyncExecute();
attributes.Add(CurrentAttribute, query.Value);
keys.Add(key);
setmethods.Add(delegate (object val)
{
var attrSet = new SetSystemAttributeSLICE6AIR(unit);
attrSet.SetValue(CurrentAttribute, val, true);
attrSet.SyncExecute();
});
}
}
public void QuerySystemAttributes_SLICE6(out Dictionary<AttributeTypes.SystemAttributesSLICE6, object> attributes, out List<SetAttributeMethod> setmethods, out List<int> keys)
{
var getKeys = new QuerySystemAttributeKeys(unit);
getKeys.SyncExecute();
keys = new List<int>();
attributes = new Dictionary<AttributeTypes.SystemAttributesSLICE6, object>();
setmethods = new List<SetAttributeMethod>();
foreach (ushort key in getKeys.Keys)
{
var CurrentAttribute = (AttributeTypes.SystemAttributesSLICE6)key;
var query = new QuerySystemAttributeSLICE6(unit);
query.Key = CurrentAttribute;
query.SyncExecute();
attributes.Add(CurrentAttribute, query.Value);
keys.Add(key);
setmethods.Add(delegate (object val)
{
var attrSet = new SetSystemAttributeSLICE6(unit);
attrSet.SetValue(CurrentAttribute, val, true);
attrSet.SyncExecute();
});
}
}
public void QuerySystemAttributes_SLICE2(out Dictionary<AttributeTypes.SystemAttributesSLICE2, object> attributes, out List<SetAttributeMethod> setmethods, out List<int> keys)
{
var getKeys = new QuerySystemAttributeKeys(unit);
getKeys.SyncExecute();
keys = new List<int>();
attributes = new Dictionary<AttributeTypes.SystemAttributesSLICE2, object>();
setmethods = new List<SetAttributeMethod>();
foreach (ushort key in getKeys.Keys)
{
var CurrentAttribute = (AttributeTypes.SystemAttributesSLICE2)key;
var query = new QuerySystemAttributeSLICE2(unit);
query.Key = CurrentAttribute;
query.SyncExecute();
attributes.Add(CurrentAttribute, query.Value);
keys.Add(key);
setmethods.Add(delegate (object val)
{
var attrSet = new SetSystemAttributeSLICE2(unit);
attrSet.SetValue(CurrentAttribute, val, true);
attrSet.SyncExecute();
});
}
}
public void QueryBridgeAttributes_SLICE2(byte bridgeID, out Dictionary<AttributeTypes.SystemAttributes_Bridge_SLICE2, object> attributes, out List<SetAttributeMethod> setmethods, out List<int> keys)
{
var getKeys = System.Enum.GetValues(typeof(AttributeTypes.SystemAttributes_Bridge_SLICE2));
keys = new List<int>();
attributes = new Dictionary<AttributeTypes.SystemAttributes_Bridge_SLICE2, object>();
setmethods = new List<SetAttributeMethod>();
foreach (ushort key in getKeys)
{
try
{
var CurrentAttribute = (AttributeTypes.SystemAttributes_Bridge_SLICE2)key;
var query = new QuerySystemAttribute_Slice2Bridge(unit);
query.DeviceID = bridgeID;
query.Key = CurrentAttribute;
query.SyncExecute();
attributes.Add(CurrentAttribute, query.Value);
keys.Add(key);
setmethods.Add(delegate (object val)
{
var attrSet = new SetSystemAttribute_Bridge_SLICE2(unit);
attrSet.SetValue(CurrentAttribute, val, true);
attrSet.SyncExecute();
});
}
catch { }
}
}
public void QueryBridgeAttributes_TOM(byte bridgeID, out Dictionary<AttributeTypes.SystemAttributes_Bridge_SLICE_TOM, object> attributes, out List<SetAttributeMethod> setmethods, out List<int> keys)
{
var getKeys = System.Enum.GetValues(typeof(AttributeTypes.SystemAttributes_Bridge_SLICE_TOM));
keys = new List<int>();
attributes = new Dictionary<AttributeTypes.SystemAttributes_Bridge_SLICE_TOM, object>();
setmethods = new List<SetAttributeMethod>();
foreach (ushort key in getKeys)
{
try
{
var CurrentAttribute = (AttributeTypes.SystemAttributes_Bridge_SLICE_TOM)key;
var query = new QuerySystemAttribute_Slice_TOM(unit);
query.DeviceID = bridgeID;
query.Key = CurrentAttribute;
query.SyncExecute();
attributes.Add(CurrentAttribute, query.Value);
keys.Add(key);
setmethods.Add(delegate (object val)
{
var attrSet = new SetSystemAttributes_Bridge_SLICE_TOM(unit);
attrSet.SetValue(CurrentAttribute, val, true);
attrSet.SyncExecute();
});
}
catch { }
}
}
public void QueryBridgeAttributes(byte bridgeID, out Dictionary<AttributeTypes.SystemAttributes_Bridge, object> attributes, out List<SetAttributeMethod> setmethods, out List<int> keys)
{
var getKeys = System.Enum.GetValues(typeof(AttributeTypes.SystemAttributes_Bridge));
keys = new List<int>();
attributes = new Dictionary<AttributeTypes.SystemAttributes_Bridge, object>();
setmethods = new List<SetAttributeMethod>();
foreach (ushort key in getKeys)
{
try
{
var CurrentAttribute = (AttributeTypes.SystemAttributes_Bridge)key;
var query = new QuerySystemAttribute_Bridge(unit);
query.DeviceID = bridgeID;
query.Key = CurrentAttribute;
query.SyncExecute();
attributes.Add(CurrentAttribute, query.Value);
keys.Add(key);
setmethods.Add(delegate (object val)
{
var attrSet = new SetSystemAttribute_Bridge(unit);
attrSet.SetValue(CurrentAttribute, val, true);
attrSet.SyncExecute();
});
}
catch { }
}
}
public delegate object UpdateAttribute(object value, bool overwrite);
public void SetSystemAttribute(AttributeTypes.SystemAttributes key, object value, bool ShouldOverwrite)
{
var set = new SetSystemAttribute(unit);
set.SetValue(key, value, ShouldOverwrite);
set.SyncExecute();
}
public void SetUserAttribute(AttributeTypes.SliceUserAttributes key, object value, bool ShouldOverwrite)
{
var set = new SetUserAttribute(unit);
set.SetValue(key, value, ShouldOverwrite);
set.SyncExecute();
}
public void QueryUserAttributes(out Dictionary<AttributeTypes.SliceUserAttributes, object> attributes, out List<SetAttributeMethod> setmethods, out List<int> keys)
{
var getKeys = new QueryUserAttributeKeys(unit);
getKeys.SyncExecute();
keys = new List<int>();
attributes = new Dictionary<AttributeTypes.SliceUserAttributes, object>();
setmethods = new List<SetAttributeMethod>();
foreach (ushort key in getKeys.Keys)
{
var CurrentAttribute = (AttributeTypes.SliceUserAttributes)key;
var query = new QueryUserAttribute(unit);
query.Key = (AttributeTypes.SliceUserAttributes)key;
query.SyncExecute();
attributes.Add(CurrentAttribute, query.Value);
keys.Add(key);
setmethods.Add(delegate (object val)
{
var attrSet = new SetUserAttribute(unit);
attrSet.SetValue(CurrentAttribute, val, true);
attrSet.SyncExecute();
});
}
}
public void QueryArmAttributes(out Dictionary<AttributeTypes.ArmAndEventAttributes, object> attributes, out List<SetAttributeMethod> setmethods, out List<int> keys)
{
var getKeys = new QueryArmAttributeKeys(unit);
getKeys.SyncExecute();
keys = new List<int>();
attributes = new Dictionary<AttributeTypes.ArmAndEventAttributes, object>();
setmethods = new List<SetAttributeMethod>();
foreach (ushort key in getKeys.Keys)
{
var CurrentAttribute = (AttributeTypes.ArmAndEventAttributes)key;
var query = new QueryArmAttribute(unit);
query.Key = (AttributeTypes.ArmAndEventAttributes)key;
query.SyncExecute();
attributes.Add(CurrentAttribute, query.Value);
keys.Add(key);
setmethods.Add(delegate (object val)
{
var attrSet = new SetArmAttribute(unit);
attrSet.SetValue(CurrentAttribute, val, true);
attrSet.SyncExecute();
});
}
}
public void SetArmAttribute(AttributeTypes.ArmAndEventAttributes key, object value, bool ShouldOverwrite)
{
var set = new SetArmAttribute(unit);
set.SetValue(key, value, ShouldOverwrite);
set.SyncExecute();
}
public void QueryEventAttributes(ushort EventNumber, out Dictionary<AttributeTypes.ArmAndEventAttributes, object> attributes, out List<SetAttributeMethod> setmethods, out List<int> keys)
{
ushort TotalEvents;
attributes = new Dictionary<AttributeTypes.ArmAndEventAttributes, object>();
setmethods = new List<SetAttributeMethod>();
keys = new List<int>();
GetTotalEventsStored(out TotalEvents);
if (0 == TotalEvents) return;
var getKeys = new QueryEventAttributeKeys(unit);
getKeys.EventNumber = EventNumber;
getKeys.SyncExecute();
foreach (ushort key in getKeys.Keys)
{
var CurrentAttribute = (AttributeTypes.ArmAndEventAttributes)key;
var query = new QueryEventAttribute(unit);
query.EventNumber = EventNumber;
query.Key = CurrentAttribute;
query.SyncExecute();
attributes.Add(CurrentAttribute, query.Value);
keys.Add(key);
setmethods.Add(delegate (object val)
{
var attrSet = new SetEventAttribute(unit);
attrSet.EventNumber = EventNumber;
attrSet.SetValue(CurrentAttribute, val, true);
attrSet.SyncExecute();
});
}
}
public void SetEventAttribute(ushort EventNumber, AttributeTypes.ArmAndEventAttributes key, object value, bool ShouldOverwrite)
{
var set = new SetEventAttribute(unit);
set.EventNumber = EventNumber;
set.SetValue(key, value, ShouldOverwrite);
set.SyncExecute();
}
public void SetAntiAliasFilterImmediately(float cutoffFrequencyHz)
{
var aafilterSet = new SetAAFilterImmediate(unit);
aafilterSet.FrequencyHz = cutoffFrequencyHz;
aafilterSet.SyncExecute();
}
public void ResetEventList()
{
var reset = new ResetEventList(unit);
reset.SyncExecute();
}
public void Arm()
{
var arm = new Arm(unit);
arm.SyncExecute();
}
public void Disarm()
{
var disarm = new Disarm(unit);
disarm.SyncExecute();
}
public void GetSingleSample(out short[] adc, out int channels)
{
var ss = new RetrieveSingleSample(unit);
ss.SyncExecute();
channels = ss.Channels;
adc = new short[channels];
for (int i = 0; i < channels; i++)
{
adc[i] = ss.GetChannelData(i);
}
}
public void GetTotalEventsStored(out ushort TotalEvents)
{
var eventCountQuery = new QuerySystemAttribute(unit);
eventCountQuery.Key = AttributeTypes.SystemAttributes.TotalEventsStored;
eventCountQuery.SyncExecute();
TotalEvents = (ushort)eventCountQuery.Value;
}
public void GetTotalChannelsByEvent(ushort EventNumberFromZero, out byte TotalChannels)
{
ushort TotalEvents;
GetTotalEventsStored(out TotalEvents);
if (TotalEvents <= EventNumberFromZero)
{
TotalChannels = 0;
}
else
{
var totalChannelsQuery = new QueryEventAttribute(unit);
totalChannelsQuery.EventNumber = EventNumberFromZero;
totalChannelsQuery.Key = AttributeTypes.ArmAndEventAttributes.TotalChannels;
totalChannelsQuery.SyncExecute();
TotalChannels = (byte)totalChannelsQuery.Value;
}
return;
}
public bool IsEventAlreadyStored(ushort EventNumberFromZero)
{
ushort TotalEvents;
GetTotalEventsStored(out TotalEvents);
return (TotalEvents > EventNumberFromZero);
}
public bool IsChannelValidForEvent(ushort EventNumberFromZero, byte ChannelNumberFromZero)
{
byte TotalChannels;
GetTotalChannelsByEvent(EventNumberFromZero, out TotalChannels);
return (ChannelNumberFromZero <= TotalChannels);
}
public void QueryEventDescription(ushort EventNumberFromZero, out string EventDescription)
{
// Make sure the event is valid
if (false == IsEventAlreadyStored(EventNumberFromZero))
{
EventDescription = string.Empty;
return;
}
// Query the EventDescription event attribute
var descriptionQuery = new QueryEventAttribute(unit);
descriptionQuery.EventNumber = EventNumberFromZero;
descriptionQuery.Key = AttributeTypes.ArmAndEventAttributes.Description;
descriptionQuery.SyncExecute();
if (null == descriptionQuery.Value)
{
EventDescription = string.Empty;
}
else
{
EventDescription = (string)descriptionQuery.Value;
}
}
public void QueryEventID(ushort EventNumberFromZero, out string EventID)
{
// Make sure the event is valid
if (false == IsEventAlreadyStored(EventNumberFromZero))
{
EventID = string.Empty;
return;
}
// Query the EventDescription event attribute
var idQuery = new QueryEventAttribute(unit);
idQuery.EventNumber = EventNumberFromZero;
idQuery.Key = AttributeTypes.ArmAndEventAttributes.Name;
idQuery.SyncExecute();
if (null == idQuery.Value)
{
EventID = string.Empty;
}
else
{
EventID = (string)idQuery.Value;
}
}
public void QueryEventSampleRate(ushort EventNumberFromZero, out UInt32 SampleRate)
{
// Make sure the event is valid
if (false == IsEventAlreadyStored(EventNumberFromZero))
{
SampleRate = 0;
return;
}
// Query the EventDescription event attribute
var sampleRateQuery = new QueryEventAttribute(unit);
sampleRateQuery.EventNumber = EventNumberFromZero;
sampleRateQuery.Key = AttributeTypes.ArmAndEventAttributes.SampleRate;
sampleRateQuery.SyncExecute();
if (null == sampleRateQuery.Value)
{
SampleRate = 0;
}
else
{
SampleRate = (UInt32)sampleRateQuery.Value;
}
}
public void GetPreTriggerSamplesByEvent(ushort EventNumberFromZero, out ulong PreTriggerSamples)
{
// Make sure the event is valid
if (false == IsEventAlreadyStored(EventNumberFromZero))
{
PreTriggerSamples = 0;
return;
}
// Query the TotalSamples event attribute
var preTriggerSamplesQuery = new QueryEventAttribute(unit);
preTriggerSamplesQuery.EventNumber = EventNumberFromZero;
preTriggerSamplesQuery.Key = AttributeTypes.ArmAndEventAttributes.PreTriggerSamplesRequested;
preTriggerSamplesQuery.SyncExecute();
if (null == preTriggerSamplesQuery.Value)
{
PreTriggerSamples = 0;
}
else
{
PreTriggerSamples = (ulong)preTriggerSamplesQuery.Value;
}
}
public void GetPostTriggerSamplesByEvent(ushort EventNumberFromZero, out ulong PostTriggerSamples)
{
// Make sure the event is valid
if (false == IsEventAlreadyStored(EventNumberFromZero))
{
PostTriggerSamples = 0;
return;
}
// Query the TotalSamples event attribute
var postTriggerSamplesQuery = new QueryEventAttribute(unit);
postTriggerSamplesQuery.EventNumber = EventNumberFromZero;
postTriggerSamplesQuery.Key = AttributeTypes.ArmAndEventAttributes.PostTriggerSamplesRequested;
postTriggerSamplesQuery.SyncExecute();
if (null == postTriggerSamplesQuery.Value)
{
PostTriggerSamples = 0;
}
else
{
PostTriggerSamples = (ulong)postTriggerSamplesQuery.Value;
}
}
public void GetTotalSamplesByEvent(ushort EventNumberFromZero, out ulong TotalSamples)
{
// Make sure the event is valid
if (false == IsEventAlreadyStored(EventNumberFromZero))
{
TotalSamples = 0;
return;
}
// Query the TotalSamples event attribute
var totalSamplesQuery = new QueryEventAttribute(unit);
totalSamplesQuery.EventNumber = EventNumberFromZero;
totalSamplesQuery.Key = AttributeTypes.ArmAndEventAttributes.TotalSamplesRecorded;
try
{
totalSamplesQuery.SyncExecute();
TotalSamples = (ulong)totalSamplesQuery.Value;
}
// Store the value in the out param, but take care because it may not
// have been stored in the event's attribute store
catch
{
TotalSamples = 0;
}
// If the param is 0, fake it by summing pre and post trigger samples
// requested for the event
if (0 == TotalSamples)
{
ulong PreTriggerSamples, PostTriggerSamples;
GetPreTriggerSamplesByEvent(EventNumberFromZero, out PreTriggerSamples);
GetPostTriggerSamplesByEvent(EventNumberFromZero, out PostTriggerSamples);
TotalSamples = PreTriggerSamples + PostTriggerSamples;
}
}
public void GetEventDataByChannel(ushort EventNumberFromZero, byte ChannelNumberFromZero, out short[] adc)
{
// Make sure the channel is valid for the event requested
if (false == IsChannelValidForEvent(EventNumberFromZero, ChannelNumberFromZero))
{
adc = null;
return;
}
// Grab all the event data for the event
List<short[]> adc_all;
GetEventDataByEvent(EventNumberFromZero, out adc_all);
if (null == adc_all)
{
adc = null;
return;
}
else
{
adc = new short[adc_all[0].Length];
}
// Copy out the requested channel
Buffer.BlockCopy(adc_all[ChannelNumberFromZero], 0, adc, 0, 2 * adc_all[ChannelNumberFromZero].Length);
}
public void GetEventDataByEvent(ushort EventNumberFromZero, out List<short[]> adc)
{
// Figure out how many samples are stored and then ...
ulong TotalSamples;
GetTotalSamplesByEvent(EventNumberFromZero, out TotalSamples);
// Grab them all
GetEventSampleRangeByEvent(EventNumberFromZero, out adc, 0, TotalSamples - 1);
}
public QueryEventDataBase GetQueryEventData(DTS.Common.Interface.DASFactory.ICommunication unit)
{
return new QueryEventDataBase(unit, QueryEventDataBase.Default_IO_Timeout);
//need to do something else if unit is slice2 ...
}
public void GetEventSampleRangeByEvent(ushort EventNumberFromZero, out List<short[]> adc,
ulong FirstSample, ulong LastSample)
{
if (FirstSample > LastSample)
{
adc = null;
return;
}
// Make sure the event is valid
if (false == IsEventAlreadyStored(EventNumberFromZero))
{
adc = null;
return;
}
// Figure out how many samples are stored
ulong TotalSamples;
GetTotalSamplesByEvent(EventNumberFromZero, out TotalSamples);
// Make sure the samples requested are in the available window
ulong SamplesToGet = LastSample - FirstSample + 1;
if (FirstSample + SamplesToGet > TotalSamples)
{
adc = null;
return;
}
// Figure out how many channels were stored
byte channels;
GetTotalChannelsByEvent(EventNumberFromZero, out channels);
// Grab the data
//var dataQuery = new QueryEventData(unit);
var dataQuery = GetQueryEventData(unit);
dataQuery.EventNumber = EventNumberFromZero;
dataQuery.LastSample = LastSample;
dataQuery.ChannelsDownloaded = channels;
ulong SamplesGotten = 0;
adc = null;
while (SamplesGotten < SamplesToGet)
{
dataQuery.FirstSample = SamplesGotten;
dataQuery.SyncExecute();
ulong SamplesThisTime = 0;
if (null == adc)
{
adc = new List<short[]>(dataQuery.ChannelsDownloaded);
for (int i = 0; i < adc.Capacity; i++)
{
adc.Add(new short[SamplesToGet]);
}
}
for (int i = 0; i < dataQuery.ChannelsDownloaded; i++)
{
short[] tmp;
dataQuery.GetChannelData(i, out tmp);
SamplesThisTime = (ulong)tmp.Length;
Buffer.BlockCopy(tmp, 0, adc[i], (int)(2 * SamplesGotten),
tmp.Length > (int)(SamplesToGet - SamplesGotten) ? (int)(2 * (SamplesToGet - SamplesGotten)) : 2 * tmp.Length);
}
SamplesGotten += SamplesThisTime;
}
}
#region private members
// empty
#endregion
public void QueryBridgeAttributes_SLICE2_GEN3(byte bridgeID, out Dictionary<AttributeTypes.SystemAttributes_Bridge_SLICE2_GEN3, object> attributes, out List<SetAttributeMethod> setmethods, out List<int> keys)
{
var getKeys = System.Enum.GetValues(typeof(AttributeTypes.SystemAttributes_Bridge_SLICE2_GEN3));
keys = new List<int>();
attributes = new Dictionary<AttributeTypes.SystemAttributes_Bridge_SLICE2_GEN3, object>();
setmethods = new List<SetAttributeMethod>();
foreach (ushort key in getKeys)
{
try
{
var CurrentAttribute = (AttributeTypes.SystemAttributes_Bridge_SLICE2_GEN3)key;
var query = new QuerySystemAttribute_Slice2Bridge_GEN3(unit);
query.DeviceID = bridgeID;
query.Key = CurrentAttribute;
query.SyncExecute();
attributes.Add(CurrentAttribute, query.Value);
keys.Add(key);
setmethods.Add(delegate (object val)
{
var attrSet = new SetSystemAttribute_Slice2Bridge_GEN3(unit);
attrSet.SetValue(CurrentAttribute, val, true);
attrSet.SyncExecute();
});
}
catch { }
}
}
public enum SLICEPRO_Generation
{
SLICEPRO_GEN2 = 0, // baseType = 0
SLICEPRO_GEN3 = 1, // baseType = 0
SLICEPRO_REVC = 2 // baseType = 0,3,4 reserve for board 204revC
}
public SLICEPRO_Generation GetSLICEProHardwareVersion(DTS.Common.Interface.DASFactory.ICommunication comm)
{
byte hardwareVersion = (byte)SLICEPRO_Generation.SLICEPRO_GEN2;
if (comm.IsCommandSupported(DFConstantsAndEnums.ProtocolLimitedCommands.HardwareRevision))
{
QuerySystemAttributeSLICE2 qsas2 = new QuerySystemAttributeSLICE2(comm, 1000);
qsas2.DeviceGroup = 0;
qsas2.DeviceID = 0;
qsas2.Key = AttributeTypes.SystemAttributesSLICE2.BaseHardwareRevision;
qsas2.SyncExecute();
hardwareVersion = (byte)qsas2.Value;
}
return (SLICEPRO_Generation)hardwareVersion;
}
public enum SLICEPRO_BaseType
{
SLICEPRO_BASE_SIM = 0,
SLICE_NANO_PHRDR = 1,
SLICE_BASE_PLUS = 2,
SLICEPRO_DIM = 3,
SLICEPRO_TOM = 4,
// reserve 5 for Trigger Distributor Module which has no com to PC.
SLICE6 = 6,
SLICE6DB = 7,
SLICE6AIR = 8,
POWER_PRO = 9,
TSRAIR = 10,
SLICE6DB_3 = 11,
}
// type
public SLICEPRO_BaseType GetSLICEProBaseType(DTS.Common.Interface.DASFactory.ICommunication comm)
{
byte baseType = (byte)SLICEPRO_BaseType.SLICEPRO_BASE_SIM;
QuerySystemAttributeSLICE2 qsa = new QuerySystemAttributeSLICE2(comm, 2000);
qsa.Key = AttributeTypes.SystemAttributesSLICE2.BaseType;
qsa.SyncExecute();
baseType = Convert.ToByte(qsa.Value);
return (SLICEPRO_BaseType)baseType;
}
}
#endregion
}