package org.hwo.pulscounter.ui; import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import org.hwo.datetime.DateTime; import org.hwo.pulscounter.PulsCounterApplication; import org.hwo.pulscounter.PulsCounterApplicationListener; import org.hwo.servicelink.ServiceLinkException; import java.awt.GridBagLayout; import javax.swing.JLabel; import java.awt.GridBagConstraints; import java.awt.Insets; import java.io.IOException; import java.util.Timer; import java.util.TimerTask; import javax.swing.JTextField; import javax.swing.DefaultListModel; import javax.swing.JButton; import javax.swing.JList; import javax.swing.JScrollPane; public class DeviceTestFrame extends JFrame { //implements PulsCounterApplicationListener { // private JPanel contentPane; // private JTextField tfCommunication; // private JTextField tfEEPROM; // private JTextField tfIO; // private JTextField tfAD; // private JTextField tfSerial; // // private Timer reconnectTimer; // // private DeviceChecker deviceChecker; // private JList lMessages; // private DefaultListModel messageListModel; // // private PulsCounterApplication pulsCounterApplication; // // /** // * Create the frame. // */ // public DeviceTestFrame(PulsCounterApplication pulsCounterApplication) { // this.pulsCounterApplication = pulsCounterApplication; // // setTitle("Device Test Frame"); // setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // setBounds(100, 100, 701, 464); // contentPane = new JPanel(); // contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); // setContentPane(contentPane); // GridBagLayout gbl_contentPane = new GridBagLayout(); // gbl_contentPane.columnWidths = new int[]{0, 0, 0}; // gbl_contentPane.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0}; // gbl_contentPane.columnWeights = new double[]{1.0, 1.0, Double.MIN_VALUE}; // gbl_contentPane.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE}; // contentPane.setLayout(gbl_contentPane); // // JLabel lblKommunikation = new JLabel("Communication:"); // GridBagConstraints gbc_lblKommunikation = new GridBagConstraints(); // gbc_lblKommunikation.anchor = GridBagConstraints.EAST; // gbc_lblKommunikation.insets = new Insets(0, 0, 5, 5); // gbc_lblKommunikation.gridx = 0; // gbc_lblKommunikation.gridy = 0; // contentPane.add(lblKommunikation, gbc_lblKommunikation); // // tfCommunication = new JTextField(); // GridBagConstraints gbc_tfCommunication = new GridBagConstraints(); // gbc_tfCommunication.insets = new Insets(0, 0, 5, 0); // gbc_tfCommunication.fill = GridBagConstraints.HORIZONTAL; // gbc_tfCommunication.gridx = 1; // gbc_tfCommunication.gridy = 0; // contentPane.add(tfCommunication, gbc_tfCommunication); // tfCommunication.setColumns(10); // // JLabel lblLeds = new JLabel("LEDs:"); // GridBagConstraints gbc_lblLeds = new GridBagConstraints(); // gbc_lblLeds.insets = new Insets(0, 0, 5, 5); // gbc_lblLeds.gridx = 0; // gbc_lblLeds.gridy = 1; // contentPane.add(lblLeds, gbc_lblLeds); // // JLabel lblEeprom = new JLabel("EEPROM:"); // GridBagConstraints gbc_lblEeprom = new GridBagConstraints(); // gbc_lblEeprom.anchor = GridBagConstraints.EAST; // gbc_lblEeprom.insets = new Insets(0, 0, 5, 5); // gbc_lblEeprom.gridx = 0; // gbc_lblEeprom.gridy = 2; // contentPane.add(lblEeprom, gbc_lblEeprom); // // tfEEPROM = new JTextField(); // GridBagConstraints gbc_tfEEPROM = new GridBagConstraints(); // gbc_tfEEPROM.insets = new Insets(0, 0, 5, 0); // gbc_tfEEPROM.fill = GridBagConstraints.HORIZONTAL; // gbc_tfEEPROM.gridx = 1; // gbc_tfEEPROM.gridy = 2; // contentPane.add(tfEEPROM, gbc_tfEEPROM); // tfEEPROM.setColumns(10); // // JLabel lblIoCircuit = new JLabel("I/O Circuit:"); // GridBagConstraints gbc_lblIoCircuit = new GridBagConstraints(); // gbc_lblIoCircuit.anchor = GridBagConstraints.EAST; // gbc_lblIoCircuit.insets = new Insets(0, 0, 5, 5); // gbc_lblIoCircuit.gridx = 0; // gbc_lblIoCircuit.gridy = 3; // contentPane.add(lblIoCircuit, gbc_lblIoCircuit); // // tfIO = new JTextField(); // GridBagConstraints gbc_tfIO = new GridBagConstraints(); // gbc_tfIO.insets = new Insets(0, 0, 5, 0); // gbc_tfIO.fill = GridBagConstraints.HORIZONTAL; // gbc_tfIO.gridx = 1; // gbc_tfIO.gridy = 3; // contentPane.add(tfIO, gbc_tfIO); // tfIO.setColumns(10); // // JLabel lblAdConverters = new JLabel("A/D Converters:"); // GridBagConstraints gbc_lblAdConverters = new GridBagConstraints(); // gbc_lblAdConverters.anchor = GridBagConstraints.EAST; // gbc_lblAdConverters.insets = new Insets(0, 0, 5, 5); // gbc_lblAdConverters.gridx = 0; // gbc_lblAdConverters.gridy = 4; // contentPane.add(lblAdConverters, gbc_lblAdConverters); // // tfAD = new JTextField(); // GridBagConstraints gbc_tfAD = new GridBagConstraints(); // gbc_tfAD.insets = new Insets(0, 0, 5, 0); // gbc_tfAD.fill = GridBagConstraints.HORIZONTAL; // gbc_tfAD.gridx = 1; // gbc_tfAD.gridy = 4; // contentPane.add(tfAD, gbc_tfAD); // tfAD.setColumns(10); // // JLabel lblSerial = new JLabel("Serial:"); // GridBagConstraints gbc_lblSerial = new GridBagConstraints(); // gbc_lblSerial.anchor = GridBagConstraints.EAST; // gbc_lblSerial.insets = new Insets(0, 0, 5, 5); // gbc_lblSerial.gridx = 0; // gbc_lblSerial.gridy = 5; // contentPane.add(lblSerial, gbc_lblSerial); // // tfSerial = new JTextField(); // GridBagConstraints gbc_tfSerial = new GridBagConstraints(); // gbc_tfSerial.insets = new Insets(0, 0, 5, 0); // gbc_tfSerial.fill = GridBagConstraints.HORIZONTAL; // gbc_tfSerial.gridx = 1; // gbc_tfSerial.gridy = 5; // contentPane.add(tfSerial, gbc_tfSerial); // tfSerial.setColumns(10); // // JButton btnSetDevice = new JButton("Confirm Device"); // GridBagConstraints gbc_btnSetDevice = new GridBagConstraints(); // gbc_btnSetDevice.insets = new Insets(0, 0, 5, 0); // gbc_btnSetDevice.gridx = 1; // gbc_btnSetDevice.gridy = 6; // contentPane.add(btnSetDevice, gbc_btnSetDevice); // // JScrollPane scrollPane = new JScrollPane(); // GridBagConstraints gbc_scrollPane = new GridBagConstraints(); // gbc_scrollPane.fill = GridBagConstraints.BOTH; // gbc_scrollPane.gridwidth = 2; // gbc_scrollPane.insets = new Insets(0, 0, 0, 5); // gbc_scrollPane.gridx = 0; // gbc_scrollPane.gridy = 7; // contentPane.add(scrollPane, gbc_scrollPane); // // lMessages = new JList(); // scrollPane.setViewportView(lMessages); // // this.initialize(); // } // // private PulsCounterApplication application(){ // return this.pulsCounterApplication; // } // // private void initialize(){ // this.reconnectTimer = new Timer("Reconnection Timer"); // // messageListModel = new DefaultListModel(); // lMessages.setModel(messageListModel); // // application().addPulsCounterApplicationListener(this); // // setVisible(true); // } // // /* // @Override // public void connectionStateChanged(Boolean connected) { // // if (!connected){ // tfCommunication.setText("NO CONNECTION"); // if (this.deviceChecker != null){ // this.deviceChecker.cancel(); // } // reconnectTimer.schedule(new TimerTask() { // // @Override // public void run() { // if (!application().getServiceLink().isOpen()){ // try { // application().getServiceLink().open(); // } catch (ServiceLinkException e) { // e.printStackTrace(); // } // } // } // }, 3000); // // } else { // if (this.deviceChecker != null){ // while (this.deviceChecker.isAlive()){ // try { // Thread.sleep(100); // } catch (InterruptedException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // } // } // this.deviceChecker = new DeviceChecker(); // this.deviceChecker.start(); // } // // } // */ // // @Override // public synchronized void messageArrived(String message) { // if (EventQueue.isDispatchThread()){ // int pos = messageListModel.size(); // String t = String.format("%s: %s",DateTime.NOW().getSQLDateTime(),message); // messageListModel.addElement(t); // lMessages.ensureIndexIsVisible(messageListModel.size()-1); // } else { // final String msg = message; // EventQueue.invokeLater(new Runnable() { // // @Override // public void run() { // messageArrived(msg); // } // }); // } // } // // // class DeviceChecker extends Thread { // // private boolean cancel; // // public DeviceChecker(){ // cancel = false; // } // // public void cancel(){ // this.cancel = true; // } // // @Override // public void run() { // // checkCommunication(); // checkEEPROM(); // checkIO(); // checkADC(); // // while (!cancel){ // checkCommunication(); // } // // } // // private void checkCommunication(){ // if (!this.cancel){ // Integer version = application().getServiceLink().getServiceRegisterCache().getCachedInteger(13, 0, 0x001A); // Integer uptime = application().getServiceLink().getServiceRegisterCache().getCachedInteger(13, 0, 0x0022); // // if ((version != null)&&(uptime != null)){ // tfCommunication.setText(String.format("OK (V: %d.%d.%d) Up: %d:%d:%d",version >> 16, (version >> 8) & 0xff, version & 0xff, uptime / 3600, (uptime / 60)%60, uptime % 60)); // } // } // } // // private void checkEEPROM(){ // if (!this.cancel){ // Integer eesize = application().getServiceLink().getServiceRegisterCache().getCachedInteger(13, 0, 0x9000); // if (eesize != null){ // tfEEPROM.setText(String.format("EEPROM Size Detected: 0x%08x Bytes (%d kBytes)", eesize, (eesize >> 10))); // } else { // tfEEPROM.setText("EEPROM failed."); // } // } // } // // private void checkIO(){ // if (!this.cancel){ // // application().message("I/O test begins..."); // application().message("I/O reset..."); // // try { // application().getServiceLink().writeInt(13, 0, 0x0682, 0); // application().getServiceLink().writeInt(13, 0, 0x0683, 0); // application().getServiceLink().writeInt(13, 0, 0x0684, 0); // application().getServiceLink().writeInt(13, 0, 0x0685, 0); // // application().message("counter reset."); // for (int i=0;i<32;i++){ // application().getServiceLink().writeInt(13, 0, 0x0600 + i, 0); // } // // application().message("PullUP-Counter test."); // for (int i=0;i<12;i++){ // Thread.sleep(250); // application().getServiceLink().writeInt(13, 0, 0x0683, -1); // Thread.sleep(250); // application().getServiceLink().writeInt(13, 0, 0x0683, 0); // } // // for (int i=0;i<32;i++){ // Thread.sleep(100); // // Integer c = application().getServiceLink().readInt(13, 0, 0x0600 + i); // if ((c != null) && (c.equals(12))){ // application().message(String.format("OK: Channel %d counted %d events.", i, c)); // } else { // application().message(String.format("FAILED: Channel %d counted %d events.", i, c)); // } // } // // // // application().message("I/O test finished!"); // } catch (IOException | ServiceLinkException e) { // e.printStackTrace(); // // application().message("I/O test FAILED!"); // } catch (InterruptedException iex){ // iex.printStackTrace(); // // application().message("I/O test FAILED!"); // } // // // // } // } // // private void checkADC(){ // if (!this.cancel){ // } // } // // } // // // @Override // public void interfaceClassesChanged(PulsCounterApplication pulsCounterApplication) { // // TODO Auto-generated method stub // // } // // @Override // public void interfacesChanged(PulsCounterApplication pulsCounterApplication) { // // TODO Auto-generated method stub // // } }