2019-08-30 19:24:08 +00:00
|
|
|
#! /bin/env python
|
2020-06-25 17:48:03 +00:00
|
|
|
#
|
|
|
|
# NanoVNASaver
|
|
|
|
#
|
|
|
|
# A python program to view and export Touchstone data from a NanoVNA
|
2020-06-25 17:52:30 +00:00
|
|
|
# Copyright (C) 2019, 2020 Rune B. Broberg
|
2021-06-30 05:21:14 +00:00
|
|
|
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
2019-08-29 13:10:35 +00:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-06-25 17:48:03 +00:00
|
|
|
"""
|
|
|
|
NanoVNASaver
|
|
|
|
|
|
|
|
A multiplatform tool to save Touchstone files from the
|
|
|
|
NanoVNA, sweep frequency spans in segments to gain more
|
|
|
|
data points, and generally display and analyze the
|
|
|
|
resulting data.
|
|
|
|
"""
|
|
|
|
import argparse
|
2019-09-16 13:47:37 +00:00
|
|
|
import logging
|
2019-09-15 21:18:35 +00:00
|
|
|
import sys
|
2019-08-28 13:43:02 +00:00
|
|
|
|
2019-09-10 21:20:59 +00:00
|
|
|
from PyQt5 import QtWidgets, QtCore
|
2019-08-27 14:00:56 +00:00
|
|
|
|
2020-06-25 17:48:03 +00:00
|
|
|
from NanoVNASaver.About import VERSION, INFO
|
|
|
|
from NanoVNASaver.NanoVNASaver import NanoVNASaver
|
2021-07-02 17:09:28 +00:00
|
|
|
from NanoVNASaver.Touchstone import Touchstone
|
2019-08-28 12:18:56 +00:00
|
|
|
|
2019-09-04 16:12:38 +00:00
|
|
|
|
|
|
|
def main():
|
2020-06-25 17:48:03 +00:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description=__doc__,
|
|
|
|
formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
|
|
parser.add_argument("-d", "--debug", action="store_true",
|
|
|
|
help="Set loglevel to debug")
|
|
|
|
parser.add_argument("-D", "--debug-file",
|
|
|
|
help="File to write debug logging output to")
|
2021-07-02 17:09:28 +00:00
|
|
|
parser.add_argument("-f", "--file",
|
|
|
|
help="Touchstone file to load as sweep for off device usage")
|
|
|
|
parser.add_argument("-r", "--ref-file",
|
|
|
|
help="Touchstone file to load as reference for off device usage")
|
2020-06-25 17:48:03 +00:00
|
|
|
parser.add_argument("--version", action="version",
|
|
|
|
version=f"NanoVNASaver {VERSION}")
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2019-09-16 20:49:21 +00:00
|
|
|
console_log_level = logging.WARNING
|
|
|
|
file_log_level = logging.DEBUG
|
|
|
|
|
2020-06-25 17:48:03 +00:00
|
|
|
print(INFO)
|
2019-09-16 13:47:37 +00:00
|
|
|
|
2020-06-25 17:48:03 +00:00
|
|
|
if args.debug:
|
2019-10-01 12:53:01 +00:00
|
|
|
console_log_level = logging.DEBUG
|
|
|
|
|
2019-09-16 13:47:37 +00:00
|
|
|
logger = logging.getLogger("NanoVNASaver")
|
2019-09-16 19:41:01 +00:00
|
|
|
logger.setLevel(logging.DEBUG)
|
2020-06-25 17:48:03 +00:00
|
|
|
|
2019-09-16 13:47:37 +00:00
|
|
|
ch = logging.StreamHandler()
|
2019-09-16 20:49:21 +00:00
|
|
|
ch.setLevel(console_log_level)
|
2020-06-25 17:48:03 +00:00
|
|
|
formatter = logging.Formatter(
|
|
|
|
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
2019-09-16 13:47:37 +00:00
|
|
|
ch.setFormatter(formatter)
|
|
|
|
logger.addHandler(ch)
|
2019-09-16 20:49:21 +00:00
|
|
|
|
2020-06-25 17:48:03 +00:00
|
|
|
if args.debug_file:
|
|
|
|
fh = logging.FileHandler(args.debug_file)
|
2019-09-16 20:49:21 +00:00
|
|
|
fh.setLevel(file_log_level)
|
|
|
|
fh.setFormatter(formatter)
|
|
|
|
logger.addHandler(fh)
|
|
|
|
|
2019-09-16 13:47:37 +00:00
|
|
|
logger.info("Startup...")
|
|
|
|
|
2020-06-25 17:48:03 +00:00
|
|
|
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling,
|
|
|
|
True)
|
2019-09-15 21:18:35 +00:00
|
|
|
app = QtWidgets.QApplication(sys.argv)
|
2019-08-27 14:00:56 +00:00
|
|
|
window = NanoVNASaver()
|
|
|
|
window.show()
|
2021-07-02 17:09:28 +00:00
|
|
|
|
|
|
|
if args.file:
|
|
|
|
t = Touchstone(args.file)
|
|
|
|
t.load()
|
|
|
|
window.saveData(t.s11, t.s21, args.file)
|
|
|
|
window.dataUpdated()
|
|
|
|
if args.ref_file:
|
|
|
|
t = Touchstone(args.ref_file)
|
|
|
|
t.load()
|
|
|
|
window.setReference(t.s11, t.s21, args.ref_file)
|
|
|
|
window.dataUpdated()
|
2020-07-11 12:00:05 +00:00
|
|
|
try:
|
|
|
|
app.exec_()
|
|
|
|
except BaseException as exc:
|
|
|
|
logger.exception("%s", exc)
|
2021-07-05 09:37:48 +00:00
|
|
|
raise exc
|
2019-09-04 16:12:38 +00:00
|
|
|
|
2022-05-27 07:03:37 +00:00
|
|
|
|
2019-09-04 16:12:38 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|