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()
def connect_to_vna(address): vna = Vna() try: vna.open_tcp(address) except: print("\n\n* Error!\n* Problem connecting to VNA at ip {0}".format(address)) return None try: if not vna.connected(): print("\n\n* Error!\n* Problem connecting to VNA at ip {0}".format(address)) return None if not vna.properties.is_known_model(): print("\n\n* Error!\n* Could not find R&S VNA at ip {0}".format(address)) print("* *IDN? response: {0}".format(vna.id_string())) return None; except: print("\n\n* Error!\n* Problem connecting to VNA at ip {0}".format(address)) return None # set long timeout, vna.timeout_ms = 60000 return vna
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()