Skip to content

Commit 1d57995

Browse files
committed
automatically log trigger thresholds/bounds
1 parent 79cfcba commit 1d57995

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

source/communication/message.py

+1
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ def get_subtype(self, subtype_char):
5151
"t": "task",
5252
"a": "api",
5353
"u": "user",
54+
"s": "trigger",
5455
},
5556
}[self][subtype_char]

source/pyControl/hardware.py

+30-2
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ def _run_start(self):
249249
# Start sampling timer, initialise threshold, aquire first sample.
250250
self.timer.init(freq=self.channel.sampling_rate)
251251
self.timer.callback(self._timer_ISR)
252+
for trigger in self.triggers:
253+
trigger.run_start()
252254
self._timer_ISR(0)
253255

254256
def _run_stop(self):
@@ -354,7 +356,7 @@ def __init__(self, threshold, rising_event=None, falling_event=None):
354356
raise ValueError("Either rising_event or falling_event or both must be specified.")
355357
self.rising_event = rising_event
356358
self.falling_event = falling_event
357-
self.set_threshold(threshold)
359+
self.threshold = threshold
358360
self.timestamp = 0
359361
self.crossing_direction = False
360362
assign_ID(self)
@@ -365,6 +367,9 @@ def _initialise(self):
365367
self.falling_event_ID = sm.events[self.falling_event] if self.falling_event in sm.events else False
366368
self.threshold_active = self.rising_event_ID or self.falling_event_ID
367369

370+
def run_start(self):
371+
self.set_threshold(self.threshold)
372+
368373
def _process_interrupt(self):
369374
# Put event generated by threshold crossing in event queue.
370375
if self.crossing_direction:
@@ -394,6 +399,15 @@ def set_threshold(self, threshold):
394399
self.threshold = threshold
395400
self.reset_above_threshold = True
396401

402+
fw.data_output_queue.put(
403+
fw.Datatuple(
404+
fw.current_time,
405+
fw.PRINT_TYP,
406+
"s",
407+
"({}, {}) threshold = {}".format(self.rising_event, self.falling_event, self.threshold),
408+
)
409+
)
410+
397411

398412
class Crossing:
399413
above = "above"
@@ -420,12 +434,15 @@ class SchmittTrigger(IO_object):
420434
def __init__(self, bounds, rising_event=None, falling_event=None):
421435
if rising_event is None and falling_event is None:
422436
raise ValueError("Either rising_event or falling_event or both must be specified.")
423-
self.set_bounds(bounds)
424437
self.rising_event = rising_event
425438
self.falling_event = falling_event
439+
self.bounds = bounds
426440
self.timestamp = 0
427441
assign_ID(self)
428442

443+
def run_start(self):
444+
self.set_bounds(self.bounds)
445+
429446
def set_bounds(self, threshold):
430447
if isinstance(threshold, tuple):
431448
threshold_requirements_str = "The threshold must be a tuple of two integers (lower_bound, upper_bound) where lower_bound <= upper_bound."
@@ -444,6 +461,17 @@ def set_bounds(self, threshold):
444461
raise ValueError("{} is not a valid threshold. {}".format(threshold, threshold_requirements_str))
445462
self.reset_crossing = True
446463

464+
fw.data_output_queue.put(
465+
fw.Datatuple(
466+
fw.current_time,
467+
fw.PRINT_TYP,
468+
"s",
469+
"({}, {}) bounds = ({},{})".format(
470+
self.rising_event, self.falling_event, self.upper_threshold, self.lower_threshold
471+
),
472+
)
473+
)
474+
447475
def _initialise(self):
448476
# Set event codes for rising and falling events.
449477
self.rising_event_ID = sm.events[self.rising_event] if self.rising_event in sm.events else False

0 commit comments

Comments
 (0)