Added connection to records on custom panel.
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
|
||||
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;
|
||||
@@ -8,6 +12,7 @@ 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.
|
||||
@@ -27,7 +32,70 @@ public class Kollimators extends javax.swing.JPanel {
|
||||
*/
|
||||
public Kollimators(String params) {
|
||||
initComponents();
|
||||
//connect("");
|
||||
}
|
||||
|
||||
ChannelDouble channel;
|
||||
String g_deviceName;
|
||||
|
||||
//Overridable callbacks
|
||||
public void onInitialize(int runCount) {
|
||||
initComponents();
|
||||
//connect("");
|
||||
}
|
||||
|
||||
public void connect(String device, JTextField textField) {
|
||||
try {
|
||||
ChannelDouble channel = new ChannelDouble(device, device, 3);
|
||||
channel.setMonitored(true);
|
||||
channel.initialize();
|
||||
|
||||
channel.addListener(new DeviceAdapter() {
|
||||
@Override
|
||||
public void onValueChanged(Device device, Object value, Object former) {
|
||||
Double val = (Double )value;
|
||||
textField.setText(String.valueOf(val));
|
||||
textField.setToolTipText(device.getName());
|
||||
}
|
||||
});
|
||||
//channel.close();
|
||||
} catch (Exception ex) {
|
||||
System.out.println(ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private void monitorChannel(ChannelDouble channel, Object textField){
|
||||
|
||||
}
|
||||
|
||||
public void animate(String deviceName) {
|
||||
g_deviceName = 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);
|
||||
}
|
||||
|
||||
public void animate() {
|
||||
animate(g_deviceName);
|
||||
}
|
||||
|
||||
public void onStateChange(State state, State former) {
|
||||
|
||||
}
|
||||
|
||||
public void onExecutedFile(String fileName, Object result) {
|
||||
}
|
||||
|
||||
|
||||
//Callback to perform update - in event thread
|
||||
protected void doUpdate() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
@@ -55,6 +123,7 @@ public class Kollimators extends javax.swing.JPanel {
|
||||
jTextRes = new javax.swing.JTextField();
|
||||
jLabel8 = new javax.swing.JLabel();
|
||||
jLabelDeviceName = new javax.swing.JLabel();
|
||||
jButton1 = new javax.swing.JButton();
|
||||
|
||||
jLabel1.setText("STA:");
|
||||
|
||||
@@ -91,13 +160,25 @@ public class Kollimators extends javax.swing.JPanel {
|
||||
jLabelDeviceName.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
|
||||
jLabelDeviceName.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
|
||||
|
||||
jButton1.setText("Reconnect");
|
||||
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()
|
||||
.addGap(3, 3, 3)
|
||||
.addComponent(jLabelDeviceName, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
|
||||
.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))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.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()
|
||||
@@ -161,18 +242,24 @@ public class Kollimators extends javax.swing.JPanel {
|
||||
.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(jTextRes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(jButton1))
|
||||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
|
||||
// TODO add your handling code here:
|
||||
animate();
|
||||
}//GEN-LAST:event_jButton1ActionPerformed
|
||||
|
||||
|
||||
/**
|
||||
* animate the panel (caget/caset). Called from TestingList.
|
||||
* This function MUST EXISTS in every custom panel callable from TestingList
|
||||
* @param deviceName
|
||||
*/
|
||||
public void animate(String deviceName) {
|
||||
public void animateOld(String deviceName) {
|
||||
try {
|
||||
|
||||
this.jLabelDeviceName.setText(deviceName);
|
||||
@@ -206,6 +293,7 @@ public class Kollimators extends javax.swing.JPanel {
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton jButton1;
|
||||
private javax.swing.JLabel jLabel1;
|
||||
private javax.swing.JLabel jLabel2;
|
||||
private javax.swing.JLabel jLabel3;
|
||||
|
||||
Reference in New Issue
Block a user