diff --git a/plugins/TestingList.java b/plugins/TestingList.java index b9026af..fcc4e98 100644 --- a/plugins/TestingList.java +++ b/plugins/TestingList.java @@ -71,13 +71,7 @@ public class TestingList extends Panel { return testingList; } - /** - * listen to script end of execution and get return value - * - * @param fileName - * @param result - * @param exception - */ + //delete this @Override protected void onExecutedFile(String fileName, Object result) { int iCurrentTestPos = 0; @@ -537,7 +531,7 @@ public class TestingList extends Panel { new Thread(() -> { try { - Object ret = eval("parallelize((run,('Motor Test 3 100ms',)), (run,('Motor Test 3 200ms',)))"); + Object ret = eval("parallelize((run,('testLocalVar1',globals(),{'a':21, 'b':34})), (run,('testLocalVar2',globals(),{'a':231, 'b':234})))"); Object ret1 = ((ArrayList) ret).get(0); Object ret2 = ((ArrayList) ret).get(1); System.out.println(String.valueOf(ret1)); @@ -826,6 +820,7 @@ public class TestingList extends Panel { private HashMap args; private HashMap hTests; + //delete this public RunTest(String sTestPath, HashMap args) { System.out.println("A1"); this.sDeviceName = args.get("device").toString(); @@ -835,15 +830,18 @@ public class TestingList extends Panel { this.mParameters = (HashMap) args.get("parameters"); this.args = args; } + //delete this public RunTest(String sTestPath) { this.sDeviceName = sTestPath; this.sTestPath = sTestPath; this.mParameters.put("a", 1); } + //delete this public RunTest(HashMap args) { System.out.println("A0"); this.hTests = (HashMap) args; } + public RunTest() { //System.out.println("A0"); } @@ -904,7 +902,7 @@ public class TestingList extends Panel { String sTestCaseName = jTable1.getValueAt(row, COL.TESTSUITE.ordinal()).toString(); String sTestPath = jTable1.getValueAt(row, COL.TESTPATH.ordinal()).toString(); HashMap mParameters = buildParametersMap(String.valueOf(jTable1.getValueAt(row, COL.TESTPARAMS.ordinal()))); - System.out.println(String.valueOf(row) + "\t" + sDeviceName + "\t" + sTestName + "\t" + sTestCaseName + "\t" + String.valueOf(rowsToExecute.length)); + //System.out.println(String.valueOf(row) + "\t" + sDeviceName + "\t" + sTestName + "\t" + sTestCaseName + "\t" + String.valueOf(rowsToExecute.length)); try { File f = new File(sTestPath); if (!f.exists() || f.isDirectory()) { @@ -942,6 +940,7 @@ public class TestingList extends Panel { int iLastExecutedTestIndex = -1; final String sParallelizeBegin = "(run,(str('"; final String sParallelizeEnd = "'),))"; + String sParallelizeArguments; try { //System.out.println("A0.1"); String sParallelizeCommand = "parallelize("; @@ -951,14 +950,20 @@ public class TestingList extends Panel { setGlobalsVars(hTest.getValue()); sTestPath = hTest.getKey().toString(); sTestPath = sTestPath.replace("\\","\\\\"); + System.out.println(hTest.getValue().get("test")); sParallelizeCommand = sParallelizeCommand + "(run,(str('" + sTestPath; i++; System.out.println("Parameters passed: " + String.valueOf(hTest.getValue().get("parameters"))); //System.out.println("A"+i); + sParallelizeArguments = "globals(),{parameters:'"+hTest.getValue().get("parameters")+ + "',test:'"+hTest.getValue().get("test")+ + "',device:'"+hTest.getValue().get("device")+ + "',status:'"+hTest.getValue().get("status")+"'}"; if (i) oTestRet).size()>=3){ + //System.out.println("ret type "+ret.getClass().toString() ); + //scan through all return mappings of all run tests + for(Object oTestRet : (ArrayList) ret){ + //check if the mapping of the selected test has all expected return values + if(((List) oTestRet).size()>=4){ + //extract return data of the current test sTestPath = String.valueOf(((List) oTestRet).get(0)); - sTestStatus = String.valueOf(((List) oTestRet).get(1)); + sDeviceName = String.valueOf(((List) oTestRet).get(1)); sTestResult = String.valueOf(((List) oTestRet).get(2)); + sTestStatus = String.valueOf(((List) oTestRet).get(3)); + //from the map of executed tests, get the test name (key is test path) HashMap hTest = hTests.get(sTestPath); - sDeviceName = String.valueOf(hTest.get("device")); sTestName = String.valueOf(hTest.get("test")); } else{ //problem, the test script does not return all the expected return values - String sErrorText = "Test "+ sTestPath+" did not return all requird return values"; + String sErrorText = "Test "+ sTestPath+" did not return all required return values"; Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, sErrorText); SwingUtils.showMessage(TestingList.this.getComponent(), "executeParallelTestsGroup()", sErrorText); System.out.println(String.valueOf(sErrorText)); + //try to fetch at least first element of returned map. If fails, it will go to catch sTestPath = String.valueOf(((List) oTestRet).get(0)); sTestStatus = sErrorText; sTestResult = "false"; @@ -1014,21 +1024,6 @@ public class TestingList extends Panel { } } - - //delete this - private void runTest(String sDeviceName, String sTestPath, HashMap mParameters) { - HashMap args = new HashMap(); - args.put("parameters", mParameters); - args.put("device", sDeviceName); - args.put("ret", ""); - args.put("status", false); - System.out.println("Parameters passed: " + String.valueOf(mParameters)); - try { - runAsync(sTestPath, args); - } catch (Controller.ControllerStateException ex) { - Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ex); - } - } /** * table management diff --git a/script/tests/tests/Collimator Tests/Motor Test 2/Motor Test 2.py b/script/tests/tests/Collimator Tests/Motor Test 2/Motor Test 2.py index 6d2e146..f8481ec 100644 --- a/script/tests/tests/Collimator Tests/Motor Test 2/Motor Test 2.py +++ b/script/tests/tests/Collimator Tests/Motor Test 2/Motor Test 2.py @@ -1,172 +1,204 @@ #Script Motor Test 2 #Go to absolute position A, then move +B steps, then -2B steps, then +2Bsteps (ie oscillate round centre position, logging after each movement); repeat N times +###### DO NOT MODIFY THE CODE BELOW ###### +def startTest(testName, DEVICE, params): + #get the path of this script + testPath = inspect.getfile(inspect.currentframe()) + #by default, failed + ret = 'Test failed' + status = False + #plot name to be given to the scan. Use: scan.setPlotName(plotName) + plotName = DEVICE + ' - ' + testName +###### WRITE YOUR CODE HERE BELOW ####### -import traceback + #get parameters from the calling interface + try: + print "Running test Motor Test 2 for device " + DEVICE + " with the following parameters:" + print params + middle = float(params["midPoint"]["value"]) + loopTimes = int(params["repeatTimes"]["value"]) + span = float(params["spanFromMidPoint"]["value"]) + except: + ret = 'Could not retrieve testing parameters - ' + traceback.format_exc() + success = False + sendFeedback(testPath, testName, DEVICE, ret, status) + return -#by default, failed -ret = 'Test failed' -status = False + #scan = ManualScan(['idX', 'idInkr'], ['idMotorStatus', 'idLogicalPosition', 'idDiameter', 'idMotorPosition', 'idPotiRaw', 'idPotiProc', 'idBtvsRaw', 'idBtvsProc', 'idDiff01', 'idDiff02'] , [-0.5, 0.0], [4.0, 3000.0], [3000, 20]) + scan = ManualScan(['idX'], ['idMotorStatus', 'idLogicalPosition', 'idDiameter', 'idMotorPosition', 'idPotiRaw', 'idPotiProc', 'idBtvsRaw', 'idBtvsProc', 'idDiff01', 'idDiff02'] , [ 0.0], [ 3000.0], [20]) + scan.setPlotName(plotName) + scan.start() + + #Creating channels: dimension 1 + try: + #RegionPositioner idInkr + #idInkr = Channel(DEVICE+':INKR:2', type = 'd') + idInkr = Channel(DEVICE+':MOTOR.VAL', type = 'd') + #ScalarDetector idMotorStatus + #idMotorStatus = Channel(DEVICE+':STA:1', type = 'd') + idMotorStatus = Channel(DEVICE+':MOTOR.MSTA', type = 'd') + #ScalarDetector idLogicalPosition + #idLogicalPosition = Channel(DEVICE+':IST:2', type = 'd') + idLogicalPosition = Channel(DEVICE+':MOTOR.RVAL', type = 'd') + #ScalarDetector idDiameter + #idDiameter = Channel(DEVICE+':DIAM:2', type = 'd') + idDiameter = Channel(DEVICE+':ENCODERoff', type = 'd') + #ScalarDetector idMotorPosition + #idMotorPosition = Channel(DEVICE+':IST1:2', type = 'd') + idMotorPosition = Channel(DEVICE+':MOTOR.RBV', type = 'd') + #ScalarDetector idPotiRaw + #idPotiRaw = Channel(DEVICE+':POSA:1', type = 'd') + idPotiRaw = Channel(DEVICE+':ENCODERraw', type = 'd') + #ScalarDetector idPotiProc + #idPotiProc = Channel(DEVICE+':POSA:2', type = 'd') + idPotiProc = Channel(DEVICE+':ENCODER', type = 'd') + #ScalarDetector idBtvsRaw + #idBtvsRaw = Channel(DEVICE+':IST3:1', type = 'd') + idBtvsRaw = Channel(DEVICE+':MOTOR.LLS', type = 'd') + #ScalarDetector idBtvsProc + #idBtvsProc = Channel(DEVICE+':IST3:2', type = 'd') + idBtvsProc = Channel(DEVICE+':MOTOR.HLS', type = 'd') + #ScalarDetector idEndSwitchL + #idBtvsRaw = Channel(DEVICE+':IST3:1', type = 'd') + idEndSwitchL = Channel(DEVICE+':MOTOR.LLS', type = 'd') + #ScalarDetector idEndSwitchH + #idBtvsProc = Channel(DEVICE+':IST3:2', type = 'd') + idEndSwitchH = Channel(DEVICE+':MOTOR.HLS', type = 'd') + #high position limit + idLimitH = Channel(DEVICE+':MOTOR.HLM', type = 'd') + #low position limit + idLimitL = Channel(DEVICE+':MOTOR.LLM', type = 'd') + except: + ret = 'Unable to create channel - ' + traceback.format_exc() + success = False + sendFeedback(testPath, testName, DEVICE, ret, status) + return + + + #remove limits + idLimitH.put(999999.9, timeout=None) + idLimitL.put(-999999.9, timeout=None) + + direction = 1.0 + startDefault = middle - span + endDefault = middle + span + end = endDefault+1 + #find position: it will be the middle point of the test + print 'Moving to middle point ' + str(middle) + idInkr.put(middle, timeout=None) # TODO: Set appropriate timeout + readback2 = idInkr.get() + if abs(readback2 - middle) > 1 : # TODO: Check accuracy + ret = 'Actor idInkr could not be set to the value ' + str(middle) + ' (current value: ' + str(readback2) + ')' + success = False + sendFeedback(testPath, testName, DEVICE, ret, status) + return + start = readback2+direction + countSteps = 0 + count = 0 + print 'Moving arond middle point (+-' + str(span) + ')' + for setpoint1 in range(0, loopTimes*2): + count = count + 1 + sleep( 2 ) # Settling time + #RegionPositioner idInkr + for setpoint2 in frange(start, end, direction): + readback1 = setpoint1 + idInkr.put(setpoint2, timeout=None) # TODO: Set appropriate timeout + sleep( 0.2 ) # Settling time + readback2 = idInkr.get() + if abs(readback2 - setpoint2) > 1 : # TODO: Check accuracy + ret = 'Actor idInkr could not be set to the value ' + str(setpoint2) + ' (current value: ' + str(readback2) + ')' + success = False + sendFeedback(testPath, testName, DEVICE, ret, status) + return + #Detector idMotorStatus + detector1 = idMotorStatus.get() + #Detector idLogicalPosition + detector2 = idLogicalPosition.get() + #Detector idDiameter + detector3 = idDiameter.get() + #Detector idMotorPosition + detector4 = idMotorPosition.get() + #Detector idPotiRaw + detector5 = idPotiRaw.get() + #Detector idPotiProc + detector6 = idPotiProc.get() + #Detector idBtvsRaw + detector7 = idBtvsRaw.get() + #Detector idBtvsProc + detector8 = idBtvsProc.get() + #end switches + endH = idEndSwitchH.get() + endL = idEndSwitchL.get() + #Manipulation idDiff02 + #Variable Mappings + a = detector4 + b = detector8 + idDiff02 = a-b + #Manipulation idDiff01 + #Variable Mappings + a = detector4 + b = detector6 + idDiff01 = a-b + countSteps = countSteps + 1 + scan.append ([countSteps], [countSteps], [detector1, detector2, detector3, detector4, detector5, detector6, detector7, detector8, idDiff02, idDiff01]) + if endH>0.0 or (direction > 0.0 and setpoint2 >= end -1): + #invert direction and swap start with end of translation + end = startDefault-1 + start = setpoint2 - direction + direction = -1.0 + print 'End of span (' + str(setpoint2) + '), changing direction to ' + str(direction) + break + if endL>0.0 or ( direction < 0.0 and setpoint2 <= end +1): + #invert direction and swap start with end of translation + end = endDefault+1 + start = setpoint2 - direction + direction = 1.0 + print 'End of span (' + str(setpoint2) + '), changing direction to ' + str(direction) + break + + #set limits back + idLimitH.put(145.0, timeout=None) + idLimitL.put(0.0, timeout=None) + + #Closing channels + idInkr.close() + idMotorStatus.close() + idLogicalPosition.close() + idDiameter.close() + idMotorPosition.close() + idPotiRaw.close() + idPotiProc.close() + idBtvsRaw.close() + idBtvsProc.close() + + scan.end() + ret = 'Slide moved back and forth (' + str(count) + ' runs)' + status = True + +########## END OF YOUR CODE ########### + +###### DO NOT MODIFY THE CODE BELOW ###### + sendFeedback(testPath, testName, DEVICE, ret, status) + +#prepare and send feedback to calling tool +def sendFeedback(testPath, testName, DEVICE, returnString, testPassed): + print 'End of test. Result:' + print 'Test path: ' + testPath + print 'Test name: ' + testName + print 'Device: ' + DEVICE + print 'Test passed: ' + str(testPassed) + print 'Return string: ' + returnString + ret = [testPath, DEVICE, returnString, testPassed] + set_return(ret) + +import sys, inspect, os, traceback +#get test arguments DEVICE = device +testName = test params = parameters -#DEVICE = 'PO2DV-NCS-LS' - -#get parameters from the calling interface -try: - print "Running test Motor Test 2 with the following parameters:" - print params - middle = float(params["midPoint"]["value"]) - loopTimes = int(params["repeatTimes"]["value"]) - span = float(params["spanFromMidPoint"]["value"]) -except: - print "Could not retrieve testing parameters: ", sys.exc_info()[0] - ret = 'Could not retrieve testing parameters - ' + traceback.format_exc() - success = False - raise Exception('Could not retrieve testing parameters - ' + traceback.format_exc()) - -#scan = ManualScan(['idX', 'idInkr'], ['idMotorStatus', 'idLogicalPosition', 'idDiameter', 'idMotorPosition', 'idPotiRaw', 'idPotiProc', 'idBtvsRaw', 'idBtvsProc', 'idDiff01', 'idDiff02'] , [-0.5, 0.0], [4.0, 3000.0], [3000, 20]) -scan = ManualScan(['idX'], ['idMotorStatus', 'idLogicalPosition', 'idDiameter', 'idMotorPosition', 'idPotiRaw', 'idPotiProc', 'idBtvsRaw', 'idBtvsProc', 'idDiff01', 'idDiff02'] , [ 0.0], [ 3000.0], [20]) -scan.start() - -#Creating channels: dimension 1 -try: - #RegionPositioner idInkr - #idInkr = Channel(DEVICE+':INKR:2', type = 'd') - idInkr = Channel(DEVICE+':MOTOR.VAL', type = 'd') - #ScalarDetector idMotorStatus - #idMotorStatus = Channel(DEVICE+':STA:1', type = 'd') - idMotorStatus = Channel(DEVICE+':MOTOR.MSTA', type = 'd') - #ScalarDetector idLogicalPosition - #idLogicalPosition = Channel(DEVICE+':IST:2', type = 'd') - idLogicalPosition = Channel(DEVICE+':MOTOR.RVAL', type = 'd') - #ScalarDetector idDiameter - #idDiameter = Channel(DEVICE+':DIAM:2', type = 'd') - idDiameter = Channel(DEVICE+':ENCODERoff', type = 'd') - #ScalarDetector idMotorPosition - #idMotorPosition = Channel(DEVICE+':IST1:2', type = 'd') - idMotorPosition = Channel(DEVICE+':MOTOR.RBV', type = 'd') - #ScalarDetector idPotiRaw - #idPotiRaw = Channel(DEVICE+':POSA:1', type = 'd') - idPotiRaw = Channel(DEVICE+':ENCODERraw', type = 'd') - #ScalarDetector idPotiProc - #idPotiProc = Channel(DEVICE+':POSA:2', type = 'd') - idPotiProc = Channel(DEVICE+':ENCODER', type = 'd') - #ScalarDetector idBtvsRaw - #idBtvsRaw = Channel(DEVICE+':IST3:1', type = 'd') - idBtvsRaw = Channel(DEVICE+':MOTOR.LLS', type = 'd') - #ScalarDetector idBtvsProc - #idBtvsProc = Channel(DEVICE+':IST3:2', type = 'd') - idBtvsProc = Channel(DEVICE+':MOTOR.HLS', type = 'd') - #ScalarDetector idEndSwitchL - #idBtvsRaw = Channel(DEVICE+':IST3:1', type = 'd') - idEndSwitchL = Channel(DEVICE+':MOTOR.LLS', type = 'd') - #ScalarDetector idEndSwitchH - #idBtvsProc = Channel(DEVICE+':IST3:2', type = 'd') - idEndSwitchH = Channel(DEVICE+':MOTOR.HLS', type = 'd') - #high position limit - idLimitH = Channel(DEVICE+':MOTOR.HLM', type = 'd') - #low position limit - idLimitL = Channel(DEVICE+':MOTOR.LLM', type = 'd') -except: - print "Unable to create channel:", sys.exc_info()[0] - ret = 'Unable to create channel - ' + traceback.format_exc() - success = False - raise Exception('Unable to create channel - ' + traceback.format_exc()) - - -#remove limits -idLimitH.put(999999.9, timeout=None) -idLimitL.put(-999999.9, timeout=None) - -direction = 1.0 -startDefault = middle - span -endDefault = middle + span -end = endDefault+1 -#find position: it will be the middle point of the test -print 'Moving to middle point ' + str(middle) -idInkr.put(middle, timeout=None) # TODO: Set appropriate timeout -start = idInkr.get()+direction -countSteps = 0 -count = 0 -print 'Moving arond middle point (+-' + str(span) + ')' -for setpoint1 in range(0, loopTimes*2): - count = count + 1 - sleep( 2 ) # Settling time - #RegionPositioner idInkr - for setpoint2 in frange(start, end, direction): - readback1 = setpoint1 - idInkr.put(setpoint2, timeout=None) # TODO: Set appropriate timeout - sleep( 0.2 ) # Settling time - readback2 = idInkr.get() - if abs(readback2 - setpoint2) > 1 : # TODO: Check accuracy - ret = 'Actor idInkr could not be set to the value ' + str(setpoint2) + ' (current value: ' + str(readback2) + ')' - success = False - raise Exception(ret) - #Detector idMotorStatus - detector1 = idMotorStatus.get() - #Detector idLogicalPosition - detector2 = idLogicalPosition.get() - #Detector idDiameter - detector3 = idDiameter.get() - #Detector idMotorPosition - detector4 = idMotorPosition.get() - #Detector idPotiRaw - detector5 = idPotiRaw.get() - #Detector idPotiProc - detector6 = idPotiProc.get() - #Detector idBtvsRaw - detector7 = idBtvsRaw.get() - #Detector idBtvsProc - detector8 = idBtvsProc.get() - #end switches - endH = idEndSwitchH.get() - endL = idEndSwitchL.get() - #Manipulation idDiff02 - #Variable Mappings - a = detector4 - b = detector8 - idDiff02 = a-b - #Manipulation idDiff01 - #Variable Mappings - a = detector4 - b = detector6 - idDiff01 = a-b - countSteps = countSteps + 1 - scan.append ([countSteps], [countSteps], [detector1, detector2, detector3, detector4, detector5, detector6, detector7, detector8, idDiff02, idDiff01]) - if endH>0.0 or (direction > 0.0 and setpoint2 >= end -1): - #invert direction and swap start with end of translation - end = startDefault-1 - start = setpoint2 - direction - direction = -1.0 - print 'End of span (' + str(setpoint2) + '), changing direction to ' + str(direction) - break - if endL>0.0 or ( direction < 0.0 and setpoint2 <= end +1): - #invert direction and swap start with end of translation - end = endDefault+1 - start = setpoint2 - direction - direction = 1.0 - print 'End of span (' + str(setpoint2) + '), changing direction to ' + str(direction) - break - -#set limits back -idLimitH.put(145.0, timeout=None) -idLimitL.put(0.0, timeout=None) - -#Closing channels -idInkr.close() -idMotorStatus.close() -idLogicalPosition.close() -idDiameter.close() -idMotorPosition.close() -idPotiRaw.close() -idPotiProc.close() -idBtvsRaw.close() -idBtvsProc.close() - -scan.end() -ret = 'Slide moved back and forth (' + str(count) + ' runs)' -status = True -set_return(24) +#launch the test +startTest(testName, DEVICE, params) diff --git a/script/tests/tests/PS Tests/power-supply-A/power-supply-A.py b/script/tests/tests/PS Tests/power-supply-A/power-supply-A.py index 1035449..f6408d7 100644 --- a/script/tests/tests/PS Tests/power-supply-A/power-supply-A.py +++ b/script/tests/tests/PS Tests/power-supply-A/power-supply-A.py @@ -1,11 +1,20 @@ -#TODO: Set the diplay names of positioners and detectors -#ManualScan(writables, readables, start = None, end = None, steps = None, relative = False) -#by default, failed - -def test(testPath, DEVICE, params): +###### DO NOT MODIFY THE CODE BELOW ###### +def startTest(testName, DEVICE, params): + #get the path of this script + testPath = inspect.getfile(inspect.currentframe()) + #by default, failed + ret = 'Test failed' + status = False + #plot name to be given to the scan. Use: scan.setPlotName(plotName) + plotName = DEVICE + ' - ' + testName +###### WRITE YOUR CODE HERE BELOW ####### + print 'testpath A: ' + testPath + print 'parameters:' + print params + print 'device: ' + DEVICE scan = ManualScan(['time'], ['SetV', 'ActualV', 'ActualI'] , [0.0], [30.0], [20]) - scan.setPlotName("A") + scan.setPlotName(plotName) scan.start() try: @@ -24,8 +33,9 @@ def test(testPath, DEVICE, params): ActualI = Channel(DEVICE + ':Actual-IA', type = 'd') #ActualI = Channel('pw84:ai', type = 'd') except: - sendFeedback( 'Unable to create channel - ' + traceback.format_exc(), False) - #raise Exception('Unable to create channel - ' + traceback.format_exc()) + sendFeedback(testPath, DEVICE, 'Unable to create channel - ' + traceback.format_exc(), False) + #raise Exception('Unable to create channel - ' + traceback.format_exc()) + return #Init SetRamp.put(10.0, timeout=None) @@ -43,7 +53,7 @@ def test(testPath, DEVICE, params): #Dimension 1 #LinearPositioner SetV - print 'Ramping up power supply' + print 'Ramping up power supply A' for setpoint1 in frange(0.0, 20.0, 5.0, True): if setpoint1 > 50.0 or setpoint1 < 0.0: break @@ -65,11 +75,9 @@ def test(testPath, DEVICE, params): #append(setpoints, positions, values) scan.append ([detector1], [detector1], [readback1, detector2, detector3]) sleep( 0.1 ) # Settling time - ret = 'Test completed' + ret = 'Test ps A completed' status = True - print 'Ramping test done' - #reset output to 0V SetV.put(0.0, timeout=None) #Closing channels @@ -78,30 +86,31 @@ def test(testPath, DEVICE, params): ActualI.close() scan.end() - - sendFeedback( 'Ramping A test done', True) +########## END OF YOUR CODE ########### - #ret = [testPath, True, 'Ramping A test done'] - #print 'testpath A: ' + testPath - #set_return(ret) - -def sendFeedback(returnString, testPassed): - ret = [testPath, testPassed, returnString] - print 'testpath A: ', testPath, returnString +###### DO NOT MODIFY THE CODE BELOW ###### + sendFeedback(testPath, testName, DEVICE, ret, status) + +#prepare and send feedback to calling tool +def sendFeedback(testPath, testName, DEVICE, returnString, testPassed): + print 'Test path: ' + testPath + print 'Test name: ' + testName + print 'Device: ' + DEVICE + print 'Test passed: ' + str(testPassed) + print 'Return string: ' + returnString + ret = [testPath, DEVICE, returnString, testPassed] set_return(ret) - sys.exit() + +def print_log(testName, DEVICE, text): + time.ctime() + now = time.strftime('%Y.%m.%d %H:%M:%S') + print now + ' ' + DEVICE + ' - ' + testName + ': ' + text -import sys, inspect, os -testPath = inspect.getfile(inspect.currentframe()) # script filename (usually with path) -print 'testpath A: ' + testPath -ret = 'Test failed' -status = False +import sys, inspect, os, traceback +#get test arguments DEVICE = device +testName = test params = parameters -print 'parameters:' -print params -print 'device:' -print DEVICE - -test(testPath, DEVICE, params) +#launch the test +startTest(testName, DEVICE, params) \ No newline at end of file diff --git a/script/tests/tests/PS Tests/power-supply-B/power-supply-B.py b/script/tests/tests/PS Tests/power-supply-B/power-supply-B.py index 6b67ac4..2ea72de 100644 --- a/script/tests/tests/PS Tests/power-supply-B/power-supply-B.py +++ b/script/tests/tests/PS Tests/power-supply-B/power-supply-B.py @@ -1,29 +1,41 @@ -#TODO: Set the diplay names of positioners and detectors -#ManualScan(writables, readables, start = None, end = None, steps = None, relative = False) - - - -def test(testPath, DEVICE, params): +###### DO NOT MODIFY THE CODE BELOW ###### +def startTest(testName, DEVICE, params): + #get the path of this script + testPath = inspect.getfile(inspect.currentframe()) + #by default, failed + ret = 'Test failed' + status = False + #plot name to be given to the scan. Use: scan.setPlotName(plotName) + plotName = DEVICE + ' - ' + testName +###### WRITE YOUR CODE HERE BELOW ####### + print 'testpath B: ' + testPath + print 'parameters:' + print params + print 'device: ' + DEVICE scan = ManualScan(['time'], ['SetVB', 'ActualVB', 'ActualIB'] , [0.0], [30.0], [20]) - scan.setPlotName("B") + scan.setPlotName(plotName) scan.start() #Creating channels: dimension 1 - #Ramp rate - SetRamp = Channel(DEVICE + ':Set-RampB', type = 'd') - #SetRamp = Channel('pw84:ai', type = 'd') - #LinearPositioner SetVA - SetVA = Channel(DEVICE + ':Set-VB', type = 'd') - #SetVA = Channel('pw84:ai', type = 'd') - #Timestamp time - #ScalarDetector ActualVA - ActualVA = Channel(DEVICE + ':Actual-VB', type = 'd') - #ActualVA = Channel('pw84:ai', type = 'd') - #ScalarDetector ActualIA - ActualIA = Channel(DEVICE + ':Actual-IB', type = 'd') - #ActualIA = Channel('pw84:ai', type = 'd') - + try: + #Ramp rate + SetRamp = Channel(DEVICE + ':Set-RampB', type = 'd') + #SetRamp = Channel('pw84:ai', type = 'd') + #LinearPositioner SetVA + SetVA = Channel(DEVICE + ':Set-VB', type = 'd') + #SetVA = Channel('pw84:ai', type = 'd') + #Timestamp time + #ScalarDetector ActualVA + ActualVA = Channel(DEVICE + ':Actual-VB', type = 'd') + #ActualVA = Channel('pw84:ai', type = 'd') + #ScalarDetector ActualIA + ActualIA = Channel(DEVICE + ':Actual-IB', type = 'd') + #ActualIA = Channel('pw84:ai', type = 'd') + except: + sendFeedback(testPath, DEVICE, 'Unable to create channel - ' + traceback.format_exc(), False) + #raise Exception('Unable to create channel - ' + traceback.format_exc()) + return #Init SetRamp.put(10.0, timeout=None) @@ -62,35 +74,40 @@ def test(testPath, DEVICE, params): #append(setpoints, positions, values) scan.append ([detector1], [detector1], [readback1, detector2, detector3]) sleep( 0.1 ) # Settling time - ret = 'Test completed' + ret = 'Test ps B completed' status = True - print 'Raming test done' - #reset output to 0V SetVA.put(0.0, timeout=None) #Closing channels SetVA.close() ActualVA.close() ActualIA.close() +########## END OF YOUR CODE ########### - ret = [testPath, True, 'Ramping B test done'] - print 'testpath B: ' + testPath - scan.end() +###### DO NOT MODIFY THE CODE BELOW ###### + sendFeedback(testPath, testName, DEVICE, ret, status) + +#prepare and send feedback to calling tool +def sendFeedback(testPath, testName, DEVICE, returnString, testPassed): + print_log(testName, DEVICE, 'End of test. Result:') + print_log(testName, DEVICE, 'Test path: ' + testPath) + print_log(testName, DEVICE, 'Test name: ' + testName ) + print_log(testName, DEVICE, 'Device: ' + DEVICE) + print_log(testName, DEVICE, 'Test passed: ' + str(testPassed)) + print_log(testName, DEVICE, 'Return string: ' + returnString) + ret = [testPath, DEVICE, returnString, testPassed] set_return(ret) -#by default, failed -import sys, inspect, os -testPath = inspect.getfile(inspect.currentframe()) # script filename (usually with path) -print 'testpath B: ' + testPath -ret = 'Test failed' -status = False +def print_log(testName, DEVICE, text): + time.ctime() + now = time.strftime('%Y.%m.%d %H:%M:%S') + print now + ' ' + DEVICE + ' - ' + testName + ': ' + text + +import sys, inspect, os, traceback +#get test arguments DEVICE = device +testName = test params = parameters -print 'parameters:' -print params -print 'device:' -print DEVICE - -#print os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) # script directory -test(testPath, DEVICE, params) +#launch the test +startTest(testName, DEVICE, params)