Files
ncs/plugins/Kollimators.java
2015-12-02 15:40:42 +01:00

318 lines
15 KiB
Java

import ch.psi.jcae.Channel;
import ch.psi.jcae.ChannelException;
import ch.psi.pshell.device.Device;
import ch.psi.pshell.device.DeviceAdapter;
import ch.psi.pshell.epics.ChannelDouble;
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;
import java.util.logging.Logger;
import javax.swing.JTextField;
/*
* Copyright (c) 2015 Paul Scherrer Institute. All rights reserved.
*/
/**
*
* @author boccioli_m
*/
public class Kollimators extends javax.swing.JPanel {
/**
* Creates new form Kollimators
*
* @param params currently not used
*/
public Kollimators(String params) {
initComponents();
}
ChannelDouble channel;
String g_deviceName;
//Overridable callbacks
public void onInitialize(int runCount) {
initComponents();
}
/**
* 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(channelName, channelName, 3);
channel.setMonitored(true);
channel.initialize();
channel.addListener(new DeviceAdapter() {
@Override
public void onValueChanged(Device channelName, Object value, Object former) {
Double val = (Double )value;
textField.setText(String.valueOf(val));
textField.setToolTipText(channelName.getName());
}
});
//channel.close();
} catch (Exception ex) {
System.out.println(ex.toString());
}
}
/**
* 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);
connect(deviceName+":STA2:1", jTextSta);
connect(deviceName+":IST1:1", jTextDist);
connect(deviceName+":IST1:1", jTextIst1);
connect(deviceName+":IST2:1", jTextIst2);
connect(deviceName+":REF1:1", jTextRef1);
connect(deviceName+":REF2:1", jTextRef2);
connect(deviceName+":IST1:1", jTextDir);
connect(deviceName+":STA2:1", jTextRes);
}
/**
* 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
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jTextSta = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jTextIst1 = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jTextIst2 = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
jTextDir = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
jTextRef1 = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
jTextRef2 = new javax.swing.JTextField();
jLabel7 = new javax.swing.JLabel();
jTextDist = new javax.swing.JTextField();
jTextRes = new javax.swing.JTextField();
jLabel8 = new javax.swing.JLabel();
jLabelDeviceName = new javax.swing.JLabel();
jButtonReconnect = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
jLabel1.setText("STA:");
jTextSta.setEditable(false);
jLabel2.setText("IST1:");
jTextIst1.setEditable(false);
jLabel3.setText("IST2:");
jTextIst2.setEditable(false);
jLabel4.setText("Direction:");
jTextDir.setEditable(false);
jLabel5.setText("REF1:");
jTextRef1.setEditable(false);
jLabel6.setText("REF2:");
jTextRef2.setEditable(false);
jLabel7.setText("DIST:");
jTextDist.setEditable(false);
jTextRes.setEditable(false);
jLabel8.setText("Resolution:");
jLabelDeviceName.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
jLabelDeviceName.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
jButtonReconnect.setText("Refresh");
jButtonReconnect.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonReconnectActionPerformed(evt);
}
});
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(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(3, 3, 3)
.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)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextSta, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextIst1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jLabel7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextDist, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextIst2, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextRef1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextRef2, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextDir, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel8)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextRes, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(0, 0, 0))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(0, 0, 0)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jTextSta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2)
.addComponent(jTextIst1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5)
.addComponent(jTextRef1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4)
.addComponent(jTextDir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabelDeviceName, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jTextIst2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6)
.addComponent(jTextRef2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7)
.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(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(g_deviceName);
}//GEN-LAST:event_jButtonReconnectActionPerformed
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;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabelDeviceName;
private javax.swing.JTextField jTextDir;
private javax.swing.JTextField jTextDist;
private javax.swing.JTextField jTextIst1;
private javax.swing.JTextField jTextIst2;
private javax.swing.JTextField jTextRef1;
private javax.swing.JTextField jTextRef2;
private javax.swing.JTextField jTextRes;
private javax.swing.JTextField jTextSta;
// End of variables declaration//GEN-END:variables
// </editor-fold>
}