Download Print this page

Appendix B) Python Example Program - Keysight Technologies N437 Series Application Note

Lightwave component analyzer automation - getting started with scpi
Hide thumbs Also See for N437 Series:

Advertisement

19 | Keysight | N437x Lightwave Component Analyzer Automation – Getting Started with SCPI - Application Note

Appendix B) Python Example Program

1.
# Import python modules
2.
visa
import
3.
time
import
4.
numpy as np
import
5.
import
matplotlib.pyplot as plt
6.
7.
# define VNA_LCA Functions
8.
9.
recall_state_VNA(mystate):
def
10.
#Recall Instrument State
11.
myVNA.write(':MMEM:LOAD '
12.
myVNA.write('*OPC?')
13.
('Recall VNA State Complete: '
print
14.
15.
def
get_data_VNA(my_INST, mytrace):
16.
#get_VNA Data
17.
my_INST == 'PNA':
if
18.
#Define trace data transfer as ASCII
19.
myVNA.write(':FORMAT
20.
myVNA.write(':FORMAT?')
21.
print('Data Xfer Format: '
22.
#Select Measurement Data using trace number
23.
myVNA.write('CALC1:PAR:MNUM '
24.
#Query data as formatted - FDATA
25.
#Query data in complex format - SDATA
26.
myVNA.write('CALC1:DATA?
27.
myydata = myVNA.read()
28.
return
29.
my_INST == 'ENA':
elif
30.
#Define return trace format
31.
myVNA.write(':FORM:DATA
32.
myVNA.write(':FORM:DATA?')
33.
print('Data Xfer Format: '
34.
#Query data as formatted - FDATA
35.
#Query data in complex format - SDATA
36.
#Note on FDATA:
37.
#Array returned for ENA formatted data will have 2x the number of
38.
#points in the returned array.
39.
#at the odd elements (i.e. n*2-2 where n = 1 to number of points)
40.
myVNA.write(':CALC1:TRAC'+str(int(mytrace))+':DATA:FDAT?')
41.
myydata = myVNA.read()
42.
return
43.
44.
def
save_csv_VNA(my_INST, mytrace, myfile):
45.
#Save VNA Data
46.
my_INST == 'PNA':
if
47.
#Format command to save PNA Data
48.
command =
49.
command = command +
50.
command = command +
51.
command = command +
52.
command =
53.
myVNA.write(command)
54.
myVNA.write('*OPC?')
55.
print
56.
my_INST == 'ENA':
elif
57.
myVNA.write('CALC1:PAR'+str(mytrace)+':SEL')
58.
#Format command to save ENA Data
59.
command =
60.
command = command +
61.
myVNA.write(command)
+ mystate)
ASC')
FDATA')
myydata
ASC')
myydata
"'"
+ myfile +
'TR'
"'"
+
'CSV Formatted Data'
"'"
+
'Trace'
"'"
+
'Displayed'
'MMEM:STORe:DATA '
('PNA trace save complete: '
':MMEMory:STORe:FDATa '
'TR'
+ str(mytrace) +
+ myVNA.read())
+ myVNA.read())
+ str(int(mytrace)))
+ myVNA.read())
The data points of interest are
+ str(mytrace) +
'.csv'
+
+
"'"
+
','
+
"'"
+
','
+ command
+ myVNA.read())
+
"'"
+ myfile
'.csv'
+
"'"
+
','
"'"
+
','
+ str(mytrace)
+
"'"

Advertisement

loading

This manual is also suitable for:

N4374b