From 2ac0f00447cbea81f90b0cf21a6022502f0bf44f Mon Sep 17 00:00:00 2001 From: gac-x03da Date: Thu, 8 Feb 2018 16:39:45 +0100 Subject: [PATCH] Startup --- script/keithley.py | 91 +++++++++++++++++++++++++++++++ script/test/ManipulatorScanKei.py | 29 ++++++++++ 2 files changed, 120 insertions(+) create mode 100644 script/keithley.py create mode 100644 script/test/ManipulatorScanKei.py diff --git a/script/keithley.py b/script/keithley.py new file mode 100644 index 00000000..f732c18c --- /dev/null +++ b/script/keithley.py @@ -0,0 +1,91 @@ +import ch.psi.epics as epics + +class Keithley(object): + def __init__(self, basename): + self.basename = basename + self.scanCh = None + self.ttypeCh = None + self.nplcCh = None + self.navgCh = None + self.tottimeCh = None + self.doinitCh = None + self.dotriggerCh = None + self.dofetchCh = None + self.readoutCh = None + + def initialize(self): + self.scanCh = epics.ChannelInteger(basename + "READSCAN.SCAN") + self.ttypeCh = epics.ChannelInteger(basename + "TTYPE") + self.nplcCh = epics.ChannelDouble(basename + "NPLC") + self.navgCh = epics.ChannelInteger(basename + "NAVG") + self.tottimeCh = epics.ChannelDouble(basename + "TOTTIME") + self.doinitCh = epics.ChannelInteger(basename + "DOINIT") + self.dotriggerCh = epics.ChannelInteger(basename + "DOTRIGGER") + self.dofetchCh = epics.ChannelInteger(basename + "DOFETCH") + self.readoutCh = epics.ChannelDouble(basename + "READOUT") + + def prepare(self, dwell): + """ + prepare keithley for gpib polling: + scan passive, bus triggered, set dwell time + + dwell = dwell time in seconds (0.1 - 20.0) + """ + self.scanCh.putq(0) + self.ttypeCh.putq(2) + nplc = 5. + navg = dwell / 0.1 + if navg > 100: + nplc *= 2 + navg /= 2 + navg = min(navg, 100) + nplc = min(nplc, 10.) + self.nplcCh.putq(nplc) + self.navgCh.putq(navg) + + def trig(self): + """ + trigger keithleys, wait until done, and read the result into EPICS. + the value can then be read by pshell from the channel. + """ + dwell1 = caget(KEI_SAMPLE + "TOTTIME") / 1000. + dwell2 = caget(KEI_REF + "TOTTIME") / 1000. + dwell = max(dwell1, dwell2) + self.doinitCh.put(1) + self.dotriggerCh.put(1) + + def get_dwell(self): + """ + get dwell time in seconds. + """ + dwell = self.tottimeCh.get() / 1000. + return dwell + + def fetch(self): + """ + fetch the current value from the keithley into EPICS. + """ + #time.sleep(self.get_dwell()) + self.dofetchCh.put(1) + + def read(self): + """ + read the curent value. + """ + return self.readoutCh.get() + + def release(self): + """ + switch keithleys to free run. + 0.1 s polling and dwell time + """ + self.nplcCh.putq(nplc) + self.navgCh.putq(navg) + self.scanCh.putq(9) + self.ttypeCh.putq(0) + +KeiSample = Keithley("X03DA-KEITHLEY-1:") +KeiReference = Keithley("X03DA-KEITHLEY-2:") + +KeiSample.initialize() +KeiReference.initialize() diff --git a/script/test/ManipulatorScanKei.py b/script/test/ManipulatorScanKei.py new file mode 100644 index 00000000..769723a8 --- /dev/null +++ b/script/test/ManipulatorScanKei.py @@ -0,0 +1,29 @@ +""" +Arguments: + +MOTOR (device) +SENSORS (list) +RANGE (tuple (min, max)) +STEPS (int or tuple) +LATENCY (double) +RELATIVE (BOOLEAN) +""" + +MOTOR = (ManipulatorY) +SENSORS (SampleCurrent, RefCurrent) +RANGE = (-0.5, 0.5) +STEPS = 10 +LATENCY = 0.5 +RELATIVE = True + +adjust_sensors() +set_adc_averaging() +before_scan() +set_preference(Preference.PLOT_TYPES, {'Scienta spectrum':1}) + +try: + lscan(MOTOR, SENSORS, RANGE[0], RANGE[1], STEPS, LATENCY, RELATIVE, before_read=before_readout, after_read = after_readout) +finally: + if ENDSCAN: + after_scan() + \ No newline at end of file