5030 lines
207 KiB
C#
5030 lines
207 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using DTS.Common.DAS.Concepts;
|
|
using DTS.Common.Interface.DASFactory;
|
|
using DTS.DASLib.Command;
|
|
using DTS.DASLib.Command.SLICE;
|
|
using DTS.DASLib.Service;
|
|
using DTS.Common.Utilities.Logging;
|
|
using QueryFirmwareVersion = DTS.DASLib.Command.SLICEDB.QueryFirmwareVersion;
|
|
using QueryProtocolVersion = DTS.DASLib.Command.SLICEDB.QueryProtocolVersion;
|
|
using QuerySerialNumber = DTS.DASLib.Command.SLICEDB.QuerySerialNumber;
|
|
using DTS.Common.Enums.DASFactory;
|
|
using DTS.Common.Interface.Communication;
|
|
using DTS.Common.Classes.Connection;
|
|
using DTS.Common.ICommunication;
|
|
using DTS.Common.Enums;
|
|
using DTS.Common.Enums.Hardware;
|
|
using TSRAirBaseClass = DTS.DASLib.DASFactory.WinUSBTsrAirHandling;
|
|
using TiltMIF;
|
|
using DTS.Utilities;
|
|
using DTS.Common.SharedResource.Strings;
|
|
using DTS.Common.Events;
|
|
using DTS.Common.Constant.DASSpecific;
|
|
|
|
namespace DTS.DASLib.DASFactory
|
|
{
|
|
public abstract class SliceHandling : IDeviceSetup
|
|
{
|
|
protected bool UtilityMode;
|
|
|
|
protected SliceHandling(bool utilMode)
|
|
{
|
|
UtilityMode = utilMode;
|
|
}
|
|
|
|
#region Slice constants
|
|
|
|
protected const uint MaxNumberOfModules = 8;
|
|
// Current SD cards have an AU of 4MB, so align this to a 4MB boundary.
|
|
// This sector needs to be past all of the attributes that are going to be stored.
|
|
// There are 4000 attributes/store + 1 attribute toc/store and each attribute/attribute toc
|
|
// uses 2 SD card blocks. This means that there are 4001 attributes/store, and MAX_EVENT_NUMBER+3
|
|
// stores. At 4001 attributes/store and 100 max events, there are 103*(4001*2) = 824206 SD
|
|
// card blocks used for attributes. Each 8192 blocks = 4MB, and 824206/8192 = 100.611083984375.
|
|
// There is also 1 block used for the event starting location storage, but that doesn't make us
|
|
// cross a 4MB boundary.
|
|
// Bumping this to the next 4MB bou1024ndary (101*4=404MB) gives 404*1024*1024/512
|
|
protected static readonly uint[] SamplerateList = { 500, 1000, 2500, 5000, 10000, 20000, 25000, 50000, 100000 };
|
|
protected static readonly float AAFilterDivider = 5.0F;
|
|
protected static readonly Dictionary<uint, float> Samplerate2AAFilterDict = new Dictionary<uint, float>
|
|
{
|
|
{500, 500.0F/AAFilterDivider},
|
|
{1000, 1000.0F/AAFilterDivider},
|
|
{2500, 2500.0F/AAFilterDivider},
|
|
{5000, 5000.0F/AAFilterDivider},
|
|
{10000, 10000.0F/AAFilterDivider},
|
|
{20000, 20000.0F/AAFilterDivider},
|
|
{25000, 25000.0F/AAFilterDivider},
|
|
{50000, 50000.0F/AAFilterDivider},
|
|
{100000, 100000.0F/AAFilterDivider}
|
|
};
|
|
|
|
#endregion
|
|
|
|
#region Slice information functions
|
|
|
|
protected void DummyRetriveGainCodes(DTS.Common.Interface.DASFactory.ICommunication dev)
|
|
{
|
|
try
|
|
{
|
|
var query = new QueryArmAttribute(dev)
|
|
{
|
|
Key = AttributeTypes.ArmAndEventAttributes.StackChannelGainCodes
|
|
};
|
|
query.SyncExecute();
|
|
}
|
|
catch
|
|
{
|
|
// we don't care about any errors, we're just trying to get the command into the log file!
|
|
}
|
|
}
|
|
|
|
protected void DummyRetreiveDasBootCount(DTS.Common.Interface.DASFactory.ICommunication dev)
|
|
{
|
|
try
|
|
{
|
|
var query = new QuerySystemAttribute(dev) { Key = AttributeTypes.SystemAttributes.DASBootCount };
|
|
query.SyncExecute();
|
|
}
|
|
|
|
catch
|
|
{
|
|
// we don't care about any errors, we're just trying to get the command into the log file!
|
|
}
|
|
}
|
|
|
|
protected virtual void ReadCalDates(DTS.Common.Interface.DASFactory.ICommunication dev)
|
|
{
|
|
if (!(dev is IDASCommunication dasComm)) { return; }
|
|
if (!RunTestVariables.QueryCalDateInRunTest && RunTestVariables.InRunTest)
|
|
{
|
|
dasComm.DASInfo.CalibrationDate = null;
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
//FB 16049 Support ECM Caldate
|
|
if (dev.IsCommandSupported(DFConstantsAndEnums.ProtocolLimitedCommands.BaseCalibrationDate)
|
|
&& dev is EthernetSliceDB)
|
|
{
|
|
try
|
|
{
|
|
Command.SLICEDB.QueryCalibrationDaysSince1970_01_01 qcal = new Command.SLICEDB.QueryCalibrationDaysSince1970_01_01(dev);
|
|
qcal.SyncExecute();
|
|
var calibrationDaysSince1970_01_01 = DataConditioning.GetIntegerIfPossible(qcal.CalibrationDaysSince1970_01_01);
|
|
dasComm.DASInfo.CalibrationDate = new DateTime(1970, 1, 1).AddDays(calibrationDaysSince1970_01_01);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.Log(ex);
|
|
dasComm.DASInfo.CalibrationDate = null;
|
|
}
|
|
return;
|
|
}
|
|
|
|
var qsa = new QuerySystemAttribute(dev)
|
|
{
|
|
Key = AttributeTypes.SystemAttributes.SA_CalibrationDaysSince1970_01_01
|
|
};
|
|
qsa.SyncExecute();
|
|
|
|
var days = DataConditioning.GetIntegerIfPossible(qsa.Value);
|
|
dasComm.DASInfo.CalibrationDate = new DateTime(1970, 1, 1).AddDays(days);
|
|
for (var i = 0; i < dasComm.DASInfo.Modules.Length; i++)
|
|
{
|
|
var module = dasComm.DASInfo.Modules[i];
|
|
if (null == module)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
try
|
|
{
|
|
var qsaB = new QuerySystemAttribute_Bridge(dev)
|
|
{
|
|
DeviceID = Convert.ToByte(1 + i),
|
|
Key = AttributeTypes.SystemAttributes_Bridge.CalibrationDaysSince1970_01_01
|
|
};
|
|
qsaB.SyncExecute();
|
|
|
|
days = DataConditioning.GetIntegerIfPossible(qsaB.Value);
|
|
module.CalibrationDate = new DateTime(1970, 1, 1).AddDays(days);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.Log(ex);
|
|
module.CalibrationDate = null;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (!ex.Message.Contains("StatusAttributeNotRegistered"))
|
|
{
|
|
APILogger.Log(ex);
|
|
}
|
|
|
|
dasComm.DASInfo.CalibrationDate = null;
|
|
}
|
|
finally
|
|
{
|
|
dasComm.SetDASInfo();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// does a queryprotocolversion command to a distributor
|
|
/// </summary>
|
|
private void QueryProtocolVersionDB(ICommunication dev, int timeout)
|
|
{
|
|
var query = new QueryProtocolVersion(dev, timeout);
|
|
query.SyncExecute();
|
|
dev.ProtocolVersion = query.ProtocolVersion;
|
|
}
|
|
|
|
/// <summary>
|
|
/// performs a queryprotocolversion to a slice
|
|
/// </summary>
|
|
private void QueryProtocolVersionSlice(ICommunication dev, int timeout)
|
|
{
|
|
var query = new Command.SLICE.QueryProtocolVersion(dev, timeout);
|
|
query.SyncExecute();
|
|
dev.ProtocolVersion = query.Version;
|
|
}
|
|
/// <summary>
|
|
/// apparently the protocol version command is very split among devices
|
|
/// ECMs, SDBs use 0x0A, everything else is using 0x02?
|
|
/// but there's code saying if IsEthernetDistributor use 0x0A, which is not
|
|
/// true if we are a s6DB, etc, so I decided to do that handling here
|
|
/// </summary>
|
|
/// <param name="dev"></param>
|
|
/// <param name="timeout"></param>
|
|
private void QueryProtocolVersionWrapper(ICommunication dev, int timeout)
|
|
{
|
|
switch (dev)
|
|
{
|
|
case EthernetSliceDB _:
|
|
QueryProtocolVersionDB(dev, timeout);
|
|
break;
|
|
case EthernetSlice6DB3 _:
|
|
case EthernetSlice6DB _:
|
|
default:
|
|
QueryProtocolVersionSlice(dev, timeout);
|
|
break;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// sets the recording modes for TOMS
|
|
/// </summary>
|
|
/// <param name="module"></param>
|
|
/// <param name="dev"></param>
|
|
protected static void SetRecordingModesTOM(InfoResult.Module module, ICommunication dev)
|
|
{
|
|
module.SupportedModes = new[] { DFConstantsAndEnums.RecordingMode.CircularBuffer, DFConstantsAndEnums.RecordingMode.RecorderMode };
|
|
}
|
|
/// <summary>
|
|
/// there was originally code that was looking for B1H9 in the firmware version
|
|
/// speaking with loc this just needs to look for protocol version 8
|
|
/// </summary>
|
|
private const int MIN_VERSION_MULTIPLE_HYBRID_RECORDER_15 = 8;
|
|
/// <summary>
|
|
/// sets the recording modes for non TOM SLICE/SLICE2/SLICE6 variants
|
|
/// </summary>
|
|
/// <param name="module"></param>
|
|
/// <param name="dev"></param>
|
|
protected static void SetRecordingModes(InfoResult.Module module, ICommunication dev)
|
|
{
|
|
var modes = new List<DFConstantsAndEnums.RecordingMode>();
|
|
if (IsEDR(dev))
|
|
{
|
|
modes.AddRange(new[]{
|
|
DFConstantsAndEnums.RecordingMode.EthernetUDPRecordingCircularMode,
|
|
DFConstantsAndEnums.RecordingMode.EthernetUDPRecordingRecorderMode,
|
|
DFConstantsAndEnums.RecordingMode.MultiEthernetUDPRecordingCircularMode,
|
|
DFConstantsAndEnums.RecordingMode.MultiEthernetUDPRecordingRecorderMode,
|
|
DFConstantsAndEnums.RecordingMode.a26_MultiRecordOnBootDataMode,
|
|
});
|
|
}
|
|
else if (dev is EthernetSlice6AirThermocoupler || dev is WinUSBSlice6AirThermocoupler)
|
|
{
|
|
modes.AddRange(new[] { DFConstantsAndEnums.RecordingMode.S6A_DeviceStreamingOnly });
|
|
}
|
|
else
|
|
{
|
|
modes.AddRange(new[] {DFConstantsAndEnums.RecordingMode.CircularBuffer,
|
|
DFConstantsAndEnums.RecordingMode.RecorderMode});
|
|
// specified per DAS
|
|
if (dev.IsCommandSupported(DFConstantsAndEnums.ProtocolLimitedCommands.MultipleAndHybridEvents))
|
|
{
|
|
modes.AddRange(new[]{
|
|
DFConstantsAndEnums.RecordingMode.HybridRecorderMode,
|
|
DFConstantsAndEnums.RecordingMode.MultiHybridRecorderMode,
|
|
DFConstantsAndEnums.RecordingMode.ContinuousRecorderMode,
|
|
DFConstantsAndEnums.RecordingMode.AutoCircularBufferMode,
|
|
DFConstantsAndEnums.RecordingMode.AutoRecorderMode,
|
|
});
|
|
}
|
|
if (dev is EthernetSlice6Air || dev is WinUSBSlice6Air)
|
|
{
|
|
modes.AddRange(new[] {
|
|
DFConstantsAndEnums.RecordingMode.CircularBufferPlusUART,
|
|
DFConstantsAndEnums.RecordingMode.RecorderModePlusUART,
|
|
DFConstantsAndEnums.RecordingMode.S6A_DeviceStreamingOnly
|
|
});
|
|
}
|
|
if (dev.IsCommandSupported(DFConstantsAndEnums.ProtocolLimitedCommands.RecordAndStreamSubSample))
|
|
{
|
|
modes.AddRange(new[] { DFConstantsAndEnums.RecordingMode.a16_CircularBufferAndStreamSubSampleMode,
|
|
DFConstantsAndEnums.RecordingMode.a14_NormalRecorderAndStreamSubSampleMode
|
|
});
|
|
}
|
|
if (dev is EthernetSlice1_5 || dev is WinUSBSlice1_5)
|
|
{
|
|
//this previously looked for firmware version < B1H9, per Loc's suggestion
|
|
//this should just check protocol version instead
|
|
//usually this is done by setting min protocol version for the DAS in question
|
|
//but I'm making this explicit here to carry over the behavior of code I'm abstracting out from
|
|
if (dev.ProtocolVersion < MIN_VERSION_MULTIPLE_HYBRID_RECORDER_15)
|
|
{
|
|
modes.Remove(DFConstantsAndEnums.RecordingMode.MultiHybridRecorderMode);
|
|
}
|
|
}
|
|
if (dev.IsCommandSupported(DFConstantsAndEnums.ProtocolLimitedCommands.ActiveRAM))
|
|
{
|
|
modes.Add(DFConstantsAndEnums.RecordingMode.RAMActive);
|
|
modes.Add(DFConstantsAndEnums.RecordingMode.MultipleEventRAMActive);
|
|
}
|
|
}
|
|
module.SupportedModes = modes.ToArray();
|
|
}
|
|
/// <summary>
|
|
/// returns true if the device is an Ethernet Data Recorder (EDR)
|
|
/// </summary>
|
|
/// <param name="dev"></param>
|
|
/// <returns></returns>
|
|
private static bool IsEDR(ICommunication dev)
|
|
{
|
|
return (dev is EthernetSlice6Air S6A && S6A.IsEthernetRecorder) || (dev is WinUSBSlice6Air wS6A && wS6A.IsEthernetRecorder);
|
|
}
|
|
protected virtual void SetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name)
|
|
{
|
|
// shortcut
|
|
if (!(dev is IDASCommunication dasComm)) { return; }
|
|
try
|
|
{
|
|
if (dasComm.IsEthernetDistributor())
|
|
{
|
|
try
|
|
{
|
|
QueryProtocolVersionWrapper(dev, 2000);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.Log("Failed to query protocol version, retrying", ex);
|
|
System.Threading.Thread.Sleep(100);
|
|
try
|
|
{
|
|
QueryProtocolVersionWrapper(dev, AbstractCommandBase.Default_IO_Timeout);
|
|
}
|
|
catch
|
|
{
|
|
dev.ProtocolVersion = 1;
|
|
}
|
|
}
|
|
|
|
var qsn = new QuerySerialNumber(dev);
|
|
qsn.SyncExecute();
|
|
dev.SerialNumber = qsn.SerialNumber;
|
|
|
|
var qfv = new QueryFirmwareVersion(dev);
|
|
qfv.SyncExecute();
|
|
dev.FirmwareVersion = qfv.FirmwareVersion;
|
|
dev.DASInfo = new Communication_DASInfo();
|
|
dasComm.SetDASInfo(new InfoResult
|
|
{
|
|
MaxEventStorageSpaceInBytes = ulong.MaxValue,
|
|
MaxNumberOfModules = 0,
|
|
Modules = new[] { new InfoResult.Module() }
|
|
}, false);
|
|
dasComm.DASInfo.Modules[0].SerialNumber = qsn.SerialNumber;
|
|
|
|
dasComm.DASInfo.NumberOfBridgeChannels = 1;
|
|
dasComm.DASInfo.NumberOfBytesPerSampleClock = 1;
|
|
((InfoResult)dasComm.DASInfo).OwningDAS = dasComm;
|
|
//FB 16049 Read cal date for distributor
|
|
ReadCalDates(dev);
|
|
return;
|
|
}
|
|
// get the stack contents
|
|
var stackQuery = new QueryStackContents(dev);
|
|
stackQuery.SyncExecute();
|
|
|
|
try
|
|
{
|
|
if (dev.IsCommandSupported(DFConstantsAndEnums.ProtocolLimitedCommands.QueryMSP430Firmware))
|
|
{
|
|
var qfv = new QueryMSP430FirmwareVersion(dev);
|
|
qfv.SyncExecute();
|
|
}
|
|
}
|
|
catch (Exception ex) { APILogger.Log(ex); }
|
|
|
|
// serialnumbers and firmware versions
|
|
dev.FirmwareVersion = stackQuery.FirmwareVersion[0];
|
|
dasComm.SerialNumber = stackQuery.SerialNumber[0];
|
|
dev.DASInfo = new Communication_DASInfo(stackQuery.SerialNumber, stackQuery.FirmwareVersion);
|
|
|
|
// create and fill in InfoResult
|
|
var dasInfo = new InfoResult
|
|
{
|
|
MaxNumberOfModules = MaxNumberOfModules,
|
|
NumberOfBytesPerSampleClock = (uint)(6 * (stackQuery.SliceCount - 1)),
|
|
OwningDAS = dasComm,
|
|
Modules = new InfoResult.Module[stackQuery.SliceCount - 1],
|
|
};
|
|
|
|
// construct module info
|
|
for (var sliceIdx = 0; sliceIdx < stackQuery.SliceCount - 1; sliceIdx++)
|
|
{
|
|
var module = new InfoResult.Module
|
|
{
|
|
ModuleArrayIndex = sliceIdx,
|
|
OwningInfoResult = dasInfo,
|
|
MaxEventStorageSpaceInBytes = null,
|
|
NumberOfBytesPerSampleClock = null,
|
|
NumberOfChannels = 3,
|
|
SerialNumber = stackQuery.SerialNumber[sliceIdx + 1],
|
|
FirmwareVersion = stackQuery.FirmwareVersion[sliceIdx + 1]
|
|
};
|
|
|
|
SetRecordingModes(module, dev);
|
|
module.SupportedSampleRates = (uint[])SamplerateList.Clone(); // this should be adjusted to real-life
|
|
|
|
var moduleTypeByte = stackQuery.SliceType.ToArray()[sliceIdx + 1];
|
|
var moduleType = Convert.ToInt16(moduleTypeByte);
|
|
switch (moduleType)
|
|
{
|
|
case (short)ChannelTypes.BRIDGE:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceBridge;
|
|
break;
|
|
case (short)ChannelTypes.IEPE:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SLICEIEPE;
|
|
break;
|
|
default:
|
|
APILogger.Log("WARNING! unknown slice module type: " + moduleType);
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceBridge;
|
|
break;
|
|
}
|
|
|
|
module.SampleRate2AAFrequency = Samplerate2AAFilterDict;
|
|
dasInfo.Modules[sliceIdx] = module;
|
|
}
|
|
|
|
// attach the structure to the DAS
|
|
dasComm.SetDASInfo(dasInfo);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.LogString("SliceHandling.SetupDASInfo exception: " + name);
|
|
APILogger.LogException(ex);
|
|
|
|
// if we're not in util mode we bail out
|
|
if (!UtilityMode)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
// if we are, we must fill in something
|
|
// dev.FirmwareVersion
|
|
// DASComm.SerialNumber
|
|
// dev.DASInfo
|
|
// DASComm.DASInfo
|
|
dev.FirmwareVersion = "UNKNOWN";
|
|
dasComm.SerialNumber = "UNKNOWN";
|
|
dev.DASInfo = new Communication_DASInfo
|
|
{
|
|
SerialNumbers = new[] { dasComm.SerialNumber },
|
|
FirmwareVersions = new[] { dev.FirmwareVersion }
|
|
};
|
|
|
|
var dasInfo = new InfoResult
|
|
{
|
|
MaxNumberOfModules = MaxNumberOfModules,
|
|
NumberOfBytesPerSampleClock = 0,
|
|
MaxEventStorageSpaceInBytes = 0,
|
|
OwningDAS = dasComm,
|
|
Modules = new InfoResult.Module[0]
|
|
};
|
|
dasComm.SetDASInfo(dasInfo, false);
|
|
}
|
|
ReadCalDates(dev);
|
|
}
|
|
|
|
protected void ReadProtocolVersion(DTS.Common.Interface.DASFactory.ICommunication dev, string name)
|
|
{
|
|
try
|
|
{
|
|
// Need to bootstrap protocol version ...
|
|
dev.ProtocolVersion = 1;
|
|
|
|
if (dev is EthernetSliceDB)
|
|
{
|
|
//doesn't have protocol version yet
|
|
}
|
|
else
|
|
{
|
|
if (dev is EthernetSlice6 && RunTestVariables.InRunTest &&
|
|
RunTestVariables.AssumedProtocolVersionForSlice6InRunTest > 0)
|
|
{
|
|
dev.ProtocolVersion = RunTestVariables.AssumedProtocolVersionForSlice6InRunTest;
|
|
}
|
|
else if (dev is EthernetSlice6DB && RunTestVariables.InRunTest &&
|
|
RunTestVariables.Assumed_S6DB_ProtocolVersion >= 0)
|
|
{
|
|
dev.ProtocolVersion = RunTestVariables.Assumed_S6DB_ProtocolVersion;
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
QueryProtocolVersionWrapper(dev, 2000);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
System.Threading.Thread.Sleep(100);
|
|
APILogger.Log("Timeout querying protocol version, re-attempting incase is in realtime", ex);
|
|
QueryProtocolVersionWrapper(dev, AbstractCommandBase.Default_IO_Timeout);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (ex is System.Net.Sockets.SocketException
|
|
|| ex is CommandException)
|
|
{
|
|
APILogger.LogString($"{APILogger.GetCurrentMethod()} Connection:{name} Message:{ex.Message}");
|
|
}
|
|
else
|
|
{
|
|
APILogger.LogException(ex);
|
|
}
|
|
|
|
// if we're in util mode we stay with version 1
|
|
if (!UtilityMode)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected bool IsInUpdateMode(DTS.Common.Interface.DASFactory.ICommunication dev, string name)
|
|
{
|
|
try
|
|
{
|
|
if (dev is EthernetSliceDB) { return false; }
|
|
var inUpdateMode = new QueryInFirmwareUpdateMode(dev);
|
|
inUpdateMode.SyncExecute();
|
|
return inUpdateMode.InUpdateMode;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (ex is NotConnectedException)
|
|
{
|
|
APILogger.LogString($"{APILogger.GetCurrentMethod()} Connection:{name} Message:{ex.Message}");
|
|
}
|
|
else
|
|
{
|
|
APILogger.LogException(ex);
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
protected void QuerySystemAttributeSafe(AttributeTypes.SystemAttributes at, ICommunication com)
|
|
{
|
|
try
|
|
{
|
|
var qsa = new QuerySystemAttribute(com, AbstractCommandBase.Default_IO_Timeout)
|
|
{
|
|
Key = at
|
|
};
|
|
qsa.SyncExecute();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.Log("Failed to query ", at, com.SerialNumber, ex);
|
|
}
|
|
}
|
|
public virtual bool QueryInformation(ConnectedDevice dev)
|
|
{
|
|
// don't assume anything...
|
|
if (string.IsNullOrEmpty(dev?.Dev?.ConnectString))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed1");
|
|
return false;
|
|
}
|
|
if (!((dev.Dev as IConnectedDAS)?.DASComm is ICommunication) || !(((IConnectedDAS)dev.Dev).DASComm is IDASCommunication))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed2");
|
|
return false;
|
|
}
|
|
|
|
// make shortcuts
|
|
var commDev = (dev.Dev as IConnectedDAS).DASComm as ICommunication;
|
|
var devName = dev.Dev.ConnectString;
|
|
|
|
try
|
|
{
|
|
|
|
// First get protocol version ...
|
|
ReadProtocolVersion(commDev, devName);
|
|
|
|
// check how stack is configured
|
|
SetupDASInfo(commDev, devName);
|
|
|
|
if (((IConnectedDAS)dev.Dev).DASComm.IsEthernetDistributor()) { return true; }
|
|
// now pickup some stuff for the log
|
|
DummyRetriveGainCodes(commDev);
|
|
DummyRetreiveDasBootCount(commDev);
|
|
|
|
// get the stored events
|
|
// moved to query configuration in slice configuration service
|
|
if (commDev.IsCommandSupported(DFConstantsAndEnums.ProtocolLimitedCommands.FlashCardInfo))
|
|
{
|
|
QuerySystemAttributeSafe(AttributeTypes.SystemAttributes.OEMAppId, commDev);
|
|
QuerySystemAttributeSafe(AttributeTypes.SystemAttributes.ProductRev_A, commDev);
|
|
QuerySystemAttributeSafe(AttributeTypes.SystemAttributes.ProductRev_B, commDev);
|
|
QuerySystemAttributeSafe(AttributeTypes.SystemAttributes.ProductSN_A, commDev);
|
|
QuerySystemAttributeSafe(AttributeTypes.SystemAttributes.ProductSN_B, commDev);
|
|
QuerySystemAttributeSafe(AttributeTypes.SystemAttributes.ManufacturerId_A, commDev);
|
|
QuerySystemAttributeSafe(AttributeTypes.SystemAttributes.ManufacturerId_B, commDev);
|
|
}
|
|
|
|
try
|
|
{
|
|
if (dev.Dev is IConnectedDAS idas)
|
|
{
|
|
idas.DASComm?.ReadFirstUseDate();
|
|
}
|
|
}
|
|
catch (Exception ex) { APILogger.Log(ex); }
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
try
|
|
{
|
|
if (ex is System.Net.Sockets.SocketException
|
|
|| ex is CommandException)
|
|
{
|
|
APILogger.LogString($"{APILogger.GetCurrentMethod()} Connection:{devName} Message:{ex.Message}");
|
|
}
|
|
if (IsInUpdateMode(commDev, devName))
|
|
{
|
|
var dasInfo = new InfoResult
|
|
{
|
|
MaxNumberOfModules = 10,
|
|
Modules = new InfoResult.Module[0]
|
|
};
|
|
((IConnectedDAS)dev.Dev).DASComm.SetDASInfo(dasInfo);
|
|
dev.InUpdateMode = true;
|
|
return true;
|
|
}
|
|
APILogger.LogException(ex);
|
|
return false;
|
|
}
|
|
catch (Exception eex)
|
|
{
|
|
APILogger.LogString("DASFactory.QuerySliceInformation.EX exception: " + dev.Dev.ConnectString);
|
|
APILogger.LogException(eex);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
public abstract ICommunication GetICommunication();
|
|
|
|
public abstract ICommunication GetICommunication(ConnectedDevice dev);
|
|
|
|
public abstract IConnectedDevice GetIConnectedDevice(DTS.Common.Interface.DASFactory.ICommunication comm);
|
|
|
|
public abstract bool IsCorrectType(ConnectedDevice dev);
|
|
|
|
public abstract DFConstantsAndEnums.DASType GetDASType();
|
|
|
|
public abstract Guid GetGuid();
|
|
|
|
public virtual int GetProductId()
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
public virtual string GetProductIdString()
|
|
{
|
|
return string.Empty;
|
|
}
|
|
protected DeviceHandling _handler;
|
|
public void SetHandler(DeviceHandling handler)
|
|
{
|
|
_handler = handler;
|
|
}
|
|
}
|
|
|
|
internal class WinUSBSliceHandling : SliceHandling
|
|
{
|
|
private const string DTS_SLICE_WINUSB_GUID = "{f99ef36a-85f6-4042-9416-e05527c43a35}";
|
|
|
|
public WinUSBSliceHandling(bool utilMode)
|
|
: base(utilMode)
|
|
{
|
|
}
|
|
|
|
public override ICommunication GetICommunication()
|
|
{
|
|
return new WinUSBSlice();
|
|
}
|
|
|
|
public override ICommunication GetICommunication(ConnectedDevice dev)
|
|
{
|
|
return (dev.Dev as ConnectedWinUSBSlice)?.DASComm as ICommunication;
|
|
}
|
|
|
|
public override IConnectedDevice GetIConnectedDevice(DTS.Common.Interface.DASFactory.ICommunication comm)
|
|
{
|
|
return new ConnectedWinUSBSlice(comm as WinUSBSlice);
|
|
}
|
|
|
|
public override bool IsCorrectType(ConnectedDevice dev)
|
|
{
|
|
return dev.Dev is ConnectedWinUSBSlice;
|
|
}
|
|
|
|
public override DFConstantsAndEnums.DASType GetDASType()
|
|
{
|
|
return DFConstantsAndEnums.DASType.WINUSB_SLICE;
|
|
}
|
|
|
|
public override Guid GetGuid()
|
|
{
|
|
return new Guid(DTS_SLICE_WINUSB_GUID);
|
|
}
|
|
}
|
|
public class WinUSBSlice2Handling : SliceHandling
|
|
{
|
|
private const string DTS_SLICE2_WINUSB_GUID = "{fb10e3ff-ece3-410e-beeb-719096813fb9}";
|
|
|
|
public WinUSBSlice2Handling(bool utilMode)
|
|
: base(utilMode)
|
|
{
|
|
}
|
|
|
|
public override ICommunication GetICommunication()
|
|
{
|
|
return new CDCUSBSlice();
|
|
}
|
|
|
|
public override ICommunication GetICommunication(ConnectedDevice dev)
|
|
{
|
|
return (dev.Dev as ConnectedCDCUSBSlice)?.DASComm as ICommunication;
|
|
}
|
|
|
|
public override IConnectedDevice GetIConnectedDevice(DTS.Common.Interface.DASFactory.ICommunication comm)
|
|
{
|
|
return new ConnectedCDCUSBSlice(comm as CDCUSBSlice);
|
|
}
|
|
|
|
public override bool IsCorrectType(ConnectedDevice dev)
|
|
{
|
|
return dev.Dev is ConnectedCDCUSBSlice;
|
|
}
|
|
|
|
public override DFConstantsAndEnums.DASType GetDASType()
|
|
{
|
|
return DFConstantsAndEnums.DASType.CDCUSB_SLICE;
|
|
}
|
|
|
|
public override Guid GetGuid()
|
|
{
|
|
return new Guid(DTS_SLICE2_WINUSB_GUID);
|
|
}
|
|
|
|
|
|
public override bool QueryInformation(ConnectedDevice dev)
|
|
{
|
|
// don't assume anything...
|
|
if (string.IsNullOrEmpty(dev?.Dev?.ConnectString))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed1");
|
|
return false;
|
|
}
|
|
if (!((dev.Dev as IConnectedDAS)?.DASComm is ICommunication) || !(((IConnectedDAS)dev.Dev).DASComm is IDASCommunication))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed2");
|
|
return false;
|
|
}
|
|
|
|
// make shortcuts
|
|
var commDev = (dev.Dev as IConnectedDAS).DASComm as ICommunication;
|
|
var devName = dev.Dev.ConnectString;
|
|
|
|
try
|
|
{
|
|
|
|
// First get protocol version ...
|
|
ReadProtocolVersion(commDev, devName);
|
|
|
|
// check how stack is configured
|
|
SetupDASInfo(commDev, devName);
|
|
|
|
if (commDev is EthernetSliceDB) { return true; }
|
|
// now pickup some stuff for the log
|
|
|
|
try
|
|
{
|
|
if (dev.Dev is IConnectedDAS idas)
|
|
{
|
|
idas.DASComm?.ReadFirstUseDate();
|
|
}
|
|
}
|
|
catch (Exception ex) { APILogger.Log(ex); }
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
try
|
|
{
|
|
if (ex is System.Net.Sockets.SocketException
|
|
|| ex is CommandException)
|
|
{
|
|
APILogger.LogString($"{APILogger.GetCurrentMethod()} Connection:{devName} Message:{ex.Message}");
|
|
}
|
|
if (IsInUpdateMode(commDev, devName))
|
|
{
|
|
var dasInfo = new InfoResult
|
|
{
|
|
MaxNumberOfModules = 10,
|
|
Modules = new InfoResult.Module[0]
|
|
};
|
|
((IConnectedDAS)dev.Dev).DASComm.SetDASInfo(dasInfo, false);
|
|
dev.InUpdateMode = true;
|
|
return true;
|
|
}
|
|
|
|
APILogger.LogException(ex);
|
|
|
|
return false;
|
|
}
|
|
catch (Exception eex)
|
|
{
|
|
APILogger.LogString("DASFactory.QuerySliceInformation.EX exception: " + dev.Dev.ConnectString);
|
|
APILogger.LogException(eex);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
protected override void ReadCalDates(DTS.Common.Interface.DASFactory.ICommunication dev)
|
|
{
|
|
var dasComm = dev as IDASCommunication;
|
|
if (!RunTestVariables.QueryCalDateInRunTest && RunTestVariables.InRunTest)
|
|
{
|
|
dasComm.DASInfo.CalibrationDate = null;
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
if (dasComm.GetIsInArm() || dasComm.GetIsInRealtime())
|
|
{
|
|
dasComm.DASInfo.CalibrationDate = null;
|
|
foreach (var module in dasComm.DASInfo.Modules)
|
|
{
|
|
module.CalibrationDate = null;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var qsa2 = new QuerySystemAttributeSLICE2(dev)
|
|
{
|
|
Key = AttributeTypes.SystemAttributesSLICE2.CalibrationDaysSince1970_01_01
|
|
};
|
|
qsa2.SyncExecute();
|
|
|
|
var days = Convert.ToInt32(qsa2.Value);
|
|
dasComm.DASInfo.CalibrationDate = new DateTime(1970, 1, 1).AddDays(days);
|
|
|
|
foreach (var module in dasComm.DASInfo.Modules)
|
|
{
|
|
try
|
|
{
|
|
var qsaS2B = new QuerySystemAttribute_Slice2Bridge(dev)
|
|
{
|
|
Key = AttributeTypes.SystemAttributes_Bridge_SLICE2.CalibrationDaysSince1970_01_01,
|
|
DeviceID = Convert.ToByte(1 + module.ModuleArrayIndex)
|
|
};
|
|
qsaS2B.SyncExecute();
|
|
|
|
days = DataConditioning.GetIntegerIfPossible(qsaS2B.Value);
|
|
module.CalibrationDate = new DateTime(1970, 1, 1).AddDays(days);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.Log(ex);
|
|
module.CalibrationDate = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (!ex.Message.Contains("StatusAttributeNotRegistered"))
|
|
{
|
|
APILogger.Log(ex);
|
|
}
|
|
|
|
dasComm.DASInfo.CalibrationDate = null;
|
|
}
|
|
finally
|
|
{
|
|
dasComm.SetDASInfo();
|
|
}
|
|
}
|
|
protected override void SetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name)
|
|
{
|
|
ResetupDASInfo(dev, name, UtilityMode);
|
|
ReadCalDates(dev);
|
|
}
|
|
|
|
private static bool IsTOM(string serial)
|
|
{
|
|
return serial.StartsWith("SPT") || serial.StartsWith("SLT");
|
|
}
|
|
/// <summary>
|
|
/// checks if device is in bootloader mode and sends a PRISM event if device might be in BL mode
|
|
/// </summary>
|
|
public static void CheckInBootloaderMode(ICommunication dev)
|
|
{
|
|
try
|
|
{
|
|
var qats = new QueryArmAndTriggerStatus(dev);
|
|
qats.SyncExecute();
|
|
}
|
|
catch (CommandException ce)
|
|
{
|
|
if (ce.Error == CommandErrorReason.InvalidMode)
|
|
{
|
|
dev.ErrorInSetup = true;
|
|
SurfaceApplicationError(string.Format(StringResources.ErrorCommunicatingWithDevice, dev.SerialNumber));
|
|
}
|
|
APILogger.Log("Failed to query arm and trigger status", ce);
|
|
}
|
|
}
|
|
private static void SurfaceApplicationError(string msg)
|
|
{
|
|
try
|
|
{
|
|
PageErrorEvent.SurfaceApplicationError(msg);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.Log(ex);
|
|
}
|
|
}
|
|
public static void ResetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name, bool utilityMode)
|
|
{
|
|
// shortcut
|
|
var dasComm = dev as IDASCommunication;
|
|
if (dev.ProtocolVersion == 0) { dev.ProtocolVersion = 1; }
|
|
try
|
|
{
|
|
// get the stack contents
|
|
var stackQuery = new QueryStackContents(dev);
|
|
stackQuery.SyncExecute();
|
|
try
|
|
{
|
|
if (dev.IsCommandSupported(DFConstantsAndEnums.ProtocolLimitedCommands.QueryMSP430Firmware))
|
|
{
|
|
var msp = new QueryMSP430FirmwareVersion(dev);
|
|
msp.SyncExecute();
|
|
}
|
|
}
|
|
catch (Exception) { }
|
|
// serialnumbers and firmware versions
|
|
dev.FirmwareVersion = stackQuery.FirmwareVersion[0];
|
|
dasComm.SerialNumber = stackQuery.SerialNumber[0];
|
|
dev.DASInfo = new Communication_DASInfo(stackQuery.SerialNumber, stackQuery.FirmwareVersion);
|
|
|
|
CheckInBootloaderMode(dev);
|
|
|
|
// create and fill in InfoResult
|
|
var dasInfo = new InfoResult
|
|
{
|
|
MaxNumberOfModules = MaxNumberOfModules,
|
|
NumberOfBytesPerSampleClock = (uint)(6 * (stackQuery.SliceCount - 1)),
|
|
OwningDAS = dasComm
|
|
};
|
|
|
|
if (IsTOM(dasComm.SerialNumber))
|
|
{
|
|
dasInfo.Modules = new InfoResult.Module[1];
|
|
var module = new InfoResult.Module
|
|
{
|
|
ModuleArrayIndex = 0,
|
|
OwningInfoResult = dasInfo
|
|
};
|
|
module.OwningInfoResult = dasInfo;
|
|
module.MaxEventStorageSpaceInBytes = null; //specified at DAS level
|
|
module.NumberOfBytesPerSampleClock = null; //specified at DAS level
|
|
module.NumberOfChannels = 16;
|
|
module.SerialNumber = stackQuery.SerialNumber[1];
|
|
module.FirmwareVersion = stackQuery.FirmwareVersion[1];
|
|
SetRecordingModesTOM(module, dev);
|
|
module.SupportedSampleRates = (uint[])SamplerateList.Clone();
|
|
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SLICEPro_TOM;
|
|
module.IsProgrammable = false;
|
|
module.SampleRate2AAFrequency = Samplerate2AAFilterDict;
|
|
|
|
dasInfo.Modules[0] = module;
|
|
}
|
|
else
|
|
{
|
|
// construct module info
|
|
dasInfo.Modules = new InfoResult.Module[stackQuery.SliceCount - 1];
|
|
for (var sliceIdx = 0; sliceIdx < stackQuery.SliceCount - 1; sliceIdx++)
|
|
{
|
|
var module = new InfoResult.Module
|
|
{
|
|
ModuleArrayIndex = sliceIdx,
|
|
OwningInfoResult = dasInfo,
|
|
MaxEventStorageSpaceInBytes = null,
|
|
NumberOfBytesPerSampleClock = null,
|
|
NumberOfChannels = 3,
|
|
SerialNumber = stackQuery.SerialNumber[sliceIdx + 1],
|
|
FirmwareVersion = stackQuery.FirmwareVersion[sliceIdx + 1],
|
|
SupportedSampleRates = (uint[])SamplerateList.Clone()
|
|
};
|
|
|
|
SetRecordingModes(module, dev);
|
|
// specified per DAS
|
|
// this should be adjusted to real-life
|
|
|
|
var moduleTypeByte = stackQuery.SliceType.ToArray()[sliceIdx + 1];
|
|
var moduleType = Convert.ToInt16(moduleTypeByte);
|
|
module.IsProgrammable = false;
|
|
|
|
if (dev.IsCommandSupported(DFConstantsAndEnums.ProtocolLimitedCommands.HardwareConfiguration)
|
|
&& !(dasComm.GetIsInArm() || dasComm.GetIsInRealtime()))
|
|
{
|
|
try
|
|
{
|
|
var q = new QueryHardwareConfiguration(dev, 1 + sliceIdx);
|
|
q.SyncExecute();
|
|
switch (q.HardwareType)
|
|
{
|
|
case QueryHardwareConfiguration.Types.Bridge_Configurable:
|
|
case QueryHardwareConfiguration.Types.IEPE_Configurable:
|
|
case QueryHardwareConfiguration.Types.IEPE_Configurable_Low:
|
|
case QueryHardwareConfiguration.Types.Bridge_Configurable_Low:
|
|
module.IsProgrammable = true;
|
|
break;
|
|
case QueryHardwareConfiguration.Types.Bridge:
|
|
case QueryHardwareConfiguration.Types.IEPE:
|
|
module.IsProgrammable = false;
|
|
break;
|
|
}
|
|
}
|
|
catch (CommandException ce)
|
|
{
|
|
if (ce.Error == CommandErrorReason.InvalidMode)
|
|
{
|
|
dasComm.SetInRealtime(false, true);
|
|
}
|
|
APILogger.Log("Failed to query hardware configuration", ce);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.Log("failed to query hardware configuration", ex);
|
|
}
|
|
}
|
|
|
|
switch (moduleType)
|
|
{
|
|
case (short)ChannelTypes.EIPE2HIGH:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceIEPE2High;
|
|
break;
|
|
case (short)ChannelTypes.IEPE2LOW:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceIEPE2Low;
|
|
break;
|
|
case (short)ChannelTypes.BRIDGE2LOW:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceBridge2Low;
|
|
break;
|
|
case (short)ChannelTypes.BRIDGE2HIGH:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceBridge2High;
|
|
break;
|
|
case (short)ChannelTypes.DIM:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.ProDIM;
|
|
break;
|
|
case (short)ChannelTypes.TOM:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SLICEPro_TOM;
|
|
break;
|
|
default:
|
|
APILogger.Log("WARNING! unknown slice module type: " + moduleType);
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceBridge;
|
|
break;
|
|
}
|
|
|
|
module.SampleRate2AAFrequency = Samplerate2AAFilterDict;
|
|
dasInfo.Modules[sliceIdx] = module;
|
|
}
|
|
}
|
|
// attach the structure to the DAS
|
|
dasComm.SetDASInfo(dasInfo);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.LogString("SliceHandling.SetupDASInfo exception: " + name);
|
|
APILogger.LogException(ex);
|
|
|
|
// if we're not in util mode we bail out
|
|
if (!utilityMode)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
// if we are, we must fill in something
|
|
dev.FirmwareVersion = "UNKNOWN";
|
|
dasComm.SerialNumber = "UNKNOWN";
|
|
dev.DASInfo = new Communication_DASInfo
|
|
{
|
|
SerialNumbers = new[] { dasComm.SerialNumber },
|
|
FirmwareVersions = new[] { dev.FirmwareVersion }
|
|
};
|
|
|
|
var dasInfo = new InfoResult
|
|
{
|
|
MaxNumberOfModules = MaxNumberOfModules,
|
|
NumberOfBytesPerSampleClock = 0,
|
|
MaxEventStorageSpaceInBytes = 0,
|
|
OwningDAS = dasComm,
|
|
Modules = new InfoResult.Module[0]
|
|
};
|
|
dasComm.SetDASInfo(dasInfo, false);
|
|
}
|
|
}
|
|
}
|
|
public class WinUSBSlice6Handling : SliceHandling
|
|
{
|
|
private const string DTS_SLICE6_WINUSB_GUID = "{d80bb9a9-2879-4d40-af1c-DONTUSE956e4}";
|
|
|
|
public WinUSBSlice6Handling(bool _utilMode)
|
|
: base(_utilMode)
|
|
{
|
|
}
|
|
|
|
public override ICommunication GetICommunication()
|
|
{
|
|
return new WinUSBSlice6();
|
|
}
|
|
|
|
public override ICommunication GetICommunication(ConnectedDevice dev)
|
|
{
|
|
return (dev.Dev as ConnectedWinUSBSlice6).DASComm as ICommunication;
|
|
}
|
|
|
|
public override IConnectedDevice GetIConnectedDevice(DTS.Common.Interface.DASFactory.ICommunication comm)
|
|
{
|
|
return new ConnectedWinUSBSlice6(comm as WinUSBSlice6);
|
|
}
|
|
|
|
public override bool IsCorrectType(ConnectedDevice dev)
|
|
{
|
|
return dev.Dev is ConnectedWinUSBSlice6;
|
|
}
|
|
|
|
public override DFConstantsAndEnums.DASType GetDASType()
|
|
{
|
|
return DFConstantsAndEnums.DASType.WINUSB_SLICE6;
|
|
}
|
|
|
|
public override Guid GetGuid()
|
|
{
|
|
return new Guid(DTS_SLICE6_WINUSB_GUID);
|
|
}
|
|
|
|
public override bool QueryInformation(ConnectedDevice dev)
|
|
{
|
|
// don't assume anything...
|
|
if (dev == null || dev.Dev == null || string.IsNullOrEmpty(dev.Dev.ConnectString))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed1");
|
|
return false;
|
|
}
|
|
if (!(dev.Dev is IConnectedDAS) || !((dev.Dev as IConnectedDAS).DASComm is ICommunication) ||
|
|
!((dev.Dev as IConnectedDAS).DASComm is IDASCommunication))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed2");
|
|
return false;
|
|
}
|
|
|
|
// make shortcuts
|
|
var CommDev = (dev.Dev as IConnectedDAS).DASComm as ICommunication;
|
|
var DevName = dev.Dev.ConnectString;
|
|
|
|
|
|
|
|
try
|
|
{
|
|
|
|
// First get protocol version ...
|
|
ReadProtocolVersion(CommDev, DevName);
|
|
|
|
// check how stack is configured
|
|
SetupDASInfo(CommDev, DevName);
|
|
|
|
if ((dev.Dev as IConnectedDAS).DASComm.IsEthernetDistributor()) { return true; }
|
|
// now pickup some stuff for the log
|
|
|
|
try
|
|
{
|
|
if (dev.Dev is IConnectedDAS idas)
|
|
{
|
|
idas.DASComm?.ReadFirstUseDate();
|
|
}
|
|
}
|
|
catch (Exception ex) { APILogger.Log(ex); }
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
try
|
|
{
|
|
if (ex is System.Net.Sockets.SocketException)
|
|
{
|
|
APILogger.LogString(string.Format("{0} Connection:{1} Message:{2}", APILogger.GetCurrentMethod(), DevName, ex.Message));
|
|
}
|
|
else
|
|
{
|
|
APILogger.LogException(ex);
|
|
}
|
|
|
|
if (IsInUpdateMode(CommDev, DevName))
|
|
{
|
|
var dasInfo = new InfoResult();
|
|
dasInfo.MaxNumberOfModules = 10;
|
|
dasInfo.Modules = new InfoResult.Module[0];
|
|
(dev.Dev as IConnectedDAS).DASComm.SetDASInfo(dasInfo, false);
|
|
dev.InUpdateMode = true;
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
catch (Exception eex)
|
|
{
|
|
APILogger.LogString("DASFactory.QuerySliceInformation.EX exception: " + dev.Dev.ConnectString);
|
|
APILogger.LogException(eex);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
protected override void SetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name)
|
|
{
|
|
ResetupDASInfo(dev, name, UtilityMode);
|
|
ReadCalDates(dev);
|
|
}
|
|
|
|
public static void ResetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name, bool UtilityMode)
|
|
{
|
|
// shortcut
|
|
var DASComm = dev as IDASCommunication;
|
|
|
|
try
|
|
{
|
|
// get the stack contents
|
|
var StackQuery = new QueryStackContents(dev);
|
|
StackQuery.SyncExecute();
|
|
// serialnumbers and firmware versions
|
|
dev.FirmwareVersion = StackQuery.FirmwareVersion[0];
|
|
DASComm.SerialNumber = StackQuery.SerialNumber[0];
|
|
|
|
WinUSBSlice2Handling.CheckInBootloaderMode(dev);
|
|
|
|
dev.DASInfo = new Communication_DASInfo(StackQuery.SerialNumber, StackQuery.FirmwareVersion);
|
|
|
|
// create and fill in InfoResult
|
|
var dasInfo = new InfoResult();
|
|
dasInfo.MaxNumberOfModules = MaxNumberOfModules;
|
|
dasInfo.NumberOfBytesPerSampleClock = (uint)(6 * (StackQuery.SliceCount - 1));
|
|
dasInfo.OwningDAS = DASComm;
|
|
|
|
// construct module info
|
|
dasInfo.Modules = new InfoResult.Module[StackQuery.SliceCount - 1];
|
|
for (var sliceIdx = 0; sliceIdx < StackQuery.SliceCount - 1; sliceIdx++)
|
|
{
|
|
var module = new InfoResult.Module();
|
|
module.ModuleArrayIndex = sliceIdx;
|
|
module.OwningInfoResult = dasInfo;
|
|
|
|
module.MaxEventStorageSpaceInBytes = null; // specified per DAS
|
|
module.NumberOfBytesPerSampleClock = null; // specified per DAS
|
|
module.NumberOfChannels = 3;
|
|
module.SerialNumber = StackQuery.SerialNumber[sliceIdx + 1];
|
|
module.FirmwareVersion = StackQuery.FirmwareVersion[sliceIdx + 1];
|
|
|
|
|
|
SetRecordingModes(module, dev);
|
|
module.SupportedSampleRates = (uint[])SamplerateList.Clone(); // this should be adjusted to real-life
|
|
|
|
var moduleTypeByte = StackQuery.SliceType.ToArray()[sliceIdx + 1];
|
|
var moduleType = Convert.ToInt16(moduleTypeByte);
|
|
module.IsProgrammable = false;
|
|
|
|
|
|
switch (moduleType)
|
|
{
|
|
case (short)ChannelTypes.BRIDGE:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceBridge;
|
|
break;
|
|
case (short)ChannelTypes.IEPE:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SLICEIEPE;
|
|
break;
|
|
default:
|
|
APILogger.Log("WARNING! unknown slice module type: " + moduleType);
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceBridge;
|
|
break;
|
|
}
|
|
|
|
module.SampleRate2AAFrequency = Samplerate2AAFilterDict;
|
|
dasInfo.Modules[sliceIdx] = module;
|
|
}
|
|
|
|
// attach the structure to the DAS
|
|
DASComm.SetDASInfo(dasInfo);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.LogString("SliceHandling.SetupDASInfo exception: " + name);
|
|
APILogger.LogException(ex);
|
|
|
|
// if we're not in util mode we bail out
|
|
if (!UtilityMode)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
// if we are, we must fill in something
|
|
// dev.FirmwareVersion
|
|
// DASComm.SerialNumber
|
|
// dev.DASInfo
|
|
// DASComm.DASInfo
|
|
dev.FirmwareVersion = "UNKNOWN";
|
|
DASComm.SerialNumber = "UNKNOWN";
|
|
dev.DASInfo = new Communication_DASInfo();
|
|
dev.DASInfo.SerialNumbers = new string[1] { DASComm.SerialNumber };
|
|
dev.DASInfo.FirmwareVersions = new string[1] { dev.FirmwareVersion };
|
|
|
|
var dasInfo = new InfoResult();
|
|
dasInfo.MaxNumberOfModules = MaxNumberOfModules;
|
|
dasInfo.NumberOfBytesPerSampleClock = 0;
|
|
dasInfo.MaxEventStorageSpaceInBytes = 0;
|
|
dasInfo.OwningDAS = DASComm;
|
|
dasInfo.Modules = new InfoResult.Module[0];
|
|
DASComm.SetDASInfo(dasInfo, false);
|
|
}
|
|
}
|
|
}
|
|
public class WinUSBSlice6AirHandling : SliceHandling
|
|
{
|
|
private const string DTS_SLICE6AIR_WINUSB_GUID = "{d80bb9a9-2879-4d40-af1c-DONTUSE956e4}";
|
|
|
|
public WinUSBSlice6AirHandling(bool _utilMode)
|
|
: base(_utilMode)
|
|
{
|
|
}
|
|
|
|
public override ICommunication GetICommunication()
|
|
{
|
|
return new WinUSBSlice6Air();
|
|
}
|
|
|
|
public override ICommunication GetICommunication(ConnectedDevice dev)
|
|
{
|
|
return (dev.Dev as ConnectedWinUSBSlice6Air).DASComm as ICommunication;
|
|
}
|
|
|
|
public override IConnectedDevice GetIConnectedDevice(DTS.Common.Interface.DASFactory.ICommunication comm)
|
|
{
|
|
return new ConnectedWinUSBSlice6Air(comm as WinUSBSlice6Air);
|
|
}
|
|
|
|
public override bool IsCorrectType(ConnectedDevice dev)
|
|
{
|
|
return dev.Dev is ConnectedWinUSBSlice6Air;
|
|
}
|
|
|
|
public override DFConstantsAndEnums.DASType GetDASType()
|
|
{
|
|
return DFConstantsAndEnums.DASType.WINUSB_SLICE6AIR;
|
|
}
|
|
|
|
public override Guid GetGuid()
|
|
{
|
|
return new Guid(DTS_SLICE6AIR_WINUSB_GUID);
|
|
}
|
|
|
|
public override bool QueryInformation(ConnectedDevice dev)
|
|
{
|
|
// don't assume anything...
|
|
if (dev == null || dev.Dev == null || string.IsNullOrEmpty(dev.Dev.ConnectString))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed1");
|
|
return false;
|
|
}
|
|
if (!(dev.Dev is IConnectedDAS) || !((dev.Dev as IConnectedDAS).DASComm is ICommunication) ||
|
|
!((dev.Dev as IConnectedDAS).DASComm is IDASCommunication))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed2");
|
|
return false;
|
|
}
|
|
|
|
// make shortcuts
|
|
var CommDev = (dev.Dev as IConnectedDAS).DASComm as ICommunication;
|
|
var DevName = dev.Dev.ConnectString;
|
|
|
|
|
|
|
|
try
|
|
{
|
|
|
|
// First get protocol version ...
|
|
ReadProtocolVersion(CommDev, DevName);
|
|
|
|
// check how stack is configured
|
|
SetupDASInfo(CommDev, DevName);
|
|
|
|
if ((dev.Dev as IConnectedDAS).DASComm.IsEthernetDistributor()) { return true; }
|
|
// now pickup some stuff for the log
|
|
|
|
try
|
|
{
|
|
if (dev.Dev is IConnectedDAS idas)
|
|
{
|
|
idas.DASComm?.ReadFirstUseDate();
|
|
}
|
|
}
|
|
catch (Exception ex) { APILogger.Log(ex); }
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
try
|
|
{
|
|
if (ex is System.Net.Sockets.SocketException)
|
|
{
|
|
APILogger.LogString(string.Format("{0} Connection:{1} Message:{2}", APILogger.GetCurrentMethod(), DevName, ex.Message));
|
|
}
|
|
else
|
|
{
|
|
APILogger.LogException(ex);
|
|
}
|
|
|
|
if (IsInUpdateMode(CommDev, DevName))
|
|
{
|
|
var dasInfo = new InfoResult();
|
|
dasInfo.MaxNumberOfModules = 10;
|
|
dasInfo.Modules = new InfoResult.Module[0];
|
|
(dev.Dev as IConnectedDAS).DASComm.SetDASInfo(dasInfo, false);
|
|
dev.InUpdateMode = true;
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
catch (Exception eex)
|
|
{
|
|
APILogger.LogString("DASFactory.QuerySliceInformation.EX exception: " + dev.Dev.ConnectString);
|
|
APILogger.LogException(eex);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
protected override void SetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name)
|
|
{
|
|
ResetupDASInfo(dev, name, UtilityMode);
|
|
ReadCalDates(dev);
|
|
}
|
|
|
|
public static void ResetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name, bool UtilityMode)
|
|
{
|
|
// shortcut
|
|
var DASComm = dev as IDASCommunication;
|
|
|
|
try
|
|
{
|
|
// get the stack contents
|
|
var StackQuery = new QueryStackContents(dev);
|
|
StackQuery.SyncExecute();
|
|
// serialnumbers and firmware versions
|
|
dev.FirmwareVersion = StackQuery.FirmwareVersion[0];
|
|
DASComm.SerialNumber = StackQuery.SerialNumber[0];
|
|
|
|
WinUSBSlice2Handling.CheckInBootloaderMode(dev);
|
|
|
|
dev.DASInfo = new Communication_DASInfo(StackQuery.SerialNumber, StackQuery.FirmwareVersion);
|
|
|
|
// create and fill in InfoResult
|
|
var dasInfo = new InfoResult();
|
|
dasInfo.MaxNumberOfModules = MaxNumberOfModules;
|
|
dasInfo.NumberOfBytesPerSampleClock = (uint)(6 * (StackQuery.SliceCount - 1));
|
|
dasInfo.OwningDAS = DASComm;
|
|
|
|
// construct module info
|
|
dasInfo.Modules = new InfoResult.Module[StackQuery.SliceCount - 1];
|
|
for (var sliceIdx = 0; sliceIdx < StackQuery.SliceCount - 1; sliceIdx++)
|
|
{
|
|
var module = new InfoResult.Module();
|
|
module.ModuleArrayIndex = sliceIdx;
|
|
module.OwningInfoResult = dasInfo;
|
|
|
|
module.MaxEventStorageSpaceInBytes = null; // specified per DAS
|
|
module.NumberOfBytesPerSampleClock = null; // specified per DAS
|
|
module.NumberOfChannels = 3;
|
|
module.SerialNumber = StackQuery.SerialNumber[sliceIdx + 1];
|
|
module.FirmwareVersion = StackQuery.FirmwareVersion[sliceIdx + 1];
|
|
|
|
SetRecordingModes(module, dev);
|
|
|
|
module.SupportedSampleRates = (uint[])SamplerateList.Clone(); // this should be adjusted to real-life
|
|
|
|
var moduleTypeByte = StackQuery.SliceType.ToArray()[sliceIdx + 1];
|
|
var moduleType = Convert.ToInt16(moduleTypeByte);
|
|
module.IsProgrammable = false;
|
|
|
|
|
|
switch (moduleType)
|
|
{
|
|
case (short)ChannelTypes.BRIDGE:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceBridge;
|
|
break;
|
|
case (short)ChannelTypes.IEPE:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SLICEIEPE;
|
|
break;
|
|
default:
|
|
APILogger.Log("WARNING! unknown slice module type: " + moduleType);
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceBridge;
|
|
break;
|
|
}
|
|
|
|
module.SampleRate2AAFrequency = Samplerate2AAFilterDict;
|
|
dasInfo.Modules[sliceIdx] = module;
|
|
}
|
|
|
|
// attach the structure to the DAS
|
|
DASComm.SetDASInfo(dasInfo);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.LogString("SliceHandling.SetupDASInfo exception: " + name);
|
|
APILogger.LogException(ex);
|
|
|
|
// if we're not in util mode we bail out
|
|
if (!UtilityMode)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
// if we are, we must fill in something
|
|
// dev.FirmwareVersion
|
|
// DASComm.SerialNumber
|
|
// dev.DASInfo
|
|
// DASComm.DASInfo
|
|
dev.FirmwareVersion = "UNKNOWN";
|
|
DASComm.SerialNumber = "UNKNOWN";
|
|
dev.DASInfo = new Communication_DASInfo();
|
|
dev.DASInfo.SerialNumbers = new string[1] { DASComm.SerialNumber };
|
|
dev.DASInfo.FirmwareVersions = new string[1] { dev.FirmwareVersion };
|
|
|
|
var dasInfo = new InfoResult();
|
|
dasInfo.MaxNumberOfModules = MaxNumberOfModules;
|
|
dasInfo.NumberOfBytesPerSampleClock = 0;
|
|
dasInfo.MaxEventStorageSpaceInBytes = 0;
|
|
dasInfo.OwningDAS = DASComm;
|
|
dasInfo.Modules = new InfoResult.Module[0];
|
|
DASComm.SetDASInfo(dasInfo, false);
|
|
}
|
|
}
|
|
}
|
|
public class WinUSBSlice6AirBridgeHandling : SliceHandling
|
|
{
|
|
private const string DTS_SLICE6_AIR_BR_WINUSB_GUID = "{d80bb9a9-2879-4d40-af1c-DONTUSE956e4}";
|
|
|
|
public WinUSBSlice6AirBridgeHandling(bool _utilMode)
|
|
: base(_utilMode)
|
|
{
|
|
}
|
|
|
|
public override ICommunication GetICommunication()
|
|
{
|
|
return new WinUSBSlice6();
|
|
}
|
|
|
|
public override ICommunication GetICommunication(ConnectedDevice dev)
|
|
{
|
|
return (dev.Dev as ConnectedWinUSBSlice6AirBridge).DASComm as ICommunication;
|
|
}
|
|
|
|
public override IConnectedDevice GetIConnectedDevice(DTS.Common.Interface.DASFactory.ICommunication comm)
|
|
{
|
|
return new ConnectedWinUSBSlice6AirBridge(comm as WinUSBSlice6AirBridge);
|
|
}
|
|
|
|
public override bool IsCorrectType(ConnectedDevice dev)
|
|
{
|
|
return dev.Dev is ConnectedWinUSBSlice6AirBridge;
|
|
}
|
|
|
|
public override DFConstantsAndEnums.DASType GetDASType()
|
|
{
|
|
return DFConstantsAndEnums.DASType.WINUSB_SLICE6AIR_BR;
|
|
}
|
|
|
|
public override Guid GetGuid()
|
|
{
|
|
return new Guid(DTS_SLICE6_AIR_BR_WINUSB_GUID);
|
|
}
|
|
|
|
public override bool QueryInformation(ConnectedDevice dev)
|
|
{
|
|
// don't assume anything...
|
|
if (dev == null || dev.Dev == null || string.IsNullOrEmpty(dev.Dev.ConnectString))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed1");
|
|
return false;
|
|
}
|
|
if (!(dev.Dev is IConnectedDAS) || !((dev.Dev as IConnectedDAS).DASComm is ICommunication) ||
|
|
!((dev.Dev as IConnectedDAS).DASComm is IDASCommunication))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed2");
|
|
return false;
|
|
}
|
|
|
|
// make shortcuts
|
|
var CommDev = (dev.Dev as IConnectedDAS).DASComm as ICommunication;
|
|
var DevName = dev.Dev.ConnectString;
|
|
|
|
|
|
|
|
try
|
|
{
|
|
|
|
// First get protocol version ...
|
|
ReadProtocolVersion(CommDev, DevName);
|
|
|
|
// check how stack is configured
|
|
SetupDASInfo(CommDev, DevName);
|
|
|
|
if ((dev.Dev as IConnectedDAS).DASComm.IsEthernetDistributor()) { return true; }
|
|
// now pickup some stuff for the log
|
|
|
|
try
|
|
{
|
|
if (dev.Dev is IConnectedDAS idas)
|
|
{
|
|
idas.DASComm?.ReadFirstUseDate();
|
|
}
|
|
}
|
|
catch (Exception ex) { APILogger.Log(ex); }
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
try
|
|
{
|
|
if (ex is System.Net.Sockets.SocketException)
|
|
{
|
|
APILogger.LogString(string.Format("{0} Connection:{1} Message:{2}", APILogger.GetCurrentMethod(), DevName, ex.Message));
|
|
}
|
|
else
|
|
{
|
|
APILogger.LogException(ex);
|
|
}
|
|
|
|
if (IsInUpdateMode(CommDev, DevName))
|
|
{
|
|
var dasInfo = new InfoResult();
|
|
dasInfo.MaxNumberOfModules = 10;
|
|
dasInfo.Modules = new InfoResult.Module[0];
|
|
(dev.Dev as IConnectedDAS).DASComm.SetDASInfo(dasInfo, false);
|
|
dev.InUpdateMode = true;
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
catch (Exception eex)
|
|
{
|
|
APILogger.LogString("DASFactory.QuerySliceInformation.EX exception: " + dev.Dev.ConnectString);
|
|
APILogger.LogException(eex);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
protected override void SetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name)
|
|
{
|
|
ResetupDASInfo(dev, name, UtilityMode);
|
|
ReadCalDates(dev);
|
|
}
|
|
|
|
public static void ResetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name, bool UtilityMode)
|
|
{
|
|
// shortcut
|
|
var DASComm = dev as IDASCommunication;
|
|
|
|
try
|
|
{
|
|
// get the stack contents
|
|
var StackQuery = new QueryStackContents(dev);
|
|
StackQuery.SyncExecute();
|
|
|
|
// serialnumbers and firmware versions
|
|
dev.FirmwareVersion = StackQuery.FirmwareVersion[0];
|
|
DASComm.SerialNumber = StackQuery.SerialNumber[0];
|
|
|
|
WinUSBSlice2Handling.CheckInBootloaderMode(dev);
|
|
|
|
dev.DASInfo = new Communication_DASInfo(StackQuery.SerialNumber, StackQuery.FirmwareVersion);
|
|
|
|
var streamOutCount = 1;
|
|
|
|
// create and fill in InfoResult
|
|
var dasInfo = new InfoResult();
|
|
dasInfo.MaxNumberOfModules = MaxNumberOfModules;
|
|
dasInfo.NumberOfBytesPerSampleClock = (uint)(6 * (StackQuery.SliceCount - 1));
|
|
dasInfo.OwningDAS = DASComm;
|
|
|
|
// construct module info
|
|
dasInfo.Modules = new InfoResult.Module[StackQuery.SliceCount + streamOutCount - 1];
|
|
for (var sliceIdx = 0; sliceIdx < StackQuery.SliceCount - 1; sliceIdx++)
|
|
{
|
|
var module = new InfoResult.Module();
|
|
module.ModuleArrayIndex = sliceIdx;
|
|
module.OwningInfoResult = dasInfo;
|
|
|
|
module.MaxEventStorageSpaceInBytes = null; // specified per DAS
|
|
module.NumberOfBytesPerSampleClock = null; // specified per DAS
|
|
module.NumberOfChannels = 3;
|
|
module.SerialNumber = StackQuery.SerialNumber[sliceIdx + 1];
|
|
module.FirmwareVersion = StackQuery.FirmwareVersion[sliceIdx + 1];
|
|
|
|
SetRecordingModes(module, dev);
|
|
module.SupportedSampleRates = (uint[])SamplerateList.Clone(); // this should be adjusted to real-life
|
|
|
|
var moduleTypeByte = StackQuery.SliceType.ToArray()[sliceIdx + 1];
|
|
var moduleType = Convert.ToInt16(moduleTypeByte);
|
|
module.IsProgrammable = false;
|
|
|
|
|
|
switch (moduleType)
|
|
{
|
|
case (short)ChannelTypes.BRIDGE:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceBridge;
|
|
break;
|
|
case (short)ChannelTypes.IEPE:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SLICEIEPE;
|
|
break;
|
|
default:
|
|
APILogger.Log("WARNING! unknown slice module type: " + moduleType);
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceBridge;
|
|
break;
|
|
}
|
|
|
|
module.SampleRate2AAFrequency = Samplerate2AAFilterDict;
|
|
dasInfo.Modules[sliceIdx] = module;
|
|
}
|
|
|
|
//then add streamout
|
|
for (var sliceIdx = 0; sliceIdx < streamOutCount; sliceIdx++)
|
|
{
|
|
var streamOutModule = new InfoResult.Module
|
|
{
|
|
ModuleArrayIndex = StackQuery.SliceCount - 1 + sliceIdx,
|
|
OwningInfoResult = dasInfo,
|
|
MaxEventStorageSpaceInBytes = null,
|
|
NumberOfBytesPerSampleClock = null,
|
|
NumberOfChannels = 1,
|
|
SerialNumber = $"{StackQuery.SerialNumber[0].Substring(0, 3)}-StreamOut{sliceIdx + 1}",
|
|
FirmwareVersion = StackQuery.FirmwareVersion[0],
|
|
SupportedModes = new DFConstantsAndEnums.RecordingMode[0],
|
|
SupportedSampleRates = new uint[0],
|
|
IsProgrammable = false,
|
|
TypeOfModule = DFConstantsAndEnums.ModuleType.StreamOut
|
|
};
|
|
dasInfo.Modules[StackQuery.SliceCount - 1 + sliceIdx] = streamOutModule;
|
|
}
|
|
|
|
// attach the structure to the DAS
|
|
DASComm.SetDASInfo(dasInfo);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.LogString("SliceHandling.SetupDASInfo exception: " + name);
|
|
APILogger.LogException(ex);
|
|
|
|
// if we're not in util mode we bail out
|
|
if (!UtilityMode)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
// if we are, we must fill in something
|
|
// dev.FirmwareVersion
|
|
// DASComm.SerialNumber
|
|
// dev.DASInfo
|
|
// DASComm.DASInfo
|
|
dev.FirmwareVersion = "UNKNOWN";
|
|
DASComm.SerialNumber = "UNKNOWN";
|
|
dev.DASInfo = new Communication_DASInfo();
|
|
dev.DASInfo.SerialNumbers = new string[1] { DASComm.SerialNumber };
|
|
dev.DASInfo.FirmwareVersions = new string[1] { dev.FirmwareVersion };
|
|
|
|
var dasInfo = new InfoResult();
|
|
dasInfo.MaxNumberOfModules = MaxNumberOfModules;
|
|
dasInfo.NumberOfBytesPerSampleClock = 0;
|
|
dasInfo.MaxEventStorageSpaceInBytes = 0;
|
|
dasInfo.OwningDAS = DASComm;
|
|
dasInfo.Modules = new InfoResult.Module[0];
|
|
DASComm.SetDASInfo(dasInfo, false);
|
|
}
|
|
}
|
|
}
|
|
|
|
public class WinUSBTsrAirHandling : SliceHandling
|
|
{
|
|
private const string DTS_TSR_AIR_WINUSB_GUID = "{ce2ed31a-2b65-4bae-826b-caf5e3120649}";
|
|
protected static readonly uint[] LowGAccelSamplerateList = { 1, 2, 3, 6, 13, 25, 50, 100, 200, 400, 800, 1600, 3200, 6400 };
|
|
protected static readonly uint[] HighGAccelSamplerateList = { 320, 6400, 1280, 2560, 5120 };
|
|
protected static readonly uint[] AngAccelSamplerateList = { 5120 };
|
|
protected static readonly uint[] AngRateSamplerateList = { 1, 2, 3, 6, 13, 25, 50, 100, 200, 400, 800, 1600 };
|
|
protected static readonly uint[] AtmSamplerateList = { 1, 10, 20, 100, 1000 };
|
|
protected static readonly uint[] LightSamplerateList = { 1, 10 };
|
|
protected static readonly uint[] MagSamplerateList = { 1, 10, 20, 100, 1000 };
|
|
protected static readonly uint[] MagInSamplerateList = { 1, 2, 3, 6, 13, 25, 50, 100, 200, 400, 800, 1600 };
|
|
protected static readonly uint[] MicSamplerateList = { 1, 2, 3, 6, 13, 25, 50, 100, 200, 400, 800, 1600 };
|
|
|
|
public WinUSBTsrAirHandling(bool _utilMode)
|
|
: base(_utilMode)
|
|
{
|
|
}
|
|
|
|
public override ICommunication GetICommunication()
|
|
{
|
|
return new WinUSBTsrAir();
|
|
}
|
|
|
|
public override ICommunication GetICommunication(ConnectedDevice dev)
|
|
{
|
|
return (dev.Dev as ConnectedWinUSBTsrAir).DASComm as ICommunication;
|
|
}
|
|
|
|
public override IConnectedDevice GetIConnectedDevice(DTS.Common.Interface.DASFactory.ICommunication comm)
|
|
{
|
|
return new ConnectedWinUSBTsrAir(comm as WinUSBTsrAir);
|
|
}
|
|
|
|
public override bool IsCorrectType(ConnectedDevice dev)
|
|
{
|
|
return dev.Dev is ConnectedWinUSBTsrAir;
|
|
}
|
|
|
|
public override DFConstantsAndEnums.DASType GetDASType()
|
|
{
|
|
return DFConstantsAndEnums.DASType.WINUSB_TSR_AIR;
|
|
}
|
|
|
|
public override Guid GetGuid()
|
|
{
|
|
return new Guid(DTS_TSR_AIR_WINUSB_GUID);
|
|
}
|
|
|
|
public override bool QueryInformation(ConnectedDevice dev)
|
|
{
|
|
// don't assume anything...
|
|
if (dev == null || dev.Dev == null || string.IsNullOrEmpty(dev.Dev.ConnectString))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed1");
|
|
return false;
|
|
}
|
|
if (!(dev.Dev is IConnectedDAS) || !((dev.Dev as IConnectedDAS).DASComm is ICommunication) ||
|
|
!((dev.Dev as IConnectedDAS).DASComm is IDASCommunication))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed2");
|
|
return false;
|
|
}
|
|
|
|
// make shortcuts
|
|
var CommDev = (dev.Dev as IConnectedDAS).DASComm as ICommunication;
|
|
var DevName = dev.Dev.ConnectString;
|
|
|
|
try
|
|
{
|
|
|
|
// First get protocol version ...
|
|
ReadProtocolVersion(CommDev, DevName);
|
|
|
|
// check how stack is configured
|
|
SetupDASInfo(CommDev, DevName);
|
|
|
|
if ((dev.Dev as IConnectedDAS).DASComm.IsEthernetDistributor()) { return true; }
|
|
// now pickup some stuff for the log
|
|
|
|
try
|
|
{
|
|
if (dev.Dev is IConnectedDAS idas)
|
|
{
|
|
idas.DASComm?.ReadFirstUseDate();
|
|
}
|
|
}
|
|
catch (Exception ex) { APILogger.Log(ex); }
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
try
|
|
{
|
|
if (ex is System.Net.Sockets.SocketException)
|
|
{
|
|
APILogger.LogString(string.Format("{0} Connection:{1} Message:{2}", APILogger.GetCurrentMethod(), DevName, ex.Message));
|
|
}
|
|
else
|
|
{
|
|
APILogger.LogException(ex);
|
|
}
|
|
|
|
if (IsInUpdateMode(CommDev, DevName))
|
|
{
|
|
var dasInfo = new InfoResult();
|
|
dasInfo.MaxNumberOfModules = 10;
|
|
dasInfo.Modules = new InfoResult.Module[0];
|
|
(dev.Dev as IConnectedDAS).DASComm.SetDASInfo(dasInfo, false);
|
|
dev.InUpdateMode = true;
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
catch (Exception eex)
|
|
{
|
|
APILogger.LogString("DASFactory.QuerySliceInformation.EX exception: " + dev.Dev.ConnectString);
|
|
APILogger.LogException(eex);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
protected override void SetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name)
|
|
{
|
|
ResetupDASInfo(dev, name, UtilityMode);
|
|
ReadCalDates(dev);
|
|
}
|
|
|
|
public static void ResetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name, bool UtilityMode)
|
|
{
|
|
// shortcut
|
|
var DASComm = dev as IDASCommunication;
|
|
|
|
try
|
|
{
|
|
//this is done to prevent calls to Max/Min sample rate longer which can happen when the system is busy
|
|
try
|
|
{
|
|
_ = DASComm?.MaxSampleRate(0);
|
|
_ = DASComm?.MinSampleRate();
|
|
}
|
|
catch (Exception) { }
|
|
// Our override will set up hw revision fetching
|
|
var hwType = DASComm.GetHardwareType();
|
|
|
|
// get the stack contents
|
|
var StackQuery = new QueryStackContents(dev);
|
|
StackQuery.SyncExecute();
|
|
// serialnumbers and firmware versions
|
|
dev.FirmwareVersion = StackQuery.FirmwareVersion[0];
|
|
DASComm.SerialNumber = StackQuery.SerialNumber[0];
|
|
|
|
WinUSBSlice2Handling.CheckInBootloaderMode(dev);
|
|
|
|
dev.DASInfo = new Communication_DASInfo(StackQuery.SerialNumber, StackQuery.FirmwareVersion);
|
|
|
|
var streamOutCount = hwType == HardwareTypes.DKR || hwType == HardwareTypes.DIR ? 0 : 1;
|
|
var uartCount = hwType == HardwareTypes.DKR || hwType == HardwareTypes.DIR ? 0 : 1;
|
|
// create and fill in InfoResult
|
|
var dasInfo = new InfoResult();
|
|
|
|
switch (hwType)
|
|
{
|
|
case HardwareTypes.DKR:
|
|
case HardwareTypes.DIR:
|
|
dasInfo.MaxNumberOfModules = MaxNumberOfModules;
|
|
dasInfo.NumberOfBytesPerSampleClock = 6; //TODO: Is this still true?
|
|
break;
|
|
default:
|
|
dasInfo.MaxNumberOfModules = MaxNumberOfModules;
|
|
dasInfo.NumberOfBytesPerSampleClock = (uint)(6 * (StackQuery.SliceCount - 1)); //TODO: Is this still true?
|
|
break;
|
|
}
|
|
|
|
|
|
dasInfo.OwningDAS = DASComm;
|
|
|
|
// construct module info
|
|
dasInfo.Modules = new InfoResult.Module[StackQuery.SliceCount + uartCount + streamOutCount - 1];
|
|
for (var sliceIdx = 0; sliceIdx < StackQuery.SliceCount - 1; sliceIdx++)
|
|
{
|
|
var module = new InfoResult.Module();
|
|
module.ModuleArrayIndex = sliceIdx;
|
|
module.OwningInfoResult = dasInfo;
|
|
|
|
module.SerialNumber = StackQuery.SerialNumber[sliceIdx + 1];
|
|
module.FirmwareVersion = StackQuery.FirmwareVersion[sliceIdx + 1];
|
|
|
|
module.MaxEventStorageSpaceInBytes = null; // specified per DAS
|
|
module.NumberOfBytesPerSampleClock = null; // specified per DAS
|
|
module.NumberOfChannels = 3;
|
|
module.SupportedSampleRates = (uint[])SamplerateList.Clone(); // this should be adjusted to real-life
|
|
|
|
var modes = new List<DFConstantsAndEnums.RecordingMode>();
|
|
modes.AddRange(new[] { DFConstantsAndEnums.RecordingMode.AutoActiveMode });
|
|
module.SupportedModes = modes.ToArray();
|
|
|
|
var moduleTypeByte = StackQuery.SliceType.ToArray()[sliceIdx + 1];
|
|
var moduleType = Convert.ToInt16(moduleTypeByte);
|
|
module.IsProgrammable = false;
|
|
|
|
|
|
switch (moduleType)
|
|
{
|
|
case (short)ChannelTypes.BRIDGE2HIGH:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceBridge2High;
|
|
break;
|
|
case (short)ChannelTypes.BRIDGE2LOW:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceBridge2Low;
|
|
break;
|
|
case (short)ChannelTypes.EMB_LIN_ACC_LO:
|
|
module.SerialNumber = $"{DASComm.SerialNumber}{DFConstantsAndEnums.SERIAL_SEPARATOR}{DFConstantsAndEnums.LOWG_SERIAL_APPEND}";
|
|
module.SupportedSampleRates = (uint[])LowGAccelSamplerateList.Clone();
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.EmbeddedLinearAccelLowG;
|
|
break;
|
|
case (short)ChannelTypes.EMB_LIN_ACC_HI:
|
|
module.SerialNumber = $"{DASComm.SerialNumber}{DFConstantsAndEnums.SERIAL_SEPARATOR}{DFConstantsAndEnums.HIGHG_SERIAL_APPEND}";
|
|
module.SupportedSampleRates = (uint[])HighGAccelSamplerateList.Clone();
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.EmbeddedLinearAccelHighG;
|
|
break;
|
|
case (short)ChannelTypes.EMB_ANG_ACC:
|
|
module.SerialNumber = $"{DASComm.SerialNumber}{DFConstantsAndEnums.SERIAL_SEPARATOR}{DFConstantsAndEnums.ANGACCEL_SERIAL_APPEND}";
|
|
module.SupportedSampleRates = (uint[])AngAccelSamplerateList.Clone();
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.EmbeddedAngularAccel;
|
|
break;
|
|
case (short)ChannelTypes.EMB_ANG_ARS:
|
|
module.SerialNumber = $"{DASComm.SerialNumber}{DFConstantsAndEnums.SERIAL_SEPARATOR}{DFConstantsAndEnums.ARS_SERIAL_APPEND}";
|
|
module.SupportedSampleRates = (uint[])AngRateSamplerateList.Clone();
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.EmbeddedAngularRate;
|
|
break;
|
|
case (short)ChannelTypes.EMB_ATM:
|
|
module.SerialNumber = $"{DASComm.SerialNumber}{DFConstantsAndEnums.SERIAL_SEPARATOR}{DFConstantsAndEnums.ATMOSPHERIC_SERIAL_APPEND}";
|
|
module.SupportedSampleRates = (uint[])AtmSamplerateList.Clone();
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.EmbeddedAtmospheric;
|
|
break;
|
|
case (short)ChannelTypes.EMB_OPT:
|
|
module.SerialNumber = $"{DASComm.SerialNumber}{DFConstantsAndEnums.SERIAL_SEPARATOR}{DFConstantsAndEnums.OPTICAL_SERIAL_APPEND}";
|
|
module.SupportedSampleRates = (uint[])LightSamplerateList.Clone();
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.EmbeddedOptical;
|
|
break;
|
|
case (short)ChannelTypes.EMB_MAG:
|
|
module.SerialNumber = $"{DASComm.SerialNumber}{DFConstantsAndEnums.SERIAL_SEPARATOR}{DFConstantsAndEnums.MAGNETIC_SERIAL_APPEND}";
|
|
module.SupportedSampleRates = (uint[])MagSamplerateList.Clone();
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.EmbeddedMagnetometer;
|
|
break;
|
|
case (short)ChannelTypes.EMB_MAG_SWITCH:
|
|
module.SerialNumber = $"{DASComm.SerialNumber}{DFConstantsAndEnums.SERIAL_SEPARATOR}{DFConstantsAndEnums.MAGNETICSWITCH_SERIAL_APPEND}";
|
|
module.SupportedSampleRates = (uint[])MagInSamplerateList.Clone();
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.EmbeddedMagnetInput;
|
|
break;
|
|
case (short)ChannelTypes.EMB_MIC:
|
|
module.SerialNumber = $"{DASComm.SerialNumber}{DFConstantsAndEnums.SERIAL_SEPARATOR}{DFConstantsAndEnums.MICROPHONE_SERIAL_APPEND}";
|
|
module.SupportedSampleRates = (uint[])MicSamplerateList.Clone();
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.EmbeddedMicrophone;
|
|
break;
|
|
case (short)ChannelTypes.EMB_RTC_S_MARK:
|
|
module.SerialNumber = $"{DASComm.SerialNumber}{DFConstantsAndEnums.SERIAL_SEPARATOR}{DFConstantsAndEnums.RTCSECONDANDMARKER_SERIAL_APPEND}";
|
|
module.SupportedSampleRates = new uint[] { };
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.EmbeddedClockSecondsAndMarker;
|
|
break;
|
|
case (short)ChannelTypes.EMB_RTC_NS_PAD:
|
|
module.SerialNumber = $"{DASComm.SerialNumber}{DFConstantsAndEnums.SERIAL_SEPARATOR}{DFConstantsAndEnums.RTCCLOCKNANOPAD_SERIAL_APPEND}";
|
|
module.SupportedSampleRates = new uint[] { };
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.EmbeddedClockNanosAndPad;
|
|
break;
|
|
case (short)ChannelTypes.SliceTcType_C:
|
|
case (short)ChannelTypes.SliceTcType_E:
|
|
case (short)ChannelTypes.SliceTcType_G:
|
|
case (short)ChannelTypes.SliceTcType_J:
|
|
case (short)ChannelTypes.SliceTcType_K:
|
|
case (short)ChannelTypes.SliceTcType_N:
|
|
case (short)ChannelTypes.SliceTcType_R:
|
|
case (short)ChannelTypes.SliceTcType_S:
|
|
case (short)ChannelTypes.SliceTcType_T:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.Thermocoupler;
|
|
break;
|
|
default:
|
|
APILogger.Log("WARNING! unknown slice module type: " + moduleType);
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceBridge;
|
|
break;
|
|
}
|
|
|
|
module.SampleRate2AAFrequency = Samplerate2AAFilterDict;
|
|
dasInfo.Modules[sliceIdx] = module;
|
|
}
|
|
|
|
//then add uart
|
|
for (var sliceIdx = 0; sliceIdx < uartCount; sliceIdx++)
|
|
{
|
|
var uartModule = new InfoResult.Module
|
|
{
|
|
ModuleArrayIndex = StackQuery.SliceCount - 1 + sliceIdx,
|
|
OwningInfoResult = dasInfo,
|
|
MaxEventStorageSpaceInBytes = null,
|
|
NumberOfBytesPerSampleClock = null,
|
|
NumberOfChannels = 1,
|
|
SerialNumber = $"{DASComm.SerialNumber}{DFConstantsAndEnums.SERIAL_SEPARATOR}{DFConstantsAndEnums.UART_SERIAL_APPEND}",
|
|
FirmwareVersion = StackQuery.FirmwareVersion[0],
|
|
SupportedModes = new DFConstantsAndEnums.RecordingMode[0],
|
|
SupportedSampleRates = new uint[0],
|
|
IsProgrammable = false,
|
|
TypeOfModule = DFConstantsAndEnums.ModuleType.UART
|
|
};
|
|
dasInfo.Modules[StackQuery.SliceCount - 1 + sliceIdx] = uartModule;
|
|
}
|
|
|
|
//then add streamout
|
|
for (var sliceIdx = 0; sliceIdx < streamOutCount; sliceIdx++)
|
|
{
|
|
var streamOutModule = new InfoResult.Module
|
|
{
|
|
ModuleArrayIndex = StackQuery.SliceCount - 1 + uartCount + sliceIdx,
|
|
OwningInfoResult = dasInfo,
|
|
MaxEventStorageSpaceInBytes = null,
|
|
NumberOfBytesPerSampleClock = null,
|
|
NumberOfChannels = 1,
|
|
SerialNumber = $"{DASComm.SerialNumber}{DFConstantsAndEnums.SERIAL_SEPARATOR}{DFConstantsAndEnums.STREAMOUT_SERIAL_APPEND}",
|
|
FirmwareVersion = StackQuery.FirmwareVersion[0],
|
|
SupportedModes = new DFConstantsAndEnums.RecordingMode[0],
|
|
SupportedSampleRates = new uint[0],
|
|
IsProgrammable = false,
|
|
TypeOfModule = DFConstantsAndEnums.ModuleType.StreamOut
|
|
};
|
|
dasInfo.Modules[StackQuery.SliceCount - 1 + uartCount + sliceIdx] = streamOutModule;
|
|
}
|
|
|
|
// attach the structure to the DAS
|
|
DASComm.SetDASInfo(dasInfo);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.LogString("SliceHandling.SetupDASInfo exception: " + name);
|
|
APILogger.LogException(ex);
|
|
|
|
// if we're not in util mode we bail out
|
|
if (!UtilityMode)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
// if we are, we must fill in something
|
|
// dev.FirmwareVersion
|
|
// DASComm.SerialNumber
|
|
// dev.DASInfo
|
|
// DASComm.DASInfo
|
|
dev.FirmwareVersion = "UNKNOWN";
|
|
DASComm.SerialNumber = "UNKNOWN";
|
|
dev.DASInfo = new Communication_DASInfo();
|
|
dev.DASInfo.SerialNumbers = new string[1] { DASComm.SerialNumber };
|
|
dev.DASInfo.FirmwareVersions = new string[1] { dev.FirmwareVersion };
|
|
|
|
var dasInfo = new InfoResult();
|
|
dasInfo.MaxNumberOfModules = MaxNumberOfModules;
|
|
dasInfo.NumberOfBytesPerSampleClock = 0;
|
|
dasInfo.MaxEventStorageSpaceInBytes = 0;
|
|
dasInfo.OwningDAS = DASComm;
|
|
dasInfo.Modules = new InfoResult.Module[0];
|
|
DASComm.SetDASInfo(dasInfo, false);
|
|
}
|
|
}
|
|
}
|
|
|
|
public class WinUSBSlice1_5Handling : SliceHandling
|
|
{
|
|
private const string DTS_SLICE1_5_WINUSB_GUID = "{d80bb9a9-2879-4d40-af1c-794b1e7956e4}";
|
|
public WinUSBSlice1_5Handling(bool _utilMode)
|
|
: base(_utilMode)
|
|
{
|
|
}
|
|
|
|
public override ICommunication GetICommunication()
|
|
{
|
|
return new WinUSBSlice1_5();
|
|
}
|
|
|
|
public override ICommunication GetICommunication(ConnectedDevice dev)
|
|
{
|
|
return (dev.Dev as ConnectedWinUSBSlice1_5).DASComm as ICommunication;
|
|
}
|
|
|
|
public override IConnectedDevice GetIConnectedDevice(DTS.Common.Interface.DASFactory.ICommunication comm)
|
|
{
|
|
return new ConnectedWinUSBSlice1_5(comm as WinUSBSlice1_5);
|
|
}
|
|
|
|
public override bool IsCorrectType(ConnectedDevice dev)
|
|
{
|
|
return dev.Dev is ConnectedWinUSBSlice1_5;
|
|
}
|
|
|
|
public override DFConstantsAndEnums.DASType GetDASType()
|
|
{
|
|
return DFConstantsAndEnums.DASType.WINUSB_SLICE1_5;
|
|
}
|
|
|
|
public override Guid GetGuid()
|
|
{
|
|
return new Guid(DTS_SLICE1_5_WINUSB_GUID);
|
|
}
|
|
|
|
public override bool QueryInformation(ConnectedDevice dev)
|
|
{
|
|
// don't assume anything...
|
|
if (dev == null || dev.Dev == null || string.IsNullOrEmpty(dev.Dev.ConnectString))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed1");
|
|
return false;
|
|
}
|
|
if (!(dev.Dev is IConnectedDAS) || !((dev.Dev as IConnectedDAS).DASComm is ICommunication) ||
|
|
!((dev.Dev as IConnectedDAS).DASComm is IDASCommunication))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed2");
|
|
return false;
|
|
}
|
|
|
|
// make shortcuts
|
|
var CommDev = (dev.Dev as IConnectedDAS).DASComm as ICommunication;
|
|
var DevName = dev.Dev.ConnectString;
|
|
|
|
|
|
|
|
try
|
|
{
|
|
|
|
// First get protocol version ...
|
|
ReadProtocolVersion(CommDev, DevName);
|
|
|
|
// check how stack is configured
|
|
SetupDASInfo(CommDev, DevName);
|
|
|
|
if ((dev.Dev as IConnectedDAS).DASComm.IsEthernetDistributor()) { return true; }
|
|
// now pickup some stuff for the log
|
|
|
|
try
|
|
{
|
|
if (dev.Dev is IConnectedDAS idas)
|
|
{
|
|
idas.DASComm?.ReadFirstUseDate();
|
|
}
|
|
}
|
|
catch (Exception ex) { APILogger.Log(ex); }
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
try
|
|
{
|
|
if (ex is System.Net.Sockets.SocketException
|
|
|| ex is CommandException)
|
|
{
|
|
APILogger.LogString(string.Format("{0} Connection:{1} Message:{2}", APILogger.GetCurrentMethod(),
|
|
DevName, ex.Message));
|
|
}
|
|
|
|
if (IsInUpdateMode(CommDev, DevName))
|
|
{
|
|
var dasInfo = new InfoResult
|
|
{
|
|
MaxNumberOfModules = 10,
|
|
Modules = new InfoResult.Module[0]
|
|
};
|
|
(dev.Dev as IConnectedDAS).DASComm.SetDASInfo(dasInfo, false);
|
|
dev.InUpdateMode = true;
|
|
return true;
|
|
}
|
|
APILogger.LogException(ex);
|
|
return false;
|
|
}
|
|
catch (Exception eex)
|
|
{
|
|
APILogger.LogString("DASFactory.QuerySliceInformation.EX exception: " + dev.Dev.ConnectString);
|
|
APILogger.LogException(eex);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
protected override void SetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name)
|
|
{
|
|
ResetupDASInfo(dev, name, UtilityMode);
|
|
ReadCalDates(dev);
|
|
}
|
|
|
|
protected override void ReadCalDates(DTS.Common.Interface.DASFactory.ICommunication dev)
|
|
{
|
|
var DASComm = dev as IDASCommunication;
|
|
if (!RunTestVariables.QueryCalDateInRunTest && RunTestVariables.InRunTest)
|
|
{
|
|
DASComm.DASInfo.CalibrationDate = null;
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
var qsa2 = new QuerySystemAttributeSLICE2(dev)
|
|
{
|
|
Key = AttributeTypes.SystemAttributesSLICE2.CalibrationDaysSince1970_01_01
|
|
};
|
|
qsa2.SyncExecute();
|
|
|
|
var days = DataConditioning.GetIntegerIfPossible(qsa2.Value);
|
|
DASComm.DASInfo.CalibrationDate = new DateTime(1970, 1, 1).AddDays(days);
|
|
|
|
for (var i = 0; i < DASComm.DASInfo.Modules.Length; i++)
|
|
{
|
|
var module = DASComm.DASInfo.Modules[i];
|
|
if (null == module)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
try
|
|
{
|
|
var qsa_b = new QuerySystemAttribute_Bridge(dev)
|
|
{
|
|
DeviceID = Convert.ToByte(1 + i),
|
|
Key = AttributeTypes.SystemAttributes_Bridge.CalibrationDaysSince1970_01_01
|
|
};
|
|
qsa_b.SyncExecute();
|
|
|
|
days = DataConditioning.GetIntegerIfPossible(qsa_b.Value);
|
|
module.CalibrationDate = new DateTime(1970, 1, 1).AddDays(days);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.Log(ex);
|
|
module.CalibrationDate = null;
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (!ex.Message.Contains("StatusAttributeNotRegistered"))
|
|
{
|
|
APILogger.Log(ex);
|
|
}
|
|
|
|
DASComm.DASInfo.CalibrationDate = null;
|
|
}
|
|
finally
|
|
{
|
|
DASComm.SetDASInfo();
|
|
}
|
|
}
|
|
|
|
public static void ResetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name, bool UtilityMode)
|
|
{
|
|
// shortcut
|
|
var DASComm = dev as IDASCommunication;
|
|
|
|
try
|
|
{
|
|
// get the stack contents
|
|
var StackQuery = new QueryStackContents(dev);
|
|
StackQuery.SyncExecute();
|
|
try
|
|
{
|
|
if (dev.IsCommandSupported(DFConstantsAndEnums.ProtocolLimitedCommands.QueryMSP430Firmware))
|
|
{
|
|
var msp = new QueryMSP430FirmwareVersion(dev);
|
|
msp.SyncExecute();
|
|
}
|
|
}
|
|
catch (Exception) { }
|
|
// serialnumbers and firmware versions
|
|
dev.FirmwareVersion = StackQuery.FirmwareVersion[0];
|
|
DASComm.SerialNumber = StackQuery.SerialNumber[0];
|
|
|
|
WinUSBSlice2Handling.CheckInBootloaderMode(dev);
|
|
|
|
dev.DASInfo = new Communication_DASInfo(StackQuery.SerialNumber, StackQuery.FirmwareVersion);
|
|
|
|
// create and fill in InfoResult
|
|
var dasInfo = new InfoResult
|
|
{
|
|
MaxNumberOfModules = MaxNumberOfModules,
|
|
NumberOfBytesPerSampleClock = (uint)(6 * (StackQuery.SliceCount - 1)),
|
|
OwningDAS = DASComm,
|
|
Modules = new InfoResult.Module[StackQuery.SliceCount - 1]
|
|
};
|
|
|
|
// construct module info
|
|
for (var sliceIdx = 0; sliceIdx < StackQuery.SliceCount - 1; sliceIdx++)
|
|
{
|
|
var module = new InfoResult.Module
|
|
{
|
|
ModuleArrayIndex = sliceIdx,
|
|
OwningInfoResult = dasInfo,
|
|
MaxEventStorageSpaceInBytes = null,
|
|
NumberOfBytesPerSampleClock = null,
|
|
NumberOfChannels = 3,
|
|
SerialNumber = StackQuery.SerialNumber[sliceIdx + 1],
|
|
FirmwareVersion = StackQuery.FirmwareVersion[sliceIdx + 1],
|
|
SupportedSampleRates = (uint[])SamplerateList.Clone()
|
|
};
|
|
SetRecordingModes(module, dev);
|
|
// specified per DAS
|
|
// specified per DAS
|
|
|
|
|
|
// this should be adjusted to real-life
|
|
|
|
var moduleTypeByte = StackQuery.SliceType.ToArray()[sliceIdx + 1];
|
|
var moduleType = Convert.ToInt16(moduleTypeByte);
|
|
module.IsProgrammable = false;
|
|
|
|
|
|
switch (moduleType)
|
|
{
|
|
case (short)ChannelTypes.BRIDGE:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceBridge;
|
|
break;
|
|
case (short)ChannelTypes.IEPE:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SLICEIEPE;
|
|
break;
|
|
default:
|
|
APILogger.Log("WARNING! unknown slice module type: " + moduleType);
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceBridge;
|
|
break;
|
|
}
|
|
|
|
module.SampleRate2AAFrequency = Samplerate2AAFilterDict;
|
|
dasInfo.Modules[sliceIdx] = module;
|
|
}
|
|
|
|
// attach the structure to the DAS
|
|
DASComm.SetDASInfo(dasInfo);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.LogString("SliceHandling.SetupDASInfo exception: " + name);
|
|
APILogger.LogException(ex);
|
|
|
|
// if we're not in util mode we bail out
|
|
if (!UtilityMode)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
// if we are, we must fill in something
|
|
// dev.FirmwareVersion
|
|
// DASComm.SerialNumber
|
|
// dev.DASInfo
|
|
// DASComm.DASInfo
|
|
dev.FirmwareVersion = "UNKNOWN";
|
|
DASComm.SerialNumber = "UNKNOWN";
|
|
dev.DASInfo = new Communication_DASInfo
|
|
{
|
|
SerialNumbers = new[] { DASComm.SerialNumber },
|
|
FirmwareVersions = new[] { dev.FirmwareVersion }
|
|
};
|
|
|
|
var dasInfo = new InfoResult
|
|
{
|
|
MaxNumberOfModules = MaxNumberOfModules,
|
|
NumberOfBytesPerSampleClock = 0,
|
|
MaxEventStorageSpaceInBytes = 0,
|
|
OwningDAS = DASComm,
|
|
Modules = new InfoResult.Module[0]
|
|
};
|
|
DASComm.SetDASInfo(dasInfo, false);
|
|
}
|
|
}
|
|
}
|
|
public class WinUSBSlice6AirThermocouplerHandling : SliceHandling
|
|
{
|
|
private const string DTS_SLICE6_AIR_TC_WINUSB_GUID = "{d80bb9a9-2879-4d40-af1c-DONTUSE956e4}";
|
|
|
|
public WinUSBSlice6AirThermocouplerHandling(bool _utilMode)
|
|
: base(_utilMode)
|
|
{
|
|
}
|
|
|
|
public override ICommunication GetICommunication()
|
|
{
|
|
return new WinUSBSlice6();
|
|
}
|
|
|
|
public override ICommunication GetICommunication(ConnectedDevice dev)
|
|
{
|
|
return (dev.Dev as ConnectedWinUSBSlice6AirThermocoupler).DASComm as ICommunication;
|
|
}
|
|
|
|
public override IConnectedDevice GetIConnectedDevice(ICommunication comm)
|
|
{
|
|
return new ConnectedWinUSBSlice6AirThermocoupler(comm as WinUSBSlice6AirThermocoupler);
|
|
}
|
|
|
|
public override bool IsCorrectType(ConnectedDevice dev)
|
|
{
|
|
return dev.Dev is ConnectedWinUSBSlice6AirThermocoupler;
|
|
}
|
|
|
|
public override DFConstantsAndEnums.DASType GetDASType()
|
|
{
|
|
return DFConstantsAndEnums.DASType.WINUSB_SLICE6AIR_TC;
|
|
}
|
|
|
|
public override Guid GetGuid()
|
|
{
|
|
return new Guid(DTS_SLICE6_AIR_TC_WINUSB_GUID);
|
|
}
|
|
|
|
public override bool QueryInformation(ConnectedDevice dev)
|
|
{
|
|
// don't assume anything...
|
|
if (dev == null || dev.Dev == null || string.IsNullOrEmpty(dev.Dev.ConnectString))
|
|
{
|
|
APILogger.LogString("SliceThermocouplerHandling.QueryInformation: Invalid parameter passed1");
|
|
return false;
|
|
}
|
|
if (!(dev.Dev is IConnectedDAS) || !((dev.Dev as IConnectedDAS).DASComm is ICommunication) ||
|
|
!((dev.Dev as IConnectedDAS).DASComm is IDASCommunication))
|
|
{
|
|
APILogger.LogString("SliceThermocouplerHandling.QueryInformation: Invalid parameter passed2");
|
|
return false;
|
|
}
|
|
|
|
// make shortcuts
|
|
var CommDev = (dev.Dev as IConnectedDAS).DASComm as ICommunication;
|
|
var DevName = dev.Dev.ConnectString;
|
|
|
|
|
|
|
|
try
|
|
{
|
|
|
|
// First get protocol version ...
|
|
ReadProtocolVersion(CommDev, DevName);
|
|
|
|
// check how stack is configured
|
|
SetupDASInfo(CommDev, DevName);
|
|
|
|
if ((dev.Dev as IConnectedDAS).DASComm.IsEthernetDistributor()) { return true; }
|
|
// now pickup some stuff for the log
|
|
|
|
try
|
|
{
|
|
if (dev.Dev is IConnectedDAS idas)
|
|
{
|
|
idas.DASComm?.ReadFirstUseDate();
|
|
}
|
|
}
|
|
catch (Exception ex) { APILogger.Log(ex); }
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
try
|
|
{
|
|
if (ex is System.Net.Sockets.SocketException)
|
|
{
|
|
APILogger.LogString(string.Format("{0} Connection:{1} Message:{2}", APILogger.GetCurrentMethod(), DevName, ex.Message));
|
|
}
|
|
else
|
|
{
|
|
APILogger.LogException(ex);
|
|
}
|
|
|
|
if (IsInUpdateMode(CommDev, DevName))
|
|
{
|
|
var dasInfo = new InfoResult();
|
|
dasInfo.NumberOfBridgeChannels = 8;
|
|
dasInfo.MaxNumberOfModules = 10;
|
|
dasInfo.Modules = new InfoResult.Module[0];
|
|
(dev.Dev as IConnectedDAS).DASComm.SetDASInfo(dasInfo, false);
|
|
dev.InUpdateMode = true;
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
catch (Exception eex)
|
|
{
|
|
APILogger.LogString("DASFactory.QuerySliceThermocouplerInformation.EX exception: " + dev.Dev.ConnectString);
|
|
APILogger.LogException(eex);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
protected override void SetupDASInfo(ICommunication dev, string name)
|
|
{
|
|
ResetupDASInfo(dev, name, UtilityMode);
|
|
ReadCalDates(dev);
|
|
}
|
|
|
|
public static void ResetupDASInfo(ICommunication dev, string name, bool UtilityMode)
|
|
{
|
|
// shortcut
|
|
var DASComm = dev as IDASCommunication;
|
|
|
|
try
|
|
{
|
|
// get the stack contents
|
|
var StackQuery = new QueryStackContents(dev);
|
|
StackQuery.SyncExecute();
|
|
|
|
// serialnumbers and firmware versions
|
|
dev.FirmwareVersion = StackQuery.FirmwareVersion[0];
|
|
DASComm.SerialNumber = StackQuery.SerialNumber[0];
|
|
|
|
WinUSBSlice2Handling.CheckInBootloaderMode(dev);
|
|
|
|
dev.DASInfo = new Communication_DASInfo(StackQuery.SerialNumber, StackQuery.FirmwareVersion);
|
|
|
|
var streamOutCount = 1;
|
|
|
|
// create and fill in InfoResult
|
|
var dasInfo = new InfoResult();
|
|
dasInfo.NumberOfBridgeChannels = 8;
|
|
dasInfo.MaxNumberOfModules = MaxNumberOfModules;
|
|
dasInfo.NumberOfBytesPerSampleClock = (uint)(6 * (StackQuery.SliceCount - 1));
|
|
dasInfo.OwningDAS = DASComm;
|
|
|
|
// construct module info
|
|
dasInfo.Modules = new InfoResult.Module[StackQuery.SliceCount + streamOutCount - 1];
|
|
for (var sliceIdx = 0; sliceIdx < StackQuery.SliceCount - 1; sliceIdx++)
|
|
{
|
|
var module = new InfoResult.Module();
|
|
module.ModuleArrayIndex = sliceIdx;
|
|
module.OwningInfoResult = dasInfo;
|
|
|
|
module.MaxEventStorageSpaceInBytes = null; // specified per DAS
|
|
module.NumberOfBytesPerSampleClock = null; // specified per DAS
|
|
module.NumberOfChannels = 3;
|
|
module.SerialNumber = StackQuery.SerialNumber[sliceIdx + 1];
|
|
module.FirmwareVersion = StackQuery.FirmwareVersion[sliceIdx + 1];
|
|
|
|
SetRecordingModes(module, dev);
|
|
module.SupportedSampleRates = (uint[])SamplerateList.Clone(); // this should be adjusted to real-life
|
|
|
|
var moduleTypeByte = StackQuery.SliceType.ToArray()[sliceIdx + 1];
|
|
var moduleType = Convert.ToInt16(moduleTypeByte);
|
|
module.IsProgrammable = false;
|
|
|
|
|
|
switch (moduleType)
|
|
{
|
|
case (short)ChannelTypes.BRIDGE:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceBridge;
|
|
break;
|
|
case (short)ChannelTypes.IEPE:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SLICEIEPE;
|
|
break;
|
|
default:
|
|
APILogger.Log("WARNING! unknown slice module type: " + moduleType);
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceBridge;
|
|
break;
|
|
}
|
|
|
|
module.SampleRate2AAFrequency = Samplerate2AAFilterDict;
|
|
dasInfo.Modules[sliceIdx] = module;
|
|
}
|
|
|
|
//then add streamout
|
|
for (var sliceIdx = 0; sliceIdx < streamOutCount; sliceIdx++)
|
|
{
|
|
var streamOutModule = new InfoResult.Module
|
|
{
|
|
ModuleArrayIndex = StackQuery.SliceCount - 1 + sliceIdx,
|
|
OwningInfoResult = dasInfo,
|
|
MaxEventStorageSpaceInBytes = null,
|
|
NumberOfBytesPerSampleClock = null,
|
|
NumberOfChannels = 1,
|
|
SerialNumber = $"{StackQuery.SerialNumber[0].Substring(0, 3)}-StreamOut{sliceIdx + 1}",
|
|
FirmwareVersion = StackQuery.FirmwareVersion[0],
|
|
SupportedModes = new DFConstantsAndEnums.RecordingMode[0],
|
|
SupportedSampleRates = new uint[0],
|
|
IsProgrammable = false,
|
|
TypeOfModule = DFConstantsAndEnums.ModuleType.StreamOut
|
|
};
|
|
dasInfo.Modules[StackQuery.SliceCount - 1 + sliceIdx] = streamOutModule;
|
|
}
|
|
|
|
// attach the structure to the DAS
|
|
DASComm.SetDASInfo(dasInfo);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.LogString("SliceThermocouplerHandling.SetupDASInfo exception: " + name);
|
|
APILogger.LogException(ex);
|
|
|
|
// if we're not in util mode we bail out
|
|
if (!UtilityMode)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
// if we are, we must fill in something
|
|
// dev.FirmwareVersion
|
|
// DASComm.SerialNumber
|
|
// dev.DASInfo
|
|
// DASComm.DASInfo
|
|
dev.FirmwareVersion = "UNKNOWN";
|
|
DASComm.SerialNumber = "UNKNOWN";
|
|
dev.DASInfo = new Communication_DASInfo();
|
|
dev.DASInfo.SerialNumbers = new string[1] { DASComm.SerialNumber };
|
|
dev.DASInfo.FirmwareVersions = new string[1] { dev.FirmwareVersion };
|
|
|
|
var dasInfo = new InfoResult();
|
|
dasInfo.NumberOfBridgeChannels = 8;
|
|
dasInfo.MaxNumberOfModules = MaxNumberOfModules;
|
|
dasInfo.NumberOfBytesPerSampleClock = 0;
|
|
dasInfo.MaxEventStorageSpaceInBytes = 0;
|
|
dasInfo.OwningDAS = DASComm;
|
|
dasInfo.Modules = new InfoResult.Module[0];
|
|
DASComm.SetDASInfo(dasInfo, false);
|
|
}
|
|
}
|
|
}
|
|
|
|
internal class EthernetSliceHandling : SliceHandling
|
|
{
|
|
public EthernetSliceHandling(bool _utilMode)
|
|
: base(_utilMode)
|
|
{
|
|
}
|
|
|
|
public override ICommunication GetICommunication()
|
|
{
|
|
return new EthernetSlice();
|
|
}
|
|
|
|
public override ICommunication GetICommunication(ConnectedDevice dev)
|
|
{
|
|
return (dev.Dev as ConnectedEthernetSlice).Comm;
|
|
}
|
|
|
|
public override IConnectedDevice GetIConnectedDevice(DTS.Common.Interface.DASFactory.ICommunication comm)
|
|
{
|
|
return new ConnectedEthernetSlice(comm as EthernetSlice);
|
|
}
|
|
public IConnectedDevice GetIConnectedSDBDevice(DTS.Common.Interface.DASFactory.ICommunication comm)
|
|
{
|
|
return new ConnectedEthernetSDB(comm as EthernetSliceDB);
|
|
}
|
|
public override bool IsCorrectType(ConnectedDevice dev)
|
|
{
|
|
return dev.Dev is ConnectedEthernetSlice;
|
|
}
|
|
|
|
public override DFConstantsAndEnums.DASType GetDASType()
|
|
{
|
|
return DFConstantsAndEnums.DASType.ETHERNET_SLICE;
|
|
}
|
|
|
|
public override Guid GetGuid()
|
|
{
|
|
return Guid.Empty;
|
|
}
|
|
}
|
|
internal class EthernetSlice2Handling : SliceHandling
|
|
{
|
|
public EthernetSlice2Handling(bool _utilMode)
|
|
: base(_utilMode)
|
|
{
|
|
}
|
|
|
|
public override ICommunication GetICommunication()
|
|
{
|
|
return new EthernetSlice2();
|
|
}
|
|
|
|
public override ICommunication GetICommunication(ConnectedDevice dev)
|
|
{
|
|
return (dev.Dev as ConnectedEthernetSlice2).Comm;
|
|
}
|
|
|
|
public override IConnectedDevice GetIConnectedDevice(DTS.Common.Interface.DASFactory.ICommunication comm)
|
|
{
|
|
return new ConnectedEthernetSlice2(comm as EthernetSlice2);
|
|
}
|
|
public IConnectedDevice GetIConnectedSDBDevice(DTS.Common.Interface.DASFactory.ICommunication comm)
|
|
{
|
|
return new ConnectedEthernetSDB(comm as EthernetSliceDB);
|
|
}
|
|
public override bool IsCorrectType(ConnectedDevice dev)
|
|
{
|
|
return dev.Dev is ConnectedEthernetSlice2;
|
|
}
|
|
|
|
public override DFConstantsAndEnums.DASType GetDASType()
|
|
{
|
|
return DFConstantsAndEnums.DASType.ETHERNET_SLICE2;
|
|
}
|
|
|
|
public override Guid GetGuid()
|
|
{
|
|
return Guid.Empty;
|
|
}
|
|
protected override void ReadCalDates(DTS.Common.Interface.DASFactory.ICommunication dev)
|
|
{
|
|
var dasComm = dev as IDASCommunication;
|
|
if (!RunTestVariables.QueryCalDateInRunTest && RunTestVariables.InRunTest)
|
|
{
|
|
dasComm.DASInfo.CalibrationDate = null;
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
var qsa = new QuerySystemAttributeSLICE2(dev)
|
|
{
|
|
Key = AttributeTypes.SystemAttributesSLICE2.CalibrationDaysSince1970_01_01
|
|
};
|
|
qsa.SyncExecute();
|
|
var days = DataConditioning.GetIntegerIfPossible(qsa.Value);
|
|
dasComm.DASInfo.CalibrationDate = new DateTime(1970, 1, 1).AddDays(days);
|
|
|
|
foreach (var module in dasComm.DASInfo.Modules)
|
|
{
|
|
try
|
|
{
|
|
var qsaS2B = new QuerySystemAttribute_Slice2Bridge_GEN3(dev)
|
|
{
|
|
Key = AttributeTypes.SystemAttributes_Bridge_SLICE2_GEN3.CalibrationDaysSince1970_01_01,
|
|
DeviceID = Convert.ToByte(1 + module.ModuleArrayIndex)
|
|
};
|
|
qsaS2B.SyncExecute();
|
|
days = DataConditioning.GetIntegerIfPossible(qsaS2B.Value);
|
|
module.CalibrationDate = new DateTime(1970, 1, 1).AddDays(days);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.Log(ex);
|
|
module.CalibrationDate = null;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (!ex.Message.Contains("StatusAttributeNotRegistered"))
|
|
{
|
|
APILogger.Log(ex);
|
|
}
|
|
|
|
dasComm.DASInfo.CalibrationDate = null;
|
|
}
|
|
finally
|
|
{
|
|
dasComm.SetDASInfo();
|
|
}
|
|
}
|
|
public override bool QueryInformation(ConnectedDevice dev)
|
|
{
|
|
// don't assume anything...
|
|
if (dev == null || dev.Dev == null || string.IsNullOrEmpty(dev.Dev.ConnectString))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed1");
|
|
return false;
|
|
}
|
|
if (!(dev.Dev is IConnectedDAS) || !((dev.Dev as IConnectedDAS).DASComm is ICommunication) ||
|
|
!((dev.Dev as IConnectedDAS).DASComm is IDASCommunication))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed2");
|
|
return false;
|
|
}
|
|
|
|
// make shortcuts
|
|
var CommDev = (dev.Dev as IConnectedDAS).DASComm as ICommunication;
|
|
var DevName = dev.Dev.ConnectString;
|
|
|
|
|
|
try
|
|
{
|
|
|
|
// First get protocol version ...
|
|
ReadProtocolVersion(CommDev, DevName);
|
|
|
|
// check how stack is configured
|
|
SetupDASInfo(CommDev, DevName);
|
|
|
|
if ((dev.Dev as IConnectedDAS).DASComm.IsEthernetDistributor()) { return true; }
|
|
// now pickup some stuff for the log
|
|
|
|
try
|
|
{
|
|
if (dev.Dev is IConnectedDAS idas)
|
|
{
|
|
idas.DASComm?.ReadFirstUseDate();
|
|
}
|
|
}
|
|
catch (Exception ex) { APILogger.Log(ex); }
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
try
|
|
{
|
|
if (ex is System.Net.Sockets.SocketException
|
|
|| ex is CommandException)
|
|
{
|
|
APILogger.LogString(string.Format("{0} Connection:{1} Message:{2}", APILogger.GetCurrentMethod(), DevName, ex.Message));
|
|
}
|
|
|
|
if (IsInUpdateMode(CommDev, DevName))
|
|
{
|
|
var dasInfo = new InfoResult
|
|
{
|
|
MaxNumberOfModules = 10,
|
|
Modules = new InfoResult.Module[0]
|
|
};
|
|
(dev.Dev as IConnectedDAS).DASComm.SetDASInfo(dasInfo, false);
|
|
dev.InUpdateMode = true;
|
|
return true;
|
|
}
|
|
APILogger.LogException(ex);
|
|
return false;
|
|
}
|
|
catch (Exception eex)
|
|
{
|
|
APILogger.LogString("DASFactory.QuerySliceInformation.EX exception: " + dev.Dev.ConnectString);
|
|
APILogger.LogException(eex);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
protected override void SetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name)
|
|
{
|
|
WinUSBSlice2Handling.ResetupDASInfo(dev, name, UtilityMode);
|
|
ReadCalDates(dev);
|
|
}
|
|
|
|
}
|
|
internal class EthernetSlice6Handling : WinUSBSlice6Handling
|
|
{
|
|
public EthernetSlice6Handling(bool _utilMode)
|
|
: base(_utilMode)
|
|
{
|
|
}
|
|
|
|
public override ICommunication GetICommunication()
|
|
{
|
|
var es = new EthernetSlice6();
|
|
es.OnDisconnected += Es_OnDisconnected;
|
|
return es;
|
|
}
|
|
|
|
private void Es_OnDisconnected(object sender, EventArgs e)
|
|
{
|
|
_handler.ReportDisconnect(sender);
|
|
}
|
|
|
|
public override ICommunication GetICommunication(ConnectedDevice dev)
|
|
{
|
|
return (dev.Dev as ConnectedEthernetSlice6).Comm;
|
|
}
|
|
|
|
public override IConnectedDevice GetIConnectedDevice(DTS.Common.Interface.DASFactory.ICommunication comm)
|
|
{
|
|
return new ConnectedEthernetSlice6(comm as EthernetSlice6);
|
|
}
|
|
public IConnectedDevice GetIConnectedSDBDevice(DTS.Common.Interface.DASFactory.ICommunication comm)
|
|
{
|
|
return new ConnectedEthernetSDB(comm as EthernetSliceDB);
|
|
}
|
|
public override bool IsCorrectType(ConnectedDevice dev)
|
|
{
|
|
return dev.Dev is ConnectedEthernetSlice6;
|
|
}
|
|
|
|
public override DFConstantsAndEnums.DASType GetDASType()
|
|
{
|
|
return DFConstantsAndEnums.DASType.ETHERNET_SLICE6;
|
|
}
|
|
|
|
public override Guid GetGuid()
|
|
{
|
|
return Guid.Empty;
|
|
}
|
|
public override bool QueryInformation(ConnectedDevice dev)
|
|
{
|
|
// don't assume anything...
|
|
if (dev == null || dev.Dev == null || string.IsNullOrEmpty(dev.Dev.ConnectString))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed1");
|
|
return false;
|
|
}
|
|
if (!(dev.Dev is IConnectedDAS) || !((dev.Dev as IConnectedDAS).DASComm is ICommunication) ||
|
|
!((dev.Dev as IConnectedDAS).DASComm is IDASCommunication))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed2");
|
|
return false;
|
|
}
|
|
|
|
// make shortcuts
|
|
var CommDev = (dev.Dev as IConnectedDAS).DASComm as ICommunication;
|
|
var DevName = dev.Dev.ConnectString;
|
|
|
|
|
|
try
|
|
{
|
|
|
|
// First get protocol version ...
|
|
ReadProtocolVersion(CommDev, DevName);
|
|
|
|
// check how stack is configured
|
|
SetupDASInfo(CommDev, DevName);
|
|
try
|
|
{
|
|
if (dev.Dev is IConnectedDAS idas)
|
|
{
|
|
idas.DASComm?.ReadFirstUseDate();
|
|
}
|
|
}
|
|
catch (Exception ex) { APILogger.Log(ex); }
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
try
|
|
{
|
|
if (ex is System.Net.Sockets.SocketException
|
|
|| ex is CommandException)
|
|
{
|
|
APILogger.LogString(string.Format("{0} Connection:{1} Message:{2}", APILogger.GetCurrentMethod(), DevName, ex.Message));
|
|
}
|
|
|
|
if (IsInUpdateMode(CommDev, DevName))
|
|
{
|
|
var dasInfo = new InfoResult();
|
|
dasInfo.MaxNumberOfModules = 10;
|
|
dasInfo.Modules = new InfoResult.Module[0];
|
|
(dev.Dev as IConnectedDAS).DASComm.SetDASInfo(dasInfo, false);
|
|
dev.InUpdateMode = true;
|
|
return true;
|
|
}
|
|
APILogger.LogException(ex);
|
|
return false;
|
|
}
|
|
catch (Exception eex)
|
|
{
|
|
APILogger.LogString("DASFactory.QuerySliceInformation.EX exception: " + dev.Dev.ConnectString);
|
|
APILogger.LogException(eex);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
public static void ResetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name, bool UtilityMode)
|
|
{
|
|
// shortcut
|
|
var dasComm = dev as IDASCommunication;
|
|
|
|
try
|
|
{
|
|
// get the stack contents
|
|
var StackQuery = new QueryStackContents(dev);
|
|
StackQuery.SyncExecute();
|
|
|
|
// serialnumbers and firmware versions
|
|
dev.FirmwareVersion = StackQuery.FirmwareVersion[0];
|
|
dasComm.SerialNumber = StackQuery.SerialNumber[0];
|
|
|
|
WinUSBSlice2Handling.CheckInBootloaderMode(dev);
|
|
|
|
dev.DASInfo = new Communication_DASInfo(StackQuery.SerialNumber, StackQuery.FirmwareVersion);
|
|
|
|
// create and fill in InfoResult
|
|
var dasInfo = new InfoResult
|
|
{
|
|
MaxNumberOfModules = MaxNumberOfModules,
|
|
NumberOfBytesPerSampleClock = (uint)(6 * (StackQuery.SliceCount - 1)),
|
|
OwningDAS = dasComm,
|
|
Modules = new InfoResult.Module[StackQuery.SliceCount - 1]
|
|
};
|
|
|
|
// construct module info
|
|
for (var sliceIdx = 0; sliceIdx < StackQuery.SliceCount - 1; sliceIdx++)
|
|
{
|
|
var module = new InfoResult.Module
|
|
{
|
|
ModuleArrayIndex = sliceIdx,
|
|
OwningInfoResult = dasInfo,
|
|
MaxEventStorageSpaceInBytes = null,
|
|
NumberOfBytesPerSampleClock = null,
|
|
NumberOfChannels = 3,
|
|
SerialNumber = StackQuery.SerialNumber[sliceIdx + 1],
|
|
FirmwareVersion = StackQuery.FirmwareVersion[sliceIdx + 1],
|
|
SupportedSampleRates = (uint[])SamplerateList.Clone()
|
|
};
|
|
SetRecordingModes(module, dev);
|
|
// specified per DAS
|
|
// specified per DAS
|
|
|
|
|
|
// this should be adjusted to real-life
|
|
|
|
var moduleTypeByte = StackQuery.SliceType.ToArray()[sliceIdx + 1];
|
|
var moduleType = Convert.ToInt16(moduleTypeByte);
|
|
module.IsProgrammable = false;
|
|
|
|
|
|
switch (moduleType)
|
|
{
|
|
case (short)ChannelTypes.BRIDGE:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceBridge;
|
|
break;
|
|
case (short)ChannelTypes.IEPE:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SLICEIEPE;
|
|
break;
|
|
default:
|
|
APILogger.Log("WARNING! unknown slice module type: " + moduleType);
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceBridge;
|
|
break;
|
|
}
|
|
|
|
module.SampleRate2AAFrequency = Samplerate2AAFilterDict;
|
|
dasInfo.Modules[sliceIdx] = module;
|
|
}
|
|
|
|
// attach the structure to the DAS
|
|
dasComm.SetDASInfo(dasInfo);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.LogString("SliceHandling.SetupDASInfo exception: " + name);
|
|
APILogger.LogException(ex);
|
|
|
|
// if we're not in util mode we bail out
|
|
if (!UtilityMode)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
// if we are, we must fill in something
|
|
// dev.FirmwareVersion
|
|
// DASComm.SerialNumber
|
|
// dev.DASInfo
|
|
// DASComm.DASInfo
|
|
dev.FirmwareVersion = "UNKNOWN";
|
|
dasComm.SerialNumber = "UNKNOWN";
|
|
dev.DASInfo = new Communication_DASInfo
|
|
{
|
|
SerialNumbers = new[] { dasComm.SerialNumber },
|
|
FirmwareVersions = new[] { dev.FirmwareVersion }
|
|
};
|
|
|
|
var dasInfo = new InfoResult
|
|
{
|
|
MaxNumberOfModules = MaxNumberOfModules,
|
|
NumberOfBytesPerSampleClock = 0,
|
|
MaxEventStorageSpaceInBytes = 0,
|
|
OwningDAS = dasComm,
|
|
Modules = new InfoResult.Module[0]
|
|
};
|
|
dasComm.SetDASInfo(dasInfo, false);
|
|
}
|
|
}
|
|
protected override void SetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name)
|
|
{
|
|
ResetupDASInfo(dev, name, UtilityMode);
|
|
ReadCalDates(dev);
|
|
}
|
|
private static DateTime DATE_TIME_1970 = new DateTime(1970, 1, 1);
|
|
protected override void ReadCalDates(DTS.Common.Interface.DASFactory.ICommunication dev)
|
|
{
|
|
if (!(dev is IDASCommunication dasComm)) { return; }
|
|
if (!RunTestVariables.QueryCalDateInRunTest && RunTestVariables.InRunTest)
|
|
{
|
|
dasComm.DASInfo.CalibrationDate = null;
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
var qsa = new QuerySystemAttributeSLICE6(dev)
|
|
{
|
|
Key = AttributeTypes.SystemAttributesSLICE6.CalibrationDaysSince1970_01_01
|
|
};
|
|
qsa.SyncExecute();
|
|
|
|
var days = DataConditioning.GetIntegerIfPossible(qsa.Value);
|
|
dasComm.DASInfo.CalibrationDate = DATE_TIME_1970.AddDays(days);
|
|
try
|
|
{
|
|
var qsaB = new QuerySystemAttribute_BridgeSlice6(dev)
|
|
{
|
|
DeviceID = Convert.ToByte(1),
|
|
Key = AttributeTypes.SystemAttributes_BridgeSlice6.CalibrationDaysSince1970_01_01
|
|
};
|
|
qsaB.SyncExecute();
|
|
|
|
days = DataConditioning.GetIntegerIfPossible(qsaB.Value);
|
|
dasComm.DASInfo.Modules[0].CalibrationDate = new DateTime(1970, 1, 1).AddDays(days);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.Log(ex);
|
|
dasComm.DASInfo.Modules[0].CalibrationDate = null;
|
|
}
|
|
foreach (var module in dasComm.DASInfo.Modules)
|
|
{
|
|
if (null == module)
|
|
{
|
|
continue;
|
|
}
|
|
module.CalibrationDate = DATE_TIME_1970.AddDays(days);
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (!ex.Message.Contains("StatusAttributeNotRegistered"))
|
|
{
|
|
APILogger.Log(ex);
|
|
}
|
|
dasComm.DASInfo.CalibrationDate = null;
|
|
}
|
|
}
|
|
}
|
|
internal class EthernetSlice6AirHandling : WinUSBSlice6AirHandling
|
|
{
|
|
public EthernetSlice6AirHandling(bool _utilMode)
|
|
: base(_utilMode)
|
|
{
|
|
}
|
|
|
|
public override ICommunication GetICommunication()
|
|
{
|
|
var es = new EthernetSlice6Air();
|
|
es.OnDisconnected += Es_OnDisconnected;
|
|
return es;
|
|
}
|
|
|
|
private void Es_OnDisconnected(object sender, EventArgs e)
|
|
{
|
|
_handler.ReportDisconnect(sender);
|
|
}
|
|
|
|
public override ICommunication GetICommunication(ConnectedDevice dev)
|
|
{
|
|
return (dev.Dev as ConnectedEthernetSlice6Air).Comm;
|
|
}
|
|
|
|
public override IConnectedDevice GetIConnectedDevice(DTS.Common.Interface.DASFactory.ICommunication comm)
|
|
{
|
|
return new ConnectedEthernetSlice6Air(comm as EthernetSlice6Air);
|
|
}
|
|
public IConnectedDevice GetIConnectedSDBDevice(DTS.Common.Interface.DASFactory.ICommunication comm)
|
|
{
|
|
return new ConnectedEthernetSDB(comm as EthernetSliceDB);
|
|
}
|
|
public override bool IsCorrectType(ConnectedDevice dev)
|
|
{
|
|
return dev.Dev is ConnectedEthernetSlice6Air;
|
|
}
|
|
|
|
public override DFConstantsAndEnums.DASType GetDASType()
|
|
{
|
|
return DFConstantsAndEnums.DASType.ETHERNET_SLICE6AIR;
|
|
}
|
|
|
|
public override Guid GetGuid()
|
|
{
|
|
return Guid.Empty;
|
|
}
|
|
public override bool QueryInformation(ConnectedDevice dev)
|
|
{
|
|
// don't assume anything...
|
|
if (dev == null || dev.Dev == null || string.IsNullOrEmpty(dev.Dev.ConnectString))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed1");
|
|
return false;
|
|
}
|
|
if (!(dev.Dev is IConnectedDAS) || !((dev.Dev as IConnectedDAS).DASComm is ICommunication) ||
|
|
!((dev.Dev as IConnectedDAS).DASComm is IDASCommunication))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed2");
|
|
return false;
|
|
}
|
|
|
|
// make shortcuts
|
|
var CommDev = (dev.Dev as IConnectedDAS).DASComm as ICommunication;
|
|
var DevName = dev.Dev.ConnectString;
|
|
|
|
|
|
try
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: " + DevName);
|
|
|
|
// First get protocol version ...
|
|
ReadProtocolVersion(CommDev, DevName);
|
|
|
|
// check how stack is configured
|
|
SetupDASInfo(CommDev, DevName);
|
|
try
|
|
{
|
|
if (dev.Dev is IConnectedDAS idas)
|
|
{
|
|
idas.DASComm?.ReadFirstUseDate();
|
|
idas.DASComm?.SetIsStreamingSupported();
|
|
}
|
|
}
|
|
catch (Exception ex) { APILogger.Log(ex); }
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
try
|
|
{
|
|
if (ex is System.Net.Sockets.SocketException
|
|
|| ex is CommandException)
|
|
{
|
|
APILogger.LogString(string.Format("{0} Connection:{1} Message:{2}", APILogger.GetCurrentMethod(), DevName, ex.Message));
|
|
}
|
|
|
|
if (IsInUpdateMode(CommDev, DevName))
|
|
{
|
|
var dasInfo = new InfoResult();
|
|
dasInfo.MaxNumberOfModules = 10;
|
|
dasInfo.Modules = new InfoResult.Module[0];
|
|
(dev.Dev as IConnectedDAS).DASComm.SetDASInfo(dasInfo, false);
|
|
dev.InUpdateMode = true;
|
|
return true;
|
|
}
|
|
APILogger.LogException(ex);
|
|
return false;
|
|
}
|
|
catch (Exception eex)
|
|
{
|
|
APILogger.LogString("DASFactory.QuerySliceInformation.EX exception: " + dev.Dev.ConnectString);
|
|
APILogger.LogException(eex);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
public static void ResetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name, bool UtilityMode)
|
|
{
|
|
// shortcut
|
|
var dasComm = dev as IDASCommunication;
|
|
|
|
try
|
|
{
|
|
// get the stack contents
|
|
var StackQuery = new QueryStackContents(dev);
|
|
StackQuery.SyncExecute();
|
|
|
|
// serialnumbers and firmware versions
|
|
dev.FirmwareVersion = StackQuery.FirmwareVersion[0];
|
|
|
|
//SLICE6Air Ethernet Recorders do not have UART nor StreamOut channels
|
|
var uartCount = (DFConstantsAndEnums.IsSLICE6ERFirmware(dev.FirmwareVersion)) ? 0 : 1;
|
|
var streamOutCount = (DFConstantsAndEnums.IsSLICE6ERFirmware(dev.FirmwareVersion)) ? 0 : 1;
|
|
|
|
dasComm.SerialNumber = StackQuery.SerialNumber[0];
|
|
|
|
WinUSBSlice2Handling.CheckInBootloaderMode(dev);
|
|
|
|
dev.DASInfo = new Communication_DASInfo(StackQuery.SerialNumber, StackQuery.FirmwareVersion);
|
|
|
|
// create and fill in InfoResult
|
|
var dasInfo = new InfoResult
|
|
{
|
|
MaxNumberOfModules = MaxNumberOfModules,
|
|
NumberOfBytesPerSampleClock = (uint)(6 * (StackQuery.SliceCount - 1)), //18363 still calculate bytes/sample based on non-UART channels (count - 1)
|
|
OwningDAS = dasComm,
|
|
Modules = new InfoResult.Module[StackQuery.SliceCount + uartCount + streamOutCount - 1] //18363 but make sure it's in the module info
|
|
};
|
|
|
|
if (DFConstantsAndEnums.IsSLICE6ERFirmware(dev.FirmwareVersion))
|
|
{
|
|
//per Loc, S6AER firmware will still report many things similar to standard S6A, even with unsupported hardware
|
|
var streamInCount = 1;
|
|
dasInfo.MaxNumberOfModules = 1;
|
|
dasInfo.Modules = new InfoResult.Module[1];
|
|
//so just add streamin
|
|
for (var sliceIdx = 0; sliceIdx < streamInCount; sliceIdx++)
|
|
{
|
|
var streamInModule = new InfoResult.Module
|
|
{
|
|
ModuleArrayIndex = 0,
|
|
OwningInfoResult = dasInfo,
|
|
MaxEventStorageSpaceInBytes = null,
|
|
NumberOfBytesPerSampleClock = null,
|
|
NumberOfChannels = 1,
|
|
SerialNumber = $"{StackQuery.SerialNumber[0].Substring(0, 3)}-StreamIn{sliceIdx + 1}",
|
|
FirmwareVersion = StackQuery.FirmwareVersion[0],
|
|
SampleRate2AAFrequency = Samplerate2AAFilterDict,
|
|
SupportedSampleRates = new uint[0],
|
|
IsProgrammable = false,
|
|
TypeOfModule = DFConstantsAndEnums.ModuleType.StreamIn
|
|
};
|
|
SetRecordingModes(streamInModule, dev);
|
|
dasInfo.Modules[sliceIdx] = streamInModule;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//first go through and add regular, read-from-query modules
|
|
for (var sliceIdx = 0; sliceIdx < StackQuery.SliceCount - 1; sliceIdx++)
|
|
{
|
|
var module = new InfoResult.Module
|
|
{
|
|
ModuleArrayIndex = sliceIdx,
|
|
OwningInfoResult = dasInfo,
|
|
MaxEventStorageSpaceInBytes = null,
|
|
NumberOfBytesPerSampleClock = null,
|
|
NumberOfChannels = 3,
|
|
SerialNumber = StackQuery.SerialNumber[sliceIdx + 1],
|
|
FirmwareVersion = StackQuery.FirmwareVersion[sliceIdx + 1],
|
|
SupportedSampleRates = (uint[])SamplerateList.Clone()
|
|
};
|
|
SetRecordingModes(module, dev);
|
|
var moduleTypeByte = StackQuery.SliceType.ToArray()[sliceIdx + 1];
|
|
var moduleType = Convert.ToInt16(moduleTypeByte);
|
|
module.IsProgrammable = false;
|
|
|
|
if (dasComm.GetIsStreaming())
|
|
{
|
|
//skip the call to query hardware configuration, it will fail ...
|
|
//15949 S6A when streaming does a whole bunch of unnecessary queries
|
|
}
|
|
else if (dev.IsCommandSupported(DFConstantsAndEnums.ProtocolLimitedCommands.HardwareConfiguration))
|
|
{
|
|
try
|
|
{
|
|
var q = new QueryHardwareConfigurationSLICE6(dev, 1 + sliceIdx);
|
|
q.SyncExecute();
|
|
switch (q.HardwareType)
|
|
{
|
|
case QueryHardwareConfigurationSLICE6.Types.Bridge_Configurable:
|
|
case QueryHardwareConfigurationSLICE6.Types.IEPE_Configurable:
|
|
case QueryHardwareConfigurationSLICE6.Types.IEPE_Configurable_Low:
|
|
case QueryHardwareConfigurationSLICE6.Types.Bridge_Configurable_Low:
|
|
module.IsProgrammable = true;
|
|
break;
|
|
case QueryHardwareConfigurationSLICE6.Types.Bridge:
|
|
case QueryHardwareConfigurationSLICE6.Types.IEPE:
|
|
module.IsProgrammable = false;
|
|
break;
|
|
}
|
|
}
|
|
catch (CommandException ce)
|
|
{
|
|
//15932 Error when performing test when S6A is streaming
|
|
if (ce.Error == CommandErrorReason.InvalidMode)
|
|
{
|
|
var idas = dev as IDASCommunication;
|
|
var armstatus = idas.DASArmStatus;
|
|
if (null == armstatus)
|
|
{
|
|
armstatus = new Service.ArmStatus();
|
|
}
|
|
try
|
|
{
|
|
var qats = new QueryArmAndTriggerStatus(dev, 1000);
|
|
qats.SyncExecute();
|
|
if (qats.IsArmed) { armstatus.IsArmed = true; }
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.Log(ex);
|
|
}
|
|
armstatus.ReceivedInvalidModeDuringSetup = true;
|
|
idas.SetDASArmStatus(armstatus, false);
|
|
APILogger.Log("Received invalid mode during setup, device may be armed or streaming");
|
|
}
|
|
}
|
|
catch (Exception ex) { APILogger.Log("failed to query hardware configuration", ex); }
|
|
}
|
|
|
|
switch (moduleType)
|
|
{
|
|
case (short)ChannelTypes.EIPE2HIGH:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceIEPE2High;
|
|
break;
|
|
case (short)ChannelTypes.IEPE2LOW:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceIEPE2Low;
|
|
break;
|
|
case (short)ChannelTypes.BRIDGE2LOW:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceBridge2Low;
|
|
break;
|
|
case (short)ChannelTypes.BRIDGE2HIGH:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceBridge2High;
|
|
break;
|
|
case (short)ChannelTypes.DIM:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.ProDIM;
|
|
break;
|
|
case (short)ChannelTypes.TOM:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SLICEPro_TOM;
|
|
break;
|
|
default:
|
|
APILogger.Log("WARNING! unknown slice module type: " + moduleType);
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceBridge;
|
|
break;
|
|
}
|
|
|
|
module.SampleRate2AAFrequency = Samplerate2AAFilterDict;
|
|
if (sliceIdx < dasInfo.Modules.Length)
|
|
{
|
|
dasInfo.Modules[sliceIdx] = module;
|
|
}
|
|
}
|
|
|
|
//then add uart
|
|
for (var sliceIdx = 0; sliceIdx < uartCount; sliceIdx++)
|
|
{
|
|
var uartModule = new InfoResult.Module
|
|
{
|
|
ModuleArrayIndex = StackQuery.SliceCount - 1 + sliceIdx,
|
|
OwningInfoResult = dasInfo,
|
|
MaxEventStorageSpaceInBytes = null,
|
|
NumberOfBytesPerSampleClock = null,
|
|
NumberOfChannels = 1,
|
|
SerialNumber = $"{StackQuery.SerialNumber[0].Substring(0, 3)}-Uart{sliceIdx + 1}",
|
|
FirmwareVersion = StackQuery.FirmwareVersion[0],
|
|
SupportedModes = new DFConstantsAndEnums.RecordingMode[0],
|
|
SupportedSampleRates = new uint[0],
|
|
IsProgrammable = false,
|
|
TypeOfModule = DFConstantsAndEnums.ModuleType.UART
|
|
};
|
|
dasInfo.Modules[StackQuery.SliceCount - 1 + sliceIdx] = uartModule;
|
|
}
|
|
|
|
//then add streamout
|
|
for (var sliceIdx = 0; sliceIdx < streamOutCount; sliceIdx++)
|
|
{
|
|
var streamOutModule = new InfoResult.Module
|
|
{
|
|
ModuleArrayIndex = StackQuery.SliceCount - 1 + uartCount + sliceIdx,
|
|
OwningInfoResult = dasInfo,
|
|
MaxEventStorageSpaceInBytes = null,
|
|
NumberOfBytesPerSampleClock = null,
|
|
NumberOfChannels = 1,
|
|
SerialNumber = $"{StackQuery.SerialNumber[0].Substring(0, 3)}-StreamOut{sliceIdx + 1}",
|
|
FirmwareVersion = StackQuery.FirmwareVersion[0],
|
|
SupportedModes = new DFConstantsAndEnums.RecordingMode[0],
|
|
SupportedSampleRates = new uint[0],
|
|
IsProgrammable = false,
|
|
TypeOfModule = DFConstantsAndEnums.ModuleType.StreamOut
|
|
};
|
|
dasInfo.Modules[StackQuery.SliceCount - 1 + uartCount + sliceIdx] = streamOutModule;
|
|
}
|
|
}
|
|
|
|
// attach the structure to the DAS
|
|
dasComm.SetDASInfo(dasInfo);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.LogString("SliceHandling.SetupDASInfo exception: " + name);
|
|
APILogger.LogException(ex);
|
|
|
|
// if we're not in util mode we bail out
|
|
if (!UtilityMode)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
// if we are, we must fill in something
|
|
// dev.FirmwareVersion
|
|
// DASComm.SerialNumber
|
|
// dev.DASInfo
|
|
// DASComm.DASInfo
|
|
dev.FirmwareVersion = "UNKNOWN";
|
|
dasComm.SerialNumber = "UNKNOWN";
|
|
dev.DASInfo = new Communication_DASInfo
|
|
{
|
|
SerialNumbers = new[] { dasComm.SerialNumber },
|
|
FirmwareVersions = new[] { dev.FirmwareVersion }
|
|
};
|
|
|
|
var dasInfo = new InfoResult
|
|
{
|
|
MaxNumberOfModules = MaxNumberOfModules,
|
|
NumberOfBytesPerSampleClock = 0,
|
|
MaxEventStorageSpaceInBytes = 0,
|
|
OwningDAS = dasComm,
|
|
Modules = new InfoResult.Module[0]
|
|
};
|
|
dasComm.SetDASInfo(dasInfo, false);
|
|
}
|
|
}
|
|
protected override void SetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name)
|
|
{
|
|
ResetupDASInfo(dev, name, UtilityMode);
|
|
ReadCalDates(dev);
|
|
}
|
|
protected override void ReadCalDates(DTS.Common.Interface.DASFactory.ICommunication dev)
|
|
{
|
|
if (!(dev is IDASCommunication dasComm)) { return; }
|
|
if (!RunTestVariables.QueryCalDateInRunTest && RunTestVariables.InRunTest)
|
|
{
|
|
dasComm.DASInfo.CalibrationDate = null;
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
if (dasComm.GetIsStreaming())
|
|
{
|
|
//15949 S6A when streaming does a whole bunch of unnecessary queries
|
|
//avoid getting cal dates while streaming, it will fail
|
|
}
|
|
else
|
|
{
|
|
var qsa = new QuerySystemAttributeSLICE6(dev)
|
|
{
|
|
Key = AttributeTypes.SystemAttributesSLICE6.CalibrationDaysSince1970_01_01
|
|
};
|
|
qsa.SyncExecute();
|
|
|
|
var days = DataConditioning.GetIntegerIfPossible(qsa.Value);
|
|
dasComm.DASInfo.CalibrationDate = new DateTime(1970, 1, 1).AddDays(days);
|
|
if (null != dasComm.DASInfo.Modules && dasComm.DASInfo.Modules.Any())
|
|
{
|
|
try
|
|
{
|
|
var qsaB = new QuerySystemAttribute_BridgeSlice6(dev)
|
|
{
|
|
DeviceID = Convert.ToByte(1),
|
|
Key = AttributeTypes.SystemAttributes_BridgeSlice6.CalibrationDaysSince1970_01_01
|
|
};
|
|
qsaB.SyncExecute();
|
|
|
|
days = DataConditioning.GetIntegerIfPossible(qsaB.Value);
|
|
dasComm.DASInfo.Modules[0].CalibrationDate = new DateTime(1970, 1, 1).AddDays(days);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.Log(ex);
|
|
dasComm.DASInfo.Modules[0].CalibrationDate = null;
|
|
}
|
|
}
|
|
foreach (var module in dasComm.DASInfo.Modules)
|
|
{
|
|
if (null == module)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
module.CalibrationDate = new DateTime(1970, 1, 1).AddDays(days);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (!ex.Message.Contains("StatusAttributeNotRegistered"))
|
|
{
|
|
APILogger.Log(ex);
|
|
}
|
|
|
|
dasComm.DASInfo.CalibrationDate = null;
|
|
}
|
|
finally
|
|
{
|
|
dasComm.SetDASInfo();
|
|
}
|
|
}
|
|
}
|
|
internal class EthernetSlice6AirBridgeHandling : WinUSBSlice6AirBridgeHandling
|
|
{
|
|
public EthernetSlice6AirBridgeHandling(bool _utilMode)
|
|
: base(_utilMode)
|
|
{
|
|
}
|
|
|
|
public override ICommunication GetICommunication()
|
|
{
|
|
var es = new EthernetSlice6AirBridge();
|
|
es.OnDisconnected += Es_OnDisconnected;
|
|
return es;
|
|
}
|
|
|
|
private void Es_OnDisconnected(object sender, EventArgs e)
|
|
{
|
|
_handler.ReportDisconnect(sender);
|
|
}
|
|
|
|
public override ICommunication GetICommunication(ConnectedDevice dev)
|
|
{
|
|
return (dev.Dev as ConnectedEthernetSlice6AirBridge).Comm;
|
|
}
|
|
|
|
public override IConnectedDevice GetIConnectedDevice(DTS.Common.Interface.DASFactory.ICommunication comm)
|
|
{
|
|
return new ConnectedEthernetSlice6AirBridge(comm as EthernetSlice6AirBridge);
|
|
}
|
|
public IConnectedDevice GetIConnectedSDBDevice(DTS.Common.Interface.DASFactory.ICommunication comm)
|
|
{
|
|
return new ConnectedEthernetSDB(comm as EthernetSliceDB);
|
|
}
|
|
public override bool IsCorrectType(ConnectedDevice dev)
|
|
{
|
|
return dev.Dev is ConnectedEthernetSlice6AirBridge;
|
|
}
|
|
|
|
public override DFConstantsAndEnums.DASType GetDASType()
|
|
{
|
|
return DFConstantsAndEnums.DASType.ETHERNET_SLICE6AIR_BR;
|
|
}
|
|
|
|
public override Guid GetGuid()
|
|
{
|
|
return Guid.Empty;
|
|
}
|
|
public override bool QueryInformation(ConnectedDevice dev)
|
|
{
|
|
// don't assume anything...
|
|
if (dev == null || dev.Dev == null || string.IsNullOrEmpty(dev.Dev.ConnectString))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed1");
|
|
return false;
|
|
}
|
|
if (!(dev.Dev is IConnectedDAS) || !((dev.Dev as IConnectedDAS).DASComm is ICommunication) ||
|
|
!((dev.Dev as IConnectedDAS).DASComm is IDASCommunication))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed2");
|
|
return false;
|
|
}
|
|
|
|
// make shortcuts
|
|
var CommDev = (dev.Dev as IConnectedDAS).DASComm as ICommunication;
|
|
var DevName = dev.Dev.ConnectString;
|
|
|
|
|
|
try
|
|
{
|
|
|
|
// First get protocol version ...
|
|
ReadProtocolVersion(CommDev, DevName);
|
|
|
|
// check how stack is configured
|
|
SetupDASInfo(CommDev, DevName);
|
|
try
|
|
{
|
|
if (dev.Dev is IConnectedDAS idas)
|
|
{
|
|
idas.DASComm?.ReadFirstUseDate();
|
|
idas.DASComm?.SetIsStreamingSupported();
|
|
}
|
|
}
|
|
catch (Exception ex) { APILogger.Log(ex); }
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
try
|
|
{
|
|
if (ex is System.Net.Sockets.SocketException
|
|
|| ex is CommandException)
|
|
{
|
|
APILogger.LogString(string.Format("{0} Connection:{1} Message:{2}", APILogger.GetCurrentMethod(), DevName, ex.Message));
|
|
}
|
|
|
|
if (IsInUpdateMode(CommDev, DevName))
|
|
{
|
|
var dasInfo = new InfoResult();
|
|
dasInfo.MaxNumberOfModules = 10;
|
|
dasInfo.Modules = new InfoResult.Module[0];
|
|
(dev.Dev as IConnectedDAS).DASComm.SetDASInfo(dasInfo, false);
|
|
dev.InUpdateMode = true;
|
|
return true;
|
|
}
|
|
APILogger.LogException(ex);
|
|
return false;
|
|
}
|
|
catch (Exception eex)
|
|
{
|
|
APILogger.LogString("DASFactory.QuerySliceInformation.EX exception: " + dev.Dev.ConnectString);
|
|
APILogger.LogException(eex);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
public static void ResetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name, bool UtilityMode)
|
|
{
|
|
// shortcut
|
|
var dasComm = dev as IDASCommunication;
|
|
|
|
try
|
|
{
|
|
// get the stack contents
|
|
var StackQuery = new QueryStackContents(dev);
|
|
StackQuery.SyncExecute();
|
|
|
|
// serialnumbers and firmware versions
|
|
dev.FirmwareVersion = StackQuery.FirmwareVersion[0];
|
|
dasComm.SerialNumber = StackQuery.SerialNumber[0];
|
|
|
|
WinUSBSlice2Handling.CheckInBootloaderMode(dev);
|
|
|
|
dev.DASInfo = new Communication_DASInfo(StackQuery.SerialNumber, StackQuery.FirmwareVersion);
|
|
|
|
var streamOutCount = 1;
|
|
|
|
// create and fill in InfoResult
|
|
var dasInfo = new InfoResult
|
|
{
|
|
MaxNumberOfModules = MaxNumberOfModules,
|
|
NumberOfBytesPerSampleClock = (uint)(6 * (StackQuery.SliceCount - 1)),
|
|
OwningDAS = dasComm,
|
|
Modules = new InfoResult.Module[StackQuery.SliceCount + streamOutCount - 1]
|
|
};
|
|
|
|
// construct module info
|
|
for (var sliceIdx = 0; sliceIdx < StackQuery.SliceCount - 1; sliceIdx++)
|
|
{
|
|
var module = new InfoResult.Module
|
|
{
|
|
ModuleArrayIndex = sliceIdx,
|
|
OwningInfoResult = dasInfo,
|
|
MaxEventStorageSpaceInBytes = null,
|
|
NumberOfBytesPerSampleClock = null,
|
|
NumberOfChannels = 3,
|
|
SerialNumber = StackQuery.SerialNumber[sliceIdx + 1],
|
|
FirmwareVersion = StackQuery.FirmwareVersion[sliceIdx + 1],
|
|
SupportedSampleRates = (uint[])SamplerateList.Clone()
|
|
};
|
|
SetRecordingModes(module, dev);
|
|
|
|
// this should be adjusted to real-life
|
|
|
|
var moduleTypeByte = StackQuery.SliceType.ToArray()[sliceIdx + 1];
|
|
var moduleType = Convert.ToInt16(moduleTypeByte);
|
|
module.IsProgrammable = false;
|
|
|
|
|
|
switch (moduleType)
|
|
{
|
|
case (short)ChannelTypes.BRIDGE:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceBridge;
|
|
break;
|
|
case (short)ChannelTypes.IEPE:
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SLICEIEPE;
|
|
break;
|
|
default:
|
|
APILogger.Log("WARNING! unknown slice module type: " + moduleType);
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.SliceBridge;
|
|
break;
|
|
}
|
|
|
|
module.SampleRate2AAFrequency = Samplerate2AAFilterDict;
|
|
dasInfo.Modules[sliceIdx] = module;
|
|
}
|
|
|
|
//then add streamout
|
|
for (var sliceIdx = 0; sliceIdx < streamOutCount; sliceIdx++)
|
|
{
|
|
var streamOutModule = new InfoResult.Module
|
|
{
|
|
ModuleArrayIndex = StackQuery.SliceCount - 1 + sliceIdx,
|
|
OwningInfoResult = dasInfo,
|
|
MaxEventStorageSpaceInBytes = null,
|
|
NumberOfBytesPerSampleClock = null,
|
|
NumberOfChannels = 1,
|
|
SerialNumber = $"{StackQuery.SerialNumber[0].Substring(0, 3)}-StreamOut{sliceIdx + 1}",
|
|
FirmwareVersion = StackQuery.FirmwareVersion[0],
|
|
SupportedModes = new DFConstantsAndEnums.RecordingMode[0],
|
|
SupportedSampleRates = new uint[0],
|
|
IsProgrammable = false,
|
|
TypeOfModule = DFConstantsAndEnums.ModuleType.StreamOut
|
|
};
|
|
dasInfo.Modules[StackQuery.SliceCount - 1 + sliceIdx] = streamOutModule;
|
|
}
|
|
|
|
// attach the structure to the DAS
|
|
dasComm.SetDASInfo(dasInfo);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.LogString("SliceHandling.SetupDASInfo exception: " + name);
|
|
APILogger.LogException(ex);
|
|
|
|
// if we're not in util mode we bail out
|
|
if (!UtilityMode)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
// if we are, we must fill in something
|
|
// dev.FirmwareVersion
|
|
// DASComm.SerialNumber
|
|
// dev.DASInfo
|
|
// DASComm.DASInfo
|
|
dev.FirmwareVersion = "UNKNOWN";
|
|
dasComm.SerialNumber = "UNKNOWN";
|
|
dev.DASInfo = new Communication_DASInfo
|
|
{
|
|
SerialNumbers = new[] { dasComm.SerialNumber },
|
|
FirmwareVersions = new[] { dev.FirmwareVersion }
|
|
};
|
|
|
|
var dasInfo = new InfoResult
|
|
{
|
|
MaxNumberOfModules = MaxNumberOfModules,
|
|
NumberOfBytesPerSampleClock = 0,
|
|
MaxEventStorageSpaceInBytes = 0,
|
|
OwningDAS = dasComm,
|
|
Modules = new InfoResult.Module[0]
|
|
};
|
|
dasComm.SetDASInfo(dasInfo, false);
|
|
}
|
|
}
|
|
protected override void SetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name)
|
|
{
|
|
ResetupDASInfo(dev, name, UtilityMode);
|
|
ReadCalDates(dev);
|
|
}
|
|
private static DateTime DATE_TIME_1970 = new DateTime(1970, 1, 1);
|
|
protected override void ReadCalDates(DTS.Common.Interface.DASFactory.ICommunication dev)
|
|
{
|
|
if (!(dev is IDASCommunication dasComm)) { return; }
|
|
if (!RunTestVariables.QueryCalDateInRunTest && RunTestVariables.InRunTest)
|
|
{
|
|
dasComm.DASInfo.CalibrationDate = null;
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
var qsa = new QuerySystemAttributeSLICE6(dev)
|
|
{
|
|
Key = AttributeTypes.SystemAttributesSLICE6.CalibrationDaysSince1970_01_01
|
|
};
|
|
qsa.SyncExecute();
|
|
|
|
var days = Convert.ToInt32(qsa.Value);
|
|
dasComm.DASInfo.CalibrationDate = DATE_TIME_1970.AddDays(days);
|
|
try
|
|
{
|
|
var qsaB = new QuerySystemAttribute_BridgeSlice6(dev)
|
|
{
|
|
DeviceID = Convert.ToByte(1),
|
|
Key = AttributeTypes.SystemAttributes_BridgeSlice6.CalibrationDaysSince1970_01_01
|
|
};
|
|
qsaB.SyncExecute();
|
|
|
|
days = Convert.ToInt32(qsaB.Value);
|
|
dasComm.DASInfo.Modules[0].CalibrationDate = new DateTime(1970, 1, 1).AddDays(days);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.Log(ex);
|
|
dasComm.DASInfo.Modules[0].CalibrationDate = null;
|
|
}
|
|
foreach (var module in dasComm.DASInfo.Modules)
|
|
{
|
|
if (null == module)
|
|
{
|
|
continue;
|
|
}
|
|
module.CalibrationDate = DATE_TIME_1970.AddDays(days);
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (!ex.Message.Contains("StatusAttributeNotRegistered"))
|
|
{
|
|
APILogger.Log(ex);
|
|
}
|
|
dasComm.DASInfo.CalibrationDate = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
internal class EthernetSlice6DBHandling : WinUSBSlice6Handling
|
|
{
|
|
public static new void ResetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name, bool UtilityMode)
|
|
{
|
|
ResetupDASInfo(dev, name, UtilityMode, null);
|
|
}
|
|
public static void ResetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name, bool UtilityMode, ConnectedDeviceUpdatedDelegate updatedDelegate)
|
|
{
|
|
// shortcut
|
|
var DASComm = dev as IDASCommunication;
|
|
|
|
try
|
|
{
|
|
dev.ProtocolVersion = 1;
|
|
var query = new Command.SLICE.QueryProtocolVersion(dev, 2000);
|
|
query.SyncExecute();
|
|
dev.ProtocolVersion = query.Version;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.Log(ex);
|
|
try
|
|
{
|
|
var query = new Command.SLICE.QueryProtocolVersion(dev, QueryProtocolVersion.Default_IO_Timeout);
|
|
query.SyncExecute();
|
|
dev.ProtocolVersion = query.Version;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
dev.ProtocolVersion = 1;
|
|
}
|
|
}
|
|
try
|
|
{
|
|
|
|
// get the stack contents
|
|
var StackQuery = new QueryStackContents(dev);
|
|
StackQuery.SyncExecute();
|
|
|
|
dev.FirmwareVersion = StackQuery.FirmwareVersion[0];
|
|
DASComm.SerialNumber = StackQuery.SerialNumber[0];
|
|
dev.DASInfo = new Communication_DASInfo(StackQuery.SerialNumber, StackQuery.FirmwareVersion);
|
|
|
|
try
|
|
{
|
|
DASComm.QueryConnectedDevices();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.Log(ex);
|
|
}
|
|
|
|
|
|
|
|
// get attached tilt sensor I2C ids
|
|
List<Common.Classes.Hardware.ExternalTilt> activeTilts = new List<Common.Classes.Hardware.ExternalTilt>();
|
|
try
|
|
{
|
|
if (dev.IsCommandSupported(DFConstantsAndEnums.ProtocolLimitedCommands.QueryExternalTiltInfo))
|
|
{
|
|
List<byte> tiltIds = new List<byte>();
|
|
ushort numTilt;
|
|
byte[] tiltAddr;
|
|
var tiltSensorGet = new TiltSensorGet(dev)
|
|
{
|
|
Sub_cmd = TiltSensorMif.TiltSenosrList
|
|
};
|
|
tiltSensorGet.SyncExecute();
|
|
numTilt = tiltSensorGet.NumberOfTilt;
|
|
tiltAddr = tiltSensorGet.Tilt_Address;
|
|
for (int i = 0; i < numTilt; i++)
|
|
{
|
|
tiltIds.Add(tiltAddr[i]);
|
|
}
|
|
foreach (var tID in tiltIds)
|
|
{
|
|
tiltSensorGet = new TiltSensorGet(dev, 600000)
|
|
{
|
|
Tilt_id = tID,
|
|
Sub_cmd = TiltSensorMif.TiltSensorEEPROM,
|
|
Data_Offset = 0,
|
|
Data_Length = 256
|
|
};
|
|
tiltSensorGet.SyncExecute();
|
|
var tiltMif = new Tilt_MIF(tiltSensorGet.Data);
|
|
if (tiltMif.ArmChecklist)
|
|
{
|
|
activeTilts.Add(new Common.Classes.Hardware.ExternalTilt()
|
|
{
|
|
SerialNumber = tiltMif.SerialNumber,
|
|
TiltID = tID,
|
|
SystemLocation = tiltMif.Location,
|
|
SystemID = tiltMif.SystemID,
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex) { APILogger.Log(ex); }
|
|
|
|
|
|
|
|
|
|
updatedDelegate?.Invoke(dev.DASInfo.ConnectedDevices);
|
|
// create and fill in InfoResult
|
|
DASComm.SetDASInfo(new InfoResult
|
|
{
|
|
MaxEventStorageSpaceInBytes = ulong.MaxValue,
|
|
MaxNumberOfModules = 0,
|
|
Modules = new[] { new InfoResult.Module() },
|
|
ActiveExternalTilts = activeTilts, // external tilt I2C ids
|
|
}, false);
|
|
DASComm.DASInfo.Modules[0].SerialNumber = DASComm.SerialNumber;
|
|
|
|
DASComm.DASInfo.NumberOfBridgeChannels = 1;
|
|
DASComm.DASInfo.NumberOfBytesPerSampleClock = 1;
|
|
((InfoResult)DASComm.DASInfo).OwningDAS = DASComm;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.Log("SLICE6DbHandling:ResetupDASInfo exception: ", ex);
|
|
// if we're not in util mode we bail out
|
|
if (!UtilityMode)
|
|
{
|
|
throw;
|
|
}
|
|
dev.FirmwareVersion = "UNKNOWN";
|
|
DASComm.SerialNumber = "UNKNOWN";
|
|
dev.DASInfo = new Communication_DASInfo();
|
|
dev.DASInfo.SerialNumbers = new string[1] { DASComm.SerialNumber };
|
|
dev.DASInfo.FirmwareVersions = new string[1] { dev.FirmwareVersion };
|
|
|
|
var dasInfo = new InfoResult();
|
|
dasInfo.MaxNumberOfModules = MaxNumberOfModules;
|
|
dasInfo.NumberOfBytesPerSampleClock = 0;
|
|
dasInfo.MaxEventStorageSpaceInBytes = 0;
|
|
dasInfo.OwningDAS = DASComm;
|
|
dasInfo.Modules = new InfoResult.Module[0];
|
|
DASComm.SetDASInfo(dasInfo, false);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// describes what to do when connected devices have been discovered
|
|
/// </summary>
|
|
/// <param name="connectedDevice"></param>
|
|
public delegate void ConnectedDeviceUpdatedDelegate(IDASConnectedDevice[] connectedDevice);
|
|
/// <summary>
|
|
/// handler for when discovered devices are found
|
|
/// </summary>
|
|
protected ConnectedDeviceUpdatedDelegate ConnectedDeviceUpdated { get; private set; }
|
|
|
|
/// <summary>
|
|
/// constructor
|
|
/// </summary>
|
|
/// <param name="_utilMode"></param>
|
|
/// <param name="updatedDelegate">function to call when connected devices are discovered</param>
|
|
public EthernetSlice6DBHandling(bool _utilMode, ConnectedDeviceUpdatedDelegate updatedDelegate = null)
|
|
: base(_utilMode)
|
|
{
|
|
ConnectedDeviceUpdated = updatedDelegate;
|
|
}
|
|
|
|
public override ICommunication GetICommunication()
|
|
{
|
|
var com = new EthernetSlice6DB();
|
|
com.OnDisconnected += Com_OnDisconnected;
|
|
return com;
|
|
}
|
|
|
|
private void Com_OnDisconnected(object sender, EventArgs e)
|
|
{
|
|
_handler.ReportDisconnect(sender);
|
|
}
|
|
|
|
public override ICommunication GetICommunication(ConnectedDevice dev)
|
|
{
|
|
return (dev.Dev as ConnectedEthernetSlice6DB).Comm;
|
|
}
|
|
|
|
public override IConnectedDevice GetIConnectedDevice(DTS.Common.Interface.DASFactory.ICommunication comm)
|
|
{
|
|
return new ConnectedEthernetSlice6DB(comm as EthernetSlice6DB);
|
|
}
|
|
|
|
public IConnectedDevice GetIConnectedSDBDevice(DTS.Common.Interface.DASFactory.ICommunication comm)
|
|
{
|
|
return new ConnectedEthernetSlice6DB(comm as EthernetSlice6DB);
|
|
}
|
|
|
|
public override bool IsCorrectType(ConnectedDevice dev)
|
|
{
|
|
return dev.Dev is ConnectedEthernetSlice6;
|
|
}
|
|
|
|
public override DFConstantsAndEnums.DASType GetDASType()
|
|
{
|
|
return DFConstantsAndEnums.DASType.ETHERNET_SLICE6DB;
|
|
}
|
|
|
|
public override Guid GetGuid()
|
|
{
|
|
return Guid.Empty;
|
|
}
|
|
|
|
public override bool QueryInformation(ConnectedDevice dev)
|
|
{
|
|
// don't assume anything...
|
|
if (dev == null || dev.Dev == null || string.IsNullOrEmpty(dev.Dev.ConnectString))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed1");
|
|
return false;
|
|
}
|
|
if (!(dev.Dev is IConnectedDAS) || !((dev.Dev as IConnectedDAS).DASComm is ICommunication) ||
|
|
!((dev.Dev as IConnectedDAS).DASComm is IDASCommunication))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed2");
|
|
return false;
|
|
}
|
|
|
|
// make shortcuts
|
|
var CommDev = (dev.Dev as IConnectedDAS).DASComm as ICommunication;
|
|
var DevName = dev.Dev.ConnectString;
|
|
|
|
try
|
|
{
|
|
|
|
// First get protocol version ...
|
|
ReadProtocolVersion(CommDev, DevName);
|
|
|
|
// check how stack is configured
|
|
SetupDASInfo(CommDev, DevName);
|
|
|
|
try
|
|
{
|
|
if (dev.Dev is IConnectedDAS idas)
|
|
{
|
|
idas.DASComm?.ReadFirstUseDate();
|
|
}
|
|
}
|
|
catch (Exception ex) { APILogger.Log(ex); }
|
|
|
|
if ((dev.Dev as IConnectedDAS).DASComm.IsEthernetDistributor())
|
|
{
|
|
return true;
|
|
}
|
|
// now pickup some stuff for the log
|
|
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
try
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation exception: " + DevName);
|
|
APILogger.LogException(ex);
|
|
|
|
if (IsInUpdateMode(CommDev, DevName))
|
|
{
|
|
var dasInfo = new InfoResult();
|
|
dasInfo.MaxNumberOfModules = 10;
|
|
dasInfo.Modules = new InfoResult.Module[0];
|
|
(dev.Dev as IConnectedDAS).DASComm.SetDASInfo(dasInfo, false);
|
|
dev.InUpdateMode = true;
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
catch (Exception eex)
|
|
{
|
|
APILogger.LogString("DASFactory.QuerySliceInformation.EX exception: " +
|
|
dev.Dev.ConnectString);
|
|
APILogger.LogException(eex);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected override void SetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name)
|
|
{
|
|
ResetupDASInfo(dev, name, UtilityMode, ConnectedDeviceUpdated);
|
|
ReadCalDates(dev);
|
|
}
|
|
|
|
protected override void ReadCalDates(DTS.Common.Interface.DASFactory.ICommunication dev)
|
|
{
|
|
if (!(dev is IDASCommunication dasComm)) { return; }
|
|
|
|
if (!RunTestVariables.QueryCalDateInRunTest && RunTestVariables.InRunTest)
|
|
{
|
|
dasComm.DASInfo.CalibrationDate = null;
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
var qsa = new QuerySystemAttributeSLICE6DB(dev)
|
|
{
|
|
Key = AttributeTypes.SystemAttributesSLICE6DB.CalibrationDaysSince1970_01_01
|
|
};
|
|
qsa.SyncExecute();
|
|
|
|
var days = DataConditioning.GetIntegerIfPossible(qsa.Value);
|
|
dasComm.DASInfo.CalibrationDate = new DateTime(1970, 1, 1).AddDays(days);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (!ex.Message.Contains("StatusAttributeNotRegistered"))
|
|
{
|
|
APILogger.Log(ex);
|
|
}
|
|
dasComm.DASInfo.CalibrationDate = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
internal class EthernetPowerProHandling : EthernetSlice6DBHandling
|
|
{
|
|
public EthernetPowerProHandling(bool _utilMode)
|
|
: base(_utilMode)
|
|
{
|
|
}
|
|
|
|
public override ICommunication GetICommunication()
|
|
{
|
|
var com = new EthernetPowerPro();
|
|
com.OnDisconnected += Com_OnDisconnected;
|
|
return com;
|
|
}
|
|
|
|
private void Com_OnDisconnected(object sender, EventArgs e)
|
|
{
|
|
_handler.ReportDisconnect(sender);
|
|
}
|
|
|
|
public override ICommunication GetICommunication(ConnectedDevice dev)
|
|
{
|
|
return (dev.Dev as ConnectedEthernetPowerPro).Comm;
|
|
}
|
|
|
|
public override IConnectedDevice GetIConnectedDevice(ICommunication comm)
|
|
{
|
|
return new ConnectedEthernetPowerPro(comm as EthernetPowerPro);
|
|
}
|
|
public IConnectedDevice GetIConnectedSDBDevice(ICommunication comm)
|
|
{
|
|
return new ConnectedEthernetSDB(comm as EthernetSliceDB);
|
|
}
|
|
public override bool IsCorrectType(ConnectedDevice dev)
|
|
{
|
|
return dev.Dev is ConnectedEthernetPowerPro;
|
|
}
|
|
|
|
public override DFConstantsAndEnums.DASType GetDASType()
|
|
{
|
|
return DFConstantsAndEnums.DASType.ETHERNET_POWERPRO;
|
|
}
|
|
}
|
|
|
|
public class EthernetTsrAirHandling : WinUSBTsrAirHandling
|
|
{
|
|
public EthernetTsrAirHandling(bool _utilMode)
|
|
: base(_utilMode)
|
|
{
|
|
}
|
|
|
|
public override ICommunication GetICommunication()
|
|
{
|
|
var es = new EthernetTsrAir();
|
|
es.OnDisconnected += Es_OnDisconnected;
|
|
return es;
|
|
}
|
|
|
|
private void Es_OnDisconnected(object sender, EventArgs e)
|
|
{
|
|
_handler.ReportDisconnect(sender);
|
|
}
|
|
|
|
public override ICommunication GetICommunication(ConnectedDevice dev)
|
|
{
|
|
return (dev.Dev as ConnectedEthernetTsrAir).Comm;
|
|
}
|
|
|
|
public override IConnectedDevice GetIConnectedDevice(DTS.Common.Interface.DASFactory.ICommunication comm)
|
|
{
|
|
return new ConnectedEthernetTsrAir(comm as EthernetTsrAir);
|
|
}
|
|
public IConnectedDevice GetIConnectedSDBDevice(DTS.Common.Interface.DASFactory.ICommunication comm)
|
|
{
|
|
return new ConnectedEthernetSDB(comm as EthernetSliceDB);
|
|
}
|
|
public override bool IsCorrectType(ConnectedDevice dev)
|
|
{
|
|
return dev.Dev is ConnectedEthernetTsrAir;
|
|
}
|
|
|
|
public override DFConstantsAndEnums.DASType GetDASType()
|
|
{
|
|
return DFConstantsAndEnums.DASType.ETHERNET_TSR_AIR;
|
|
}
|
|
|
|
public override Guid GetGuid()
|
|
{
|
|
return Guid.Empty;
|
|
}
|
|
public override bool QueryInformation(ConnectedDevice dev)
|
|
{
|
|
// don't assume anything...
|
|
if (dev == null || dev.Dev == null || string.IsNullOrEmpty(dev.Dev.ConnectString))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed1");
|
|
return false;
|
|
}
|
|
if (!(dev.Dev is IConnectedDAS) || !((dev.Dev as IConnectedDAS).DASComm is ICommunication) ||
|
|
!((dev.Dev as IConnectedDAS).DASComm is IDASCommunication))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed2");
|
|
return false;
|
|
}
|
|
|
|
// make shortcuts
|
|
var CommDev = (dev.Dev as IConnectedDAS).DASComm as ICommunication;
|
|
var DevName = dev.Dev.ConnectString;
|
|
|
|
|
|
try
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: " + DevName);
|
|
|
|
// First get protocol version ...
|
|
ReadProtocolVersion(CommDev, DevName);
|
|
|
|
// check how stack is configured
|
|
SetupDASInfo(CommDev, DevName);
|
|
try
|
|
{
|
|
if (dev.Dev is IConnectedDAS idas)
|
|
{
|
|
idas.DASComm?.ReadFirstUseDate();
|
|
if (CommDev.IsCommandSupported(DFConstantsAndEnums.ProtocolLimitedCommands.DisableStreamingFeature))
|
|
{
|
|
idas.DASComm?.SetIsStreamingSupported();
|
|
}
|
|
else
|
|
{
|
|
idas.DASComm?.SetIsStreamingSupported(true);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex) { APILogger.Log(ex); }
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.RaiseError($"{APILogger.GetCurrentMethod()} Connection:{DevName} failed Message:{ex.Message}");
|
|
try
|
|
{
|
|
if (ex is System.Net.Sockets.SocketException
|
|
|| ex is CommandException)
|
|
{
|
|
APILogger.LogString(string.Format("{0} Connection:{1} Message:{2}", APILogger.GetCurrentMethod(), DevName, ex.Message));
|
|
}
|
|
|
|
if (IsInUpdateMode(CommDev, DevName))
|
|
{
|
|
var dasInfo = new InfoResult();
|
|
dasInfo.MaxNumberOfModules = 10;
|
|
dasInfo.Modules = new InfoResult.Module[0];
|
|
(dev.Dev as IConnectedDAS).DASComm.SetDASInfo(dasInfo, false);
|
|
dev.InUpdateMode = true;
|
|
return true;
|
|
}
|
|
APILogger.LogException(ex);
|
|
return false;
|
|
}
|
|
catch (Exception eex)
|
|
{
|
|
APILogger.LogString("DASFactory.QuerySliceInformation.EX exception: " + dev.Dev.ConnectString);
|
|
APILogger.LogException(eex);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
public new static void ResetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name, bool UtilityMode)
|
|
{
|
|
TSRAirBaseClass.ResetupDASInfo(dev, name, UtilityMode);
|
|
}
|
|
protected override void SetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name)
|
|
{
|
|
ResetupDASInfo(dev, name, UtilityMode);
|
|
ReadCalDates(dev);
|
|
|
|
}
|
|
protected override void ReadCalDates(DTS.Common.Interface.DASFactory.ICommunication dev)
|
|
{
|
|
if (!(dev is IDASCommunication dasComm)) { return; }
|
|
if (!RunTestVariables.QueryCalDateInRunTest && RunTestVariables.InRunTest)
|
|
{
|
|
dasComm.DASInfo.CalibrationDate = null;
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
if (dasComm.GetIsStreaming())
|
|
{
|
|
//15949 S6A when streaming does a whole bunch of unnecessary queries
|
|
//avoid getting cal dates while streaming, it will fail
|
|
}
|
|
else
|
|
{
|
|
var qsa = new QuerySystemAttributeSLICE6(dev)
|
|
{
|
|
Key = AttributeTypes.SystemAttributesSLICE6.CalibrationDaysSince1970_01_01
|
|
};
|
|
qsa.SyncExecute();
|
|
|
|
var days = DataConditioning.GetIntegerIfPossible(qsa.Value);
|
|
dasComm.DASInfo.CalibrationDate = new DateTime(1970, 1, 1).AddDays(days);
|
|
try
|
|
{
|
|
var qsaB = new QuerySystemAttribute_BridgeSlice6(dev)
|
|
{
|
|
DeviceID = Convert.ToByte(1),
|
|
Key = AttributeTypes.SystemAttributes_BridgeSlice6.CalibrationDaysSince1970_01_01
|
|
};
|
|
qsaB.SyncExecute();
|
|
|
|
days = DataConditioning.GetIntegerIfPossible(qsaB.Value);
|
|
dasComm.DASInfo.Modules[0].CalibrationDate = new DateTime(1970, 1, 1).AddDays(days);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.Log(ex);
|
|
dasComm.DASInfo.Modules[0].CalibrationDate = null;
|
|
}
|
|
|
|
foreach (var module in dasComm.DASInfo.Modules)
|
|
{
|
|
if (null == module)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
module.CalibrationDate = new DateTime(1970, 1, 1).AddDays(days);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (!ex.Message.Contains("StatusAttributeNotRegistered"))
|
|
{
|
|
APILogger.Log(ex);
|
|
}
|
|
|
|
dasComm.DASInfo.CalibrationDate = null;
|
|
}
|
|
finally
|
|
{
|
|
dasComm.SetDASInfo();
|
|
}
|
|
}
|
|
}
|
|
|
|
internal class EthernetSlice6DB3Handling : EthernetSlice6DBHandling
|
|
{
|
|
public EthernetSlice6DB3Handling(bool _utilMode, EthernetSlice6DBHandling.ConnectedDeviceUpdatedDelegate updatedDelegate = null)
|
|
: base(_utilMode, updatedDelegate)
|
|
{
|
|
}
|
|
|
|
public override ICommunication GetICommunication()
|
|
{
|
|
var com = new EthernetSlice6DB3();
|
|
com.OnDisconnected += Com_OnDisconnected;
|
|
return com;
|
|
}
|
|
|
|
private void Com_OnDisconnected(object sender, EventArgs e)
|
|
{
|
|
_handler.ReportDisconnect(sender);
|
|
}
|
|
|
|
public override ICommunication GetICommunication(ConnectedDevice dev)
|
|
{
|
|
return (dev.Dev as ConnectedEthernetSlice6DB3).Comm;
|
|
}
|
|
|
|
public override IConnectedDevice GetIConnectedDevice(ICommunication comm)
|
|
{
|
|
return new ConnectedEthernetSlice6DB3(comm as EthernetSlice6DB3);
|
|
}
|
|
public new IConnectedDevice GetIConnectedSDBDevice(ICommunication comm)
|
|
{
|
|
return new ConnectedEthernetSlice6DB3(comm as EthernetSlice6DB3);
|
|
}
|
|
public override bool IsCorrectType(ConnectedDevice dev)
|
|
{
|
|
return dev.Dev is ConnectedEthernetSlice6DB3;
|
|
}
|
|
|
|
public override DFConstantsAndEnums.DASType GetDASType()
|
|
{
|
|
return DFConstantsAndEnums.DASType.ETHERNET_SLICE6DB3;
|
|
}
|
|
}
|
|
internal class EthernetSliceProDBHandling : EthernetSlice6DBHandling
|
|
{
|
|
public EthernetSliceProDBHandling(bool _utilMode, ConnectedDeviceUpdatedDelegate updatedDelegate = null)
|
|
: base(_utilMode, updatedDelegate)
|
|
{
|
|
}
|
|
|
|
public override ICommunication GetICommunication()
|
|
{
|
|
var com = new EthernetSlicePRODB();
|
|
com.OnDisconnected += Com_OnDisconnected;
|
|
return com;
|
|
}
|
|
|
|
private void Com_OnDisconnected(object sender, EventArgs e)
|
|
{
|
|
_handler.ReportDisconnect(sender);
|
|
}
|
|
|
|
public override ICommunication GetICommunication(ConnectedDevice dev)
|
|
{
|
|
return (dev.Dev as ConnectedEthernetSliceProDB).Comm;
|
|
}
|
|
|
|
public override IConnectedDevice GetIConnectedDevice(ICommunication comm)
|
|
{
|
|
return new ConnectedEthernetSliceProDB(comm as EthernetSlicePRODB);
|
|
}
|
|
public new IConnectedDevice GetIConnectedSDBDevice(ICommunication comm)
|
|
{
|
|
return new ConnectedEthernetSliceProDB(comm as EthernetSlicePRODB);
|
|
}
|
|
public override bool IsCorrectType(ConnectedDevice dev)
|
|
{
|
|
return dev.Dev is ConnectedEthernetSliceProDB;
|
|
}
|
|
|
|
public override DFConstantsAndEnums.DASType GetDASType()
|
|
{
|
|
return DFConstantsAndEnums.DASType.ETHERNET_SLICEPRODB;
|
|
}
|
|
}
|
|
internal class EthernetSlice1_5Handling : WinUSBSlice1_5Handling
|
|
{
|
|
public EthernetSlice1_5Handling(bool _utilMode)
|
|
: base(_utilMode)
|
|
{
|
|
}
|
|
|
|
public override ICommunication GetICommunication()
|
|
{
|
|
return new EthernetSlice1_5();
|
|
}
|
|
|
|
public override ICommunication GetICommunication(ConnectedDevice dev)
|
|
{
|
|
return (dev.Dev as ConnectedEthernetSlice1_5).Comm;
|
|
}
|
|
|
|
public override IConnectedDevice GetIConnectedDevice(DTS.Common.Interface.DASFactory.ICommunication comm)
|
|
{
|
|
return new ConnectedEthernetSlice1_5(comm as EthernetSlice1_5);
|
|
}
|
|
public IConnectedDevice GetIConnectedSDBDevice(DTS.Common.Interface.DASFactory.ICommunication comm)
|
|
{
|
|
return new ConnectedEthernetSDB(comm as EthernetSliceDB);
|
|
}
|
|
public override bool IsCorrectType(ConnectedDevice dev)
|
|
{
|
|
return dev.Dev is ConnectedEthernetSlice1_5;
|
|
}
|
|
|
|
public override DFConstantsAndEnums.DASType GetDASType()
|
|
{
|
|
return DFConstantsAndEnums.DASType.ETHERNET_SLICE1_5;
|
|
}
|
|
|
|
public override Guid GetGuid()
|
|
{
|
|
return Guid.Empty;
|
|
}
|
|
public override bool QueryInformation(ConnectedDevice dev)
|
|
{
|
|
// don't assume anything...
|
|
if (dev == null || dev.Dev == null || string.IsNullOrEmpty(dev.Dev.ConnectString))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed1");
|
|
return false;
|
|
}
|
|
if (!(dev.Dev is IConnectedDAS) || !((dev.Dev as IConnectedDAS).DASComm is ICommunication) ||
|
|
!((dev.Dev as IConnectedDAS).DASComm is IDASCommunication))
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: Invalid parameter passed2");
|
|
return false;
|
|
}
|
|
|
|
// make shortcuts
|
|
var CommDev = (dev.Dev as IConnectedDAS).DASComm as ICommunication;
|
|
var DevName = dev.Dev.ConnectString;
|
|
|
|
|
|
try
|
|
{
|
|
APILogger.LogString("SliceHandling.QueryInformation: " + DevName);
|
|
|
|
// First get protocol version ...
|
|
ReadProtocolVersion(CommDev, DevName);
|
|
|
|
// check how stack is configured
|
|
SetupDASInfo(CommDev, DevName);
|
|
|
|
try
|
|
{
|
|
if (dev.Dev is IConnectedDAS idas)
|
|
{
|
|
idas.DASComm?.ReadFirstUseDate();
|
|
}
|
|
}
|
|
catch (Exception ex) { APILogger.Log(ex); }
|
|
if ((dev.Dev as IConnectedDAS).DASComm.IsEthernetDistributor()) { return true; }
|
|
// now pickup some stuff for the log
|
|
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
try
|
|
{
|
|
if (ex is System.Net.Sockets.SocketException
|
|
|| ex is CommandException)
|
|
{
|
|
APILogger.LogString(string.Format("{0} Connection:{1} Message:{2}", APILogger.GetCurrentMethod(), DevName, ex.Message));
|
|
}
|
|
|
|
if (IsInUpdateMode(CommDev, DevName))
|
|
{
|
|
var dasInfo = new InfoResult
|
|
{
|
|
MaxNumberOfModules = 10,
|
|
Modules = new InfoResult.Module[0]
|
|
};
|
|
(dev.Dev as IConnectedDAS).DASComm.SetDASInfo(dasInfo, false);
|
|
dev.InUpdateMode = true;
|
|
return true;
|
|
}
|
|
APILogger.LogException(ex);
|
|
return false;
|
|
}
|
|
catch (Exception eex)
|
|
{
|
|
APILogger.LogString("DASFactory.QuerySliceInformation.EX exception: " + dev.Dev.ConnectString);
|
|
APILogger.LogException(eex);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
protected override void SetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name)
|
|
{
|
|
ResetupDASInfo(dev, name, UtilityMode);
|
|
ReadCalDates(dev);
|
|
}
|
|
}
|
|
public class EthernetSlice6AirThermocouplerHandling : WinUSBSlice6AirThermocouplerHandling
|
|
{
|
|
protected new const uint MaxNumberOfModules = 3; //"new" so we don't hide what is inherited from SliceHandling
|
|
public EthernetSlice6AirThermocouplerHandling(bool _utilMode)
|
|
: base(_utilMode)
|
|
{
|
|
}
|
|
|
|
private void Es_OnDisconnected(object sender, EventArgs e)
|
|
{
|
|
_handler.ReportDisconnect(sender);
|
|
}
|
|
|
|
public override ICommunication GetICommunication()
|
|
{
|
|
var es = new EthernetSlice6AirThermocoupler();
|
|
es.OnDisconnected += Es_OnDisconnected;
|
|
return es;
|
|
}
|
|
|
|
public override ICommunication GetICommunication(ConnectedDevice dev)
|
|
{
|
|
return (dev.Dev as ConnectedEthernetSlice6AirThermocoupler).Comm;
|
|
}
|
|
|
|
public override IConnectedDevice GetIConnectedDevice(ICommunication comm)
|
|
{
|
|
return new ConnectedEthernetSlice6AirThermocoupler(comm as EthernetSlice6AirThermocoupler);
|
|
}
|
|
public IConnectedDevice GetIConnectedSlice6AirThermocouplerDevice(ICommunication comm)
|
|
{
|
|
return new ConnectedEthernetSlice6AirThermocoupler(comm as EthernetSlice6AirThermocoupler);
|
|
}
|
|
public override bool IsCorrectType(ConnectedDevice dev)
|
|
{
|
|
return dev.Dev is ConnectedEthernetSlice6AirThermocoupler;
|
|
}
|
|
|
|
public override DFConstantsAndEnums.DASType GetDASType()
|
|
{
|
|
return DFConstantsAndEnums.DASType.ETHERNET_SLICE6AIR_TC;
|
|
}
|
|
|
|
public override Guid GetGuid()
|
|
{
|
|
return Guid.Empty;
|
|
}
|
|
public override bool QueryInformation(ConnectedDevice dev)
|
|
{
|
|
// don't assume anything...
|
|
if (dev == null || dev.Dev == null || string.IsNullOrEmpty(dev.Dev.ConnectString))
|
|
{
|
|
APILogger.LogString("Slice6AirThermocouplerHandling.QueryInformation: Invalid parameter passed1");
|
|
return false;
|
|
}
|
|
if (!(dev.Dev is IConnectedDAS) || !((dev.Dev as IConnectedDAS).DASComm is ICommunication) ||
|
|
!((dev.Dev as IConnectedDAS).DASComm is IDASCommunication))
|
|
{
|
|
APILogger.LogString("Slice6AirThermocouplerHandling.QueryInformation: Invalid parameter passed2");
|
|
return false;
|
|
}
|
|
|
|
// make shortcuts
|
|
var CommDev = (dev.Dev as IConnectedDAS).DASComm as ICommunication;
|
|
var DevName = dev.Dev.ConnectString;
|
|
|
|
|
|
try
|
|
{
|
|
|
|
// First get protocol version ...
|
|
ReadProtocolVersion(CommDev, DevName);
|
|
|
|
// check how stack is configured
|
|
SetupDASInfo(CommDev, DevName);
|
|
try
|
|
{
|
|
if (dev.Dev is IConnectedDAS idas)
|
|
{
|
|
idas.DASComm?.ReadFirstUseDate();
|
|
idas.DASComm?.SetIsStreamingSupported();
|
|
}
|
|
}
|
|
catch (Exception ex) { APILogger.Log(ex); }
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
try
|
|
{
|
|
if (ex is System.Net.Sockets.SocketException
|
|
|| ex is CommandException)
|
|
{
|
|
APILogger.LogString(string.Format("{0} Connection:{1} Message:{2}", APILogger.GetCurrentMethod(), DevName, ex.Message));
|
|
}
|
|
|
|
if (IsInUpdateMode(CommDev, DevName))
|
|
{
|
|
var dasInfo = new InfoResult();
|
|
dasInfo.NumberOfBridgeChannels = 8;
|
|
dasInfo.MaxNumberOfModules = 10;
|
|
dasInfo.Modules = new InfoResult.Module[0];
|
|
(dev.Dev as IConnectedDAS).DASComm.SetDASInfo(dasInfo, false);
|
|
dev.InUpdateMode = true;
|
|
return true;
|
|
}
|
|
APILogger.LogException(ex);
|
|
return false;
|
|
}
|
|
catch (Exception eex)
|
|
{
|
|
APILogger.LogString("DASFactory.QuerySlice6AirThermocouplerHandlingInformation.EX exception: " + dev.Dev.ConnectString);
|
|
APILogger.LogException(eex);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
public static void ResetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name, bool UtilityMode)
|
|
{
|
|
// shortcut
|
|
var dasComm = dev as IDASCommunication;
|
|
|
|
try
|
|
{
|
|
// get the stack contents
|
|
var StackQuery = new QueryStackContents(dev);
|
|
StackQuery.SyncExecute();
|
|
|
|
// serialnumbers and firmware versions
|
|
dev.FirmwareVersion = StackQuery.FirmwareVersion[0];
|
|
dasComm.SerialNumber = StackQuery.SerialNumber[0];
|
|
|
|
WinUSBSlice2Handling.CheckInBootloaderMode(dev);
|
|
|
|
dev.DASInfo = new Communication_DASInfo(StackQuery.SerialNumber, StackQuery.FirmwareVersion);
|
|
|
|
var streamOutCount = 1;
|
|
|
|
// create and fill in InfoResult
|
|
var dasInfo = new InfoResult
|
|
{
|
|
MaxNumberOfModules = MaxNumberOfModules,
|
|
NumberOfBytesPerSampleClock = (uint)(6 * (StackQuery.SliceCount - 1)),
|
|
OwningDAS = dasComm,
|
|
Modules = new InfoResult.Module[StackQuery.SliceCount + streamOutCount + 1 /*uart*/ - 1],
|
|
NumberOfBridgeChannels = 8
|
|
};
|
|
|
|
// construct module info
|
|
for (var sliceIdx = 0; sliceIdx < StackQuery.SliceCount - 1; sliceIdx++)
|
|
{
|
|
var module = new InfoResult.Module
|
|
{
|
|
ModuleArrayIndex = sliceIdx,
|
|
OwningInfoResult = dasInfo,
|
|
MaxEventStorageSpaceInBytes = null,
|
|
NumberOfBytesPerSampleClock = null,
|
|
NumberOfChannels = SLICE6AIRTC.ThermocouplersPerModule,
|
|
SerialNumber = StackQuery.SerialNumber[sliceIdx + 1],
|
|
FirmwareVersion = StackQuery.FirmwareVersion[sliceIdx + 1],
|
|
SupportedSampleRates = (uint[])SamplerateList.Clone()
|
|
};
|
|
SetRecordingModes(module, dev);
|
|
|
|
module.IsProgrammable = false;
|
|
|
|
module.TypeOfModule = DFConstantsAndEnums.ModuleType.Thermocoupler;
|
|
module.SampleRate2AAFrequency = Samplerate2AAFilterDict;
|
|
dasInfo.Modules[sliceIdx] = module;
|
|
}
|
|
|
|
//then add streamout
|
|
for (var sliceIdx = 0; sliceIdx < streamOutCount; sliceIdx++)
|
|
{
|
|
var streamOutModule = new InfoResult.Module
|
|
{
|
|
ModuleArrayIndex = StackQuery.SliceCount - 1 + sliceIdx,
|
|
OwningInfoResult = dasInfo,
|
|
MaxEventStorageSpaceInBytes = null,
|
|
NumberOfBytesPerSampleClock = null,
|
|
NumberOfChannels = 1,
|
|
SerialNumber = $"StreamOut {sliceIdx + 1}",
|
|
FirmwareVersion = StackQuery.FirmwareVersion[0],
|
|
SupportedModes = new DFConstantsAndEnums.RecordingMode[0],
|
|
SupportedSampleRates = new uint[0],
|
|
IsProgrammable = false,
|
|
TypeOfModule = DFConstantsAndEnums.ModuleType.StreamOut
|
|
};
|
|
dasInfo.Modules[StackQuery.SliceCount - 1 + sliceIdx] = streamOutModule;
|
|
}
|
|
AddUart(dasInfo);
|
|
|
|
// attach the structure to the DAS
|
|
dasComm.SetDASInfo(dasInfo);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.LogString("SliceHandling.SetupDASInfo exception: " + name);
|
|
APILogger.LogException(ex);
|
|
|
|
// if we're not in util mode we bail out
|
|
if (!UtilityMode)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
// if we are, we must fill in something
|
|
// dev.FirmwareVersion
|
|
// DASComm.SerialNumber
|
|
// dev.DASInfo
|
|
// DASComm.DASInfo
|
|
dev.FirmwareVersion = "UNKNOWN";
|
|
dasComm.SerialNumber = "UNKNOWN";
|
|
dev.DASInfo = new Communication_DASInfo
|
|
{
|
|
SerialNumbers = new[] { dasComm.SerialNumber },
|
|
FirmwareVersions = new[] { dev.FirmwareVersion }
|
|
};
|
|
|
|
var dasInfo = new InfoResult
|
|
{
|
|
MaxNumberOfModules = MaxNumberOfModules,
|
|
NumberOfBytesPerSampleClock = 0,
|
|
MaxEventStorageSpaceInBytes = 0,
|
|
OwningDAS = dasComm,
|
|
Modules = new InfoResult.Module[0]
|
|
};
|
|
dasComm.SetDASInfo(dasInfo, false);
|
|
}
|
|
}
|
|
private static void AddUart(InfoResult dasInfo)
|
|
{
|
|
if (null == dasInfo) { return; }
|
|
if (null == dasInfo.Modules || 0 == dasInfo.Modules.Length) { return; }
|
|
var module = new InfoResult.Module
|
|
{
|
|
ModuleArrayIndex = dasInfo.Modules.Length-1,
|
|
OwningInfoResult = dasInfo,
|
|
MaxEventStorageSpaceInBytes = null,
|
|
NumberOfBytesPerSampleClock = null,
|
|
NumberOfChannels = 1,
|
|
SerialNumber = $"{DFConstantsAndEnums.UART_SERIAL_APPEND} {1}",
|
|
FirmwareVersion = dasInfo.Modules[0].FirmwareVersion,
|
|
SupportedModes = new DFConstantsAndEnums.RecordingMode[0],
|
|
SupportedSampleRates = new uint[0],
|
|
IsProgrammable = false,
|
|
TypeOfModule = DFConstantsAndEnums.ModuleType.UART
|
|
};
|
|
dasInfo.Modules[dasInfo.Modules.Length-1] = module;
|
|
}
|
|
protected override void SetupDASInfo(DTS.Common.Interface.DASFactory.ICommunication dev, string name)
|
|
{
|
|
ResetupDASInfo(dev, name, UtilityMode);
|
|
ReadCalDates(dev);
|
|
}
|
|
private static DateTime DATE_TIME_1970 = new DateTime(1970, 1, 1);
|
|
protected override void ReadCalDates(DTS.Common.Interface.DASFactory.ICommunication dev)
|
|
{
|
|
if (!(dev is IDASCommunication dasComm)) { return; }
|
|
if (!RunTestVariables.QueryCalDateInRunTest && RunTestVariables.InRunTest)
|
|
{
|
|
dasComm.DASInfo.CalibrationDate = null;
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
var qsa = new QuerySystemAttributeSLICE6(dev)
|
|
{
|
|
Key = AttributeTypes.SystemAttributesSLICE6.CalibrationDaysSince1970_01_01
|
|
};
|
|
qsa.SyncExecute();
|
|
|
|
var days = Convert.ToInt32(qsa.Value);
|
|
dasComm.DASInfo.CalibrationDate = DATE_TIME_1970.AddDays(days);
|
|
|
|
foreach (var module in dasComm.DASInfo.Modules)
|
|
{
|
|
if (null == module)
|
|
{
|
|
continue;
|
|
}
|
|
module.CalibrationDate = DATE_TIME_1970.AddDays(days);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (!ex.Message.Contains("StatusAttributeNotRegistered"))
|
|
{
|
|
APILogger.Log(ex);
|
|
}
|
|
dasComm.DASInfo.CalibrationDate = null;
|
|
}
|
|
}
|
|
}
|
|
}
|