def run_target(uut, args): args.plot_volts = True if args.set_volts != None else False work = zero_offset.ZeroOffset( uut, args.nchan, args.awglen, target=(args.set_volts if args.plot_volts else 0), aochan=int(args.aochan), gain=args.gain * (0.95 * 32768 / 10 if args.plot_volts else 1), passvalue=args.passvalue, ao0=args.ao0) try: loader = work.load() ii = 0 while next(loader): uut.run_oneshot() print("read_chan %d" % (args.post * args.nchan)) rdata = uut.read_chan(0, args.post * args.nchan) if args.plot > 0: plt.cla() title = "AI for shot %d %s" % (ii, "persistent plot" if args.plot > 1 else "") print(title) plt.title(title) pltsup.plot(uut, args, ii, rdata) pltsup.store_file(ii, rdata, args.nchan, args.post) if args.wait_user: key = input("hit return to continue, q for quit").strip() if key == 'q': work.user_quit = True if work.in_bounds: work.finished = True print("raw_input {}".format(key)) else: if work.in_bounds: work.finished = True chx = np.reshape(uut.scale_raw(rdata, volts=args.plot_volts), (args.post, args.nchan)) if args.plot_volts: chv = np.array([ uut.chan2volts(ch + 1, chx[:, ch]) for ch in range(0, args.nchan) ]) print("feedback volts") work.feedback(np.transpose(chv)) else: work.feedback(chx) ii += 1 except StopIteration: print("offset zeroed within bounds") except acq400_hapi.acq400.Acq400.AwgBusyError: print("AwgBusyError, trying a soft trigger and quit, then re-run me") uut.s0.soft_trigger = '1' raise SystemExit return work
def run_shots(args): uut = acq400_hapi.Acq400(args.uuts[0]) acq400_hapi.cleanup.init() if args.plot: plt.ion() uut.s0.transient = 'POST=%d SOFT_TRIGGER=%d DEMUX=0' % \ (args.post, 1 if args.trg == 'int' else 0) if args.aochan == 0: args.aochan = args.nchan for sx in uut.modules: if args.trg == 'int': uut.modules[sx].trg = '1,1,1' else: if args.trg.contains('falling'): uut.modules[sx].trg = '1,0,0' else: uut.modules[sx].trg = '1,0,1' if args.pulse != None: work = awg_data.Pulse(uut, args.aochan, args.awglen, args.pulse.split(',')) elif args.files != "": work = awg_data.RunsFiles(uut, args.files.split(','), run_forever=True) else: work = awg_data.RainbowGen(uut, args.aochan, args.awglen, run_forever=True) # compensate gain ONLY Rainbow Case if args.range != "default": gain = 10/float(args.range.strip('V')) print("setting work.gain {}".format(gain)) work.gain = gain # Set range knobs, valid ALL data sources. if args.range != "default": for sx in uut.modules: print("setting GAIN_ALL {}".format(args.range)) uut.modules[sx].GAIN_ALL = args.range break print("args.autorearm {}".format(args.autorearm)) loader = work.load(autorearm = args.autorearm) for ii in range(0, args.loop): print("shot: %d" % (ii)) if ii == 0 or not args.autorearm: f = loader.next() print("Loaded %s" % (f)) else: if args.autorearm and ii+1 == args.loop: # on the final run, drop out of autorearm mode. # the final shot MUST be in ONCE mode so that the DMAC # is freed on conclusion for sx in uut.modules: if uut.modules[sx].MODEL.startswith('AO'): uut.modules[sx].playloop_oneshot = '1' uut.run_oneshot() print("read_chan %d" % (args.post*args.nchan)) rdata = uut.read_chan(0, args.post*args.nchan) if args.store: pltsup.store_file(ii, rdata, args.nchan, args.post) if args.plot > 0 : plt.cla() plt.title("AI for shot %d %s" % (ii, "persistent plot" if args.plot > 1 else "")) pltsup.plot(uut, args, ii, rdata) if args.wait_user is not None: args.wait_user()