Commit 7596d0db authored by ahoms's avatar ahoms

* first wrapping of DebObj in sip,

  used in testfreloninterface/control.py


git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@201 45c4679d-1946-429d-baad-37912b19538b
parent fcacd999
......@@ -2,10 +2,17 @@ import os, sys, string, gc, time
import lima
import processlib
deb_params = lima.DebParams(lima.DebModTest)
class ImageStatusCallback(lima.CtControl.ImageStatusCallback):
deb_params = lima.DebParams(lima.DebModTest, "ImageStatusCallback")
def __init__(self, ct, acq_state, print_time=1):
deb_params = lima.DebObj(self.deb_params, "__init__")
lima.CtControl.ImageStatusCallback.__init__(self)
self.m_ct = ct
self.m_acq_state = acq_state
self.m_nb_frames = 0
......@@ -14,6 +21,8 @@ class ImageStatusCallback(lima.CtControl.ImageStatusCallback):
self.m_print_time = print_time
def imageStatusChanged(self, img_status):
deb_params = lima.DebObj(self.deb_params, "imageStatusChanged")
last_acq_frame_nb = img_status.LastImageAcquired;
last_saved_frame_nb = img_status.LastImageSaved;
......@@ -37,17 +46,23 @@ class ImageStatusCallback(lima.CtControl.ImageStatusCallback):
now = time.time()
if ((now - self.m_last_print_ts >= self.m_print_time) or
acq_state_changed):
print "Last Acquired: %8d, Last Saved: %8d" % (last_acq_frame_nb, \
last_saved_frame_nb)
deb_msg = ("Last Acquired: %8d, Last Saved: %8d" %
(last_acq_frame_nb, last_saved_frame_nb))
print >> deb_obj.Always(), deb_msg
self.m_last_print_ts = now
if msg:
print msg
print >> deb_obj.Always(), msg
class FrelonAcq:
deb_params = lima.DebParams(lima.DebModTest, "FrelonAcq")
def __init__(self, espia_dev_nb, use_events=False, print_time=1):
deb_obj = lima.DebObj(self.deb_params, "__init__")
self.m_edev = lima.Espia.Dev(espia_dev_nb)
self.m_acq = lima.Espia.Acq(self.m_edev)
self.m_buffer_cb_mgr = lima.Espia.BufferMgr(self.m_acq)
......@@ -75,6 +90,8 @@ class FrelonAcq:
self.m_poll_time = 0.1
def __del__(self):
deb_obj = lima.DebObj(self.deb_params, "__del__")
if self.m_use_events:
del self.m_img_status_cb; gc.collect()
......@@ -90,11 +107,15 @@ class FrelonAcq:
del self.m_edev; gc.collect()
def start(self):
deb_obj = lima.DebObj(self.deb_params, "start")
self.m_ct.prepareAcq()
self.m_acq_state.set(lima.AcqState.Acquiring)
self.m_ct.startAcq()
def wait(self):
deb_obj = lima.DebObj(self.deb_params, "wait")
if self.m_use_events:
state_mask = lima.AcqState.Acquiring | lima.AcqState.Saving
self.m_acq_state.waitNot(state_mask)
......@@ -123,8 +144,9 @@ class FrelonAcq:
now = time.time()
if ((now - last_print_ts >= self.m_print_time) or
acq_state_changed):
print "Last Acquired: %8d, Last Saved: %8d" % \
(last_acq_frame_nb, last_saved_frame_nb)
deb_msg = ("Last Acquired: %8d, Last Saved: %8d" %
(last_acq_frame_nb, last_saved_frame_nb))
print >> deb_obj.Always(), deb_msg
last_print_ts = now
if msg:
......@@ -136,10 +158,14 @@ class FrelonAcq:
pool_thread_mgr.wait()
def run(self):
deb_obj = lima.DebObj(self.deb_params, "run")
self.start()
self.wait()
def initSaving(self, dir, prefix, suffix, idx, fmt, mode, frames_per_file):
deb_obj = lima.DebObj(self.deb_params, "initSaving")
self.m_ct_saving.setDirectory(dir)
self.m_ct_saving.setPrefix(prefix)
self.m_ct_saving.setSuffix(suffix)
......@@ -149,35 +175,41 @@ class FrelonAcq:
self.m_ct_saving.setFramesPerFile(frames_per_file)
def setExpTime(self, exp_time):
deb_obj = lima.DebObj(self.deb_params, "setExpTime")
self.m_ct_acq.setAcqExpoTime(exp_time)
def setNbAcqFrames(self, nb_acq_frames):
deb_obj = lima.DebObj(self.deb_params, "setNbAcqFrames")
self.m_ct_acq.setAcqNbFrames(nb_acq_frames)
def setBin(self, bin):
deb_obj = lima.DebObj(self.deb_params, "setBin")
self.m_ct_image.setBin(bin)
def setRoi(self, roi):
deb_obj = lima.DebObj(self.deb_params, "setRoi")
self.m_ct_image.setRoi(roi)
def test_frelon_control(enable_debug):
deb_obj = lima.DebObj(deb_params, "test_frelon_control")
if not enable_debug:
lima.DebParams.disableModuleFlags(lima.DebParams.AllFlags)
print "Crating FrelonAcq"
print >> deb_obj.Always(), "Creating FrelonAcq"
espia_dev_nb = 0
use_events = False
acq = FrelonAcq(espia_dev_nb, use_events)
print "Done!"
print >> deb_obj.Always(), "Done!"
acq.initSaving("data", "img", ".edf", 0, lima.CtSaving.EDF,
lima.CtSaving.AutoFrame, 1);
print "First run with default pars"
print >> deb_obj.Always(), "First run with default pars"
acq.run()
print "Done!"
print >> deb_obj.Always(), "Done!"
exp_time = 1e-6
acq.setExpTime(exp_time)
......@@ -185,9 +217,10 @@ def test_frelon_control(enable_debug):
nb_acq_frames = 500
acq.setNbAcqFrames(nb_acq_frames)
print "Run exp_time=%s, nb_acq_frames=%s" % (exp_time, nb_acq_frames)
print >> deb_obj.Always(), ("Run exp_time=%s, nb_acq_frames=%s" %
(exp_time, nb_acq_frames))
acq.run()
print "Done!"
print >> deb_obj.Always(), "Done!"
bin = lima.Bin(2, 2)
acq.setBin(bin)
......@@ -195,30 +228,30 @@ def test_frelon_control(enable_debug):
nb_acq_frames = 5
acq.setNbAcqFrames(nb_acq_frames)
print "Run bin=<%sx%s>, nb_acq_frames=%s" % (bin.getX(), bin.getY(),
nb_acq_frames)
print >> deb_obj.Always(), ("Run bin=<%sx%s>, nb_acq_frames=%s" %
(bin.getX(), bin.getY(), nb_acq_frames))
acq.run()
print "Done!"
print >> deb_obj.Always(), "Done!"
roi = lima.Roi(lima.Point(256, 256), lima.Size(512, 512));
acq.setRoi(roi);
roi_tl, roi_size = roi.getTopLeft(), roi.getSize()
print "Run roi=<%s,%s>-<%sx%s>" % (roi_tl.x, roi_tl.y,
roi_size.getWidth(),
roi_size.getHeight())
print >> deb_obj.Always(), ("Run roi=<%s,%s>-<%sx%s>" %
(roi_tl.x, roi_tl.y,
roi_size.getWidth(), roi_size.getHeight()))
acq.run()
print "Done!"
print >> deb_obj.Always(), "Done!"
roi = lima.Roi(lima.Point(267, 267), lima.Size(501, 501));
acq.setRoi(roi);
roi_tl, roi_size = roi.getTopLeft(), roi.getSize()
print "Run roi=<%s,%s>-<%sx%s>" % (roi_tl.x, roi_tl.y,
roi_size.getWidth(),
roi_size.getHeight())
print >> deb_obj.Always(), ("Run roi=<%s,%s>-<%sx%s>" %
(roi_tl.x, roi_tl.y,
roi_size.getWidth(), roi_size.getHeight()))
acq.run()
print "Done!"
print >> deb_obj.Always(), "Done!"
def main(argv):
......
......@@ -17,8 +17,12 @@ Data_FLOAT = 9
Data_DOUBLE = 10
deb_params = lima.DebParams(lima.DebModTest)
class SoftRoiCallback( processlib.TaskEventCallback ):
deb_params = lima.DebParams(lima.DebModTest, "SoftRoiCallback")
DataType2ImageType = {
N.int8: lima.Bpp8,
N.uint8: lima.Bpp8,
......@@ -29,12 +33,16 @@ class SoftRoiCallback( processlib.TaskEventCallback ):
}
def __init__(self, hw_inter, buffer_save, acq_state):
deb_obj = lima.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
def finished(self, data):
deb_obj = lima.DebObj(self.deb_params, "finished")
finfo, fdim = self.data2FrameInfo(data)
self.m_buffer_save.writeFrame(finfo)
......@@ -44,6 +52,8 @@ class SoftRoiCallback( processlib.TaskEventCallback ):
self.m_acq_state.set(lima.AcqState.Finished)
def data2FrameInfo(self, data):
deb_obj = lima.DebObj(self.deb_params, "data2FrameInfo")
arr = data.buffer
arr_type = arr.dtype.type
arr_height, arr_width = arr.shape
......@@ -64,6 +74,8 @@ class SoftRoiCallback( processlib.TaskEventCallback ):
class TestFrameCallback( lima.HwFrameCallback ):
deb_params = lima.DebParams(lima.DebModTest, "TestFrameCallback")
ImageType2DataType = {
lima.Bpp8: Data_UINT8,
lima.Bpp16: Data_UINT16,
......@@ -71,6 +83,8 @@ class TestFrameCallback( lima.HwFrameCallback ):
}
def __init__(self, hw_inter, soft_roi, buffer_save, acq_state):
deb_obj = lima.DebObj(self.deb_params, "__init__")
lima.HwFrameCallback.__init__(self)
self.m_hw_inter = hw_inter
self.m_soft_roi = soft_roi
......@@ -80,6 +94,8 @@ class TestFrameCallback( lima.HwFrameCallback ):
acq_state)
def newFrameReady(self, frame_info):
deb_obj = lima.DebObj(self.deb_params, "newFrameReady")
msg = 'acq_frame_nb=%d, ' % frame_info.acq_frame_nb
fdim = frame_info.frame_dim
size = fdim.getSize()
......@@ -87,7 +103,7 @@ class TestFrameCallback( lima.HwFrameCallback ):
(size.getWidth(), size.getHeight(), fdim.getDepth())
msg += 'frame_timestamp=%.6f, ' % frame_info.frame_timestamp
msg += 'valid_pixels=%d' % frame_info.valid_pixels
print 'newFrameReady:', msg
print >> deb_obj.Always(), "newFrameReady: %s" % msg
data = self.frameInfo2Data(frame_info)
......@@ -99,6 +115,8 @@ class TestFrameCallback( lima.HwFrameCallback ):
return True
def frameInfo2Data(self, frame_info):
deb_obj = lima.DebObj(self.deb_params, "frameInfo2Data")
data = processlib.Data()
data.buffer = frame_info.frame_ptr
data.frameNumber = frame_info.acq_frame_nb
......@@ -109,76 +127,84 @@ class TestFrameCallback( lima.HwFrameCallback ):
class MaxImageSizeCallback( lima.HwMaxImageSizeCallback ):
deb_params = lima.DebParams(lima.DebModTest, "MaxImageSizeCallback")
def maxImageSizeChanged(self, size, image_type):
deb_obj = lima.DebObj(self.deb_params, "maxImageSizeChanged")
fdim = lima.FrameDim(size, image_type)
msg = "size=%sx%s, image_type=%s, depth=%d" % \
(size.getWidth(), size.getHeight(), image_type, \
fdim.getDepth())
print "MaxImageSizeChanged:", msg
print >> deb_obj.Always(), "MaxImageSizeChanged: " % msg
def main(argv):
print "Creating Espia.Dev"
deb_obj = lima.DebObj(deb_params, "main")
print >> deb_obj.Always(), "Creating Espia.Dev"
edev = lima.Espia.Dev(0)
print "Creating Espia.Acq"
print >> deb_obj.Always(), "Creating Espia.Acq"
acq = lima.Espia.Acq(edev)
acqstat = acq.getStatus()
print "Whether the Acquisition is running : ", acqstat.running
print >> deb_obj.Always(), ("Whether the Acquisition is running : ",
acqstat.running)
print "Creating Espia.BufferMgr"
print >> deb_obj.Always(), "Creating Espia.BufferMgr"
buffer_cb_mgr = lima.Espia.BufferMgr(acq)
print "Creating BufferCtrlMgr"
print >> deb_obj.Always(), "Creating BufferCtrlMgr"
buffer_mgr = lima.BufferCtrlMgr(buffer_cb_mgr)
print "Creating Espia.SerialLine"
print >> deb_obj.Always(), "Creating Espia.SerialLine"
eser_line = lima.Espia.SerialLine(edev)
print "Creating Frelon.Camera"
print >> deb_obj.Always(), "Creating Frelon.Camera"
cam = lima.Frelon.Camera(eser_line)
print "Creating the Hw Interface ... "
print >> deb_obj.Always(), "Creating the Hw Interface ... "
hw_inter = lima.Frelon.Interface(acq, buffer_mgr, cam)
print "Creating BufferSave"
print >> deb_obj.Always(), "Creating BufferSave"
buffer_save = lima.BufferSave(lima.BufferSave.EDF, "img", 0, ".edf",
True, 1)
print "Getting HW detector info"
print >> deb_obj.Always(), "Getting HW detector info"
hw_det_info = hw_inter.getHwCtrlObj(lima.HwCap.DetInfo)
print "Getting HW buffer"
print >> deb_obj.Always(), "Getting HW buffer"
hw_buffer = hw_inter.getHwCtrlObj(lima.HwCap.Buffer)
print "Getting HW Sync"
print >> deb_obj.Always(), "Getting HW Sync"
hw_sync = hw_inter.getHwCtrlObj(lima.HwCap.Sync)
print "Getting HW Bin"
print >> deb_obj.Always(), "Getting HW Bin"
hw_bin = hw_inter.getHwCtrlObj(lima.HwCap.Bin)
print "Getting HW RoI"
print >> deb_obj.Always(), "Getting HW RoI"
hw_roi = hw_inter.getHwCtrlObj(lima.HwCap.Roi)
mis_cb = MaxImageSizeCallback()
hw_det_info.registerMaxImageSizeCallback(mis_cb);
print "Setting FTM";
print >> deb_obj.Always(), "Setting FTM";
cam.setFrameTransferMode(lima.Frelon.FTM)
print "Setting FFM";
print >> deb_obj.Always(), "Setting FFM";
cam.setFrameTransferMode(lima.Frelon.FFM)
soft_roi = lima.Roi()
acq_state = lima.AcqState()
print "Creating a TestFrameCallback"
print >> deb_obj.Always(), "Creating a TestFrameCallback"
cb = TestFrameCallback(hw_inter, soft_roi, buffer_save, acq_state)
do_reset = False
if do_reset:
print "Reseting hardware ..."
print >> deb_obj.Always(), "Reseting hardware ..."
hw_inter.reset(lima.HwInterface.HardReset)
print " Done!"
print >> deb_obj.Always(), " Done!"
size = hw_det_info.getMaxImageSize()
image_type = hw_det_info.getCurrImageType()
......@@ -198,18 +224,18 @@ def main(argv):
hw_sync.setExpTime(2)
hw_sync.setNbFrames(3)
print "Starting Acquisition"
print >> deb_obj.Always(), "Starting Acquisition"
acq_state.set(lima.AcqState.Acquiring)
hw_inter.startAcq()
print "Waiting acq finished..."
print >> deb_obj.Always(), "Waiting acq finished..."
acq_state.waitNot(lima.AcqState.Acquiring)
print "Acq finished!!"
print >> deb_obj.Always(), "Acq finished!!"
print "Stopping Acquisition"
print >> deb_obj.Always(), "Stopping Acquisition"
hw_inter.stopAcq()
print "This is the End..."
print >> deb_obj.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