96 lines
4.3 KiB
Python
96 lines
4.3 KiB
Python
|
|
###### Init - DO NOT MODIFY THE CODE BELOW ######
|
|
global print_log, sendFeedback, inspect, log, sys, inspect, os, traceback
|
|
import sys, inspect, os, traceback
|
|
|
|
def print_log(testName, DEVICE, text):
|
|
time.ctime()
|
|
now = time.strftime('%Y.%m.%d %H:%M:%S')
|
|
print now + ' ' + DEVICE + ' - ' + testName + ': ' + str(text)
|
|
log (now + ' ' + DEVICE + ' - ' + testName + ': ' + text )
|
|
|
|
#prepare and send feedback to calling tool
|
|
def sendFeedback(testPath, testName, DEVICE, returnString, testPassed):
|
|
print_log(testName, DEVICE, 'End of test. Result:')
|
|
print_log(testName, DEVICE, 'Device: ' + DEVICE)
|
|
print_log(testName, DEVICE, 'Test name: ' + testName)
|
|
print_log(testName, DEVICE, 'Test path: ' + testPath)
|
|
print_log(testName, DEVICE, 'Test passed: ' + str(testPassed))
|
|
print_log(testName, DEVICE, 'Return string: ' + returnString)
|
|
ret = [testPath, DEVICE, returnString, testPassed]
|
|
set_return(ret)
|
|
|
|
def startTest(testName, DEVICE, params):
|
|
try:
|
|
import traceback
|
|
#get the path of this script
|
|
testPath = inspect.getfile(inspect.currentframe())
|
|
#by default, failed
|
|
ret = 'Test failed'
|
|
success = False
|
|
#plot name to be given to the scan. Use: scan.setPlotName(plotName)
|
|
plotName = DEVICE + ' - ' + testName
|
|
######### WRITE YOUR CODE HERE BELOW #############
|
|
#get parameters from the calling interface
|
|
print_log(testName, DEVICE, 'testpath: ' + testPath )
|
|
print_log(testName, DEVICE, 'parameters:' + str( params) )
|
|
print_log(testName, DEVICE, 'device: ' + DEVICE )
|
|
scan = ManualScan(['time'], ['idMotorStep', 'idPotiPosition', 'idPotiRef1Position','idMotorStep-idPotiPosition'] , [0.0], [30.0], [20])
|
|
scan.setPlotName(plotName)
|
|
scan.start()
|
|
|
|
#Creating channels: dimension 1
|
|
try:
|
|
idCom = Channel(DEVICE+':COM:2', type = 'd') #current position as from motor step counter [mm]
|
|
idMotorStep = Channel(DEVICE+':IST3:2', type = 'd') #current position as from motor step counter [mm]
|
|
idPotiPosFromBeam = Channel(DEVICE+':IST1:2', type = 'd') #current position from beam as from potentiometer [mm]
|
|
idPotiPosition = Channel(DEVICE+':IST2:1', type = 'd') #current position as from potentiometer [mm]
|
|
idPotiRef1Position = Channel(DEVICE+':REF1:1', type = 'd') #R1 position as from potentiometer [mm]
|
|
idPotiRef2Position = Channel(DEVICE+':REF2:1', type = 'd') #R2 position as from potentiometer [mm]
|
|
|
|
except:
|
|
sendFeedback(testPath, testName, DEVICE, 'Unable to create channel - ' + traceback.format_exc(), False)
|
|
#raise Exception('Unable to create channel - ' + traceback.format_exc())
|
|
return
|
|
|
|
idCom.put('3', timeout=None) # go to R1
|
|
print_log(testName, DEVICE, 'Moving to reference point')
|
|
#scan quickly the output during some seconds
|
|
detector4 = idPotiPosition.get()
|
|
detector6 = idPotiRef2Position.get()
|
|
timeElapsed=0
|
|
while detector4>detector6 and timeElapsed<600:
|
|
#Detector time
|
|
detector1 = float(java.lang.System.currentTimeMillis())
|
|
|
|
detector2 = idMotorStep.get()
|
|
detector3 = idPotiPosFromBeam.get()
|
|
detector4 = idPotiPosition.get()
|
|
detector5 = idPotiRef1Position.get()
|
|
detector6 = idPotiRef2Position.get()
|
|
diff1 = detector2-detector4
|
|
scan.append ([detector1], [detector1], [detector2, detector4, detector5, diff1])
|
|
sleep( 0.1 ) # Settling time
|
|
timeElapsed=timeElapsed+1
|
|
|
|
#Closing channels
|
|
idCom.close()
|
|
idMotorStep.close()
|
|
idPotiPosFromBeam.close()
|
|
idPotiPosition.close()
|
|
idPotiRef1Position.close()
|
|
idPotiRef2Position.close()
|
|
print_log(testName, DEVICE, ' Reference point reached')
|
|
|
|
################ END OF YOUR CODE ################
|
|
###### Final - DO NOT MODIFY THE CODE BELOW ######
|
|
sendFeedback(testPath, testName, DEVICE, ret, success)
|
|
except:
|
|
ret = traceback.format_exc()
|
|
success = False
|
|
sendFeedback(testPath, testName, DEVICE, ret, success)
|
|
return
|
|
|
|
#launch the test
|
|
startTest(test, device, parameters)
|