sys.exit(0)

sl = ScriptLogger(start_time)
log = sl.script_log
log.info('arguments: %s' % str(args))

last_read = []
controller = None  # keep handle to some variables in case you want to enter an interactive session
board_info = None
try:
    controller = larpix.Controller(timeout=0.01)
    board_info = larpix_scripting.load_board(controller, args.board)
    controller.disable()
    config_ok, different_registers = larpix_scripting.load_chip_configurations(
        controller,
        board_info,
        args.config,
        threshold_correction=args.global_threshold_correction,
        trim_correction=args.trim_correction)

    for chip in controller.chips:
        chip.config.external_trigger_mask[7] = 0
        controller.write_configuration(chip, range(56, 60))

    for _ in range(args.subruns):
        specifier = time.strftime('%Y_%m_%d_%H_%M_%S')
        log.info('begin collect_data_%s' % specifier)
        controller.run(args.run_time, 'collect_data_%s' % specifier)
        last_read = controller.reads[-1]
        log.info('end collect_data_%s' % specifier)
        log.info('storing...')
        sl.flush_datalog()
data_logfile = outdir + '/' + os.path.basename(
    pathnames.default_data_logfile(start_time))
sl = ScriptLogger(start_time,
                  script_logfile=script_logfile,
                  data_logfile=data_logfile)
log = sl.script_log
log.info('arguments: %s' % str(args))

try:
    controller = larpix.Controller(timeout=0.01)
    # Initial configuration of chips
    board_info = larpix_scripting.load_board(controller, infile)
    log.info('begin initial configuration of chips for board %s' % board_info)
    config_ok, different_registers = larpix_scripting.load_chip_configurations(
        controller,
        board_info,
        config_file,
        silence=True,
        default_config=default_config)
    if config_ok:
        log.info('initial configuration of chips complete')

    # Run low pedestal test on each chip
    board_results = []
    for chip_idx, chip in enumerate(controller.chips):
        try:
            start_time = time.time()
            chip_id = chip.chip_id
            io_chain = chip.io_chain
            chip_info = (io_chain, chip_id)
            if chips_to_scan is None:
                pass