

caput("TESTIOC:TESTCALCOUT:Input", 2.0)

time.sleep(0.0)

caput("TESTIOC:TESTCALCOUT:Input", 5.0)

try:
    #write_logs()
        
    waiting = True
    def plot_task():
        global waiting
        while waiting:
            if count.take() != pos:
                time.sleep(2.0)
    
    ret = fork(plot_task)
    try:       
        #Post-actions
        wait_channel("TESTIOC:TESTCALCOUT:Output", "3.0", type = 's')
        time.sleep(2.0)
        print "Finished Energy scan"
    finally:    
        waiting = False
    join(ret)
    
    #plot_file(newName)
    print("Success")        
  
except:    
    while caget('TESTIOC:TESTCALCOUT:Output') != 3.0:
        print("Aborting...")      
        caput("TESTIOC:TESTCALCOUT:Input", 3.0)