From 782772c2545cc5ea962081b8a113c584b21c2994 Mon Sep 17 00:00:00 2001 From: boccioli_m Date: Mon, 31 Aug 2015 09:18:17 +0200 Subject: [PATCH] added plot example to template --- script/tests/templates/testTemplate.py | 36 +++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/script/tests/templates/testTemplate.py b/script/tests/templates/testTemplate.py index 5af3b88..9356093 100644 --- a/script/tests/templates/testTemplate.py +++ b/script/tests/templates/testTemplate.py @@ -62,6 +62,14 @@ def startTest(testName, DEVICE, params): sendFeedback(testPath, testName, DEVICE, ret, success) return + #example: 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 + scan.start() #IMPORTANT: if the test resulted with an error, write the following: ret = "Example - Error, the test failed because...." @@ -69,7 +77,33 @@ def startTest(testName, DEVICE, params): #IMPORTANT: if the test was successful, write the following: ret = "Example - Test successful, here some detail: ..." success = True - + #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') + except: + #prepare return information: return text + ret = 'Unable to create channel - ' + traceback.format_exc() + #prepare return information: return success + success = False + #send return information + sendFeedback(testPath, testName, DEVICE, ret, success) + return + #take 100 samples of the channels + for sample in range(0, 100): + readback1 = sample + sleep( 0.1 ) # Settling time + #get value + motor_msta = pv_motor_msta.get() + #get value + motor_val = pv_motor_val.get() + #add values to plot + scan.append ([sample], [readback1], [detmotor_msta, motor_val] ) + + #Closing channels + pv_motor_msta.close() + pv_motor_val.close() + #once the test is finished, no need to do anything. The code below yours will do the rest. ################ END OF YOUR CODE ################ ###### Final - DO NOT MODIFY THE CODE BELOW ######