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

Controlling device via Serial commands #676

Open
krupis opened this issue Oct 17, 2023 · 9 comments
Open

Controlling device via Serial commands #676

krupis opened this issue Oct 17, 2023 · 9 comments
Labels
enhancement New feature or request

Comments

@krupis
Copy link

krupis commented Oct 17, 2023

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?

@krupis krupis added the enhancement New feature or request label Oct 17, 2023
@Ho-Ro
Copy link
Member

Ho-Ro commented Oct 17, 2023

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.

@krupis
Copy link
Author

krupis commented Oct 18, 2023

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.

@Ho-Ro
Copy link
Member

Ho-Ro commented Oct 18, 2023

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.

@krupis
Copy link
Author

krupis commented Oct 18, 2023

@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?

@Ho-Ro
Copy link
Member

Ho-Ro commented Oct 18, 2023

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.

@krupis
Copy link
Author

krupis commented Oct 18, 2023

@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!

@krupis
Copy link
Author

krupis commented Oct 18, 2023

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!

@Ho-Ro
Copy link
Member

Ho-Ro commented Oct 18, 2023

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

@Ho-Ro
Copy link
Member

Ho-Ro commented Oct 18, 2023

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

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

2 participants