import ch.psi.pshell.scan.LineScan;
import ch.psi.pshell.scan.AreaScan;


def sleep(millis){
    Thread.sleep(millis);
}

def toArray(obj){
   /* if (!obj.getClass().isArray()){
        arr =  java.lang.reflect.Array.newInstance(obj.getClass(), 1);
        arr[0]= obj;
        obj=arr
    }*/
    return obj
}


def scan(writables, readables, start, end, steps, latency_ms=0, plot=null){
    writables=toList(writables)
    readables=toList(readables)
    start=toList(start)
    end=toList(end)    
    scan = LineScan(writables,readables, start, end , steps,latency_ms, controller)
    scan.setPlotName(plot)
    scan.start()
    return scan.getResult()
}

def tscan(readables, points, interval_ms, plot=null){
    writables=[]
    //readables=toList(readables)
    readables=[readables,]
    start=[0]
    
    end=[points]
    steps=points
    scan = LineScan(writables,readables, start, end , steps,interval_ms, controller)
    scan.setPlotName(plot)
    scan.start()
    return scan.getResult()
}

def ascan(writables, readables, start, end, steps, latency_ms0, plot=null){
    writables=toList(writables)
    readables=toList(readables)
    start=toList(start)
    end=toList(end)    
    scan = AreaScan(writables,readables, start, end , steps,latency_ms, controller)
    scan.setPlotName(plot)
    scan.start()
    return scan.getResult()    
}