Skip to content

Commit 25bf389

Browse files
committed
Cache more state & simplify
1 parent a2111b1 commit 25bf389

17 files changed

+65
-163
lines changed

source/TS.NET.Sequencer/Sequence.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,18 @@ public async Task Run(CancellationTokenSource cancellationTokenSource)
5050
overallTermination = true;
5151
break;
5252
}
53+
Steps[i].Result = new StepResult() { Status = Sequencer.Status.Running, Duration = null, Exception = null, Summary = null, Metadata = [] };
5354
PreStep?.Invoke(Steps[i]);
5455
await Task.Run(() => Steps[i].Run(cancellationTokenSource));
5556
PostStep?.Invoke(Steps[i]);
56-
if (!Steps[i].IgnoreError && (Steps[i].Result.Status == Sequencer.Status.Failed || Steps[i].Result.Status == Sequencer.Status.Error || Steps[i].Result.Status == Sequencer.Status.Cancelled))
57+
if (!Steps[i].IgnoreError && (Steps[i].Result!.Status == Sequencer.Status.Failed || Steps[i].Result!.Status == Sequencer.Status.Error || Steps[i].Result!.Status == Sequencer.Status.Cancelled))
5758
break;
5859
}
5960
// Always run Cleanup step if it exists and it didn't run
6061
if (Steps.Any(s => s.Name == "Cleanup" && s.Result == null))
6162
{
6263
var cleanupStep = Steps.First(s => s.Name == "Cleanup");
64+
cleanupStep.Result = new StepResult() { Status = Sequencer.Status.Running, Duration = null, Exception = null, Summary = null, Metadata = [] };
6365
PreStep?.Invoke(cleanupStep);
6466
await Task.Run(() => cleanupStep.Run(cancellationTokenSource));
6567
PostStep?.Invoke(cleanupStep);

source/TS.NET.Sequencer/Step.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public Step(string name)
2626

2727
public void Run(CancellationTokenSource cancellationTokenSource)
2828
{
29-
Result = new StepResult() { Status = Status.Running, Duration = null, Exception = null, Summary = null, Metadata = [] };
29+
// Result is set in Sequence.Run so that the UI shows a Running step with PreStep?.Invoke
3030
var stopwatch = Stopwatch.StartNew();
3131
Status status = Status.Running;
3232
Exception? exception = null;

source/TS.NET.Sequences/Sequences/BenchCalibrationSequence.cs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@ private void AddSteps(Func<Dialog, DialogResult> uiDialog)
2323
new InitialiseDeviceStep("Initialise device", Variables),
2424
new InitialiseSigGensStep("Initialise instruments", Variables),
2525
new LoadUserCalFromDeviceFallbackToFileStep("Load calibration from device/file", Variables),
26-
new WarmupStep("Warmup device", Variables) { Skip = false },
27-
28-
new Step("Set channel 1"){ Action = (CancellationToken cancellationToken) => {
29-
Instruments.Instance.SetThunderscopeChannel([0]);
30-
return Sequencer.Status.Done;
31-
}},
26+
new WarmupStep("Warmup device", Variables) { Skip = true },
3227

3328
new TrimOffsetDacGainStep("Channel 1 - measure trim offset DAC scale - HG L0", 0, 0, Variables) { IgnoreError = true, Timeout = TimeSpan.FromSeconds(30), Retries = 3 },
3429
new TrimOffsetDacGainStep("Channel 1 - measure trim offset DAC scale - HG L1", 0, 1, Variables) { IgnoreError = true, Timeout = TimeSpan.FromSeconds(30), Retries = 3 },
@@ -136,10 +131,6 @@ private void AddSteps(Func<Dialog, DialogResult> uiDialog)
136131

137132
new Step("Disconnect SDG2042X"){ Action = (CancellationToken cancellationToken) => { Instruments.Instance.SetSdgChannel(-1); return Sequencer.Status.Done; }},
138133

139-
new Step("Set channel 2"){ Action = (CancellationToken cancellationToken) => {
140-
Instruments.Instance.SetThunderscopeChannel([1]);
141-
return Sequencer.Status.Done; }},
142-
143134
new TrimOffsetDacGainStep("Channel 2 - measure trim offset DAC scale - HG L0", 1, 0, Variables) { IgnoreError = true, Timeout = TimeSpan.FromSeconds(30), Retries = 3 },
144135
new TrimOffsetDacGainStep("Channel 2 - measure trim offset DAC scale - HG L1", 1, 1, Variables) { IgnoreError = true, Timeout = TimeSpan.FromSeconds(30), Retries = 3 },
145136
new TrimOffsetDacGainStep("Channel 2 - measure trim offset DAC scale - HG L2", 1, 2, Variables) { IgnoreError = true, Timeout = TimeSpan.FromSeconds(30), Retries = 3 },
@@ -244,11 +235,6 @@ private void AddSteps(Func<Dialog, DialogResult> uiDialog)
244235

245236
new Step("Disconnect SDG2042X"){ Action = (CancellationToken cancellationToken) => { Instruments.Instance.SetSdgChannel(-1); return Sequencer.Status.Done; }},
246237

247-
new Step("Set Channel 3"){ Action = (CancellationToken cancellationToken) => {
248-
Instruments.Instance.SetThunderscopeChannel([2]);
249-
return Sequencer.Status.Done;
250-
}},
251-
252238
new TrimOffsetDacGainStep("Channel 3 - measure trim offset DAC scale - HG L0", 2, 0, Variables) { IgnoreError = true, Timeout = TimeSpan.FromSeconds(30), Retries = 3 },
253239
new TrimOffsetDacGainStep("Channel 3 - measure trim offset DAC scale - HG L1", 2, 1, Variables) { IgnoreError = true, Timeout = TimeSpan.FromSeconds(30), Retries = 3 },
254240
new TrimOffsetDacGainStep("Channel 3 - measure trim offset DAC scale - HG L2", 2, 2, Variables) { IgnoreError = true, Timeout = TimeSpan.FromSeconds(30), Retries = 3 },
@@ -353,11 +339,6 @@ private void AddSteps(Func<Dialog, DialogResult> uiDialog)
353339

354340
new Step("Disconnect SDG2042X"){ Action = (CancellationToken cancellationToken) => { Instruments.Instance.SetSdgChannel(-1); return Sequencer.Status.Done; }},
355341

356-
new Step("Set Channel 4"){ Action = (CancellationToken cancellationToken) => {
357-
Instruments.Instance.SetThunderscopeChannel([3]);
358-
return Sequencer.Status.Done;
359-
}},
360-
361342
new TrimOffsetDacGainStep("Channel 4 - measure trim offset DAC scale - HG L0", 3, 0, Variables) { IgnoreError = true, Timeout = TimeSpan.FromSeconds(30), Retries = 3 },
362343
new TrimOffsetDacGainStep("Channel 4 - measure trim offset DAC scale - HG L1", 3, 1, Variables) { IgnoreError = true, Timeout = TimeSpan.FromSeconds(30), Retries = 3 },
363344
new TrimOffsetDacGainStep("Channel 4 - measure trim offset DAC scale - HG L2", 3, 2, Variables) { IgnoreError = true, Timeout = TimeSpan.FromSeconds(30), Retries = 3 },
@@ -462,7 +443,7 @@ private void AddSteps(Func<Dialog, DialogResult> uiDialog)
462443

463444
new Step("Disconnect SDG2042X"){ Action = (CancellationToken cancellationToken) => { Instruments.Instance.SetSdgChannel(-1); return Sequencer.Status.Done; }},
464445

465-
new SaveUserCalToFileStep("Save calibration to file", Variables),
446+
//new SaveUserCalToFileStep("Save calibration to file", Variables),
466447
new SaveUserCalToDeviceStep("Save calibration to device", Variables),
467448

468449
new Step("Cleanup"){ Action = (CancellationToken cancellationToken) => {

source/TS.NET.Sequences/Sequences/BodePlotSequence.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ private void AddSteps(Func<Dialog, DialogResult> uiDialog)
2525
new LoadUserCalFromDeviceStep("Load calibration from device", Variables),
2626
//new WarmupStep("Warmup device", Variables) { Skip = false },
2727

28-
new Step("Set channel 1"){ Action = (CancellationToken cancellationToken) => {
29-
Instruments.Instance.SetThunderscopeChannel([0]);
30-
Instruments.Instance.SetThunderscopeRate(1_000_000_000, Variables);
31-
return Sequencer.Status.Done;
32-
}},
3328
new Step("Connect SDG2042X"){ Action = (CancellationToken cancellationToken) => {
3429
Instruments.Instance.SetSdgChannel(0);
3530
cancellationToken.WaitHandle.WaitOne(2000);
@@ -38,11 +33,6 @@ private void AddSteps(Func<Dialog, DialogResult> uiDialog)
3833

3934
new BodePlotStep("Channel 1", 0, 21, 0.8, false, Variables),
4035

41-
new Step("Set channel 2"){ Action = (CancellationToken cancellationToken) => {
42-
Instruments.Instance.SetThunderscopeChannel([1]);
43-
Instruments.Instance.SetThunderscopeRate(1_000_000_000, Variables);
44-
return Sequencer.Status.Done;
45-
}},
4636
new Step("Connect SDG2042X"){ Action = (CancellationToken cancellationToken) => {
4737
Instruments.Instance.SetSdgChannel(1);
4838
cancellationToken.WaitHandle.WaitOne(2000);
@@ -51,11 +41,6 @@ private void AddSteps(Func<Dialog, DialogResult> uiDialog)
5141

5242
new BodePlotStep("Channel 2", 1, 21, 0.8, false, Variables),
5343

54-
new Step("Set channel 3"){ Action = (CancellationToken cancellationToken) => {
55-
Instruments.Instance.SetThunderscopeChannel([2]);
56-
Instruments.Instance.SetThunderscopeRate(1_000_000_000, Variables);
57-
return Sequencer.Status.Done;
58-
}},
5944
new Step("Connect SDG2042X"){ Action = (CancellationToken cancellationToken) => {
6045
Instruments.Instance.SetSdgChannel(2);
6146
cancellationToken.WaitHandle.WaitOne(2000);
@@ -64,11 +49,6 @@ private void AddSteps(Func<Dialog, DialogResult> uiDialog)
6449

6550
new BodePlotStep("Channel 3", 2, 21, 0.8, false, Variables),
6651

67-
new Step("Set channel 4"){ Action = (CancellationToken cancellationToken) => {
68-
Instruments.Instance.SetThunderscopeChannel([3]);
69-
Instruments.Instance.SetThunderscopeRate(1_000_000_000, Variables);
70-
return Sequencer.Status.Done;
71-
}},
7252
new Step("Connect SDG2042X"){ Action = (CancellationToken cancellationToken) => {
7353
Instruments.Instance.SetSdgChannel(3);
7454
cancellationToken.WaitHandle.WaitOne(2000);

source/TS.NET.Sequences/Sequences/NoiseVerificationSequence.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ private void AddSteps(Func<Dialog, DialogResult> uiDialog)
2424
new LoadUserCalFromDeviceStep("Load calibration from device", Variables),
2525
new WarmupStep("Warmup device", Variables) { Skip = false },
2626

27-
new Step("Set channel 1"){ Action = (CancellationToken cancellationToken) => {
28-
Instruments.Instance.SetThunderscopeChannel([0], setDefaultRate: true);
29-
return Sequencer.Status.Done;
30-
}},
31-
3227
new AcRmsStep("Channel 1 - AC RMS - 50R, 8-bit, 1 GSPS, BW 20M, PGA HG L0", 0, 0, ThunderscopeTermination.FiftyOhm, ThunderscopeBandwidth.Bw20M, 1_000_000_000, Variables){ MinLimit = 0.00003, MaxLimit = 0.00009 },
3328
// new AcRmsStep("Channel 1 - AC RMS - 50R, 500 MSPS, 20M, HG L0", 0, 0, ThunderscopeTermination.FiftyOhm, ThunderscopeBandwidth.Bw20M, 500_000_000, Variables){ MinLimit = 0.00003, MaxLimit = 0.00009 },
3429
// new AcRmsStep("Channel 1 - AC RMS - 50R, 250 MSPS, 20M, HG L0", 0, 0, ThunderscopeTermination.FiftyOhm, ThunderscopeBandwidth.Bw20M, 250_000_000, Variables){ MinLimit = 0.00003, MaxLimit = 0.00009 },
@@ -46,11 +41,6 @@ private void AddSteps(Func<Dialog, DialogResult> uiDialog)
4641
// new AcRmsStep("Channel 1 - AC RMS - 50R, 250 MSPS, FULL, HG L0", 0, 0, ThunderscopeTermination.FiftyOhm, ThunderscopeBandwidth.BwFull, 250_000_000, Variables){ MinLimit = 0.00003, MaxLimit = 0.00009 },
4742
// new AcRmsStep("Channel 1 - AC RMS - 50R, 100 MSPS, FUL, HG L0", 0, 0, ThunderscopeTermination.FiftyOhm, ThunderscopeBandwidth.BwFull, 100_000_000, Variables){ MinLimit = 0.00003, MaxLimit = 0.00009 },
4843

49-
new Step("Set channel 2"){ Action = (CancellationToken cancellationToken) => {
50-
Instruments.Instance.SetThunderscopeChannel([1], setDefaultRate: true);
51-
return Sequencer.Status.Done;
52-
}},
53-
5444
new AcRmsStep("Channel 2 - AC RMS - 50R, 8-bit, 1 GSPS, BW 20M, PGA HG L0", 1, 0, ThunderscopeTermination.FiftyOhm, ThunderscopeBandwidth.Bw20M, 1_000_000_000, Variables){ MinLimit = 0.00003, MaxLimit = 0.00009 },
5545
// new AcRmsStep("Channel 2 - AC RMS - 50R, 500 MSPS, 20M, HG L0", 1, 0, ThunderscopeTermination.FiftyOhm, ThunderscopeBandwidth.Bw20M, 500_000_000, Variables){ MinLimit = 0.00003, MaxLimit = 0.00009 },
5646
// new AcRmsStep("Channel 2 - AC RMS - 50R, 250 MSPS, 20M, HG L0", 1, 0, ThunderscopeTermination.FiftyOhm, ThunderscopeBandwidth.Bw20M, 250_000_000, Variables){ MinLimit = 0.00003, MaxLimit = 0.00009 },
@@ -68,11 +58,6 @@ private void AddSteps(Func<Dialog, DialogResult> uiDialog)
6858
// new AcRmsStep("Channel 2 - AC RMS - 50R, 250 MSPS, FULL, HG L0", 1, 0, ThunderscopeTermination.FiftyOhm, ThunderscopeBandwidth.BwFull, 250_000_000, Variables){ MinLimit = 0.00003, MaxLimit = 0.00009 },
6959
// new AcRmsStep("Channel 2 - AC RMS - 50R, 100 MSPS, FUL, HG L0", 1, 0, ThunderscopeTermination.FiftyOhm, ThunderscopeBandwidth.BwFull, 100_000_000, Variables){ MinLimit = 0.00003, MaxLimit = 0.00009 },
7060

71-
new Step("Set channel 3"){ Action = (CancellationToken cancellationToken) => {
72-
Instruments.Instance.SetThunderscopeChannel([2], setDefaultRate: true);
73-
return Sequencer.Status.Done;
74-
}},
75-
7661
new AcRmsStep("Channel 3 - AC RMS - 50R, 8-bit, 1 GSPS, BW 20M, PGA HG L0", 2, 0, ThunderscopeTermination.FiftyOhm, ThunderscopeBandwidth.Bw20M, 1_000_000_000, Variables){ MinLimit = 0.00003, MaxLimit = 0.00009 },
7762
// new AcRmsStep("Channel 3 - AC RMS - 50R, 500 MSPS, 20M, HG L0", 2, 0, ThunderscopeTermination.FiftyOhm, ThunderscopeBandwidth.Bw20M, 500_000_000, Variables){ MinLimit = 0.00003, MaxLimit = 0.00009 },
7863
// new AcRmsStep("Channel 3 - AC RMS - 50R, 250 MSPS, 20M, HG L0", 2, 0, ThunderscopeTermination.FiftyOhm, ThunderscopeBandwidth.Bw20M, 250_000_000, Variables){ MinLimit = 0.00003, MaxLimit = 0.00009 },
@@ -90,11 +75,6 @@ private void AddSteps(Func<Dialog, DialogResult> uiDialog)
9075
// new AcRmsStep("Channel 3 - AC RMS - 50R, 250 MSPS, FULL, HG L0", 2, 0, ThunderscopeTermination.FiftyOhm, ThunderscopeBandwidth.BwFull, 250_000_000, Variables){ MinLimit = 0.00003, MaxLimit = 0.00009 },
9176
// new AcRmsStep("Channel 3 - AC RMS - 50R, 100 MSPS, FUL, HG L0", 2, 0, ThunderscopeTermination.FiftyOhm, ThunderscopeBandwidth.BwFull, 100_000_000, Variables){ MinLimit = 0.00003, MaxLimit = 0.00009 },
9277

93-
new Step("Set channel 4"){ Action = (CancellationToken cancellationToken) => {
94-
Instruments.Instance.SetThunderscopeChannel([3], setDefaultRate: true);
95-
return Sequencer.Status.Done;
96-
}},
97-
9878
new AcRmsStep("Channel 4 - AC RMS - 50R, 8-bit, 1 GSPS, BW 20M, PGA HG L0", 3, 0, ThunderscopeTermination.FiftyOhm, ThunderscopeBandwidth.Bw20M, 1_000_000_000, Variables){ MinLimit = 0.00003, MaxLimit = 0.00009 },
9979
// new AcRmsStep("Channel 4 - AC RMS - 50R, 500 MSPS, 20M, HG L0", 3, 0, ThunderscopeTermination.FiftyOhm, ThunderscopeBandwidth.Bw20M, 500_000_000, Variables){ MinLimit = 0.00003, MaxLimit = 0.00009 },
10080
// new AcRmsStep("Channel 4 - AC RMS - 50R, 250 MSPS, 20M, HG L0", 3, 0, ThunderscopeTermination.FiftyOhm, ThunderscopeBandwidth.Bw20M, 250_000_000, Variables){ MinLimit = 0.00003, MaxLimit = 0.00009 },

source/TS.NET.Sequences/Sequences/SelfCalibrationSequence.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ private void AddSteps(Func<Dialog, DialogResult> uiDialog)
2424
new LoadUserCalFromDeviceFallbackToFileStep("Load calibration from device/file", Variables),
2525
new WarmupStep("Warmup device", Variables) { Skip = false },
2626

27-
new Step("Set channel 1"){ Action = (CancellationToken cancellationToken) => {
28-
Instruments.Instance.SetThunderscopeChannel([0]);
29-
return Sequencer.Status.Done;
30-
}},
31-
3227
new TrimOffsetDacGainStep("Channel 1 - measure trim offset DAC scale - HG L0", 0, 0, Variables) { IgnoreError = true, Timeout = TimeSpan.FromSeconds(30), Retries = 3 },
3328
new TrimOffsetDacGainStep("Channel 1 - measure trim offset DAC scale - HG L1", 0, 1, Variables) { IgnoreError = true, Timeout = TimeSpan.FromSeconds(30), Retries = 3 },
3429
new TrimOffsetDacGainStep("Channel 1 - measure trim offset DAC scale - HG L2", 0, 2, Variables) { IgnoreError = true, Timeout = TimeSpan.FromSeconds(30), Retries = 3 },
@@ -75,11 +70,6 @@ private void AddSteps(Func<Dialog, DialogResult> uiDialog)
7570
new TrimOffsetDacZeroStep("Channel 1 - find trim offset DAC zero - LG L9", 0, 20, Variables),
7671
new TrimOffsetDacZeroStep("Channel 1 - find trim offset DAC zero - LG L10", 0, 21, Variables),
7772

78-
new Step("Set channel 2"){ Action = (CancellationToken cancellationToken) => {
79-
Instruments.Instance.SetThunderscopeChannel([1]);
80-
return Sequencer.Status.Done;
81-
}},
82-
8373
new TrimOffsetDacGainStep("Channel 2 - measure trim offset DAC scale - HG L0", 1, 0, Variables) { IgnoreError = true, Timeout = TimeSpan.FromSeconds(30), Retries = 3 },
8474
new TrimOffsetDacGainStep("Channel 2 - measure trim offset DAC scale - HG L1", 1, 1, Variables) { IgnoreError = true, Timeout = TimeSpan.FromSeconds(30), Retries = 3 },
8575
new TrimOffsetDacGainStep("Channel 2 - measure trim offset DAC scale - HG L2", 1, 2, Variables) { IgnoreError = true, Timeout = TimeSpan.FromSeconds(30), Retries = 3 },
@@ -126,11 +116,6 @@ private void AddSteps(Func<Dialog, DialogResult> uiDialog)
126116
new TrimOffsetDacZeroStep("Channel 2 - find trim offset DAC zero - LG L9", 1, 20, Variables),
127117
new TrimOffsetDacZeroStep("Channel 2 - find trim offset DAC zero - LG L10", 1, 21, Variables),
128118

129-
new Step("Set Channel 3"){ Action = (CancellationToken cancellationToken) => {
130-
Instruments.Instance.SetThunderscopeChannel([2]);
131-
return Sequencer.Status.Done;
132-
}},
133-
134119
new TrimOffsetDacGainStep("Channel 3 - measure trim offset DAC scale - HG L0", 2, 0, Variables) { IgnoreError = true, Timeout = TimeSpan.FromSeconds(30), Retries = 3 },
135120
new TrimOffsetDacGainStep("Channel 3 - measure trim offset DAC scale - HG L1", 2, 1, Variables) { IgnoreError = true, Timeout = TimeSpan.FromSeconds(30), Retries = 3 },
136121
new TrimOffsetDacGainStep("Channel 3 - measure trim offset DAC scale - HG L2", 2, 2, Variables) { IgnoreError = true, Timeout = TimeSpan.FromSeconds(30), Retries = 3 },
@@ -177,11 +162,6 @@ private void AddSteps(Func<Dialog, DialogResult> uiDialog)
177162
new TrimOffsetDacZeroStep("Channel 3 - find trim offset DAC zero - LG L9", 2, 20, Variables),
178163
new TrimOffsetDacZeroStep("Channel 3 - find trim offset DAC zero - LG L10", 2, 21, Variables),
179164

180-
new Step("Set Channel 4"){ Action = (CancellationToken cancellationToken) => {
181-
Instruments.Instance.SetThunderscopeChannel([3]);
182-
return Sequencer.Status.Done;
183-
}},
184-
185165
new TrimOffsetDacGainStep("Channel 4 - measure trim offset DAC scale - HG L0", 3, 0, Variables) { IgnoreError = true, Timeout = TimeSpan.FromSeconds(30), Retries = 3 },
186166
new TrimOffsetDacGainStep("Channel 4 - measure trim offset DAC scale - HG L1", 3, 1, Variables) { IgnoreError = true, Timeout = TimeSpan.FromSeconds(30), Retries = 3 },
187167
new TrimOffsetDacGainStep("Channel 4 - measure trim offset DAC scale - HG L2", 3, 2, Variables) { IgnoreError = true, Timeout = TimeSpan.FromSeconds(30), Retries = 3 },

0 commit comments

Comments
 (0)