Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Climate Lab Test Stand
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MSK-SW
Low-Level Radio Frequency
Climate Lab
Climate Lab Test Stand
Commits
ff873b10
Commit
ff873b10
authored
3 years ago
by
Jakub Kowalik
Browse files
Options
Downloads
Patches
Plain Diff
Implemented basic VNA functionality as methods
parent
f15488f6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1
Prototype
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Python script/VNA.py
+144
-54
144 additions, 54 deletions
Python script/VNA.py
with
144 additions
and
54 deletions
Python script/VNA.py
+
144
−
54
View file @
ff873b10
...
...
@@ -3,7 +3,7 @@ import time
class
Vna
:
def
__init__
(
self
):
def
__init__
(
self
,
ip_address
):
"""
Implements the basic operation of the VNA
...
...
@@ -11,81 +11,171 @@ class Vna:
# open connection here
# store the credentials so that methods can access them
#
self.__ip_address = ip_address
self
.
__ip_address
=
ip_address
# we try to connect to the
climate chamber
just to see if there is an error
# we try to connect to the
VNA
just to see if there is an error
self
.
rm
=
pyvisa
.
ResourceManager
()
self
.
vna
=
self
.
rm
.
open_resource
(
"
TCPIP
0
::
192.168.115.39 ::57732
::SOCKET
"
)
#
self.vna.write_termination = '\r\n'
#
self.vna.read_termination = '\
r\
n'
self
.
vna
=
self
.
rm
.
open_resource
(
"
TCPIP::
"
+
self
.
__ip_address
+
"
::5025
::SOCKET
"
)
self
.
vna
.
write_termination
=
'
\r\n
'
self
.
vna
.
read_termination
=
'
\n
'
self
.
vna
.
timeout
=
5000
# Preset the VNA and wait for preset completion via use of *OPC?
self
.
vna
.
write
(
"
SYST:PRES; *OPC?
"
)
self
.
vna
.
read
()
self
.
preset_vna
()
# Clear the event status registers and empty the error queue
self
.
vna
.
write
(
"
*CLS
"
)
self
.
clear_status
(
)
# Query identification string *IDN?
self
.
vna
.
write
(
"
*IDN?
"
)
print
(
self
.
vna
.
read
())
def
get_tuples_of_current_traces
(
self
):
"""
Returns list of tuples containing trace and measured parameter pairs
# check the error queue
self
.
vna
.
write
(
"
SYST:ERR?
"
)
print
(
self
.
vna
.
read
())
:return: list of tuples
"""
traces
=
self
.
get_current_traces
()
result
=
[]
for
i
in
range
(
0
,
len
(
traces
)):
if
i
%
2
==
0
:
result
.
append
((
traces
[
i
],
traces
[
i
+
1
]))
return
result
def
get_current_traces
(
self
):
"""
Returns list of string containing traces and measured parameters
# the communication section
:return: list of strings
"""
return
self
.
vna
.
query
(
"
CALC1:PAR:CATALOG?
"
).
replace
(
"'"
,
""
).
split
(
'
,
'
)
# Select the default measurement name as assigned on preset. To catalog the measurement names,
# by channel number, use the 'CALCulate[n]:PARameter:CATalog?' command where [n] is the channel
# number.
self
.
vna
.
write
(
"
CALC:PAR:SEL
'
CH1_S11_1
'"
)
def
create_new_trace
(
self
,
name
,
parameter
):
"""
Creates new trace
# Set data transfer format to ASCII
self
.
vna
.
write
(
"
FORM:DATA ASCII
"
)
Parameters
----------
name : str
Name of new trace.
parameter : int
Measured parameter.
Returns
-------
None.
# Alter measure from S11 to S21
self
.
vna
.
write
(
"
CALC:PAR:MOD S21
"
)
"""
self
.
vna
.
write
(
"
CALC1:PAR:SDEF
'"
+
name
+
"'
,
'"
+
parameter
+
"'"
)
def
set_trace_measurements
(
self
,
trace
,
measurement
):
"""
Set measured parameter of given trace
# Loop to control the number of trace points, provide single sweep synchronization, query the data,
# indicate number of points and indicate number of characters in the trace read.
self
.
traceData
=
[]
i
=
0
self
.
numPointsList
=
[
201
,
401
,
801
,
1601
,
3201
,
6401
,
12801
,
20001
,
32001
,
100001
]
Parameters
----------
trace : str
Name of new trace.
measurement : int
Measured parameter.
while
i
<
len
(
self
.
numPointsList
):
# Set number of points by list value
self
.
numPoints
=
self
.
numPointsList
[
i
]
self
.
vna
.
write
(
"
SENS:SWE:POIN
"
+
str
(
self
.
numPoints
)
+
"
;*OPC?
"
)
self
.
vna
.
read
()
Returns
-------
None.
self
.
startTime
=
self
.
time
.
clock
()
# Trigger assertion with hold-off for trigger complete via *OPC?
self
.
vna
.
write
(
"
SENS:SWE:MODE SING;*OPC?
"
)
self
.
vna
.
read
()
"""
self
.
vna
.
write
(
"
CALC1:PAR:MEAS
'"
+
trace
+
"'
,
'"
+
measurement
+
"'"
)
self
.
stopTime
=
self
.
time
.
clock
()
-
self
.
startTime
def
set_sweep_points
(
self
,
points
):
return
self
.
vna
.
query
(
"
SENS1:SWE:POIN
"
+
str
(
points
)
+
"
;*OPC?
"
)
# The SDATA assertion queries underlying real and imaginary pair data
self
.
vna
.
write
(
"
CALC:DATA? SDATA
"
)
self
.
traceData
=
self
.
vna
.
read
()
def
check_error_queue
(
self
):
"""
Check the error queue. Initially *CLS asserted in beginning of program.
The application should run from stem to stern error free. The final error
queue query should return
'
+0, No Error
'
, else the application has potentially
caused a correctable error!.
"""
return
self
.
vna
.
query
(
"
SYST:ERR?
"
)
print
(
"
Time to sweep =
"
+
str
(
self
.
stopTime
))
print
(
"
Number of trace points set =
"
+
str
(
self
.
numPoints
))
print
(
"
Number of characters in returned data
"
+
str
(
len
(
self
.
traceData
)))
print
(
self
.
traceData
)
def
query_identification
(
self
):
return
self
.
vna
.
query
(
"
*IDN?
"
)
i
=
i
+
1
def
set_active_trace
(
self
,
trace
):
"""
Selects active trace
Parameters
----------
trace : str
Name of trace.
"""
self
.
vna
.
write
(
"
CALC1:PAR:SEL
'"
+
trace
+
"'"
)
def
set_sweep_mode
(
self
,
mode
):
"""
Trigger assertion with hold-off for trigger complete via *OPC?
# Check the error queue. Initially *CLS asserted in beginning of program.
# The application should run from stem to stern error free. The final error
# queue query should return '+0, No Error', else the application has potentially
# caused a correctable error!.
self
.
vna
.
write
(
"
SYST:ERR?
"
)
print
(
self
.
vna
.
read
())
Parameters
----------
mode : str
Sweep mode.
"""
return
self
.
vna
.
query
(
"
SENS1:SWE:MODE
"
+
mode
+
"
; *OPC?
"
)
def
get_measurement_string
(
self
,
trace
,
result_format
):
"""
Returns string of measured values
Parameters
----------
trace : str
Name of trace.
result_format : str
VNA format of returned result.
Returns
-------
None.
"""
# Set data transfer format to ASCII
self
.
vna
.
write
(
"
FORM:DATA ASCII
"
)
return
self
.
vna
.
query
(
"
CALC1:DATA:TRAC?
'"
+
trace
+
"'
,
"
+
result_format
+
""
)
def
get_list_of_measurement_values
(
self
,
trace
,
result_format
):
"""
Returns list of measured values
Parameters
----------
trace : str
Name of trace.
result_format : str
VNA format of returned result.
Returns
-------
None.
"""
measurements
=
self
.
get_measurement_string
(
trace
,
result_format
)
result
=
[]
for
x
in
measurements
.
split
(
'
,
'
)[
10
:]:
if
x
!=
'
0
'
and
x
!=
'
-999
'
:
# no value is indicated with 0 for SDAT and -999 for FDAT
result
.
append
(
float
(
x
))
return
result
def
clear_status
(
self
):
"""
Clear the event status registers and empty the error queue
"""
self
.
vna
.
write
(
"
*CLS
"
)
def
preset_vna
(
self
):
self
.
vna
.
write
(
"
SYST:PRES; *OPC?
"
)
self
.
vna
.
read
()
# Close the VISA connection
def
close
(
self
):
self
.
vna
.
close
()
def
__del__
(
self
):
self
.
close
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment