diff --git a/NanoVNASaver/Hardware/NanoVNA.py b/NanoVNASaver/Hardware/NanoVNA.py index 5a6dbef..e6ac3c0 100644 --- a/NanoVNASaver/Hardware/NanoVNA.py +++ b/NanoVNASaver/Hardware/NanoVNA.py @@ -56,6 +56,9 @@ class NanoVNA(VNA): self.screenwidth * self.screenheight * 2) self.serial.timeout = timeout self.serial.timeout = timeout + return image_data + + def _convert_data(self, image_data: bytes) -> bytes: rgb_data = struct.unpack( f">{self.screenwidth * self.screenheight}H", image_data) @@ -70,7 +73,7 @@ class NanoVNA(VNA): if not self.connected(): return QtGui.QPixmap() try: - rgba_array = self._capture_data() + rgba_array = self._convert_data(self._capture_data()) image = QtGui.QImage( rgba_array, self.screenwidth, diff --git a/NanoVNASaver/Hardware/NanoVNA_F_V2.py b/NanoVNASaver/Hardware/NanoVNA_F_V2.py index a16267e..ae22804 100644 --- a/NanoVNASaver/Hardware/NanoVNA_F_V2.py +++ b/NanoVNASaver/Hardware/NanoVNA_F_V2.py @@ -15,20 +15,6 @@ class NanoVNA_F_V2(NanoVNA): screenwidth = 800 screenheight = 480 - def _capture_data(self) -> bytes: - timeout = self.serial.timeout - with self.serial.lock: - drain_serial(self.serial) - timeout = self.serial.timeout - self.serial.write("capture\r".encode('ascii')) - self.serial.readline() - self.serial.timeout = 4 - image_data = self.serial.read( - self.screenwidth * self.screenheight * 2) - self.serial.timeout = timeout - self.serial.timeout = timeout - return image_data - def getScreenshot(self) -> QtGui.QPixmap: logger.debug("Capturing screenshot...") if not self.connected(): @@ -37,10 +23,12 @@ class NanoVNA_F_V2(NanoVNA): rgba_array = self._capture_data() image = QtGui.QImage( rgba_array, - self.screenwidth, self.screenheight, + self.screenwidth, + self.screenheight, QtGui.QImage.Format_RGB16) logger.debug("Captured screenshot") return QtGui.QPixmap(image) except serial.SerialException as exc: - logger.exception("Exception while capturing screenshot: %s", exc) + logger.exception( + "Exception while capturing screenshot: %s", exc) return QtGui.QPixmap()