diff --git a/script/tests/templates/testTemplate.py b/script/tests/templates/testTemplate.py index 8886acf..1b89d03 100644 --- a/script/tests/templates/testTemplate.py +++ b/script/tests/templates/testTemplate.py @@ -11,23 +11,21 @@ def startTest(testName, DEVICE, params): """ Main method running the test """ - # by default, assume the test failed. + # 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. + # get the path of this script: testPath = inspect.getfile(inspect.currentframe()) - # init the testing tool class. It can be sued in the following ways: + # init the testing tool class: test = TestingTool(testName, testPath, DEVICE, params) - # plot name to be given to the scan. Use: scan.setPlotName(plotName). - plotName = test.getPlotName() ################ END OF Init ##################### ######### WRITE YOUR CODE HERE BELOW ############# """ - All the code in this section ###..YOUR CODE..### can be modified/deleted. + All the code in this section # WRITE YOUR CODE HERE BELOW # can be modified/deleted. It must be indented to the same level as this comment ----------------------------------- GETTING INPUTS: @@ -84,17 +82,33 @@ def startTest(testName, DEVICE, params): # 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'], ['Motor Status (MSTA)', 'Motor Position (VAL)']) + scan = ManualScan(['sample'], ['Status (MSTA)', 'Position (VAL)']) # set plot name(tab title): scan.setPlotName(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 + 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 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() + ':MOTOR.MSTA', type='d') - pv_motor_val = Channel(test.getDeviceName() + ':MOTOR.VAL' , type='d') - pv_motor_com = Channel(test.getDeviceName() + ':COM:2' , type='d') + 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() @@ -103,8 +117,8 @@ def startTest(testName, DEVICE, params): # send return information: test.sendFeedback(ret, success) return - # send a command to a channel (it is translated to a caput): - pv_motor_com.put(1.0, timeout=None) # optionally, a timeout can be given. + # 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.