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