start = time() for i in xrange(repeats): #### Need such routine to avoid timeout ### wait until it is nearly time to ask for the result ### but only when the gating time is long if (gatetime > 2): stoptime = start + gatetime -1 while time() < stoptime: try: sleep(0.1) except KeyboardInterrupt: out.close() print "Interrupt by user" sys.exit(1) # Ask for the result, this also starts the next measurement freq = float(counter.ask("FETCH:FREQ?")) finish = time() counter.write(":FREQ:EXP1 %s" %freq) elapsed = finish - start start = finish # Print result to file and screen result = array([[finish, freq]]) savetxt(out, result) print "%g Hz (elapsed: %.3f s) " %(freq, elapsed) out.close()