From f6c1a860ae68981298606c5e86da781d479a6a0a Mon Sep 17 00:00:00 2001 From: gac-x12sa Date: Thu, 5 Jan 2023 15:06:47 +0100 Subject: [PATCH] Closedown --- plugins/Eiger.java | 44 ++++++++++++++++++++++++++++++++------ script/devices/Detector.py | 23 ++++++++++++++++++-- script/devices/StdDaq.py | 3 ++- script/local.py | 2 +- 4 files changed, 62 insertions(+), 10 deletions(-) diff --git a/plugins/Eiger.java b/plugins/Eiger.java index f12b3e5..62efc33 100644 --- a/plugins/Eiger.java +++ b/plugins/Eiger.java @@ -349,18 +349,50 @@ public class Eiger extends Panel { } return ret; - }); - - + }); } } catch (Exception ex){ showException(ex); - } - + } }//GEN-LAST:event_buttonConfigActionPerformed private void buttonConfigDetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonConfigDetActionPerformed - // TODO add your handling code here: + try{ + if (stddaq!=null){ + String title = "Detector Config"; + this.evalAsync("detector.get_config()").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_config(_detector_config)").handle((r,e)->{ + if (e!=null){ + showException((Exception) e); + } else { + showMessage(title, "Success updating config"); + } + return ret; + }); + } + } catch (Exception e){ + showException(e); + } + } + + return ret; + }); + } + } catch (Exception ex){ + showException(ex); + } }//GEN-LAST:event_buttonConfigDetActionPerformed private void buttonParsDetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonParsDetActionPerformed diff --git a/script/devices/Detector.py b/script/devices/Detector.py index 5d6f23c..feb0301 100644 --- a/script/devices/Detector.py +++ b/script/devices/Detector.py @@ -1,8 +1,10 @@ class Detector(DeviceBase): - def __init__(self, name, simulated=False): - DeviceBase.__init__(self, name) + def __init__(self, name, url, simulated=False): + DeviceBase.__init__(self, name) + self.url = url if simulated: self.setSimulated() + self.simulated_config={'det_name': 'EIGER', 'dr': 16, 'exptime': 1.0, 'frames': 100, 'period': 0.01, 'speed': 'speedLevel.FULL_SPEED', 'tengiga': True, 'threshold': -1, 'timing': 'timingMode.AUTO_TIMING', 'triggers': 1} self.simulated_pars = {} def doInitialize(self): @@ -29,5 +31,22 @@ class Detector(DeviceBase): if self.simulated: self.simulated_pars=pars + def get_config(self): + if self.simulated: + return self.simulated_config + else: + return requests.get(url = "http://127.0.0.1:5000/detector/eiger") + + + def set_config(self, ): + if type(config) == dict or isinstance(config, java.util.Map) : + if self.simulated: + self.simulated_config=config + else: + data = {"det_name":"eiger","config":config} + headers = {'Content-type': 'application/json'} + r = requests.post(url = self.url + "/detector", json=data, headers=headers) + + def doClose(self): pass \ No newline at end of file diff --git a/script/devices/StdDaq.py b/script/devices/StdDaq.py index a893a6b..b98eec1 100644 --- a/script/devices/StdDaq.py +++ b/script/devices/StdDaq.py @@ -67,12 +67,13 @@ class StdDaq(DeviceBase): def get_config(self): if self.simulated: return self.simulated_config + #TODO def set_config(self, config): if type(config) == dict or isinstance(config, java.util.Map) : if self.simulated: self.simulated_config=config - + #TODO def doClose(self): pass diff --git a/script/local.py b/script/local.py index 5aacba7..15b6a86 100644 --- a/script/local.py +++ b/script/local.py @@ -29,5 +29,5 @@ add_device(RegisterMatrixSource("image", stream.devMatrix), True) stream.devMatrix.modulo = DETECTOR_IMAGE_MODULO -add_device(Detector("detector", True), True) +add_device(Detector("detector", STD_DAQ_ADDRESS, True), True) add_device(StdDaq("std_daq", STD_DAQ_ADDRESS, True), True) \ No newline at end of file