| 1 |
""" |
| 2 |
.. module:: skrf.vi.vna |
| 3 |
=============================================== |
| 4 |
vna (:mod:`skrf.vi.vna`) |
| 5 |
=============================================== |
| 6 |
|
| 7 |
|
| 8 |
Provides classes to interact with Vector Network Analyzers (VNAs) from numerous |
| 9 |
manufacturers. |
| 10 |
|
| 11 |
VNA Classes |
| 12 |
======================================= |
| 13 |
|
| 14 |
.. autosummary:: |
| 15 |
:nosignatures: |
| 16 |
:toctree: generated/ |
| 17 |
|
| 18 |
hp.HP8510C |
| 19 |
keysight.FieldFox |
| 20 |
keysight.PNA |
| 21 |
nanovna.NanoVNAv2 |
| 22 |
rohde_schwarz.ZVA |
| 23 |
|
| 24 |
The Base Class and Writing an Instrument Driver |
| 25 |
=============================================== |
| 26 |
|
| 27 |
All VNAs are derived from the :class:`VNA` class. This class should never be |
| 28 |
instantiated directly, but instead serves as a means to run certain setup code |
| 29 |
depending on the capabilities of the instrument. |
| 30 |
|
| 31 |
* :ref:`SCPI` |
| 32 |
* :ref:`Channels` |
| 33 |
* :ref:`Property Creator` |
| 34 |
* :ref:`Validators` |
| 35 |
|
| 36 |
When writing a new instrument driver, the following minimum questions should be |
| 37 |
considered: |
| 38 |
|
| 39 |
* Does the instrument use SCPI? |
| 40 |
* Does the instrument support multiple channels? |
| 41 |
|
| 42 |
SCPI |
| 43 |
---- |
| 44 |
|
| 45 |
For those instruments that use SCPI, default universal SCPI methods are included |
| 46 |
by default. However, for those instruments that do not support SPCI, do the |
| 47 |
following: |
| 48 |
|
| 49 |
.. code-block:: python |
| 50 |
|
| 51 |
class VNAWithoutSCPI(VNA): |
| 52 |
_scpi = False |
| 53 |
# ... |
| 54 |
|
| 55 |
Channels |
| 56 |
-------- |
| 57 |
|
| 58 |
Some instruments support channels and can have multiple measurements with |
| 59 |
different frequency/power/if bandwidth/etc settings. |
| 60 |
|
| 61 |
For instruments without channel support, the typical properties (freq_start, |
| 62 |
freq_stop, etc) should be defined on the class. For instruments **with** channel |
| 63 |
support, the class should include a subclass of :class:`Channel` that defines |
| 64 |
properties specific to channel settings in the channel definition while other |
| 65 |
instrument properties should be defined in the instrument class. To make this |
| 66 |
more clear, consider the following example from the Keysight PNA implementation |
| 67 |
(the property creator `VNA.Command` is explained later) |
| 68 |
|
| 69 |
.. code-block:: python |
| 70 |
|
| 71 |
class PNA(VNA): |
| 72 |
class Channel(vna.Channel): |
| 73 |
freq_start = VNA.Command( |
| 74 |
get_cmd="SENS<self:cnum>:FREQ:STAR?", |
| 75 |
set_cmd="SENS<self:cnum>:FREQ:STAR <arg>", |
| 76 |
doc=\"""Start frequency [Hz]\""", |
| 77 |
validator=FreqValidator() |
| 78 |
) |
| 79 |
|
| 80 |
def __init__(self, address, backend='@py'): |
| 81 |
# ... |
| 82 |
|
| 83 |
nports = VNA.Command( |
| 84 |
get_cmd="SYST:CAP:HARD:PORT:COUN?", |
| 85 |
set_cmd=None, |
| 86 |
doc=\"""Number of ports\""", |
| 87 |
validator=IntValidator() |
| 88 |
) |
| 89 |
|
| 90 |
Here, the start frequency is set **per channel** whereas the number of ports is |
| 91 |
related to the instrument itself. Instruments with channel support should create a |
| 92 |
single channel in `__init__()` using `create_channel` |
| 93 |
|
| 94 |
Property Creator |
| 95 |
---------------- |
| 96 |
|
| 97 |
Inspired by `PyMeasure <https://github.com/pymeasure/pymeasure>`_, skrf has a property |
| 98 |
creator to simplify creating properties that are queried and set with commands. |
| 99 |
|
| 100 |
.. automethod:: VNA.command |
| 101 |
|
| 102 |
For `get_cmd` and `set_cmd`, you can substitute delimiters to be |
| 103 |
replaced when the call is made. `self` is always passed, so you can |
| 104 |
reference any part of "self" when making the call. Additionally, the |
| 105 |
`set_cmd` receives an additional parameter `arg` which is the argument |
| 106 |
passed to the setter. These can be used in the get/set strings by using |
| 107 |
angle bracket delimiters and referring to the name. Here are some |
| 108 |
examples: |
| 109 |
|
| 110 |
Here, we are assuming we are writing a command for an instrument with |
| 111 |
channels, and writing a command **for** the internal `Channel` class. |
| 112 |
In `get_cmd`, `<self:cnum>` gets the `self.cnum` property of the Channel |
| 113 |
class **at runtime**. In `set_cmd`, `<arg>` is replaced by the argument |
| 114 |
passed to the setter. |
| 115 |
|
| 116 |
.. code-block:: python |
| 117 |
|
| 118 |
freq_start = VNA.command( |
| 119 |
get_cmd="CALC<self:cnum>:FREQ:STAR?", |
| 120 |
set_cmd="CALC<self:cnum>:FREQ:STAR <arg>", |
| 121 |
) |
| 122 |
|
| 123 |
And here's an example of calling this function and what the resultant |
| 124 |
command strings would be after replacement. |
| 125 |
|
| 126 |
.. code-block:: python |
| 127 |
|
| 128 |
_ = instr.ch1.freq_start |
| 129 |
# Sends the command CALC1:FREQ:STAR? to the instrument |
| 130 |
instr.ch1.freq_start = 100 |
| 131 |
# Sends the command CALC1:FREQ:STAR 100 to the instrument |
| 132 |
|
| 133 |
|
| 134 |
Validators |
| 135 |
---------- |
| 136 |
|
| 137 |
Validators are (optionally, but almost always) passed to `VNA.command`. When a property |
| 138 |
is get or set, the appropriate validate command is called to convert input to the proper |
| 139 |
format expected by the instrument, or convert responses from the instrument to the |
| 140 |
proper type. |
| 141 |
|
| 142 |
The current validators are: |
| 143 |
* :class:`skrf.vi.validators.BooleanValidator` |
| 144 |
* :class:`skrf.vi.validators.DelimitedStrValidator` |
| 145 |
* :class:`skrf.vi.validators.DictValidator` |
| 146 |
* :class:`skrf.vi.validators.EnumValidator` |
| 147 |
* :class:`skrf.vi.validators.IntValidator` |
| 148 |
* :class:`skrf.vi.validators.FloatValidator` |
| 149 |
* :class:`skrf.vi.validators.FreqValidator` |
| 150 |
* :class:`skrf.vi.validators.SetValidator` |
| 151 |
|
| 152 |
The documentation for each of these explains more about their functionality, but in essence |
| 153 |
when writing a `VNA.command`, consider how the command must be formatted to be sent to the |
| 154 |
instrument and what the expected response from the instrument will be and how that can be |
| 155 |
transformed to something more useful than, say, a string. |
| 156 |
|
| 157 |
Here's an example of using a validator: |
| 158 |
|
| 159 |
.. code-block:: python |
| 160 |
|
| 161 |
freq_start = VNA.command( |
| 162 |
get_cmd="CALC:FREQ:STAR?", |
| 163 |
set_cmd="CALC:FREQ:STAR <arg>", |
| 164 |
validator=FreqValidator() |
| 165 |
) |
| 166 |
|
| 167 |
# ... |
| 168 |
|
| 169 |
# This will call FreqValidator.validate_input('100 kHz') to |
| 170 |
# transform the string '100 kHz' to '100000'. The full command |
| 171 |
# then becomes: |
| 172 |
# CALC:FREQ:STAR 100000 |
| 173 |
instr.ch1.freq_start = '100 Hz' |
| 174 |
|
| 175 |
# This will send the command CALC:FREQ:STAR? to the instrument |
| 176 |
# then send the response from the instrument to |
| 177 |
# FreqValidator.validate_output() to attempt to transform, as an |
| 178 |
# example, the string '100000' to the int 100_000 |
| 179 |
_ = instr.ch1.freq_start |
| 180 |
""" |
| 181 |
|
| 182 |
from .vna import VNA, Channel, ValuesFormat |
| 183 |
from . import keysight, nanovna, rohde_schwarz, hp |