From 1809c74aef8e363931be74267831a3bd50577519 Mon Sep 17 00:00:00 2001 From: gac-x12sa Date: Thu, 5 Jan 2023 11:34:00 +0100 Subject: [PATCH] Closedown --- plugins/Eiger.form | 176 +++++++++++++++++++++++- plugins/Eiger.java | 267 +++++++++++++++++++++++++++++++++++-- script/devices/Detector.py | 5 +- 3 files changed, 431 insertions(+), 17 deletions(-) diff --git a/plugins/Eiger.form b/plugins/Eiger.form index 118fad5..e49035c 100644 --- a/plugins/Eiger.form +++ b/plugins/Eiger.form @@ -17,7 +17,10 @@ - + + + + @@ -26,9 +29,13 @@ - + - + + + + + @@ -52,15 +59,85 @@ - + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -74,12 +151,12 @@ - + - + @@ -91,5 +168,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/Eiger.java b/plugins/Eiger.java index 614fceb..f4c7da3 100644 --- a/plugins/Eiger.java +++ b/plugins/Eiger.java @@ -1,13 +1,19 @@ +import ch.psi.pshell.device.Device; import ch.psi.pshell.ui.Panel; +import ch.psi.utils.EncoderJson; import ch.psi.utils.State; +import ch.psi.utils.swing.ScriptDialog; import java.nio.file.Paths; +import java.util.Map; /** * */ public class Eiger extends Panel { final String RENDERER_PERSIST_FILE = "{context}/EigerRenderer"; + Device detector; + Device stddaq; public Eiger() { initComponents(); @@ -17,11 +23,27 @@ public class Eiger extends Panel { //Overridable callbacks @Override public void onInitialize(int runCount) { + detector = (Device) getDevice("detector"); + stddaq = (Device) getDevice("std_daq"); } + void updateControls(){ + boolean enabled = getState().isReady(); + + buttonStart.setEnabled(enabled && ((stddaq!=null) || (stddaq.getState().isReady()))); + buttonStop.setEnabled(enabled && ((stddaq!=null) || (stddaq.getState()==State.Busy))); + buttonConfig.setEnabled(enabled && ((stddaq!=null) || (stddaq.getState().isInitialized()))); + + buttonStartDet.setEnabled(enabled && ((detector!=null) || (detector.getState().isReady()))); + buttonStopDet.setEnabled(enabled && ((detector!=null) || (detector.getState()==State.Busy))); + buttonConfigDet.setEnabled(enabled && ((detector!=null) || (detector.getState().isInitialized()))); + buttonParsDet.setEnabled(enabled && ((detector!=null) || (detector.getState().isInitialized()))); + + } + @Override public void onStateChange(State state, State former) { - + updateControls(); } @Override @@ -52,20 +74,86 @@ public class Eiger extends Panel { private void initComponents() { jPanel1 = new javax.swing.JPanel(); + buttonStartDet = new javax.swing.JButton(); + buttonStopDet = new javax.swing.JButton(); + buttonConfigDet = new javax.swing.JButton(); + deviceStatePanel2 = new ch.psi.pshell.swing.DeviceStatePanel(); + buttonParsDet = new javax.swing.JButton(); jPanel2 = new javax.swing.JPanel(); renderer = new ch.psi.pshell.imaging.Renderer(); + jPanel3 = new javax.swing.JPanel(); + buttonStart = new javax.swing.JButton(); + buttonStop = new javax.swing.JButton(); + buttonConfig = new javax.swing.JButton(); + deviceStatePanel1 = new ch.psi.pshell.swing.DeviceStatePanel(); jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder("Detector"))); + buttonStartDet.setText("Start"); + buttonStartDet.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonStartDetActionPerformed(evt); + } + }); + + buttonStopDet.setText("Stop"); + buttonStopDet.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonStopDetActionPerformed(evt); + } + }); + + buttonConfigDet.setText("Config"); + buttonConfigDet.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonConfigDetActionPerformed(evt); + } + }); + + deviceStatePanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("State")); + deviceStatePanel2.setDeviceName("detector"); + + buttonParsDet.setText("Pars"); + buttonParsDet.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonParsDetActionPerformed(evt); + } + }); + javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 238, Short.MAX_VALUE) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(buttonStartDet) + .addComponent(buttonStopDet) + .addComponent(buttonConfigDet) + .addComponent(buttonParsDet)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap() + .addComponent(deviceStatePanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(25, Short.MAX_VALUE)) ); + + jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonConfigDet, buttonParsDet, buttonStartDet, buttonStopDet}); + jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 0, Short.MAX_VALUE) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap() + .addComponent(buttonStartDet) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonStopDet) + .addGap(18, 18, Short.MAX_VALUE) + .addComponent(buttonConfigDet) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonParsDet) + .addGap(18, 18, Short.MAX_VALUE) + .addComponent(deviceStatePanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Stream")); @@ -76,11 +164,70 @@ public class Eiger extends Panel { jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, 434, Short.MAX_VALUE) + .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, 454, Short.MAX_VALUE) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, 349, Short.MAX_VALUE) + .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + ); + + jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder("Detector"), "STD DAQ")); + + buttonStart.setText("Start"); + buttonStart.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonStartActionPerformed(evt); + } + }); + + buttonStop.setText("Stop"); + buttonStop.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonStopActionPerformed(evt); + } + }); + + buttonConfig.setText("Config"); + buttonConfig.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonConfigActionPerformed(evt); + } + }); + + deviceStatePanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("State")); + deviceStatePanel1.setDeviceName("std_daq"); + + javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); + jPanel3.setLayout(jPanel3Layout); + jPanel3Layout.setHorizontalGroup( + jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel3Layout.createSequentialGroup() + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(buttonStart) + .addComponent(buttonStop) + .addComponent(buttonConfig)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(jPanel3Layout.createSequentialGroup() + .addContainerGap() + .addComponent(deviceStatePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(25, Short.MAX_VALUE)) + ); + + jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonConfig, buttonStart, buttonStop}); + + jPanel3Layout.setVerticalGroup( + jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel3Layout.createSequentialGroup() + .addContainerGap() + .addComponent(buttonStart) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonStop) + .addGap(18, 18, Short.MAX_VALUE) + .addComponent(buttonConfig) + .addGap(18, 18, Short.MAX_VALUE) + .addComponent(deviceStatePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); @@ -88,23 +235,127 @@ public class Eiger extends Panel { layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addGap(0, 0, 0)) ); }// //GEN-END:initComponents + private void buttonConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonConfigActionPerformed + + }//GEN-LAST:event_buttonConfigActionPerformed + + private void buttonConfigDetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonConfigDetActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_buttonConfigDetActionPerformed + + private void buttonParsDetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonParsDetActionPerformed + try{ + if (stddaq!=null){ + String title = "Detector Parameters"; + this.evalAsync("detector.get_pars()").handle((ret,ex)->{ + if (ex!=null){ + showException((Exception) ex); + } else { + try{ + Map cfg = (Map) ret; + String json = EncoderJson.encode(cfg, true); + ScriptDialog dlg = new ScriptDialog(getWindow(), true, title, json, "json"); + dlg.setVisible(true); + if (dlg.getResult()){ + json = dlg.getText(); + cfg = (Map) EncoderJson.decode(json, Map.class); + setGlobalVar("_detector_config", cfg); + evalAsync("detector.set_pars(_detector_config)").handle((r,e)->{ + if (e!=null){ + showException((Exception) e); + } else { + showMessage(title, "Success"); + } + return ret; + }); + } + } catch (Exception e){ + showException(e); + } + } + + return ret; + }); + + + } + } catch (Exception ex){ + showException(ex); + } + }//GEN-LAST:event_buttonParsDetActionPerformed + + private void buttonStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStartActionPerformed + try{ + if (stddaq!=null){ + evalAsync("stddaq.start()"); + } + } catch (Exception ex){ + showException(ex); + } + }//GEN-LAST:event_buttonStartActionPerformed + + private void buttonStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStopActionPerformed + try{ + if (stddaq!=null){ + evalAsync("stddaq.stop()"); + } + } catch (Exception ex){ + showException(ex); + } + }//GEN-LAST:event_buttonStopActionPerformed + + private void buttonStartDetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStartDetActionPerformed + try{ + if (stddaq!=null){ + evalAsync("detector.start()"); + } + } catch (Exception ex){ + showException(ex); + } + }//GEN-LAST:event_buttonStartDetActionPerformed + + private void buttonStopDetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStopDetActionPerformed + try{ + if (stddaq!=null){ + evalAsync("detector.stop()"); + } + } catch (Exception ex){ + showException(ex); + } + }//GEN-LAST:event_buttonStopDetActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton buttonConfig; + private javax.swing.JButton buttonConfigDet; + private javax.swing.JButton buttonParsDet; + private javax.swing.JButton buttonStart; + private javax.swing.JButton buttonStartDet; + private javax.swing.JButton buttonStop; + private javax.swing.JButton buttonStopDet; + private ch.psi.pshell.swing.DeviceStatePanel deviceStatePanel1; + private ch.psi.pshell.swing.DeviceStatePanel deviceStatePanel2; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; + private javax.swing.JPanel jPanel3; private ch.psi.pshell.imaging.Renderer renderer; // End of variables declaration//GEN-END:variables } diff --git a/script/devices/Detector.py b/script/devices/Detector.py index a406591..f52eb8a 100644 --- a/script/devices/Detector.py +++ b/script/devices/Detector.py @@ -6,10 +6,11 @@ class Detector(DeviceBase): DeviceBase.doInitialize(self) def start(): - print "startd" + setState(State.Busy) def stop(): - print "stopd" + setState(State.Ready) + def doClose(self): DeviceBase.doClose(self) \ No newline at end of file