src.pynanovna.pynanovna.VNA

class VNA(vna_index=0, logging_level='info')[source]

Bases: object

Initialize a VNA object for the NanoVNA.

Args:

vna_index (int): If multiple NanoVNAs are connected you can specify which to use. logging_level (str): The level of outputs. ‘critical’, ‘info’ or ‘debug’. Defaults to ‘info’.

Methods

calibrate

Calculates a calibration from the steps.

calibration_step

Runs a sweep and uses the data for calibration.

info

Get info about your NanoVNA and the connection to it.

is_connected

Check if the NanoVNA is connected.

kill

Disconnect the NanoVNA.

load_calibration

Load a previous calibration from a file.

save_calibration

Save the current calibration.

set_offset_delay

Manually set offset delay.

set_sweep

Set the sweep parameters.

set_vna_wait

There is a small sleep time in the communication with the NanoVNA, which is needed.

stream

Creates a data stream from the continuous sweeping.

stream_to_csv

Function to save the stream to a csv file.

sweep

Run a single sweep and return the data.

calibrate()[source]

Calculates a calibration from the steps.

Raises:

Exception: If the calibration is not successfully calculated.

calibration_step(step)[source]

Runs a sweep and uses the data for calibration.

Args:

step (str): The calibration step.

info()[source]

Get info about your NanoVNA and the connection to it.

Return type:

dict

Returns:

dict: A dictionary with the info.

is_connected()[source]

Check if the NanoVNA is connected.

Return type:

bool

Returns:

bool: If it is connected or not.

kill()[source]

Disconnect the NanoVNA.

Raises:

Exception: If the NanoVNA was not successfully disconnected.

load_calibration(filename)[source]

Load a previous calibration from a file.

Args:

filename (str): The file containing the previous calibration.

save_calibration(filename)[source]

Save the current calibration.

Args:

filename (str): The filename for the calibration.

set_offset_delay(delay)[source]

Manually set offset delay. This is used in calibration.

Args:

delay (float): The delay.

set_sweep(start, stop, points)[source]

Set the sweep parameters.

Args:

start (int): The start frequnecy. stop (int): The stop frequency. points (int): Number of points in the sweep.

set_vna_wait(wait)[source]
There is a small sleep time in the communication with the NanoVNA, which is needed.

You can change the sleep time in order to speed up the communication. Beware of unexpected errors if setting this to lower than 0.05.

Args:

wait (float): Time in seconds

stream(overwrite_wait=0.05)[source]

Creates a data stream from the continuous sweeping.

Return type:

tuple[list[complex], list[complex], list[int]]

Args:
overwrite_wait: Do not change if you don’t know what youre doing.

This can be used to lower the wait in the hardware functions.

Yields:

tuple: Yields a list of data when new data is available. Each datapoint: (s11, s21, frequencies)

stream_to_csv(filename, nr_sweeps=inf, skip_start=5, sweepdivider='sweepnumber: ')[source]

Function to save the stream to a csv file.

Args:

filename (str): The filename to save to. nr_sweeps (int): Number of sweeps to run. Defaults to 10. skip_start (int): The NanoVNA usually gives bad data in the beginning, therefore this data can be skipped. Defaults to 5. sweepdivider (str): A string to write between every sweep data to divide.

Raises:

TypeError: If the filename is not a string.

sweep(overwrite_wait=0.05)[source]

Run a single sweep and return the data.

Return type:

tuple[list[complex], list[complex], list[int]]

Args:
overwrite_wait: Do not change if you don’t know what youre doing.

This can be used to lower the wait in the hardware functions.

Returns:

tuple: s11, s21, frequencies