NanoVNA-Saver / nanovna-saver

A tool for reading, displaying and saving data from the NanoVNA

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Controlling device via Serial commands

krupis opened this issue · comments

Feature Request

Hello. I am looking for potential solutions for our problem. We need to be able to perform RF tests on 2.4Ghz antenna. One of the possible solutions is to use NanoVNA device.

Describe Preferred Solution

In order to perform all the tests we want, we need to be able to control the device using serial commands. Using serial commands, we need to do the following:

  • Set frequency range, span, center frequency;
  • Set maximum measurement points;
  • Place cursors on specific frequencies;
  • Read dB measurement data from set cursors.

We do not need any GUI , we only want to send the command and receive a simple response in text. Do you know if anything similar is currently possible?

Additional Context

Could you also clarify to me what kind of NanoVNA devices do you support? From what I understand, there are quite a few different options such as:
NanoVNA H
NanoVNA H4
NanoVNA V2 (design by HCXQS/NanoRF)
NanoVNA V3 (design by HCXQS/NanoRF)

and probably a few others that I dont know about.

Does your tool support all versions of NanoVNA?

We need to be able to perform RF tests on 2.4Ghz antenna.

Please be more specific what kind of tests, S11 with the Antenna alone or S21 with a calibrated reference antenna?
2.4 GHz is an exclusion criterion for -H and -H4.

Thanks for your quick reply. I have now realized that you are the same person that have responded on the:
https://groups.io/g/nanovna-users/topic/102014357

suggesting me to use https://github.com/Ho-Ro/nanovna-tools

Could you please help me understand what are the differences between these two tools and which one is more suitable for my particular application?

Please be more specific what kind of tests, S11 with the Antenna alone or S21 with a calibrated reference antenna?
We will need to do both of those tests.

I currently have my hands on NanoVNA -H (I am aware that it is not capable of measuring 2.4 GHz but I can use this to familiarise myself with the tools available and how to use them). I can then later buy the NanoVNA V2 and I expect I would be able to use the tools in a Similar way.

For a 1st start you can try also with the -H, it can go up to 2.7 GHz - but with degraded performance because the oscillator chip can only deliver frequencies up to 300 MHz and the device uses the harmonics of the generated square wave for the higher frequency ranges.
About your question which tool to use, I would go with an easy terminal based approach, connect the -H to USB and try to open a terminal program, e.g. hterm or putty and play with the commands. Press and get a response, if this works, type help and see the commands, etc.
Then try the same with "nanovna_command.py" from my toolbox. If this works, you can use this program or "nanovna_snp.py" as a template for own experiments.

@Ho-Ro
Understood. I have already managed to get the https://github.com/Ho-Ro/nanovna-tools up and running

I have managed to get the nanovna_command.py working. For example I can execute sweep command:

C:\Users\petrikas.lu\Downloads\nanovna-tools-main\nanovna-tools-main>python nanovna_command.py sweep
10000000 1500000000 101

However, I am not fully understanding how to use nanovna_capture.py and nanovna_snp.py as I am getting the following errors:

C:\Users\petrikas.lu\Downloads\nanovna-tools-main\nanovna-tools-main>python nanovna_snp.py
# HZ S RI R 50
Traceback (most recent call last):
  File "C:\Users\petrikas.lu\Downloads\nanovna-tools-main\nanovna-tools-main\nanovna_snp.py", line 174, in <module>
    output_string( format_parameter_line( line ) )
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\petrikas.lu\Downloads\nanovna-tools-main\nanovna-tools-main\nanovna_snp.py", line 129, in format_parameter_line
    freq, S11r, S11i = line.split()
    ^^^^^^^^^^^^^^^^
ValueError: too many values to unpack (expected 3)

and

C:\Users\petrikas.lu\Downloads\nanovna-tools-main\nanovna-tools-main>python nanovna_capture.py
Traceback (most recent call last):
  File "C:\Users\petrikas.lu\Downloads\nanovna-tools-main\nanovna-tools-main\nanovna_capture.py", line 115, in <module>
    if bytestream == b'capture?\r\nch> ': # error message
       ^^^^^^^^^^
NameError: name 'bytestream' is not defined

Also, I notice that some commands cannot go through even using nanovna_command.py . For example:

C:\Users\petrikas.lu\Downloads\nanovna-tools-main\nanovna-tools-main>python nanovna_command.py capture
Traceback (most recent call last):
  File "C:\Users\petrikas.lu\Downloads\nanovna-tools-main\nanovna-tools-main\nanovna_command.py", line 74, in <module>
    print( response.decode() )                        # write string to stdout
           ^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x84 in position 30: invalid start byte

Also, trying to measure S11 parameter, I am not getting anything returned:
image

Am I not using this properly?

NameError: name 'bytestream' is not defined

This is an error, sorry, the line must be

if captured_bytes == b'capture?\r\nch> ': # error message

but nevertheless you're getting an error in communication (Windows?, see below)
But I would propose to get the nanovna_command.py running, then you have the core communication template available. The capture program captures a screenshot of the device and relies on a perfect low level communication because it transfers the complete screen content in one rush without much protocol overhead. That means on the other hand that comm error spoils the complete transfer.

1st step: try with a terminal and make you familiar with the ASCII communication
2nd step: try the python tools

My development system is Linux, Windows behaves probably different. You can put print(...) statements before the lines in trouble, e.g. at the end of nanovna_command.py and see the format, adapt the program etc.

EDIT: Yes, you're using it not properly, the capture command sends a screen shot as binary data that cannot be displayed as text.

But please be patient, I'm not on my development system right now and don't have NanoVNA or a Linux computer at hand, so I'm practically just doing it from my (faulty) memories.

@Ho-Ro

I do not fully understand what you mean:

1st step: try with a terminal and make you familiar with the ASCII communication

That is exactly what I am doing, no? Using various python scripts and their commands such as nanovna_command sweep and nanovna_capture and others using terminal? I do not know what else could you be refering to when you say try with a terminal

Could you provide one or two examples on what exactly you mean using terminal vs using python so I can understand? Thanks!

I understand you now.. You refer to using serial commands directly via serial terminal. I use Termite:
image

I will familiarise myself with this. Thanks!

The command format is described here and there. Otherwise help gives an overview which commands are available.

EDIT: this is the up-to-date version: shellcommands.txt

@krupis Please close this issue and follow the discussion at the right repo:
Ho-Ro/nanovna-tools#2