Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion source/TS.NET.Engine/EngineManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,21 +188,25 @@ public bool TryStart(string settingsFile, string calibrationFile, string deviceS
{
logger?.LogInformation($"Calibration loaded from path: {calibrationFile}");
loadedCalibration = Calibration.FromJsonFile(calibrationFile);
ts.SetCalibration(loadedCalibration);
}
else if (ThunderscopeNonVolatileMemory.TryReadUserCalibration(ts, out var userCalibration))
{
logger?.LogInformation($"Calibration loaded from user calibration memory");
loadedCalibration = userCalibration!;
ts.SetCalibration(loadedCalibration);
}
else if (ThunderscopeNonVolatileMemory.TryReadFactoryCalibration(ts, out var factoryCalibration))
{
logger?.LogInformation($"Calibration loaded from factory calibration memory");
loadedCalibration = factoryCalibration!;
// Factory Calibration loaded by tslitex
}
else if (File.Exists("thunderscope-calibration.json"))
{
logger?.LogInformation($"Calibration loaded from thunderscope-calibration.json");
loadedCalibration = Calibration.FromJsonFile("thunderscope-calibration.json");
ts.SetCalibration(loadedCalibration);
}
else
{
Expand All @@ -225,7 +229,7 @@ public bool TryStart(string settingsFile, string calibrationFile, string deviceS
initialHardwareConfiguration.ExtSyncMode = ThunderscopeExtSyncMode.Disabled;
initialHardwareConfiguration.RefClockMode = ThunderscopeRefClockMode.Disabled;
initialHardwareConfiguration.RefClockFrequencyHz = 10_000_000;
ts.Configure(initialHardwareConfiguration, loadedCalibration, thunderscopeSettings.HardwareRevision);
ts.Configure(initialHardwareConfiguration);
ts.StartMonitoring();
thunderscope = ts;
break;
Expand Down
10 changes: 5 additions & 5 deletions source/TS.NET.Sequences/Singletons/Instruments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public string Initialise()
hardwareConfig.Frontend[3] = ThunderscopeChannelFrontend.Default();
thunderScope = new Driver.Libtslitex.Thunderscope(loggerFactory, 1024 * 1024);
thunderScope.Open(0);
thunderScope.Configure(hardwareConfig, Calibration.Default(), "");
thunderScope.Configure(hardwareConfig);
// Need to set manual control on all channels so that SetRate doesn't run normal logic
var manualControl = new ThunderscopeChannelFrontendManualControl() { Coupling = ThunderscopeCoupling.DC, Termination = ThunderscopeTermination.OneMegaohm, Attenuator = 0, DAC = 2000, DPOT = 50, PgaLadderAttenuation = 0, PgaFilter = ThunderscopeBandwidth.Bw20M, PgaHighGain = 0 };
thunderScope.SetChannelManualControl(0, manualControl);
Expand Down Expand Up @@ -144,10 +144,10 @@ public void SetThunderscopeChannel(int[] enabledChannelIndices)
{
if (!enabledChannelIndices.SequenceEqual(cachedChannelIndices))
{
thunderScope?.SetChannelEnable(0, enabledChannelIndices.Contains(0), updateFrontends: false);
thunderScope?.SetChannelEnable(1, enabledChannelIndices.Contains(1), updateFrontends: false);
thunderScope?.SetChannelEnable(2, enabledChannelIndices.Contains(2), updateFrontends: false);
thunderScope?.SetChannelEnable(3, enabledChannelIndices.Contains(3), updateFrontends: false);
thunderScope?.SetChannelEnable(0, enabledChannelIndices.Contains(0));
thunderScope?.SetChannelEnable(1, enabledChannelIndices.Contains(1));
thunderScope?.SetChannelEnable(2, enabledChannelIndices.Contains(2));
thunderScope?.SetChannelEnable(3, enabledChannelIndices.Contains(3));
cachedSampleRateHz = 0;
cachedChannelIndices = enabledChannelIndices;
}
Expand Down
110 changes: 90 additions & 20 deletions source/TS.NET/Drivers/Libtslitex/Interop/Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,35 +87,99 @@ public struct tsScopeState_t
public byte acq_power_good;
}

[StructLayout(LayoutKind.Sequential)]
public struct tsAfePathCalibration_s
{
public double bufferInputVpp;
public double trimOffsetDacZeroC;
public double trimOffsetDacZeroM;
public double trimOffsetDacScale;
public uint trimDPot;
}

[StructLayout(LayoutKind.Sequential)]
public struct tsChannelCalibration_t
{
public int buffer_uV;
public int bias_uV;
public int attenuatorGain1M_mdB;
public int attenuatorGain50_mdB;
public int bufferGain_mdB;
public int trimRheostat_range;
public int preampLowGainError_mdB;
public int preampHighGainError_mdB;
public double attenuatorScale;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = 11)]
public tsAfePathCalibration_s[] highPgaPathCal;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = 11)]
public tsAfePathCalibration_s[] lowPgaPathCal;

public tsChannelCalibration_t() {
highPgaPathCal = new tsAfePathCalibration_s[11];
lowPgaPathCal = new tsAfePathCalibration_s[11]; }
}

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 11)]
public int[] preampAttenuatorGain_mdB;
public int preampOutputGainError_mdB;
public int preampLowOffset_uV;
public int preampHighOffset_uV;
public int preampInputBias_uA;
[StructLayout(LayoutKind.Sequential)]
public struct tsAdcLoad_t
{
public uint rate;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public double[] scale;

public tsChannelCalibration_t() { preampAttenuatorGain_mdB = new int[11]; }
public tsAdcLoad_t() { scale = new double[4];}
}

[StructLayout(LayoutKind.Sequential)]
public struct tsAdcCalibration_t
public struct tsAdcLoadCal_t
{
public uint channels;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = 8)]
public tsAdcLoad_t[] conf;

public tsAdcLoadCal_t() {
conf = new tsAdcLoad_t[8];
for (var cal = 0; cal < 8; cal++)
{
conf[cal] = new tsAdcLoad_t();
}
}
}

[StructLayout(LayoutKind.Sequential)]
public struct tsAdcGain_t
{
public uint rate;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public byte[] branchFineGain;
public byte[] gain;

public tsAdcCalibration_t() { branchFineGain = new byte[8]; }
public tsAdcGain_t() { gain = new byte[8];}
}

[StructLayout(LayoutKind.Sequential)]
public struct tsAdcGainCal_t
{
public uint channels;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = 8)]
public tsAdcGain_t[] conf;

public tsAdcGainCal_t() {
conf = new tsAdcGain_t[8];
for (var cal = 0; cal < 8; cal++)
{
conf[cal] = new tsAdcGain_t();
}
}
}

[StructLayout(LayoutKind.Sequential)]
public struct tsAdcCalibration_t
{
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = 11)]
public tsAdcLoadCal_t[] loadCal;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = 11)]
public tsAdcGainCal_t[] branchFineGain;

public tsAdcCalibration_t() {
loadCal = new tsAdcLoadCal_t[11];
branchFineGain = new tsAdcGainCal_t[11];
for (var cal = 0; cal < 11; cal++)
{
loadCal[cal] = new tsAdcLoadCal_t();
branchFineGain[cal] = new tsAdcGainCal_t();
}
}
}

public enum tsSampleFormat_t
Expand Down Expand Up @@ -171,7 +235,10 @@ public enum tsSampleFormat_t
public static unsafe partial int UserDataWrite(nint ts, byte* buffer, uint offset, uint writeLen);

[DllImport(library, EntryPoint = "thunderscopeChanCalibrationSet")] // Use runtime marshalling for now. Custom marshalling later.
public static extern int SetCalibration(nint ts, uint channel, in tsChannelCalibration_t cal);
public static extern int SetAFECalibration(nint ts, uint channel, in tsChannelCalibration_t cal);

[DllImport(library, EntryPoint = "thunderscopeAdcCalibrationGet")] // Use runtime marshalling for now. Custom marshalling later.
public static extern int GetAFECalibration(nint ts, uint channel, out tsChannelCalibration_t cal);

[DllImport(library, EntryPoint = "thunderscopeAdcCalibrationSet")] // Use runtime marshalling for now. Custom marshalling later.
public static extern int SetAdcCalibration(nint ts, in tsAdcCalibration_t cal);
Expand All @@ -194,6 +261,9 @@ public struct tsChannelCtrl_t

[LibraryImport(library, EntryPoint = "thunderscopeCalibrationManualCtrl")]
public static unsafe partial int SetChannelManualControl(nint ts, uint channel, in tsChannelCtrl_t ctrl);

[LibraryImport(library, EntryPoint = "thunderscopeCalibrationManualAdcFineGain")]
public static unsafe partial int SetAdcManualFineGain(nint ts, in byte[] ctrl);

public enum tsEventType_t
{
Expand Down
Loading