Closedown

This commit is contained in:
X11MA
2015-12-02 18:43:13 +01:00
parent a294078e3f
commit 45f1df468b
3 changed files with 50 additions and 36 deletions

View File

@@ -24,6 +24,7 @@ import ch.psi.pshell.plot.Plot;
import ch.psi.pshell.ui.Panel;
import java.io.IOException;
import java.util.logging.Logger;
import javax.swing.SwingUtilities;
/**
*
@@ -33,16 +34,17 @@ public class EnergyScan extends Panel {
public EnergyScan() {
initComponents();
}
long start;
ChannelDouble k1;
ChannelDouble k2;
ChannelDouble k3;
ChannelDouble energy;
ChannelInteger otf_start;
double[] offsets = new double[4];
double energyCache = 0;
boolean restart;
@Override
public void onInitialize(int runCount) {
@@ -51,31 +53,35 @@ public class EnergyScan extends Panel {
k1 = (ChannelDouble) getController().getDevicePool().getByName("keithley_1a");
k2 = (ChannelDouble) getController().getDevicePool().getByName("keithley_2a");
k3 = (ChannelDouble) getController().getDevicePool().getByName("keithley_3a");
energy= (ChannelDouble) getController().getDevicePool().getByName("energy");
energy = (ChannelDouble) getController().getDevicePool().getByName("energy");
otf_start = (ChannelInteger) getController().getDevicePool().getByName("otf_start");
for (Device dev :new Device[]{energy}){
for (Device dev : new Device[]{energy}) {
dev.addListener(new DeviceAdapter() {
@Override
public void onValueChanged(Device device, Object value, Object former) {
try {
if (Math.abs(energyCache - ((Double)value)) > 0.1) {
if (radioK3.isSelected())
if (Math.abs(energyCache - ((Double) value)) > 0.1) {
if (radioK3.isSelected()) {
k3.update();
else
} else {
k1.update();
}
k2.update();
energyCache = (Double)value;
update();
energyCache = (Double) value;
if (otf_start.take() == 1) {
update();
}
}
} catch (Exception ex) {
Logger.getLogger(EnergyScan.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
});
}
start = System.currentTimeMillis();
update();
}
@@ -88,16 +94,25 @@ public class EnergyScan extends Panel {
public void onExecutedFile(String fileName, Object result) {
}
boolean otf;
@Override
protected void doUpdate() {
if ((otf_start.take()== 1) && !otf){
try {
startPlot();
} catch (Exception ex) {
Logger.getLogger(EnergyScan.class.getName()).log(Level.SEVERE, null, ex);
}
}
otf = otf_start.take() > 0;
plot();
}
void stopScan() {
try{
try {
getLogger().info("Stopping scan");
evalAsync("caput('START', 'STOP')");
} catch (Exception ex){
} catch (Exception ex) {
getLogger().log(Level.WARNING, null, ex);
}
}
@@ -105,7 +120,7 @@ public class EnergyScan extends Panel {
Path getConfigFile() {
return Paths.get(getController().getSetup().getConfigPath(), "energy_scan.properties");
}
LinePlotBase scanPlot;
LinePlotSeries scanSeries;
@@ -129,10 +144,10 @@ public class EnergyScan extends Panel {
void plot() {
try {
if ((scanPlot != null) && (scanSeries != null) && scanPlot.isShowing() ) {
//if ((scanPlot != null) && (scanSeries != null) && scanPlot.isShowing() && (count != null)) {
double x = energy.take();
double y = k2.take() / ((radioK3.isSelected()) ? k3.take() : k1.take());
if ((scanPlot != null) && (scanSeries != null) && scanPlot.isShowing()) {
//if ((scanPlot != null) && (scanSeries != null) && scanPlot.isShowing() && (count != null)) {
double x = energy.take();
double y = k2.take() / ((radioK3.isSelected()) ? k3.take() : k1.take());
scanSeries.appendData(x, y);
}
@@ -142,7 +157,6 @@ public class EnergyScan extends Panel {
}
}
void run() throws Exception {
HashMap args = new HashMap();
Double e1 = (Double) spinnerE1.getValue();
@@ -150,24 +164,22 @@ public class EnergyScan extends Panel {
args.put("E1", e1);
args.put("E2", e2);
args.put("TIME", (Double) spinnerTime.getValue());
args.put("DELAY", (Double) spinnerDelay.getValue());
args.put("DELAY", (Double) spinnerDelay.getValue());
args.put("OFFSET1", (Double) spinnerOffset1.getValue());
args.put("OFFSET2", (Double) spinnerOffset2.getValue());
args.put("PREFIX", textPrefix.getText());
args.put("RUNTYPE", comboRunType.getSelectedItem().toString());
buttonAbort.setEnabled(true);
runAsync("EnergyScan", args).handle((ok, ex) -> {
try{
runAsync("EnergyScan", args).handle((ok, ex) -> {
try {
buttonAbort.setEnabled(false);
if (ex != null) {
throw ex;
} else {
}
} catch (Throwable t){
}
} catch (Throwable t) {
getLogger().log(Level.WARNING, null, ex);
//showException((Exception)ex);
}
@@ -221,17 +233,17 @@ public class EnergyScan extends Panel {
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel1.setText("E1:");
spinnerE1.setModel(new javax.swing.SpinnerNumberModel(690.0d, 0.0d, 9999.0d, 1.0d));
spinnerE1.setModel(new javax.swing.SpinnerNumberModel(680.0d, 0.0d, 9999.0d, 1.0d));
jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel2.setText("E2:");
spinnerE2.setModel(new javax.swing.SpinnerNumberModel(755.0d, 0.0d, 9999.0d, 1.0d));
spinnerE2.setModel(new javax.swing.SpinnerNumberModel(750.0d, 0.0d, 9999.0d, 1.0d));
jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel3.setText("Time(min):");
spinnerTime.setModel(new javax.swing.SpinnerNumberModel(3.0d, 0.0d, 60.0d, 1.0d));
spinnerTime.setModel(new javax.swing.SpinnerNumberModel(2.0d, 0.0d, 60.0d, 1.0d));
jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel4.setText("Delay(s):");
@@ -250,7 +262,7 @@ public class EnergyScan extends Panel {
jLabel11.setText("Run Type:");
comboRunType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "+/-" }));
comboRunType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "+/-", "+", "-" }));
jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel9.setText("Prefix:");