use pyepics automonitor and callbacks

This commit is contained in:
gac-x10da
2025-09-11 17:11:47 +02:00
committed by appel_c
parent abcf910faf
commit f643b50f5c
+56 -33
View File
@@ -2,50 +2,73 @@
# PyEpics version of the script
import time
import threading
import epics
# Define PVs
I0 = epics.PV("X10DA-ES1-SAI_01:MEAN")
Trigger = epics.PV("X10DA-ES1:SMPL")
TriggerDone = epics.PV("X10DA-ES1:SMPL-DONE")
def main():
# Define PVs
I0 = epics.PV("X10DA-ES1-SAI_01:MEAN")
Trigger = epics.PV("X10DA-ES1:SMPL")
TriggerDone = epics.PV("X10DA-ES1:SMPL-DONE", auto_monitor=True)
XMAPStart = epics.PV("X10DA-SITORO:EraseStart")
XMAPStop = epics.PV("X10DA-SITORO:StopAll")
XMAPAcquiring = epics.PV("X10DA-SITORO:Acquiring")
XMAPICR = epics.PV("X10DA-SITORO:dxp1:InputCountRate")
XMAPOCR = epics.PV("X10DA-SITORO:dxp1:OutputCountRate")
XMAPROI = epics.PV("X10DA-SITORO:mca1.R0")
XMAPStart = epics.PV("X10DA-SITORO:EraseStart")
XMAPStop = epics.PV("X10DA-SITORO:StopAll")
XMAPAcquiring = epics.PV("X10DA-SITORO:Acquiring", auto_monitor=True)
XMAPICR = epics.PV("X10DA-SITORO:dxp1:InputCountRate")
XMAPOCR = epics.PV("X10DA-SITORO:dxp1:OutputCountRate")
XMAPROI = epics.PV("X10DA-SITORO:mca1.R0")
# Wait for connections (optional)
for pv in [I0, Trigger, TriggerDone, XMAPStart, XMAPStop, XMAPAcquiring, XMAPICR, XMAPOCR, XMAPROI]:
pv.wait_for_connection(timeout=2)
acquire_started = threading.Event()
acquire_stopped = threading.Event()
trigger_done = threading.Event()
# Measurement loop
for i in range(25):
start_time = time.time()
XMAPStart.put(1, wait=True)
def acquiring_cb(pvname=None, value=None, **kwargs):
if value == 1:
acquire_started.set()
elif value == 0:
acquire_stopped.set()
while XMAPAcquiring.get() == 0:
time.sleep(0.05)
def trigger_done_cb(pvname=None, value=None, **kwargs):
if value == 1:
trigger_done.set()
Trigger.put(1, wait=True)
time.sleep(0.2)
# Wait for connections (optional)
for pv in [I0, Trigger, TriggerDone, XMAPStart, XMAPStop, XMAPAcquiring, XMAPICR, XMAPOCR, XMAPROI]:
pv.wait_for_connection(timeout=2)
while TriggerDone.get() == 0:
time.sleep(0.05)
TriggerDone.add_callback(trigger_done_cb)
XMAPAcquiring.add_callback(acquiring_cb)
XMAPStop.put(1, wait=True)
# Measurement loop
for i in range(25):
acquire_started.clear()
acquire_stopped.clear()
trigger_done.clear()
while XMAPAcquiring.get() == 1:
time.sleep(0.05)
start_time = time.time()
XMAPStart.put(1, wait=False)
time.sleep(0.1)
acquire_started.wait(timeout=5)
i0 = I0.get()
icr = XMAPICR.get()
ocr = XMAPOCR.get()
roi = XMAPROI.get()
end_time = time.time()
Trigger.put(1, wait=False)
print(f"time={end_time - start_time:.4f}", i0, icr, ocr, roi)
trigger_done.wait(3)
XMAPStop.put(1, wait=True)
acquire_stopped.wait(5)
time.sleep(0.1)
i0 = I0.get()
icr = XMAPICR.get()
ocr = XMAPOCR.get()
roi = XMAPROI.get()
end_time = time.time()
print(f"time={end_time - start_time:.4f}", i0, icr, ocr, roi)
if __name__=="__main__":
main()