NanoVNA-Saver / nanovna-saver

A tool for reading, displaying and saving data from the NanoVNA
GNU General Public License v3.0
895 stars 273 forks source link

NanoVNA_V2.py ._read_version times out too early #585

Closed Endaris closed 1 year ago

Endaris commented 1 year ago

Bug Report

NanoVNA-Saver version: https://github.com/NanoVNA-Saver/nanovna-saver/commit/d654ea0441939e4e1c599d1333b587a185394fbe I followed the instructions here to run the project: https://github.com/NanoVNA-Saver/nanovna-saver/blob/main/docs/INSTALLATION.md Current behavior: After starting up, the application notices the device and shows it under Serial Port Control. After I click connect, the application closes with the following crash:

2023-01-18 15:26:39,084 - NanoVNASaver.Hardware.NanoVNA_V2 - ERROR - Timeout reading version registers. Got: b''
2023-01-18 15:26:39,085 - NanoVNASaver.Controls.SerialControl - ERROR - Unable to connect to VNA: Timeout reading version registers
Traceback (most recent call last):
  File "~/Code/OdA/nanovna-saver/NanoVNASaver/Controls/SerialControl.py", line 74, in serialButtonClick
    self.connect_device()
  File "~/Code/OdA/nanovna-saver/NanoVNASaver/Controls/SerialControl.py", line 105, in connect_device
    frequencies = self.app.vna.readFrequencies()
  File "~/Code/OdA/nanovna-saver/NanoVNASaver/Hardware/VNA.py", line 151, in readFrequencies
    return [int(f) for f in self.readValues("frequencies")]
  File "~/Code/OdA/nanovna-saver/NanoVNASaver/Hardware/VNA.py", line 193, in readValues
    result = list(self.exec_command(value))
  File "~/Code/OdA/nanovna-saver/NanoVNASaver/Hardware/VNA.py", line 96, in exec_command
    drain_serial(self.serial)
  File "~/Code/OdA/nanovna-saver/NanoVNASaver/Hardware/Serial.py", line 33, in drain_serial
    cnt = len(serial_port.read(128))
  File "~/.venv_nano/lib/python3.10/site-packages/serial/serialposix.py", line 560, in read
    raise PortNotOpenError()
serial.serialutil.PortNotOpenError: Attempting to use a port that is not open
Abgebrochen (Speicherabzug geschrieben)

Expected behavior:

NanoVNA_V2.py does not run into a timeout upon trying to read the version. I started debugging this and as I slowly stepped through, it worked. I have now added a sleep to _read_version so the timeout no longer occurs.

Steps to reproduce:

Might be difficult without my specific NanoVNA.

Related code:

I added a sleep(2) at the start of def _read_version(self, cmd_0: int, cmd_1: int): inside of NanoVNA_V2.py and the timeout no longer occurs. It sometimes works with just sleep(1) as well but not as reliably.

Other information:

I had NanoVNASaver originally installed for the first time in November with v0.5.3 I think. I vaguely remember having to install some packages extra before it ran but I didn't have the same issue back then.

After the NanoVNA changed to USB mode, I can restart the application without the sleep and disconnect and connect it as often as I want. I would assume that my device is just a bit slow with entering USB mode and transmitting the information NanoVNA-Saver needs on initial connection.

fred777 commented 1 year ago

I can confirm this bug and replacing sleep(WRITE_SLEEP) with sleep(2) fixes it for me too, having a genuine NanoVNA v2 Plus4 with firmware v1.0.2 20211227.

github-actions[bot] commented 1 year ago

There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale. Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by leaving a 👍 Because this issue is marked as stale, it will be closed and locked in 7 days if no further activity occurs. Thank you for your contributions!