Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: nanovnasaver v0.6.8 does not work in NetBSD and FreeBSD #753

Open
ea4nz opened this issue Jan 12, 2025 · 0 comments
Open

feat: nanovnasaver v0.6.8 does not work in NetBSD and FreeBSD #753

ea4nz opened this issue Jan 12, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@ea4nz
Copy link

ea4nz commented Jan 12, 2025

Feature Request

Hello I am trying to make nanovnasaver v0.6.8 work under NetBSD and FreeBSD operating systems. In both operating systems serial port detection that relies on py-serial python modules does not work. py-serial does not work the same way as in Linux.

Under Linux, device is /dev/ttyAMC0, in NetBSD device is /dev/ttyU0 and /dev/dtyU0, FreeBSD is /dev/cuaU0. I have given permission to the device and can perfectly be accesed with the cu program as a normal user: I can send and receive commands from the device.

netbsd-x260$ cu -l /dev/ttyU0
Connected

ChibiOS/RT Shell
ch> help
Commands: help exit info threads version reset freq offset time dac saveconfig clearconfig data dump frequencies port stat gain power sample scan sweep test touchcal touchtest pause resume cal save recall trace marker edelay capture vbat transform threshold
ch> info
Kernel:       4.0.0
Compiler:     GCC 8.2.1 20181213 (release) [gcc-8-branch revision 267074]
Architecture: ARMv6-M
Core Variant: Cortex-M0
Port Info:    Preemption through NMI
Platform:     STM32F072xB Entry Level Medium Density devices
Board:        NanoVNA-H
Build time:   Oct 18 2019 - 16:10:54
ch> ~
[EOT]
netbsd-x260$

Nanovnaserver uses py-serial python module to communicate with Nanovna but in NetBSD nanovnasaver program is confused with py-serial detection functions output, they do not work the same as in Linux.

LINUX detects theese ports:

ramiro@debian-x260:~$ pyserial-ports -v
/dev/ttyACM0
    desc: ChibiOS/RT Virtual COM Port
    hwid: USB VID:PID=0483:5740 SER=400 LOCATION=1-1:1.0
/dev/ttyS0
    desc: n/a
    hwid: n/a
2 ports found
ramiro@debian-x260:~$

On the other hand, in NetBSD and FreeBSD py-serial detect 121 of devices but no useful information on /dev/ttyU0 and /dev/dtyU0

NETBSD:

netbsd-x260$ pyserial-ports-3.12
/dev/dty00
/dev/dty01
/dev/dty02
/dev/dty03
/dev/dtyCY000
...
...
/dev/dtyCZ0000
...
...
/dev/dtyCZ0063
/dev/dtyHS0.00
...
...
/dev/dtyHS0.10
/dev/dtyU0
/dev/dtyU1
/dev/dtyU2
/dev/dtyU3
/dev/dtyU4
/dev/dtyU5
/dev/dtyU6
/dev/dtyU7
/dev/dtyY0
/dev/dtyY1
121 ports found
netbsd-x260$

If more detail is requested it does not output more details:

netbsd-x260# pyserial-ports-3.12 -v
/dev/dty00
    desc: n/a
    hwid: n/a
..
..

/dev/dtyU0
    desc: n/a
    hwid: n/a
/dev/dtyU1
    desc: n/a
    hwid: n/a
/dev/dtyU2
    desc: n/a
    hwid: n/a
/dev/dtyU3
    desc: n/a
    hwid: n/a
/dev/dtyU4
    desc: n/a
    hwid: n/a
/dev/dtyU5
    desc: n/a
    hwid: n/a
/dev/dtyU6
    desc: n/a
    hwid: n/a
/dev/dtyU7
    desc: n/a
    hwid: n/a
/dev/dtyY0
    desc: n/a
    hwid: n/a
/dev/dtyY1
    desc: n/a
    hwid: n/a
121 ports found
netbsd-x260#

If I run this simple python program that scan the ports using py-serial python module:

netbsd-x260$ cat test.py

import serial
from serial.tools import list_ports
from serial.tools.list_ports_common import ListPortInfo

for d in list_ports.comports(include_links=True):
 print('device',d.device)
 print('name',d.name)
 print('description',d.description)
 print('hwid',d.hwid)
 print('vid',d.vid)
 print('pid',d.pid)
 print('serial_number',d.serial_number)
 print('location',d.location)
 print('manufacturer',d.manufacturer)
 print('product',d.product)
 print('interface',d.interface)

LINUX output:

device /dev/ttyACM0
name ttyACM0
description ChibiOS/RT Virtual COM Port
hwid USB VID:PID=0483:5740 SER=400 LOCATION=1-1.2:1.0
vid 1155
pid 22336
serial_number 400
location 1-1.2:1.0
manufacturer STMicroelectronics
product ChibiOS/RT Virtual COM Port
interface None

NETBSD outputs 121 devices but I only print below the device of interest. There is no information about the description, hwid, vendor, product and serial number:

device /dev/dtyU0
name dtyU0
description n/a
hwid n/a
vid None
pid None
serial_number None
location None
manufacturer None
prpy313-libusb1oduct None
interface None

I have been told that py-serial in the BSD operating system does not provide USB information like vid,pid etc, so It is not a good way automatically configuring the serial port. For those operating systems it would be a good thing beeing able to configure it manually instead.

I can fool nanovnasaver by entering serial port configuration data literaly in the code this way in Hardware.py file: in this two functions:

def get_interfaces() -> list[Interface]:
    interfaces = []
    # serial like usb interfaces
    for d in list_ports.comports():
        if platform.system() == "Windows" and d.vid is None:
            d = _fix_v2_hwinfo(d)  # noqa: PLW2901

#remigio
        d.device="/dev/dtyU0"
        d.name="dtyU0"
        d.vid=0x0483
        d.pid=0x5740
#remigio

        if not (typename := usb_typename(d)):
            continue
      
        logger.debug(
            "Found %s USB:(%04x:%04x) on port %s",
            typename,
            d.vid,
            d.pid,
            d.device,
        )
        iface = Interface("serial", typename)
        iface.port = d.device
        iface.open()
        iface.comment = get_comment(iface)
        iface.close()
        interfaces.append(iface)

#remigio
        break
#remigio
def get_portinfos() -> list[str]:
    portinfos = []
    # serial like usb interfaces
    for d in list_ports.comports():
#remigio
        d.device="/dev/dtyU0"
        d.name="dtyU0"
        d.vid=0x0483
        d.pid=0x5740
#remigio
        logger.debug("Found USB:(%04x:%04x) on port %s", d.vid, d.pid, d.device)
        iface = Interface("serial", "DEBUG")
        iface.port = d.device
        iface.open()
        version = detect_version(iface)
        iface.close()
        portinfos.append(version)

#remigio
        break
#remigio
    return portinfos

This way the device "/dev/dtyU0 H" or "/dev/cuaU0 H" are shown in the serial control box in NetBSD and FreeBSD. When pressing to "Connect to the device":

  • In FreeBSD the device sometimes work and sometimes do not work. When it works, device is detected and I am able to do frequency sweeps. When it does not work the error shown is the same as in NetBSD operating system.

  • In NetBSD it never works giving this error in the Debug file:

2025-01-12 08:15:08,765 - NanoVNASaver.NanoVNASaver - DEBUG - New font width: 189.015625, normal font: 189.015625, factor: 1.000000
2025-01-12 08:15:08,832 - NanoVNASaver.NanoVNASaver - DEBUG - Finished building interface
2025-01-12 08:15:10,629 - NanoVNASaver.Controls.SerialControl - INFO - Connection /dev/dtyU0 (H)
2025-01-12 08:15:10,737 - NanoVNASaver.Hardware.VNA - DEBUG - exec_command(version)
2025-01-12 08:15:10,857 - NanoVNASaver.Hardware.VNA - DEBUG - Max retries: 41
2025-01-12 08:15:10,917 - NanoVNASaver.Hardware.VNA - DEBUG - Needed retries: 0
2025-01-12 08:15:10,917 - NanoVNASaver.Hardware.VNA - DEBUG - result:
['v0.2.3-2-g8ac9166']
2025-01-12 08:15:10,917 - NanoVNASaver.Hardware.VNA - DEBUG - exec_command(help)
2025-01-12 08:15:11,037 - NanoVNASaver.Hardware.VNA - DEBUG - Max retries: 41
2025-01-12 08:15:11,097 - NanoVNASaver.Hardware.VNA - DEBUG - Needed retries: 0
2025-01-12 08:15:11,097 - NanoVNASaver.Hardware.VNA - DEBUG - result:
['Commands:', 'help', 'exit', 'info', 'threads', 'version', 'reset', 'freq', 'offset', 'time', 'dac', 'saveconfig', 'clearconfig', 'data', 'dump', 'frequencies', 'port', 'stat', 'gain', 'power', 'sample', 'scan', 'sweep', 'test', 'touchcal', 'touchtest', 'pause', 'resume', 'cal', 'save', 'recall', 'trace', 'marker', 'edelay', 'capture', 'vbat', 'transform', 'threshold']
2025-01-12 08:15:11,097 - NanoVNASaver.Hardware.NanoVNA - DEBUG - Using new scan command.
2025-01-12 08:15:11,097 - NanoVNASaver.Hardware.VNA - DEBUG - Features: {'Screenshots', 'Scan command', 'Customizable data points'}
2025-01-12 08:15:11,097 - NanoVNASaver.Hardware.VNA - DEBUG - exec_command(help)
2025-01-12 08:15:11,217 - NanoVNASaver.Hardware.VNA - DEBUG - Max retries: 41
2025-01-12 08:15:11,277 - NanoVNASaver.Hardware.VNA - DEBUG - Needed retries: 0
2025-01-12 08:15:11,277 - NanoVNASaver.Hardware.VNA - DEBUG - result:
['Commands:', 'help', 'exit', 'info', 'threads', 'version', 'reset', 'freq', 'offset', 'time', 'dac', 'saveconfig', 'clearconfig', 'data', 'dump', 'frequencies', 'port', 'stat', 'gain', 'power', 'sample', 'scan', 'sweep', 'test', 'touchcal', 'touchtest', 'pause', 'resume', 'cal', 'save', 'recall', 'trace', 'marker', 'edelay', 'capture', 'vbat', 'transform', 'threshold']
2025-01-12 08:15:11,277 - NanoVNASaver.Hardware.NanoVNA - DEBUG - Using new scan command.
2025-01-12 08:15:11,277 - NanoVNASaver.Hardware.NanoVNA - DEBUG - Setting initial start,stop
2025-01-12 08:15:11,277 - NanoVNASaver.Hardware.NanoVNA - DEBUG - Reading values: frequencies
2025-01-12 08:15:11,277 - NanoVNASaver.Hardware.VNA - DEBUG - VNA reading frequencies
2025-01-12 08:15:11,277 - NanoVNASaver.Hardware.VNA - DEBUG - exec_command(frequencies)
2025-01-12 08:15:11,397 - NanoVNASaver.Hardware.VNA - DEBUG - Max retries: 41
2025-01-12 08:15:16,437 - NanoVNASaver.Hardware.NanoVNA - WARNING - too many retries reading frequencies
2025-01-12 08:15:16,438 - NanoVNASaver.Hardware.NanoVNA - INFO - falling back to generic
2025-01-12 08:15:16,440 - NanoVNASaver.Hardware.NanoVNA - DEBUG - readFrequencies: scan
2025-01-12 08:15:16,440 - NanoVNASaver.Hardware.VNA - DEBUG - VNA reading frequencies
2025-01-12 08:15:16,441 - NanoVNASaver.Hardware.VNA - DEBUG - exec_command(frequencies)
2025-01-12 08:15:16,557 - NanoVNASaver.Hardware.VNA - DEBUG - Max retries: 41

Both FreeBSD (when it fails ) and NetBSD fail on the same command when retrieving frequencies from the VNA:

netbsd-x260$ python3.11 nanovna-saver.py
NanoVNASaver 0.6.9.dev1+gb5da81b.d20250112

Copyright (C) 2019, 2020 Rune B. Broberg
Copyright (C) 2020ff NanoVNA-Saver Authors

This program comes with ABSOLUTELY NO WARRANTY
This program is licensed under the GNU General Public License version 3

See https://github.com/NanoVNA-Saver/nanovna-saver for further details.

2025-01-12 11:28:22,963 - NanoVNASaver.Hardware.NanoVNA - WARNING - too many retries reading frequencies
Traceback (most recent call last):
  File "/home/ramiro/nanovna-saver/src/NanoVNASaver/Controls/SerialControl.py", line 84, in serialButtonClick
    self.connect_device()
  File "/home/ramiro/nanovna-saver/src/NanoVNASaver/Controls/SerialControl.py", line 123, in connect_device
    frequencies = self.app.vna.read_frequencies()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ramiro/nanovna-saver/src/NanoVNASaver/Hardware/NanoVNA.py", line 128, in read_frequencies
    return super().read_frequencies()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ramiro/nanovna-saver/src/NanoVNASaver/Hardware/VNA.py", line 164, in read_frequencies
    return [int(f.real) for f in self.readValues("frequencies")]
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ramiro/nanovna-saver/src/NanoVNASaver/Hardware/NanoVNA.py", line 138, in readValues
    return super().readValues(value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ramiro/nanovna-saver/src/NanoVNASaver/Hardware/VNA.py", line 206, in readValues
    result = [
             ^
  File "/home/ramiro/nanovna-saver/src/NanoVNASaver/Hardware/VNA.py", line 206, in <listcomp>
    result = [
             ^
  File "/home/ramiro/nanovna-saver/src/NanoVNASaver/Hardware/VNA.py", line 115, in exec_command
    raise IOError("too many retries")
OSError: too many retries
[1]   Abort trap (core dumped) python3.11 nanovna-saver.py
netbsd-x260$ 

I do not know why it does fail sometimes in FreeBSD and it always fails in NetBSD. Any hints will be appreciated. I have been playing with software timeouts just in case but it did not work.

Thanks.

Ramiro.

Describe Preferred Solution

Apart from py-serial port autodetect, it would be a good thing to manually configure serial ports. Also fix the code to make it work under BSD.

@ea4nz ea4nz added the enhancement New feature or request label Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant