Skip to content

Commit 2f4c1c7

Browse files
committed
fixup! Add emulator support
1 parent 415bea0 commit 2f4c1c7

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

pybpodapi/bpod/bpod_base.py

+23-8
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ def run_state_machine(self, sma):
295295
# create a list of executed states
296296
state_change_indexes = []
297297

298+
pause_task = False
298299
# flags used to stop a trial (or all trials)
299300
interrupt_task = False
300301
kill_task = False
@@ -306,7 +307,7 @@ def run_state_machine(self, sma):
306307
if self.stdin is not None:
307308
inline = self.stdin.readline()
308309
if inline is not None:
309-
interrupt_task, kill_task = self.handle_inline(inline, sma)
310+
pause_task, interrupt_task, kill_task = self.handle_inline(inline, sma)
310311
#####################################################
311312

312313
# read commands from a net socket ###################
@@ -315,8 +316,10 @@ def run_state_machine(self, sma):
315316

316317
if inline is not None:
317318
inline = inline.decode().strip()
318-
interrupt_task, kill_task = self.handle_inline(inline, sma)
319+
pause_task, interrupt_task, kill_task = self.handle_inline(inline, sma)
319320
#####################################################
321+
if pause_task:
322+
continue
320323

321324
opcode, data = None, None
322325
if self._emulator:
@@ -352,19 +355,31 @@ def run_state_machine(self, sma):
352355
return not interrupt_task
353356

354357
def handle_inline(self, inline, sma):
358+
pause_task = False
355359
interrupt_task = False
356360
kill_task = False
357361
if inline.startswith('pause-trial'):
358-
self.pause()
362+
if self._emulator is None:
363+
self.pause()
364+
else:
365+
pause_task = True
359366
elif inline.startswith('resume-trial'):
360-
self.resume()
367+
if self._emulator is None:
368+
self.resume()
369+
else:
370+
pause_task = False
361371
elif inline.startswith('stop-trial'):
362-
self.stop_trial()
372+
if self._emulator is None:
373+
self.stop_trial()
374+
else:
375+
interrupt_task = True
363376
elif inline.startswith('close'):
364-
self.stop_trial()
377+
if self._emulator is None:
378+
self.stop_trial()
365379
interrupt_task = True
366380
elif inline.startswith('kill'):
367-
self.stop_trial()
381+
if self._emulator is None:
382+
self.stop_trial()
368383
interrupt_task = kill_task = True
369384
elif inline.startswith('SoftCode'):
370385
softcode = int(inline[-1]) - 1
@@ -395,7 +410,7 @@ def handle_inline(self, inline, sma):
395410
final_msg.append(int(x))
396411
self.load_message(module_index, final_msg)
397412

398-
return interrupt_task, kill_task
413+
return pause_task, interrupt_task, kill_task
399414

400415
def load_serial_message(self, serial_channel, message_ID, serial_message):
401416
"""

0 commit comments

Comments
 (0)