Commit 829f6e29 authored by ahoms's avatar ahoms

* first implementation of CtControl::reset

* added common/python/Debug.py with debug helpers and decorators,
  include module as namespace and file name and line number
* updated debug testfreloninterface/control.py and [Frelon]TacoCcd.py



git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@204 45c4679d-1946-429d-baad-37912b19538b
parent b3e8bbc3
import os, sys, string, gc, time
from lima import *
from Debug import *
import processlib
glob_deb_params = DebParams(DebModTest)
DEB_GLOBAL(DebModTest)
class ImageStatusCallback(CtControl.ImageStatusCallback):
deb_params = DebParams(DebModTest, "ImageStatusCallback")
def __init__(self, ct, acq_state, print_time=1):
deb_params = DebObj(self.deb_params, "__init__")
DEB_CLASS(DebModTest, "ImageStatusCallback")
@DEB_MEMBER_FUNCT
def __init__(self, ct, acq_state, print_time=1):
CtControl.ImageStatusCallback.__init__(self)
self.m_ct = ct
......@@ -20,9 +20,8 @@ class ImageStatusCallback(CtControl.ImageStatusCallback):
self.m_last_print_ts = 0
self.m_print_time = print_time
@DEB_MEMBER_FUNCT
def imageStatusChanged(self, img_status):
deb_params = DebObj(self.deb_params, "imageStatusChanged")
last_acq_frame_nb = img_status.LastImageAcquired;
last_saved_frame_nb = img_status.LastImageSaved;
......@@ -46,22 +45,21 @@ class ImageStatusCallback(CtControl.ImageStatusCallback):
now = time.time()
if ((now - self.m_last_print_ts >= self.m_print_time) or
acq_state_changed):
deb_obj.Always("Last Acquired: %8d, Last Saved: %8d" %
(last_acq_frame_nb, last_saved_frame_nb))
deb.Always("Last Acquired: %8d, Last Saved: %8d" %
(last_acq_frame_nb, last_saved_frame_nb))
self.m_last_print_ts = now
if msg:
deb_obj.Always(msg)
deb.Always(msg)
class FrelonAcq:
deb_params = DebParams(DebModTest, "FrelonAcq")
DEB_CLASS(DebModTest, "FrelonAcq")
@DEB_MEMBER_FUNCT
def __init__(self, espia_dev_nb, use_events=False, print_time=1):
deb_obj = DebObj(self.deb_params, "__init__")
self.m_edev = Espia.Dev(espia_dev_nb)
self.m_acq = Espia.Acq(self.m_edev)
self.m_buffer_cb_mgr = Espia.BufferMgr(self.m_acq)
......@@ -88,9 +86,8 @@ class FrelonAcq:
else:
self.m_poll_time = 0.1
@DEB_MEMBER_FUNCT
def __del__(self):
deb_obj = DebObj(self.deb_params, "__del__")
if self.m_use_events:
del self.m_img_status_cb; gc.collect()
......@@ -105,16 +102,14 @@ class FrelonAcq:
del self.m_acq; gc.collect()
del self.m_edev; gc.collect()
@DEB_MEMBER_FUNCT
def start(self):
deb_obj = DebObj(self.deb_params, "start")
self.m_ct.prepareAcq()
self.m_acq_state.set(AcqState.Acquiring)
self.m_ct.startAcq()
@DEB_MEMBER_FUNCT
def wait(self):
deb_obj = DebObj(self.deb_params, "wait")
if self.m_use_events:
state_mask = AcqState.Acquiring | AcqState.Saving
self.m_acq_state.waitNot(state_mask)
......@@ -143,8 +138,8 @@ class FrelonAcq:
now = time.time()
if ((now - last_print_ts >= self.m_print_time) or
acq_state_changed):
deb_obj.Always("Last Acquired: %8d, Last Saved: %8d" %
(last_acq_frame_nb, last_saved_frame_nb))
deb.Always("Last Acquired: %8d, Last Saved: %8d" %
(last_acq_frame_nb, last_saved_frame_nb))
last_print_ts = now
if msg:
......@@ -155,15 +150,13 @@ class FrelonAcq:
pool_thread_mgr = processlib.PoolThreadMgr.get()
pool_thread_mgr.wait()
@DEB_MEMBER_FUNCT
def run(self):
deb_obj = DebObj(self.deb_params, "run")
self.start()
self.wait()
@DEB_MEMBER_FUNCT
def initSaving(self, dir, prefix, suffix, idx, fmt, mode, frames_per_file):
deb_obj = DebObj(self.deb_params, "initSaving")
self.m_ct_saving.setDirectory(dir)
self.m_ct_saving.setPrefix(prefix)
self.m_ct_saving.setSuffix(suffix)
......@@ -172,42 +165,41 @@ class FrelonAcq:
self.m_ct_saving.setSavingMode(mode)
self.m_ct_saving.setFramesPerFile(frames_per_file)
@DEB_MEMBER_FUNCT
def setExpTime(self, exp_time):
deb_obj = DebObj(self.deb_params, "setExpTime")
self.m_ct_acq.setAcqExpoTime(exp_time)
@DEB_MEMBER_FUNCT
def setNbAcqFrames(self, nb_acq_frames):
deb_obj = DebObj(self.deb_params, "setNbAcqFrames")
self.m_ct_acq.setAcqNbFrames(nb_acq_frames)
@DEB_MEMBER_FUNCT
def setBin(self, bin):
deb_obj = DebObj(self.deb_params, "setBin")
self.m_ct_image.setBin(bin)
@DEB_MEMBER_FUNCT
def setRoi(self, roi):
deb_obj = DebObj(self.deb_params, "setRoi")
self.m_ct_image.setRoi(roi)
@DEB_GLOBAL_FUNCT
def test_frelon_control(enable_debug):
deb_obj = DebObj(glob_deb_params, "test_frelon_control")
if not enable_debug:
DebParams.disableModuleFlags(DebParams.AllFlags)
deb_obj.Always("Creating FrelonAcq")
deb.Always("Creating FrelonAcq")
espia_dev_nb = 0
use_events = False
acq = FrelonAcq(espia_dev_nb, use_events)
deb_obj.Always("Done!")
deb.Always("Done!")
acq.initSaving("data", "img", ".edf", 0, CtSaving.EDF,
CtSaving.AutoFrame, 1);
deb_obj.Always("First run with default pars")
deb.Always("First run with default pars")
acq.run()
deb_obj.Always("Done!")
deb.Always("Done!")
exp_time = 1e-6
acq.setExpTime(exp_time)
......@@ -215,10 +207,9 @@ def test_frelon_control(enable_debug):
nb_acq_frames = 500
acq.setNbAcqFrames(nb_acq_frames)
deb_obj.Always("Run exp_time=%s, nb_acq_frames=%s" %
(exp_time, nb_acq_frames))
deb.Always("Run exp_time=%s, nb_acq_frames=%s" % (exp_time, nb_acq_frames))
acq.run()
deb_obj.Always("Done!")
deb.Always("Done!")
bin = Bin(2, 2)
acq.setBin(bin)
......@@ -226,30 +217,30 @@ def test_frelon_control(enable_debug):
nb_acq_frames = 5
acq.setNbAcqFrames(nb_acq_frames)
deb_obj.Always("Run bin=<%sx%s>, nb_acq_frames=%s" %
(bin.getX(), bin.getY(), nb_acq_frames))
deb.Always("Run bin=<%sx%s>, nb_acq_frames=%s" %
(bin.getX(), bin.getY(), nb_acq_frames))
acq.run()
deb_obj.Always("Done!")
deb.Always("Done!")
roi = Roi(Point(256, 256), Size(512, 512));
acq.setRoi(roi);
roi_tl, roi_size = roi.getTopLeft(), roi.getSize()
deb_obj.Always("Run roi=<%s,%s>-<%sx%s>" %
(roi_tl.x, roi_tl.y,
roi_size.getWidth(), roi_size.getHeight()))
deb.Always("Run roi=<%s,%s>-<%sx%s>" %
(roi_tl.x, roi_tl.y,
roi_size.getWidth(), roi_size.getHeight()))
acq.run()
deb_obj.Always("Done!")
deb.Always("Done!")
roi = Roi(Point(267, 267), Size(501, 501));
acq.setRoi(roi);
roi_tl, roi_size = roi.getTopLeft(), roi.getSize()
deb_obj.Always("Run roi=<%s,%s>-<%sx%s>" %
(roi_tl.x, roi_tl.y,
roi_size.getWidth(), roi_size.getHeight()))
deb.Always("Run roi=<%s,%s>-<%sx%s>" %
(roi_tl.x, roi_tl.y,
roi_size.getWidth(), roi_size.getHeight()))
acq.run()
deb_obj.Always("Done!")
deb.Always("Done!")
def main(argv):
......
import sys
from lima import *
from Debug import *
import processlib
import time
import numpy as N
......@@ -17,11 +18,11 @@ Data_FLOAT = 9
Data_DOUBLE = 10
glob_deb_params = DebParams(DebModTest)
DEB_GLOBAL(DebModTest)
class SoftRoiCallback( processlib.TaskEventCallback ):
deb_params = DebParams(DebModTest, "SoftRoiCallback")
DEB_CLASS(DebModTest, "SoftRoiCallback")
DataType2ImageType = {
N.int8: Bpp8,
......@@ -31,18 +32,16 @@ class SoftRoiCallback( processlib.TaskEventCallback ):
N.int32: Bpp32,
N.uint32: Bpp32
}
@DEB_MEMBER_FUNCT
def __init__(self, hw_inter, buffer_save, acq_state):
deb_obj = DebObj(self.deb_params, "__init__")
processlib.TaskEventCallback.__init__(self)
self.m_hw_inter = hw_inter
self.m_buffer_save = buffer_save
self.m_acq_state = acq_state
@DEB_MEMBER_FUNCT
def finished(self, data):
deb_obj = DebObj(self.deb_params, "finished")
finfo, fdim = self.data2FrameInfo(data)
self.m_buffer_save.writeFrame(finfo)
......@@ -51,9 +50,8 @@ class SoftRoiCallback( processlib.TaskEventCallback ):
if finfo.acq_frame_nb == nb_frames - 1:
self.m_acq_state.set(AcqState.Finished)
@DEB_MEMBER_FUNCT
def data2FrameInfo(self, data):
deb_obj = DebObj(self.deb_params, "data2FrameInfo")
arr = data.buffer
arr_type = arr.dtype.type
arr_height, arr_width = arr.shape
......@@ -74,7 +72,7 @@ class SoftRoiCallback( processlib.TaskEventCallback ):
class TestFrameCallback( HwFrameCallback ):
deb_params = DebParams(DebModTest, "TestFrameCallback")
DEB_CLASS(DebModTest, "TestFrameCallback")
ImageType2DataType = {
Bpp8: Data_UINT8,
......@@ -82,9 +80,8 @@ class TestFrameCallback( HwFrameCallback ):
Bpp32: Data_UINT32
}
@DEB_MEMBER_FUNCT
def __init__(self, hw_inter, soft_roi, buffer_save, acq_state):
deb_obj = DebObj(self.deb_params, "__init__")
HwFrameCallback.__init__(self)
self.m_hw_inter = hw_inter
self.m_soft_roi = soft_roi
......@@ -93,9 +90,8 @@ class TestFrameCallback( HwFrameCallback ):
self.m_roi_cb = SoftRoiCallback(hw_inter, buffer_save,
acq_state)
@DEB_MEMBER_FUNCT
def newFrameReady(self, frame_info):
deb_obj = DebObj(self.deb_params, "newFrameReady")
msg = 'acq_frame_nb=%d, ' % frame_info.acq_frame_nb
fdim = frame_info.frame_dim
size = fdim.getSize()
......@@ -103,7 +99,7 @@ class TestFrameCallback( HwFrameCallback ):
(size.getWidth(), size.getHeight(), fdim.getDepth())
msg += 'frame_timestamp=%.6f, ' % frame_info.frame_timestamp
msg += 'valid_pixels=%d' % frame_info.valid_pixels
deb_obj.Always("newFrameReady: %s" % msg)
deb.Always("newFrameReady: %s" % msg)
data = self.frameInfo2Data(frame_info)
......@@ -114,9 +110,8 @@ class TestFrameCallback( HwFrameCallback ):
return True
@DEB_MEMBER_FUNCT
def frameInfo2Data(self, frame_info):
deb_obj = DebObj(self.deb_params, "frameInfo2Data")
data = processlib.Data()
data.buffer = frame_info.frame_ptr
data.frameNumber = frame_info.acq_frame_nb
......@@ -127,83 +122,81 @@ class TestFrameCallback( HwFrameCallback ):
class MaxImageSizeCallback( HwMaxImageSizeCallback ):
deb_params = DebParams(DebModTest, "MaxImageSizeCallback")
DEB_CLASS(DebModTest, "MaxImageSizeCallback")
@DEB_MEMBER_FUNCT
def maxImageSizeChanged(self, size, image_type):
deb_obj = DebObj(self.deb_params, "maxImageSizeChanged")
fdim = FrameDim(size, image_type)
msg = "size=%sx%s, image_type=%s, depth=%d" % \
(size.getWidth(), size.getHeight(), image_type, \
fdim.getDepth())
deb_obj.Always("MaxImageSizeChanged: " % msg)
deb.Always("MaxImageSizeChanged: %s" % msg)
@DEB_GLOBAL_FUNCT
def main(argv):
deb_obj = DebObj(glob_deb_params, "main")
deb_obj.Always("Creating Espia.Dev")
deb.Always("Creating Espia.Dev")
edev = Espia.Dev(0)
deb_obj.Always("Creating Espia.Acq")
deb.Always("Creating Espia.Acq")
acq = Espia.Acq(edev)
acqstat = acq.getStatus()
deb_obj.Always("Whether the Acquisition is running : %s" %
deb.Always("Whether the Acquisition is running : %s" %
acqstat.running)
deb_obj.Always("Creating Espia.BufferMgr")
deb.Always("Creating Espia.BufferMgr")
buffer_cb_mgr = Espia.BufferMgr(acq)
deb_obj.Always("Creating BufferCtrlMgr")
deb.Always("Creating BufferCtrlMgr")
buffer_mgr = BufferCtrlMgr(buffer_cb_mgr)
deb_obj.Always("Creating Espia.SerialLine")
deb.Always("Creating Espia.SerialLine")
eser_line = Espia.SerialLine(edev)
deb_obj.Always("Creating Frelon.Camera")
deb.Always("Creating Frelon.Camera")
cam = Frelon.Camera(eser_line)
deb_obj.Always("Creating the Hw Interface ... ")
deb.Always("Creating the Hw Interface ... ")
hw_inter = Frelon.Interface(acq, buffer_mgr, cam)
deb_obj.Always("Creating BufferSave")
deb.Always("Creating BufferSave")
buffer_save = BufferSave(BufferSave.EDF, "img", 0, ".edf", True, 1)
deb_obj.Always("Getting HW detector info")
deb.Always("Getting HW detector info")
hw_det_info = hw_inter.getHwCtrlObj(HwCap.DetInfo)
deb_obj.Always("Getting HW buffer")
deb.Always("Getting HW buffer")
hw_buffer = hw_inter.getHwCtrlObj(HwCap.Buffer)
deb_obj.Always("Getting HW Sync")
deb.Always("Getting HW Sync")
hw_sync = hw_inter.getHwCtrlObj(HwCap.Sync)
deb_obj.Always("Getting HW Bin")
deb.Always("Getting HW Bin")
hw_bin = hw_inter.getHwCtrlObj(HwCap.Bin)
deb_obj.Always("Getting HW RoI")
deb.Always("Getting HW RoI")
hw_roi = hw_inter.getHwCtrlObj(HwCap.Roi)
mis_cb = MaxImageSizeCallback()
hw_det_info.registerMaxImageSizeCallback(mis_cb)
deb_obj.Always("Setting FTM")
deb.Always("Setting FTM")
cam.setFrameTransferMode(Frelon.FTM)
deb_obj.Always("Setting FFM")
deb.Always("Setting FFM")
cam.setFrameTransferMode(Frelon.FFM)
soft_roi = Roi()
acq_state = AcqState()
deb_obj.Always("Creating a TestFrameCallback")
deb.Always("Creating a TestFrameCallback")
cb = TestFrameCallback(hw_inter, soft_roi, buffer_save, acq_state)
do_reset = False
if do_reset:
deb_obj.Always("Reseting hardware ...")
deb.Always("Reseting hardware ...")
hw_inter.reset(HwInterface.HardReset)
deb_obj.Always(" Done!")
deb.Always(" Done!")
size = hw_det_info.getMaxImageSize()
image_type = hw_det_info.getCurrImageType()
......@@ -223,18 +216,18 @@ def main(argv):
hw_sync.setExpTime(2)
hw_sync.setNbFrames(3)
deb_obj.Always("Starting Acquisition")
deb.Always("Starting Acquisition")
acq_state.set(AcqState.Acquiring)
hw_inter.startAcq()
deb_obj.Always("Waiting acq finished...")
deb.Always("Waiting acq finished...")
acq_state.waitNot(AcqState.Acquiring)
deb_obj.Always("Acq finished!!")
deb.Always("Acq finished!!")
deb_obj.Always("Stopping Acquisition")
deb.Always("Stopping Acquisition")
hw_inter.stopAcq()
deb_obj.Always("This is the End...")
deb.Always("This is the End...")
if __name__ == '__main__':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment