Skip to content

Commit

Permalink
Choosable datapoints / scan on V2
Browse files Browse the repository at this point in the history
In DeviceManage window, with v2 the ammount of datapoints
per scan is choosable
  • Loading branch information
zarath committed Jun 17, 2020
1 parent e5490a5 commit 92ece2c
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 35 deletions.
2 changes: 1 addition & 1 deletion NanoVNASaver/Hardware/NanoVNA.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def getScreenshot(self) -> QtGui.QPixmap:
data = "a"
while data != "":
data = self.serial.readline().decode('ascii')
self.serial.write("capture\r".encode('ascii'))
timeout = self.serial.timeout
self.serial.write("capture\r".encode('ascii'))
self.serial.timeout = 4
self.serial.readline()
image_data = self.serial.read(
Expand Down
9 changes: 3 additions & 6 deletions NanoVNASaver/Hardware/NanoVNA_V2.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

class NanoVNAV2(VNA):
name = "NanoVNA-V2"
DEFAULT_DATAPOINTS = 300
_datapoints = (303, 101, 256, 512, 1023)
screenwidth = 320
screenheight = 240

Expand All @@ -72,8 +72,6 @@ def __init__(self, app, serialPort):
# TODO: more than one dp per freq
self.features.add("Multi data points")

self.datapoints = NanoVNAV2.DEFAULT_DATAPOINTS

# firmware major version of 0xff indicates dfu mode
if self.firmware.major == 0xff:
self._isDFU = True
Expand All @@ -82,7 +80,7 @@ def __init__(self, app, serialPort):
self._isDFU = False
self.sweepStartHz = 200e6
self.sweepStepHz = 1e6
self.sweepData = [(0, 0)] * self.datapoints
self.sweepData = [(0, 0)] * max(self._datapoints)
self._updateSweep()

def isValid(self):
Expand Down Expand Up @@ -117,8 +115,7 @@ def readFrequencies(self) -> List[str]:

def readValues(self, value) -> List[str]:
self.checkValid()
self.serial.timeout = round(self.datapoints / 40)

self.serial.timeout = 8 # should be enough

# Actually grab the data only when requesting channel 0.
# The hardware will return all channels which we will store.
Expand Down
8 changes: 5 additions & 3 deletions NanoVNASaver/Hardware/VNA.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@

class VNA:
name = "VNA"
_datapoints = (101, )

def __init__(self, app: QtWidgets.QWidget, serial_port: serial.Serial):
self.app = app
self.serial = serial_port
self.version: Version = Version("0.0.0")
self.features = set()
self.validateInput = True
self.datapoints = 101
self.datapoints = self._datapoints[0]

def readFeatures(self) -> List[str]:
raw_help = self.readFromCommand("help")
Expand All @@ -44,6 +45,8 @@ def readFeatures(self) -> List[str]:
# Detect features from the help command
if "capture" in raw_help:
self.features.add("Screenshots")
if len(self._datapoints) > 1:
self.features.add("Customizable data points")

return self.features

Expand Down Expand Up @@ -183,10 +186,9 @@ def setSweep(self, start, stop):
# unconnected devices
class InvalidVNA(VNA):
name = "Invalid"

_datapoints = (0, )
def __init__(self, app: QtWidgets.QWidget, serial_port: serial.Serial):
super().__init__(app, serial_port)
self.datapoints = 0

def setSweep(self, start, stop):
return
Expand Down
2 changes: 1 addition & 1 deletion NanoVNASaver/NanoVNASaver.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ def updateStepSize(self):
if self.sweepCountInput.text().isdigit():
segments = int(self.sweepCountInput.text())
if segments > 0:
fstep = fspan / (segments * 101 - 1)
fstep = fspan / (segments * self.vna.datapoints - 1)
self.sweepStepLabel.setText(
f"{RFTools.formatShortFrequency(fstep)}/step")

Expand Down
18 changes: 10 additions & 8 deletions NanoVNASaver/SweepWorker.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ def run(self):
break
start = sweep_from + i * self.vna.datapoints * stepsize
freq, val11, val21 = self.readAveragedSegment(
start, start + (self.vna.datapoints-1) * stepsize, self.averages)
start, start + (self.vna.datapoints - 1) * stepsize, self.averages)

frequencies += freq
values += val11
values21 += val21

self.percentage = (i + 1) * (self.vna.datapoints-1) / self.noSweeps
self.percentage = (i + 1) * (self.vna.datapoints - 1) / self.noSweeps
logger.debug("Saving acquired data")
self.saveData(frequencies, values, values21)

Expand All @@ -129,16 +129,16 @@ def run(self):
if self.stopped:
logger.debug("Stopping sweeping as signalled")
break
start = sweep_from + i*self.vna.datapoints*stepsize
start = sweep_from + i * self.vna.datapoints * stepsize
try:
freq, val11, val21 = self.readSegment(
start, start+(self.vna.datapoints-1)*stepsize)
start, start + (self.vna.datapoints - 1) * stepsize)

frequencies += freq
values += val11
values21 += val21

self.percentage = (i+1)*100/self.noSweeps
self.percentage = (i + 1) * 100 / self.noSweeps
logger.debug("Saving acquired data")
self.saveData(frequencies, values, values21)
except NanoVNAValueException as e:
Expand Down Expand Up @@ -216,10 +216,12 @@ def saveData(self, frequencies, values11, values21):
raw_data11 = []
raw_data21 = []
logger.debug("Calculating data including corrections")
for i, val11 in enumerate(values11):
re, im = val11
for i, freq in enumerate(frequencies):
logger.debug("Freqnr %i, len(%i)", i, len(frequencies))
logger.debug("Val11 %s", values11[i])
logger.debug("Val21 %s", values21[i])
re, im = values11[i]
re21, im21 = values21[i]
freq = frequencies[i]
raw_data11 += [Datapoint(freq, re, im)]
raw_data21 += [Datapoint(freq, re21, im21)]
self.data11, self.data21 = self.applyCalibration(raw_data11, raw_data21)
Expand Down
51 changes: 37 additions & 14 deletions NanoVNASaver/Windows/DeviceSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ def __init__(self, app: QtWidgets.QWidget):

QtWidgets.QShortcut(QtCore.Qt.Key_Escape, self, self.hide)

layout = QtWidgets.QVBoxLayout()
self.setLayout(layout)
top_layout = QtWidgets.QHBoxLayout()
left_layout = QtWidgets.QVBoxLayout()
right_layout = QtWidgets.QVBoxLayout()
top_layout.addLayout(left_layout)
top_layout.addLayout(right_layout)
self.setLayout(top_layout)

status_box = QtWidgets.QGroupBox("Status")
status_layout = QtWidgets.QFormLayout(status_box)
Expand Down Expand Up @@ -66,9 +70,20 @@ def __init__(self, app: QtWidgets.QWidget):
self.btnCaptureScreenshot.clicked.connect(self.captureScreenshot)
control_layout.addWidget(self.btnCaptureScreenshot)

layout.addWidget(status_box)
layout.addWidget(settings_box)
layout.addLayout(control_layout)
left_layout.addWidget(status_box)
left_layout.addLayout(control_layout)

self.datapoints = QtWidgets.QComboBox()
self.datapoints.addItem(str(self.app.vna.datapoints))
self.datapoints.currentIndexChanged.connect(self.updateNrDatapoints)
form_layout = QtWidgets.QFormLayout()
form_layout.addRow(QtWidgets.QLabel("Datapoints"), self.datapoints)
right_layout.addWidget(settings_box)
settings_layout.addRow(form_layout)

def _set_datapoint_index(self, dpoints: int):
self.datapoints.setCurrentIndex(
self.datapoints.findText(str(dpoints)))

def show(self):
super().show()
Expand All @@ -88,10 +103,14 @@ def updateFields(self):
for item in features:
self.featureList.addItem(item)

if "Screenshots" in features:
self.btnCaptureScreenshot.setDisabled(False)
else:
self.btnCaptureScreenshot.setDisabled(True)
self.btnCaptureScreenshot.setDisabled(not "Screenshots" in features)
if "Customizable data points" in features:
self.datapoints.clear()
cur_dps = self.app.vna.datapoints
dplist = self.app.vna._datapoints[:]
for d in sorted(dplist):
self.datapoints.addItem(str(d))
self._set_datapoint_index(cur_dps)
else:
self.statusLabel.setText("Not connected.")
self.calibrationStatusLabel.setText("Not connected.")
Expand All @@ -108,8 +127,12 @@ def captureScreenshot(self):
pixmap = self.app.vna.getScreenshot()
self.screenshotWindow.setScreenshot(pixmap)
self.screenshotWindow.show()
else:
# TODO: Tell the user no screenshots while sweep is running?
# TODO: Consider having a list of widgets that want to be
# disabled when a sweep is running?
pass
# TODO: Tell the user no screenshots while sweep is running?
# TODO: Consider having a list of widgets that want to be
# disabled when a sweep is running?

def updateNrDatapoints(self, i):
if i < 0 or self.app.worker.running:
return
logger.debug("DP: %s", self.datapoints.itemText(i))
self.app.vna.datapoints = int(self.datapoints.itemText(i))
5 changes: 3 additions & 2 deletions NanoVNASaver/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

version = '0.2.3'
debug = False
version = '0.2.3-dg5gbh'
#debug = False
debug = True

0 comments on commit 92ece2c

Please sign in to comment.