mirror of
https://github.com/bec-project/ophyd_devices.git
synced 2025-07-09 10:18:03 +02:00
Can start an acquisition
This commit is contained in:
@ -6,7 +6,7 @@ Created on Wed Dec 6 11:33:54 2023
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from ophyd import Device, Component, EpicsMotor, EpicsSignal, EpicsSignalRO, Kind
|
from ophyd import Device, Component, EpicsMotor, EpicsSignal, EpicsSignalRO, Kind
|
||||||
from ophyd.status import Status, SubscriptionStatus, StatusBase
|
from ophyd.status import Status, SubscriptionStatus, StatusBase, DeviceStatus
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import warnings
|
import warnings
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@ -39,13 +39,13 @@ class HelgeCameraCore(Device):
|
|||||||
# ########################################################################
|
# ########################################################################
|
||||||
# Polled state maschine with separate transition states
|
# Polled state maschine with separate transition states
|
||||||
camStatusCode = Component(EpicsSignalRO, "STATUSCODE", auto_monitor=True, kind=Kind.config)
|
camStatusCode = Component(EpicsSignalRO, "STATUSCODE", auto_monitor=True, kind=Kind.config)
|
||||||
camSetParam = Component(EpicsSignalRO, "SET_PARAM", auto_monitor=True, kind=Kind.config)
|
camSetParam = Component(EpicsSignal, "SET_PARAM", auto_monitor=True, kind=Kind.config)
|
||||||
camSetParamBusy = Component(EpicsSignalRO, "BUSY_SET_PARAM", auto_monitor=True, kind=Kind.config)
|
camSetParamBusy = Component(EpicsSignalRO, "BUSY_SET_PARAM", auto_monitor=True, kind=Kind.config)
|
||||||
camCamera = Component(EpicsSignalRO, "CAMERA", auto_monitor=True, kind=Kind.config)
|
camCamera = Component(EpicsSignalRO, "CAMERA", auto_monitor=True, kind=Kind.config)
|
||||||
camCameraBusy = Component(EpicsSignalRO, "BUSY_CAMERA", auto_monitor=True, kind=Kind.config)
|
camCameraBusy = Component(EpicsSignalRO, "BUSY_CAMERA", auto_monitor=True, kind=Kind.config)
|
||||||
camInit= Component(EpicsSignalRO, "INIT", auto_monitor=True, kind=Kind.config)
|
camInit= Component(EpicsSignalRO, "INIT", auto_monitor=True, kind=Kind.config)
|
||||||
camInitBusy = Component(EpicsSignalRO, "BUSY_INIT", auto_monitor=True, kind=Kind.config)
|
camInitBusy = Component(EpicsSignalRO, "BUSY_INIT", auto_monitor=True, kind=Kind.config)
|
||||||
camRemoved = Component(EpicsSignalRO, "REMOVAL", auto_monitor=True, kind=Kind.config)
|
#camRemoval = Component(EpicsSignalRO, "REMOVAL", auto_monitor=True, kind=Kind.config)
|
||||||
|
|
||||||
camStateString = Component(EpicsSignalRO, "SS_CAMERA", string=True, auto_monitor=True, kind=Kind.config)
|
camStateString = Component(EpicsSignalRO, "SS_CAMERA", string=True, auto_monitor=True, kind=Kind.config)
|
||||||
|
|
||||||
@ -61,8 +61,8 @@ class HelgeCameraCore(Device):
|
|||||||
return "RUNNING"
|
return "RUNNING"
|
||||||
if self.camRemoval.value==0 and self.camInit.value==0:
|
if self.camRemoval.value==0 and self.camInit.value==0:
|
||||||
return "OFFLINE"
|
return "OFFLINE"
|
||||||
if self.camRemoval.value:
|
#if self.camRemoval.value:
|
||||||
return "REMOVED"
|
# return "REMOVED"
|
||||||
return "UNKNOWN"
|
return "UNKNOWN"
|
||||||
|
|
||||||
@state.setter
|
@state.setter
|
||||||
@ -76,20 +76,26 @@ class HelgeCameraCore(Device):
|
|||||||
def stage(self) -> None:
|
def stage(self) -> None:
|
||||||
""" Start acquisition"""
|
""" Start acquisition"""
|
||||||
|
|
||||||
# State transitions are only allowed when the IOC is not busy
|
# Acquisition is only allowed when the IOC is not busy
|
||||||
if self.state not in ("OFFLINE", "BUSY", "REMOVED", "RUNNING"):
|
if self.state in ("OFFLINE", "BUSY", "REMOVED", "RUNNING"):
|
||||||
raise RuntimeError(f"Camera in in state: {self.state}")
|
raise RuntimeError(f"Camera in in state: {self.state}")
|
||||||
|
|
||||||
# Start the acquisition
|
# Start the acquisition (this sets parameers and starts acquisition)
|
||||||
self.camStatusCmd.set("Running").wait()
|
self.camStatusCmd.set("Running").wait()
|
||||||
|
|
||||||
|
# Subscribe and wait for update
|
||||||
|
def isRunning(*args, old_value, value, timestamp, **kwargs):
|
||||||
|
return bool(self.state=="RUNNING")
|
||||||
|
status = SubscriptionStatus(self.camStatusCode, isRunning, settle_time=0.2)
|
||||||
|
status.wait()
|
||||||
|
# Call parent
|
||||||
super().stage()
|
super().stage()
|
||||||
|
|
||||||
def kickoff(self, settle_time=0.2) -> DeviceStatus:
|
def kickoff(self, settle_time=0.2) -> DeviceStatus:
|
||||||
""" Start acquisition"""
|
""" Start acquisition"""
|
||||||
|
|
||||||
# State transitions are only allowed when the IOC is not busy
|
# Acquisition is only allowed when the IOC is not busy
|
||||||
if self.state not in ("OFFLINE", "BUSY", "REMOVED", "RUNNING"):
|
if self.state in ("OFFLINE", "BUSY", "REMOVED", "RUNNING"):
|
||||||
raise RuntimeError(f"Camera in in state: {self.state}")
|
raise RuntimeError(f"Camera in in state: {self.state}")
|
||||||
|
|
||||||
# Start the acquisition
|
# Start the acquisition
|
||||||
@ -106,11 +112,11 @@ class HelgeCameraCore(Device):
|
|||||||
def stop(self):
|
def stop(self):
|
||||||
""" Stop the running acquisition """
|
""" Stop the running acquisition """
|
||||||
self.camStatusCmd.set("Idle").wait()
|
self.camStatusCmd.set("Idle").wait()
|
||||||
|
super().unstage()
|
||||||
|
|
||||||
def unstage(self):
|
def unstage(self):
|
||||||
""" Stop the running acquisition and unstage the device"""
|
""" Stop the running acquisition and unstage the device"""
|
||||||
self.camStatusCmd.set("Idle").wait()
|
self.camStatusCmd.set("Idle").wait()
|
||||||
|
|
||||||
super().unstage()
|
super().unstage()
|
||||||
|
|
||||||
|
|
||||||
@ -203,9 +209,10 @@ class HelgeCameraBase(HelgeCameraCore):
|
|||||||
old = self.read_configuration()
|
old = self.read_configuration()
|
||||||
super().configure(d)
|
super().configure(d)
|
||||||
|
|
||||||
exposure_time = d['exptime']
|
if "exptime" in d:
|
||||||
if exposure_time is not None:
|
exposure_time = d['exptime']
|
||||||
self.acqExpTime.set(exposure_time).wait()
|
if exposure_time is not None:
|
||||||
|
self.acqExpTime.set(exposure_time).wait()
|
||||||
|
|
||||||
if "roi" in d:
|
if "roi" in d:
|
||||||
roi = d["roi"]
|
roi = d["roi"]
|
||||||
@ -247,7 +254,7 @@ class HelgeCameraBase(HelgeCameraCore):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def shape(self):
|
def shape(self):
|
||||||
return (self.pxNumX.value, self.pxNumY.value)
|
return (int(self.pxNumX.value), int(self.pxNumY.value))
|
||||||
|
|
||||||
@shape.setter
|
@shape.setter
|
||||||
def shape(self):
|
def shape(self):
|
||||||
@ -255,7 +262,7 @@ class HelgeCameraBase(HelgeCameraCore):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def bin(self):
|
def bin(self):
|
||||||
return (self.pxBinX.value, self.pxBinY.value)
|
return (int(self.pxBinX.value), int(self.pxBinY.value))
|
||||||
|
|
||||||
@bin.setter
|
@bin.setter
|
||||||
def bin(self):
|
def bin(self):
|
||||||
@ -263,7 +270,7 @@ class HelgeCameraBase(HelgeCameraCore):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def roi(self):
|
def roi(self):
|
||||||
return ((self.pxRoiX_lo.value, self.pxRoiX_hi.value), (self.pxRoiY_lo.value, self.pxRoiY_hi.value))
|
return ((int(self.pxRoiX_lo.value), int(self.pxRoiX_hi.value)), (int(self.pxRoiY_lo.value), int(self.pxRoiY_hi.value)))
|
||||||
|
|
||||||
@roi.setter
|
@roi.setter
|
||||||
def roi(self):
|
def roi(self):
|
||||||
@ -279,28 +286,6 @@ class HelgeCameraBase(HelgeCameraCore):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Automatically connect to test camera if directly invoked
|
# Automatically connect to test camera if directly invoked
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user