diff --git a/devices/CurrentCamera.properties b/devices/CurrentCamera.properties index 19c35b7..c0aa018 100644 --- a/devices/CurrentCamera.properties +++ b/devices/CurrentCamera.properties @@ -1,13 +1,13 @@ -#Tue Apr 25 13:06:46 CEST 2017 +#Wed Apr 26 17:50:35 CEST 2017 colormap=Flame -colormapAutomatic=false -colormapMax=318.0 -colormapMin=9.0 +colormapAutomatic=true +colormapMax=0.0 +colormapMin=0.0 flipHorizontally=false flipVertically=false grayscale=false -imageHeight=2160 -imageWidth=2560 +imageHeight=1024 +imageWidth=1280 invert=false regionStartX=1 regionStartY=1 @@ -21,9 +21,9 @@ rotation=0.0 rotationCrop=false scale=1.0 serverURL=localhost\:10000 -spatialCalOffsetX=-1057.0 -spatialCalOffsetY=-1420.0 -spatialCalScaleX=-8.51063829787234 -spatialCalScaleY=-8.559201141226819 +spatialCalOffsetX=-640.5003909304144 +spatialCalOffsetY=-512.5004887585533 +spatialCalScaleX=-8.4375 +spatialCalScaleY=-8.49609375 spatialCalUnits=mm transpose=false diff --git a/plugins/WireScan.form b/plugins/WireScan.form index 8d337ea..1f2af81 100644 --- a/plugins/WireScan.form +++ b/plugins/WireScan.form @@ -18,84 +18,106 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -107,29 +129,38 @@ - + - + - - - - + + + + + + + - - + + + + + + + + - - - - + + + + @@ -149,17 +180,30 @@ - + - - - - - - + + + + + + + + + + + + + + + + + + + @@ -172,7 +216,7 @@ - + @@ -180,26 +224,26 @@ - + - + - + - + - + - + @@ -225,13 +269,13 @@ - + - + @@ -276,14 +320,14 @@ - + - + @@ -326,7 +370,7 @@ - + @@ -368,5 +412,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/WireScan.java b/plugins/WireScan.java index 3fdc672..b242d96 100644 --- a/plugins/WireScan.java +++ b/plugins/WireScan.java @@ -3,6 +3,7 @@ */ import ch.psi.pshell.device.Device; +import ch.psi.pshell.device.DeviceAdapter; import ch.psi.pshell.epics.ChannelDouble; import ch.psi.pshell.epics.Epics; import ch.psi.pshell.plot.LinePlotSeries; @@ -13,6 +14,7 @@ import ch.psi.pshell.scan.ScanRecord; import ch.psi.pshell.ui.App; import ch.psi.pshell.ui.Panel; import ch.psi.pshell.ui.Plugin; +import ch.psi.utils.Convert; import ch.psi.utils.State; import ch.psi.utils.swing.SwingUtils; import java.awt.BorderLayout; @@ -21,6 +23,8 @@ import java.awt.Component; import java.awt.Dimension; import java.util.ArrayList; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.swing.DefaultComboBoxModel; import javax.swing.JComboBox; import javax.swing.JLabel; @@ -38,6 +42,8 @@ public class WireScan extends Panel { final int[] seriesYAxis = new int[]{1, 1, 2, 1, 1, 2}; LinePlotSeries[] series = new LinePlotSeries[seriesNames.length]; boolean homed; + boolean parked; + String currentScannner; public WireScan() { initComponents(); @@ -49,7 +55,7 @@ public class WireScan extends Panel { plot.getAxis(Plot.AxisId.Y).setLabel("mm"); plot.getAxis(Plot.AxisId.Y2).setLabel("pc"); plot.setLegendVisible(true); - bpmCombos = new JComboBox[]{comboBpm1, comboBpm2, comboBpm3}; + bpmCombos = new JComboBox[]{comboBpm1, comboBpm2, comboBpm3}; } //Overridable callbacks @@ -65,17 +71,15 @@ public class WireScan extends Panel { for (String scan: ret){ model.addElement(scan); } - comboWireScan.setModel(model); + comboWireScanner.setModel(model); eval("run('Devices/WireScanner')", true); model = new DefaultComboBoxModel(); - ret = (List) ((Plugin)this).eval("WireScanner.Selection", true); + ret = (List) ((Plugin)this).eval("WireScanner.ScanType", true); for (String scan: ret){ - if (!scan.equals("GARAGE")){ - model.addElement(scan); - } + model.addElement(scan); } - comboSelection.setModel(model); - comboWireScanActionPerformed(null); + comboScanType.setModel(model); + comboWireScannerActionPerformed(null); ret = (List) ((Plugin)this).eval("get_bpms()", true); @@ -88,24 +92,39 @@ public class WireScan extends Panel { cb.setModel(model); } if (App.hasArgument("ws")){ - comboWireScan.setSelectedItem(App.getArgumentValue("ws")); + comboWireScanner.setSelectedItem(App.getArgumentValue("ws")); } - comboWireScanActionPerformed(null); + comboWireScannerActionPerformed(null); } catch (Exception ex) { showException(ex); } } + @Override + public void onStart() { + super.onStart(); + } + + @Override + public void onStop() { + try { + closeDevices(); + } catch (Exception ex) { + Logger.getLogger(WireScan.class.getName()).log(Level.WARNING, null, ex); + } + super.onStop(); + } + + @Override protected void onTimer(){ try{ - boolean validWireScan = !comboWireScan.getSelectedItem().toString().isEmpty(); - if (validWireScan){ - homed = (Epics.get(comboWireScan.getSelectedItem().toString() + ":MOTOR_1_HOMED", Integer.class) == 1); + if (isValidScanner()){ + homed = (Epics.get(currentScannner + ":MOTOR_1_HOMED", Integer.class) == 1); if (homed){ ledHomed.setColor(Color.GREEN); - } else if (Epics.get(comboWireScan.getSelectedItem().toString() + ":MOTOR_1_HOMING", Integer.class) == 1){ + } else if (Epics.get(currentScannner + ":MOTOR_1_HOMING", Integer.class) == 1){ ledHomed.setColor(Color.YELLOW); } else { ledHomed.setColor(Color.RED); @@ -121,21 +140,27 @@ public class WireScan extends Panel { //S20CB01-DWSC440:MOTOR_1_HOME.PROC @Override public void onStateChange(State state, State former) { - boolean validWireScan = !comboWireScan.getSelectedItem().toString().isEmpty(); + boolean validWireScan = isValidScanner(); buttonMoveStart.setEnabled((state==State.Ready) && validWireScan && homed); buttonPark.setEnabled((state==State.Ready) && validWireScan && homed); buttonScan.setEnabled((state==State.Ready) && validWireScan && homed); buttonAbort.setEnabled(state==State.Busy); - comboSelection.setEnabled(validWireScan); + comboScanType.setEnabled(validWireScan); comboBpm1.setEnabled(validWireScan); comboBpm2.setEnabled(validWireScan); comboBpm3.setEnabled(validWireScan); buttonMotorPanel.setEnabled(validWireScan); buttonScannerPanel.setEnabled(validWireScan); buttonHoming.setEnabled(validWireScan); - for (Component c: SwingUtils.getComponentsByType(this, JSpinner.class)){ - c.setEnabled(validWireScan); - } + spinnerVel.setEnabled(validWireScan); + spinnerCycles.setEnabled(validWireScan); + int type = comboScanType.getSelectedIndex(); + boolean isX = (type==0) || (type==2) || (type>=4); + boolean isY = (type==1) || (type==3) || (type>=4); + spinnerStartX.setEnabled(validWireScan && isX); + spinnerEndX.setEnabled(validWireScan && isX); + spinnerStartY.setEnabled(validWireScan && isY); + spinnerEndY.setEnabled(validWireScan && isY); } @Override @@ -164,10 +189,10 @@ public class WireScan extends Panel { public void onNewRecord(Scan scan, ScanRecord record) { try{ if ("WireScan".equals(getContext().getExecutionPars().getName())) { - double position = (Double) record.getValues()[1]; + double position = (Double) record.getValues()[0]; for (int i=0; i< series.length; i++){ if (record.getValues()[4 + i] != null){ - series[i].appendData(position,(Double) record.getValues()[4 + i]); + series[i].appendData(position,(Double) record.getValues()[5 + i]); } } } @@ -182,14 +207,72 @@ public class WireScan extends Panel { } }; + boolean isValidScanner(){ + return (currentScannner!=null) && (!currentScannner.isEmpty()); + } + + void closeDevices() throws Exception{ + if ((currentScannner!=null) && (!currentScannner.isEmpty())){ + try{ + if (panelStatus.getDevice()!=null){ + panelStatus.getDevice().close(); + panelStatus.setDevice(null); + } + if (panelPosition.getDevice()!=null){ + panelPosition.getDevice().close(); + panelPosition.setDevice(null); + } + labelPosX.setText(""); + labelPosY.setText(""); + boolean moved = Epics.get(currentScannner + ":WIRE_SP", Integer.class) != 0; + if (parked && moved){ + System.out.println("Parking scanner"); + Epics.putq(currentScannner + ":GARAGE_SEL.PROC", 1); + } + } catch (Exception ex){ + ex.printStackTrace(); + throw ex; + } finally{ + currentScannner = "" ; + } + } + } + + int getWireSet(){ + int i = comboScanType.getSelectedIndex(); + switch (i){ + case 2: + case 3: + case 5: + return 2; + } + return 1; + } + + void updatePosition(Double value){ + if (value!=null && !Double.isNaN((Double)value)){ + try { + List pos = (List)eval("get_wire_pos(scanner_info, " + value + ")", true); + int offset = (getWireSet()-1) *2; + labelPosX.setText(String.valueOf(Convert.roundDouble(pos.get(0 + offset),1))); + labelPosY.setText(String.valueOf(Convert.roundDouble(pos.get(1 + offset),1))); + return; + } catch (Exception ex) { + ex.printStackTrace(); + } + } + labelPosX.setText(""); + labelPosY.setText(""); + } + @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { - comboWireScan = new javax.swing.JComboBox(); + comboWireScanner = new javax.swing.JComboBox(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); - comboSelection = new javax.swing.JComboBox(); + comboScanType = new javax.swing.JComboBox(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); @@ -202,8 +285,8 @@ public class WireScan extends Panel { buttonScan = new javax.swing.JButton(); buttonAbort = new javax.swing.JButton(); buttonMoveStart = new javax.swing.JButton(); - spinnerStart = new javax.swing.JSpinner(); - spinnerEnd = new javax.swing.JSpinner(); + spinnerStartX = new javax.swing.JSpinner(); + spinnerEndX = new javax.swing.JSpinner(); spinnerVel = new javax.swing.JSpinner(); spinnerCycles = new javax.swing.JSpinner(); panelStatus = new ch.psi.pshell.swing.DeviceValuePanel(); @@ -218,22 +301,30 @@ public class WireScan extends Panel { jLabel12 = new javax.swing.JLabel(); ledHomed = new ch.psi.pshell.swing.Led(); buttonHoming = new javax.swing.JButton(); + jLabel13 = new javax.swing.JLabel(); + jLabel14 = new javax.swing.JLabel(); + labelPosX = new javax.swing.JLabel(); + labelPosY = new javax.swing.JLabel(); + labelStartY = new javax.swing.JLabel(); + spinnerStartY = new javax.swing.JSpinner(); + labelEndY = new javax.swing.JLabel(); + spinnerEndY = new javax.swing.JSpinner(); - comboWireScan.addActionListener(new java.awt.event.ActionListener() { + comboWireScanner.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { - comboWireScanActionPerformed(evt); + comboWireScannerActionPerformed(evt); } }); jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel1.setText("Wire Scan:"); + jLabel1.setText("Wire Scanner:"); jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel2.setText("Selection:"); + jLabel2.setText("Scan Type"); - comboSelection.addActionListener(new java.awt.event.ActionListener() { + comboScanType.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { - comboSelectionActionPerformed(evt); + comboScanTypeActionPerformed(evt); } }); @@ -247,10 +338,10 @@ public class WireScan extends Panel { jLabel5.setText("BPM 3:"); jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel6.setText("Start (µm):"); + jLabel6.setText("Start X (µm):"); jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel7.setText("End (µm):"); + jLabel7.setText("End X (µm):"); jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); jLabel8.setText("Vel (µm/s):"); @@ -282,9 +373,9 @@ public class WireScan extends Panel { } }); - spinnerStart.setModel(new javax.swing.SpinnerNumberModel(1000.0d, -10000.0d, 10000.0d, 1.0d)); + spinnerStartX.setModel(new javax.swing.SpinnerNumberModel(1000.0d, -10000.0d, 10000.0d, 1.0d)); - spinnerEnd.setModel(new javax.swing.SpinnerNumberModel(1000.0d, -10000.0d, 10000.0d, 1.0d)); + spinnerEndX.setModel(new javax.swing.SpinnerNumberModel(1000.0d, -10000.0d, 10000.0d, 1.0d)); spinnerVel.setModel(new javax.swing.SpinnerNumberModel(200.0d, 1.0d, 10000.0d, 1.0d)); @@ -300,7 +391,7 @@ public class WireScan extends Panel { }); jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel11.setText("Position:"); + jLabel11.setText("Pos mot (µm):"); buttonMotorPanel.setText("Motor Panel"); buttonMotorPanel.addActionListener(new java.awt.event.ActionListener() { @@ -328,82 +419,127 @@ public class WireScan extends Panel { } }); + jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel13.setText("Pos x (µm):"); + + jLabel14.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel14.setText("Pos y (µm):"); + + labelPosX.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + labelPosX.setBorder(javax.swing.BorderFactory.createTitledBorder("")); + + labelPosY.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + labelPosY.setBorder(javax.swing.BorderFactory.createTitledBorder("")); + + labelStartY.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + labelStartY.setText("Start Y (µm):"); + + spinnerStartY.setModel(new javax.swing.SpinnerNumberModel(1000.0d, -10000.0d, 10000.0d, 1.0d)); + + labelEndY.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + labelEndY.setText("End Y (µm):"); + + spinnerEndY.setModel(new javax.swing.SpinnerNumberModel(1000.0d, -10000.0d, 10000.0d, 1.0d)); + 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.TRAILING, false) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addComponent(jLabel1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(comboWireScan, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(buttonPark) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonMoveStart) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonScan) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonAbort)) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(comboSelection, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(comboBpm3, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(spinnerStart) - .addComponent(spinnerVel)) - .addGap(46, 46, 46) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(jLabel7) - .addGap(8, 8, 8) - .addComponent(spinnerEnd)) - .addGroup(layout.createSequentialGroup() - .addComponent(jLabel9) - .addGap(8, 8, 8) - .addComponent(spinnerCycles)))) - .addComponent(panelStatus, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(comboBpm1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(comboBpm2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(jLabel11) - .addComponent(jLabel12)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(panelPosition, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGroup(layout.createSequentialGroup() - .addComponent(ledHomed, 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) - .addComponent(buttonHoming))) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonMotorPanel, javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(buttonScannerPanel, javax.swing.GroupLayout.Alignment.TRAILING)))) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(comboWireScanner, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addComponent(buttonPark) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(buttonMoveStart) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(buttonScan) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(buttonAbort)) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel11) + .addComponent(jLabel13) + .addComponent(jLabel14)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(panelPosition, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(labelPosX, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(labelPosY, javax.swing.GroupLayout.PREFERRED_SIZE, 90, 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.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel12) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(ledHomed, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(buttonHoming)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(buttonScannerPanel, javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(buttonMotorPanel, javax.swing.GroupLayout.Alignment.TRAILING))) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(labelStartY, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(comboScanType, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(comboBpm3, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(panelStatus, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(comboBpm1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(comboBpm2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(spinnerStartY) + .addGroup(layout.createSequentialGroup() + .addComponent(spinnerVel, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(18, 18, Short.MAX_VALUE) + .addComponent(jLabel9) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(spinnerCycles))) + .addGap(0, 0, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(labelEndY)) + .addGroup(layout.createSequentialGroup() + .addComponent(spinnerStartX) + .addGap(18, 18, Short.MAX_VALUE) + .addComponent(jLabel7))) + .addGap(8, 8, 8) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(spinnerEndX, javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(spinnerEndY, javax.swing.GroupLayout.Alignment.TRAILING)))))) + .addComponent(jLabel8)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, 457, Short.MAX_VALUE) + .addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, 418, Short.MAX_VALUE) .addGap(11, 11, 11)) ); - layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel10, jLabel11, jLabel2, jLabel3, jLabel4, jLabel5, jLabel6, jLabel7, jLabel8, jLabel9}); + layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel10, jLabel11, jLabel13, jLabel14, jLabel2, jLabel3, jLabel4, jLabel5, jLabel6, jLabel7, jLabel8, jLabel9, labelEndY, labelStartY}); layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonAbort, buttonMoveStart, buttonPark, buttonScan}); layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonMotorPanel, buttonScannerPanel}); + layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {labelPosX, labelPosY, panelPosition}); + + layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerCycles, spinnerEndX, spinnerEndY}); + + layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerStartX, spinnerStartY, spinnerVel}); + layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() @@ -411,25 +547,32 @@ public class WireScan extends Panel { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(comboWireScan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(comboWireScanner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(comboSelection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(comboScanType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(jLabel8) + .addComponent(spinnerCycles, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel6) - .addComponent(jLabel7) - .addComponent(spinnerEnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addComponent(spinnerStart, 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.UNRELATED) + .addComponent(jLabel9) + .addComponent(spinnerVel, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(jLabel6) + .addComponent(jLabel7) + .addComponent(spinnerEndX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(spinnerStartX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel8) - .addComponent(jLabel9) - .addComponent(spinnerVel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(spinnerCycles, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(spinnerStartY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(labelEndY) + .addComponent(spinnerEndY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(labelStartY)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) @@ -446,14 +589,23 @@ public class WireScan extends Panel { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) .addComponent(jLabel11) .addComponent(panelPosition, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(buttonScannerPanel)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(buttonScannerPanel) .addComponent(jLabel12) - .addComponent(ledHomed, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(buttonMotorPanel) - .addComponent(buttonHoming)) - .addGap(18, 18, 18) + .addComponent(ledHomed, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(buttonMotorPanel) + .addComponent(buttonHoming)) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(jLabel13) + .addComponent(labelPosX)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(jLabel14) + .addComponent(labelPosY)))) + .addGap(18, 18, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) .addComponent(jLabel10) .addComponent(panelStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) @@ -463,69 +615,99 @@ public class WireScan extends Panel { .addComponent(buttonScan) .addComponent(buttonMoveStart) .addComponent(buttonPark))) - .addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, 416, Short.MAX_VALUE)) + .addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap()) ); + + layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {labelPosX, labelPosY, panelPosition}); + + layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {spinnerStartX, spinnerStartY, spinnerVel}); + + layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {spinnerCycles, spinnerEndX, spinnerEndY}); + }// //GEN-END:initComponents - private void comboWireScanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboWireScanActionPerformed + private void comboWireScannerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboWireScannerActionPerformed try { - if (panelStatus.getDevice()!=null){ - panelStatus.getDevice().close(); - panelStatus.setDevice(null); - } - if (panelPosition.getDevice()!=null){ - panelPosition.getDevice().close(); - panelPosition.setDevice(null); - } + closeDevices(); ledHomed.setColor(Color.darkGray); - homed = false; + homed = false; + parked = false; + currentScannner = comboWireScanner.getSelectedItem().toString(); - if ( comboWireScan.getSelectedItem().toString().isEmpty()){ + if (currentScannner.isEmpty()){ for (JComboBox cb : bpmCombos){ cb.setSelectedItem(""); } } else { - List ret = (List) ((Plugin)this).eval("get_wire_scans_bpms('" + comboWireScan.getSelectedItem().toString()+ "')", true); + List ret = (List) ((Plugin)this).eval("get_wire_scans_bpms('" + currentScannner + "')", true); comboBpm1.setSelectedItem((ret==null) ? "" : ret.get(0)); comboBpm2.setSelectedItem((ret==null) ? "" : ret.get(1)); - comboSelection.setSelectedIndex(Epics.get(comboWireScan.getSelectedItem().toString() + ":WIRE_SP", Integer.class)); - spinnerVel.setValue(Epics.get(comboWireScan.getSelectedItem().toString() + ":SCAN_VELO_SP", Double.class)); - spinnerCycles.setValue(Epics.get(comboWireScan.getSelectedItem().toString() + ":NB_CYCL_SP", Integer.class)); - Device dev= (Device)eval("newScanInfoDevice(None, '" + comboWireScan.getSelectedItem().toString()+ "')", true); - panelStatus.setDevice(dev); - - dev = new ChannelDouble (null, comboWireScan.getSelectedItem().toString() + ":ENC_1_BS", 3); + int selection = Epics.get(currentScannner + ":WIRE_SP", Integer.class); + //comboSelection.setSelectedIndex(selection); //TODO: FIX + spinnerVel.setValue(Epics.get(currentScannner + ":SCAN_VELO_SP", Double.class)); + spinnerCycles.setValue(Epics.get(currentScannner + ":NB_CYCL_SP", Integer.class)); + Device scannerInfo = (Device)eval("new_scan_info_device(None, '" + currentScannner+ "')", true); + setGlobalVar("scanner_info", scannerInfo); + panelStatus.setDevice(scannerInfo); + Device dev = new ChannelDouble (null, currentScannner + ":ENC_1_BS", 3); dev.setMonitored(true); + dev.addListener(new DeviceAdapter() { + @Override + public void onValueChanged(Device device, Object value, Object former) { + updatePosition((Double)value); + } + }); dev.initialize(); - panelPosition.setDevice(dev); + panelPosition.setDevice(dev); + parked = (selection== 0); + comboScanTypeActionPerformed(null); } - } catch (Exception ex) { + } catch (Exception ex) { + try { + closeDevices(); + } catch (Exception ex1) { + Logger.getLogger(WireScan.class.getName()).log(Level.SEVERE, null, ex1); + } showException(ex); - comboWireScan.setSelectedItem(""); + comboWireScanner.setSelectedItem(""); for (JComboBox cb : bpmCombos){ cb.setSelectedItem(""); } } onStateChange(getState(), getState()); - }//GEN-LAST:event_comboWireScanActionPerformed + }//GEN-LAST:event_comboWireScannerActionPerformed - private void comboSelectionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboSelectionActionPerformed + private void comboScanTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboScanTypeActionPerformed try { - spinnerStart.setValue(Epics.get(comboWireScan.getSelectedItem().toString()+ ":" + comboSelection.getSelectedItem().toString() + "_START_SP", Double.class)); - spinnerEnd.setValue(Epics.get(comboWireScan.getSelectedItem().toString() + ":" + comboSelection.getSelectedItem().toString() + "_END_SP", Double.class)); - + int type = comboScanType.getSelectedIndex(); + boolean isSet = (type>=4); + boolean isSet1 = (type==0) || (type==1) || (type==4); + spinnerStartX.setValue(Epics.get(currentScannner + (isSet1 ? ":W1X" : ":W2X") + "_START_SP", Double.class)); + spinnerEndX.setValue(Epics.get(currentScannner + (isSet1 ? ":W1X" : ":W2X") + "_END_SP", Double.class)); + spinnerStartY.setValue(Epics.get(currentScannner + (isSet1 ? ":W1Y" : ":W2Y") + "_START_SP", Double.class)); + spinnerEndY.setValue(Epics.get(currentScannner + (isSet1 ? ":W1Y" : ":W2Y") + "_END_SP", Double.class)); } catch (Exception ex) { showException(ex); } - }//GEN-LAST:event_comboSelectionActionPerformed + try { + updatePosition((Double) panelPosition.getDevice().take()); + } catch (Exception ex) { + showException(ex); + } + onStateChange(getState(), getState()); + }//GEN-LAST:event_comboScanTypeActionPerformed private void buttonScanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonScanActionPerformed ArrayList parameters = new ArrayList(); - parameters.add(comboWireScan.getSelectedItem().toString()); - parameters.add(comboSelection.getSelectedItem().toString()); - parameters.add(spinnerStart.getValue()); - parameters.add(spinnerEnd.getValue()); + parameters.add(currentScannner); + parameters.add(comboScanType.getSelectedItem().toString()); + ArrayList range = new ArrayList(); + range.add(spinnerStartX.getValue()); + range.add(spinnerEndX.getValue()); + range.add(spinnerStartY.getValue()); + range.add(spinnerEndY.getValue()); + parameters.add(range); parameters.add(spinnerCycles.getValue()); parameters.add(spinnerVel.getValue()); ArrayList bpms = new ArrayList(); @@ -568,7 +750,7 @@ public class WireScan extends Panel { private void buttonMoveStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonMoveStartActionPerformed try { - Epics.putq(comboWireScan.getSelectedItem().toString() + ":INIT.PROC", 1); + Epics.putq(currentScannner + ":INIT.PROC", 1); } catch (Exception ex) { showException(ex); } @@ -576,7 +758,7 @@ public class WireScan extends Panel { private void buttonParkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonParkActionPerformed try { - Epics.putq(comboWireScan.getSelectedItem().toString() + ":GARAGE_SEL.PROC", 1); + Epics.putq(currentScannner + ":GARAGE_SEL.PROC", 1); } catch (Exception ex) { showException(ex); } @@ -585,7 +767,7 @@ public class WireScan extends Panel { String caqtdm = "caqtdm -noMsg -stylefile sfop.qss -attach"; private void buttonMotorPanelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonMotorPanelActionPerformed try { - String cmd = caqtdm + " -macro 'P=" + comboWireScan.getSelectedItem() + ":,M=MOTOR_1' /sf/common/config/qt/motorx_all.ui"; + String cmd = caqtdm + " -macro 'P=" + comboWireScanner.getSelectedItem() + ":,M=MOTOR_1' /sf/common/config/qt/motorx_all.ui"; Runtime.getRuntime().exec(new String[]{"bash", "-c", cmd.toString()}); } catch (Exception ex) { showException(ex); @@ -594,7 +776,7 @@ public class WireScan extends Panel { private void buttonScannerPanelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonScannerPanelActionPerformed try { - String cmd = caqtdm + " -macro 'DEVICE=" + comboWireScan.getSelectedItem() + "' /sf/op/config/qt/S_DI_WSC.ui"; + String cmd = caqtdm + " -macro 'DEVICE=" + comboWireScanner.getSelectedItem() + "' /sf/op/config/qt/S_DI_WSC.ui"; Runtime.getRuntime().exec(new String[]{"bash", "-c", cmd.toString()}); } catch (Exception ex) { showException(ex); @@ -604,7 +786,7 @@ public class WireScan extends Panel { private void buttonHomingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonHomingActionPerformed try { - Epics.putq(comboWireScan.getSelectedItem().toString() + ":MOTOR_1_HOME.PROC", 1); + Epics.putq(currentScannner + ":MOTOR_1_HOME.PROC", 1); } catch (Exception ex) { showException(ex); } @@ -621,12 +803,14 @@ public class WireScan extends Panel { private javax.swing.JComboBox comboBpm1; private javax.swing.JComboBox comboBpm2; private javax.swing.JComboBox comboBpm3; - private javax.swing.JComboBox comboSelection; - private javax.swing.JComboBox comboWireScan; + private javax.swing.JComboBox comboScanType; + private javax.swing.JComboBox comboWireScanner; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; + private javax.swing.JLabel jLabel13; + private javax.swing.JLabel jLabel14; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; @@ -635,13 +819,19 @@ public class WireScan extends Panel { private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; + private javax.swing.JLabel labelEndY; + private javax.swing.JLabel labelPosX; + private javax.swing.JLabel labelPosY; + private javax.swing.JLabel labelStartY; private ch.psi.pshell.swing.Led ledHomed; private ch.psi.pshell.swing.DeviceValuePanel panelPosition; private ch.psi.pshell.swing.DeviceValuePanel panelStatus; private ch.psi.pshell.plot.LinePlotJFree plot; private javax.swing.JSpinner spinnerCycles; - private javax.swing.JSpinner spinnerEnd; - private javax.swing.JSpinner spinnerStart; + private javax.swing.JSpinner spinnerEndX; + private javax.swing.JSpinner spinnerEndY; + private javax.swing.JSpinner spinnerStartX; + private javax.swing.JSpinner spinnerStartY; private javax.swing.JSpinner spinnerVel; // End of variables declaration//GEN-END:variables } diff --git a/script/Devices/WireScanner.py b/script/Devices/WireScanner.py index 4011a0e..9454b29 100644 --- a/script/Devices/WireScanner.py +++ b/script/Devices/WireScanner.py @@ -19,6 +19,10 @@ class WireScanInfo(DeviceBase): self.on_status_change(None) self.initialize() + self.home_offsets = [] + for s in ("W1X_U0_SP", "W1Y_U0_SP", "W2X_U0_SP", "W2Y_U0_SP", "FOIL_U0_SP"): + self.home_offsets.append(caget(self.prefix + ":" +s, 'd')) + def on_status_change(self, val): try: if self.status_channels[0].get() == 1: @@ -55,15 +59,38 @@ class WireScanInfo(DeviceBase): self.curr_cycl.close() for c in self.status_channels: c.close() + + def get_wire_pos(self, pos_motor): + if (pos_motor is None) or math.isnan(pos_motor): + return [pos_motor] * 4 + w1x = (pos_motor - self.home_offsets[0]) / -(math.sqrt(2)) + w1y = (pos_motor - self.home_offsets[1]) / (math.sqrt(2)) + w2x = (pos_motor - self.home_offsets[2]) / -(math.sqrt(2)) + w2y = (pos_motor - self.home_offsets[3]) / (math.sqrt(2)) + return [w1x, w1y, w2x, w2y] + -def newScanInfoDevice(name, prefix): +def new_scan_info_device(name, prefix): return WireScanInfo(name, prefix) - +def get_wire_pos(wire_scanner, pos): + return wire_scanner.get_wire_pos(pos) + +def get_scan_selection(scan_type, index = 0): + if scan_type == WireScanner.WireX1: return WireScanner.W1X + if scan_type == WireScanner.WireY1: return WireScanner.W1Y + if scan_type == WireScanner.WireX2: return WireScanner.W2X + if scan_type == WireScanner.WireY2: return WireScanner.W2Y + if scan_type == WireScanner.Set1: return WireScanner.W1X if (index==0) else WireScanner.W1Y + if scan_type == WireScanner.Set2: return WireScanner.W2X if (index==0) else WireScanner.W2Y + return None + class WireScanner(WireScanInfo): + + ScanType = [WireX1, WireY1, WireX2, WireY2, Set1, Set2] = ['X1', 'Y1', 'X2', 'Y2', 'Set1', 'Set2'] Selection = [Garage, W1X, W1Y, W2X, W2Y, Foil] = "GARAGE", "W1X", "W1Y", "W2X", "W2Y", "FOIL" - def __init__(self, prefix, sel = None, start=None , end=None, cycles=None, velocity=None, continuous = None): + def __init__(self, prefix, scan_range, cycles=None, velocity=None, continuous = None): WireScanInfo.__init__(self, "Wire Scan " + prefix, prefix) self.motor = ch.psi.pshell.epics.Motor("WireScanner motor", self.prefix + ":MOTOR_1") self.motor.uploadConfig() @@ -80,14 +107,10 @@ class WireScanner(WireScanInfo): self.range = None self.start = None self.end = None + self.scan_range = scan_range; if sel is not None: self.set_selection(sel) - #Setting parameters - if start is not None: - self.start.write(float(start)) - if end is not None: - self.end.write(float(end)) if velocity is not None: self.wire_velocity.write(float(velocity)) if cycles is not None: @@ -97,8 +120,7 @@ class WireScanner(WireScanInfo): self.readback = self.motor_bs_readback.get() self.cycles = self.nb_cycles.get() - self.velocity = self.wire_velocity.get() - self.scan_range = [self.start.get(), self.end.get()] + self.velocity = self.wire_velocity.get() self.initialize() #def on_readback_change(self, val): @@ -113,7 +135,16 @@ class WireScanner(WireScanInfo): self.range = Channel(self.prefix + ":" + self.selection + "_RANGE_SP") self.start = Channel(self.prefix + ":" + self.selection + "_START_SP") self.end = Channel(self.prefix + ":" + self.selection + "_END_SP") - self.wire_sel.put(WireScanner.Selection.index(sel)) + self.wire_sel.put(WireScanner.Selection.index(sel)) + + #Setting parameters + if start is not None: + if sel in ["W1X", "W2X"]: self.start.write(float(self.scan_range[0])) + if sel in ["W1Y", "W2Y"]: self.start.write(float(self.scan_range[2])) + if end is not None: + if sel in ["W1X", "W2X"]: self.end.write(float(self.scan_range[1])) + if sel in ["W1Y", "W2Y"]: self.end.write(float(self.scan_range[3])) + def abort(self): caputq(self.prefix + ":ABORT.PROC", 1) @@ -127,6 +158,16 @@ class WireScanner(WireScanInfo): def scan(self): self.cycles = self.nb_cycles.get() caputq(self.prefix + ":SCAN_WIRE", 1) + + def get_sel_wire_pos(self, pos_motor=None): + if pos_motor is None: + pos_motor = self.motor_bs_readback.get() + wire_pos = self.get_wire_pos(pos_motor) + if self.selection == WireScanner.W1X: return wire_pos[0] + if self.selection == WireScanner.W1Y: return wire_pos[1] + if self.selection == WireScanner.W2X: return wire_pos[2] + if self.selection == WireScanner.W2Y: return wire_pos[3] + return float('nan') def doClose(self): WireScanInfo.doClose(self) diff --git a/script/Diagnostics/WireScan.py b/script/Diagnostics/WireScan.py index 5c5d29c..bf6ca23 100644 --- a/script/Diagnostics/WireScan.py +++ b/script/Diagnostics/WireScan.py @@ -6,25 +6,26 @@ run("Devices/WireScanner") BPM_SENSORS = [("x","X1"), ("y","Y1"), ("q","Q1")] #(logic name sufix, channel sufix) #Paramter parsing -prefix = args[0] if is_panel else "S30CB09-DWSC440" -sel = args[1] if is_panel else WireScanner.W1X -start = args[2] if is_panel else -200 -end = args[3] if is_panel else 200 -cycles = args[4] if is_panel else 5 -velocity = args[5] if is_panel else 200 -bpms = args[6] if is_panel else get_wire_scans_bpms(prefix) -print "WireScan parameters: ", prefix, sel, start, end, cycles, cycles, bpms +prefix = args[0] if is_panel else "S30CB09-DWSC440" +scan_type = args[1] if is_panel else WireScanner.WireX1 +scan_range = args[2] if is_panel else [-200, 200] +cycles = args[3] if is_panel else 5 +velocity = args[4] if is_panel else 200 +bpms = args[5] if is_panel else get_wire_scans_bpms(prefix) +print "WireScan parameters: ", prefix, scan_type, scan_range, cycles, cycles, bpms #Creating WireScanner object print "Creating scanner..." if prefix not in get_wire_scans(): - raise Exception("Invalid wire scan: " + prefix) -scanner = WireScanner(prefix, sel, start, end, cycles, velocity, True) + raise Exception("Invalid wire scan: " + prefix) +scanner = WireScanner(prefix, scan_range, cycles, velocity, True) +scanner.set_selection(get_scan_selection(scan_type)) scanner.init() scanner.waitValue("At start", 60000) + #List of stream channels -channels = [("w_pos", scanner.motor_bs_readback.get_name()), +channels = [("m_pos", scanner.motor_bs_readback.get_name()), ("cur_cycle", scanner.curr_cycl.get_name()), ("scanning", scanner.status_channels[0].get_name())] @@ -38,16 +39,21 @@ for i in range (len(bpms)): print "Starting stream..." st = Stream("pulse_id", dispatcher) scanner.curr_cycl.write(0) -st.setFilter(scanner.curr_cycl.get_name() + ">0") #scanner.status_channels[0].get_name() + ">0" not used because we must the reansition to know when the finished +st.setFilter(scanner.curr_cycl.get_name() + ">0") #scanner.status_channels[0].get_name() + ">0" not used because we must the transition to know when the finished for c in channels: st.addScalar(c[0], c[1], 10, 0) st.initialize() st.start() st.waitCacheChange(10000) #Wait stream be running before starting scan +#Pseudo-device returning the wire position +class w_pos(Readable): + def read(self): + return scanner.get_sel_wire_pos(st.getChildren()[0].take()) + #End of scan checking -scan_complete=False -cur_cycle = 1 +scan_complete = None +cur_cycle = None def check_end_scan(record, scan): global scan_complete,cur_cycle if record[3]<1: @@ -61,22 +67,41 @@ def check_end_scan(record, scan): #Metadata set_attribute("/", "Wire Scan", prefix) -set_attribute("/", "Selection", sel) -set_attribute("/", "Range", scanner.scan_range) -set_attribute("/", "Cycles", scanner.cycles ) -set_attribute("/", "Velocity", scanner.velocity ) +set_attribute("/", "Scan Type", scan_type) +set_attribute("/", "Range", scan_range) +set_attribute("/", "Cycles", cycles) +set_attribute("/", "Velocity", velocity) -#Scan -try: - print "Starting scan..." - scanner.scan() #scanner.waitState(State.Busy, 60000) Not needed as stream filter will make the wait - mscan (st, st.getReadables(), -1, -1, after_read = check_end_scan) -except: - if not scanner.isReady(): - print "Aborting Wire Scan" - scanner.abort() - if not scan_complete: - raise +#Scan + +def do_scan(): + global scan_complete, cur_cycle + scan_complete=False + cur_cycle = 1 + try: + scanner.scan() #scanner.waitState(State.Busy, 60000) Not needed as stream filter will make the wait + mscan (st, [w_pos()] + st.getReadables(), -1, -1, after_read = check_end_scan) + except: + if not scanner.isReady(): + print "Aborting scan" + scanner.abort() + if not scan_complete: + raise + + +print "Starting scan..." +try: + set_exec_pars(group=scan_type in [WireScanner.WireY1, WireScanner.WireY1] ? "y_{count}" : "x_{count}"); + do_scan() + if scan_type in [WireScanner.Set1, WireScanner.Set2]: + scanner.set_selection(get_scan_selection(scan_type)) + scanner.curr_cycl.write(0) + scanner.set_selection(get_scan_selection(scan_type, 1)) + scanner.init() + scanner.waitValue("At start", 60000) + set_exec_pars(group="y_{count}", reset=True) + do_scan() + finally: print "Closing scanner" scanner.close() diff --git a/script/test/SchottkyStreamTest.py b/script/test/SchottkyStreamTest.py new file mode 100644 index 0000000..f689946 --- /dev/null +++ b/script/test/SchottkyStreamTest.py @@ -0,0 +1,11 @@ +st = Stream("ICTstream", dispatcher) +q = st.addScalar("Charge", "SINEG01-DICT215:B1_CHARGE", 1, 0) +st.initialize() +st.start() + + +try: + qb = create_averager(q, 5, 0.100) + r = tscan((qb), 10, 1.0) +finally: + st.close() diff --git a/script/test/TestMscan.py b/script/test/TestMscan.py new file mode 100644 index 0000000..b92b9df --- /dev/null +++ b/script/test/TestMscan.py @@ -0,0 +1,25 @@ +prefix = "S30CB09-DWSC440" +prefix = "SINDI01-DWSC090" + +channels = [("m_pos", prefix+":ENC_1_BS"), + #("cur_cycle", prefix+":CURR_CYCL"), + # ("scanning", prefix+":SCANNING") + ] + + + +class w_pos(Readable): + def read(self): + return st.getChildren()[0].take() + +st = Stream("pulse_id", dispatcher) +for c in channels: + st.addScalar(c[0], c[1], 10, 0) +st.initialize() +st.start() + + +try: + mscan (st, [w_pos()] + st.getReadables(), 10) +finally: + st.close()