-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapx525_functions.py
326 lines (270 loc) · 11.3 KB
/
apx525_functions.py
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
execfile(r"C:\Users\bar.kristal\Documents\GitHub\Python\apx525_module.py")
import matplotlib.pyplot as plt
import threading
################################################################
### some examples:
## initialize APx500
# APx = APx500_Application(APxOperatingMode.BenchMode, True)
# APx.Visible = True
### running an APx project:
# filename = 'Electrical_Test_Setup_APX_100mV_0dB.approjx'
# directory = "T:\Barkristal\DBMD6\DBMD6_electrical_functionality_tests\Tools"
# fullpath = os.path.join(directory, filename)
# APx.OpenProject(fullpath)
### BenchMode, FFT:
'''Connect the Digital Serial output to the Digital Serial input.
The test generates a sine wave from the digital serial, and show it's FFT'''
# APx.BenchMode.Setup.OutputConnector.Type = OutputConnectorType.DigitalSerial
# APx.BenchMode.Setup.InputConnector.Type = InputConnectorType.DigitalSerial
# APx.SignalPathSetup.SerialDigitalTransmitter.EnableOutputs = True
# #APx.BenchMode.Generator.Levels.SetValue(OutputChannelIndex.Ch1, 0.02)
# APx.BenchMode.Generator.Frequency.Value = 2000
# APx.BenchMode.Generator.On = True
# fft = APx.BenchMode.Measurements.Fft
# fft.Show()
# fft.Start()
# time.sleep(2)
# xValues = fft.FFTSpectrum.GetXValues(InputChannelIndex.Ch1, VerticalAxis.Left)
# yValues = fft.FFTSpectrum.GetYValues(InputChannelIndex.Ch1, VerticalAxis.Left)
# yval = []
# xval = []
# for i in yValues:
# yval.append(i)
# for j in xValues:
# xval.append(j)
# plt.semilogx(xval, yval)
# plt.show()
### BenchMode, THD:
'''Connect the Digital Serial output to the Digital Serial input.
The test generates a sine wave from the digital serial, and measure it's THD'''
# APx.BenchMode.Setup.OutputConnector.Type = OutputConnectorType.DigitalSerial
# APx.BenchMode.Setup.InputConnector.Type = InputConnectorType.DigitalSerial
# APx.SignalPathSetup.SerialDigitalTransmitter.EnableOutputs = True
# APx.BenchMode.Generator.Frequency.Value = 2000
# APx.BenchMode.Generator.On = True
# AcousticResponse = APx.BenchMode.Measurements.AcousticResponse
# AcousticResponse.Start() #start measurements
# THD = AcousticResponse.ThdLevel
# time.sleep(2)
# xValues = THD.GetXValues(InputChannelIndex.Ch1, VerticalAxis.Left)
# yValues = THD.GetYValues(InputChannelIndex.Ch1, VerticalAxis.Left)
# yval = []
# xval = []
# for i in yValues:
# yval.append(i)
# for j in xValues:
# xval.append(j)
# plt.semilogx(xval,yval)
# plt.show()
### BenchMode, THD, load project:
'''Connect the Digital Serial output to the Digital Serial input.
The test generates a sine wave from the digital serial, and measure it's THD'''
# APx.OpenProject(r"C:\Users\bar.kristal\Documents\GitHub\Python\Tests\apx500_functionality_test\THD_test.approjx")
# AcousticResponse = APx.BenchMode.Measurements.AcousticResponse
# AcousticResponse.Start() #start measurements
# THD = AcousticResponse.ThdLevel
# time.sleep(2)
# xValues = THD.GetXValues(InputChannelIndex.Ch1, VerticalAxis.Left)
# yValues = THD.GetYValues(InputChannelIndex.Ch1, VerticalAxis.Left)
# yval = []
# xval = []
# for i in yValues:
# yval.append(i)
# for j in xValues:
# xval.append(j)
# plt.semilogx(xval,yval)
# plt.show()
### SequenceMode, SNR, load project:
def SequenceMode_SNR_from_project(project_path):
'''This function loads a specified project, and returns the SNR results.
Results are in the following form: list results, str units. The length of the results list
is dependent on the number of channels that turned on in the project.
The project need to be in Sequence mode'''
APx = APx500_Application()
APx.Visible = True
APx.OpenProject(project_path)
SNR = APx.Sequence.GetMeasurement("Signal Path1", "Signal to Noise Ratio")
SNR.Checked = True
SNR.Run()
show_fft(APx) # save a figure of the FFT
if SNR.HasSequenceResults:
readingValues = SNR.SequenceResults[MeasurementResultType.SignalToNoiseRatioMeter].GetMeterValues()
units = SNR.SequenceResults[MeasurementResultType.SignalToNoiseRatioMeter].MeterUnit
results = []
for i in range(len(readingValues)):
results.append(readingValues[i])
return results, units
def SequenceMode_THDN_Ratio_from_project(project_path):
'''This function loads a specified project, and returns the THD+N results.
Results are in the following form: list results, str units. The length of the results list
is dependent on the number of channels that turned on in the project.
The project need to be in Sequence mode'''
APx = APx500_Application()
APx.Visible = True
APx.OpenProject(project_path)
THD_N = APx.Sequence.GetMeasurement("Signal Path1", "THD+N")
THD_N.Checked = True
THD_N.Run() #run the measurement
show_fft(APx) # save a figure of the FFT
if THD_N.HasSequenceResults:
readingValues = THD_N.SequenceResults[MeasurementResultType.ThdNRatioMeter].GetMeterValues()
units = THD_N.SequenceResults[MeasurementResultType.ThdNRatioMeter].MeterUnit
results = []
for i in range(len(readingValues)):
results.append(readingValues[i])
return results, units
def SequenceMode_THD_from_project(project_path):
'''This function loads a specified project, and returns the THD results.
Results are in the following form: list results, str units. The length of the results list
is dependent on the number of channels that turned on in the project.
The project need to be in Sequence mode'''
APx = APx500_Application()
APx.Visible = True
APx.OpenProject(project_path)
THD = APx.Sequence.GetMeasurement("Signal Path1", "THD+N")
THD.Checked = True
THD.Run() #run the measurement
show_fft(APx) # save a figure of the FFT
if THD.HasSequenceResults:
readingValues = THD.SequenceResults[MeasurementResultType.ThdRatioMeter].GetMeterValues()
units = THD.SequenceResults[MeasurementResultType.ThdRatioMeter].MeterUnit
results = []
for i in range(len(readingValues)):
results.append(readingValues[i])
return results, units
def SequenceMode_SINAD_from_project(project_path):
'''This function loads a specified project, and returns the SINAD results.
Results are in the following form: list results, str units. The length of the results list
is dependent on the number of channels that turned on in the project.
The project need to be in Sequence mode'''
APx = APx500_Application()
APx.Visible = True
APx.OpenProject(project_path)
SINAD = APx.Sequence.GetMeasurement("Signal Path1", "SINAD")
SINAD.Checked = True
SINAD.Run() #run the measurement
time.sleep(4)
show_fft(APx) #save a figure of the FFT
if SINAD.HasSequenceResults:
readingValues = SINAD.SequenceResults[MeasurementResultType.SinadRatioMeter].GetMeterValues()
units = SINAD.SequenceResults[MeasurementResultType.SinadRatioMeter].MeterUnit
results = []
for i in range(len(readingValues)):
results.append(readingValues[i])
return results, units
def SequenceMode_NoiseLevel_from_project(project_path):
'''This function loads a specified project, and returns the Noise level results.
Results are in the following form: list results, str units. The length of the results list
is dependent on the number of channels that turned on in the project.
The project need to be in Sequence mode'''
APx = APx500_Application()
APx.Visible = True
APx.OpenProject(project_path)
Noise = APx.Sequence.GetMeasurement("Signal Path1", "Noise (RMS)")
Noise.Checked = True
Noise.Run() #run the measurement
show_fft(APx) # save a figure of the FFT
if Noise.HasSequenceResults:
readingValues = Noise.SequenceResults[MeasurementResultType.NoiseRmsLevelMeter].GetMeterValues()
units = Noise.SequenceResults[MeasurementResultType.NoiseRmsLevelMeter].MeterUnit
results = []
for i in range(len(readingValues)):
results.append(readingValues[i])
return results, units
def SequenceMode_CMRR_from_project(project_path):
'''This function loads a specified project, and returns the CMRR results.
Results are in the following form: list results, str units. The length of the results list
is dependent on the number of channels that turned on in the project.
The project need to be in Sequence mode'''
APx = APx500_Application()
APx.Visible = True
APx.OpenProject(project_path)
CMRR = APx.Sequence.GetMeasurement("Signal Path1", "CMRR")
CMRR.Checked = True
CMRR.Run() #run the measurement
show_fft(APx) # save a figure of the FFT
if CMRR.HasSequenceResults:
readingValues = CMRR.SequenceResults[MeasurementResultType.CmrrMeter].GetMeterValues()
units = CMRR.SequenceResults[MeasurementResultType.CmrrMeter].MeterUnit
results = []
for i in range(len(readingValues)):
results.append(readingValues[i])
return results, units
def SequenceMode_frequency_response_from_project(project_path):
'''This function loads a specified project, and returns the frequency response results.
Results are in the following form: list results, str units. The length of the results list
is dependent on the number of channels that turned on in the project.
The project need to be in Sequence mode'''
APx = APx500_Application()
APx.Visible = True
APx.OpenProject(project_path)
APx.FrequencyResponse.Start()
level = APx.FrequencyResponse.Level
data = level.GetValues(0, APx.FrequencyResponse.Level.AcquisitionCount - 1)
xval = []
yval = []
for i in range(len(data)):
# print "point %s: (%s %s,%s %s)"%(i, data[i].X, level.XAxis.Unit, data[i].Y, level.YAxis.Unit)
xval.append(data[i].X)
yval.append(data[i].Y)
graph_path = DIR_NAME + r"\\" + TEST_NAME + r"_" + "frequency_response" + TEST_DATE + r"_" + TEST_TIME + r".png"
plt.plot(xval, yval)
# plt.show()
plt.savefig(graph_path)
return graph_path
def SequenceMode_full_sequence_from_project(project_path, results_path):
'''This function loads a project that runs a sequence of measurments,
sets the path and name for the results_file to be saved,
and runs the sequence.'''
APx = APx500_Application()
APx.Visible = True
APx.OpenProject(project_path)
SequenceMode_change_log_path(APx, results_path)
APx.Sequence.Run()
def SequenceMode_change_log_path(APx, log_path):
'''
:param APx: instance ot the APx_Application() class
log_path: path for the results csv file to be saved
for example: log_path = "c:\DBMA7\SNR", than the results_file will be saved at: "c:\DBMA7\SNR\date&time.csv"
:return: none
'''
path = log_path+"$(Date)$(Time).csv"
try:
APx.Sequence.DataOutput.MeterReadingsFileName = path
except:
raise "path is not valid"
def show_scope(APx):
scope_path = DIR_NAME + r"\\" + TEST_NAME + r"_" + "scope_figure" + TEST_DATE + r"_" + TEST_TIME + r".png"
scope = APx.ScopeSignalMonitor.Scope
yValues = scope.GetYValues(InputChannelIndex.Ch1, VerticalAxis.Left)
xValues = scope.GetXValues(InputChannelIndex.Ch1, VerticalAxis.Left)
yval = []
xval = []
for i in yValues:
yval.append(i)
for j in xValues:
xval.append(j)
plt.plot(xval, yval)
#plt.show()
plt.savefig(scope_path)
def show_fft(APx):
fft_path = DIR_NAME + r"\\" + TEST_NAME + r"_" + "fft_figure" + TEST_DATE + r"_" + TEST_TIME + r".png"
fft = APx.FftSpectrumSignalMonitor
fft.FFTLength = FFTLength.FFT_48000
xValues = fft.FFTSpectrum.GetXValues(InputChannelIndex.Ch1, VerticalAxis.Left)
yValues = fft.FFTSpectrum.GetYValues(InputChannelIndex.Ch1, VerticalAxis.Left)
yval = []
xval = []
for i in yValues:
yval.append(i)
for j in xValues:
xval.append(j)
plt.semilogx(xval, yval)
#plt.show()
plt.savefig(fft_path)
def show_scope_new_thread(APx):
thread = threading.Thread(target=show_scope, args=(APx,))
thread.start()
def show_fft_new_thread(APx):
thread = threading.Thread(target=show_fft, args=(APx,))
thread.start()