From bc83f13ad29431fc6ae378a0a54f158fcca1955a Mon Sep 17 00:00:00 2001 From: boccioli_m Date: Wed, 30 Aug 2017 10:29:23 +0200 Subject: [PATCH] Startup --- script/tests/tests.properties | 2 +- script/tests/tests/sad/rpstry/.config | 4 + script/tests/tests/sad/rpstry/help.html | 21 ++++ script/tests/tests/sad/rpstry/rpstry.py | 146 ++++++++++++++++++++++++ 4 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 script/tests/tests/sad/rpstry/.config create mode 100644 script/tests/tests/sad/rpstry/help.html create mode 100644 script/tests/tests/sad/rpstry/rpstry.py diff --git a/script/tests/tests.properties b/script/tests/tests.properties index 18af6c3..699a26e 100644 --- a/script/tests/tests.properties +++ b/script/tests/tests.properties @@ -1,5 +1,5 @@ #TestingList for pshell: configuration properties -#Wed Aug 30 10:20:21 CEST 2017 +#Wed Aug 30 10:29:11 CEST 2017 customPanel= showEnabledTestsOnly=true listFilter=test-bx84 diff --git a/script/tests/tests/sad/rpstry/.config b/script/tests/tests/sad/rpstry/.config new file mode 100644 index 0000000..28d5780 --- /dev/null +++ b/script/tests/tests/sad/rpstry/.config @@ -0,0 +1,4 @@ +#Tue Aug 29 14:40:54 CEST 2017 +name=rpstry +parameters=delay\:.2\:delay between 2 steps;mask\:2\:bit mask;setVal\:10\:value to set;expectedVal\:1\:expected returned value; +description=try to use pshell for rps test diff --git a/script/tests/tests/sad/rpstry/help.html b/script/tests/tests/sad/rpstry/help.html new file mode 100644 index 0000000..1a7d5ec --- /dev/null +++ b/script/tests/tests/sad/rpstry/help.html @@ -0,0 +1,21 @@ + + + +

Description

+move around a value and plot the result +

Parameters

+ + + + + + +
delay delay between 2 steps
centre centre where to move around
moveAround move right and left from centre
steps steps of each move
maxErr maximum allowed error between the value when moving one direction and the corresponding value when moving to opposite direction
+ + +

Contact

+Marco Boccioli
+Tel. 3078 + + + diff --git a/script/tests/tests/sad/rpstry/rpstry.py b/script/tests/tests/sad/rpstry/rpstry.py new file mode 100644 index 0000000..c7c72a3 --- /dev/null +++ b/script/tests/tests/sad/rpstry/rpstry.py @@ -0,0 +1,146 @@ +# Test name: rightleft +# move around a value and plot the result +# Copyright (c) 2015 Paul Scherrer Institute. All rights reserved. + +###### Init - DO NOT MODIFY THE CODE BELOW ###### +global sys, inspect, os, traceback +import sys, inspect, os, traceback + + +def startTest(testName, DEVICE, params): + """ + Main method running the test + """ + # by default, assume the test failed: + ret = 'Test failed' + status = False + # 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: + test = TestingTool(testName, testPath, DEVICE, params) + +################ END OF Init ##################### +######### WRITE YOUR CODE HERE BELOW ############# + + """ + All the code in this section # WRITE YOUR CODE HERE BELOW # is just an example and can be modified/deleted. + It must be indented to the same level as this comment. + ----------------------------------- + GETTING INPUTS: + ----------------------------------- + If needed, the following methods are available: + + test.getPath() string, path of this test file + test.getName() string, name of this test + test.getDeviceName() string, device for which the test must run (typically it is the beginning of a process variable name) + test.getPlotName() string, name to be given to the plot when using setPlotTitle(). Example: scan.setPlotTitle(test.getPlotName()) + ----------------------------------- + GETTING TEST PARAMETERS: + ----------------------------------- + if you need to get parameters for the test, use: + + myParamValue = test.getParam('myParamName') + + the calls to getParam are added to the code automatically, one per parameter, when creating the new test. + NOTE: Casting may be necessary. + See the test config for the list of parameters specific to the test. + ----------------------------------- + SETTING OUTPUTS: + ----------------------------------- + When the test has ended (error or success), this method must be called in order to return to pshell: + + test.sendFeedback(ret,success) + + ret string, a text summarizing the result of the test. + success bool, True = test successful. False = test failed. + ----------------------------------- + LOG INFO: + ----------------------------------- + when some information must be shown on the log on pshell, use the following line: + test.log('text to log') + """ + + ########## Example (can be removed) ###### + + # print the list of parameters passed. If any error, stop and send feedback. + # test.log("Example - Test name: " + test.getName()) + # test.log("Example - Device name: " + test.getDeviceName() ) + try: + test.log("-------------------------------------------") + test.log("Running test with the following parameters:") + test.printParams() + # If present, use the parameters here below for your test script. + # These parameters were automatically generated: you might need to change the casting. + delay = float(test.getParam('delay')) ; expectedVal = float(test.getParam('expectedVal')) ; setVal = float(test.getParam('setVal')) ; mask = float(test.getParam('mask')) ; + except: + # test failed, write the report into the variables ret and success and send feedback: + import traceback + ret = 'Could not retrieve testing parameters - ' + traceback.format_exc() + success = False + test.sendFeedback(ret, success) + return + + # now try with data from real device: this part will most probably fail: correct the PV names with existing ones. + try: + # set up connection to channels. "type" of data can be "d" (= double), "l" (= long). + pv_motor_sta = Channel(test.getDeviceName() + ':ao' , type='d') + pv_motor_val = Channel(test.getDeviceName() + ':ai' , type='d') + except: + # prepare return information: return text: + import traceback + ret = 'Unable to create channel - ' + traceback.format_exc() + # prepare return information: return success: + success = False + # send return information: + test.sendFeedback(ret, success) + return + # send a command to a channel (it is translated to a caput): uncomment this line below to try it + #pv_motor_com.put(1.0, timeout=None) # optionally, a timeout can be given. + pv_motor_val.put(float(setVal)) + # get value (it is translated to a caget): + motor_sta = float(pv_motor_sta.get()) + + # Closing channels: all channels that were opened with Channel() must be closed before exit: + pv_motor_sta.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: + if motor_sta == expectedVal: + ret = "Test successful, val returned as expected: " + str(motor_sta) + success = True + else: + ret = "Test failed, val expected: " + str(expectedVal) + " ; val received: " + str(motor_sta) + success = False + #test.sendFeedback(ret, success) + # 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. + test.sendFeedback(ret, success) + except (KeyboardInterrupt): + # user stop error handler. + import traceback + ret = 'Test stopped by user.' + success = False + test.sendFeedback(ret, success) + except: + # generic error handler. + import traceback + ret = traceback.format_exc() + success = False + test.sendFeedback(ret, success) + + +# launch the test. +startTest(test, device, parameters) + +################ END OF Final #################### +#### IF NEEDED, ADD YOUR FUNCTIONS HERE BELOW #### +# Indent to end left +# def yourCustomFunction: