示例#1
0
def main():
    parser = argparse.ArgumentParser(
        description='Connect to a Rohde & Schwarz VNA')
    parser.add_argument('--visa',
                        metavar='bus',
                        default=False,
                        help="use VISA with 'bus'")
    parser.add_argument('--address',
                        default='127.0.0.1',
                        help='instrument address')
    parser.add_argument('--timeout',
                        default=5000,
                        type=int,
                        help='default instrument timeout (ms)')
    parser.add_argument('--log', default='', help='SCPI command log filename')
    args = parser.parse_args()

    vna = Vna()
    try:
        if args.visa:
            vna.open(args.visa, args.address)
        else:
            vna.open_tcp(args.address)
        if args.timeout:
            vna.timeout_ms = args.timeout

        if vna.connected():
            print("connected: {0}".format(vna.id_string()))
            if args.log:
                vna.open_log(args.log)
                vna.log.write('{0}\n'.format(datetime.datetime.now()))
                vna.log.write('--------------------------\n\n')
                vna.print_info()
            sys.path.insert(0, os.getcwd())
            code.interact('', local=locals())
            sys.exit(0)
        else:
            raise Exception('Could not connect to instrument')
    except SystemExit:
        pass
    except:
        print('Error connecting to instrument\n')
        parser.print_help()
    finally:
        if vna.log:
            vna.close_log()
        if vna.connected():
            vna.close()
示例#2
0
def main():
    parser = argparse.ArgumentParser(description='Connect to a Rohde & Schwarz VNA')
    parser.add_argument('--visa', metavar='bus', default=False,
                        help="use VISA with 'bus'")
    parser.add_argument('--address', default='127.0.0.1',
                        help='instrument address')
    parser.add_argument('--log', default='',
                        help='SCPI command log filename')
    args = parser.parse_args()

    vna = Vna()
    try:
        if args.visa:
            vna.open(args.visa, args.address)
        else:
            vna.open_tcp(args.address)

        if vna.connected():
            print("connected: {0}".format(vna.id_string()))
            if args.log:
                vna.open_log(args.log)
                vna.log.write('{0}\n'.format(datetime.datetime.now()))
                vna.log.write('--------------------------\n\n')
                vna.print_info()
            code.interact('', local=locals())
        else:
            print('Could not connect to instrument\n')
            parser.print_help()
    except SystemExit:
        pass
    except:
        print('Error connecting to instrument\n')
        parser.print_help()
    finally:
        if vna.log:
            vna.close_log()
        if vna.connected():
            vna.close()
示例#3
0
# Complex formats are:
# - COMP (Re, Im)
# - LINP (Linear magnitude,   phase [deg])
# - LOGP (Log magnitude [dB], phase [deg])
complex_format = "COMP"
scpi = ":MMEM:STOR:TRAC:PORT {0},'{1}',{2},{3}"
scpi = scpi.format(channel, 'temp.s4p', complex_format, ports_string)
vna.write(scpi)

# Save trace data to vna as
# displayed on screen
# Note: See command documentation for
#       additional data format options
scpi = ":MMEM:STOR:TRAC '{0}', '{1}', FORM"
scpi = scpi.format(trace_name, 'temp.csv')
vna.write(scpi)

# Wait for saves to complete
vna.query("*OPC?")

# Transfer files from vna
# - See read_file.py
vna.file.download_file("temp.s4p", touchstone_filename)
vna.file.download_file("temp.csv", trace_filename)

# Delete files from vna
vna.file.delete("temp.s4p")
vna.file.delete("temp.csv")

vna.close()
示例#4
0
 def tearDownClass(self):
     vna = Vna()
     vna.open_tcp()
     vna.close()
def main():
    parser = argparse.ArgumentParser(
        description='Connect to a Rohde & Schwarz VNA')
    parser.add_argument('--visa',
                        metavar='bus',
                        default=False,
                        help="use VISA with 'bus'")
    parser.add_argument('--address',
                        default='127.0.0.1',
                        help='instrument address')
    parser.add_argument('--port',
                        default=5025,
                        type=int,
                        help='port (TCP only)')
    parser.add_argument('--timeout',
                        default=5000,
                        type=int,
                        help='default instrument timeout (ms)')
    parser.add_argument('--log', help='SCPI command log filename')
    parser.add_argument(
        '--export-cal-data',
        action='store_true',
        help='Save corrections to numpy `savez` (*.pyz) data file')
    parser.add_argument('--outer-channel',
                        type=int,
                        help='channel with outer corrections')
    parser.add_argument('--outer-cal-group',
                        help='cal group containing outer corrections')
    parser.add_argument('--inner-channel',
                        type=int,
                        help='channel with inner corrections')
    parser.add_argument('--inner-cal-group',
                        help='cal group containing inner corrections')
    parser.add_argument('--filename',
                        default='Port {port}.s2p',
                        help="default: 'Port {port}.s2p'")
    parser.add_argument('ports',
                        type=int,
                        nargs='+',
                        help='VNA ports to extract DUTs from')
    args = parser.parse_args()

    if not args.inner_channel and not args.inner_cal_group:
        print('error: must include inner source, either channel or cal group')
        parser.print_help()
        sys.exit(-1)
    if not args.outer_channel and not args.outer_cal_group:
        print('error: must include outer source, either channel or cal group')
        parser.print_help()
        sys.exit(-1)

    vna = Vna()
    try:
        if args.visa:
            vna.open(args.visa, args.address)
        else:
            vna.open_tcp(args.address, args.port)
        if args.timeout:
            vna.timeout_ms = args.timeout

        if vna.connected():
            if args.log:
                vna.open_log(args.log)
                print_header(vna.log, 'R&S S2P Extractor', '1.0')
                vna.print_info()
        else:
            raise Exception('Could not connect to instrument')

        if args.outer_channel:
            outer_source = Source(Type.CHANNEL, args.outer_channel)
        else:
            outer_source = Source(Type.CAL_GROUP, args.outer_cal_group)
        if args.inner_channel:
            inner_source = Source(Type.CHANNEL, args.inner_channel)
        else:
            inner_source = Source(Type.CAL_GROUP, args.inner_cal_group)
        print(f"ports: {args.ports}")
        for port in args.ports:
            filename = args.filename.format(port=port)
            print(f'  {filename}')
            calculate(vna, outer_source, inner_source, port, filename,
                      args.export_cal_data)
    except Exception as err:
        parser.print_help()
        raise
    finally:
        if vna.connected():
            vna.errors
            vna.clear_status()
        if vna.log:
            vna.close_log()
        if vna.connected():
            vna.close()