Automatically detect screenshot capability

pull/117/head
Rune Broberg 2019-12-11 10:36:48 +01:00
rodzic 850c8d1291
commit f772068b38
2 zmienionych plików z 44 dodań i 1 usunięć

Wyświetl plik

@ -57,6 +57,18 @@ class VNA:
logger.warning("Did not recognize NanoVNA type from firmware.")
return NanoVNA(app, serial_port)
def readFeatures(self) -> List[str]:
features = []
raw_help = self.readFromCommand("help")
logger.debug("Help command output:")
logger.debug(raw_help)
# Detect features from the help command
if "capture" in raw_help:
features.append("Screenshots")
return features
def readFrequencies(self) -> List[str]:
pass
@ -113,6 +125,29 @@ class VNA:
logger.error("Unable to acquire serial lock to read firmware.")
return ""
def readFromCommand(self, command) -> str:
if self.app.serialLock.acquire():
result = ""
try:
data = "a"
while data != "":
data = self.serial.readline().decode('ascii')
self.serial.write((command + "\r").encode('ascii'))
result = ""
data = ""
sleep(0.01)
while data != "ch> ":
data = self.serial.readline().decode('ascii')
result += data
except serial.SerialException as exc:
logger.exception("Exception while reading " + command + ": %s", exc)
finally:
self.app.serialLock.release()
return result
else:
logger.error("Unable to acquire serial lock to read " + command + ".")
return ""
def readValues(self, value) -> List[str]:
logger.debug("VNA reading %s", value)
if self.app.serialLock.acquire():
@ -212,6 +247,7 @@ class NanoVNA(VNA):
logger.debug("Older than 0.2.0, using old sweep command.")
self.features.append("Original sweep method")
self.useScan = False
self.features.extend(self.readFeatures())
def isValid(self):
return True

Wyświetl plik

@ -2623,13 +2623,20 @@ class DeviceSettingsWindow(QtWidgets.QWidget):
self.featureList.clear()
self.featureList.addItem(self.app.vna.name + " v" + str(self.app.vna.version))
for item in self.app.vna.getFeatures():
features = self.app.vna.getFeatures()
for item in features:
self.featureList.addItem(item)
if "Screenshots" in features:
self.btnCaptureScreenshot.setDisabled(False)
else:
self.btnCaptureScreenshot.setDisabled(True)
else:
self.statusLabel.setText("Not connected.")
self.calibrationStatusLabel.setText("Not connected.")
self.featureList.clear()
self.featureList.addItem("Not connected.")
self.btnCaptureScreenshot.setDisabled(True)
def updateValidation(self, validate_data: bool):
self.app.vna.validateInput = validate_data