Closedown

This commit is contained in:
x07maop
2015-08-25 10:12:27 +02:00
parent 535685c3fe
commit 5adc24f116
5 changed files with 133 additions and 145 deletions

View File

@@ -14,7 +14,6 @@ import javax.swing.JLabel;
import ch.psi.utils.State;
import ch.psi.utils.swing.DsvEditor;
import ch.psi.utils.swing.Editor.EditorDialog;
import ch.psi.pshell.core.Controller.ControllerStateException;
import ch.psi.pshell.data.PlotDescriptor;
import ch.psi.pshell.device.Device;
import ch.psi.pshell.device.DeviceAdapter;
@@ -46,18 +45,19 @@ public class EnergyScan extends Panel {
ChannelInteger count;
double[] offsets = new double[4];
/*
//Overridable callbacks
@Override
public void onStart() {
super.onStart();
loadConfig();
}
*/
/*
//Overridable callbacks
@Override
public void onStart() {
super.onStart();
loadConfig();
}
*/
@Override
public void onInitialize(int runCount) {
super.onInitialize(runCount);
loadConfig();
count = (ChannelInteger) getController().getDevicePool().getByName("count");
@@ -81,35 +81,8 @@ public class EnergyScan extends Panel {
setEnabled(state == State.Ready);
}
long scanStartTimestamp;
@Override
public void onExecutedFile(String fileName, Object result) {
try {
switch (fileName) {
case "EnergyScan":
if (result instanceof Exception) {
batchIndex = 0;
batch = null;
stopScan();
throw ((Exception) result);
}
if (batch != null) {
batchIndex++;
if (batchIndex >= batch.length) {
batchIndex = 0;
batch = null;
} else {
setMode(batch[batchIndex]);
run();
}
}
break;
}
} catch (Exception ex) {
getLogger().log(Level.WARNING, null, ex);
showException(ex);
}
}
@Override
@@ -117,8 +90,13 @@ public class EnergyScan extends Panel {
plot();
}
void stopScan() throws Exception {
evalAsync("caput('START', 'STOP')");
void stopScan() {
try{
getLogger().info("Stopping scan");
evalAsync("caput('START', 'STOP')");
} catch (Exception ex){
getLogger().log(Level.WARNING, null, ex);
}
}
Path getConfigFile() {
@@ -276,10 +254,10 @@ public class EnergyScan extends Panel {
for (String line : Files.readAllLines(getConfigFile())) {
if ((line != null) && (!line.trim().isEmpty())) {
String[] tokens = line.split("=");
if (tokens.length <2) {
if (tokens.length < 2) {
throw new Exception("Invalid file format");
}
if (tokens[0].equals(selection)){
if (tokens[0].equals(selection)) {
tokens = tokens[1].trim().split(";");
if (tokens.length != 8) {
throw new Exception("Invalid file format");
@@ -294,9 +272,9 @@ public class EnergyScan extends Panel {
offsets[2] = Double.valueOf(tokens[6].trim());
offsets[3] = Double.valueOf(tokens[7].trim());
break;
}
}
}
}
}
}
void setRunType() throws Exception {
@@ -331,7 +309,7 @@ public class EnergyScan extends Panel {
checkParameterControls();
}
void run() throws ControllerStateException {
void run() throws Exception {
HashMap args = new HashMap();
Double e1 = (Double) spinnerE1.getValue();
Double e2 = (Double) spinnerE2.getValue();
@@ -347,13 +325,29 @@ public class EnergyScan extends Panel {
args.put("FILE", file);
String folder = expandPath("{year}_{month}/{date}");
args.put("FOLDER", folder);
scanStartTimestamp = System.currentTimeMillis();
buttonAbort.setEnabled(true);
runAsync("EnergyScan", args).handle((ok, ex) -> {
buttonAbort.setEnabled(false);
if (ex != null) {
runAsync("EnergyScan", args).handle((ok, ex) -> {
try{
buttonAbort.setEnabled(false);
if (ex != null) {
stopScan();
throw ex;
} else {
if (batch != null) {
batchIndex++;
if (batchIndex >= batch.length) {
batch = null;
} else {
setMode(batch[batchIndex]);
run();
}
}
}
} catch (Throwable t){
batch = null;
getLogger().log(Level.WARNING, null, ex);
showException((Exception)ex);
}
return ok;
});
@@ -808,7 +802,7 @@ public class EnergyScan extends Panel {
private void comboSetupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboSetupActionPerformed
try {
if (comboSetup.getSelectedItem()!=null){
if (comboSetup.getSelectedItem() != null) {
setElement();
if (!isManualRun()) {
setRunType();
@@ -833,7 +827,7 @@ public class EnergyScan extends Panel {
dlgConfig.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
if (System.currentTimeMillis() - new File(dlgConfig.getEditor().getFileName()).lastModified() < 5000){
if (System.currentTimeMillis() - new File(dlgConfig.getEditor().getFileName()).lastModified() < 5000) {
loadConfig();
}
}