diff --git a/plugins/ReturnBug.form b/plugins/ReturnBug.form
new file mode 100644
index 0000000..30cebc6
--- /dev/null
+++ b/plugins/ReturnBug.form
@@ -0,0 +1,284 @@
+
+
+
diff --git a/plugins/ReturnBug.java b/plugins/ReturnBug.java
new file mode 100644
index 0000000..e30d7fb
--- /dev/null
+++ b/plugins/ReturnBug.java
@@ -0,0 +1,358 @@
+/*
+ * Copyright (c) 2014-2017 Paul Scherrer Institute. All rights reserved.
+ */
+
+import ch.psi.pshell.plot.LinePlotSeries;
+import ch.psi.pshell.plot.Plot;
+import ch.psi.pshell.scan.Scan;
+import ch.psi.pshell.scan.ScanListener;
+import ch.psi.pshell.scan.ScanRecord;
+import ch.psi.pshell.ui.Panel;
+import ch.psi.utils.State;
+import java.awt.Color;
+import java.util.ArrayList;
+
+/**
+ *
+ */
+public class ReturnBug extends Panel {
+ LinePlotSeries series = new LinePlotSeries("Values");
+
+ public ReturnBug() {
+ initComponents();
+ plot.addSeries(series);
+ plot.getAxis(Plot.AxisId.X).setLabel("Phase");
+ plot.getAxis(Plot.AxisId.Y).setLabel("Charge");
+ }
+
+ //Overridable callbacks
+ @Override
+ public void onInitialize(int runCount) {
+
+ }
+
+ @Override
+ public void onStateChange(State state, State former) {
+ buttonAbort.setEnabled(state.isProcessing());
+ buttonStart.setEnabled(state == State.Ready);
+
+ spinnerStart.setEnabled(buttonStart.isEnabled());
+ spinnerStop.setEnabled(buttonStart.isEnabled());
+ spinnerStep.setEnabled(buttonStart.isEnabled());
+ spinnerSamples.setEnabled(buttonStart.isEnabled());
+ spinnerLatency.setEnabled(buttonStart.isEnabled());
+
+ }
+
+ @Override
+ public void onExecutedFile(String fileName, Object result) {
+ }
+
+
+ //Callback to perform update - in event thread
+ @Override
+ protected void doUpdate() {
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+ getContext().addScanListener(scanListener);
+ }
+
+ @Override
+ public void onStop() {
+ getContext().removeScanListener(scanListener);
+ super.onStop();
+
+ }
+
+
+ ScanListener scanListener = new ScanListener() {
+ @Override
+ public void onScanStarted(Scan scan, String plotTitle) {
+ if ("ReturnBug".equals(getContext().getExecutionPars().getName())){
+ series.clear();
+ }
+ }
+
+ @Override
+ public void onNewRecord(Scan scan, ScanRecord record) {
+ if ("ReturnBug".equals(getContext().getExecutionPars().getName())){
+ series.appendData((Double)record.getPositions()[0], ((Number)record.getValues()[0]).doubleValue());
+ }
+ }
+
+ @Override
+ public void onScanEnded(Scan scan, Exception ex) {
+ }
+ };
+
+
+
+ @SuppressWarnings("unchecked")
+ // //GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ buttonStart = new javax.swing.JButton();
+ buttonAbort = new javax.swing.JButton();
+ jPanel1 = new javax.swing.JPanel();
+ spinnerStep = new javax.swing.JSpinner();
+ jLabel5 = new javax.swing.JLabel();
+ jLabel1 = new javax.swing.JLabel();
+ spinnerStop = new javax.swing.JSpinner();
+ jLabel3 = new javax.swing.JLabel();
+ jLabel2 = new javax.swing.JLabel();
+ spinnerLatency = new javax.swing.JSpinner();
+ spinnerSamples = new javax.swing.JSpinner();
+ jLabel4 = new javax.swing.JLabel();
+ spinnerStart = new javax.swing.JSpinner();
+ plot = new ch.psi.pshell.plot.LinePlotJFree();
+ jPanel2 = new javax.swing.JPanel();
+ jLabel7 = new javax.swing.JLabel();
+ spinnerPhaseRef = new javax.swing.JSpinner();
+
+ buttonStart.setText("Start");
+ buttonStart.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ buttonStartActionPerformed(evt);
+ }
+ });
+
+ buttonAbort.setText("Abort");
+ buttonAbort.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ buttonAbortActionPerformed(evt);
+ }
+ });
+
+ jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Parameters"));
+
+ spinnerStep.setModel(new javax.swing.SpinnerNumberModel(5.0d, 0.1d, 90.0d, 1.0d));
+
+ jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
+ jLabel5.setText("Latency:");
+
+ jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
+ jLabel1.setText("Start:");
+
+ spinnerStop.setModel(new javax.swing.SpinnerNumberModel(360.0d, -45.0d, 360.0d, 1.0d));
+
+ jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
+ jLabel3.setText("Step:");
+
+ jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
+ jLabel2.setText("Stop:");
+
+ spinnerLatency.setModel(new javax.swing.SpinnerNumberModel(0.1d, 0.0d, 1.0d, 0.01d));
+
+ spinnerSamples.setModel(new javax.swing.SpinnerNumberModel(1, 1, 50, 1));
+
+ jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
+ jLabel4.setText("Nb Samples:");
+
+ spinnerStart.setModel(new javax.swing.SpinnerNumberModel(0.0d, -45.0d, 360.0d, 1.0d));
+
+ javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
+ jPanel1.setLayout(jPanel1Layout);
+ jPanel1Layout.setHorizontalGroup(
+ jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(jPanel1Layout.createSequentialGroup()
+ .addContainerGap()
+ .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(jPanel1Layout.createSequentialGroup()
+ .addComponent(jLabel1)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(spinnerStart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGroup(jPanel1Layout.createSequentialGroup()
+ .addComponent(jLabel2)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(spinnerStop, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGroup(jPanel1Layout.createSequentialGroup()
+ .addComponent(jLabel3)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(spinnerStep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGroup(jPanel1Layout.createSequentialGroup()
+ .addComponent(jLabel4)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(spinnerSamples, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGroup(jPanel1Layout.createSequentialGroup()
+ .addComponent(jLabel5)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(spinnerLatency, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
+ .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ );
+
+ jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel2, jLabel3, jLabel4, jLabel5});
+
+ jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerLatency, spinnerSamples, spinnerStart, spinnerStep, spinnerStop});
+
+ jPanel1Layout.setVerticalGroup(
+ jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(jPanel1Layout.createSequentialGroup()
+ .addContainerGap()
+ .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jLabel1)
+ .addComponent(spinnerStart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jLabel2)
+ .addComponent(spinnerStop, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jLabel3)
+ .addComponent(spinnerStep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jLabel4)
+ .addComponent(spinnerSamples, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jLabel5)
+ .addComponent(spinnerLatency, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ );
+
+ plot.setTitle("");
+
+ jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Output"));
+
+ jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
+ jLabel7.setText("Ref Phase:");
+
+ spinnerPhaseRef.setModel(new javax.swing.SpinnerNumberModel(0.0d, -45.0d, 360.0d, 1.0d));
+ spinnerPhaseRef.addChangeListener(new javax.swing.event.ChangeListener() {
+ public void stateChanged(javax.swing.event.ChangeEvent evt) {
+ spinnerPhaseRefStateChanged(evt);
+ }
+ });
+
+ javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
+ jPanel2.setLayout(jPanel2Layout);
+ jPanel2Layout.setHorizontalGroup(
+ jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(jPanel2Layout.createSequentialGroup()
+ .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(jLabel7)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(spinnerPhaseRef, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addContainerGap())
+ );
+ jPanel2Layout.setVerticalGroup(
+ jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(jPanel2Layout.createSequentialGroup()
+ .addContainerGap()
+ .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jLabel7)
+ .addComponent(spinnerPhaseRef, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addContainerGap(116, Short.MAX_VALUE))
+ );
+
+ javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
+ this.setLayout(layout);
+ layout.setHorizontalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(buttonStart)
+ .addGap(27, 27, 27)
+ .addComponent(buttonAbort)
+ .addGap(0, 411, Short.MAX_VALUE))
+ .addGroup(layout.createSequentialGroup()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
+ .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, 393, Short.MAX_VALUE)
+ .addContainerGap())
+ );
+
+ layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonAbort, buttonStart});
+
+ layout.setVerticalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ .addContainerGap()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)
+ .addGap(18, 18, 18))
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(buttonStart)
+ .addComponent(buttonAbort))
+ .addGap(17, 17, 17))
+ );
+ }// //GEN-END:initComponents
+
+ private void buttonStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStartActionPerformed
+//((Plugin)this).
+ plot.removeMarker(null);
+ spinnerPhaseRef.setValue(0.0);
+ ArrayList parameters = new ArrayList();
+ parameters.add(spinnerStart.getValue());
+ parameters.add(spinnerStop.getValue());
+ parameters.add(spinnerStep.getValue());
+ parameters.add(spinnerSamples.getValue());
+ parameters.add(spinnerLatency.getValue());
+ try {
+ //How to get a callback on the end of execution
+
+ runAsync("test/ReturnBug", parameters).handle((ret, ex) -> {
+ if (ex != null){
+ getLogger().info("Exception executing scan: " + ex);
+ } else {
+ spinnerPhaseRef.setValue(ret);
+ }
+ return ret;
+ });
+
+
+ //runAsync("RFscan/ReturnBug", parameters);
+ } catch (Exception ex) {
+ showException(ex);
+ }
+
+ }//GEN-LAST:event_buttonStartActionPerformed
+
+ private void buttonAbortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAbortActionPerformed
+ try {
+ abort();
+ } catch (Exception ex) {
+ showException(ex);
+ }
+ }//GEN-LAST:event_buttonAbortActionPerformed
+
+ private void spinnerPhaseRefStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerPhaseRefStateChanged
+ try {
+ plot.removeMarker(null);
+ plot.addMarker((Double)spinnerPhaseRef.getValue(), Plot.AxisId.X, "Ref Phase",Color.BLUE);
+ } catch (Exception ex) {
+ showException(ex);
+ }
+ }//GEN-LAST:event_spinnerPhaseRefStateChanged
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JButton buttonAbort;
+ private javax.swing.JButton buttonStart;
+ private javax.swing.JLabel jLabel1;
+ private javax.swing.JLabel jLabel2;
+ private javax.swing.JLabel jLabel3;
+ private javax.swing.JLabel jLabel4;
+ private javax.swing.JLabel jLabel5;
+ private javax.swing.JLabel jLabel7;
+ private javax.swing.JPanel jPanel1;
+ private javax.swing.JPanel jPanel2;
+ private ch.psi.pshell.plot.LinePlotJFree plot;
+ private javax.swing.JSpinner spinnerLatency;
+ private javax.swing.JSpinner spinnerPhaseRef;
+ private javax.swing.JSpinner spinnerSamples;
+ private javax.swing.JSpinner spinnerStart;
+ private javax.swing.JSpinner spinnerStep;
+ private javax.swing.JSpinner spinnerStop;
+ // End of variables declaration//GEN-END:variables
+}
diff --git a/plugins/ShottkyScan.java b/plugins/ShottkyScan.java
index 02e39c3..725f6b6 100644
--- a/plugins/ShottkyScan.java
+++ b/plugins/ShottkyScan.java
@@ -8,12 +8,9 @@ import ch.psi.pshell.scan.Scan;
import ch.psi.pshell.scan.ScanListener;
import ch.psi.pshell.scan.ScanRecord;
import ch.psi.pshell.ui.Panel;
-import ch.psi.pshell.ui.Plugin;
import ch.psi.utils.State;
import java.awt.Color;
import java.util.ArrayList;
-import java.util.logging.Level;
-import java.util.logging.Logger;
/**
*
@@ -45,7 +42,7 @@ public class ShottkyScan extends Panel {
spinnerSamples.setEnabled(buttonStart.isEnabled());
spinnerLatency.setEnabled(buttonStart.isEnabled());
- }
+ }
@Override
public void onExecutedFile(String fileName, Object result) {
diff --git a/script/RFscan/ShottkyScan.py b/script/RFscan/ShottkyScan.py
index 75b6271..b9a2e34 100644
--- a/script/RFscan/ShottkyScan.py
+++ b/script/RFscan/ShottkyScan.py
@@ -36,16 +36,14 @@ finally:
q.close()
#st.close()
-# Here the user needs to pick a phase as reference phase (onset of charge emission)
-phase_ref = 80.0
-phase_offset = - phase_ref
-caput("SINEG01-RSYS:CALC-VSUM-PHASE-OFFSET", phase_offset)
-
-
#Setting the return value
#set_return(50.0)
y = r.getReadable(0)
x = r.getPositions(0)
y = [v.mean for v in y]
-index_max = y.index(max(y))
-_ = x[index_max]
\ No newline at end of file
+index_max = y.index(max(y))
+phase_ref = x[index_max]
+phase_offset = - phase_ref
+caput("SINEG01-RSYS:CALC-VSUM-PHASE-OFFSET", phase_offset)
+
+_ = phase_ref
\ No newline at end of file
diff --git a/script/test/ReturnBug.py b/script/test/ReturnBug.py
new file mode 100644
index 0000000..26a9a92
--- /dev/null
+++ b/script/test/ReturnBug.py
@@ -0,0 +1,39 @@
+import ch.psi.pshell.epics.ControlledVariable as ControlledVariable
+
+phase = ControlledVariable("Phase", "SINEG01-RSYS:SET-VSUM-PHASE-SIM", "SINEG01-RSYS:GET-VSUM-PHASE-SIM")
+phase.config.minValue =-45.0
+phase.config.maxValue = 360.0
+phase.config.resolution = 0.5
+
+
+#st = Stream("ICTstream", dispatcher)
+#q = st.addScalar("Charge", "SINEG01-DICT215:B1_CHARGE-SIM", 1, 0)
+#st.initialize()
+#st.start(True)
+q = Channel("SINEG01-DICT215:B1_CHARGE-SIM", type = 'd', alias='ICT-Q')
+
+
+if get_exec_pars().source == CommandSource.ui:
+ start = 0.0
+ stop = 360.0
+ step = 5.0
+ nb = 1
+ lat = 0.005
+else:
+ start = args[0]
+ stop = args[1]
+ step = args[2]
+ nb = int(args[3])
+ lat = args[4]
+
+
+r = lscan(ao1, ai1, start, stop, step, latency=lat)
+
+#Setting the return value
+#set_return(50.0)
+y = r.getReadable(0)
+x = r.getPositions(0)
+
+index_max = y.index(max(y))
+phase_ref = x[index_max]
+set_return(phase_ref)
\ No newline at end of file