389 lines
20 KiB
Java
389 lines
20 KiB
Java
/*
|
|
* Copyright (c) 2014-2017 Paul Scherrer Institute. All rights reserved.
|
|
*/
|
|
|
|
import ch.psi.pshell.device.Averager;
|
|
import ch.psi.pshell.device.DescStatsDouble;
|
|
import ch.psi.pshell.plot.LinePlotErrorSeries;
|
|
import ch.psi.pshell.plot.LinePlotJFree;
|
|
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 ch.psi.utils.swing.SwingUtils;
|
|
import java.awt.Color;
|
|
import java.util.ArrayList;
|
|
import javax.swing.JSpinner;
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public class SchottkyScan extends Panel {
|
|
LinePlotErrorSeries series = new LinePlotErrorSeries("Values");
|
|
|
|
public SchottkyScan() {
|
|
initComponents();
|
|
plot.setStyle(LinePlotJFree.Style.ErrorY);
|
|
plot.addSeries(series);
|
|
plot.getAxis(Plot.AxisId.X).setLabel("Gun Phase");
|
|
plot.getAxis(Plot.AxisId.Y).setLabel("SINEG01-DICT215:B1_CHARGE");
|
|
//setPersistedComponents(SwingUtils.getComponentsByType(panelPars, JSpinner.class));
|
|
}
|
|
|
|
//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);
|
|
buttonSet.setEnabled(buttonStart.isEnabled());
|
|
spinnerStart.setEnabled(buttonStart.isEnabled());
|
|
spinnerStop.setEnabled(buttonStart.isEnabled());
|
|
spinnerStep.setEnabled(buttonStart.isEnabled());
|
|
spinnerSamples.setEnabled(buttonStart.isEnabled());
|
|
spinnerLatency.setEnabled(buttonStart.isEnabled());
|
|
spinnerPhaseRef.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 ("SchottkyScan".equals(getContext().getExecutionPars().getName())){
|
|
series.clear();
|
|
}
|
|
}
|
|
@Override
|
|
public void onNewRecord(Scan scan, ScanRecord record) {
|
|
if ("SchottkyScan".equals(getContext().getExecutionPars().getName())){
|
|
series.appendData((Double)record.getPositions()[0], ((DescStatsDouble)record.getValues()[0]).getMean(),
|
|
((DescStatsDouble)record.getValues()[0]).getStdev());
|
|
}
|
|
}
|
|
@Override
|
|
public void onScanEnded(Scan scan, Exception ex) {
|
|
}
|
|
};
|
|
|
|
@SuppressWarnings("unchecked")
|
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
|
private void initComponents() {
|
|
|
|
buttonStart = new javax.swing.JButton();
|
|
buttonAbort = new javax.swing.JButton();
|
|
panelPars = 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();
|
|
panelOutput = new javax.swing.JPanel();
|
|
jLabel7 = new javax.swing.JLabel();
|
|
spinnerPhaseRef = new javax.swing.JSpinner();
|
|
buttonSet = new javax.swing.JButton();
|
|
|
|
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);
|
|
}
|
|
});
|
|
|
|
panelPars.setBorder(javax.swing.BorderFactory.createTitledBorder("Parameters"));
|
|
|
|
spinnerStep.setModel(new javax.swing.SpinnerNumberModel(5.0d, 1.0d, 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(180.0d, -180.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, 5.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, -180.0d, 360.0d, 1.0d));
|
|
|
|
javax.swing.GroupLayout panelParsLayout = new javax.swing.GroupLayout(panelPars);
|
|
panelPars.setLayout(panelParsLayout);
|
|
panelParsLayout.setHorizontalGroup(
|
|
panelParsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(panelParsLayout.createSequentialGroup()
|
|
.addContainerGap()
|
|
.addGroup(panelParsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(panelParsLayout.createSequentialGroup()
|
|
.addComponent(jLabel1)
|
|
.addGap(0, 0, 0)
|
|
.addComponent(spinnerStart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
|
.addGroup(panelParsLayout.createSequentialGroup()
|
|
.addComponent(jLabel4)
|
|
.addGap(0, 0, 0)
|
|
.addComponent(spinnerSamples, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
|
.addGroup(panelParsLayout.createSequentialGroup()
|
|
.addComponent(jLabel5)
|
|
.addGap(0, 0, 0)
|
|
.addComponent(spinnerLatency, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
|
.addGroup(panelParsLayout.createSequentialGroup()
|
|
.addGroup(panelParsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addComponent(jLabel2)
|
|
.addComponent(jLabel3))
|
|
.addGap(1, 1, 1)
|
|
.addGroup(panelParsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addComponent(spinnerStep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addComponent(spinnerStop, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
|
|
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
|
);
|
|
|
|
panelParsLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel2, jLabel3, jLabel4, jLabel5});
|
|
|
|
panelParsLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerLatency, spinnerSamples, spinnerStart, spinnerStep, spinnerStop});
|
|
|
|
panelParsLayout.setVerticalGroup(
|
|
panelParsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(panelParsLayout.createSequentialGroup()
|
|
.addContainerGap()
|
|
.addGroup(panelParsLayout.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(panelParsLayout.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(panelParsLayout.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(panelParsLayout.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(panelParsLayout.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("");
|
|
|
|
panelOutput.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);
|
|
}
|
|
});
|
|
|
|
buttonSet.setText("Set");
|
|
buttonSet.addActionListener(new java.awt.event.ActionListener() {
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
buttonSetActionPerformed(evt);
|
|
}
|
|
});
|
|
|
|
javax.swing.GroupLayout panelOutputLayout = new javax.swing.GroupLayout(panelOutput);
|
|
panelOutput.setLayout(panelOutputLayout);
|
|
panelOutputLayout.setHorizontalGroup(
|
|
panelOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(panelOutputLayout.createSequentialGroup()
|
|
.addContainerGap(25, Short.MAX_VALUE)
|
|
.addGroup(panelOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelOutputLayout.createSequentialGroup()
|
|
.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))
|
|
.addComponent(buttonSet, javax.swing.GroupLayout.Alignment.TRAILING))
|
|
.addContainerGap())
|
|
);
|
|
|
|
panelOutputLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonSet, spinnerPhaseRef});
|
|
|
|
panelOutputLayout.setVerticalGroup(
|
|
panelOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(panelOutputLayout.createSequentialGroup()
|
|
.addContainerGap()
|
|
.addGroup(panelOutputLayout.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))
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
|
.addComponent(buttonSet)
|
|
.addContainerGap(79, 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()
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
|
.addGroup(layout.createSequentialGroup()
|
|
.addComponent(buttonStart)
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
|
.addComponent(buttonAbort))
|
|
.addComponent(panelPars, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
|
.addComponent(panelOutput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
|
.addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, 522, 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(panelPars, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
|
.addComponent(panelOutput, 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)))
|
|
.addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
|
.addGap(17, 17, 17))
|
|
);
|
|
}// </editor-fold>//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("RFscan/SchottkyScan", parameters).handle((ret, ex) -> {
|
|
if (ex != null){
|
|
getLogger().info("Exception executing scan: " + ex);
|
|
} else {
|
|
spinnerPhaseRef.setValue(ret);
|
|
}
|
|
return ret;
|
|
});
|
|
//runAsync("RFscan/SchottkyScan", 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.GREEN);
|
|
} catch (Exception ex) {
|
|
showException(ex);
|
|
}
|
|
}//GEN-LAST:event_spinnerPhaseRefStateChanged
|
|
|
|
private void buttonSetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSetActionPerformed
|
|
try {
|
|
double phaseOffset = -((Double)spinnerPhaseRef.getValue());
|
|
String cmd = "caput('SINEG01-RSYS:SET-VSUM-PHASE-OFFSET-BASE', " + phaseOffset + ")";
|
|
cmd += "; " + "caput('SINEG01-RSYS:CMD-LOAD-CALIB-BEAM', 1)";
|
|
evalAsync(cmd).handle((ret, ex) -> {
|
|
if (ex != null){
|
|
showException((Exception)ex);
|
|
} else {
|
|
SwingUtils.showMessage(this, "Success", "Success setting ref phase");
|
|
}
|
|
return ret;
|
|
});
|
|
} catch (Exception ex) {
|
|
showException(ex);
|
|
}
|
|
}//GEN-LAST:event_buttonSetActionPerformed
|
|
|
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
|
private javax.swing.JButton buttonAbort;
|
|
private javax.swing.JButton buttonSet;
|
|
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 panelOutput;
|
|
private javax.swing.JPanel panelPars;
|
|
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
|
|
}
|