Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hardware triggering #18

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,823 changes: 0 additions & 4,823 deletions 1146

This file was deleted.

Empty file added startup/.42-scans_legacy.py.swx
Empty file.
3 changes: 3 additions & 0 deletions startup/02-accelerator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from ophyd import EpicsSignalRO

sr_current = EpicsSignalRO('SR:OPS-BI{DCCT:1}I:Real-I', name='sr_current')
156 changes: 156 additions & 0 deletions startup/05-ion-chamber.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
from ophyd import Device, Component as Cpt, EpicsScaler, EpicsSignal, EpicsSignalRO
from ophyd.device import DynamicDeviceComponent as DDC
from collections import OrderedDict


# The source for the scaler code is github.com/NSLS-II-SRX/profile_collection/startup/30-scaler.py


class EpicsSignalROLazyier(EpicsSignalRO):
def get(self, *args, timeout=5, **kwargs):
return super().get(*args, timeout=timeout, **kwargs)


def _scaler_fields(attr_base, field_base, range_, **kwargs):
defn = OrderedDict()
for i in range_:
attr = "{attr}{i}".format(attr=attr_base, i=i)
suffix = "{field}{i}".format(field=field_base, i=i)
defn[attr] = (EpicsSignalROLazyier, suffix, kwargs)

return defn


class FXIScaler(EpicsScaler):
acquire_mode = Cpt(EpicsSignal, "AcquireMode")
acquiring = Cpt(EpicsSignal, "Acquiring")
asyn = Cpt(EpicsSignal, "Asyn")
channel1_source = Cpt(EpicsSignal, "Channel1Source")
channel_advance = Cpt(EpicsSignal, "ChannelAdvance", string=True)
channels = DDC(_scaler_fields("chan", ".S", range(1, 33)))
client_wait = Cpt(EpicsSignal, "ClientWait")
count_on_start = Cpt(EpicsSignal, "CountOnStart")
current_channel = Cpt(EpicsSignal, "CurrentChannel")
disable_auto_count = Cpt(EpicsSignal, "DisableAutoCount")
do_read_all = Cpt(EpicsSignal, "DoReadAll")
dwell = Cpt(EpicsSignal, "Dwell")
elapsed_real = Cpt(EpicsSignal, "ElapsedReal")
enable_client_wait = Cpt(EpicsSignal, "EnableClientWait")
erase_all = Cpt(EpicsSignal, "EraseAll")
erase_start = Cpt(EpicsSignal, "EraseStart")
firmware = Cpt(EpicsSignal, "Firmware")
hardware_acquiring = Cpt(EpicsSignal, "HardwareAcquiring")
input_mode = Cpt(EpicsSignal, "InputMode")
max_channels = Cpt(EpicsSignal, "MaxChannels")
model = Cpt(EpicsSignal, "Model")
mux_output = Cpt(EpicsSignal, "MUXOutput")
nuse_all = Cpt(EpicsSignal, "NuseAll")
output_mode = Cpt(EpicsSignal, "OutputMode")
output_polarity = Cpt(EpicsSignal, "OutputPolarity")
prescale = Cpt(EpicsSignal, "Prescale")
preset_real = Cpt(EpicsSignal, "PresetReal")
read_all = Cpt(EpicsSignal, "ReadAll")
read_all_once = Cpt(EpicsSignal, "ReadAllOnce")
set_acquiring = Cpt(EpicsSignal, "SetAcquiring")
set_client_wait = Cpt(EpicsSignal, "SetClientWait")
snl_connected = Cpt(EpicsSignal, "SNL_Connected")
software_channel_advance = Cpt(EpicsSignal, "SoftwareChannelAdvance")
count_mode = Cpt(EpicsSignal, ".CONT")
start_all = Cpt(EpicsSignal, "StartAll")
stop_all = Cpt(EpicsSignal, "StopAll")
user_led = Cpt(EpicsSignal, "UserLED")
wfrm = Cpt(EpicsSignal, "Wfrm")
mca1 = Cpt(EpicsSignalRO, "mca1")
mca2 = Cpt(EpicsSignalRO, "mca2")
mca3 = Cpt(EpicsSignalRO, "mca3")
mca4 = Cpt(EpicsSignalRO, "mca4")

def __init__(self, prefix, **kwargs):
super().__init__(prefix, **kwargs)
self.stage_sigs[self.count_mode] = "OneShot"

sclr1 = FXIScaler("XF:18IDB-ES{Sclr:1}", name="sclr1")



class SR570(Device):
# SR570 preamps are controlled via one-way RS232 connection. The IOC can keep track only of the
# settings change via EPICS. It does not know the actual settings if the changes are made
# manually using buttons on the hardware unit.

init = Cpt(EpicsSignal, "init.PROC")
reset = Cpt(EpicsSignal, "reset.PROC")

sensitivity_num = Cpt(EpicsSignal, "sens_num", string=True)
sensitivity_unit = Cpt(EpicsSignal, "sens_unit", string=True)

offset_on = Cpt(EpicsSignal, "offset_on", string=True)
offset_sign = Cpt(EpicsSignal, "offset_sign", string=True)
offset_num = Cpt(EpicsSignal, "offset_num", string=True)
offset_unit = Cpt(EpicsSignal, "offset_unit", string=True)
offset_u_put = Cpt(EpicsSignal, "off_u_put", )
offset_u_tweak = Cpt(EpicsSignal, "offset_u_tweak")
offset_cal = Cpt(EpicsSignal, "offset_cal", string=True)

bias_put = Cpt(EpicsSignal, "bias_put")
bias_tweak = Cpt(EpicsSignal, "bias_tweak")
bias_on = Cpt(EpicsSignal, "bias_on", string=True)

filter_type = Cpt(EpicsSignal, "filter_type", string=True)
filter_reset = Cpt(EpicsSignal, "filter_reset.PROC")
filter_low_freq = Cpt(EpicsSignal, "low_freq", string=True)
filter_high_freq = Cpt(EpicsSignal, "high_freq", string=True)

gain_mode = Cpt(EpicsSignal, "gain_mode", string=True)
invert_on = Cpt(EpicsSignal, "invert_on", string=True)
blank_on = Cpt(EpicsSignal, "blank_on", string=True)


class SR570_PREAMPS(Device):
unit1 = Cpt(SR570, "{SR570:1}")
unit2 = Cpt(SR570, "{SR570:2}")
unit3 = Cpt(SR570, "{SR570:3}")
unit4 = Cpt(SR570, "{SR570:4}")


sr570_preamps = SR570_PREAMPS("XF:18IDB-CT", name="sr570_preamps")


class WienerHVCrateChannel(Device):

status_dec = Cpt(EpicsSignalRO, "StatusDec") # Bits 0-7

# Meanings of the status bits:
# outputOn (0) output channel is on
# outputInhibit(1) external (hardware-)inhibit of the output channel
# outputFailureMinSenseVoltage (2) Sense voltage is too low
# outputFailureMaxSenseVoltage (3) Sense voltage is too high
# outputFailureMaxTerminalVoltage (4) Terminal voltage is too high
# outputFailureMaxCurrent (5) Current is too high
# outputFailureMaxTemperature (6) Heat sink temperature is too high
# outputFailureMaxPower (7) Output power is too high

switch_on_off = Cpt(EpicsSignal, "Switch")
V_set = Cpt(EpicsSignal, "V-Set")
V_sense = Cpt(EpicsSignalRO, "V-Sense")
I_set_limit = Cpt(EpicsSignal, "I-SetLimit")
I_sense = Cpt(EpicsSignalRO, "I-Sense")
temperature = Cpt(EpicsSignalRO, "Temperature")
V_fall_rate = Cpt(EpicsSignal, "V-FallRate")
V_rise_rate = Cpt(EpicsSignal, "V-RiseRate")


class WienerHVCrate(Device):

u0 = Cpt(WienerHVCrateChannel, "HV:u0}")
u1 = Cpt(WienerHVCrateChannel, "HV:u1}")
u2 = Cpt(WienerHVCrateChannel, "HV:u2}")
u3 = Cpt(WienerHVCrateChannel, "HV:u3}")
u4 = Cpt(WienerHVCrateChannel, "HV:u4}")
u5 = Cpt(WienerHVCrateChannel, "HV:u5}")
u6 = Cpt(WienerHVCrateChannel, "HV:u6}")
u7 = Cpt(WienerHVCrateChannel, "HV:u7}")


hv_crate = WienerHVCrate("XF:18IDB-OP{WPS:01-", name="hv_crate")

93 changes: 74 additions & 19 deletions startup/10-area-detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
from ophyd.areadetector.cam import AreaDetectorCam
from ophyd.areadetector.detectors import DetectorBase
from nslsii.ad33 import StatsPluginV33, CamV33Mixin
#from nslsii.ad33 import SingleTriggerV33


from nslsii.ad33 import SingleTriggerV33


from ophyd.areadetector.trigger_mixins import TriggerBase, ADTriggerStatus
from ophyd.device import Staged
from ophyd.status import SubscriptionStatus
Expand All @@ -44,7 +48,7 @@ def describe(self):
)
return res


'''
class SingleTriggerV33(TriggerBase):
_status_type = ADTriggerStatus

Expand All @@ -68,7 +72,7 @@ def acquire_complete(*args, old_value, value, **kwargs):
self.dispatch(self._image_name, ttime.time())
return status


'''
class AndorCam(CamV33Mixin, AreaDetectorCam):
def __init__(self, *args, **kwargs):
AreaDetectorCam.__init__(self, *args, **kwargs)
Expand Down Expand Up @@ -174,23 +178,22 @@ class AndorKlass(SingleTriggerV33, DetectorBase):
roi4 = Cpt(ROIPlugin, "ROI4:")
proc1 = Cpt(ProcessPlugin, "Proc1:")

def cam_name(self):
print(self.prefix.split("{")[1].strip("}").split(":")[1])

root_path = "/nsls2/data/fxi-new/legacy/Andor"
hdf5 = Cpt(
HDF5PluginWithFileStore,
suffix="HDF1:",
write_path_template="/nsls2/data/fxi-new/legacy/Andor/%Y/%m/%d/",
# write_path_template='/tmp/test_2022/%Y/%m/%d/' ,
# write_path_template="/nsls2/data/fxi-new/assets/default/%Y/%m/%d/",
# write_path_template="/nsls2/data/fxi-new/legacy/Andor//%Y/%m/%d/",
# root="/nsls2/data/fxi-new/assets/default",
root="/nsls2/data/fxi-new/legacy/Andor",
# root = "/tmp/test_2022",
# root="/nsls2/data/fxi-new/legacy/Andor/",
# write_path_template='/tmp/',
# root='/dev/shm',
write_path_template=f"{root_path}/%Y/%m/%d/",
root=root_path,
)

ac_period = Cpt(EpicsSignal, "cam1:AcquirePeriod")
binning = Cpt(EpicsSignal, "cam1:A3Binning")
pre_amp = Cpt(EpicsSignal, "cam1:PreAmpGain")
rd_rate = Cpt(EpicsSignal, "cam1:ReadoutRate")
pxl_encoding = Cpt(EpicsSignal, "cam1:PixelEncoding")

def stop(self):
self.hdf5.capture.put(0)
Expand Down Expand Up @@ -219,7 +222,7 @@ def resume(self):
self.hdf5._generate_resource(res_kwargs)
return super().resume()

@timing
#@timing
def stage(self):
import itertools
if self.cam.detector_state.get() != 0:
Expand All @@ -237,7 +240,7 @@ def stage(self):
else:
raise

@timing
#@timing
def unstage(self, *args, **kwargs):
import itertools
#self._acquisition_signal.put(0, wait=True)
Expand Down Expand Up @@ -275,9 +278,12 @@ class Manta(SingleTrigger, AreaDetector):
HDF5PluginWithFileStore,
suffix="HDF1:",
# write_path_template="/nsls2/data/fxi-new/legacy/Andor/%Y/%m/%d/",
write_path_template="/nsls2/data/fxi-new/legacy/Andor//%Y/%m/%d/",
# write_path_template = '/dev/shm/',
root="/nsls2/data/fxi-new/legacy/Andor/",
write_path_template="/nsls2/data/fxi-new/legacy/Oryx/%Y/%m/%d/",
# write_path_template='/tmp/test_2022/%Y/%m/%d/' ,
# write_path_template="/nsls2/data/fxi-new/assets/default/%Y/%m/%d/",
# write_path_template="/nsls2/data/fxi-new/legacy/Andor//%Y/%m/%d/",
# root="/nsls2/data/fxi-new/assets/default",
root="/nsls2/data/fxi-new/legacy/Oryx",
# write_path_template='/tmp/',
# root='/',
)
Expand Down Expand Up @@ -346,7 +352,9 @@ def resume(self):
Andor.hdf5.read_attrs = []
"""


"""
Comment out this section when Andor Neo2 is not connected
#---- added by xh
Andor = AndorKlass("XF:18IDB-BI{Det:Neo2}", name="Andor")
Andor.cam.ensure_nonblocking()
# Andor.read_attrs = ['hdf5', 'stats1', 'stats5']
Expand All @@ -361,8 +369,20 @@ def resume(self):
for k in ("image", "trans1", "roi1", "proc1"):
getattr(Andor, k).ensure_nonblocking()
Andor.hdf5.time_stamp.name = "Andor_timestamps"
"""

#########################################
# added by XH
MaranaU = AndorKlass("XF:18IDB-ES{Det:Marana1}", name="Andor")
MaranaU.cam.ensure_nonblocking()
MaranaU.read_attrs = ['hdf5']
MaranaU.hdf5.read_attrs = ["time_stamp"]
MaranaU.stage_sigs["cam.image_mode"] = 0
for k in ("image", "trans1", "roi1", "proc1"):
getattr(MaranaU, k).ensure_nonblocking()
MaranaU.hdf5.time_stamp.name = "Andor_timestamps"

#############################################
# vlm = Manta("XF:18IDB-BI{VLM:1}", name="vlm")
# detA1.read_attrs = ['hdf5', 'stats1', 'stats5']
# detA1.read_attrs = ['hdf5']
Expand All @@ -372,9 +392,44 @@ def resume(self):
# vlm.hdf5.read_attrs = []


#############################################
# turn off Oryx when it is not used
# Oryx = Manta("XF:18IDB-ES{Det:Oryx1}", name="Oryx")
# #Oryx.cam.ensure_nonblocking()
# Oryx.read_attrs = ["hdf5"]
# #Oryx.stats1.read_attrs = ["total"]
# Oryx.hdf5.read_attrs = ["time_stamp"]
# Oryx.stage_sigs["cam.image_mode"] = 1
# for k in ("image", ):
# getattr(Oryx, k).ensure_nonblocking()
# Oryx.hdf5.time_stamp.name = "Oryx_timestamps"
#############################################

#for det in [detA1, Andor]:
for det in [detA1]:
det.stats1.total.kind = "hinted"
# It does not work since it's not defined in the class, commenting out:
# det.stats5.total.kind = 'hinted'

#############################################
# added by XH
CAM_RD_CFG = {
"MARANA-4BV6X": {
"rd_time": {
'12-bit (low noise)': 0.011,
'16-bit (high dynamic rang': 0.014,
'11-bit (high speed)': 0.007
},
"pxl_encoding": {
'12-bit (low noise)': 'Mono12',
'16-bit (high dynamic rang': 'Mono16',
'11-bit (high speed)': 'Mono12'},
"image_mode": MaranaU.cam.image_mode.metadata["enum_strs"],
"trigger_mode": MaranaU.cam.trigger_mode.metadata["enum_strs"],
},
}

def cfg_cam_encoding(cam):
cam_model = cam.cam.model.value
yield from abs_set(cam.pxl_encoding, CAM_RD_CFG[cam_model]["pxl_encoding"][cam.pre_amp.enum_strs[cam.pre_amp.value]], wait=True)

Loading
Loading