scan_complete=False
scan_result = None

def check_end_scan(record, scan):
    global scan_complete, scan_result
    if record.index>=50:
        print "Data aquisition completed"
        scan.abort()
        scan_complete=True
        record.cancel()   
        scan_result = scan.result 
    elif (record.index>0) and (record.index % 10 == 0):
        get_context().dataManager.splitScanData(scan)


xxx=None
def do_scan():
    global scan_complete, scan_result
    scan_complete=False
    try:            
        mscan (sin, [sin,arr], -1, -1, after_read = check_end_scan, range="auto")       
    except:        
        if not scan_complete:
            raise
    return scan_result


set_exec_pars(group="x_{count}", reset=True);
r1 =do_scan()

#set_exec_pars(group="y_{count}", reset=True)
#r2 = do_scan()

