-
Notifications
You must be signed in to change notification settings - Fork 0
/
Capture multi segment traces.xml
324 lines (307 loc) · 18.5 KB
/
Capture multi segment traces.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<pkg:Program
xsi:schemaLocation="urn:schemas-www-wisware.nl-scriptingpackages ../XmlSchemas.Common.XmlScript/XMLScripting.Packages.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:schemas-www-wisware.nl-xmlscripting"
xmlns:pkg="urn:schemas-www-wisware.nl-scriptingpackages"
xmlns:sys="urn:schemas-www-wisware.nl-xmlscripting"
xmlns:fil="urn:schemas-www-wisware.nl-xmlscripting-filemanagement"
xmlns:inx="urn:schemas-www-wisware.nl-xmlscripting-index"
xmlns:lil="urn:schemas-www-wisware.nl-xmlscripting-linkedlist"
xmlns:msx="urn:schemas-www-wisware.nl-xmlscripting-xml"
xmlns:rep="urn:schemas-www-wisware.nl-xmlscripting-report"
xmlns:sts="urn:schemas-www-wisware.nl-xmlscripting-showstatus"
xmlns:syu="urn:schemas-www-wisware.nl-xmlscripting-sysutils"
xmlns:sim="urn:schemas-www-wisware.nl-xmlscripting-simulateuserinput"
xmlns:stm="urn:schemas-www-wisware.nl-xmlscripting-statemanagement">
>
<pkg:ReportTargets>
<pkg:Target Identifier="Default" Description="Report"/>
<pkg:Target Identifier="Visa" Description="Visa report"/>
</pkg:ReportTargets>
<pkg:Config>
<![CDATA[
[Check]
; Set to 1 if these are all correct.
ValidParameters=0
[Config]
;Defaults to reporting directory
;OutputDirectory=C:\WaveCapture
GenerateTestSignal=0
[VISA]
;scope = dns, can be replace with ip-adress
ScopeRN=TCPIP0::scope::inst0::INSTR
;Only needed if GenerateTestSignal=1
AwgRN=TCPIP0::awg::inst0::INSTR
[DigitalSignal]
VoltageLow=0 V
VoltageHigh= 5 V
MaxRiseTime= 50 ns
MaxFallTime= 50 ns
]]>
</pkg:Config>
<Imports>
<Import Identifier="ElectronicUtils" Filename="..\Script.Common.Electronics\ElectronicUtils.xml"/>
<Import Identifier="VISAInstrument" Filename="..\Script.Common.VISA\VISA Instrument.xml"/>
<Import Identifier="SiglentScopes" Filename="..\Script.Common.VISA\VISA Siglent Scopes.xml"/>
<Import Identifier="SiglentSDG1000X" Filename="..\Script.Common.VISA\VISA Siglent SDG1000X.xml"/>
</Imports>
<Uses>
<Use Identifier="ElectronicUtils"/>
<Use Identifier="VISAInstrument"/>
<Use Identifier="SiglentScopes"/>
<Use Identifier="SiglentSDG1000X"/>
</Uses>
<Constants>
<Constant Identifier="ScriptVersion" Type="string" Expression="'5.4.290'"/>
</Constants>
<Variables>
<Variable Identifier="ucVolt" Type="TUnitConvertor" Init="TUnitConvertor.Create(TGranularity.Pico, TSiUnit.Volt)"/>
<Variable Identifier="ucTime" Type="TUnitConvertor" Init="TUnitConvertor.Create(TGranularity.Pico, TSiUnit.Second)"/>
<Variable Identifier="ScopeRN" Type="string" Init="'TCPIP0::scope::inst0::INSTR'"/>
<Variable Identifier="AwgRN" Type="string" Init="'TCPIP0::awg::inst0::INSTR'"/>
<Variable Identifier="OutputDirectory" Type="string" Init="'C:\Traces'"/>
<Variable Identifier="Scope" Type="TSiglentScope"/>
<Variable Identifier="convDigitalSignalVoltageLow" Type="ConvInt"/>
<Variable Identifier="convDigitalSignalVoltageHigh" Type="ConvInt"/>
<Variable Identifier="convDigitalSignalMaxRiseTime" Type="ConvInt"/>
<Variable Identifier="convDigitalSignalMaxFallTime" Type="ConvInt"/>
<Variable Identifier="GenerateTestsignal" Type="Boolean" Init="False"/>
</Variables>
<Procedures>
<Procedure Identifier="ReadConfig">
<Block>
<Object.Use Identifier="Ini" Type="TIniHelper" Expression="TIniHelper.Create(ConfigInifile, True)">
<Execute Statement="Ini.Section('Check', False)"/>
<Variable Identifier="ValidParameters" Type="Boolean" Init="Ini.ReadBool('ValidParameters', False)"/>
<Execute Statement="Ini.Section('Config')"/>
<Execute Statement="OutputDirectory:= Ini.ReadString('OutputDirectory', Coalesce(ReportingBase, OutputDirectory)) "/>
<Execute Statement="GenerateTestsignal:= Ini.ReadBool('GenerateTestsignal', GenerateTestsignal) "/>
<Execute Statement="Ini.Section('VISA')"/>
<Execute Statement="ScopeRN:= Ini.ReadString('ScopeRN', ScopeRN) "/>
<Execute Statement="AwgRN:= Ini.ReadString('AwgRN', AwgRN) "/>
<Execute Statement="Ini.Section('DigitalSignal')"/>
<Execute Statement="convDigitalSignalVoltageLow:= Ini.ReadConvInt('VoltageLow', ucVolt, '0 V')"/>
<Execute Statement="convDigitalSignalVoltageHigh:= Ini.ReadConvInt('VoltageHigh', ucVolt, '5 V')"/>
<Execute Statement="convDigitalSignalMaxRiseTime:= Ini.ReadConvInt('MaxRiseTime', ucTime, '50 ns')"/>
<Execute Statement="convDigitalSignalMaxFallTime:= Ini.ReadConvInt('MaxFallTime', ucTime, '50 ns')"/>
<Raise Expression="Exception.Create('Please check the config and set validparameters=1')" Condition="not ValidParameters"/>
</Object.Use>
</Block>
</Procedure>
<Procedure Identifier="WaveCapureToFile">
<Parameters>
<Parameter Identifier="Trace" Type="TTraceType"/>
<Parameter Identifier="Filename" Type="string"/>
</Parameters>
<Block>
<Variable Identifier="TraceName" Type="string" Init="Scope.TraceTypeName(Trace)"/>
<sts:Status.Block Text="Format('Capturing %s to "%s"', TraceName, Filename)" LeaveText="Format('Done capturing %s to "%s"', TraceName, Filename)">
<rep:Reporter.Information Text="Format('Capturing %s to "%s"', TraceName, Filename)"/>
<Execute Statement="Scope.WaveCapureToFile(Trace, ObjNil, Filename)"/>
<rep:Reporter.Information Text="'File saved'"/>
<rep:Reporter.Information Text="''"/>
</sts:Status.Block>
</Block>
</Procedure>
<Function Identifier="ViolatesSlopeSampleCount">
<Parameters>
<Parameter Identifier="Acquisition" Type="TSamplesAcquisitionInfo"/>
</Parameters>
<Block>
<sts:Status.Block Text="'Checking slope violation'" LeaveText="'Done checking slope violation'">
<Variable Identifier="Samples" Type="TListInt8" Init="Acquisition.Samples"/>
<Variable Identifier="PeekToPeek" Type="Extended" Init="ucVolt.IntValueToExtended(convDigitalSignalVoltageHigh - convDigitalSignalVoltageLow)"/>
<Variable Identifier="SlopeLowValue" Type="Int32" Init="Round((ucVolt.IntValueToExtended(convDigitalSignalVoltageLow) + 0.1 * PeekToPeek - Acquisition.VOffset) / Acquisition.VFactor)"/>
<Variable Identifier="SlopeHighValue" Type="Int32" Init="Round((ucVolt.IntValueToExtended(convDigitalSignalVoltageHigh) - 0.1 * PeekToPeek - Acquisition.VOffset) / Acquisition.VFactor)"/>
<Variable Identifier="MaxRiseSampleCount" Type="Int32" Init="Round(ucTime.IntValueToExtended(convDigitalSignalMaxRiseTime) / Acquisition.TimePerSample)"/>
<Variable Identifier="MaxFallSampleCount" Type="Int32" Init="Round(ucTime.IntValueToExtended(convDigitalSignalMaxFallTime) / Acquisition.TimePerSample)"/>
<rep:Reporter.Information Text="Format('SlopeLowValue: %d', SlopeLowValue)" Condition="IsVerbose"/>
<rep:Reporter.Information Text="Format('SlopeHighValue: %d', SlopeHighValue)" Condition="IsVerbose"/>
<rep:Reporter.Information Text="Format('MaxRiseSampleCount: %d', MaxRiseSampleCount)" Condition="IsVerbose"/>
<rep:Reporter.Information Text="Format('MaxFallSampleCount: %d', MaxFallSampleCount)" Condition="IsVerbose"/>
<Variable Identifier="SlopeStart" Type="Int32"/>
<stm:StateHandler InitialState="Unknown">
<ForLoop Indexer="I" From="0" To="Samples.Count - 1">
<Variable Identifier="Value" Type="Int32" Init="Samples[I]"/>
<stm:HandleStates>
<stm:State Name="Unknown">
<Execute Statement="SlopeStart:= I"/>
<Choose>
<When Expression="Value < SlopeLowValue">
<stm:SetState Name="LowRegion"/>
</When>
<When Expression="Value > SlopeHighValue">
<stm:SetState Name="HighRegion"/>
</When>
</Choose>
</stm:State>
<stm:State Name="LowRegion">
<Choose>
<When Expression="Value > SlopeHighValue">
<!-- Very fast rising slope - skip -->
<stm:SetState Name="HighRegion"/>
<Execute Statement="SlopeStart:= I"/>
</When>
<When Expression="Value > SlopeLowValue">
<stm:SetState Name="RisingSlope"/>
</When>
<Otherwise>
<Execute Statement="SlopeStart:= I"/>
</Otherwise>
</Choose>
</stm:State>
<stm:State Name="HighRegion">
<Choose>
<When Expression="Value < SlopeLowValue">
<!-- Very fast falling slope - skip -->
<stm:SetState Name="LowRegion"/>
<Execute Statement="SlopeStart:= I"/>
</When>
<When Expression="Value < SlopeHighValue">
<stm:SetState Name="FallingSlope"/>
</When>
<Otherwise>
<Execute Statement="SlopeStart:= I"/>
</Otherwise>
</Choose>
</stm:State>
<stm:State Name="RisingSlope">
<Choose>
<When Expression="Value < SlopeLowValue">
<stm:SetState Name="LowRegion"/>
<Execute Statement="SlopeStart:= I"/>
</When>
<When Expression="Value > SlopeHighValue">
<!-- Slope finnished -->
<rep:Reporter.Information Text="Format('Rise samples: %d', I - SlopeStart)" Condition="IsVerbose"/>
<Exit Result="True" Condition="(I - SlopeStart) >= MaxRiseSampleCount"/>
<stm:SetState Name="HighRegion"/>
<Execute Statement="SlopeStart:= I"/>
</When>
</Choose>
</stm:State>
<stm:State Name="FallingSlope">
<Choose>
<When Expression="Value > SlopeHighValue">
<stm:SetState Name="HighRegion"/>
<Execute Statement="SlopeStart:= I"/>
</When>
<When Expression="Value < SlopeLowValue">
<!-- Slope finnished -->
<rep:Reporter.Information Text="Format('Fall samples: %d', I - SlopeStart)" Condition="IsVerbose"/>
<Exit Result="True" Condition="(I - SlopeStart) >= MaxFallSampleCount"/>
<stm:SetState Name="LowRegion"/>
<Execute Statement="SlopeStart:= I"/>
</When>
</Choose>
</stm:State>
</stm:HandleStates>
</ForLoop>
</stm:StateHandler>
<Execute Statement="Result:= False"/>
</sts:Status.Block>
</Block>
</Function>
<Procedure Identifier="Execute">
<Block>
<rep:Reporter.Information Text="'Capture traces'" Markup="Header1"/>
<rep:Reporter.Information Text="Format('Time: %s', FormatDateTime('', Now))"/>
<rep:Reporter.Information Text="Format('Interpreter version: %s', GetVersionInfo('%d.%d.%d'))"/>
<rep:Reporter.Information Text="Format('Script version: %s', ScriptVersion)"/>
<rep:Reporter.Information Text="Format('Filename: %s', ScriptFilename)"/>
<rep:Reporter.Information Text="Format('Reporting base directory: %s', ReportingBase)" Condition="not IsEmpty(ReportingBase)"/>
<rep:Reporter.Information Text="''"/>
<rep:Reporter.Information Text="'Config report'" Markup="Header2"/>
<rep:Reporter.Information Text="''"/>
<Execute Statement="ReadConfig"/>
<rep:Reporter.Information Text="''"/>
<Object.Use Identifier="VisaRM" Type="TVisaResourceManager" Expression="TVisaResourceManager.Create">
<Object.Use Identifier="ScopeSession" Type="TVisaResource" Expression="VisaRM.OpenResource(ScopeRN, TAccessMode.NO_LOCK, 1000)">
<Object.Use Identifier="Scope" Type="TSiglentScope" Expression="TSiglentScope.MatchingClass(ScopeSession).Create(ScopeSession)" LocalVariable="false">
<TryFinally>
<Try>
<rep:Reporter.Information Text="'Capturing waveforms'" Markup="Header2"/>
<rep:Reporter.Information Text="'Using ' + Scope.IDN"/>
<rep:Reporter.Information Text="''"/>
<Execute Statement="Scope.CommHeader:= THeaderType.Off"/>
<sts:Status.Block Text="'Activating test signal'" LeaveText="'Done activating test signal'" Condition="GenerateTestsignal">
<Object.Use Identifier="AwgSession" Type="TVisaResource" Expression="VisaRM.OpenResource(AwgRN, TAccessMode.No_Lock, 10000)">
<Object.Use Identifier="Awg" Type="TSiglentSDG1000X" Expression="TSiglentSDG1000X.Create(AwgSession)">
<Execute Statement="Awg.WriteString('C1:BSWV WVTP,PULSE,FRQ,500HZ,AMP,5V,AMPVRMS,2.5Vrms,OFST,2.5V,HLEV,5V,LLEV,0V,WIDTH,0.0000001,RISE,3e-08S,FALL,3e-08S,DLY,0')"/>
<Execute Statement="Awg.WriteString('C2:BSWV WVTP,PULSE,FRQ,5HZ,AMP,5V,AMPVRMS,2.5Vrms,OFST,2.5V,HLEV,5V,LLEV,0V,WIDTH,0.0000005,RISE,30e-08S,FALL,30e-08S,DLY,0.0000002')"/>
<Execute Statement="Awg.WriteString('C1:CoMBiNe ON')"/>
<Execute Statement="Awg.Enabled[TSDGChannel.CH1]:= True"/>
<Execute Statement="Awg.Enabled[TSDGChannel.CH2]:= True"/>
</Object.Use>
</Object.Use>
</sts:Status.Block>
<Variable Identifier="DirectoryPath" Type="string" Init="IncludeTrailingPathDelimiter(OutputDirectory)"/>
<syu:CreateDirectory Path="DirectoryPath"/>
<Block Condition="not FileExists(DirectoryPath + 'WaveForm.xsd')">
<Variable Identifier="ScriptPath" Type="string" Init="ExtractFilePath(ScriptFilename)"/>
<Variable Identifier="ResourceDirectory" Type="string" Init="GetFilenameFromBase(ScriptPath, '..\XmlSchemas.Common.VISA')"/>
<Variable Identifier="SourceFilename" Type="string" Init="ExpandFileName(ResourceDirectory + '\WaveForm.xsd')"/>
<Variable Identifier="TargetFilename" Type="string" Init="ExpandFileName(DirectoryPath + 'WaveForm.xsd')"/>
<syu:CopyFile SourceFilename="SourceFilename" TargetFilename="TargetFilename"/>
</Block>
<Execute Statement="Scope.HistoryMode:= True"/>
<Variable Identifier="FrameHighIndex" Type="Integer" Init="Scope.ActiveFrame"/>
<ForLoop Indexer="I" From="1" To="FrameHighIndex">
<sts:Status.Block Text="Format('Processing segment %d', I)" LeaveText="Format('Done processing segment %d', I)">
<Execute Statement="Scope.ActiveFrame:= I"/>
<Object.Use Identifier="Acquisition" Type="TSamplesAcquisitionInfo" Expression="Scope.GetSamples(TTraceType.CH1, ObjNil)">
<ExitOnAbortRequest/>
<Block Condition="ViolatesSlopeSampleCount(Acquisition)">
<Variable Identifier="Segment" Type="string" Init="Format('%.5d', I)"/>
<Execute Statement="Scope.SaveSamplesToFile(Acquisition, DirectoryPath + 'CH1 - ' + Segment + '.xml')"/>
<Execute Statement="WaveCapureToFile(TTraceType.CH2, DirectoryPath + 'CH2 - ' + Segment + '.xml')" Condition="Scope.SupportsTrace(TTraceType.CH2) and Scope.Enabled[TTraceType.CH2]"/>
<ExitOnAbortRequest/>
<Execute Statement="WaveCapureToFile(TTraceType.CH3, DirectoryPath + 'CH3 - ' + Segment + '.xml')" Condition="Scope.SupportsTrace(TTraceType.CH3) and Scope.Enabled[TTraceType.CH3]"/>
<ExitOnAbortRequest/>
<Execute Statement="WaveCapureToFile(TTraceType.CH4, DirectoryPath + 'CH4 - ' + Segment + '.xml')" Condition="Scope.SupportsTrace(TTraceType.CH4) and Scope.Enabled[TTraceType.CH4]"/>
<ExitOnAbortRequest/>
<Variable Identifier="ScreenCaptureFilename" Type="string" Init="DirectoryPath + 'Screen capture - ' + Segment + '.png'"/>
<rep:Reporter.Information Text="Format('Capturing screen to: %s', ScreenCaptureFilename)"/>
<Execute Statement="Scope.ScreenCapureToFile(ScreenCaptureFilename, TImageType.PNG)"/>
<ExitOnAbortRequest/>
<rep:Reporter.Information Text="'File saved'"/>
<rep:Reporter.Information Text="''"/>
</Block>
</Object.Use>
</sts:Status.Block>
</ForLoop>
</Try>
<Finally>
<rep:Reporter.Information Text="'Done'" Markup="Header2"/>
<rep:Reporter.Information Text="Format('Time: %s', FormatDateTime('', Now))"/>
</Finally>
</TryFinally>
</Object.Use>
</Object.Use>
</Object.Use>
</Block>
</Procedure>
</Procedures>
<Block>
<TryExcept>
<Try>
<sts:Status.Block Text="'Executing script'" LeaveText="'Done executing script'">
<Execute Statement="DoReportVisa:= IsDebugging"/>
<Execute Statement="Execute"/>
</sts:Status.Block>
<sts:Status Text="'Aborted script - reports are not saved automatically'" Condition="AbortRequest"/>
</Try>
<Except>
<On Identifier="E" ClassType="Exception">
<rep:Reporter.Error Text="Format('An exception of type %s was raised: %s', E.ClassName, E.Message)"/>
<sts:Status Text="'Failed executing script: ' + E.Message"/>
<Raise/>
</On>
<Otherwise>
<Raise/>
</Otherwise>
</Except>
</TryExcept>
</Block>
</pkg:Program>