From 7f540c8ffa122b75ee39d4670d58a2414eb71c25 Mon Sep 17 00:00:00 2001 From: gac-x12sa Date: Fri, 16 Dec 2022 16:55:33 +0100 Subject: [PATCH] Creation --- config/config.properties | 49 +++++++++++++ config/mail.properties | 9 +++ config/plugins.properties | 1 + config/preferences.json | 136 ++++++++++++++++++++++++++++++++++++ config/setup.properties | 25 +++++++ devices/src_a10.properties | 25 +++++++ plugins/Eiger.form | 28 ++++++++ plugins/Eiger.java | 66 ++++++++++++++++++ script/devices/Array10.py | 138 +++++++++++++++++++++++++++++++++++++ script/local.groovy | 3 + script/local.js | 4 ++ script/local.py | 18 +++++ 12 files changed, 502 insertions(+) create mode 100644 config/config.properties create mode 100644 config/mail.properties create mode 100644 config/plugins.properties create mode 100644 config/preferences.json create mode 100644 config/setup.properties create mode 100644 devices/src_a10.properties create mode 100644 plugins/Eiger.form create mode 100644 plugins/Eiger.java create mode 100644 script/devices/Array10.py create mode 100644 script/local.groovy create mode 100644 script/local.js create mode 100644 script/local.py diff --git a/config/config.properties b/config/config.properties new file mode 100644 index 0000000..9a79a95 --- /dev/null +++ b/config/config.properties @@ -0,0 +1,49 @@ +#Fri Dec 16 16:55:24 CET 2022 +autoSaveScanData=true +simulation=false +dataScanSaveOutput=false +userAuthenticator= +dataScanSaveScript=false +notifiedTasks= +parallelInitialization=false +fdaSerialization=false +dataTransferPath= +saveConsoleSessionFiles=false +hostName= +disableEmbeddedAttributes=false +serverPort=8080 +versionTrackingEnabled=true +dataPath={data}/{year}_{month}/{date}/{date}_{time}_{name} +serverEnabled=false +depthDimension=0 +logLevel=Info +dataLayout=default +disableDataFileLogs=false +sessionHandling=Off +terminalEnabled=false +notificationLevel=Off +terminalPort=3579 +dataTransferUser= +versionTrackingLogin= +noBytecodeFiles=false +versionTrackingRemote= +logDaysToLive=-1 +logLevelConsole=Off +filePermissionsConfig=Default +scanStreamerPort=-1 +dataScanSaveSetpoints=false +versionTrackingManual=false +dataTransferMode=Off +userManagement=false +instanceName=x12sa +dataServerPort=-1 +hideServerMessages=false +dataScanReleaseRecords=false +dataScanPreserveTypes=false +dataScanFlushRecords=false +filePermissionsLogs=Default +logPath={logs}/{date}_{time} +filePermissionsScripts=Default +filePermissionsData=Default +dataProvider=h5 +saveCommandStatistics=false diff --git a/config/mail.properties b/config/mail.properties new file mode 100644 index 0000000..b6866af --- /dev/null +++ b/config/mail.properties @@ -0,0 +1,9 @@ +#Fri Dec 16 16:32:36 CET 2022 +port=0 +usr= +auth=None +smsSuffix=@sms.switch.ch +host= +from= +to= +pwd= diff --git a/config/plugins.properties b/config/plugins.properties new file mode 100644 index 0000000..25f89fb --- /dev/null +++ b/config/plugins.properties @@ -0,0 +1 @@ +Eiger.java=enabled diff --git a/config/preferences.json b/config/preferences.json new file mode 100644 index 0000000..b08de8f --- /dev/null +++ b/config/preferences.json @@ -0,0 +1,136 @@ +{ + "fontShellPanel" : { + "name" : "Monospaced", + "style" : 0, + "size" : 13 + }, + "fontShellCommand" : { + "name" : "SansSerif", + "style" : 0, + "size" : 13 + }, + "fontOutput" : { + "name" : "Monospaced", + "style" : 0, + "size" : 13 + }, + "fontEditor" : { + "name" : "Monospaced", + "style" : 0, + "size" : 13 + }, + "fontPlotLabel" : { + "name" : "SansSerif", + "style" : 0, + "size" : 11 + }, + "fontPlotTick" : { + "name" : "SansSerif", + "style" : 0, + "size" : 10 + }, + "fontPlotTitle" : { + "name" : "SansSerif", + "style" : 1, + "size" : 13 + }, + "fontTerminal" : { + "name" : "Monospaced", + "style" : 0, + "size" : 14 + }, + "tabSize" : 4, + "contentWidth" : 0, + "editorBackground" : null, + "editorForeground" : null, + "simpleEditor" : false, + "hideEditorLineNumbers" : false, + "hideEditorContextMenu" : false, + "consoleLocation" : "Left", + "dataPanelLocation" : "Status", + "openDataFilesInDocTab" : false, + "noVariableEvaluationPropagation" : false, + "processingScripts" : [ ], + "asyncViewersUpdate" : false, + "asyncHistoryPlotsUpdate" : true, + "scanPlotDisabled" : false, + "scanTableDisabled" : false, + "cachedDataPanel" : false, + "dataExtensions" : "", + "dataSubFiles" : "", + "hideFileName" : false, + "showEmergencyStop" : false, + "showHomingButtons" : false, + "showJogButtons" : false, + "hideScanPanel" : false, + "hideOutputPanel" : false, + "showXScanFileBrowser" : false, + "showQueueBrowser" : false, + "backgroundRendering" : false, + "showImageStatusBar" : true, + "persistRendererWindows" : false, + "defaultRendererColormap" : "Grayscale", + "linePlot" : "ch.psi.pshell.plot.LinePlotJFree", + "matrixPlot" : "ch.psi.pshell.plot.MatrixPlotJFree", + "surfacePlot" : "null", + "timePlot" : "ch.psi.pshell.plot.TimePlotJFree", + "plotsDetached" : false, + "plotLayout" : "Vertical", + "quality" : "High", + "defaultPlotColormap" : "Temperature", + "markerSize" : 2, + "plotBackground" : null, + "gridColor" : null, + "outlineColor" : null, + "disableOffscreenBuffer" : false, + "defaultPanels" : [ { + "deviceClassName" : "ch.psi.pshell.epics.Scaler", + "panelClassName" : "ch.psi.pshell.swing.ScalerPanel" + }, { + "deviceClassName" : "ch.psi.pshell.epics.Scienta", + "panelClassName" : "ch.psi.pshell.swing.ScientaPanel" + }, { + "deviceClassName" : "ch.psi.pshell.device.Motor", + "panelClassName" : "ch.psi.pshell.swing.MotorPanel" + }, { + "deviceClassName" : "ch.psi.pshell.device.MasterPositioner", + "panelClassName" : "ch.psi.pshell.swing.MasterPositionerPanel" + }, { + "deviceClassName" : "ch.psi.pshell.device.ProcessVariable", + "panelClassName" : "ch.psi.pshell.swing.ProcessVariablePanel" + }, { + "deviceClassName" : "ch.psi.pshell.device.MotorGroup", + "panelClassName" : "ch.psi.pshell.swing.MotorGroupPanel" + }, { + "deviceClassName" : "ch.psi.pshell.device.DiscretePositioner", + "panelClassName" : "ch.psi.pshell.swing.DiscretePositionerPanel" + }, { + "deviceClassName" : "ch.psi.pshell.device.Camera", + "panelClassName" : "ch.psi.pshell.swing.CameraPanel" + }, { + "deviceClassName" : "ch.psi.pshell.device.Slit", + "panelClassName" : "ch.psi.pshell.swing.SlitPanel" + }, { + "deviceClassName" : "ch.psi.pshell.device.HistogramGenerator", + "panelClassName" : "ch.psi.pshell.swing.HistogramGeneratorPanel" + }, { + "deviceClassName" : "ch.psi.pshell.bs.Stream", + "panelClassName" : "ch.psi.pshell.swing.StreamPanel" + }, { + "deviceClassName" : "ch.psi.pshell.bs.StreamChannel", + "panelClassName" : "ch.psi.pshell.swing.StreamChannelPanel" + }, { + "deviceClassName" : "ch.psi.pshell.camserver.CamServerStream", + "panelClassName" : "ch.psi.pshell.swing.CamServerStreamPanel" + }, { + "deviceClassName" : "ch.psi.pshell.camserver.CamServerService", + "panelClassName" : "ch.psi.pshell.swing.CamServerServicePanel" + }, { + "deviceClassName" : "ch.psi.pshell.device.ReadonlyRegister$ReadonlyRegisterArray", + "panelClassName" : "ch.psi.pshell.swing.DeviceValueChart" + }, { + "deviceClassName" : "ch.psi.pshell.device.ReadonlyRegister$ReadonlyRegisterMatrix", + "panelClassName" : "ch.psi.pshell.swing.DeviceValueChart" + } ], + "scriptPopupDialog" : "None" +} \ No newline at end of file diff --git a/config/setup.properties b/config/setup.properties new file mode 100644 index 0000000..954be4d --- /dev/null +++ b/config/setup.properties @@ -0,0 +1,25 @@ +#Fri Dec 16 16:32:34 CET 2022 +scriptPath={home}/script +sessionsPath={outp}/sessions +configFileDevices={config}/devices.properties +xscanPath={script} +queuePath={script} +extensionsPath={home}/extensions +configPath={home}/config +configFileSessions={config}/sessions.properties +userSessionsPath={sessions}/user +dataPath={outp}/data +configFileVariables={config}/variables.properties +wwwPath={home}/www +logPath={outp}/log +configFile={config}/config.properties +configFileTasks={config}/tasks.properties +pluginsPath={home}/plugins +consoleSessionsPath={sessions}/console +libraryPath={script}; {script}/Lib +contextPath={outp}/context +configFilePlugins={config}/plugins.properties +devicesPath={home}/devices +configFileSettings={config}/settings.properties +imagesPath={outp}/images +scriptType=py diff --git a/devices/src_a10.properties b/devices/src_a10.properties new file mode 100644 index 0000000..93bf6d5 --- /dev/null +++ b/devices/src_a10.properties @@ -0,0 +1,25 @@ +#Fri Dec 16 16:50:04 CET 2022 +spatialCalOffsetY=NaN +spatialCalOffsetX=NaN +colormapLogarithmic=false +scale=1.0 +grayscale=false +spatialCalScaleX=NaN +spatialCalScaleY=NaN +colormapMax=NaN +rescaleOffset=0.0 +roiWidth=-1 +colormap=Grayscale +invert=false +colormapMin=NaN +rotation=0.0 +rotationCrop=false +rescaleFactor=1.0 +spatialCalUnits=mm +flipVertically=false +roiHeight=-1 +flipHorizontally=false +colormapAutomatic=false +roiY=0 +roiX=0 +transpose=false diff --git a/plugins/Eiger.form b/plugins/Eiger.form new file mode 100644 index 0000000..ff9cfab --- /dev/null +++ b/plugins/Eiger.form @@ -0,0 +1,28 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/plugins/Eiger.java b/plugins/Eiger.java new file mode 100644 index 0000000..e12cf3a --- /dev/null +++ b/plugins/Eiger.java @@ -0,0 +1,66 @@ + +import ch.psi.pshell.ui.Panel; +import ch.psi.utils.State; + +/** + * + */ +public class Eiger extends Panel { + + public Eiger() { + initComponents(); + } + + //Overridable callbacks + @Override + public void onInitialize(int runCount) { + + } + + @Override + public void onStateChange(State state, State former) { + + } + + @Override + public void onExecutedFile(String fileName, Object result) { + } + + @Override + protected void onTimer() { + } + + @Override + protected void onLoaded() { + + } + + @Override + protected void onUnloaded() { + + } + + //Invoked by 'update()' to update components in the event thread + @Override + protected void doUpdate() { + } + + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 449, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 137, Short.MAX_VALUE) + ); + }// //GEN-END:initComponents + + // Variables declaration - do not modify//GEN-BEGIN:variables + // End of variables declaration//GEN-END:variables +} diff --git a/script/devices/Array10.py b/script/devices/Array10.py new file mode 100644 index 0000000..2674f10 --- /dev/null +++ b/script/devices/Array10.py @@ -0,0 +1,138 @@ +import org.zeromq.ZMQ as ZMQ +import org.zeromq.ZMQ.Socket as Socket +import json + + + +class Array10Array(ReadonlyAsyncRegisterBase, ReadonlyRegisterArray): + def getSize(self): + return 0 if (self.take() is None) else len(self.take()) + + def set(self, data): + self.onReadout(data) + + +class Array10Matrix(ReadonlyAsyncRegisterBase, ReadonlyRegisterMatrix): + def getWidth(self): + return 0 if (self.take() is None) else len(self.take()[0]) + + def getHeight(self): + return 0 if (self.take() is None) else len(self.take()) + + def set(self, data, shape): + if (data is not None) and (shape is not None): + self.onReadout(Convert.reshape(data, shape)) + + +class Array10(DeviceBase, Readable, Cacheable, Readable.ReadableType): + def __init__(self, name, address, modulo_array=1, modulo_matrix=1, mode=ZMQ.PULL): + """ Device implementing communication with over Array10. + Args: + name(str): device name + address(str): address of stream + modulo_array(int, default=1): if defined create child device that holds the data array subsampled by this value. + modulo_matrix(int, default=1): if defined create child device that holds the 2d image subsampled by this value. + """ + super(Array10, self).__init__(name) + self.address = address + self.mode = mode + self.context = None + self.socket = None + self.running = False + self.header=None + self.data=None + self.array_dev=None + self.matrix_dev=None + self.message_count=0 + + if modulo_array is not None: + self.array_dev = Array10Array(self.name + "_array" ) + self.addChild(self.array_dev) + self.array_dev.modulo = modulo_array + else: + self.array_dev = None + + if modulo_matrix is not None: + self.matrix_dev = Array10Matrix(self.name + "_matrix" ) + self.addChild(self.matrix_dev) + self.matrix_dev.modulo = modulo_matrix + else: + self.matrix_dev = None + + + def doInitialize(self): + self.stop() + self.header=None + self.data=None + self.message_count=0 + self.start() + + def start(self): + if self.running==False: + self.getLogger().info("Starting"); + self.running = True + self.task = fork(self.rx_thread) + + + def stop(self): + if self.running: + self.getLogger().info("Stopping"); + self.running = False + ret = join(self.task) + + + def rx_thread(self): + self.getLogger().info("Enter rx thread"); + try: + self.context = ZMQ.context(1) + self.socket = self.context.socket(self.mode) + self.socket.connect(self.address) + while self.running: + header = self.socket.recv(ZMQ.NOBLOCK) + if (header is not None): + try: + self.header=json.loads(''.join(chr(i) for i in header)) + self.data = self.socket.recv() + if self.data is not None: + self.setCache({"header":self.header, "data":self.data}, None) + self.message_count=self.message_count+1 + if self.array_dev is not None: + if self.message_count % self.array_dev.modulo == 0: + self.array_dev.set(self.data) + if self.matrix_dev is not None: + if self.message_count % self.matrix_dev.modulo == 0: + shape = self.header.get("shape", None) + if shape: shape=(shape[1],shape[0]) #TODO: FIXME + self.matrix_dev.set(self.data, shape) + continue + except Exception as e: + print e + time.sleep(0.01) + except Exception as e: + print e + finally: + if self.socket: + self.socket.close() + if self.context: + self.context.term() + self.getLogger().info("Quit rx thread"); + + def doClose(self): + """Close the channel. + """ + self.stop() + super(Array10, self).doClose() + + #Readable interface + def read(self): + self.waitCacheChange(-1) + return self.take() + + +#Testing +#add_device(Array10("a10", "tcp://localhost:1234", modulo_array=1, modulo_matrix=10), True) +#add_device(a10.array_dev, True) +#add_device(a10.matrix_dev, True) +#add_device(RegisterMatrixSource("src_a10", a10.matrix_dev), True) + + diff --git a/script/local.groovy b/script/local.groovy new file mode 100644 index 0000000..eef7106 --- /dev/null +++ b/script/local.groovy @@ -0,0 +1,3 @@ +/////////////////////////////////////////////////////////////////////////////////////////////////// +// Deployment specific global definitions - executed after startup.groovy +/////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/script/local.js b/script/local.js new file mode 100644 index 0000000..e2eeaad --- /dev/null +++ b/script/local.js @@ -0,0 +1,4 @@ +/////////////////////////////////////////////////////////////////////////////////////////////////// +// Deployment specific global definitions - executed after startup.js +/////////////////////////////////////////////////////////////////////////////////////////////////// + diff --git a/script/local.py b/script/local.py new file mode 100644 index 0000000..9e43344 --- /dev/null +++ b/script/local.py @@ -0,0 +1,18 @@ +################################################################################################### +# Deployment specific global definitions - executed after startup.py +################################################################################################### + +import requests + +# Definitions +DETECTOR_ADDRESS = "tcp://localhost:1234" +DETECTOR_IMAGE_MODULO = 1 + +# Devices + +run("devices/Array10") + +add_device(Array10("eiger", DETECTOR_ADDRESS, modulo_array=1, modulo_matrix=DETECTOR_IMAGE_MODULO), True) +add_device(eiger.array_dev, True) +add_device(eiger.matrix_dev, True) +add_device(RegisterMatrixSource("src_a10", eiger.matrix_dev), True)