...
 
Commits (16)
...@@ -795,6 +795,7 @@ class Serial: ...@@ -795,6 +795,7 @@ class Serial:
local_timeout = timeout or self._timeout local_timeout = timeout or self._timeout
return self._raw_handler.write(msg, local_timeout) return self._raw_handler.write(msg, local_timeout)
@try_open
def write_read(self, msg, write_synchro=None, size=1, timeout=None): def write_read(self, msg, write_synchro=None, size=1, timeout=None):
if isinstance(msg, str): if isinstance(msg, str):
raise TypeError("a bytes-like object is required, not 'str'") raise TypeError("a bytes-like object is required, not 'str'")
...@@ -804,6 +805,7 @@ class Serial: ...@@ -804,6 +805,7 @@ class Serial:
write_synchro.notify() write_synchro.notify()
return self._read(size, timeout) return self._read(size, timeout)
@try_open
def write_readline(self, msg, write_synchro=None, eol=None, timeout=None): def write_readline(self, msg, write_synchro=None, eol=None, timeout=None):
if isinstance(msg, str): if isinstance(msg, str):
raise TypeError("a bytes-like object is required, not 'str'") raise TypeError("a bytes-like object is required, not 'str'")
...@@ -813,6 +815,7 @@ class Serial: ...@@ -813,6 +815,7 @@ class Serial:
write_synchro.notify() write_synchro.notify()
return self._readline(eol, timeout) return self._readline(eol, timeout)
@try_open
def write_readlines( def write_readlines(
self, msg, nb_lines, write_synchro=None, eol=None, timeout=None self, msg, nb_lines, write_synchro=None, eol=None, timeout=None
): ):
......
...@@ -700,7 +700,9 @@ class PI_E712(Controller): ...@@ -700,7 +700,9 @@ class PI_E712(Controller):
else traj.events_positions else traj.events_positions
) )
for evt in events: for evt in events:
commmands.append("TWS 1 %d 1" % (round(evt["time"] / servo_cycle))) commmands.append(
"TWS 1 %d 1" % (int((evt["time"] // servo_cycle) + 1.5))
)
for cmd in commmands: for cmd in commmands:
self.command(cmd) self.command(cmd)
......
...@@ -43,8 +43,18 @@ config example: ...@@ -43,8 +43,18 @@ config example:
""" """
def _atomic_communication(fn):
def f(self, *args, **kwargs):
with self._cnx.lock:
return fn(self, *args, **kwargs)
return f
class PI_HEXA(Controller): class PI_HEXA(Controller):
COMMAND = enum.Enum("PI_HEXA.COMMAND", "POSITIONS MOVE_STATE MOVE_SEP INIT") COMMAND = enum.Enum(
"PI_HEXA.COMMAND", "POSITIONS MOVE_STATE MOVE_SEP INIT STOP_ERROR"
)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
Controller.__init__(self, *args, **kwargs) Controller.__init__(self, *args, **kwargs)
...@@ -93,12 +103,14 @@ class PI_HEXA(Controller): ...@@ -93,12 +103,14 @@ class PI_HEXA(Controller):
self.COMMAND.MOVE_STATE: ("\5", lambda x: int(x)), self.COMMAND.MOVE_STATE: ("\5", lambda x: int(x)),
self.COMMAND.MOVE_SEP: "", self.COMMAND.MOVE_SEP: "",
self.COMMAND.INIT: "INI X", self.COMMAND.INIT: "INI X",
self.COMMAND.STOP_ERROR: 2,
}, },
887: { 887: {
self.COMMAND.POSITIONS: "\3", self.COMMAND.POSITIONS: "\3",
self.COMMAND.MOVE_STATE: ("\5", lambda x: int(x, 16)), self.COMMAND.MOVE_STATE: ("\5", lambda x: int(x, 16)),
self.COMMAND.MOVE_SEP: " ", self.COMMAND.MOVE_SEP: " ",
self.COMMAND.INIT: "FRF X", self.COMMAND.INIT: "FRF X",
self.COMMAND.STOP_ERROR: 10,
}, },
} }
...@@ -114,6 +126,7 @@ class PI_HEXA(Controller): ...@@ -114,6 +126,7 @@ class PI_HEXA(Controller):
def read_position(self, axis): def read_position(self, axis):
return self._read_all_positions()[axis.channel] return self._read_all_positions()[axis.channel]
@_atomic_communication
def state(self, axis): def state(self, axis):
cmd, test_func = self._commands[self.COMMAND.MOVE_STATE] cmd, test_func = self._commands[self.COMMAND.MOVE_STATE]
moving_flag = test_func(self.command(cmd, 1)) moving_flag = test_func(self.command(cmd, 1))
...@@ -136,6 +149,7 @@ class PI_HEXA(Controller): ...@@ -136,6 +149,7 @@ class PI_HEXA(Controller):
def start_one(self, motion): def start_one(self, motion):
self.start_all(motion) self.start_all(motion)
@_atomic_communication
def start_all(self, *motions): def start_all(self, *motions):
sep = self._commands[self.COMMAND.MOVE_SEP] sep = self._commands[self.COMMAND.MOVE_SEP]
cmd = "MOV " + " ".join( cmd = "MOV " + " ".join(
...@@ -150,6 +164,7 @@ class PI_HEXA(Controller): ...@@ -150,6 +164,7 @@ class PI_HEXA(Controller):
def stop(self, axis): def stop(self, axis):
self.stop_all() self.stop_all()
@_atomic_communication
def stop_all(self, *motions): def stop_all(self, *motions):
self.command("STP") self.command("STP")
self._check_error_and_raise(ignore_stop=True) self._check_error_and_raise(ignore_stop=True)
...@@ -173,6 +188,7 @@ class PI_HEXA(Controller): ...@@ -173,6 +188,7 @@ class PI_HEXA(Controller):
else: else:
return self._cnx.write(cmd) return self._cnx.write(cmd)
@_atomic_communication
def home_search(self, axis, switch): def home_search(self, axis, switch):
init_cmd = self._commands[self.COMMAND.INIT] init_cmd = self._commands[self.COMMAND.INIT]
self.command(init_cmd) self.command(init_cmd)
...@@ -180,7 +196,13 @@ class PI_HEXA(Controller): ...@@ -180,7 +196,13 @@ class PI_HEXA(Controller):
def _read_all_positions(self): def _read_all_positions(self):
cmd = self._commands[self.COMMAND.POSITIONS] cmd = self._commands[self.COMMAND.POSITIONS]
try:
answer = self.command(cmd, nb_line=6) answer = self.command(cmd, nb_line=6)
except:
import traceback
traceback.print_exc()
raise
positions = dict() positions = dict()
try: try:
for channel_name, ans in zip(["%s=" % x for x in "XYZUVW"], answer): for channel_name, ans in zip(["%s=" % x for x in "XYZUVW"], answer):
...@@ -196,7 +218,9 @@ class PI_HEXA(Controller): ...@@ -196,7 +218,9 @@ class PI_HEXA(Controller):
def _check_error_and_raise(self, ignore_stop=False, **kwargs): def _check_error_and_raise(self, ignore_stop=False, **kwargs):
err = int(self.command("ERR?", **kwargs)) err = int(self.command("ERR?", **kwargs))
if err > 0: if err > 0:
if ignore_stop and err == 10: # stopped by user if (
ignore_stop and err == self._commands[self.COMMAND.STOP_ERROR]
): # stopped by user
return return
human_error = get_error_str(err) human_error = get_error_str(err)
errors = [self.name, err, human_error] errors = [self.name, err, human_error]
......
...@@ -417,6 +417,10 @@ class musst(object): ...@@ -417,6 +417,10 @@ class musst(object):
with remote_open(program_file) as program: with remote_open(program_file) as program:
program_bytes = program.read() program_bytes = program.read()
for old, new in template_replacement.items(): for old, new in template_replacement.items():
if isinstance(old, str):
old = old.encode()
if isinstance(new, str):
new = new.encode()
program_bytes = program_bytes.replace(old, new) program_bytes = program_bytes.replace(old, new)
self.upload_program(program_bytes) self.upload_program(program_bytes)
...@@ -426,6 +430,7 @@ class musst(object): ...@@ -426,6 +430,7 @@ class musst(object):
program_data -- program data you want to upload program_data -- program data you want to upload
""" """
if isinstance(program_data, str):
program_data = program_data.encode() program_data = program_data.encode()
m = hashlib.md5() m = hashlib.md5()
m.update(program_data) m.update(program_data)
...@@ -473,14 +478,14 @@ class musst(object): ...@@ -473,14 +478,14 @@ class musst(object):
current_offset = current_buffer_id * buffer_size + current_offset current_offset = current_buffer_id * buffer_size + current_offset
from_offset = (from_event_id * nb_counters) % buffer_memory from_offset = (from_event_id * nb_counters) % buffer_memory
current_offset = current_offset / nb_counters * nb_counters current_offset = current_offset // nb_counters * nb_counters
if current_offset >= from_offset: if current_offset >= from_offset:
nb_lines = (current_offset - from_offset) / nb_counters nb_lines = (current_offset - from_offset) // nb_counters
data = numpy.empty((nb_lines, nb_counters), dtype=numpy.int32) data = numpy.empty((nb_lines, nb_counters), dtype=numpy.int32)
self._read_data(from_offset, current_offset, data) self._read_data(from_offset, current_offset, data)
else: else:
nb_lines = current_offset / nb_counters nb_lines = current_offset // nb_counters
first_nblines = (buffer_memory - from_offset) / nb_counters first_nblines = (buffer_memory - from_offset) // nb_counters
nb_lines += first_nblines nb_lines += first_nblines
data = numpy.empty((nb_lines, nb_counters), dtype=numpy.int32) data = numpy.empty((nb_lines, nb_counters), dtype=numpy.int32)
self._read_data(from_offset, buffer_memory, data) self._read_data(from_offset, buffer_memory, data)
...@@ -502,7 +507,7 @@ class musst(object): ...@@ -502,7 +507,7 @@ class musst(object):
self._cnx.open() self._cnx.open()
with KillMask(): with KillMask():
self._cnx._write(b"?*EDAT %d %d %d" % (size_to_read, 0, offset)) self._cnx._write(b"?*EDAT %d %d %d" % (size_to_read, 0, offset))
raw_data = "" raw_data = b""
while len(raw_data) < (size_to_read * 4): while len(raw_data) < (size_to_read * 4):
raw_data += self._cnx.raw_read() raw_data += self._cnx.raw_read()
data_pt[ data_pt[
......
...@@ -240,8 +240,8 @@ class IntegratingCounterAcquisitionDevice(BaseCounterAcquisitionDevice): ...@@ -240,8 +240,8 @@ class IntegratingCounterAcquisitionDevice(BaseCounterAcquisitionDevice):
reader, reader,
count_time, count_time,
npoints=None, npoints=None,
prepare_once=None, prepare_once=keys.pop("prepare_once", None),
start_once=None, start_once=keys.pop("start_once", None),
**keys **keys
) )
for cnt in counters: for cnt in counters:
......
...@@ -191,6 +191,10 @@ class LimaAcquisitionMaster(AcquisitionMaster): ...@@ -191,6 +191,10 @@ class LimaAcquisitionMaster(AcquisitionMaster):
return True return True
def wait_ready(self): def wait_ready(self):
if self.device.camera_model.find("Basler") > -1:
return True
if self.device.camera_model.find("Eiger") > -1:
return True
if self._reading_task: if self._reading_task:
self._ready_event.wait() self._ready_event.wait()
......
...@@ -214,6 +214,7 @@ class _MusstAcquisitionDevice(AcquisitionDevice): ...@@ -214,6 +214,7 @@ class _MusstAcquisitionDevice(AcquisitionDevice):
def wait_ready(self): def wait_ready(self):
if isinstance(self.device, MusstAcquisitionMaster): if isinstance(self.device, MusstAcquisitionMaster):
self._master.wait_ready() self._master.wait_ready()
self.wait_reading()
def reading(self): def reading(self):
master = self._master master = self._master
......
...@@ -79,6 +79,7 @@ class BlissRepl(PythonRepl): ...@@ -79,6 +79,7 @@ class BlissRepl(PythonRepl):
def stop_current_task(self, block=True, exception=gevent.GreenletExit): def stop_current_task(self, block=True, exception=gevent.GreenletExit):
current_task = self.current_task current_task = self.current_task
print("stop_current_task", current_task, block, exception)
if current_task is not None: if current_task is not None:
current_task.kill(block=block, exception=exception) current_task.kill(block=block, exception=exception)
...@@ -225,6 +226,7 @@ def embed(*args, **kwargs): ...@@ -225,6 +226,7 @@ def embed(*args, **kwargs):
if stop_signals: if stop_signals:
def stop_current_task(signum, frame, exception=gevent.GreenletExit): def stop_current_task(signum, frame, exception=gevent.GreenletExit):
print("stop_current_task", signum, frame, exception)
repl = cmd_line_i.python_input repl = cmd_line_i.python_input
repl.stop_current_task(block=False, exception=exception) repl.stop_current_task(block=False, exception=exception)
......