| 1 |
{ |
| 2 |
"cells": [ |
| 3 |
{ |
| 4 |
"cell_type": "raw", |
| 5 |
"metadata": { |
| 6 |
"raw_mimetype": "text/restructuredtext" |
| 7 |
}, |
| 8 |
"source": [ |
| 9 |
".. _virtualinstruments:\n", |
| 10 |
"\n", |
| 11 |
"|\n", |
| 12 |
"|\n", |
| 13 |
"\n", |
| 14 |
"Download This Notebook: :download:`VirtualInstruments.ipynb`" |
| 15 |
] |
| 16 |
}, |
| 17 |
{ |
| 18 |
"cell_type": "markdown", |
| 19 |
"metadata": {}, |
| 20 |
"source": [ |
| 21 |
"# Virtual Instruments\n", |
| 22 |
" \n", |
| 23 |
"## Introduction" |
| 24 |
] |
| 25 |
}, |
| 26 |
{ |
| 27 |
"cell_type": "raw", |
| 28 |
"metadata": { |
| 29 |
"raw_mimetype": "text/restructuredtext" |
| 30 |
}, |
| 31 |
"source": [ |
| 32 |
".. warning::\n", |
| 33 |
"\n", |
| 34 |
" The `vi` modules depends on `PyVISA\n", |
| 35 |
" <https://pyvisa.readthedocs.io/en/latest/>`_ as well as some additional\n", |
| 36 |
" libraries. Make sure you've followed the instructions in the `installation\n", |
| 37 |
" tutorial <Installation.ipynb>`_ to ensure a working setup. \n", |
| 38 |
"\n", |
| 39 |
" Additionally, PyVISA can use a number of different backends to communicate\n", |
| 40 |
" with instruments. The installation of these is up to the user, but there are\n", |
| 41 |
" further instructions in the `PyVISA documentation <https://pyvisa.readthedocs.io>`_\n", |
| 42 |
" By default, PyVISA uses it's Python VISA implementation, but certain instrument\n", |
| 43 |
" configurations require their manufacturer's specific VISA library be\n", |
| 44 |
" installed and used to communicate with instruments. For example, the\n", |
| 45 |
" Keysight IO libraries suite has to be used to communicate with their\n", |
| 46 |
" instruments over GPIB." |
| 47 |
] |
| 48 |
}, |
| 49 |
{ |
| 50 |
"cell_type": "markdown", |
| 51 |
"metadata": {}, |
| 52 |
"source": [ |
| 53 |
"The virtual instrument module defines a consistent high-level interface for\n", |
| 54 |
"interacting with different types of instruments that can be controlled with SCPI\n", |
| 55 |
"(or other means). Primarily for scikit-rf, this is vector network analyzers\n", |
| 56 |
"(VNAs), but we are actively working on adding support for spectrum analyzers.\n", |
| 57 |
"\n", |
| 58 |
"For information on specific instruments, consult the [vi](../api/vi/index.rst)\n", |
| 59 |
"module's documentation.\n", |
| 60 |
"\n", |
| 61 |
"The currently supported instruments are (organized by manufacturer):\n", |
| 62 |
"\n", |
| 63 |
"### Rohde & Schwarz\n", |
| 64 |
"- [ZNA](../api/vi/generated/skrf.vi.vna.rohde_schwarz.ZNA.rst)\n", |
| 65 |
"- [ZVA](../api/vi/generated/skrf.vi.vna.rohde_schwarz.ZVA.rst)\n", |
| 66 |
"\n", |
| 67 |
"### Keysight\n", |
| 68 |
"- [FieldFox](../api/vi/generated/skrf.vi.vna.keysight.FieldFox.rst)\n", |
| 69 |
"- [PNA](../api/vi/generated/skrf.vi.vna.keysight.PNA.rst)\n", |
| 70 |
"\n", |
| 71 |
"### NanoVNA\n", |
| 72 |
"- [NanoVNA V2](../api/vi/generated/skrf.vi.vna.nanovna.NanoVNAv2.rst)" |
| 73 |
] |
| 74 |
}, |
| 75 |
{ |
| 76 |
"cell_type": "raw", |
| 77 |
"metadata": { |
| 78 |
"raw_mimetype": "text/restructuredtext" |
| 79 |
}, |
| 80 |
"source": [ |
| 81 |
".. tip::\n", |
| 82 |
"\n", |
| 83 |
" You can help grow scikit-rf by adding support for more instruments! It's\n", |
| 84 |
" really not that complicated. Check out the `vi module documentation <../api/vi/index.rst>`_ to\n", |
| 85 |
" learn how." |
| 86 |
] |
| 87 |
}, |
| 88 |
{ |
| 89 |
"cell_type": "markdown", |
| 90 |
"metadata": {}, |
| 91 |
"source": [ |
| 92 |
"\n", |
| 93 |
"## Examples" |
| 94 |
] |
| 95 |
}, |
| 96 |
{ |
| 97 |
"cell_type": "raw", |
| 98 |
"metadata": { |
| 99 |
"raw_mimetype": "text/restructuredtext" |
| 100 |
}, |
| 101 |
"source": [ |
| 102 |
".. note::\n", |
| 103 |
"\n", |
| 104 |
" You can download this Jupyter notebook and run it directly on your PC:\n", |
| 105 |
" :download:`VirtualInstruments.ipynb`\n", |
| 106 |
"\n", |
| 107 |
" Make sure to comment out any code that is not needed for your instrument." |
| 108 |
] |
| 109 |
}, |
| 110 |
{ |
| 111 |
"cell_type": "markdown", |
| 112 |
"metadata": {}, |
| 113 |
"source": "### Connecting to an instrument" |
| 114 |
}, |
| 115 |
{ |
| 116 |
"metadata": {}, |
| 117 |
"cell_type": "code", |
| 118 |
"outputs": [], |
| 119 |
"execution_count": null, |
| 120 |
"source": [ |
| 121 |
"from skrf import Frequency\n", |
| 122 |
"from skrf.vi.vna.keysight import PNA\n", |
| 123 |
"from skrf.vi.vna.nanovna import NanoVNAv2\n", |
| 124 |
"from skrf.vi.vna.rohde_schwarz import ZNA\n", |
| 125 |
"\n", |
| 126 |
"# Rohde & Schwarz ZNA over ethernet\n", |
| 127 |
"instr = ZNA(address=\"TCPIP::10.0.0.5::INSTR\")\n", |
| 128 |
"ch1 = instr.ch1\n", |
| 129 |
"\n", |
| 130 |
"# Keysight PNA over ethernet\n", |
| 131 |
"instr = PNA(address=\"TCPIP::10.0.0.5::INSTR\")\n", |
| 132 |
"ch1 = instr.ch1\n", |
| 133 |
"\n", |
| 134 |
"# NanoVNA V2 over USB\n", |
| 135 |
"instr = NanoVNAv2(\"ASRL/dev/ttyACM0::INSTR\") # Linux\n", |
| 136 |
"instr = NanoVNAv2(\"ASRL1::INSTR\") # Windows\n", |
| 137 |
"ch1 = instr # NanoVNA does not support channels\n", |
| 138 |
"\n", |
| 139 |
"print(instr.id)" |
| 140 |
] |
| 141 |
}, |
| 142 |
{ |
| 143 |
"cell_type": "markdown", |
| 144 |
"metadata": {}, |
| 145 |
"source": [ |
| 146 |
"### Changing the frequency settings of an instrument" |
| 147 |
] |
| 148 |
}, |
| 149 |
{ |
| 150 |
"metadata": {}, |
| 151 |
"cell_type": "code", |
| 152 |
"outputs": [], |
| 153 |
"execution_count": null, |
| 154 |
"source": [ |
| 155 |
"freq = Frequency(start=1, stop=2, npoints = 101, unit=\"GHz\") # create frequency object\n", |
| 156 |
"ch1.frequency = freq # apply frequency" |
| 157 |
] |
| 158 |
}, |
| 159 |
{ |
| 160 |
"cell_type": "markdown", |
| 161 |
"metadata": {}, |
| 162 |
"source": "### Creating measurements on the instrument" |
| 163 |
}, |
| 164 |
{ |
| 165 |
"metadata": {}, |
| 166 |
"cell_type": "code", |
| 167 |
"outputs": [], |
| 168 |
"execution_count": null, |
| 169 |
"source": [ |
| 170 |
"# not supported on NanoVNA\n", |
| 171 |
"ch1.create_measurement(name=\"Temp_S11\", parameter=\"S11\")\n", |
| 172 |
"ch1.create_measurement(name=\"Temp_S22\", parameter=\"S22\")" |
| 173 |
] |
| 174 |
}, |
| 175 |
{ |
| 176 |
"cell_type": "markdown", |
| 177 |
"metadata": {}, |
| 178 |
"source": "### Getting a 2-port network and plotting" |
| 179 |
}, |
| 180 |
{ |
| 181 |
"metadata": {}, |
| 182 |
"cell_type": "code", |
| 183 |
"outputs": [], |
| 184 |
"execution_count": null, |
| 185 |
"source": [ |
| 186 |
"ntwk = ch1.get_snp_network(ports=(1,2))\n", |
| 187 |
"ntwk.plot_s_db()" |
| 188 |
] |
| 189 |
}, |
| 190 |
{ |
| 191 |
"metadata": {}, |
| 192 |
"cell_type": "markdown", |
| 193 |
"source": "### Deleting measurements on the instrument" |
| 194 |
}, |
| 195 |
{ |
| 196 |
"metadata": {}, |
| 197 |
"cell_type": "code", |
| 198 |
"outputs": [], |
| 199 |
"execution_count": null, |
| 200 |
"source": [ |
| 201 |
"# not supported on NanoVNA\n", |
| 202 |
"ch1.delete_measurement(name=\"Temp_S11\")\n", |
| 203 |
"ch1.delete_measurement(name=\"Temp_S22\")" |
| 204 |
] |
| 205 |
} |
| 206 |
], |
| 207 |
"metadata": { |
| 208 |
"celltoolbar": "Raw Cell Format", |
| 209 |
"kernelspec": { |
| 210 |
"display_name": "Python 3.10.4 ('skrf')", |
| 211 |
"language": "python", |
| 212 |
"name": "python3" |
| 213 |
}, |
| 214 |
"language_info": { |
| 215 |
"codemirror_mode": { |
| 216 |
"name": "ipython", |
| 217 |
"version": 3 |
| 218 |
}, |
| 219 |
"file_extension": ".py", |
| 220 |
"mimetype": "text/x-python", |
| 221 |
"name": "python", |
| 222 |
"nbconvert_exporter": "python", |
| 223 |
"pygments_lexer": "ipython3", |
| 224 |
"version": "3.10.4" |
| 225 |
}, |
| 226 |
"vscode": { |
| 227 |
"interpreter": { |
| 228 |
"hash": "6e9ab46c0308d25f8ecf2297d605bcf30c0184a06f23fc8ad30aef47f26c08c0" |
| 229 |
} |
| 230 |
}, |
| 231 |
"nbsphinx": { |
| 232 |
"execute": "never" |
| 233 |
} |
| 234 |
}, |
| 235 |
"nbformat": 4, |
| 236 |
"nbformat_minor": 1 |
| 237 |
} |