Closedown

This commit is contained in:
X11MA
2015-12-02 20:19:38 +01:00
parent 300e9dfff1
commit 06b7e38812
3 changed files with 49 additions and 30 deletions

View File

@@ -21,7 +21,9 @@ import ch.psi.pshell.plot.LinePlotBase;
import ch.psi.pshell.plot.LinePlotSeries;
import ch.psi.pshell.plot.Plot;
import ch.psi.pshell.ui.Panel;
import ch.psi.utils.Chrono;
import java.util.logging.Logger;
import javax.swing.SwingUtilities;
/**
*
@@ -52,7 +54,21 @@ public class EnergyScan extends Panel {
k3 = (ChannelDouble) getController().getDevicePool().getByName("keithley_3a");
energy = (ChannelDouble) getController().getDevicePool().getByName("energy");
otf_start = (ChannelInteger) getController().getDevicePool().getByName("otf_start");
/*
otf_start.addListener(new DeviceAdapter() {
@Override
public void onValueChanged(Device device, Object value, Object former) {
if (((Integer) value) == 1) {
SwingUtilities.invokeLater(() -> {
try {
startPlot();
} catch (Exception ex) {
Logger.getLogger(EnergyScan.class.getName()).log(Level.SEVERE, null, ex);
}
});
}
}
});*/
for (Device dev : new Device[]{energy}) {
dev.addListener(new DeviceAdapter() {
@Override
@@ -67,6 +83,9 @@ public class EnergyScan extends Panel {
k2.update();
energyCache = (Double) value;
if (otf_start.take() == 1) {
SwingUtilities.invokeLater(() -> {
plot();
});
update();
}
}
@@ -79,7 +98,7 @@ public class EnergyScan extends Panel {
start = System.currentTimeMillis();
update();
plot();
}
@Override
@@ -92,18 +111,7 @@ public class EnergyScan extends Panel {
}
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 {
@@ -125,7 +133,7 @@ public class EnergyScan extends Panel {
public void setEnabled(boolean value) {
super.setEnabled(value);
buttonExecute.setEnabled(value);
buttonPlot.setEnabled(value);
//buttonPlot.setEnabled(value);
checkParameterControls();
}
@@ -138,22 +146,30 @@ public class EnergyScan extends Panel {
}
//spinnerAlpha.setEnabled(enabled && comboMode.getSelectedItem().equals("LINEAR"));
}
double last = 0;
void plot() {
try {
if ((scanPlot != null) && (scanSeries != null) && scanPlot.isShowing()) {
if ((scanPlot != null) && (scanSeries != null)) {
//if ((scanPlot != null) && (scanSeries != null) && scanPlot.isShowing() && (count != null)) {
double x = energy.take();
if (last < (x -10.0)){
if (scanSeries!=null){
scanSeries.clear();
}
}
last = x;
double y = k2.take() / ((radioK3.isSelected()) ? k3.take() : k1.take());
scanSeries.appendData(x, y);
}
} catch (Exception ex) {
//showException(ex);
ex.printStackTrace();
}
}
void run() throws Exception {
HashMap args = new HashMap();
Double e1 = (Double) spinnerE1.getValue();
@@ -165,7 +181,7 @@ public class EnergyScan extends Panel {
args.put("OFFSET1", (Double) spinnerOffset1.getValue());
args.put("OFFSET2", (Double) spinnerOffset2.getValue());
args.put("RUNTYPE", comboRunType.getSelectedItem().toString());
args.put("ROUNDS", (Integer) spinnerRounds.getValue());
args.put("ROUNDS", (Integer) spinnerRounds.getValue());
buttonAbort.setEnabled(true);
@@ -190,6 +206,7 @@ public class EnergyScan extends Panel {
void startPlot() throws Exception {
PlotDescriptor descriptors = new PlotDescriptor("Energy Scan");
//ArrayList<LinePlot> plots = getController().plot(new PlotDescriptor[]{descriptors}, Chrono.getTimeStr(System.currentTimeMillis(), "hh:mm:ss"));
ArrayList<LinePlot> plots = getController().plot(new PlotDescriptor[]{descriptors}, null);
scanPlot = (LinePlotBase) plots.get(0);
scanSeries = scanPlot.getSeries(0);
@@ -287,7 +304,7 @@ public class EnergyScan extends Panel {
.addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(spinnerE1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(spinnerTime, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 84, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 82, Short.MAX_VALUE)
.addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
@@ -305,7 +322,7 @@ public class EnergyScan extends Panel {
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(spinnerRounds, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(43, Short.MAX_VALUE))
.addContainerGap(41, Short.MAX_VALUE))
);
panelParametersLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerE1, spinnerTime});
@@ -364,7 +381,7 @@ public class EnergyScan extends Panel {
}
});
buttonPlot.setText("Plot");
buttonPlot.setText("Clear");
buttonPlot.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonPlotActionPerformed(evt);
@@ -381,7 +398,7 @@ public class EnergyScan extends Panel {
.addComponent(buttonPlot, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(radioK1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(radioK3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(34, Short.MAX_VALUE))
.addContainerGap(30, Short.MAX_VALUE))
);
jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {radioK1, radioK3});
@@ -478,8 +495,11 @@ public class EnergyScan extends Panel {
EditorDialog dlgConfig;
private void buttonPlotActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPlotActionPerformed
try {
startPlot();
plot();
//startPlot();
//plot();
if (scanSeries!=null){
scanSeries.clear();
}
} catch (Exception ex) {
showException(ex);
}