| 1 |
# |
| 2 |
# This file is part of the PyMeasure package. |
| 3 |
# |
| 4 |
# Copyright (c) 2013-2024 PyMeasure Developers |
| 5 |
# |
| 6 |
# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 |
# of this software and associated documentation files (the "Software"), to deal |
| 8 |
# in the Software without restriction, including without limitation the rights |
| 9 |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 |
# copies of the Software, and to permit persons to whom the Software is |
| 11 |
# furnished to do so, subject to the following conditions: |
| 12 |
# |
| 13 |
# The above copyright notice and this permission notice shall be included in |
| 14 |
# all copies or substantial portions of the Software. |
| 15 |
# |
| 16 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 |
# THE SOFTWARE. |
| 23 |
# |
| 24 |
import logging |
| 25 |
|
| 26 |
from pymeasure.instruments import Instrument, Channel, SCPIUnknownMixin |
| 27 |
from pymeasure.instruments.validators import ( |
| 28 |
strict_discrete_set, |
| 29 |
strict_range |
| 30 |
) |
| 31 |
|
| 32 |
log = logging.getLogger(__name__) |
| 33 |
log.addHandler(logging.NullHandler()) |
| 34 |
|
| 35 |
|
| 36 |
class AnritsuMS464xB(SCPIUnknownMixin, Instrument): |
| 37 |
""" A class representing the Anritsu MS464xB Vector Network Analyzer (VNA) series. |
| 38 |
|
| 39 |
This family consists of the MS4642B, MS4644B, MS4645B, and MS4647B, which are represented in |
| 40 |
their respective classes (:class:`~.AnritsuMS4642B`, :class:`~.AnritsuMS4644B`, |
| 41 |
:class:`~.AnritsuMS4645B`, :class:`~.AnritsuMS4647B`), that only differ in the available |
| 42 |
frequency range. |
| 43 |
|
| 44 |
They can contain up to 16 instances of :class:`~.MeasurementChannel` (depending on the |
| 45 |
configuration of the instrument), that are accessible via the `channels` dict or directly via |
| 46 |
`ch_` + the channel number. |
| 47 |
|
| 48 |
:param active_channels: defines the number of active channels (default=16); if active_channels |
| 49 |
is "auto", the instrument will be queried for the number of active channels. |
| 50 |
:type active_channels: int (1-16) or str ("auto") |
| 51 |
:param installed_ports: defines the number of installed ports (default=4); if "auto" is |
| 52 |
provided, the instrument will be queried for the number of ports |
| 53 |
:type installed_ports: int (1-4) or str ("auto") |
| 54 |
:param traces_per_channel: defines the number of traces that is assumed for each channel |
| 55 |
(between 1 and 16); if not provided, the maximum number is assumed; "auto" is provided, |
| 56 |
the instrument will be queried for the number of traces of each channel. |
| 57 |
:type traces_per_channel: int (1-16) or str ("auto") or None |
| 58 |
""" |
| 59 |
CHANNELS_MAX = 16 |
| 60 |
TRACES_MAX = 16 |
| 61 |
PORTS = 4 |
| 62 |
TRIGGER_TYPES = ["POIN", "SWE", "CHAN", "ALL"] |
| 63 |
|
| 64 |
FREQUENCY_RANGE = [1E7, 7E10] |
| 65 |
|
| 66 |
SPARAM_LIST = ["S11", "S12", "S21", "S22", |
| 67 |
"S13", "S23", "S33", "S31", |
| 68 |
"S32", "S14", "S24", "S34", |
| 69 |
"S41", "S42", "S43", "S44", ] |
| 70 |
DISPLAY_LAYOUTS = ["R1C1", "R1C2", "R2C1", "R1C3", "R3C1", |
| 71 |
"R2C2C1", "R2C1C2", "C2R2R1", "C2R1R2", |
| 72 |
"R1C4", "R4C1", "R2C2", "R2C3", "R3C2", |
| 73 |
"R2C4", "R4C2", "R3C3", "R5C2", "R2C5", |
| 74 |
"R4C3", "R3C4", "R4C4"] |
| 75 |
|
| 76 |
def __init__(self, adapter, |
| 77 |
name="Anritsu MS464xB Vector Network Analyzer", |
| 78 |
active_channels=16, |
| 79 |
installed_ports=4, |
| 80 |
traces_per_channel=None, |
| 81 |
**kwargs): |
| 82 |
super().__init__( |
| 83 |
adapter, |
| 84 |
name, |
| 85 |
timeout=10000, |
| 86 |
**kwargs, |
| 87 |
) |
| 88 |
|
| 89 |
self.PORTS = self.number_of_ports if installed_ports == "auto" else installed_ports |
| 90 |
|
| 91 |
number_of_channels = None if active_channels == "auto" else active_channels |
| 92 |
|
| 93 |
self.update_channels(number_of_channels=number_of_channels, |
| 94 |
traces=traces_per_channel) |
| 95 |
|
| 96 |
def update_channels(self, number_of_channels=None, **kwargs): |
| 97 |
"""Create or remove channels to be correct with the actual number of channels. |
| 98 |
|
| 99 |
:param int number_of_channels: optional, if given, defines the desired number of channels. |
| 100 |
""" |
| 101 |
if number_of_channels is None: |
| 102 |
number_of_channels = self.number_of_channels |
| 103 |
|
| 104 |
if not hasattr(self, "channels"): |
| 105 |
self.channels = {} |
| 106 |
|
| 107 |
if len(self.channels) == number_of_channels: |
| 108 |
return |
| 109 |
|
| 110 |
# Remove redundant channels |
| 111 |
while len(self.channels) > number_of_channels: |
| 112 |
self.remove_child(self.channels[len(self.channels)]) |
| 113 |
|
| 114 |
# Create new channels |
| 115 |
while len(self.channels) < number_of_channels: |
| 116 |
self.add_child(MeasurementChannel, len(self.channels) + 1, |
| 117 |
frequency_range=self.FREQUENCY_RANGE, |
| 118 |
**kwargs) |
| 119 |
|
| 120 |
def check_errors(self): |
| 121 |
""" Read all errors from the instrument. |
| 122 |
|
| 123 |
:return: list of error entries |
| 124 |
""" |
| 125 |
errors = [] |
| 126 |
while True: |
| 127 |
err = self.values("SYST:ERR?") |
| 128 |
if err[0] != "No Error": |
| 129 |
log.error(f"{self.name}: {err[0]}") |
| 130 |
errors.append(err) |
| 131 |
else: |
| 132 |
break |
| 133 |
return errors |
| 134 |
|
| 135 |
datablock_header_format = Instrument.control( |
| 136 |
"FDHX?", "FDH%d", |
| 137 |
"""Control the way the arbitrary block header for output data is formed. |
| 138 |
|
| 139 |
Valid values are: |
| 140 |
|
| 141 |
===== =========================================================== |
| 142 |
value description |
| 143 |
===== =========================================================== |
| 144 |
0 A block header with arbitrary length will be sent. |
| 145 |
1 The block header will have a fixed length of 11 characters. |
| 146 |
2 No block header will be sent. Not IEEE 488.2 compliant. |
| 147 |
===== =========================================================== |
| 148 |
""", |
| 149 |
values=[0, 1, 2], |
| 150 |
validator=strict_discrete_set, |
| 151 |
cast=int, |
| 152 |
) |
| 153 |
|
| 154 |
datafile_frequency_unit = Instrument.control( |
| 155 |
":FORM:SNP:FREQ?", ":FORM:SNP:FREQ %s", |
| 156 |
"""Control the frequency unit displayed in a SNP data file. |
| 157 |
|
| 158 |
Valid values are HZ, KHZ, MHZ, GHZ. |
| 159 |
""", |
| 160 |
values=["HZ", "KHZ", "MHZ", "GHZ"], |
| 161 |
validator=strict_discrete_set, |
| 162 |
) |
| 163 |
|
| 164 |
datablock_numeric_format = Instrument.control( |
| 165 |
":FORM:DATA?", ":FORM:DATA %s", |
| 166 |
"""Control format for numeric I/O data representation. |
| 167 |
|
| 168 |
Valid values are: |
| 169 |
|
| 170 |
===== ========================================================================== |
| 171 |
value description |
| 172 |
===== ========================================================================== |
| 173 |
ASCII An ASCII number of 20 or 21 characters long with floating point notation. |
| 174 |
8byte 8 bytes of binary floating point number representation limited to 64 bits. |
| 175 |
4byte 4 bytes of floating point number representation. |
| 176 |
===== ========================================================================== |
| 177 |
""", |
| 178 |
values={"ASCII": "ASC", "8byte": "REAL", "4byte": "REAL32"}, |
| 179 |
map_values=True, |
| 180 |
) |
| 181 |
|
| 182 |
datafile_include_heading = Instrument.control( |
| 183 |
":FORM:DATA:HEAD?", ":FORM:DATA:HEAD %d", |
| 184 |
"""Control whether a heading is included in the data files. """, |
| 185 |
values={True: 1, False: 0}, |
| 186 |
map_values=True, |
| 187 |
) |
| 188 |
|
| 189 |
datafile_parameter_format = Instrument.control( |
| 190 |
":FORM:SNP:PAR?", ":FORM:SNP:PAR %s", |
| 191 |
"""Control the parameter format displayed in an SNP data file. |
| 192 |
|
| 193 |
Valid values are: |
| 194 |
|
| 195 |
===== =========================== |
| 196 |
value description |
| 197 |
===== =========================== |
| 198 |
LINPH Linear and Phase. |
| 199 |
LOGPH Log and Phase. |
| 200 |
REIM Real and Imaginary Numbers. |
| 201 |
===== =========================== |
| 202 |
""", |
| 203 |
values=["LINPH", "LOGPH", "REIM"], |
| 204 |
validator=strict_discrete_set, |
| 205 |
) |
| 206 |
|
| 207 |
data_drawing_enabled = Instrument.control( |
| 208 |
"DD1?", "DD%d", |
| 209 |
"""Control whether data drawing is enabled (True) or not (False). """, |
| 210 |
values={True: 1, False: 0}, |
| 211 |
map_values=True, |
| 212 |
) |
| 213 |
|
| 214 |
event_status_enable_bits = Instrument.control( |
| 215 |
"*ESE?", "*ESE %d", |
| 216 |
"""Control the Standard Event Status Enable Register bits. |
| 217 |
|
| 218 |
The register can be queried using the :meth:`~.query_event_status_register` method. Valid |
| 219 |
values are between 0 and 255. Refer to the instrument manual for an explanation of the bits. |
| 220 |
""", |
| 221 |
values=[0, 255], |
| 222 |
validator=strict_range, |
| 223 |
cast=int, |
| 224 |
) |
| 225 |
|
| 226 |
def query_event_status_register(self): |
| 227 |
""" Query the value of the Standard Event Status Register. |
| 228 |
|
| 229 |
Note that querying this value, clears the register. Refer to the instrument manual for an |
| 230 |
explanation of the returned value. |
| 231 |
""" |
| 232 |
return self.values("*ESR?", cast=int)[0] |
| 233 |
|
| 234 |
service_request_enable_bits = Instrument.control( |
| 235 |
"*SRE?", "*SRE %d", |
| 236 |
"""Control the Service Request Enable Register bits. |
| 237 |
|
| 238 |
Valid values are between 0 and 255; setting 0 performs a register reset. Refer to the |
| 239 |
instrument manual for an explanation of the bits. |
| 240 |
""", |
| 241 |
values=[0, 255], |
| 242 |
validator=strict_range, |
| 243 |
cast=int, |
| 244 |
) |
| 245 |
|
| 246 |
def return_to_local(self): |
| 247 |
""" Returns the instrument to local operation. """ |
| 248 |
self.write("RTL") |
| 249 |
|
| 250 |
binary_data_byte_order = Instrument.control( |
| 251 |
":FORM:BORD?", ":FORM:BORD %s", |
| 252 |
"""Control the binary numeric I/O data byte order. |
| 253 |
|
| 254 |
valid values are: |
| 255 |
|
| 256 |
===== ========================================= |
| 257 |
value description |
| 258 |
===== ========================================= |
| 259 |
NORM The most significant byte (MSB) is first |
| 260 |
SWAP The least significant byte (LSB) is first |
| 261 |
===== ========================================= |
| 262 |
""", |
| 263 |
values=["NORM", "SWAP"], |
| 264 |
validator=strict_discrete_set, |
| 265 |
) |
| 266 |
|
| 267 |
max_number_of_points = Instrument.control( |
| 268 |
":SYST:POIN:MAX?", ":SYST:POIN:MAX %d", |
| 269 |
"""Control the maximum number of points the instrument can measure in a sweep. |
| 270 |
|
| 271 |
Note that when this value is changed, the instrument will be rebooted. |
| 272 |
Valid values are 25000 and 100000. When 25000 points is selected, the instrument supports 16 |
| 273 |
channels with 16 traces each; when 100000 is selected, the instrument supports 1 channel |
| 274 |
with 16 traces. |
| 275 |
""", |
| 276 |
values=[25000, 100000], |
| 277 |
validator=strict_discrete_set, |
| 278 |
cast=int, |
| 279 |
) |
| 280 |
|
| 281 |
number_of_ports = Instrument.measurement( |
| 282 |
":SYST:PORT:COUN?", |
| 283 |
"""Get the number of instrument test ports. """, |
| 284 |
cast=int, |
| 285 |
) |
| 286 |
|
| 287 |
number_of_channels = Instrument.control( |
| 288 |
":DISP:COUN?", ":DISP:COUN %d", |
| 289 |
"""Control the number of displayed (and therefore accessible) channels. |
| 290 |
|
| 291 |
When the system is in 25000 points mode, the number of channels can be 1, 2, 3, 4, 6, 8, 9, |
| 292 |
10, 12, or 16; when the system is in 100000 points mode, the system only supports 1 channel. |
| 293 |
If a value is provided that is not valid in the present mode, the instrument is set to the |
| 294 |
next higher channel number. |
| 295 |
""", |
| 296 |
values=[1, CHANNELS_MAX], |
| 297 |
validator=strict_range, |
| 298 |
cast=int, |
| 299 |
) |
| 300 |
|
| 301 |
display_layout = Instrument.control( |
| 302 |
":DISP:SPL?", ":DISP:SPL %s", |
| 303 |
"""Control the channel display layout in a Row-by-Column format. |
| 304 |
|
| 305 |
Valid values are: {}. The number following the R indicates the number of rows, following the |
| 306 |
C the number of columns; e.g. R2C2 results in a 2-by-2 layout. The options that contain two |
| 307 |
C's or R's result in asymmetric layouts; e.g. R2C1C2 results in a layout with 1 channel on |
| 308 |
top and two channels side-by-side on the bottom row. |
| 309 |
""".format(", ".join(DISPLAY_LAYOUTS)), |
| 310 |
values=DISPLAY_LAYOUTS, |
| 311 |
validator=strict_discrete_set, |
| 312 |
cast=str, |
| 313 |
) |
| 314 |
|
| 315 |
active_channel = Instrument.control( |
| 316 |
":DISP:WIND:ACT?", ":DISP:WIND%d:ACT", |
| 317 |
"""Control the active channel. """, |
| 318 |
values=[1, CHANNELS_MAX], |
| 319 |
validator=strict_range, |
| 320 |
cast=int, |
| 321 |
) |
| 322 |
|
| 323 |
bandwidth_enhancer_enabled = Instrument.control( |
| 324 |
":SENS:BAND:ENH?", ":SENS:BAND:ENH %d", |
| 325 |
"""Control the state of the IF bandwidth enhancer. """, |
| 326 |
values={True: 1, False: 0}, |
| 327 |
map_values=True, |
| 328 |
) |
| 329 |
|
| 330 |
trigger_source = Instrument.control( |
| 331 |
":TRIG:SOUR?", ":TRIG:SOUR %s", |
| 332 |
"""Control the source of the sweep/measurement triggering. |
| 333 |
|
| 334 |
Valid values are: |
| 335 |
|
| 336 |
===== ================================================== |
| 337 |
value description |
| 338 |
===== ================================================== |
| 339 |
AUTO Automatic triggering |
| 340 |
MAN Manual triggering |
| 341 |
EXTT Triggering from rear panel BNC via the GPIB parser |
| 342 |
EXT External triggering port |
| 343 |
REM Remote triggering |
| 344 |
===== ================================================== |
| 345 |
""", |
| 346 |
values=["AUTO", "MAN", "EXTT", "EXT", "REM"], |
| 347 |
validator=strict_discrete_set, |
| 348 |
) |
| 349 |
|
| 350 |
external_trigger_type = Instrument.control( |
| 351 |
":TRIG:EXT:TYP?", ":TRIG:EXT:TYP %s", |
| 352 |
"""Control the type of trigger that will be associated with the external trigger. |
| 353 |
|
| 354 |
Valid values are POIN (for point), SWE (for sweep), CHAN (for channel), and ALL. |
| 355 |
""", |
| 356 |
values=TRIGGER_TYPES, |
| 357 |
validator=strict_discrete_set, |
| 358 |
) |
| 359 |
|
| 360 |
external_trigger_delay = Instrument.control( |
| 361 |
":TRIG:EXT:DEL?", ":TRIG:EXT:DEL %g", |
| 362 |
"""Control the delay time of the external trigger in seconds. |
| 363 |
|
| 364 |
Valid values are between 0 [s] and 10 [s] in steps of 1e-9 [s] (i.e. 1 ns). |
| 365 |
""", |
| 366 |
values=[0, 10], |
| 367 |
validator=strict_range, |
| 368 |
) |
| 369 |
|
| 370 |
external_trigger_edge = Instrument.control( |
| 371 |
":TRIG:EXT:EDG?", ":TRIG:EXT:EDG %s", |
| 372 |
"""Control the edge type of the external trigger. |
| 373 |
|
| 374 |
Valid values are POS (for positive or leading edge) or NEG (for negative or trailing edge). |
| 375 |
""", |
| 376 |
values=["POS", "NEG"], |
| 377 |
validator=strict_discrete_set, |
| 378 |
) |
| 379 |
|
| 380 |
external_trigger_handshake = Instrument.control( |
| 381 |
":TRIG:EXT:HAND?", ":TRIG:EXT:HAND %s", |
| 382 |
"""Control status of the external trigger handshake. """, |
| 383 |
values={True: 1, False: 0}, |
| 384 |
map_values=True, |
| 385 |
) |
| 386 |
|
| 387 |
remote_trigger_type = Instrument.control( |
| 388 |
":TRIG:REM:TYP?", ":TRIG:REM:TYP %s", |
| 389 |
"""Control the type of trigger that will be associated with the remote trigger. |
| 390 |
|
| 391 |
Valid values are POIN (for point), SWE (for sweep), CHAN (for channel), and ALL. |
| 392 |
""", |
| 393 |
values=TRIGGER_TYPES, |
| 394 |
validator=strict_discrete_set, |
| 395 |
) |
| 396 |
|
| 397 |
manual_trigger_type = Instrument.control( |
| 398 |
":TRIG:MAN:TYP?", ":TRIG:MAN:TYP %s", |
| 399 |
"""Control the type of trigger that will be associated with the manual trigger. |
| 400 |
|
| 401 |
Valid values are POIN (for point), SWE (for sweep), CHAN (for channel), and ALL. |
| 402 |
""", |
| 403 |
values=TRIGGER_TYPES, |
| 404 |
validator=strict_discrete_set, |
| 405 |
) |
| 406 |
|
| 407 |
def trigger(self): |
| 408 |
""" Trigger a continuous sweep from the remote interface. """ |
| 409 |
self.write("*TRG") |
| 410 |
|
| 411 |
def trigger_single(self): |
| 412 |
""" Trigger a single sweep with synchronization from the remote interface. """ |
| 413 |
self.write(":TRIG:SING") |
| 414 |
|
| 415 |
def trigger_continuous(self): |
| 416 |
""" Trigger a continuous sweep from the remote interface. """ |
| 417 |
self.write(":TRIG") |
| 418 |
|
| 419 |
hold_function_all_channels = Instrument.control( |
| 420 |
":SENS:HOLD:FUNC?", ":SENS:HOLD:FUNC %s", |
| 421 |
"""Control the hold function of all channels. |
| 422 |
|
| 423 |
Valid values are: |
| 424 |
|
| 425 |
===== ================================================= |
| 426 |
value description |
| 427 |
===== ================================================= |
| 428 |
CONT Perform continuous sweeps on all channels |
| 429 |
HOLD Hold the sweep on all channels |
| 430 |
SING Perform a single sweep and then hold all channels |
| 431 |
===== ================================================= |
| 432 |
""", |
| 433 |
values=["CONT", "HOLD", "SING"], |
| 434 |
validator=strict_discrete_set, |
| 435 |
) |
| 436 |
|
| 437 |
def load_data_file(self, filename): |
| 438 |
"""Load a data file from the VNA HDD into the VNA memory. |
| 439 |
|
| 440 |
:param str filename: full filename including path |
| 441 |
""" |
| 442 |
|
| 443 |
self.write(f":MMEM:LOAD '{filename}'") |
| 444 |
|
| 445 |
def delete_data_file(self, filename): |
| 446 |
"""Delete a file on the VNA HDD. |
| 447 |
|
| 448 |
:param str filename: full filename including path |
| 449 |
""" |
| 450 |
self.write(f":MMEM:DEL '{filename}'") |
| 451 |
|
| 452 |
def copy_data_file(self, from_filename, to_filename): |
| 453 |
"""Copy a file on the VNA HDD. |
| 454 |
|
| 455 |
:param str from_filename: full filename including pat |
| 456 |
:param str to_filename: full filename including path |
| 457 |
""" |
| 458 |
self.write(f":MMEM:COPY '{from_filename}', '{to_filename}'") |
| 459 |
|
| 460 |
def load_data_file_to_memory(self, filename): |
| 461 |
"""Load a data file to a memory trace. |
| 462 |
|
| 463 |
:param str filename: full filename including path |
| 464 |
""" |
| 465 |
self.write(f":MMEM:LOAD:MDATA '{filename}'") |
| 466 |
|
| 467 |
def create_directory(self, dir_name): |
| 468 |
"""Create a directory on the VNA HDD. |
| 469 |
|
| 470 |
:param str dir_name: directory name |
| 471 |
""" |
| 472 |
self.write(f":MMEM:MDIR '{dir_name}'") |
| 473 |
|
| 474 |
def delete_directory(self, dir_name): |
| 475 |
"""Delete a directory on the VNA HDD. |
| 476 |
|
| 477 |
:param str dir_name: directory name |
| 478 |
""" |
| 479 |
self.write(f":MMEM:RDIR '{dir_name}'") |
| 480 |
|
| 481 |
def store_image(self, filename): |
| 482 |
"""Capture a screenshot to the file specified. |
| 483 |
|
| 484 |
:param str filename: full filename including path |
| 485 |
""" |
| 486 |
self.write(f":MMEM:STOR:IMAG '{filename}'") |
| 487 |
|
| 488 |
def read_datafile( |
| 489 |
self, |
| 490 |
channel, |
| 491 |
sweep_points, |
| 492 |
datafile_freq, |
| 493 |
datafile_par, |
| 494 |
filename, |
| 495 |
): |
| 496 |
"""Read a data file from the VNA. |
| 497 |
|
| 498 |
:param int channel: Channel Index |
| 499 |
:param int sweep_points: number of sweep point as an integer |
| 500 |
:param DataFileFrequencyUnits datafile_freq: Data file frequency unit |
| 501 |
:param DataFileParameter datafile_par: Data file parameter format |
| 502 |
:param str filename: full path of the file to be saved |
| 503 |
""" |
| 504 |
cur_ch = self.channels[channel] # type: MeasurementChannel |
| 505 |
cur_ch.sweep_points = sweep_points |
| 506 |
self.datafile_frequency_unit = datafile_freq |
| 507 |
self.datafile_parameter_format = datafile_par |
| 508 |
self.write("TRS;WFS;OS2P") |
| 509 |
|
| 510 |
bytes_to_transfer = int(self.read_bytes(11)[2:11]) |
| 511 |
data = self.read_bytes(bytes_to_transfer) |
| 512 |
with open(filename, "w") as textfile: |
| 513 |
data_list = data.split(b"\r\n") |
| 514 |
for s in data_list: |
| 515 |
textfile.write(str(s)[2 : len(s)] + "\n") # noqa |
| 516 |
|
| 517 |
|
| 518 |
class Port(Channel): |
| 519 |
"""Represents a port within a :class:`~.MeasurementChannel` of the Anritsu MS464xB VNA. """ |
| 520 |
placeholder = "pt" |
| 521 |
|
| 522 |
power_level = Channel.control( |
| 523 |
":SOUR{{ch}}:POW:PORT{pt}?", ":SOUR{{ch}}:POW:PORT{pt} %g", |
| 524 |
"""Control the power level (in dBm) of the indicated port on the indicated channel. """, |
| 525 |
values=[-3E1, 3E1], |
| 526 |
validator=strict_range, |
| 527 |
) |
| 528 |
|
| 529 |
|
| 530 |
class Trace(Channel): |
| 531 |
"""Represents a trace within a :class:`~.MeasurementChannel` of the Anritsu MS464xB VNA. """ |
| 532 |
placeholder = "tr" |
| 533 |
|
| 534 |
def activate(self): |
| 535 |
""" Set the indicated trace as the active one. """ |
| 536 |
self.write(":CALC{{ch}}:PAR{tr}:SEL") |
| 537 |
|
| 538 |
measurement_parameter = Channel.control( |
| 539 |
":CALC{{ch}}:PAR{tr}:DEF?", ":CALC{{ch}}:PAR{tr}:DEF %s", |
| 540 |
"""Control the measurement parameter of the indicated trace. |
| 541 |
|
| 542 |
Valid values are any S-parameter (e.g. S11, S12, S41) for 4 ports, or one of the |
| 543 |
following: |
| 544 |
|
| 545 |
===== ================================================================ |
| 546 |
value description |
| 547 |
===== ================================================================ |
| 548 |
Sxx S-parameters (1-4 for both x) |
| 549 |
MIX Response Mixed Mode |
| 550 |
NFIG Noise Figure trace response (only with option 41 or 48) |
| 551 |
NPOW Noise Power trace response (only with option 41 or 48) |
| 552 |
NTEMP Noise Temperature trace response (only with option 41 or 48) |
| 553 |
AGA Noise Figure Available Gain trace response (only with option 48) |
| 554 |
IGA Noise Figure Insertion Gain trace response (only with option 48) |
| 555 |
===== ================================================================ |
| 556 |
""", |
| 557 |
values=AnritsuMS464xB.SPARAM_LIST + ["MIX", "NFIG", "NPOW", "NTEMP", "AGA", "IGA"], |
| 558 |
validator=strict_discrete_set, |
| 559 |
) |
| 560 |
|
| 561 |
|
| 562 |
class MeasurementChannel(Channel): |
| 563 |
"""Represents a channel of Anritsu MS464xB VNA. |
| 564 |
|
| 565 |
Contains 4 instances of :class:`~.Port` (accessible via the `ports` dict or directly `pt_` + the |
| 566 |
port number) and up to 16 instances of :class:`~.Trace` (accessible via the `traces` dict or |
| 567 |
directly `tr_` + the trace number). |
| 568 |
|
| 569 |
:param frequency_range: defines the number of installed ports (default=4). |
| 570 |
:type frequency_range: list of floats |
| 571 |
:param traces: defines the number of traces that is assumed for the channel |
| 572 |
(between 1 and 16); if not provided, the maximum number is assumed; "auto" is provided, |
| 573 |
the instrument will be queried for the number of traces. |
| 574 |
:type traces: int (1-16) or str ("auto") or None |
| 575 |
""" |
| 576 |
|
| 577 |
def __init__(self, *args, frequency_range=None, traces=None, **kwargs): |
| 578 |
super().__init__(*args, **kwargs) |
| 579 |
|
| 580 |
for pt in range(self.parent.PORTS): |
| 581 |
self.add_child(Port, pt + 1, collection="ports", prefix="pt_") |
| 582 |
|
| 583 |
if traces is None: |
| 584 |
number_of_traces = self.parent.TRACES_MAX |
| 585 |
elif traces == "auto": |
| 586 |
number_of_traces = None |
| 587 |
else: |
| 588 |
number_of_traces = traces |
| 589 |
|
| 590 |
self.update_traces(number_of_traces) |
| 591 |
|
| 592 |
if frequency_range is not None: |
| 593 |
self.update_frequency_range(frequency_range) |
| 594 |
|
| 595 |
def update_frequency_range(self, frequency_range): |
| 596 |
"""Update the values-attribute of the frequency-related dynamic properties. |
| 597 |
|
| 598 |
:param list frequency_range: the frequency range that the instrument is capable of. |
| 599 |
""" |
| 600 |
self.frequency_start_values = frequency_range |
| 601 |
self.frequency_stop_values = frequency_range |
| 602 |
self.frequency_center_values = frequency_range |
| 603 |
self.frequency_CW_values = frequency_range |
| 604 |
|
| 605 |
self.frequency_span_values = [2, frequency_range[1]] |
| 606 |
|
| 607 |
def update_traces(self, number_of_traces=None): |
| 608 |
"""Create or remove traces to be correct with the actual number of traces. |
| 609 |
|
| 610 |
:param int number_of_traces: optional, if given defines the desired number of traces. |
| 611 |
""" |
| 612 |
if number_of_traces is None: |
| 613 |
number_of_traces = self.number_of_traces |
| 614 |
|
| 615 |
if not hasattr(self, "traces"): |
| 616 |
self.traces = {} |
| 617 |
|
| 618 |
if len(self.traces) == number_of_traces: |
| 619 |
return |
| 620 |
|
| 621 |
# Remove redant channels |
| 622 |
while len(self.traces) > number_of_traces: |
| 623 |
self.remove_child(self.traces[len(self.traces)]) |
| 624 |
|
| 625 |
# Remove create new channels |
| 626 |
while len(self.traces) < number_of_traces: |
| 627 |
self.add_child(Trace, len(self.traces) + 1, collection="traces", prefix="tr_") |
| 628 |
|
| 629 |
def check_errors(self): |
| 630 |
return self.parent.check_errors() |
| 631 |
|
| 632 |
def activate(self): |
| 633 |
""" Set the indicated channel as the active channel. """ |
| 634 |
self.write(":DISP:WIND{ch}:ACT") |
| 635 |
|
| 636 |
number_of_traces = Channel.control( |
| 637 |
":CALC{ch}:PAR:COUN?", ":CALC{ch}:PAR:COUN %d", |
| 638 |
"""Control the number of traces on the specified channel |
| 639 |
|
| 640 |
Valid values are between 1 and 16. |
| 641 |
""", |
| 642 |
values=[1, AnritsuMS464xB.TRACES_MAX], |
| 643 |
validator=strict_range, |
| 644 |
cast=int, |
| 645 |
) |
| 646 |
|
| 647 |
active_trace = Channel.setting( |
| 648 |
":CALC{ch}:PAR%d:SEL", |
| 649 |
"""Set the active trace on the indicated channel. """, |
| 650 |
values=[1, AnritsuMS464xB.TRACES_MAX], |
| 651 |
validator=strict_range, |
| 652 |
) |
| 653 |
|
| 654 |
display_layout = Channel.control( |
| 655 |
":DISP:WIND{ch}:SPL?", ":DISP:WIND{ch}:SPL %s", |
| 656 |
"""Control the trace display layout in a Row-by-Column format for the indicated channel. |
| 657 |
|
| 658 |
Valid values are: {}. The number following the R indicates the number of rows, following the |
| 659 |
C the number of columns; e.g. R2C2 results in a 2-by-2 layout. The options that contain two |
| 660 |
C's or R's result in asymmetric layouts; e.g. R2C1C2 results in a layout with 1 trace on top |
| 661 |
and two traces side-by-side on the bottom row. |
| 662 |
""".format(", ".join(AnritsuMS464xB.DISPLAY_LAYOUTS)), |
| 663 |
values=AnritsuMS464xB.DISPLAY_LAYOUTS, |
| 664 |
validator=strict_discrete_set, |
| 665 |
cast=str, |
| 666 |
) |
| 667 |
|
| 668 |
application_type = Channel.control( |
| 669 |
":CALC{ch}:APPL:MEAS:TYP?", ":CALC{ch}:APPL:MEAS:TYP %s", |
| 670 |
"""Control the application type of the specified channel. |
| 671 |
|
| 672 |
Valid values are TRAN (for transmission/reflection), NFIG (for noise figure measurement), |
| 673 |
PULS (for PulseView). |
| 674 |
""", |
| 675 |
values=["TRAN", "NFIG", "PULS"], |
| 676 |
validator=strict_discrete_set, |
| 677 |
) |
| 678 |
|
| 679 |
hold_function = Channel.control( |
| 680 |
":SENS{ch}:HOLD:FUNC?", ":SENS{ch}:HOLD:FUNC %s", |
| 681 |
"""Control the hold function of the specified channel. |
| 682 |
|
| 683 |
valid values are: |
| 684 |
|
| 685 |
===== ================================================= |
| 686 |
value description |
| 687 |
===== ================================================= |
| 688 |
CONT Perform continuous sweeps on all channels |
| 689 |
HOLD Hold the sweep on all channels |
| 690 |
SING Perform a single sweep and then hold all channels |
| 691 |
===== ================================================= |
| 692 |
""", |
| 693 |
values=["CONT", "HOLD", "SING"], |
| 694 |
validator=strict_discrete_set, |
| 695 |
) |
| 696 |
|
| 697 |
cw_mode_enabled = Channel.control( |
| 698 |
":SENS{ch}:SWE:CW?", ":SENS{ch}:SWE:CW %d", |
| 699 |
"""Control the state of the CW sweep mode of the indicated channel. """, |
| 700 |
values={True: 1, False: 0}, |
| 701 |
map_values=True, |
| 702 |
) |
| 703 |
|
| 704 |
cw_number_of_points = Channel.control( |
| 705 |
":SENS{ch}:SWE:CW:POIN?", ":SENS{ch}:SWE:CW:POIN %g", |
| 706 |
"""Control the CW sweep mode number of points of the indicated channel. |
| 707 |
|
| 708 |
Valid values are between 1 and 25000 or 100000 depending on the maximum points setting. |
| 709 |
""", |
| 710 |
values=[1, 100000], |
| 711 |
validator=strict_range, |
| 712 |
cast=int, |
| 713 |
) |
| 714 |
|
| 715 |
number_of_points = Channel.control( |
| 716 |
"SENS{ch}:SWE:POIN?", "SENS{ch}:SWE:POIN %g", |
| 717 |
"""Control the number of measurement points in a frequency sweep of the indicated channel. |
| 718 |
|
| 719 |
Valid values are between 1 and 25000 or 100000 depending on the maximum points setting. |
| 720 |
""", |
| 721 |
values=[1, 100000], |
| 722 |
validator=strict_range, |
| 723 |
cast=int, |
| 724 |
) |
| 725 |
|
| 726 |
frequency_start = Channel.control( |
| 727 |
":SENS{ch}:FREQ:STAR?", ":SENS{ch}:FREQ:STAR %g", |
| 728 |
"""Control the start value of the sweep range of the indicated channel in hertz. |
| 729 |
|
| 730 |
Valid values are between 1E7 [Hz] (i.e. 10 MHz) and 4E10 [Hz] (i.e. 40 GHz). |
| 731 |
""", |
| 732 |
values=AnritsuMS464xB.FREQUENCY_RANGE, |
| 733 |
validator=strict_range, |
| 734 |
dynamic=True, |
| 735 |
) |
| 736 |
|
| 737 |
frequency_stop = Channel.control( |
| 738 |
":SENS{ch}:FREQ:STOP?", ":SENS{ch}:FREQ:STOP %g", |
| 739 |
"""Control the stop value of the sweep range of the indicated channel in hertz. |
| 740 |
|
| 741 |
Valid values are between 1E7 [Hz] (i.e. 10 MHz) and 4E10 [Hz] (i.e. 40 GHz). |
| 742 |
""", |
| 743 |
values=AnritsuMS464xB.FREQUENCY_RANGE, |
| 744 |
validator=strict_range, |
| 745 |
dynamic=True, |
| 746 |
) |
| 747 |
|
| 748 |
frequency_span = Channel.control( |
| 749 |
":SENS{ch}:FREQ:SPAN?", ":SENS{ch}:FREQ:SPAN %g", |
| 750 |
"""Control the span value of the sweep range of the indicated channel in hertz. |
| 751 |
|
| 752 |
Valid values are between 2 [Hz] and 4E10 [Hz] (i.e. 40 GHz). |
| 753 |
""", |
| 754 |
values=[2, AnritsuMS464xB.FREQUENCY_RANGE[1]], |
| 755 |
validator=strict_range, |
| 756 |
dynamic=True, |
| 757 |
) |
| 758 |
|
| 759 |
frequency_center = Channel.control( |
| 760 |
":SENS{ch}:FREQ:CENT?", ":SENS{ch}:FREQ:CENT %g", |
| 761 |
"""Control the center value of the sweep range of the indicated channel in hertz. |
| 762 |
|
| 763 |
Valid values are between 1E7 [Hz] (i.e. 10 MHz) and 4E10 [Hz] (i.e. 40 GHz). |
| 764 |
""", |
| 765 |
values=AnritsuMS464xB.FREQUENCY_RANGE, |
| 766 |
validator=strict_range, |
| 767 |
dynamic=True, |
| 768 |
) |
| 769 |
|
| 770 |
frequency_CW = Channel.control( |
| 771 |
":SENS{ch}:FREQ:CW?", ":SENS{ch}:FREQ:CW %g", |
| 772 |
"""Control the CW frequency of the indicated channel in hertz. |
| 773 |
|
| 774 |
Valid values are between 1E7 [Hz] (i.e. 10 MHz) and 4E10 [Hz] (i.e. 40 GHz). |
| 775 |
""", |
| 776 |
values=AnritsuMS464xB.FREQUENCY_RANGE, |
| 777 |
validator=strict_range, |
| 778 |
dynamic=True, |
| 779 |
) |
| 780 |
|
| 781 |
def clear_average_count(self): |
| 782 |
""" Clear and restart the averaging sweep count of the indicated channel. """ |
| 783 |
self.write(":SENS{ch}:AVER:CLE") |
| 784 |
|
| 785 |
average_count = Channel.control( |
| 786 |
":SENS{ch}:AVER:COUN?", ":SENS{ch}:AVER:COUN %d", |
| 787 |
"""Control the averaging count for the indicated channel. |
| 788 |
|
| 789 |
The channel must be turned on. Valid values are between 1 and 1024. |
| 790 |
""", |
| 791 |
values=[1, 1024], |
| 792 |
validator=strict_range, |
| 793 |
cast=int, |
| 794 |
) |
| 795 |
|
| 796 |
average_sweep_count = Channel.measurement( |
| 797 |
":SENS{ch}:AVER:SWE?", |
| 798 |
"""Get the averaging sweep count for the indicated channel. """, |
| 799 |
cast=int, |
| 800 |
) |
| 801 |
|
| 802 |
average_type = Channel.control( |
| 803 |
":SENS{ch}:AVER:TYP?", ":SENS{ch}:AVER:TYP %s", |
| 804 |
"""Control the averaging type to for the indicated channel. |
| 805 |
|
| 806 |
Valid values are POIN (point-by-point) or SWE (sweep-by-sweep) |
| 807 |
""", |
| 808 |
values=["POIN", "SWE"], |
| 809 |
validator=strict_discrete_set, |
| 810 |
) |
| 811 |
|
| 812 |
averaging_enabled = Channel.control( |
| 813 |
":SENS{ch}:AVER?", ":SENS{ch}:AVER %d", |
| 814 |
"""Control whether the averaging is turned on for the indicated channel. """, |
| 815 |
values={True: 1, False: 0}, |
| 816 |
map_values=True, |
| 817 |
) |
| 818 |
|
| 819 |
sweep_type = Channel.control( |
| 820 |
":SENS{ch}:SWE:TYP?", ":SENS{ch}:SWE:TYP %s", |
| 821 |
"""Control the sweep type of the indicated channel. |
| 822 |
|
| 823 |
Valid options are: |
| 824 |
|
| 825 |
===== =============================================================== |
| 826 |
value description |
| 827 |
===== =============================================================== |
| 828 |
LIN Frequency-based linear sweep |
| 829 |
LOG Frequency-based logarithmic sweep |
| 830 |
FSEGM Segment-based sweep with frequency-based segments |
| 831 |
ISEGM Index-based sweep with frequency-based segments |
| 832 |
POW Power-based sweep with either a CW frequency or swept-frequency |
| 833 |
MFGC Multiple frequency gain compression |
| 834 |
===== =============================================================== |
| 835 |
""", |
| 836 |
validator=strict_discrete_set, |
| 837 |
values=["LIN", "LOG", "FSEGM", "ISEGM", "POW", "MFGC"], |
| 838 |
) |
| 839 |
|
| 840 |
sweep_mode = Channel.control( |
| 841 |
":SENS{ch}:SA:MODE?", ":SENS{ch}:SA:MODE %s", |
| 842 |
"""Control the sweep mode for Spectrum Analysis on the indicated channel. |
| 843 |
|
| 844 |
Valid options are VNA (for a VNA-like mode where the instrument will only measure at points |
| 845 |
in the frequency list) or CLAS (for a classical mode, where the instrument will scan all |
| 846 |
frequencies in the range).""", |
| 847 |
validator=strict_discrete_set, |
| 848 |
values=["VNA", "CLAS"], |
| 849 |
) |
| 850 |
|
| 851 |
sweep_time = Channel.control( |
| 852 |
":SENS{ch}:SWE:TIM?", ":SENS{ch}:SWE:TIM %d", |
| 853 |
"""Control the sweep time of the indicated channel. |
| 854 |
|
| 855 |
Valid values are between 2 and 100000.""", |
| 856 |
validator=strict_range, |
| 857 |
values=[2, 100000], |
| 858 |
) |
| 859 |
|
| 860 |
bandwidth = Channel.control( |
| 861 |
":SENS{ch}:BWID?", ":SENS{ch}:BWID %g", |
| 862 |
"""Control the IF bandwidth for the indicated channel. |
| 863 |
|
| 864 |
Valid values are between 1 [Hz] and 1E6 [Hz] (i.e. 1 MHz). The system will automatically |
| 865 |
select the closest IF bandwidth from the available options (1, 3, 10 ... 1E5, 3E5, 1E6). |
| 866 |
""", |
| 867 |
values=[1, 1E6], |
| 868 |
validator=strict_range, |
| 869 |
) |
| 870 |
|
| 871 |
calibration_enabled = Channel.control( |
| 872 |
":SENS{ch}:CORR:STAT?", ":SENS{ch}:CORR:STAT %d", |
| 873 |
"""Control whether the RF correction (calibration) is enabled for indicated channel. """, |
| 874 |
values={True: 1, False: 0}, |
| 875 |
map_values=True, |
| 876 |
) |
| 877 |
|
| 878 |
|
| 879 |
class AnritsuMS4642B(AnritsuMS464xB): |
| 880 |
"""A class representing the Anritsu MS4642B Vector Network Analyzer (VNA). |
| 881 |
|
| 882 |
This VNA has a frequency range from 10 MHz to 20 GHz and is part of the |
| 883 |
:class:`~.AnritsuMS464xB` family of instruments; for documentation, for documentation refer to |
| 884 |
this base class. |
| 885 |
""" |
| 886 |
FREQUENCY_RANGE = [1E7, 2E10] |
| 887 |
|
| 888 |
|
| 889 |
class AnritsuMS4644B(AnritsuMS464xB): |
| 890 |
"""A class representing the Anritsu MS4644B Vector Network Analyzer (VNA). |
| 891 |
|
| 892 |
This VNA has a frequency range from 10 MHz to 40 GHz and is part of the |
| 893 |
:class:`~.AnritsuMS464xB` family of instruments; for documentation, for documentation refer to |
| 894 |
this base class. |
| 895 |
""" |
| 896 |
FREQUENCY_RANGE = [1E7, 4E10] |
| 897 |
|
| 898 |
|
| 899 |
class AnritsuMS4645B(AnritsuMS464xB): |
| 900 |
"""A class representing the Anritsu MS4645B Vector Network Analyzer (VNA). |
| 901 |
|
| 902 |
This VNA has a frequency range from 10 MHz to 50 GHz and is part of the |
| 903 |
:class:`~.AnritsuMS464xB` family of instruments; for documentation, for documentation refer to |
| 904 |
this base class. |
| 905 |
""" |
| 906 |
FREQUENCY_RANGE = [1E7, 5E10] |
| 907 |
|
| 908 |
|
| 909 |
class AnritsuMS4647B(AnritsuMS464xB): |
| 910 |
"""A class representing the Anritsu MS4647B Vector Network Analyzer (VNA). |
| 911 |
|
| 912 |
This VNA has a frequency range from 10 MHz to 70 GHz and is part of the |
| 913 |
:class:`~.AnritsuMS464xB` family of instruments; for documentation, for documentation refer to |
| 914 |
this base class. |
| 915 |
""" |
| 916 |
FREQUENCY_RANGE = [1E7, 7E10] |