Code clean-up
This commit is contained in:
@@ -8,6 +8,7 @@ import ch.psi.utils.State;
|
||||
import gov.aps.jca.CAException;
|
||||
import gov.aps.jca.Context;
|
||||
import gov.aps.jca.JCALibrary;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Level;
|
||||
@@ -32,7 +33,6 @@ public class Kollimators extends javax.swing.JPanel {
|
||||
*/
|
||||
public Kollimators(String params) {
|
||||
initComponents();
|
||||
//connect("");
|
||||
}
|
||||
|
||||
ChannelDouble channel;
|
||||
@@ -41,21 +41,27 @@ public class Kollimators extends javax.swing.JPanel {
|
||||
//Overridable callbacks
|
||||
public void onInitialize(int runCount) {
|
||||
initComponents();
|
||||
//connect("");
|
||||
}
|
||||
|
||||
public void connect(String device, JTextField textField) {
|
||||
/**
|
||||
* Connect to the PVs.
|
||||
* And animate the corresponding test field on the panel.
|
||||
*
|
||||
* @param channelName name of the channel to connect to. Example: KMA5:STA2:1
|
||||
* @param textField name of the text field to animate with the value of the channel
|
||||
*/
|
||||
public void connect(String channelName, JTextField textField) {
|
||||
try {
|
||||
ChannelDouble channel = new ChannelDouble(device, device, 3);
|
||||
ChannelDouble channel = new ChannelDouble(channelName, channelName, 3);
|
||||
channel.setMonitored(true);
|
||||
channel.initialize();
|
||||
|
||||
channel.addListener(new DeviceAdapter() {
|
||||
@Override
|
||||
public void onValueChanged(Device device, Object value, Object former) {
|
||||
public void onValueChanged(Device channelName, Object value, Object former) {
|
||||
Double val = (Double )value;
|
||||
textField.setText(String.valueOf(val));
|
||||
textField.setToolTipText(device.getName());
|
||||
textField.setToolTipText(channelName.getName());
|
||||
}
|
||||
});
|
||||
//channel.close();
|
||||
@@ -64,10 +70,13 @@ public class Kollimators extends javax.swing.JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
private void monitorChannel(ChannelDouble channel, Object textField){
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* animate the panel (caget/caset).
|
||||
* Called from TestingList.
|
||||
* This function MUST EXISTS in every custom panel callable from TestingList
|
||||
* @param deviceName string containing the device name (without pv name, i.e. KMA5 and not KMA5:COM:1)
|
||||
*/
|
||||
public void animate(String deviceName) {
|
||||
g_deviceName = deviceName;
|
||||
jLabelDeviceName.setText(deviceName);
|
||||
@@ -81,23 +90,35 @@ public class Kollimators extends javax.swing.JPanel {
|
||||
connect(deviceName+":STA2:1", jTextRes);
|
||||
}
|
||||
|
||||
public void animate() {
|
||||
animate(g_deviceName);
|
||||
}
|
||||
/**
|
||||
* Send stop command to the motor.
|
||||
* Send signal 0 to the motor communication channel
|
||||
*/
|
||||
public void stopMotor() {
|
||||
try {
|
||||
ChannelDouble channel = new ChannelDouble(g_deviceName+":COM:2", g_deviceName+":COM:2", 0);
|
||||
Object stopVal = 0;
|
||||
channel.write( (Double) stopVal);
|
||||
} catch (InterruptedException ex) {
|
||||
System.out.println(ex.toString());
|
||||
} catch (IOException ex) {
|
||||
System.out.println(ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void onStateChange(State state, State former) {
|
||||
|
||||
}
|
||||
|
||||
public void onExecutedFile(String fileName, Object result) {
|
||||
}
|
||||
|
||||
|
||||
//Callback to perform update - in event thread
|
||||
protected void doUpdate() {
|
||||
}
|
||||
|
||||
|
||||
private void monitorChannel(ChannelDouble channel, Object textField){
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
@@ -125,6 +146,7 @@ public class Kollimators extends javax.swing.JPanel {
|
||||
jLabel8 = new javax.swing.JLabel();
|
||||
jLabelDeviceName = new javax.swing.JLabel();
|
||||
jButtonReconnect = new javax.swing.JButton();
|
||||
jButton1 = new javax.swing.JButton();
|
||||
|
||||
jLabel1.setText("STA:");
|
||||
|
||||
@@ -168,6 +190,13 @@ public class Kollimators extends javax.swing.JPanel {
|
||||
}
|
||||
});
|
||||
|
||||
jButton1.setText("Stop motor");
|
||||
jButton1.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton1ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
@@ -176,9 +205,11 @@ public class Kollimators extends javax.swing.JPanel {
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(3, 3, 3)
|
||||
.addComponent(jLabelDeviceName, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE))
|
||||
.addComponent(jLabelDeviceName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(jButtonReconnect)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jButton1)
|
||||
.addGap(0, 0, Short.MAX_VALUE)))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
@@ -244,56 +275,25 @@ public class Kollimators extends javax.swing.JPanel {
|
||||
.addComponent(jTextDist, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(jLabel8)
|
||||
.addComponent(jTextRes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(jButtonReconnect))
|
||||
.addComponent(jButtonReconnect)
|
||||
.addComponent(jButton1))
|
||||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void jButtonReconnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonReconnectActionPerformed
|
||||
// TODO add your handling code here:
|
||||
animate();
|
||||
animate(g_deviceName);
|
||||
}//GEN-LAST:event_jButtonReconnectActionPerformed
|
||||
|
||||
|
||||
/**
|
||||
* animate the panel (caget/caset). Called from TestingList.
|
||||
* This function MUST EXISTS in every custom panel callable from TestingList
|
||||
* @param deviceName
|
||||
*/
|
||||
public void animateOld(String deviceName) {
|
||||
try {
|
||||
|
||||
this.jLabelDeviceName.setText(deviceName);
|
||||
this.jTextDir.setToolTipText(deviceName+"?");
|
||||
this.jTextDist.setToolTipText(deviceName+"?");
|
||||
this.jTextIst1.setToolTipText(deviceName+":IST1:1");
|
||||
this.jTextIst2.setToolTipText(deviceName+":IST2:1");
|
||||
this.jTextRef1.setToolTipText(deviceName+":REF1:1");
|
||||
this.jTextRef2.setToolTipText(deviceName+":REF2:1");
|
||||
this.jTextRes.setToolTipText(deviceName+"?");
|
||||
this.jTextSta.setToolTipText(deviceName+":STA:2");
|
||||
|
||||
JCALibrary jca= JCALibrary.getInstance();
|
||||
Context ctxt= jca.createContext(JCALibrary.JNI_SINGLE_THREADED);
|
||||
// Create the Channel to connect to the PV.
|
||||
Channel ch= (Channel) ctxt.createChannel("SIM-MMAC3:STR:2");
|
||||
System.out.println("channel created");
|
||||
this.jTextIst1.setText(String.valueOf(ch.getValue()));
|
||||
System.out.println("value got");
|
||||
} catch (CAException ex) {
|
||||
System.out.println(ex.toString());
|
||||
} catch (InterruptedException ex) {
|
||||
System.out.println(ex.toString());
|
||||
} catch (TimeoutException ex) {
|
||||
System.out.println(ex.toString());
|
||||
} catch (ChannelException ex) {
|
||||
System.out.println(ex.toString());
|
||||
} catch (ExecutionException ex) {
|
||||
System.out.println(ex.toString());
|
||||
}
|
||||
}
|
||||
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
|
||||
// TODO add your handling code here:
|
||||
stopMotor();
|
||||
}//GEN-LAST:event_jButton1ActionPerformed
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="Variables declaration">
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton jButton1;
|
||||
private javax.swing.JButton jButtonReconnect;
|
||||
private javax.swing.JLabel jLabel1;
|
||||
private javax.swing.JLabel jLabel2;
|
||||
@@ -313,4 +313,5 @@ public class Kollimators extends javax.swing.JPanel {
|
||||
private javax.swing.JTextField jTextRes;
|
||||
private javax.swing.JTextField jTextSta;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
// </editor-fold>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user