This commit is contained in:
boccioli_m
2015-07-01 09:19:02 +02:00
parent 86d98e0c2f
commit edcc5cb443
4 changed files with 222 additions and 447 deletions
+48 -297
View File
@@ -442,7 +442,7 @@ public class TestingList extends Panel {
updateStatus();
executeTests();
} else {
setButtonToStop();
setToStopped();
}
}//GEN-LAST:event_jButtonRunActionPerformed
@@ -695,7 +695,7 @@ public class TestingList extends Panel {
logger.log(Level.SEVERE, "Cant find Test: " + testName + " in table.");
}
//check if there are still pending tests. If not, set the status of the tool to Stopped.
if (rowD >= jTable1.getRowCount()-1 || pendingTestsCount()==0) {
if (pendingTestsCount()==0 && runningTestsCount()==0) {
setToStopped();
}
return rowD;
@@ -815,261 +815,10 @@ public class TestingList extends Panel {
public void executeTests(){
RunTest runTest = new RunTest();
System.out.println("C");
Thread t = new Thread(runTest);
System.out.println("D");
t.start();
System.out.println("E");
}
/*
//execute the selected tests in the list, starting from the position
public void executeTest_Old(int position) {
boolean bSelected = false;
String sDeviceName;
String sTestName;
String sTestCaseName;
String sTestPath;
HashMap<String,Object> args = new HashMap<>();
HashMap mParameters = new HashMap();
//scan through the table starting from 'position' and execute the first selected test found
int row = position;
if (row >= 0 && row <= jTable1.getRowCount() - 1) {
for (row = position; row <= jTable1.getRowCount() - 1; row++) {
bSelected = (boolean) jTable1.getValueAt(row, COL.CHECK.ordinal());
if (bSelected) {
break;
}
}
if (bSelected) {
//build the .py test file path
sDeviceName = jTable1.getValueAt(row, COL.DEVICENAME.ordinal()).toString();
sTestName = jTable1.getValueAt(row, COL.TESTNAME.ordinal()).toString();
sTestCaseName = jTable1.getValueAt(row, COL.TESTSUITE.ordinal()).toString();
sTestPath = jTable1.getValueAt(row, COL.TESTPATH.ordinal()).toString();
mParameters = buildParametersMap(String.valueOf(jTable1.getValueAt(row, COL.TESTPARAMS.ordinal())));
try {
File f = new File(sTestPath);
if (!f.exists() || f.isDirectory()) {
logger.log(Level.SEVERE, "Cannot find test script: " + sTestPath);
showResult(sDeviceName, sTestPath, "Cannot find test script: " + sTestPath, TestStatus.FAILURE.toString());
executeTest(position + 1);
return;
}
showResult(sDeviceName, sTestPath, "Test running", TestStatus.RUNNING.toString());
//launch the test
args.put("DEVICE", sDeviceName);
args.put("ret", "");
args.put("status", false);
if (!mParameters.isEmpty()) {
args.put("parameters", mParameters);
logger.log(Level.INFO, "Running test '" + sTestName + "' with the following parameters: " + mParameters.toString());
} else {
logger.log(Level.INFO, "Running Test '" + sTestName + "'. No parameters found.");
}
runAsync(sTestPath, args);
} catch (Exception ex) {
SwingUtils.showMessage(this, "executeTest()", ex.toString());
logger.log(Level.SEVERE, ex.toString());
showResult(sDeviceName, sTestPath, ex.toString(), TestStatus.FAILURE.toString());
setButtonToStop();
}
}
}
if (!bSelected) { //No test to play. Stop
setToStopped();
}
t.start();
}
//execute the selected tests in the list, starting from the position
public void executeTest(int position) {
boolean bSelected = false;
String sStartSequence, sStatus;
int[] selectedTestsRows = {};
//scan through the table starting from 'position' and execute the first selected test found
int row = 0;// position;
if (row >= 0 && row < jTable1.getRowCount()) {
for (row = position; row < jTable1.getRowCount(); row++) {
bSelected = (boolean) jTable1.getValueAt(row, COL.CHECK.ordinal());
sStartSequence = jTable1.getValueAt(row, COL.STARTSEQUENCE.ordinal()).toString();
sStatus = jTable1.getValueAt(row, COL.STATUS.ordinal()).toString();
//collect tests to be launched in parallel
//the test must be: selected, set as start with previous, pending.
//alternatively, the test must be: selected, first of the list.
//System.out.println(String.valueOf(row) + "\t" + String.valueOf(bSelected) + "\t" + String.valueOf(selectedTestsRows.length) + "\t" + sStartSequence + "\t" + sStatus);
if (bSelected
&& sStatus.equals(TestStatus.PENDING.toString())
&& (selectedTestsRows.length == 0 || //the test must be: selected, pending, first of the list.
sStartSequence.equals(StartSequence.START_SEQ_TOGETHER.toString()))) { //or the test must be: selected, pending, set as start with previous
selectedTestsRows = append(selectedTestsRows, row);
} else if (bSelected
&& sStatus.equals(TestStatus.PENDING.toString()) &&//if this test must be executed...
selectedTestsRows.length > 0 && //but there are already tests to be executed in parallel....
(sStartSequence.equals(StartSequence.START_SEQ_AFTER.toString()))) { //...and this test must be executed in series, then stop searching
break;
}
}
if (selectedTestsRows.length > 0) { //at least one test is selected: launch it (or them)
if (executeParallelTestsGroup(selectedTestsRows) < 0) { //last execution did not find a test file. Continue with next execution
executeTest(position + 1);
}
}
}
}
//start all the tests in the rowsToExecute
private int executeParallelTestsGroup(int[] rowsToExecute) {
int iRet = -1;
HashMap args = new HashMap(); //this is the global map that will contain one map per test.
HashMap testArgs; //this is the map for a test.
RunTest runTest;
for (int row : rowsToExecute) {
String sDeviceName = jTable1.getValueAt(row, COL.DEVICENAME.ordinal()).toString();
String sTestName = jTable1.getValueAt(row, COL.TESTNAME.ordinal()).toString();
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));
try {
File f = new File(sTestPath);
if (!f.exists() || f.isDirectory()) {
logger.log(Level.SEVERE, "Cannot find test script: " + sTestPath);
showResult(sDeviceName, sTestPath, "Cannot find test script: " + sTestPath, TestStatus.FAILURE.toString());
iRet = -1;
continue;
}
showResult(sDeviceName, sTestPath, "Test running", TestStatus.RUNNING.toString());
//launch the test
if (!mParameters.isEmpty()) {
logger.log(Level.INFO, "Running test '" + sTestName + "' with the following parameters: " + mParameters.toString());
System.out.println("Running test '" + sTestName + "' with the following parameters: " + mParameters.toString());
} else {
logger.log(Level.INFO, "Running Test '" + sTestName + "'. No parameters found.");
System.out.println("Running test '" + sTestName + "'. No parameters found.");
}
testArgs = new HashMap();
//args.put("ret", "");
testArgs.put("parameters", mParameters);
testArgs.put("test", sTestName);
testArgs.put("device", sDeviceName);
testArgs.put("status", false);
args.put(sTestPath,testArgs);
System.out.println("A");
iRet = 0;
} catch (Exception ex) {
SwingUtils.showMessage(this, "executeTest()", ex.toString());
logger.log(Level.SEVERE, ex.toString());
showResult(sDeviceName, sTestPath, ex.toString(), TestStatus.FAILURE.toString());
setButtonToStop();
}
}
try{
runTest = new RunTest(args);
System.out.println("C");
Thread t = new Thread(runTest);
System.out.println("D");
t.start();
System.out.println("E");
} catch (Exception ex) {
SwingUtils.showMessage(this, "executeTest(), run thread", ex.toString());
logger.log(Level.SEVERE, ex.toString());
setButtonToStop();
}
return iRet;
}
*/
//delete this
/*
public class RunTest_old implements Runnable {
private String sDeviceName, sTestPath;
private HashMap mParameters;
private HashMap<String,Object> args;
private HashMap<String,HashMap> hTests;
public RunTest(String sTestPath, HashMap<String,Object> args) {
System.out.println("A1");
this.sDeviceName = args.get("device").toString();
System.out.println("A2");
this.sTestPath = sTestPath;
System.out.println("A3");
this.mParameters = (HashMap) args.get("parameters");
this.args = args;
}
public RunTest(String sTestPath) {
this.sDeviceName = sTestPath;
this.sTestPath = sTestPath;
this.mParameters.put("a", 1);
}
public RunTest(HashMap<String,HashMap> args) {
System.out.println("A0");
this.hTests = (HashMap) args;
}
public void run() {
// code in the other thread, can reference "var" variable
int iLastExecutedTestIndex = -1;
final String sParallelizeBegin = "(run,(str('";
final String sParallelizeEnd = "'),))";
try {
System.out.println("A0.1");
//runAsync(sTestPath, args);parallelize((run,('Motor Test 3 100ms'), (run,('Motor Test 3 200ms')))
// Object ret = eval("parallelize((run,('Motor Test 3 100ms',)), (run,('Motor Test 3 200ms',)))");
String sParallelizeCommand = "parallelize(";
int i = 0;
int iTotalEntries = hTests.entrySet().size();
for(Map.Entry<String, HashMap> hTest : hTests.entrySet()){
setGlobalsVars(hTest.getValue());
sTestPath = hTest.getKey().toString();
sTestPath = sTestPath.replace("\\","\\\\");
sParallelizeCommand = sParallelizeCommand + "(run,(str('" + sTestPath;
i++;
System.out.println("Parameters passed: " + String.valueOf(hTest.getValue().get("parameters")));
System.out.println("A"+i);
if (i<iTotalEntries){
sParallelizeCommand = sParallelizeCommand + "'),,locals='pio')),"; //between each "run" command
}else{
sParallelizeCommand = sParallelizeCommand + "'),)))"; //very last part of command "parallelize"
}
}
System.out.println(sParallelizeCommand);
Object ret = eval(sParallelizeCommand);
// Object ret = eval("parallelize((run,(str('"+sTestPath+"'),)), (run,('Motor Test 3 200ms',)))");
System.out.println("Ret = " + String.valueOf(ret));
//Object ret1 = ((ArrayList) ret).get(0);
//Object ret11 = ((List<PyList>) ret1).get(0);
//Object ret2 = ((ArrayList) ret).get(1);
//System.out.println(String.valueOf(ret1));
//System.out.println(String.valueOf(ret11));
String sTestResult, sTestStatus, sTestName;
//read the return mapping and put the result in the right table row
for(Object oTestRet : (ArrayList) ret){
sTestPath = String.valueOf(((List<PyList>) oTestRet).get(0));
sTestStatus = String.valueOf(((List<PyList>) oTestRet).get(1));
sTestResult = String.valueOf(((List<PyList>) oTestRet).get(2));
HashMap<String, HashMap> hTest = hTests.get(sTestPath);
sDeviceName = String.valueOf(hTest.get("device"));
sTestName = String.valueOf(hTest.get("test"));
System.out.println(sDeviceName + "|" + sTestPath + "|" + sTestResult + "|" + sTestStatus);
iLastExecutedTestIndex = showResult(sDeviceName, sTestPath, sTestResult, sTestStatus) ;
}
} catch (Exception ex) {
Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ex);
SwingUtils.showMessage(TestingList.this.getComponent(), "runTest()", ex.toString());
System.out.println(String.valueOf(ex));
}
}
}
*/
public class RunTest implements Runnable {
private String sDeviceName, sTestPath;
@@ -1096,7 +845,7 @@ public class TestingList extends Panel {
this.hTests = (HashMap) args;
}
public RunTest() {
System.out.println("A0");
//System.out.println("A0");
}
public void run() {
@@ -1135,9 +884,9 @@ public class TestingList extends Panel {
}
}
if (selectedTestsRows.length > 0) { //at least one test is selected: launch it (or them)
if (executeParallelTestsGroup(selectedTestsRows) < 0) { //last execution did not find a test file. Continue with next execution
executeParallelTestsGroup(selectedTestsRows) ; //last execution did not find a test file. Continue with next execution
executeTest(position + 1);
}
}
}
}
@@ -1161,7 +910,6 @@ public class TestingList extends Panel {
if (!f.exists() || f.isDirectory()) {
logger.log(Level.SEVERE, "Cannot find test script: " + sTestPath);
showResult(sDeviceName, sTestPath, "Cannot find test script: " + sTestPath, TestStatus.FAILURE.toString());
iRet = -1;
continue;
}
showResult(sDeviceName, sTestPath, "Test running", TestStatus.RUNNING.toString());
@@ -1180,29 +928,22 @@ public class TestingList extends Panel {
testArgs.put("device", sDeviceName);
testArgs.put("status", false);
args.put(sTestPath,testArgs);
System.out.println("A");
//System.out.println("A");
hTests = args;
iRet = 0;
} catch (Exception ex) {
SwingUtils.showMessage(TestingList.this.getComponent(), "executeTest()", ex.toString());
logger.log(Level.SEVERE, ex.toString());
showResult(sDeviceName, sTestPath, ex.toString(), TestStatus.FAILURE.toString());
setButtonToStop();
setToStopped();
}
}
try{
// runTest = new RunTest(args);
// System.out.println("C");
// Thread t = new Thread(runTest);
// System.out.println("D");
// t.start();
// System.out.println("E");
int iLastExecutedTestIndex = -1;
final String sParallelizeBegin = "(run,(str('";
final String sParallelizeEnd = "'),))";
try {
System.out.println("A0.1");
//System.out.println("A0.1");
String sParallelizeCommand = "parallelize(";
int i = 0;
int iTotalEntries = hTests.entrySet().size();
@@ -1213,9 +954,9 @@ public class TestingList extends Panel {
sParallelizeCommand = sParallelizeCommand + "(run,(str('" + sTestPath;
i++;
System.out.println("Parameters passed: " + String.valueOf(hTest.getValue().get("parameters")));
System.out.println("A"+i);
//System.out.println("A"+i);
if (i<iTotalEntries){
sParallelizeCommand = sParallelizeCommand + "'),,locals='pio')),"; //between each "run" command
sParallelizeCommand = sParallelizeCommand + "'),)),"; //between each "run" command
}else{
sParallelizeCommand = sParallelizeCommand + "'),)))"; //very last part of command "parallelize"
}
@@ -1223,46 +964,56 @@ public class TestingList extends Panel {
System.out.println(sParallelizeCommand);
Object ret = eval(sParallelizeCommand);
// Object ret = eval("parallelize((run,(str('"+sTestPath+"'),)), (run,('Motor Test 3 200ms',)))");
System.out.println("Ret = " + String.valueOf(ret));
//System.out.println("Ret = " + String.valueOf(ret));
String sTestResult, sTestStatus, sTestName;
//read the return mapping and put the result in the right table row
for(Object oTestRet : (ArrayList) ret){
sTestPath = String.valueOf(((List<PyList>) oTestRet).get(0));
sTestStatus = String.valueOf(((List<PyList>) oTestRet).get(1));
sTestResult = String.valueOf(((List<PyList>) oTestRet).get(2));
HashMap<String, HashMap> hTest = hTests.get(sTestPath);
sDeviceName = String.valueOf(hTest.get("device"));
sTestName = String.valueOf(hTest.get("test"));
System.out.println("ret type "+ret.getClass().toString() );
for(Object oTestRet : (ArrayList) ret){
if(oTestRet.getClass().toString() == "org.python.core.PyList" && ((List<PyList>) oTestRet).size()>=3){
sTestPath = String.valueOf(((List<PyList>) oTestRet).get(0));
sTestStatus = String.valueOf(((List<PyList>) oTestRet).get(1));
sTestResult = String.valueOf(((List<PyList>) oTestRet).get(2));
HashMap<String, 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";
Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, sErrorText);
SwingUtils.showMessage(TestingList.this.getComponent(), "executeParallelTestsGroup()", sErrorText);
System.out.println(String.valueOf(sErrorText));
sTestPath = String.valueOf(((List<PyList>) oTestRet).get(0));
sTestStatus = sErrorText;
sTestResult = "false";
HashMap<String, HashMap> hTest = hTests.get(sTestPath);
sDeviceName = String.valueOf(hTest.get("device"));
sTestName = String.valueOf(hTest.get("test"));
}
System.out.println(sDeviceName + "|" + sTestPath + "|" + sTestResult + "|" + sTestStatus);
iLastExecutedTestIndex = showResult(sDeviceName, sTestPath, sTestResult, sTestStatus) ;
iLastExecutedTestIndex = showResult(sDeviceName, sTestPath, sTestResult, sTestStatus) ;
}
} catch (ClassCastException ccex) {
Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ccex);
SwingUtils.showMessage(TestingList.this.getComponent(), "executeParallelTestsGroup()", ccex.toString());
//System.out.println(String.valueOf(ccex));
if(!sDeviceName.isEmpty())
showResult(sDeviceName, sTestPath, ccex.toString(), TestStatus.FAILURE.toString());
} catch (Exception ex) {
Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ex);
SwingUtils.showMessage(TestingList.this.getComponent(), "runTest()", ex.toString());
SwingUtils.showMessage(TestingList.this.getComponent(), "executeParallelTestsGroup()", ex.toString());
System.out.println(String.valueOf(ex));
setButtonToStop();
showResult(sDeviceName, sTestPath, ex.toString(), TestStatus.FAILURE.toString());
}
} catch (Exception ex) {
SwingUtils.showMessage(TestingList.this.getComponent(), "executeTest(), run thread", ex.toString());
SwingUtils.showMessage(TestingList.this.getComponent(), "executeParallelTestsGroup(), run thread", ex.toString());
logger.log(Level.SEVERE, ex.toString());
setButtonToStop();
}
setToStopped();
}
return iRet;
}
}
}
}
//delete this
private void runTest(String sDeviceName, String sTestPath, HashMap mParameters) {
@@ -4,4 +4,4 @@ description=Go to absolute position A, then move +B steps, then -2B steps, then
#optional parameters. Description is compulsory. Syntax:
#parameters=<parameter1Name>:<parameter1Value>:<Parameter 1 description>[;<parameter2Name>:<parameter2Value>:<Parameter 2 description>]
parameters=repeatTimes:1:Repeat N times;midPoint:41.0:Middle point A;spanFromMidPoint:5.0:B steps around middle point A
parameters=repeatTimes:1:Repeat N times;midPoint:41.0:Middle point A;spanFromMidPoint:2.0:B steps around middle point A
@@ -2,8 +2,98 @@
#ManualScan(writables, readables, start = None, end = None, steps = None, relative = False)
#by default, failed
def test(testPath, DEVICE, params):
scan = ManualScan(['time'], ['SetV', 'ActualV', 'ActualI'] , [0.0], [30.0], [20])
scan.setPlotName("A")
scan.start()
try:
#Creating channels: dimension 1
#Ramp rate
SetRamp = Channel(DEVICE + ':Set-RampA', type = 'd')
#SetRamp = Channel('pw84:ai', type = 'd')
#LinearPositioner SetV
SetV = Channel(DEVICE + ':Set-VA', type = 'd')
#SetV = Channel('pw84:ai', type = 'd')
#Timestamp time
#ScalarDetector ActualV
ActualV = Channel(DEVICE + ':Actual-VA', type = 'd')
#ActualV = Channel('pw84:ai', type = 'd')
#ScalarDetector ActualI
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())
#Init
SetRamp.put(10.0, timeout=None)
#set voltage to 0
print 'Ramping down power supply A to 0V'
SetV.put(0.0, timeout=None)
#wait up to 2 minutes for voltage to be ~0
for setpoint1 in frange(0.0, 120.0, 1.0, True):
detector2 = ActualV.get()
if detector2 <= 1.0:
break
sleep(0.5)
#Dimension 1
#LinearPositioner SetV
print 'Ramping up power supply'
for setpoint1 in frange(0.0, 20.0, 5.0, True):
if setpoint1 > 50.0 or setpoint1 < 0.0:
break
SetV.put(setpoint1, timeout=None) # TODO: Set appropriate timeout
readback1 = SetV.get()
if abs(readback1 - setpoint1) > 0.9 : # TODO: Check accuracy
raise Exception('SetV could not be set to the value ' + str(setpoint1))
ret = 'SetV could not be set to the value ' + str(setpoint1) + '(measured value: '+str(readback1)+')'
status = False
break
#scan quickly the output during some seconds
for setpoint2 in range(0, 20):
#Detector time
detector1 = float(java.lang.System.currentTimeMillis())
#Detector ActualV
detector2 = ActualV.get()
detector3 = ActualI.get()
#scan.append ([setpoint1], [readback1], [detector1, detector2])
#append(setpoints, positions, values)
scan.append ([detector1], [detector1], [readback1, detector2, detector3])
sleep( 0.1 ) # Settling time
ret = 'Test completed'
status = True
print 'Ramping test done'
#reset output to 0V
SetV.put(0.0, timeout=None)
#Closing channels
SetV.close()
ActualV.close()
ActualI.close()
scan.end()
sendFeedback( 'Ramping A test done', True)
#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
set_return(ret)
sys.exit()
import sys, inspect, os
testPath = inspect.getfile(inspect.currentframe()) # script filename (usually with path)
print 'testpath A: ' + testPath
ret = 'Test failed'
status = False
DEVICE = device
@@ -13,77 +103,5 @@ print params
print 'device:'
print DEVICE
scan = ManualScan(['time'], ['SetV', 'ActualV', 'ActualI'] , [0.0], [30.0], [20])
scan.setPlotName("A")
scan.start()
#Creating channels: dimension 1
#Ramp rate
SetRamp = Channel(DEVICE + ':Set-RampA', type = 'd')
#SetRamp = Channel('pw84:ai', type = 'd')
#LinearPositioner SetV
SetV = Channel(DEVICE + ':Set-VA', type = 'd')
#SetV = Channel('pw84:ai', type = 'd')
#Timestamp time
#ScalarDetector ActualV
ActualV = Channel(DEVICE + ':Actual-VA', type = 'd')
#ActualV = Channel('pw84:ai', type = 'd')
#ScalarDetector ActualI
ActualI = Channel(DEVICE + ':Actual-IA', type = 'd')
#ActualI = Channel('pw84:ai', type = 'd')
#Init
SetRamp.put(10.0, timeout=None)
#set voltage to 0
print 'Ramping down power supply A to 0V'
SetV.put(0.0, timeout=None)
#wait up to 2 minutes for voltage to be ~0
for setpoint1 in frange(0.0, 120.0, 1.0, True):
detector2 = ActualV.get()
if detector2 <= 1.0:
break
sleep(0.5)
#Dimension 1
#LinearPositioner SetV
print 'Ramping up power supply'
for setpoint1 in frange(0.0, 20.0, 5.0, True):
if setpoint1 > 50.0 or setpoint1 < 0.0:
break
SetV.put(setpoint1, timeout=None) # TODO: Set appropriate timeout
readback1 = SetV.get()
if abs(readback1 - setpoint1) > 0.9 : # TODO: Check accuracy
raise Exception('SetV could not be set to the value ' + str(setpoint1))
ret = 'SetV could not be set to the value ' + str(setpoint1) + '(measured value: '+str(readback1)+')'
status = False
break
#scan quickly the output during some seconds
for setpoint2 in range(0, 20):
#Detector time
detector1 = float(java.lang.System.currentTimeMillis())
#Detector ActualV
detector2 = ActualV.get()
detector3 = ActualI.get()
#scan.append ([setpoint1], [readback1], [detector1, detector2])
#append(setpoints, positions, values)
scan.append ([detector1], [detector1], [readback1, detector2, detector3])
sleep( 0.1 ) # Settling time
ret = 'Test completed'
status = True
print 'Ramping test done'
#reset output to 0V
SetV.put(0.0, timeout=None)
#Closing channels
SetV.close()
ActualV.close()
ActualI.close()
scan.end()
ret = [testPath, True, 'Ramping A test done']
set_return(ret)
test(testPath, DEVICE, params)
@@ -1,9 +1,88 @@
#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):
scan = ManualScan(['time'], ['SetVB', 'ActualVB', 'ActualIB'] , [0.0], [30.0], [20])
scan.setPlotName("B")
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')
#Init
SetRamp.put(10.0, timeout=None)
#set voltage to 0
print 'Ramping down power supply B to 0V'
SetVA.put(0.0, timeout=None)
#wait up to 2 minutes for voltage to be ~0
for setpoint1 in frange(0.0, 120.0, 1.0, True):
detector2 = ActualVA.get()
if detector2 <= 1.0:
break
sleep(0.5)
#Dimension 1
#LinearPositioner SetVA
print 'Ramping up power supply'
for setpoint1 in frange(0.0, 20.0, 5.0, True):
if setpoint1 > 50.0 or setpoint1 < 0.0:
break
SetVA.put(setpoint1, timeout=None) # TODO: Set appropriate timeout
readback1 = SetVA.get()
if abs(readback1 - setpoint1) > 0.9 : # TODO: Check accuracy
raise Exception('SetVB could not be set to the value ' + str(setpoint1))
ret = 'SetVB could not be set to the value ' + str(setpoint1) + '(measured value: '+str(readback1)+')'
status = False
break
#scan quickly the output during some seconds
for setpoint2 in range(0, 20):
#Detector time
detector1 = float(java.lang.System.currentTimeMillis())
#Detector ActualVA
detector2 = ActualVA.get()
detector3 = ActualIA.get()
#scan.append ([setpoint1], [readback1], [detector1, detector2])
#append(setpoints, positions, values)
scan.append ([detector1], [detector1], [readback1, detector2, detector3])
sleep( 0.1 ) # Settling time
ret = 'Test 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()
ret = [testPath, True, 'Ramping B test done']
print 'testpath B: ' + testPath
scan.end()
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
DEVICE = device
@@ -11,80 +90,7 @@ params = parameters
print 'parameters:'
print params
print 'device:'
print DEVICE
print DEVICE
#print os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) # script directory
scan = ManualScan(['time'], ['SetVB', 'ActualVB', 'ActualIB'] , [0.0], [30.0], [20])
scan.setPlotName("B")
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')
#Init
SetRamp.put(10.0, timeout=None)
#set voltage to 0
print 'Ramping down power supply B to 0V'
SetVA.put(0.0, timeout=None)
#wait up to 2 minutes for voltage to be ~0
for setpoint1 in frange(0.0, 120.0, 1.0, True):
detector2 = ActualVA.get()
if detector2 <= 1.0:
break
sleep(0.5)
#Dimension 1
#LinearPositioner SetVA
print 'Ramping up power supply'
for setpoint1 in frange(0.0, 20.0, 5.0, True):
if setpoint1 > 50.0 or setpoint1 < 0.0:
break
SetVA.put(setpoint1, timeout=None) # TODO: Set appropriate timeout
readback1 = SetVA.get()
if abs(readback1 - setpoint1) > 0.9 : # TODO: Check accuracy
raise Exception('SetVB could not be set to the value ' + str(setpoint1))
ret = 'SetVB could not be set to the value ' + str(setpoint1) + '(measured value: '+str(readback1)+')'
status = False
break
#scan quickly the output during some seconds
for setpoint2 in range(0, 20):
#Detector time
detector1 = float(java.lang.System.currentTimeMillis())
#Detector ActualVA
detector2 = ActualVA.get()
detector3 = ActualIA.get()
#scan.append ([setpoint1], [readback1], [detector1, detector2])
#append(setpoints, positions, values)
scan.append ([detector1], [detector1], [readback1, detector2, detector3])
sleep( 0.1 ) # Settling time
ret = 'Test 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()
ret = [testPath, True, 'Ramping B test done']
scan.end()
set_return(ret)
test(testPath, DEVICE, params)