From 3dc213865f2f953887eaffe93dc5dc7bd1c02c99 Mon Sep 17 00:00:00 2001 From: boccioli_m Date: Fri, 13 Oct 2017 11:18:31 +0200 Subject: [PATCH] Startup --- script/tests/devices/bis-BMA1/.config | 4 + script/tests/tests.properties | 2 +- .../Betriebsmode/.config | 4 + .../Betriebsmode/Betriebsmode.py | 172 ++++++++++++++++++ .../Betriebsmode/help.html | 19 ++ 5 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 script/tests/devices/bis-BMA1/.config create mode 100644 script/tests/tests/RPS Tests Betriebsmode/Betriebsmode/.config create mode 100644 script/tests/tests/RPS Tests Betriebsmode/Betriebsmode/Betriebsmode.py create mode 100644 script/tests/tests/RPS Tests Betriebsmode/Betriebsmode/help.html diff --git a/script/tests/devices/bis-BMA1/.config b/script/tests/devices/bis-BMA1/.config new file mode 100644 index 0000000..4d369ac --- /dev/null +++ b/script/tests/devices/bis-BMA1/.config @@ -0,0 +1,4 @@ +#Fri Oct 13 11:04:30 CEST 2017 +name=bis-BMA1 +tests=RPS Tests Betriebsmode +description=rps section till BMA1 diff --git a/script/tests/tests.properties b/script/tests/tests.properties index f6c4f6d..1b16a0a 100644 --- a/script/tests/tests.properties +++ b/script/tests/tests.properties @@ -1,5 +1,5 @@ #TestingList for pshell: configuration properties -#Fri Oct 13 10:58:21 CEST 2017 +#Fri Oct 13 11:18:17 CEST 2017 customPanel= showEnabledTestsOnly= listFilter=rps-try diff --git a/script/tests/tests/RPS Tests Betriebsmode/Betriebsmode/.config b/script/tests/tests/RPS Tests Betriebsmode/Betriebsmode/.config new file mode 100644 index 0000000..a7ac8ee --- /dev/null +++ b/script/tests/tests/RPS Tests Betriebsmode/Betriebsmode/.config @@ -0,0 +1,4 @@ +#Fri Oct 13 11:12:22 CEST 2017 +name=Betriebsmode +parameters=mode&2,IQCOM,$BMA1,1,DIA&[string] Betriebs mode;expectedVal14&0x0000&[hex] Expected value for channels 1-4;expectedVal58&0x0000&[hex] Expected value for channels 5-8;setGetDelay&1000&[ms] delay between set and get; +description=betriebsmode diff --git a/script/tests/tests/RPS Tests Betriebsmode/Betriebsmode/Betriebsmode.py b/script/tests/tests/RPS Tests Betriebsmode/Betriebsmode/Betriebsmode.py new file mode 100644 index 0000000..f68293a --- /dev/null +++ b/script/tests/tests/RPS Tests Betriebsmode/Betriebsmode/Betriebsmode.py @@ -0,0 +1,172 @@ +# Test name: Betriebsmode +# betriebsmode +# 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("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. + mode = float(test.getParam('mode')) ; expectedVal14 = float(test.getParam('expectedVal14')) ; expectedVal58 = float(test.getParam('expectedVal58')) ; setGetDelay = float(test.getParam('setGetDelay')) ; + except: + # test failed, write the report into the variables ret and success and send feedback: + 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: pass here the axis names: + scan = ManualScan(['sample'], ['Status (MSTA)', 'Position (VAL)']) + # set plot name(tab title): + scan.setPlotTitle(test.getPlotName()) + # start plots. See further below how to add points to the plots (scan): + scan.start() + + # inject a sinus into the plot, as example + from math import sin + motor_msta = 0 + # take 100 samples of a sinus and a jigsaw plot them: + for sample in range(0, 100): + readback1 = sample #the x axis. + sleep(0.1) # settling time. + # get value (it is translated to a caget): + motor_msta = motor_msta + +1 + if motor_msta > 50: + motor_msta = 0 + # get value: + motor_val = sin(float(sample)/10.0)*10.0-10.0 + # add values to plot: + scan.append([readback1], [readback1], [motor_msta, motor_val]) + + # 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_msta = Channel(test.getDeviceName() + ':IST:2' , type='d') + pv_motor_val = Channel(test.getDeviceName() + ':IST:1' , type='d') + pv_motor_com = Channel(test.getDeviceName() + ':COM:2' , type='d') + except: + # prepare return information: return text: + 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. + # take 100 samples of the channels and plot them: + for sample in range(0, 100): + readback1 = sample #the x axis. + sleep(0.1) # settling time. + # get value (it is translated to a caget): + motor_msta = pv_motor_msta.get() + # get value: + motor_val = pv_motor_val.get() + # add values to plot: + scan.append([readback1], [readback1], [motor_msta, motor_val]) + + # Closing channels: all channels that were opened with Channel() must be closed before exit: + pv_motor_msta.close() + pv_motor_val.close() + pv_motor_com.close() + + # 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. + ################ 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: diff --git a/script/tests/tests/RPS Tests Betriebsmode/Betriebsmode/help.html b/script/tests/tests/RPS Tests Betriebsmode/Betriebsmode/help.html new file mode 100644 index 0000000..80208a8 --- /dev/null +++ b/script/tests/tests/RPS Tests Betriebsmode/Betriebsmode/help.html @@ -0,0 +1,19 @@ + + + +

Description

+betriebsmode +

Parameters

+ + + + + + +
mode [string] Betriebs mode
expectedVal14 [hex] Expected value for channels 1-4
expectedVal58 [hex] Expected value for channels 5-8
setGetDelay [ms] delay between set and get
+

Contact

+Marco Boccioli
+Tel. 3078 + + +