kopia lustrzana https://github.com/NanoVNA-Saver/nanovna-saver
- Error handling for serial port problems
rodzic
b9f9cd07ad
commit
1397aef995
|
@ -802,33 +802,33 @@ class Calibration:
|
||||||
lines = file.readlines()
|
lines = file.readlines()
|
||||||
parsed_header = False
|
parsed_header = False
|
||||||
|
|
||||||
for l in lines:
|
for line in lines:
|
||||||
l = l.strip()
|
line = line.strip()
|
||||||
if l.startswith("!"):
|
if line.startswith("!"):
|
||||||
note = l[2:]
|
note = line[2:]
|
||||||
self.notes.append(note)
|
self.notes.append(note)
|
||||||
continue
|
continue
|
||||||
if l.startswith("#") and not parsed_header:
|
if line.startswith("#") and not parsed_header:
|
||||||
# Check that this is a valid header
|
# Check that this is a valid header
|
||||||
if l == "# Hz ShortR ShortI OpenR OpenI LoadR LoadI ThroughR ThroughI IsolationR IsolationI":
|
if line == "# Hz ShortR ShortI OpenR OpenI LoadR LoadI ThroughR ThroughI IsolationR IsolationI":
|
||||||
parsed_header = True
|
parsed_header = True
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
# This is some other comment line
|
# This is some other comment line
|
||||||
continue
|
continue
|
||||||
if not parsed_header:
|
if not parsed_header:
|
||||||
logger.warning("Warning: Read line without having read header: %s", l)
|
logger.warning("Warning: Read line without having read header: %s", line)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if l.count(" ") == 6:
|
if line.count(" ") == 6:
|
||||||
freq, shortr, shorti, openr, openi, loadr, loadi = l.split(" ")
|
freq, shortr, shorti, openr, openi, loadr, loadi = line.split(" ")
|
||||||
self.s11short.append(Datapoint(int(freq), float(shortr), float(shorti)))
|
self.s11short.append(Datapoint(int(freq), float(shortr), float(shorti)))
|
||||||
self.s11open.append(Datapoint(int(freq), float(openr), float(openi)))
|
self.s11open.append(Datapoint(int(freq), float(openr), float(openi)))
|
||||||
self.s11load.append(Datapoint(int(freq), float(loadr), float(loadi)))
|
self.s11load.append(Datapoint(int(freq), float(loadr), float(loadi)))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
freq, shortr, shorti, openr, openi, loadr, loadi, throughr, throughi, isolationr, isolationi = l.split(" ")
|
freq, shortr, shorti, openr, openi, loadr, loadi, throughr, throughi, isolationr, isolationi = line.split(" ")
|
||||||
self.s11short.append(Datapoint(int(freq), float(shortr), float(shorti)))
|
self.s11short.append(Datapoint(int(freq), float(shortr), float(shorti)))
|
||||||
self.s11open.append(Datapoint(int(freq), float(openr), float(openi)))
|
self.s11open.append(Datapoint(int(freq), float(openr), float(openi)))
|
||||||
self.s11load.append(Datapoint(int(freq), float(loadr), float(loadi)))
|
self.s11load.append(Datapoint(int(freq), float(loadr), float(loadi)))
|
||||||
|
@ -836,7 +836,7 @@ class Calibration:
|
||||||
self.s21isolation.append(Datapoint(int(freq), float(isolationr), float(isolationi)))
|
self.s21isolation.append(Datapoint(int(freq), float(isolationr), float(isolationi)))
|
||||||
|
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
logger.exception("Error parsing calibration data \"%s\": %s", l, e)
|
logger.exception("Error parsing calibration data \"%s\": %s", line, e)
|
||||||
file.close()
|
file.close()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception("Failed loading calibration data: %s", e)
|
logger.exception("Failed loading calibration data: %s", e)
|
||||||
|
|
|
@ -1132,7 +1132,6 @@ class QualityFactorChart(FrequencyChart):
|
||||||
qp.drawText(3, 35, str(self.maxQ))
|
qp.drawText(3, 35, str(self.maxQ))
|
||||||
|
|
||||||
def drawValues(self, qp: QtGui.QPainter):
|
def drawValues(self, qp: QtGui.QPainter):
|
||||||
from NanoVNASaver.NanoVNASaver import NanoVNASaver
|
|
||||||
if len(self.data) == 0 and len(self.reference) == 0:
|
if len(self.data) == 0 and len(self.reference) == 0:
|
||||||
return
|
return
|
||||||
if self.span == 0:
|
if self.span == 0:
|
||||||
|
|
|
@ -595,13 +595,17 @@ class NanoVNASaver(QtWidgets.QWidget):
|
||||||
logger.info(self.readFirmware())
|
logger.info(self.readFirmware())
|
||||||
|
|
||||||
frequencies = self.readValues("frequencies")
|
frequencies = self.readValues("frequencies")
|
||||||
logger.info("Read starting frequency %s and end frequency %s", frequencies[0], frequencies[100])
|
if frequencies:
|
||||||
if int(frequencies[0]) == int(frequencies[100]) and (self.sweepStartInput.text() == "" or self.sweepEndInput.text() == ""):
|
logger.info("Read starting frequency %s and end frequency %s", frequencies[0], frequencies[100])
|
||||||
self.sweepStartInput.setText(frequencies[0])
|
if int(frequencies[0]) == int(frequencies[100]) and (self.sweepStartInput.text() == "" or self.sweepEndInput.text() == ""):
|
||||||
self.sweepEndInput.setText(str(int(frequencies[100]) + 100000))
|
self.sweepStartInput.setText(frequencies[0])
|
||||||
elif self.sweepStartInput.text() == "" or self.sweepEndInput.text() == "":
|
self.sweepEndInput.setText(str(int(frequencies[100]) + 100000))
|
||||||
self.sweepStartInput.setText(frequencies[0])
|
elif self.sweepStartInput.text() == "" or self.sweepEndInput.text() == "":
|
||||||
self.sweepEndInput.setText(frequencies[100])
|
self.sweepStartInput.setText(frequencies[0])
|
||||||
|
self.sweepEndInput.setText(frequencies[100])
|
||||||
|
else:
|
||||||
|
logger.warning("No frequencies read")
|
||||||
|
return
|
||||||
|
|
||||||
logger.debug("Starting initial sweep")
|
logger.debug("Starting initial sweep")
|
||||||
self.sweep()
|
self.sweep()
|
||||||
|
@ -696,6 +700,8 @@ class NanoVNASaver(QtWidgets.QWidget):
|
||||||
values = result.split("\r\n")
|
values = result.split("\r\n")
|
||||||
except serial.SerialException as exc:
|
except serial.SerialException as exc:
|
||||||
logger.exception("Exception while reading %s: %s", value, exc)
|
logger.exception("Exception while reading %s: %s", value, exc)
|
||||||
|
self.serialLock.release()
|
||||||
|
return
|
||||||
|
|
||||||
self.serialLock.release()
|
self.serialLock.release()
|
||||||
return values[1:102]
|
return values[1:102]
|
||||||
|
|
|
@ -295,6 +295,9 @@ class SweepWorker(QtCore.QRunnable):
|
||||||
done = True
|
done = True
|
||||||
returndata = []
|
returndata = []
|
||||||
tmpdata = self.app.readValues(data)
|
tmpdata = self.app.readValues(data)
|
||||||
|
if not tmpdata:
|
||||||
|
logger.warning("Read no values")
|
||||||
|
raise NanoVNAValueException("Failed reading data: Returned no values.")
|
||||||
logger.debug("Read %d values", len(tmpdata))
|
logger.debug("Read %d values", len(tmpdata))
|
||||||
for d in tmpdata:
|
for d in tmpdata:
|
||||||
a, b = d.split(" ")
|
a, b = d.split(" ")
|
||||||
|
@ -334,6 +337,9 @@ class SweepWorker(QtCore.QRunnable):
|
||||||
done = True
|
done = True
|
||||||
returnfreq = []
|
returnfreq = []
|
||||||
tmpfreq = self.app.readValues("frequencies")
|
tmpfreq = self.app.readValues("frequencies")
|
||||||
|
if not tmpfreq:
|
||||||
|
logger.warning("Read no frequencies")
|
||||||
|
raise NanoVNAValueException("Failed reading frequencies: Returned no values.")
|
||||||
for f in tmpfreq:
|
for f in tmpfreq:
|
||||||
if not f.isdigit():
|
if not f.isdigit():
|
||||||
logger.warning("Got a non-digit frequency: %s", f)
|
logger.warning("Got a non-digit frequency: %s", f)
|
||||||
|
|
Ładowanie…
Reference in New Issue