#Script imported from: test2.xml

#Variables
var1 = 0.0

#TODO: Set the diplay names of positioners and detectors
scan = ManualScan(['id643271', 'id278043'], ['id348623', 'id367393'] , [0.0, 0.0], [5.0, 31.0], [5, 31])
scan.start()

#Creating channels: dimension 1
#LinearPositioner id643271
id643271 = Channel('TESTIOC:TESTCALC:MyCalc', type = 'd')
#Creating channels: dimension 2
#LinearPositioner id278043
id278043 = Channel('TESTIOC:TESTCALCOUT:Input', type = 'd')
#ScalarDetector id348623
id348623 = Channel('TESTIOC:TESTCALCOUT:Output', type = 'd')
#ScalarDetector id367393
id367393 = Channel('TESTIOC:TESTSINUS:SinCalc', type = 'd')

#Dimension 1
#LinearPositioner id643271
for setpoint1 in frange(0.0, 5.0, 1.0, True):
    if setpoint1 > 5.0 or  setpoint1 < 0.0:
        break
    id643271.put(setpoint1, timeout=None) # TODO: Set appropriate timeout
    readback1 = id643271.get()
    if abs(readback1 - setpoint1) > 0.5 : # TODO: Check accuracy
        raise Exception('Actor id643271 could not be set to the value ' + str(setpoint1))
    #Dimension 2
    #LinearPositioner id278043
    for setpoint2 in frange(0.0, 31.0, 1.0, True):
        if setpoint2 > 31.0 or  setpoint2 < 0.0:
            break
        id278043.put(setpoint2, timeout=None) # TODO: Set appropriate timeout
        readback2 = id278043.get()
        if abs(readback2 - setpoint2) > 0.5 : # TODO: Check accuracy
            raise Exception('Actor id278043 could not be set to the value ' + str(setpoint2))
        #Dimension Actions
        #Script action
        #TODO: Move, if needed, this import to the file header: import time
        time.sleep(0.01)
        #Detector id348623
        detector1 = id348623.get()
        #Detector id367393
        detector2 = id367393.get()
        scan.append ([setpoint1, setpoint2], [readback1, readback2], [detector1, detector2])

#Closing channels
id278043.close()
id348623.close()
id367393.close()
id643271.close()

scan.end()
