diff --git a/plugins/NewTest.java b/plugins/NewTest.java index 19cae87..5ac948c 100644 --- a/plugins/NewTest.java +++ b/plugins/NewTest.java @@ -2,12 +2,11 @@ * Copyright (c) 2015 Paul Scherrer Institute. All rights reserved. */ +import ch.psi.pshell.ui.App; +import ch.psi.pshell.ui.View; import ch.psi.utils.swing.SwingUtils; import ch.psi.utils.swing.SwingUtils.OptionResult; import ch.psi.utils.swing.SwingUtils.OptionType; -import java.awt.Color; -import java.awt.Component; -import java.awt.Desktop; import java.awt.Point; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; @@ -27,13 +26,7 @@ import java.util.HashMap; import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; -import javax.swing.ImageIcon; -import javax.swing.JDialog; -import javax.swing.JPanel; -import javax.swing.event.HyperlinkEvent; -import javax.swing.event.HyperlinkListener; import javax.swing.table.DefaultTableModel; -import org.apache.commons.io.FilenameUtils; /** * @@ -43,32 +36,44 @@ public class NewTest extends javax.swing.JPanel { /** * constants declarations */ - public static Path TESTS_DEVICES_DEFAULT_DIR = Paths.get(".", "home", "script", "tests", "devices"); - public static Path TESTS_TESTS_DEFAULT_DIR = Paths.get(".", "home", "script", "tests", "tests"); - public static Path TESTS_CONFIG_DEFAULT_DIR = Paths.get(".", "home", "script", "tests", "config"); - public static Path TEMPLATES_HELP_FILEPATH = Paths.get(".", "home", "script", "tests","templates","helpTemplate.html"); - public static Path TEMPLATES_TESTSCRIPT_FILEPATH = Paths.get(".", "home", "script", "tests","templates","testTemplate.py"); - public static Path TEMPLATES_TESTCONFIG_FILEPATH = Paths.get(".", "home", "script", "tests","templates","testTemplate.config"); - public static Path TEMPLATES_DEVICECONFIG_FILEPATH = Paths.get(".", "home", "script", "tests","templates","deviceTemplate.config"); + public static String TESTS_ROOT_DIR = Paths.get(".", "home", "script", "tests").toString(); + public static Path TESTS_DEVICES_DEFAULT_DIR = Paths.get(TESTS_ROOT_DIR, "devices"); + public static Path TESTS_TESTS_DEFAULT_DIR = Paths.get(TESTS_ROOT_DIR, "tests"); + public static Path TESTS_CONFIG_DEFAULT_DIR = Paths.get(TESTS_ROOT_DIR, "config"); + public static Path TEMPLATES_HELP_FILEPATH = Paths.get(TESTS_ROOT_DIR, "templates","helpTemplate.html"); + public static Path TEMPLATES_TESTSCRIPT_FILEPATH = Paths.get(TESTS_ROOT_DIR, "templates","testTemplate.py"); + public static Path TEMPLATES_TESTCONFIG_FILEPATH = Paths.get(TESTS_ROOT_DIR, "templates","testTemplate.config"); + public static Path TEMPLATES_DEVICECONFIG_FILEPATH = Paths.get(TESTS_ROOT_DIR, "templates","deviceTemplate.config"); public static String TESTS_CONFIG_FILENAME = ".config"; public static String TESTS_HELP_FILENAME = "help.html"; public static String ALLOWED_CHARSET1 = "[a-z A-Z 0-9 . _ \\- \\[\\] () : , < > =]*"; //les restricted set of chars public static String ALLOWED_CHARSET2 = "[a-z A-Z 0-9 . _ \\- \\[\\] ()]*"; //more restricted set of chars public static String ALLOWED_CHARSET3 = "[a-zA-Z0-9._\\-]*"; //even more restricted set of chars - public static String NEW_TYPE_DEVICE = "Device"; - public static String NEW_TYPE_TEST = "Test"; + /** + * enumeration of table column indexes + */ + public enum TypeOfNewFile { + Test, + Device; + }; /** * Creates new form TestingListDetails */ - private String sType; + private TypeOfNewFile sType; + public NewTest() { initComponents(); } public NewTest(String hDetails) { initComponents(); - sType = hDetails; + if(hDetails.equals("Device")){ + sType = TypeOfNewFile.Device; + } + else{ + sType = TypeOfNewFile.Test; + } fillComponents(sType); } @@ -305,12 +310,13 @@ public class NewTest extends javax.swing.JPanel { /** * fill table with example parameters - * @param newType the new can be NEW_TYPE_DEVICE or NEW_TYPE_TEST. + * @param newType of type TypeOfNewFile, can be device or test. */ - private void fillComponents(String newType) { + private void fillComponents(TypeOfNewFile newType) { // listener for mouse-click also on table header jTableParams.getTableHeader().addMouseListener(new MouseAdapter() { + @Override public void mouseClicked(MouseEvent evt) { if(evt.getButton() == java.awt.event.MouseEvent.BUTTON3){ jPopupMenuTable.show(jTableParams, evt.getX(), evt.getY()); @@ -318,8 +324,8 @@ public class NewTest extends javax.swing.JPanel { } }); - //adapt labels according to type (NEW_TYPE_DEVICE or NEW_TYPE_TEST) - if(newType == NEW_TYPE_DEVICE){ + //adapt labels according to type + if(newType == TypeOfNewFile.Device){ this.lblDescr.setText(newType + " "+ this.lblDescr.getText()); this.lblName.setText( newType + " "+ this.lblName.getText()); this.lblName.setToolTipText(newType + " name. Can be a PV name."); @@ -337,7 +343,7 @@ public class NewTest extends javax.swing.JPanel { File[] listOfTests = testsFolder.listFiles(); for (File listOfTest : listOfTests) { if (listOfTest.isDirectory()) { - this.jComboBoxTestSuites.addItem(listOfTest.getName().toString()); + this.jComboBoxTestSuites.addItem(listOfTest.getName()); } } } @@ -451,21 +457,31 @@ public class NewTest extends javax.swing.JPanel { "Please fill-in all compulsory fields (marked with *)"); return false; } - if(sType.equals(NEW_TYPE_TEST) && this.txtContactName.getText().isEmpty()){ + if(sType == TypeOfNewFile.Test && this.txtContactName.getText().isEmpty()){ SwingUtils.showMessage(this, "checkDataFields()", "Please write a user name in the field Contact person"); return false; } String allowedChars = ALLOWED_CHARSET2; - if (sType.equals(NEW_TYPE_DEVICE)){ + if (sType == TypeOfNewFile.Device){ allowedChars = ALLOWED_CHARSET1; } - if(!(txtTestName.getText().matches(allowedChars) && - txtTestDescription.getText().matches(ALLOWED_CHARSET1) && - jComboBoxTestSuites.getSelectedItem().toString().matches(allowedChars) + if(!(txtTestName.getText().matches(allowedChars) )){ SwingUtils.showMessage(this, "checkDataFields()", - "Please remove forbidden chars; allowed are: "+ allowedChars.replace("\\", "").replace("*", "")); + "Please remove forbidden chars from the name; allowed are: "+ allowedChars.replace("\\", "").replace("*", "")); + return false; + } + if(!(txtTestDescription.getText().matches(ALLOWED_CHARSET1) + )){ + SwingUtils.showMessage(this, "checkDataFields()", + "Please remove forbidden chars from the description; allowed are: "+ ALLOWED_CHARSET1.replace("\\", "").replace("*", "")); + return false; + } + if(!(jComboBoxTestSuites.getSelectedItem().toString().matches(allowedChars) + )){ + SwingUtils.showMessage(this, "checkDataFields()", + "Please remove forbidden chars from the tests suite name; allowed are: "+ allowedChars.replace("\\", "").replace("*", "")); return false; } if(!(txtContactName.getText().matches(ALLOWED_CHARSET3) @@ -483,14 +499,24 @@ public class NewTest extends javax.swing.JPanel { SwingUtils.showMessage(this, "checkDataFields()", "You must fill-in all the values in the parameters table"); return false; } - if(!(sParam.matches(ALLOWED_CHARSET2) && - sVal.matches(ALLOWED_CHARSET2) && - sDescr.matches(ALLOWED_CHARSET2)) + if(!(sParam.matches(ALLOWED_CHARSET3)) ){ SwingUtils.showMessage(this, "checkDataFields()", - "Please remove forbidden chars from parameters table; allowed are: "+ ALLOWED_CHARSET2.replace("\\", "").replace("*", "")); + "Please remove forbidden chars from parameters name in table; allowed are: "+ ALLOWED_CHARSET3.replace("\\", "").replace("*", "")); return false; - } + } + if(!(sVal.matches(ALLOWED_CHARSET3) ) + ){ + SwingUtils.showMessage(this, "checkDataFields()", + "Please remove forbidden chars from parameters value in table; allowed are: "+ ALLOWED_CHARSET3.replace("\\", "").replace("*", "")); + return false; + } + if(!(sDescr.matches(ALLOWED_CHARSET2)) + ){ + SwingUtils.showMessage(this, "checkDataFields()", + "Please remove forbidden chars from parameters description in table; allowed are: "+ ALLOWED_CHARSET2.replace("\\", "").replace("*", "")); + return false; + } } return true; } @@ -501,7 +527,7 @@ public class NewTest extends javax.swing.JPanel { */ public void generateTestFiles(){ HashMap hmTestParams = (HashMap) getParametersFromTable(); - if(sType.equals(NEW_TYPE_DEVICE)){ + if(sType == TypeOfNewFile.Device){ generateDeviceFiles(this.txtTestName.getText(), this.txtTestDescription.getText(), this.jComboBoxTestSuites.getSelectedItem().toString(), @@ -520,6 +546,7 @@ public class NewTest extends javax.swing.JPanel { * * @param sTestName name of the test * @param sTestDescription description of the test + * @param sContactName user name of the contact person for this test * @param sTestSuite test cases/test suite name * @param hmTestParams test parameters. For the details of the structure, see buildParametersMap */ @@ -574,7 +601,17 @@ public class NewTest extends javax.swing.JPanel { sTestDescription, sTestSuite, hmTestParams)) return; - SwingUtils.showMessage(this, "Test generated", "Test "+sTestName+" successfully generated in \n"+testDir.toString()); + //SwingUtils.showMessage(this, "Test generated", "Test "+sTestName+" successfully generated in \n"+testDir.toString()); + OptionResult res = SwingUtils.showOption(this, "Test generated", + "Test "+sTestName+" successfully generated in \n"+testDir.toString() + "\nDo you want to edit the testing script now?", + OptionType.YesNo); + if (res == OptionResult.Yes){ + try { + ((View)App.getInstance().getMainFrame()).openScript(makeTestFilePath(testDir, sTestName).toString()); + } catch (IOException ex) { + Logger.getLogger(NewTest.class.getName()).log(Level.SEVERE, null, ex); + } + } }else{ SwingUtils.showMessage(this, "generateTestFiles()", "Cannot find tests default directory " + TESTS_TESTS_DEFAULT_DIR.toString()); @@ -625,6 +662,9 @@ public class NewTest extends javax.swing.JPanel { } } + public Path makeTestFilePath(Path testDir, String sTestName){ + return Paths.get(testDir.toString(), cleanFileName(sTestName+".py")); + } /** * generate the python script that runs the test @@ -642,7 +682,7 @@ public class NewTest extends javax.swing.JPanel { String sTestSuite, HashMap hmTestParams){ boolean success = false; - Path path = Paths.get(testDir.toString(), cleanFileName(sTestName+".py")); + Path path = makeTestFilePath(testDir, sTestName); try { if(Files.exists(path)){ Files.delete(path); @@ -720,7 +760,7 @@ public class NewTest extends javax.swing.JPanel { props.load(in); in.close(); FileOutputStream out = new FileOutputStream(configFile); - if(sType.equals(NEW_TYPE_DEVICE)){ + if(sType == TypeOfNewFile.Device){ //creation of device config props.setProperty("name", sTestName); props.setProperty("description", sTestDescription); diff --git a/plugins/TestingList.form b/plugins/TestingList.form index 9863e9f..f4718b5 100644 --- a/plugins/TestingList.form +++ b/plugins/TestingList.form @@ -123,6 +123,8 @@ + + @@ -131,8 +133,6 @@ - - diff --git a/plugins/TestingList.java b/plugins/TestingList.java index adf480d..46e94a6 100644 --- a/plugins/TestingList.java +++ b/plugins/TestingList.java @@ -347,8 +347,8 @@ public class TestingList extends Panel { jMenuItemSelectNone = new javax.swing.JMenuItem(); jMenuItemSelectSelection = new javax.swing.JMenuItem(); jMenuItemDeselectSelection = new javax.swing.JMenuItem(); - jCheckBoxMenuShowSelectedTests1 = new javax.swing.JCheckBoxMenuItem(); jSeparator4 = new javax.swing.JPopupMenu.Separator(); + jCheckBoxMenuShowSelectedTests1 = new javax.swing.JCheckBoxMenuItem(); jMenuItemReload1 = new javax.swing.JMenuItem(); jScrollPane2 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); @@ -454,6 +454,7 @@ public class TestingList extends Panel { jMenuSelect.add(jMenuItemDeselectSelection); jPopupMenuTable.add(jMenuSelect); + jPopupMenuTable.add(jSeparator4); jCheckBoxMenuShowSelectedTests1.setText("Show enabled tests only"); jCheckBoxMenuShowSelectedTests1.addActionListener(new java.awt.event.ActionListener() { @@ -462,7 +463,6 @@ public class TestingList extends Panel { } }); jPopupMenuTable.add(jCheckBoxMenuShowSelectedTests1); - jPopupMenuTable.add(jSeparator4); jMenuItemReload1.setText("Reload tests"); jMenuItemReload1.addActionListener(new java.awt.event.ActionListener() { @@ -882,8 +882,8 @@ public class TestingList extends Panel { private javax.swing.JScrollPane jScrollPane2; private javax.swing.JPopupMenu.Separator jSeparator1; private javax.swing.JPopupMenu.Separator jSeparator2; - private javax.swing.JSeparator jSeparator3; - private javax.swing.JSeparator jSeparator4; + private javax.swing.JPopupMenu.Separator jSeparator3; + private javax.swing.JPopupMenu.Separator jSeparator4; private javax.swing.JTable jTable1; // End of variables declaration//GEN-END:variables // diff --git a/plugins/TestingListDetails.java b/plugins/TestingListDetails.java index 849327f..89501ce 100644 --- a/plugins/TestingListDetails.java +++ b/plugins/TestingListDetails.java @@ -286,7 +286,7 @@ public class TestingListDetails extends javax.swing.JPanel { @Override public void hyperlinkUpdate(HyperlinkEvent hle) { if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) { - System.out.println(hle.getURL()); + //System.out.println(hle.getURL()); Desktop desktop = Desktop.getDesktop(); try { desktop.browse(hle.getURL().toURI()); diff --git a/script/tests/templates/helpTemplate.html b/script/tests/templates/helpTemplate.html index 527a061..2bde863 100644 --- a/script/tests/templates/helpTemplate.html +++ b/script/tests/templates/helpTemplate.html @@ -1,9 +1,7 @@ -

Short Description

+

Description

$testDescription -

Details

-Add here the detailed description of the test, with reference to the parameters (if any).

Parameters

$testParameters

Contact

diff --git a/script/tests/templates/testTemplate.py b/script/tests/templates/testTemplate.py index 9356093..292057e 100644 --- a/script/tests/templates/testTemplate.py +++ b/script/tests/templates/testTemplate.py @@ -1,4 +1,4 @@ -#$testName +#Test name: $testName #$testDescription ###### Init - DO NOT MODIFY THE CODE BELOW ###### diff --git a/script/tests/tests/Collimator Tests pro/Calibrate/Calibrate.py b/script/tests/tests/Collimator Tests pro/Calibrate/Calibrate.py index b3b25c7..7ca2885 100644 --- a/script/tests/tests/Collimator Tests pro/Calibrate/Calibrate.py +++ b/script/tests/tests/Collimator Tests pro/Calibrate/Calibrate.py @@ -1,79 +1,118 @@ #Script imported from: Calibrate.xml +###### Init - DO NOT MODIFY THE CODE BELOW ###### +global print_log, sendFeedback, inspect, log, sys, inspect, os, traceback +import sys, inspect, os, traceback -ret = 'Calibration failed' -status = False - -try: - #Pre-actions: 1 = calibrate - caput(DEVICE+':COM:2', 1) - #Creating channels: dimension 1 - #PseudoPositioner id000000 - #ScalarDetector id000001 - id000001 = Channel(DEVICE+':STA:1', type = 'd') - #ScalarDetector id000003 - id000003 = Channel(DEVICE+':IST:2', type = 'd') - #ScalarDetector id000004 - id000004 = Channel(DEVICE+':DIAM:2', type = 'd') - #ScalarDetector id000005 - id000005 = Channel(DEVICE+':IST1:1', type = 'd') - #ScalarDetector id000006 - id000006 = Channel(DEVICE+':IST1:2', type = 'd') - #ScalarDetector id000007 - id000007 = Channel(DEVICE+':IST2:1', type = 'd') - #ScalarDetector id000008 - id000008 = Channel(DEVICE+':IST2:2', type = 'd') - #ScalarDetector id000009 - id000009 = Channel(DEVICE+':IST3:1', type = 'd') - #ScalarDetector id000010 - id000010 = Channel(DEVICE+':IST3:2', type = 'd') -except: - print "Unexpected error:", sys.exc_info()[0] - ret = 'Unable to create channel - ' + traceback.format_exc() - success = False - raise Exception('Unable to create channel - ' + traceback.format_exc()) - sys.exit() - -#TODO: Set the diplay names of positioners and detectors -scan = ManualScan(['id000000'], ['id000001', 'id000003', 'id000004', 'id000005', 'id000006', 'id000007', 'id000008', 'id000009', 'id000010'] , [0.0], [900.0], [900]) -scan.start() +def print_log(testName, DEVICE, text): + time.ctime() + now = time.strftime('%Y.%m.%d %H:%M:%S') + print now + ' ' + DEVICE + ' - ' + testName + ': ' + str(text) + log (now + ' ' + DEVICE + ' - ' + testName + ': ' + text ) -#Dimension 1 -#PseudoPositioner id000000 -for setpoint1 in range(0, 900): - readback1 = setpoint1 - sleep( 0.1 ) # Settling time - #Detector id000001 - detector1 = id000001.get() - #Detector id000003 - detector2 = id000003.get() - #Detector id000004 - detector3 = id000004.get() - #Detector id000005 - detector4 = id000005.get() - #Detector id000006 - detector5 = id000006.get() - #Detector id000007 - detector6 = id000007.get() - #Detector id000008 - detector7 = id000008.get() - #Detector id000009 - detector8 = id000009.get() - #Detector id000010 - detector9 = id000010.get() - scan.append ([setpoint1], [readback1], [detector1, detector2, detector3, detector4, detector5, detector6, detector7, detector8, detector9]) +#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, 'Device: ' + DEVICE) + print_log(testName, DEVICE, 'Test name: ' + testName) + print_log(testName, DEVICE, 'Test path: ' + testPath) + print_log(testName, DEVICE, 'Test passed: ' + str(testPassed)) + print_log(testName, DEVICE, 'Return string: ' + returnString) + ret = [testPath, DEVICE, returnString, testPassed] + set_return(ret) -#Closing channels -id000001.close() -id000003.close() -id000004.close() -id000005.close() -id000006.close() -id000007.close() -id000008.close() -id000009.close() -id000010.close() +def startTest(testName, DEVICE, params): + try: + import traceback + #get the path of this script + testPath = inspect.getfile(inspect.currentframe()) + #by default, failed + ret = 'Test failed' + success = False + #plot name to be given to the scan. Use: scan.setPlotName(plotName) + plotName = DEVICE + ' - ' + testName +######### WRITE YOUR CODE HERE BELOW ############# + scan = ManualScan(['sample'], ['Drive Status: '+DEVICE+':STA:1', 'Logical Pos: '+DEVICE+':IST:2', 'Diameter: '+DEVICE+':DIAM:2 (mm)', 'Cpc: '+DEVICE+':IST1:2 (mm)', 'Pot: '+DEVICE+':IST2:2 (mm)', 'Btvs: '+DEVICE+':IST3:2 (mm)'] , [0.0], [900.0], [900]) + scan.setPlotName(plotName) + scan.start() + + try: + #Pre-actions: 1 = calibrate + caput(DEVICE+':COM:2', 1) + #Creating channels: dimension 1 + #PseudoPositioner id000000 + #ScalarDetector id000001 + id000001 = Channel(DEVICE+':STA:1', type = 'd') + #ScalarDetector id000003 + id000003 = Channel(DEVICE+':IST:2', type = 'd') + #ScalarDetector id000004 + id000004 = Channel(DEVICE+':DIAM:2', type = 'd') + #ScalarDetector id000005 + id000005 = Channel(DEVICE+':IST1:1', type = 'd') + #ScalarDetector id000006 + id000006 = Channel(DEVICE+':IST1:2', type = 'd') + #ScalarDetector id000007 + id000007 = Channel(DEVICE+':IST2:1', type = 'd') + #ScalarDetector id000008 + id000008 = Channel(DEVICE+':IST2:2', type = 'd') + #ScalarDetector id000009 + id000009 = Channel(DEVICE+':IST3:1', type = 'd') + #ScalarDetector id000010 + id000010 = Channel(DEVICE+':IST3:2', type = 'd') + except: + ret = 'Unable to create channel - ' + traceback.format_exc() + success = False + sendFeedback(testPath, testName, DEVICE, ret, success) + return + + #Dimension 1 + #PseudoPositioner id000000 + for setpoint1 in range(0, 900): + readback1 = setpoint1 + sleep( 0.1 ) # Settling time + #Detector id000001 + detector1 = id000001.get() + #Detector id000003 + detector2 = id000003.get() + #Detector id000004 + detector3 = id000004.get() + #Detector id000005 + detector4 = id000005.get() + #Detector id000006 + detector5 = id000006.get() + #Detector id000007 + detector6 = id000007.get() + #Detector id000008 + detector7 = id000008.get() + #Detector id000009 + detector8 = id000009.get() + #Detector id000010 + detector9 = id000010.get() + scan.append ([setpoint1], [readback1], [detector1, detector2, detector3, detector5, detector7, detector9]) -scan.end() + #Closing channels + id000001.close() + id000003.close() + id000004.close() + id000005.close() + id000006.close() + id000007.close() + id000008.close() + id000009.close() + id000010.close() -ret = 'Calibration done' -status = True + scan.end() + + ret = 'Calibration done' + status = True +################ END OF YOUR CODE ################ +###### Final - DO NOT MODIFY THE CODE BELOW ###### + sendFeedback(testPath, testName, DEVICE, ret, success) + except: + ret = traceback.format_exc() + success = False + sendFeedback(testPath, testName, DEVICE, ret, success) + return + +#launch the test +startTest(test, device, parameters) + \ No newline at end of file diff --git a/script/tests/tests/Collimator Tests pro/Drive Out/Drive Out.py b/script/tests/tests/Collimator Tests pro/Drive Out/Drive Out.py index f197379..5f2dd02 100644 --- a/script/tests/tests/Collimator Tests pro/Drive Out/Drive Out.py +++ b/script/tests/tests/Collimator Tests pro/Drive Out/Drive Out.py @@ -1,82 +1,118 @@ -#Script imported from: Drive Out.xml -import traceback +###### Init - DO NOT MODIFY THE CODE BELOW ###### +global print_log, sendFeedback, inspect, log, sys, inspect, os, traceback +import sys, inspect, os, traceback -#by default, failed -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 + ': ' + str(text) + log (now + ' ' + DEVICE + ' - ' + testName + ': ' + text ) + +#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, 'Device: ' + DEVICE) + print_log(testName, DEVICE, 'Test name: ' + testName) + print_log(testName, DEVICE, 'Test path: ' + testPath) + print_log(testName, DEVICE, 'Test passed: ' + str(testPassed)) + print_log(testName, DEVICE, 'Return string: ' + returnString) + ret = [testPath, DEVICE, returnString, testPassed] + set_return(ret) -try: - #Pre-actions: 2 = drive out - caput(DEVICE+':COM:2', 2) - #Creating channels: dimension 1 - #PseudoPositioner id000000 - #ScalarDetector id000001 - id000001 = Channel(DEVICE+':STA:1', type = 'd') - #ScalarDetector id000003 - id000003 = Channel(DEVICE+':IST:2', type = 'd') - #ScalarDetector id000004 - id000004 = Channel(DEVICE+':DIAM:2', type = 'd') - #ScalarDetector id000005 - id000005 = Channel(DEVICE+':IST1:1', type = 'd') - #ScalarDetector id000006 - id000006 = Channel(DEVICE+':IST1:2', type = 'd') - #ScalarDetector id000007 - id000007 = Channel(DEVICE+':IST2:1', type = 'd') - #ScalarDetector id000008 - id000008 = Channel(DEVICE+':IST2:2', type = 'd') - #ScalarDetector id000009 - id000009 = Channel(DEVICE+':IST3:1', type = 'd') - #ScalarDetector id000010 - id000010 = Channel(DEVICE+':IST3:2', type = 'd') -except: - print "Unexpected error:", sys.exc_info()[0] - ret = 'Unable to create channel - ' + traceback.format_exc() - success = False - raise Exception('Unable to create channel - ' + traceback.format_exc()) - sys.exit() +def startTest(testName, DEVICE, params): + try: + import traceback + #get the path of this script + testPath = inspect.getfile(inspect.currentframe()) + #by default, failed + ret = 'Test failed' + success = False + #plot name to be given to the scan. Use: scan.setPlotName(plotName) + plotName = DEVICE + ' - ' + testName +######### WRITE YOUR CODE HERE BELOW ############# + scan = ManualScan(['sample'], ['Drive Status: '+DEVICE+':STA:1', 'Logical Pos: '+DEVICE+':IST:2', 'Diameter: '+DEVICE+':DIAM:2 (mm)', 'Cpc: '+DEVICE+':IST1:2 (mm)', 'Pot: '+DEVICE+'::IST2:2 (mm)', 'Btvs: '+DEVICE+':IST3:2 (mm)'] ) + scan.setPlotName(plotName); + scan.start() -#TODO: Set the diplay names of positioners and detectors -scan = ManualScan(['id000000'], ['id000001', 'id000003', 'id000004', 'id000005', 'id000006', 'id000007', 'id000008', 'id000009', 'id000010'] , [0.0], [3000.0], [3000]) -scan.start() + try: + #Pre-actions: 2 = drive out + caput(DEVICE+':COM:2', 2) + #Creating channels: dimension 1 + #PseudoPositioner id000000 + #ScalarDetector id000001 + id000001 = Channel(DEVICE+':STA:1', type = 'd') + #ScalarDetector id000003 + id000003 = Channel(DEVICE+':IST:2', type = 'd') + #ScalarDetector id000004 + id000004 = Channel(DEVICE+':DIAM:2', type = 'd') + #ScalarDetector id000005 + id000005 = Channel(DEVICE+':IST1:1', type = 'd') + #ScalarDetector id000006 + id000006 = Channel(DEVICE+':IST1:2', type = 'd') + #ScalarDetector id000007 + id000007 = Channel(DEVICE+':IST2:1', type = 'd') + #ScalarDetector id000008 + id000008 = Channel(DEVICE+':IST2:2', type = 'd') + #ScalarDetector id000009 + id000009 = Channel(DEVICE+':IST3:1', type = 'd') + #ScalarDetector id000010 + id000010 = Channel(DEVICE+':IST3:2', type = 'd') + except: + ret = 'Unable to create channel - ' + traceback.format_exc() + success = False + sendFeedback(testPath, testName, DEVICE, ret, success) + return -#Dimension 1 -#PseudoPositioner id000000 -for setpoint1 in range(0, 3000): - readback1 = setpoint1 - sleep( 0.1 ) # Settling time - #Detector id000001 - detector1 = id000001.get() - #Detector id000003 - detector2 = id000003.get() - #Detector id000004 - detector3 = id000004.get() - #Detector id000005 - detector4 = id000005.get() - #Detector id000006 - detector5 = id000006.get() - #Detector id000007 - detector6 = id000007.get() - #Detector id000008 - detector7 = id000008.get() - #Detector id000009 - detector8 = id000009.get() - #Detector id000010 - detector9 = id000010.get() - scan.append ([setpoint1], [readback1], [detector1, detector2, detector3, detector4, detector5, detector6, detector7, detector8, detector9]) -#Closing channels -id000001.close() -id000003.close() -id000004.close() -id000005.close() -id000006.close() -id000007.close() -id000008.close() -id000009.close() -id000010.close() + #Dimension 1 + #PseudoPositioner id000000 + for setpoint1 in range(0, 3000): + readback1 = setpoint1 + sleep( 0.1 ) # Settling time + #Detector id000001 + detector1 = id000001.get() + #Detector id000003 + detector2 = id000003.get() + #Detector id000004 + detector3 = id000004.get() + #Detector id000005 + detector4 = id000005.get() + #Detector id000006 + detector5 = id000006.get() + #Detector id000007 + detector6 = id000007.get() + #Detector id000008 + detector7 = id000008.get() + #Detector id000009 + detector8 = id000009.get() + #Detector id000010 + detector9 = id000010.get() + scan.append ([setpoint1], [readback1], [detector1, detector2, detector3, detector5, detector7, detector9]) -scan.end() + #Closing channels + id000001.close() + id000003.close() + id000004.close() + id000005.close() + id000006.close() + id000007.close() + id000008.close() + id000009.close() + id000010.close() -#return ok -ret = 'Slides moved out' -status = True \ No newline at end of file + scan.end() + + #return ok + ret = 'Slides moved out' + status = True +############# END OF YOUR CODE ########### +###### DO NOT MODIFY THE CODE BELOW ###### + sendFeedback(testPath, testName, DEVICE, ret, success) + except: + ret = traceback.format_exc() + success = False + sendFeedback(testPath, testName, DEVICE, ret, success) + return + +#launch the test +startTest(test, device, parameters)