- Error handling for serial port problems

pull/27/head
Rune Broberg 2019-10-01 13:23:38 +02:00
rodzic b9f9cd07ad
commit 1397aef995
4 zmienionych plików z 30 dodań i 19 usunięć

Wyświetl plik

@ -802,33 +802,33 @@ class Calibration:
lines = file.readlines()
parsed_header = False
for l in lines:
l = l.strip()
if l.startswith("!"):
note = l[2:]
for line in lines:
line = line.strip()
if line.startswith("!"):
note = line[2:]
self.notes.append(note)
continue
if l.startswith("#") and not parsed_header:
if line.startswith("#") and not parsed_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
continue
else:
# This is some other comment line
continue
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
try:
if l.count(" ") == 6:
freq, shortr, shorti, openr, openi, loadr, loadi = l.split(" ")
if line.count(" ") == 6:
freq, shortr, shorti, openr, openi, loadr, loadi = line.split(" ")
self.s11short.append(Datapoint(int(freq), float(shortr), float(shorti)))
self.s11open.append(Datapoint(int(freq), float(openr), float(openi)))
self.s11load.append(Datapoint(int(freq), float(loadr), float(loadi)))
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.s11open.append(Datapoint(int(freq), float(openr), float(openi)))
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)))
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()
except Exception as e:
logger.exception("Failed loading calibration data: %s", e)

Wyświetl plik

@ -1132,7 +1132,6 @@ class QualityFactorChart(FrequencyChart):
qp.drawText(3, 35, str(self.maxQ))
def drawValues(self, qp: QtGui.QPainter):
from NanoVNASaver.NanoVNASaver import NanoVNASaver
if len(self.data) == 0 and len(self.reference) == 0:
return
if self.span == 0:

Wyświetl plik

@ -595,13 +595,17 @@ class NanoVNASaver(QtWidgets.QWidget):
logger.info(self.readFirmware())
frequencies = self.readValues("frequencies")
logger.info("Read starting frequency %s and end frequency %s", frequencies[0], frequencies[100])
if int(frequencies[0]) == int(frequencies[100]) and (self.sweepStartInput.text() == "" or self.sweepEndInput.text() == ""):
self.sweepStartInput.setText(frequencies[0])
self.sweepEndInput.setText(str(int(frequencies[100]) + 100000))
elif self.sweepStartInput.text() == "" or self.sweepEndInput.text() == "":
self.sweepStartInput.setText(frequencies[0])
self.sweepEndInput.setText(frequencies[100])
if frequencies:
logger.info("Read starting frequency %s and end frequency %s", frequencies[0], frequencies[100])
if int(frequencies[0]) == int(frequencies[100]) and (self.sweepStartInput.text() == "" or self.sweepEndInput.text() == ""):
self.sweepStartInput.setText(frequencies[0])
self.sweepEndInput.setText(str(int(frequencies[100]) + 100000))
elif self.sweepStartInput.text() == "" or self.sweepEndInput.text() == "":
self.sweepStartInput.setText(frequencies[0])
self.sweepEndInput.setText(frequencies[100])
else:
logger.warning("No frequencies read")
return
logger.debug("Starting initial sweep")
self.sweep()
@ -696,6 +700,8 @@ class NanoVNASaver(QtWidgets.QWidget):
values = result.split("\r\n")
except serial.SerialException as exc:
logger.exception("Exception while reading %s: %s", value, exc)
self.serialLock.release()
return
self.serialLock.release()
return values[1:102]

Wyświetl plik

@ -295,6 +295,9 @@ class SweepWorker(QtCore.QRunnable):
done = True
returndata = []
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))
for d in tmpdata:
a, b = d.split(" ")
@ -334,6 +337,9 @@ class SweepWorker(QtCore.QRunnable):
done = True
returnfreq = []
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:
if not f.isdigit():
logger.warning("Got a non-digit frequency: %s", f)