commit 0287177fb31c3ed8bf46e8ad6e0429ca58d0f708 Author: x03daop Date: Thu Mar 26 16:06:42 2015 +0100 Creation diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..09f6e485 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +/data +/sessions +/context +/log +/plugins +/extensions +script/cachedir +script/Lib +script/*.class diff --git a/config/config.properties b/config/config.properties new file mode 100644 index 00000000..aace00a7 --- /dev/null +++ b/config/config.properties @@ -0,0 +1,19 @@ +#Thu Mar 26 16:05:54 CET 2015 +dataFile={data}/{year}_{month}/{date}/{date}_{time}_{context} +dataFilesCreation=true +devicePoolFile={config}/devices.properties +deviceUpdateStrategyFile={config}/update.properties +imageSourcesFile={config}/imaging.properties +logDaysToLive=-1 +logLevel=Info +logLevelConsole=Off +scriptType=py +serverEnabled=false +serverPort=8080 +simulation=false +tasksFile={config}/tasks.properties +terminalEnabled=false +terminalPort=3579 +versionTrackingEnabled=true +versionTrackingLogin= +versionTrackingRemote= diff --git a/config/devices.properties b/config/devices.properties new file mode 100644 index 00000000..9d352163 --- /dev/null +++ b/config/devices.properties @@ -0,0 +1,18 @@ +#det=ch.psi.pshell.epics.AreaDetector X03DA-SCIENTA:cam1 X03DA-SCIENTA:image1 +scienta=ch.psi.pshell.epics.Scienta X03DA-SCIENTA:cam1 X03DA-SCIENTA:image1 +manip=ch.psi.pshell.epics.Manipulator +x=ch.psi.pshell.epics.Motor X03DA-ES2-MA:TRX +y=ch.psi.pshell.epics.Motor X03DA-ES2-MA:TRY +z=ch.psi.pshell.epics.Motor X03DA-ES2-MA:TRZ +theta=ch.psi.pshell.epics.Motor X03DA-ES2-MA:THT +tilt=ch.psi.pshell.epics.Motor X03DA-ES2-MA:TLT +phi=ch.psi.pshell.epics.Motor X03DA-ES2-MA:PHI +sctrg=ch.psi.pshell.epics.ChannelInteger X03DA-SCIENTA:cam1:Acquire +adctrg=ch.psi.pshell.epics.ChannelInteger X03DA-OP-10ADC:TRG +current=ch.psi.pshell.epics.ChannelDouble ARIDI-PCT:CURRENT Read 3 +cur1=ch.psi.pshell.epics.ChannelDouble X03DA-OP:CURRENT1 Read 3 +cur2=ch.psi.pshell.epics.ChannelDouble X03DA-OP:CURRENT2 Read 3 +cur3=ch.psi.pshell.epics.ChannelDouble X03DA-OP:CURRENT3 Read 3 +#sizex=ch.psi.pshell.epics.ChannelInteger X03DA-SCIENTA:cam1:SizeX_RBV +#lowen=ch.psi.pshell.epics.ChannelDouble X03DA-SCIENTA:cam1:LOW_ENERGY 6 +#highen=ch.psi.pshell.epics.ChannelDouble X03DA-SCIENTA:cam1:HIGH_ENERGY 6 diff --git a/config/devices.properties~ b/config/devices.properties~ new file mode 100644 index 00000000..4d08840b --- /dev/null +++ b/config/devices.properties~ @@ -0,0 +1,17 @@ +det=ch.psi.pshell.epics.AreaDetector X03DA-SCIENTA:cam1 X03DA-SCIENTA:image1 +manip=ch.psi.pshell.epics.DiscretePositioner +x=ch.psi.pshell.epics.Motor X03DA-ES2-MA:TRX +y=ch.psi.pshell.epics.Motor X03DA-ES2-MA:TRY +z=ch.psi.pshell.epics.Motor X03DA-ES2-MA:TRZ +theta=ch.psi.pshell.epics.Motor X03DA-ES2-MA:THT +tilt=ch.psi.pshell.epics.Motor X03DA-ES2-MA:TLT +phi=ch.psi.pshell.epics.Motor X03DA-ES2-MA:PHI +sctrg=ch.psi.pshell.epics.ChannelInteger X03DA-SCIENTA:cam1:Acquire +adctrg=ch.psi.pshell.epics.ChannelInteger X03DA-OP-10ADC:TRG +current=ch.psi.pshell.epics.ChannelDouble ARIDI-PCT:CURRENT Read 8 +cur1=ch.psi.pshell.epics.ChannelDouble X03DA-OP:CURRENT1 Read 8 +cur2=ch.psi.pshell.epics.ChannelDouble X03DA-OP:CURRENT2 Read 8 +cur3=ch.psi.pshell.epics.ChannelDouble X03DA-OP:CURRENT3 Read 8 +sizex=ch.psi.pshell.epics.ChannelInteger X03DA-SCIENTA:cam1:SizeX_RBV +lowen=ch.psi.pshell.epics.ChannelDouble X03DA-SCIENTA:cam1:LOW_ENERGY 6 +highen=ch.psi.pshell.epics.ChannelDouble X03DA-SCIENTA:cam1:HIGH_ENERGY 6 diff --git a/config/imaging.properties b/config/imaging.properties new file mode 100644 index 00000000..5b108cdb --- /dev/null +++ b/config/imaging.properties @@ -0,0 +1,2 @@ +img=ch.psi.pshell.imaging.CameraSource scienta +cam1=ch.psi.pshell.imaging.MjpegSource http://x03da-cam-1/axis-cgi/mjpg/video.cgi diff --git a/config/jcae.properties b/config/jcae.properties new file mode 100644 index 00000000..260865a2 --- /dev/null +++ b/config/jcae.properties @@ -0,0 +1,9 @@ +#ch.psi.jcae.ContextFactory.addressList= +ch.psi.jcae.ContextFactory.maxArrayBytes=10000000 + +ch.psi.jcae.ChannelFactory.timeout=2000 +ch.psi.jcae.ChannelFactory.retries=2 +ch.psi.jcae.ChannelBeanFactory.timeout=10000 +ch.psi.jcae.ChannelBeanFactory.waitTimeout=3600000 +ch.psi.jcae.ChannelBeanFactory.retries=2 + diff --git a/config/tasks.properties b/config/tasks.properties new file mode 100644 index 00000000..e69de29b diff --git a/config/update.properties b/config/update.properties new file mode 100644 index 00000000..bf72260a --- /dev/null +++ b/config/update.properties @@ -0,0 +1,18 @@ +det= +scienta=monitored +manip=monitored +x=monitored +y=monitored +z=monitored +theta=monitored +tilt=monitored +phi=monitored +sctrg=monitored +adctrg=monitored +current=monitored +cur1=monitored +cur2=monitored +cur3=monitored +sizex= +lowen= +highen= diff --git a/devices/cam1.properties b/devices/cam1.properties new file mode 100644 index 00000000..71ecab5f --- /dev/null +++ b/devices/cam1.properties @@ -0,0 +1,14 @@ +#Tue Mar 24 14:36:27 CET 2015 +dataPolling=0 +flipHorizontally=false +flipVertically=false +grayscale=false +invert=false +mirrored=false +pollingBackground=false +pollingInterval=0 +rescaleFactor=1.0 +rescaleOffset=0.0 +rotation=0.0 +scale=1.0 +url=null diff --git a/devices/img.properties b/devices/img.properties new file mode 100644 index 00000000..a854135c --- /dev/null +++ b/devices/img.properties @@ -0,0 +1,18 @@ +#Tue Mar 24 14:36:27 CET 2015 +colormap=Grayscale +colormapAutomatic=false +colormapMax=255.0 +colormapMin=0.0 +dataMonitoring=false +dataPolling=0 +flipHorizontally=false +flipVertically=false +grayscale=false +invert=false +mirrored=false +pollingBackground=false +pollingInterval=0 +rescaleFactor=1.0 +rescaleOffset=0.0 +rotation=0.0 +scale=1.0 diff --git a/devices/manip.properties b/devices/manip.properties new file mode 100644 index 00000000..99a08c96 --- /dev/null +++ b/devices/manip.properties @@ -0,0 +1,7 @@ +#Tue Mar 03 17:49:13 CET 2015 +position_pvs=X03DA-MA\:RETRACTED | X03DA-MA\:YAG | X03DA-MA\:NE | X03DA-MA\:TRCL | X03DA-MA\:SHIELD | X03DA-MA\:CLAMP | X03DA-MA\:HEATER | X03DA-MA\:SAMPLE +precision=-1 +positions=Retracted | YAG | Normal emission | Transfer | Shield | Clamping screw | Heater screw | Saple access +accessType=ReadWrite +stop_pv=X03DA-MA-STOP\:ALL +readback_pv=X03DA-MA\:STS diff --git a/devices/mx.properties b/devices/mx.properties new file mode 100644 index 00000000..e3fe9810 --- /dev/null +++ b/devices/mx.properties @@ -0,0 +1,13 @@ +#Tue Mar 03 11:13:47 CET 2015 +accessType=ReadWrite +defaultSpeed=1.0 +minSpeed=0.001 +scale=1.0 +resolution=NaN +offset=0.0 +precision=-1 +maxValue=NaN +channel=X03DA-ES2-MA\:TRX +minValue=NaN +unit=mm +maxSpeed=100.0 diff --git a/devices/phi.properties b/devices/phi.properties new file mode 100644 index 00000000..76096b03 --- /dev/null +++ b/devices/phi.properties @@ -0,0 +1,12 @@ +#Wed Mar 18 09:07:35 CET 2015 +accessType=ReadWrite +defaultSpeed=1.0 +maxSpeed=100.0 +maxValue=NaN +minSpeed=0.001 +minValue=NaN +offset=0.0 +precision=4 +resolution=NaN +scale=1.0 +unit=null diff --git a/devices/theta.properties b/devices/theta.properties new file mode 100644 index 00000000..1dc0c1dd --- /dev/null +++ b/devices/theta.properties @@ -0,0 +1,12 @@ +#Tue Mar 03 17:49:13 CET 2015 +accessType=ReadWrite +defaultSpeed=1.0 +minSpeed=0.001 +scale=1.0 +resolution=NaN +offset=0.0 +precision=4 +maxValue=NaN +minValue=NaN +unit=null +maxSpeed=100.0 diff --git a/devices/tilt.properties b/devices/tilt.properties new file mode 100644 index 00000000..1dc0c1dd --- /dev/null +++ b/devices/tilt.properties @@ -0,0 +1,12 @@ +#Tue Mar 03 17:49:13 CET 2015 +accessType=ReadWrite +defaultSpeed=1.0 +minSpeed=0.001 +scale=1.0 +resolution=NaN +offset=0.0 +precision=4 +maxValue=NaN +minValue=NaN +unit=null +maxSpeed=100.0 diff --git a/devices/x.properties b/devices/x.properties new file mode 100644 index 00000000..1dc0c1dd --- /dev/null +++ b/devices/x.properties @@ -0,0 +1,12 @@ +#Tue Mar 03 17:49:13 CET 2015 +accessType=ReadWrite +defaultSpeed=1.0 +minSpeed=0.001 +scale=1.0 +resolution=NaN +offset=0.0 +precision=4 +maxValue=NaN +minValue=NaN +unit=null +maxSpeed=100.0 diff --git a/devices/y.properties b/devices/y.properties new file mode 100644 index 00000000..1dc0c1dd --- /dev/null +++ b/devices/y.properties @@ -0,0 +1,12 @@ +#Tue Mar 03 17:49:13 CET 2015 +accessType=ReadWrite +defaultSpeed=1.0 +minSpeed=0.001 +scale=1.0 +resolution=NaN +offset=0.0 +precision=4 +maxValue=NaN +minValue=NaN +unit=null +maxSpeed=100.0 diff --git a/devices/z.properties b/devices/z.properties new file mode 100644 index 00000000..1dc0c1dd --- /dev/null +++ b/devices/z.properties @@ -0,0 +1,12 @@ +#Tue Mar 03 17:49:13 CET 2015 +accessType=ReadWrite +defaultSpeed=1.0 +minSpeed=0.001 +scale=1.0 +resolution=NaN +offset=0.0 +precision=4 +maxValue=NaN +minValue=NaN +unit=null +maxSpeed=100.0 diff --git a/script/back.py b/script/back.py new file mode 100644 index 00000000..1e382a74 --- /dev/null +++ b/script/back.py @@ -0,0 +1,7 @@ +import java.util.logging.Logger as Logger +logger = Logger.getLogger("back") + + +logger.info("Started") + + diff --git a/script/calc.groovy b/script/calc.groovy new file mode 100644 index 00000000..2eb6185b --- /dev/null +++ b/script/calc.groovy @@ -0,0 +1,6 @@ + + +def calc(a){ + a*2 +} + diff --git a/script/calc.js b/script/calc.js new file mode 100644 index 00000000..39afdfa6 --- /dev/null +++ b/script/calc.js @@ -0,0 +1,5 @@ + + +function calc(a) { + return a * 5; + } \ No newline at end of file diff --git a/script/calc.py b/script/calc.py new file mode 100644 index 00000000..a86ca499 --- /dev/null +++ b/script/calc.py @@ -0,0 +1,3 @@ +def calc(a): + return a*2 + diff --git a/script/cls.groovy b/script/cls.groovy new file mode 100644 index 00000000..97d7612b --- /dev/null +++ b/script/cls.groovy @@ -0,0 +1,7 @@ +package script +class cls { + double val = 1.0 + void exec(){ + println "Exec" + } +} \ No newline at end of file diff --git a/script/cls.py b/script/cls.py new file mode 100644 index 00000000..6c2a6f23 --- /dev/null +++ b/script/cls.py @@ -0,0 +1,4 @@ +class cls: + def execute(self): + print "Execute" + diff --git a/script/local.py b/script/local.py new file mode 100644 index 00000000..4b7a5364 --- /dev/null +++ b/script/local.py @@ -0,0 +1,2 @@ +#det.data.monitored=True +startBackgroudTask("back",1.0) \ No newline at end of file diff --git a/script/scan.py b/script/scan.py new file mode 100644 index 00000000..a86ca499 --- /dev/null +++ b/script/scan.py @@ -0,0 +1,3 @@ +def calc(a): + return a*2 + diff --git a/script/scan1.py b/script/scan1.py new file mode 100644 index 00000000..e0154061 --- /dev/null +++ b/script/scan1.py @@ -0,0 +1 @@ +a= lscan(scienta.sizeX, (scienta.spectrum,current,cur1), 980.0, 992.0, 12, 0.1) \ No newline at end of file diff --git a/script/script.groovy b/script/script.groovy new file mode 100644 index 00000000..7f275d78 --- /dev/null +++ b/script/script.groovy @@ -0,0 +1,31 @@ + +def function(a){ + a*2 +} +//evaluate (new File("calc.groovy")) +//evaluate (new File("cls.groovy")) + +println "--------------" + +lib.load "calc" +cls = lib.load "cls" + + +//This is how to load a new class dinamically +// ClassLoader parent = lib.class.getClassLoader(); +// groovy.lang.GroovyClassLoader loader = new groovy.lang.GroovyClassLoader(parent); +// Class cls = loader.parseClass(new File("script\\cls.groovy")); + + +println dev.get() +println dev2.val +println calc(6) + + +//cls = Class.forName('cls') +//obj = new cls() +obj = cls.newInstance() +println obj.val +obj.exec() + + diff --git a/script/script.js b/script/script.js new file mode 100644 index 00000000..d6ec8b62 --- /dev/null +++ b/script/script.js @@ -0,0 +1,13 @@ +function calcx(a) { + return a * 5; + } + +print('Hello, World') +lib.load ("calc") + + +a=3 +a +print (dev.get()) +print (dev2.val) +print (calc(5)) diff --git a/script/script.py b/script/script.py new file mode 100644 index 00000000..74493601 --- /dev/null +++ b/script/script.py @@ -0,0 +1,42 @@ +import sys +import time + +#To add library folders from within the script +#sys.path.append("./site-packages") + + +import requests +r = requests.get('https://api.github.com', auth=('user', 'pass')) +print r.status_code +print r.headers['content-type'] +r.close() + + +def calc2(a): + return a*2 +time.sleep(2) +#import os +#print os.environ +#import calc + + +lib.load("calc") +lib.load("cls") +time.sleep(2) +for x in range(3): + print x + while(True): + print x*2 + break +time.sleep(2) +x=cls() +x.execute() +print dev.take() +print dev2.val +time.sleep(1) +print calc(4) + + +""" +It lives!!!! +""" \ No newline at end of file diff --git a/script/startup.groovy b/script/startup.groovy new file mode 100644 index 00000000..b17d5a1d --- /dev/null +++ b/script/startup.groovy @@ -0,0 +1,53 @@ +import ch.psi.pshell.scan.LineScan; +import ch.psi.pshell.scan.AreaScan; + + +def sleep(millis){ + Thread.sleep(millis); +} + +def toArray(obj){ + /* if (!obj.getClass().isArray()){ + arr = java.lang.reflect.Array.newInstance(obj.getClass(), 1); + arr[0]= obj; + obj=arr + }*/ + return obj +} + + +def scan(writables, readables, start, end, steps, latency_ms=0, plot=null){ + writables=toList(writables) + readables=toList(readables) + start=toList(start) + end=toList(end) + scan = LineScan(writables,readables, start, end , steps,latency_ms, controller) + scan.setPlotName(plot) + scan.start() + return scan.getResult() +} + +def tscan(readables, points, interval_ms, plot=null){ + writables=[] + //readables=toList(readables) + readables=[readables,] + start=[0] + + end=[points] + steps=points + scan = LineScan(writables,readables, start, end , steps,interval_ms, controller) + scan.setPlotName(plot) + scan.start() + return scan.getResult() +} + +def ascan(writables, readables, start, end, steps, latency_ms0, plot=null){ + writables=toList(writables) + readables=toList(readables) + start=toList(start) + end=toList(end) + scan = AreaScan(writables,readables, start, end , steps,latency_ms, controller) + scan.setPlotName(plot) + scan.start() + return scan.getResult() +} \ No newline at end of file diff --git a/script/startup.py b/script/startup.py new file mode 100644 index 00000000..8884eae1 --- /dev/null +++ b/script/startup.py @@ -0,0 +1,310 @@ +import sys +import time +import math +from array import array + +import java.lang.Class as Class +import org.python.core.PyArray as PyArray +import ch.psi.pshell.dev.MotorGroupBase.MoveMode as MoveMode + +import ch.psi.pshell.scan.LineScan +import ch.psi.pshell.scan.AreaScan +import ch.psi.pshell.scan.VectorScan +import ch.psi.pshell.dev.Readable as Readable + +import ch.psi.pshell.epics.Epics as Epics +import ch.psi.pshell.epics.EpicsScan as EpicsScan + + +def onScanBeforeReadout(scan): + try: + if (scan.before_read!=None): + scan.before_read() + except AttributeError: + pass + +def onScanAfterReadout(scan): + try: + if (scan.after_read!=None): + scan.after_read() + except AttributeError: + pass + +class LineScan(ch.psi.pshell.scan.LineScan): + def onBeforeReadout(self): + onScanBeforeReadout(self) + + def onAfterReadout(self): + onScanAfterReadout(self) + +class AreaScan(ch.psi.pshell.scan.AreaScan): + def onBeforeReadout(self): + onScanBeforeReadout(self) + + def onAfterReadout(self): + onScanAfterReadout(self) + +class VectorScan(ch.psi.pshell.scan.VectorScan): + def onBeforeReadout(self): + onScanBeforeReadout(self) + + def onAfterReadout(self): + onScanAfterReadout(self) + +def sleep(sec): + time.sleep(sec) + +def toList(obj): + if isinstance(obj,tuple): + return list(obj) + if not isinstance(obj,list): + return [obj,] + return obj + + +def lscan(writables, readables, start, end, steps, latency=0.0, plot=None, before_read=None, after_read=None): + """Line Scan: positioners change together, linearly from start to end positions. + + Args: + writables(list of Writable): Positioners set on each step. + readables(list of Readable): Sensors to be sampled on each step. + start(list of float): start positions of writables. + end(list of float): final positions of writables. + steps(int): number of scan steps. + latency(float, optional): sleep time in each step before readout, defaults to 0.0. + plot(str, optional): plotting context name. + before_read (function): callback on each step, before each readout. + after_read (function): callback on each step, after each readout. + + Returns: + ArrayList of ScanRecord objects. + + """ + latency_ms=int(latency*1000) + writables=toList(writables) + readables=toList(readables) + start=toList(start) + end=toList(end) + scan = LineScan(writables,readables, start, end , steps,latency_ms, controller) + scan.before_read=before_read + scan.after_read=after_read + scan.setPlotName(plot) + scan.start() + return scan.getResult() + +def vscan(writables, readables, vector, latency=0.0, plot=None, before_read=None, after_read=None): + """Vector Scan: positioners change following values provided in a vector. + + Args: + writables(list of Writable): Positioners set on each step. + readables(list of Readable): Sensors to be sampled on each step. + vector(list of list of float): table of positioner values. + latency(float, optional): sleep time in each step before readout, defaults to 0.0. + plot(str, optional): plotting context name. + before_read (function): callback on each step, before each readout. + after_read (function): callback on each step, after each readout. + + Returns: + ArrayList of ScanRecord objects. + + """ + latency_ms=int(latency*1000) + writables=toList(writables) + readables=toList(readables) + scan = VectorScan(writables,readables, vector, latency_ms, controller) + scan.before_read=before_read + scan.after_read=after_read + scan.setPlotName(plot) + scan.start() + return scan.getResult() + +def ascan(writables, readables, start, end, steps, latency=0.0, plot=None, before_read=None, after_read=None): + """Area Scan: multi-dimentional scan, each positioner is a dimention. + + Args: + writables(list of Writable): Positioners set on each step. + readables(list of Readable): Sensors to be sampled on each step. + start(list of float): start positions of writables. + end(list of float): final positions of writables. + steps(list of int): number of scan steps for each positioner. + latency(float, optional): sleep time in each step before readout, defaults to 0.0. + plot(str, optional): plotting context name. + before_read (function): callback on each step, before each readout. + after_read (function): callback on each step, after each readout. + + Returns: + ArrayList of ScanRecord objects. + + """ + latency_ms=int(latency*1000) + writables=toList(writables) + readables=toList(readables) + start=toList(start) + end=toList(end) + scan = AreaScan(writables,readables, start, end , steps,latency_ms, controller) + scan.before_read=before_read + scan.after_read=after_read + scan.setPlotName(plot) + scan.start() + return scan.getResult() + +def tscan(readables, points, interval, plot=None, before_read=None, after_read=None): + """Time Scan: sensors are sampled in fixed time intervals. + + Args: + readables(list of Readable): Sensors to be sampled on each step. + points(int): number of samples. + interval(float): time interval between readouts. + plot(str, optional): plotting context name. + before_read (function): callback on each step, before each readout. + after_read (function): callback on each step, after each readout. + + Returns: + ArrayList of ScanRecord objects. + + """ + latency_ms=int(interval*1000) + writables=[] + readables=toList(readables) + start=[0,] + end=[points,] + steps=points + scan = LineScan(writables,readables, start, end , steps,latency_ms, controller) + scan.before_read=before_read + scan.after_read=after_read + scan.setPlotName(plot) + scan.start() + return scan.getResult() + +def escan(name, plot=None): + """Epics Scan: execute an Epics Scan Record. + + Args: + name(str): Name of scan record. + plot(str, optional): plotting context name. + + Returns: + ArrayList of ScanRecord objects. + + """ + scan = EpicsScan(name, controller) + scan.setPlotName(plot) + scan.start() + return scan.getResult() + + + +class ListReader(Readable): + def __init__(self,list, plot): + self.counter=0 + self.list=list + def getName(self): + return None + def read(self): + if (self.counter>=len(self.list)): + return None; + ret = self.list[self.counter] + self.counter=self.counter+1 + return ret + +def plot(data, plot=None): + """Plot a list in a graph. + + Args: + data(list): data to be plotted + plot(str, optional): plotting context name. + + """ + latency_ms=0 + data=toList(data) + writables=[] + readables=[ListReader(data,plot),] + start=[0,] + end=[len(data),] + steps=len(data)-1 + scan = LineScan(writables,readables, start, end , steps,latency_ms, controller) + scan.setPlotName(plot) + scan.start() + +channel_types = { + 'b': "java.lang.Byte", + 'i': "java.lang.Short", + 'l': "java.lang.Integer", + 'd': "java.lang.Double", + 's': "java.lang.String", + + 'b,': "[B", + 'i,': "[S", + 'l,': "[I", + 'd,': "[D", + 's,': "[Ljava.lang.String;", +} + +array_types = { + int: "i", + long: "l", + float:"d", + str:Class.forName("java.lang.String"), +} + +def caget(name, type='d', size=None): + """Reads an Epics PV. + + Args: + name(str): PV name + type(str, optional): type of PV, defaults 'd'. + Scalar values: 'b', 'i', 'l', 'd', 's'. + Array: values: 'b,', 'i,', 'l,', 'd,', 's,'. + """ + if (size==None): + return Epics.get(name, Class.forName(channel_types.get(type,type))) + else: + return Epics.get(name, Class.forName(channel_types.get(type,type)),size) + +def adjustPutVal(value): + if isinstance(value,tuple): + value = list(value) + if isinstance(value,list): + array = PyArray(array_types.get(type(value[0]),'d')) + array.fromlist(value) + value=array + return value + +def caput(name, value): + """Writes to an Epics PV. + + Args: + name(str): PV name + value(scalar, string or array): new PV value. + """ + value=adjustPutVal(value) + return Epics.put(name, value) + +def caputq(name, value): + """Writes to an Epics PV and does not wait. + + Args: + name(str): PV name + value(scalar, string or array): new PV value. + """ + value=adjustPutVal(value) + return Epics.putq(name, value) + +def log(log): + """Writes log to data file. + + Args: + log(str): Log string + + """ + controller.getDataManager().addLog(str(log)) + +def startBackgroudTask(script, interval): + interval_ms=int(interval*1000) + controller.taskManager.create(script,interval_ms) + controller.taskManager.start(script) + +def stopBackgroudTask(script, interval): + controller.taskManager.remove(script) + +execfile(controller.setup.getScriptPath()+"/local.py") \ No newline at end of file diff --git a/script/test1.py b/script/test1.py new file mode 100644 index 00000000..7b36398e --- /dev/null +++ b/script/test1.py @@ -0,0 +1,5 @@ +""" +Line Scan +""" + +a= lscan(inp,(sin,out,arr),0,40,20,0.1) \ No newline at end of file diff --git a/script/test2.py b/script/test2.py new file mode 100644 index 00000000..de4ec03b --- /dev/null +++ b/script/test2.py @@ -0,0 +1,16 @@ +""" +Line Scan with 2 writables and triggering +""" + +index=0 + +def BeforeReadout(): + global index + print "Frame = " + str(index) + index=index+1 + #log("trigger " + index) + caput("TESTIOC:TESTBO:MyBO","On") + caput("TESTIOC:TESTBO:MyBO","Off") + + +a= lscan((motor,inp),(sin,out,arr),(0,0),(4,40),20,0.1, before_read=BeforeReadout) \ No newline at end of file diff --git a/script/test3.py b/script/test3.py new file mode 100644 index 00000000..9aa7971f --- /dev/null +++ b/script/test3.py @@ -0,0 +1,12 @@ +""" +Processing and plotting scan data +""" + +inp.write(0.0) +scan1= lscan(inp,(sin,out,arr),0,40,20,0.1,"Scan 1") +scan2= lscan(inp,(sin,out,arr),0,40,20,0.1,"Scan 2") +result=[] +for i in range(20): + result.append(scan1[i].values[0]+scan2[i].values[0]) +plot(result) +print result diff --git a/script/test4.py b/script/test4.py new file mode 100644 index 00000000..a3eefabc --- /dev/null +++ b/script/test4.py @@ -0,0 +1,11 @@ +""" +Vector Scan +""" + +vector = [ [1,1] , [1,2] , [1,3] , [1,4] , + [1.5,2.5] , + [2,1] , [2,2] , [2,3] , [2,4] , + [2.5,2.5] , + [3,1] , [3,2] , [3,3] , [3,4] ] + +a= vscan((dev,inp),(sin,out),vector,0.1) diff --git a/script/test5.py b/script/test5.py new file mode 100644 index 00000000..bf6c7a60 --- /dev/null +++ b/script/test5.py @@ -0,0 +1,5 @@ +""" +Area Scan +""" + +ascan((dev,out),(sin,out,arr),(0,10),(20,30),(100,100)) \ No newline at end of file diff --git a/script/test6.py b/script/test6.py new file mode 100644 index 00000000..199f9bba --- /dev/null +++ b/script/test6.py @@ -0,0 +1,36 @@ +""" +Creating pseudo-devices +""" +import time + +sin_val=None + +class Sensor(ch.psi.pshell.dev.Readable): + def read(self): + global sin_val + return sin_val + time.clock() + def getName(self): + return "Sensor" + +class Positioner(ch.psi.pshell.dev.Writable): + def write(self,pos): + print pos + def getName(self): + return "Positioner" + +class Listener (ch.psi.pshell.dev.DeviceListener): + def onStateChanged(self, device, state, former): + pass + def onValueChanged(self, device, value, former): + global sin_val + sin_val=value + +sensor=Sensor() +positioner=Positioner() +listener = Listener() + +sin.addListener(listener) +try: + a= lscan((inp,positioner),(sin,sensor),(0,0),(40,10),20,0.1) +finally: + sin.removeListener(listener) \ No newline at end of file