PICC-Group / pynanovna

A python library to easily read and save data from a NanoVNA.
https://pypi.org/project/pynanovna/
Other
8 stars 1 forks source link

single_sweep() returns same sweep everytime #3

Closed OdoctorG closed 6 months ago

OdoctorG commented 6 months ago

If you run singe_sweep() you get the same data everytime, example:

from pynanovna import NanoVNAWorker
from time import sleep

worker = NanoVNAWorker(verbose=False)
worker.set_sweep(2.95e9,3.05e9,1,11)
datafile = False #  Set this to a path if you want to play a previously recorded file.

while(True):
    data = worker.single_sweep()
    sleep(1.0)
    print(data[0])

There is however a fix, you simply copy the data object everytime, eg.

while(True):
    data = worker.single_sweep()
    data = (data[0].copy(), data[1].copy())
    sleep(1.0)
    print(data[0])
OdoctorG commented 6 months ago

This also seems to be true when using a stream and taking the next value of the generator provided by the stream:

worker = NanoVNAWorker(verbose=False)
worker.set_sweep(2.95e9,3.05e9,1,11)
datafile = False #  Set this to a path if you want to play a previously recorded file.

stream = worker.stream_data(datafile)

while(True):
    data = next(stream)
    print(data[0])

will print the same data everytime. Here the fix is the same, you have to copy data.

tbergkvist commented 6 months ago

As in the provided example, use for data in stream: print(data[0])

This works for streams.

Will look into single sweeps and while loop support in future, expect a patch in dist 0.0.7.

tbergkvist commented 6 months ago

This seems to have been fixed in some distribution of pynanovna. Issue should be resolved by upgrading pynanovna to the latest version. Please run pip install pynanovna --upgrade If that does not resolve it, please run pip install pynanovna --force-reinstall