Commit 1a0f0c9c authored by Sebastien Petitdemange's avatar Sebastien Petitdemange
Browse files

scanning: manage read all method for counters

parent 58841c38
......@@ -10,6 +10,7 @@ import time
from gevent import event,sleep
from bliss.common.event import dispatcher
from ..chain import AcquisitionDevice,AcquisitionChannel
from bliss.common.measurement import CounterBase
class CounterAcqDevice(AcquisitionDevice):
def __init__(self,counter,
......@@ -24,13 +25,17 @@ class CounterAcqDevice(AcquisitionDevice):
start_once=start_once,
**keys)
self._count_time = count_time
self.channels.append(AcquisitionChannel(counter.name,numpy.double, (1,)))
if not isinstance(counter,CounterBase.ReadAllHandler):
self.channels.append(AcquisitionChannel(counter.name,numpy.double, (1,)))
self._nb_acq_points = 0
self._event = event.Event()
self._stop_flag = False
self._ready_event = event.Event()
self._ready_flag = True
def add_counter_to_read(self,counter):
self.channels.append(AcquisitionChannel(counter.name,numpy.double, (1,)))
def prepare(self):
self._nb_acq_points = 0
self._stop_flag = False
......@@ -58,6 +63,15 @@ class CounterAcqDevice(AcquisitionDevice):
self._ready_event.clear()
def reading(self):
counter_name = [x.name for x in self.channels]
if isinstance(self.device,CounterBase.ReadAllHandler):
def read():
return numpy.array(self.device.read_all(*counter_name),
dtype=numpy.double)
else: # read_all
def read():
return numpy.array(self.device.read(),
dtype=numpy.double)
while self._nb_acq_points < self.npoints:
#trigger wait
self._event.wait()
......@@ -69,12 +83,12 @@ class CounterAcqDevice(AcquisitionDevice):
nb_read = 0
acc_read_time = 0
acc_value = 0
acc_value = numpy.zeros((len(counter_name),),dtype=numpy.double)
stop_time = trig_time + self._count_time or 0
#Counter integration loop
while not self._stop_flag:
start_read = time.time()
acc_value += self.device.read()
acc_value += read()
end_read = time.time()
nb_read += 1
acc_read_time += end_read - start_read
......@@ -85,11 +99,10 @@ class CounterAcqDevice(AcquisitionDevice):
sleep(0) # Be able to kill the task
self._nb_acq_points += 1
data = numpy.zeros((1,),dtype=numpy.double)
data[0] = acc_value / nb_read
data = acc_value / nb_read
channel_data = {name:data[index] for index,name in enumerate(counter_name)}
dispatcher.send("new_data",self,
{"channel_data": {self.name:data}})
{"channel_data": channel_data})
self._ready_flag = True
self._ready_event.set()
Supports Markdown
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