Rule
class optris_sdk.alarms.Rule
One signal, one condition, and what to do about it.
Owns an SDK handle until Camera.alarms.add takes it; use it
as a context manager, or let add consume it, which frees the
handle for you.
reference (added in 12.0.28) is the second signal of a rule that
compares two, the same as calling set_reference afterwards.
Rule — properties
inhibit_count
How many inhibit sources the rule has.
name
What this rule is called.
enabled
Whether the rule is evaluated.
input
The signal it watches, as a SignalId.
reference
The signal the input is compared with, as a SignalId,
or None when the rule compares its input alone.
condition
The band, the shaping and the latch; see Condition.
Reads through to the rule, so one obtained from
Alarms.get reports what the camera holds.
actions
Everything the rule does about a transition, in order.
The order is the one they were added in, which is the order
they run in and the order ActionError.action_index refers
to. Each is a RuleAction.
Rule — methods
set_name(name)
What this rule is called in an event and in a log.
set_input(signal)
Which signal it watches.
set_condition(condition)
When that signal counts as alarming.
set_reference(signal)
Compare the input with a second signal: a differential alarm.
With a reference, every band of the condition is tested against
the input minus the reference, so the limits are offsets.
"Region A's maximum more than 2 K above region B's maximum" is
COMPARE_ABOVE with high=2.0 and a reference naming B's
FIELD_MAX; "a spot within 5 K of a reference region either
way" is COMPARE_OUTSIDE with low=-5.0 and high=5.0.
Those offsets are temperature differences, so in Fahrenheit the
same two rules take high=3.6 and low=-9.0, high=9.0.
The warning band, hysteresis, delays, latching, inhibits and
actions apply to the difference unchanged, and
AlarmEvent.value carries the difference.
Either signal missing orphans the rule: it reports
ALARM_ORPHANED while the input or the reference is not being
produced (a region removed, a replay that does not carry it),
and resumes when both are back.
SignalId.region(field) means the rule's own region and is
resolved when the rule is added to a region; name another region
with the three-argument SignalId and the slot from
Camera.alarms.region_signal_slot(). A reference that is the
same signal as the input makes Camera.alarms.add() raise.
Setting one replaces any earlier one; clear_reference
removes it.
clear_reference()
Compare the input alone again.
For editing a rule read back with Camera.alarms.get().
Clearing a rule that has no reference is not an error.
set_enabled(enabled)
Switch the rule off without removing it.
A disabled rule reports ALARM_DISABLED, which an operator
interface should show differently from "suppressed right now"
(ALARM_INHIBITED) and from clear.
The counterpart of the enabled property, which could be
read before this existed and not written -- so a rule could be
built disabled only by not building it.
To silence a rule for the duration of a known disturbance, use
add_inhibit instead: an inhibit lifts itself and stays
visible as an inhibit, and it fails towards the alarm working.
add_inhibit(signal, condition, invert = False)
Hold the rule clear while another signal's condition holds.
How an operator silences alarms during a known disturbance
without disabling them. An inhibit source is just another
signal, so it can be a PIF input, a device reading or an
application value -- SignalId builds any of them.
An inhibited rule reports ALARM_INHIBITED rather than
clear, so the difference stays visible. If the suppressing
signal stops arriving the rule alarms: suppression fails
towards the alarm working, never towards silence.
- Parameter
invert— inhibit while the condition is not met.
clear_inhibits()
Remove every inhibit source.
For editing a rule read back from a camera with
Camera.alarms.get(), where the inhibits came with it.
clear_actions()
Remove every action.
For editing a rule read back from a camera with
Camera.alarms.get(), where the actions came with it. The
condition, the input and the name are left alone.
add_callback_action(slot, trigger = ON_ACTIVATE)
Call one registered handler when the rule fires.
slot is what
optris_sdk.alarms.Alarms.register_callback returned.
That method's own documentation has named this one since it was
written; until now there was nothing here to name.
Distinct from Camera.alarms.on_alarm(), which is told about
every transition and needs no action. Use this when one global
handler is not enough and a handler should fire only for the
rules that asked for it.
add_pif_output_action(channel, active_value, inactive_value = 0.0, digital = True, trigger = ON_ACTIVATE)
Drive a process-interface output while the alarm is active.
The relay half of an alarm: the SDK writes active_value
while the rule is active and inactive_value otherwise, so
the line follows the alarm without the application being in
the loop.
- Parameter
channel— the output channel's index. - Parameter
active_value— written while the alarm is active. For a digital output, non-zero is high. - Parameter
inactive_value— written otherwise. - Parameter
digital—Truefor a digital output,Falsefor analog.
add_snapshot_action(trigger = ON_ACTIVATE, format = SNAPSHOT_PNG, directory = None, name_pattern = None, min_interval_s = None, options = None)
Write a still image when the rule fires.
{rule}, {region}, {serial}, {model},
{sequence}, {timestamp} and {timestamp_us} expand
in name_pattern. One table, shared with interval capture:
{timestamp} is a local YYYYmmdd_HHMMSS date and
{sequence} is zero-padded to six digits. {timestamp_us}
is the raw microsecond stamp {timestamp} used to produce.
min_interval_s rate-limits it, which is not optional
politeness: an alarm chattering at the frame rate would
otherwise fill a disk.
None, the default, uses the SDK's own default of one
second. 0.0 switches the limit off, so every
activation writes a still, however fast they come. A
negative value is a mistake rather than a request and takes
the one-second default, not the unbounded rate.
That last sentence was once the other way round, and
this parameter's default was 0.0 -- so "no limit" could
not be asked for from Python at all, and the obvious spelling
of it silently gave one still a second. Every surface agrees
now: zero is no spacing, and the default is spelled by not
saying anything. A caller that passed 0.0 meaning "the
default" has to pass None or nothing.
**Two stills of one frame must not differ by who asked for
them.** Until this parameter existed an alarm still was
written with the defaults whatever the application had
chosen for its own stills, so a user who picked a 16-bit
TIFF because their tool cannot read float32 got alarm
stills that tool could not open.
- Parameter
options— aoptris_sdk.snapshot.SnapshotOptionssaying how to write the file -- the compression level, the 16-bit TIFF variant and the fixed Kelvin-per-count scale.Nonemeans the defaults.
add_recording_action(trigger = ON_ACTIVATE, mode = RECORDING_WHILE_ACTIVE, duration_s = 0, directory = None, name_pattern = None, options = None)
Start or stop a recording when the rule fires.
mode says what ends it:
RECORDING_WHILE_ACTIVE stops the recording this rule
started on its own clear, RECORDING_FIXED_DURATION
stops it after duration_s, and RECORDING_STOP stops
whatever is recording even if another rule started it. The
first two deliberately leave an operator's manual recording
alone.
name_pattern expands the same placeholders
add_snapshot_action documents.
**The segment limits are the reason this is not
cosmetic.** With `max_segment_bytes` unset a recording
never rolls over, so one onto a destination that caps a
single file fails at that cap instead of continuing in a new
part -- and an alarm recording is the one case where nobody
is watching when it happens. Set it to whatever the
destination holds.
`duration_s` on the options object is **ignored**:
`mode` and this method's own `duration_s` are the stop,
and a recording that stopped itself on the options field
would leave the SDK believing this rule still owned an open
recording.
- Parameter
options— aoptris_sdk.recording.RecordingOptionssaying how to write the recording -- the segment limits and the lossy settings.Nonemeans the defaults.
snapshot_options(index)
How the snapshot action at index writes its file.
A separate call rather than fields on RuleAction,
because optris_sdk.snapshot.SnapshotOptions is
versioned on its own and will grow -- nesting a growable struct
inside a growable one moves every offset after it. The answer
can be handed straight back to add_snapshot_action.
- Raises
~optris_sdk.errors.InvalidArgumentError— ifindexis past the end, or the action there is not a snapshot action. Refused rather than answered with the defaults, because all-defaults is exactly what a snapshot action using the defaults reads back as.
recording_options(index)
How the recording action at index writes its file.
The recording half of snapshot_options; see there for
why it is a call of its own.
duration_s always reads back None: the field is ignored
on an action, and reporting what was passed would describe a
stop that does not happen. The action's stop is its
recording_mode and duration_s.