Python script improvements

This commit is contained in:
boccioli_m
2015-09-14 10:59:05 +02:00
parent c706223161
commit 5ab97dbf05
14 changed files with 649 additions and 236 deletions
+61 -57
View File
@@ -1,25 +1,29 @@
#Test name: $testName
#$testDescription
# Test name: $testName
# $testDescription
###### Init - DO NOT MODIFY THE CODE BELOW ######
global sys, inspect, os, traceback
import sys, inspect, os, traceback
def startTest(testName, DEVICE, params):
#by default, assume the test failed
"""
Main method running the test
"""
# by default, assume the test failed
ret = 'Test failed'
status = False
#plot name to be given to the scan. Use: scan.setPlotName(plotName)
# plot name to be given to the scan. Use: scan.setPlotName(plotName)
plotName = DEVICE + ' - ' + testName
#put the whole custom code under try/catch
# put the whole custom code under try/catch
try:
#get the path of this script
testPath = inspect.getfile(inspect.currentframe())
#init the testing tool class. It can be sued in the following ways:
# get the path of this script
testPath = inspect.getfile(inspect.currentframe())
# init the testing tool class. It can be sued in the following ways:
test = TestingTool(testName, testPath, DEVICE, params)
################ END OF Init #####################
######### WRITE YOUR CODE HERE BELOW #############
################ END OF Init #####################
######### WRITE YOUR CODE HERE BELOW #############
"""
All the code in this section ###..YOUR CODE..### can be modified/deleted.
@@ -56,89 +60,89 @@ def startTest(testName, DEVICE, params):
when some information must be shown on the log, use:
test.log('test to log')
"""
########## Example (can be removed) ######
#print the list of parameters passed. If any error, stop and send feedback
test.log("Example - Test name: "+testName)
test.log("Example - Device name: "+DEVICE)
# print the list of parameters passed. If any error, stop and send feedback
test.log("Example - Test name: " + testName)
test.log("Example - Device name: " + DEVICE)
try:
test.log("Running test Initialise with the following parameters:")
test.log(params )
#If present, use the parameters here below for your test script. You might need to change the casting
test.log(params)
# If present, use the parameters here below for your test script. You might need to change the casting
#$testParameters
except:
ret = 'Could not retrieve testing parameters - ' + traceback.format_exc()
success = False
test.sendFeedback( ret, success)
return
#loop to read channels for a while and plot the channels values.
#initialise plot tab with 2 plots
scan = ManualScan(['sample'], ['Motor Status (MSTA)', 'Motor Position (VAL)'] )
#set plot name(tab title)
test.sendFeedback(ret, success)
return
# loop to read channels for a while and plot the channels values.
# initialise plot tab with 2 plots
scan = ManualScan(['sample'], ['Motor Status (MSTA)', 'Motor Position (VAL)'])
# set plot name(tab title)
scan.setPlotName(plotName)
#start plots. See further below how to add points to the plots
# start plots. See further below how to add points to the plots
scan.start()
#IMPORTANT: if the test failed, write the report into the variables ret and success.
#for example, write the following:
# IMPORTANT: if the test failed, write the report into the variables ret and success.
# for example, write the following:
ret = "Example - Error, the test failed because...."
success = False
#set up connection to channels. "type" of data can be "d" (= double), "l" (= long)
# set up connection to channels. "type" of data can be "d" (= double), "l" (= long)
try:
pv_motor_msta = Channel(DEVICE+':MOTOR.MSTA', type = 'd')
pv_motor_val = Channel(DEVICE+':MOTOR.VAL' , type = 'd')
pv_motor_msta = Channel(DEVICE + ':MOTOR.MSTA', type='d')
pv_motor_val = Channel(DEVICE + ':MOTOR.VAL', type='d')
except:
#prepare return information: return text
# prepare return information: return text
ret = 'Unable to create channel - ' + traceback.format_exc()
#prepare return information: return success
# prepare return information: return success
success = False
#send return information
test.sendFeedback( ret, success)
# send return information
test.sendFeedback(ret, success)
return
#take 100 samples of the channels
# take 100 samples of the channels
for sample in range(0, 100):
readback1 = sample
sleep( 0.1 ) # Settling time
#get value
sleep(0.1) # Settling time
# get value
motor_msta = pv_motor_msta.get()
#get value
# get value
motor_val = pv_motor_val.get()
#add values to plot
scan.append ([sample], [readback1], [motor_msta, motor_val] )
# add values to plot
scan.append([sample], [readback1], [motor_msta, motor_val])
#Closing channels
# Closing channels
pv_motor_msta.close()
pv_motor_val.close()
#IMPORTANT: if the test was successful, write the report into the variables ret and success.
#for example, write the following:
# IMPORTANT: if the test was successful, write the report into the variables ret and success.
# for example, write the following:
ret = "Example - Test successful, here some detail: ..."
success = True
test.sendFeedback(ret, success)
#once the test is finished, no need to do anything. The code below yours will do the rest.
# once the test is finished, no need to do anything. The code below yours will do the rest.
################ End of Example ##########
################ END OF YOUR CODE ################
###### Final - DO NOT MODIFY THE CODE BELOW ######
#just in case the feedback was forgotten
################ END OF YOUR CODE ################
###### Final - DO NOT MODIFY THE CODE BELOW ######
# just in case the feedback was forgotten
test.sendFeedback(ret, success)
except (KeyboardInterrupt):
#user stop error handler
# user stop error handler
ret = 'Test stopped by user.'
success = False
test.sendFeedback(ret, success)
except:
#generic error handler
# generic error handler
ret = traceback.format_exc()
success = False
test.sendFeedback(ret, success)
#launch the test
# launch the test
startTest(test, device, parameters)
################ END OF Final ####################
#### IF NEEDED, ADD YOUR FUNCTIONS HERE BELOW ####
#def yourCustomFunction:
# def yourCustomFunction: