OptrisOptrisDocumentation

Documentation/OTC SDK/Overviewv12.0

Fail Safe

In Fahrenheit: with the SDK switched to Fahrenheit (SetTemperatureUnit() and its counterparts, see Temperatures in Fahrenheit), every temperature on this page is read and written in Fahrenheit, and every difference in Fahrenheit degrees; the samples are unchanged.

Overview

The fail-safe watchdog monitors the camera and the SDK processing pipeline. While all conditions pass it outputs a heartbeat signal on the configured PIF channels; when any condition fails the heartbeat stops. A PLC or other downstream system uses the signal to detect critical failures in the camera or the SDK application.

The watchdog is the heartbeat's only producer. It steps the line on a frame arriving from the camera, once the conditions below have passed. Nothing advances the line on a timer, and PifController::Poll() does not touch it.

Warning: 12.0.0 and 12.0.1 (2026-11-12) do not do this. The fix is in 12.0.2, and listed under Fixed in What Changed in Version 12. There the watchdog was never started and no condition was evaluated: PifController::Poll() advanced the output on its configured period for as long as the application kept calling Poll(), so the signal reported that the poll loop was running, not that the camera was healthy. Read that entry before trusting an installation wired from one of them.

Conditions

The SDK checks four conditions, in sync with incoming frames.

Condition Switch Default
Frames Arriving (none) always active, cannot be disabled
Processing Pipeline IRImagerConfig::failSafeProcessingChainTimeouts on
Flag Timeout IRImagerConfig::failSafeFlagTimeouts, with IRImagerConfig::failSafeFlagTimeoutsMaxCycleFailures for the tolerated count on, 0 tolerated failures, so the first failed cycle trips it
Client Interrupt DeviceControl::InterruptFailSafe() not asserted

Every IRImagerConfig switch above is reachable only from a legacy configuration file. None has a C++, C or .NET surface.

Frames Arriving

The check runs only when a frame arrives, so a camera going quiet stops the heartbeat with nothing to detect and no timeout to configure. An unplugged camera, a dropped USB or Ethernet link, a stalled stream and a wedged acquisition thread are one event: nothing arrives, nothing is checked, the line stops changing.

Frames are counted as the camera sends them, before any frame-rate subsampling, so an application taking every eighth frame still gets a heartbeat at the camera's rate.

Processing Pipeline

The SDK verifies that frames flow through the entire processing pipeline (radiometry, RDC, temperature conversion, measurement fields) within expected time bounds. A pipeline that accepts every frame and finishes none of them stops the heartbeat while the camera keeps sending.

Check interval Once every n frames the camera sends, n = floor(f × 0.1s) and never less than 1: about 100 ms above 10 Hz, once per frame at or below it.
Counted on Camera frames, not delivered ones, so subsampling does not slow the checks down.
Endpoints The thermal frame, plus one per measurement field, each timed separately. A region added mid-stream starts its timing fresh and cannot trip anything.
Suspended during A shutter (flag) calibration cycle, restarted afterwards. Nothing is dispatched while the shutter is closed, so otherwise a healthy camera would stop its own line once per calibration, several times an hour.
Not judged at all Until a frame rate is known. Every budget derives from the check interval, and before setFramerates() the only figure available is the 250 ms floor, shorter than one frame on any camera below 4 Hz (an Xi 410 over USB). Judging against it would trip the fail-safe permanently on a healthy slow camera.

The budget and the debounce

Each check measures the window from the previous check to the last endpoint that arrived before this one. The budget that window is judged against derives from the check interval and is then clamped:

Value Why
Per-endpoint budget 1.5 × t_check, clamped to 250–350 ms 250 ms is the interface's own edge budget: see How long a period the interface can carry.
Budget actually applied that, × the number of endpoints The endpoints run in sequence and share the chain, so each one's window legitimately contains the others'.
Trip after 3 consecutive late windows One is not a stall.

The endpoint count is one for the thermal frame plus one per measurement field. A camera with no measuring areas is judged at 250 ms; the same camera with three of them at 1000 ms. Version 11 judged endpoints on the same lenient sequential budget: setUseMultiThreading is never forwarded to the watchdog, and v11's ImageProcessing::setUseMultiThreading is commented out in its entirety.

t_check derives from the rate the camera delivers after subsampling, not the rate it captures at. On a subsampled camera that figure is longer than the real interval between checks, so it lands on the 350 ms ceiling rather than the 250 ms floor: more slack, never less.

A single late check does not stop the line. Measured on two cameras:

Run Samples Median p99 Worst
PI, 120 s 2625 frames 36.4 ms 42.8 ms 2116 ms
Xi 400, 90 s 2040 intervals 36.3 ms 43.4 ms 2155 ms

A healthy camera produces long windows regularly, and the worst of them is a shutter cycle. All seven Xi intervals over 150 ms straddled one, where these checks are suspended anyway; with those removed the worst interval in the whole run was 50.6 ms and p99.9 was 47.5 ms. That is why 250 ms is a safe floor.

At any rate from 20 fps up the per-endpoint budget is 250 ms, so on a camera with no measuring areas three consecutive late windows put the verdict within about 0.75 s of the stall starting, inside the relay's hold. Every measuring area lengthens that, by the multiplier above.

Note: Before v12 this was max(1.5 / fps, 150 ms): a flat 150 ms on every camera above 15 fps, a step where a 16 fps camera got more slack than a 14 fps one, and no debounce at all. 150 ms is less than two frame intervals on a 27 Hz camera, so one scheduler hiccup tripped it.

What is logged, and at what level

The processing-chain check logs no fault on a camera where no fail-safe is enabled. It still runs, so an application can read the state and arming a line need not wait for the watchdog to warm up, but the trip and the recovery drop to Debug.

On a camera that is driving a line:

Event Level
A late window, before the trip threshold Debug: always, armed or not
The trip itself Warning: the relay holds for about a second and has very likely not dropped yet
A trip still in force after that hold Error, once per trip
Recovery Info, with how long the trip lasted

The other two conditions are not gated on whether a line is armed:

Event Level
A client interrupt asserted (InterruptFailSafe(true, ...)) Error, with the reason
That interrupt released Info
Flag cycles past the tolerated count Error, naming the count and the tolerance
Flag cycles restored Info

Each is said once on the transition, not once per check. A camera with no PIF at all still produces an Error line for either of those two, because both describe something the application or the shutter did rather than something the wire is reading.

Flag Timeout

The mechanical shutter flag must cycle periodically for offset calibration. A cycle in which the shutter never reports itself closed is a failed cycle; enough consecutive failures stops the heartbeat, and one completed cycle resets the count.

A camera with a failing shutter goes on producing normal-looking frames that are no longer corrected: the offsets behind them are ageing, so the temperatures drift away from the truth with nothing in the image to say so.

Client Interrupt

The watchdog cannot watch your application. InterruptFailSafe() reports an application's own trouble to the same output: a stuck worker thread, a queue that stopped draining, a control loop that missed its deadline. It is on DeviceControl, reached through Imager::Device():

// Stop the heartbeat: the application knows it is in trouble.
imager->Device().InterruptFailSafe(true, "GUI thread crashed");

// Release the interrupt.
imager->Device().InterruptFailSafe(false, "GUI thread restored");

Releasing the interrupt does not by itself restart the heartbeat; the watchdog's own conditions still have to pass.

From the flat C ABI, optris_sdk_imager_interrupt_fail_safe(). From .NET, ThermalCamera.InterruptFailSafe(bool, string).

Configuring the line

PifController has three fail-safe methods: two configuration, one measurement.

Method Description
SetFailSafe(const PifFailSafeConfig &) Configure the fail-safe channel: enabled, index, signal, active_value, inactive_value, default_to_range_endpoints and the minimum interval period between edges. Returns nothing and throws PifException on a refusal.
GetFailSafe() The configuration currently in force.
GetFailSafeHealth() What the line is actually doing, measured. Returns PifFailSafeStatus by value. See Reading the line's health.

SetFailSafe() is the whole of the control surface: enabling, disabling and reconfiguring all go through PifFailSafeConfig. There is no separate enable, trigger or reset call.

Field Rules
index Read only for signal = kDigital or kAnalog, and checked against the hardware's channel count: a fail-safe on an output the PIF does not have throws PifException with code() PifError::kOutOfRange rather than being armed. Most PIF variants have no digital outputs at all, so read digital_output_count before choosing kDigital. Ignored for kFailSafe, which names the dedicated terminal pair and has no index.
signal kFailSafe on an interface whose has_fail_safe is false throws PifException with code() PifError::kUnsupported.
period The shortest interval between edges, not a timer that produces them: the watchdog offers a step on every passed check and skips one that would arrive sooner than period, so the camera's command channel is not saturated. Zero means "step on every passed check", the rate version 11 ran the line at, and is what the hardware group would rather an application asked for: the SDK knows the frame rate and the interface.
pif::PifFailSafeConfig fail_safe;
fail_safe.enabled = true;
fail_safe.signal = pif::PifSignal::kDigital;
fail_safe.index = 1;
fail_safe.period = std::chrono::milliseconds{100};
pif->SetFailSafe(fail_safe);

How long a period the interface can carry

The period is bounded by the interface, not by preference. Read the bound from PifHardwareInfo::fail_safe_max_period; SetFailSafe() throws PifException with code() PifError::kOutOfRange above it, naming the numbers in the message.

The relay is a retriggerable monoflop. The line retriggers it once per cycle (two edges) and it stays energised about 1.1 s afterwards (PifHardwareInfo::fail_safe_relay_hold), with the interface reporting a fault at about 1.5 s. So 2 × period has to fit inside the hold, and the arithmetic breaks down around 550 ms.

The accepted maximum is 250 ms, not 550, so that one missed cycle is still survivable. At 500 ms the relay is retriggered every 1.0 s against a 1.1 s hold, and one missed cycle (one long shutter cycle, one stalled transfer, one busy host) takes it to 2.0 s and releases the relay. At 250 ms a whole missed cycle is 1.0 s and the relay still holds.

The default is 100 ms, the cadence the hardware is designed around and the rate the SDK's own watchdog offers steps at.

Note: These numbers come from one measurement on one variant: an industrial current PIF on a PI 400, with a 24 V supply through a 10 k pull-up across the relay and an oscilloscope on the junction. They are reported as data on PifHardwareInfo so a second measurement moves one field rather than changing the API.

Reading the line's health

GetFailSafeHealth() reports what the line is doing, as opposed to what was configured:

FailSafeHealth Meaning
kDisabled No fail-safe is configured. Not a fault.
kArming Armed, and no heartbeat has arrived yet. The relay has not been retriggered, so a receiver is reading a fault, correctly, because the camera is not yet known to be delivering frames.
kBeating Edges are arriving inside the interface's budget. The relay is held.
kLate The line has not moved for longer than the relay can hold, or has not moved once since it was armed that long ago, or the camera reports that it cannot reach the Stackable PIF the line is on. The relay has released.

PifFailSafeStatus carries the numbers behind the verdict (since_last_edge, longest_gap, edge_budget, edges and a sticky was_ever_late) plus detail, the same answer in a sentence for a support report.

Read this rather than IoSnapshot::fail_safe_level, which is the instantaneous level of a line whose job is to alternate: it flickers between High and Low on a perfectly healthy system, so a UI using it as a health indicator shows noise.

kBeating is the only value that says the signal is reaching the interface. The SDK's heartbeat log line is about the watchdog: frames arriving, the pipeline finishing them, the shutter cycling, no client interrupt. All of those can be true while the line sits still and the relay releases; the health above is derived from the line itself.

No interface reports its relay back, so an edge is what the SDK sent and the camera accepted. On a Stackable PIF the camera does say, frame by frame, whether it can read the box: when it reports that it cannot, or when the box's input readings were arriving and stop, the health is kLate whatever was sent, and the log says why. A pulled PIF cable is the case this catches.

was_ever_late is sticky on purpose: an instantaneous reading taken after a recovery says everything is fine, and omits that the relay released and that whatever it was interlocking saw a fault.

Note: PifFailSafeConfig::on_alarm and on_flag_timeout are not implemented on any camera, and SetFailSafe() rejects a configuration that sets them by throwing PifException with code() PifError::kUnsupported, rather than accepting and ignoring them. For alarms, drive an ordinary digital or analog output from the alarm and keep the fail-safe line for camera and pipeline health. For shutter cycles there is no v12 replacement: the imager watches them through the legacy IRImagerConfig::failSafeFlagTimeouts.

Note: flag_cycles is inert (meaningful only alongside on_flag_timeout, which is refused, so it can never be reached) and is deliberately not refused on its own. It is part of the record every caller round-trips, and refusing a value merely read back from the camera and written again would reject a plain watchdog that requested no feature at all.

PIF Signals

The signal is an alternation, on every destination including the dedicated one. There is no "level" form of the fail-safe: a constant level is indistinguishable from the fault the line exists to report, and it is the edges that retrigger the relay. Wire a receiver to look for movement, never for a steady voltage.

PifFailSafeConfig::signal chooses one of three destinations, and each gets the same alternating level:

signal Where the level goes What alternates
kFailSafe the dedicated fail-safe terminals, which have no index the terminal's own two states, read back as IoSnapshot::fail_safe_level
kDigital digital output index high and low
kAnalog analog output index active_value and inactive_value, in the channel's own unit, or, when you set neither, the two ends of output_range

The analog default beats across the whole range

active_value and inactive_value default to 1.0 and 0.0, which are logic levels: correct on a digital line, where they are not used at all, and meaningless on an analog one, where a level is in the channel's output_range own unit: volts in 0-10 V, milliamperes in both current ranges, never amperes. In 4-20 mA both clamp to 4 mA and land on converter code 200, so the line could not move at all; in 0-20 mA they are codes 50 and 0, a 1 mA swing on a 20 mA span.

The two defaults are therefore the mark that no level was given, and default_to_range_endpoints (on by default) resolves them to output_range.max and output_range.min: 20 ↔ 4 mA, 20 ↔ 0 mA, 10 ↔ 0 V. That is the largest edge the channel can make, which is what a PLC or a relay module needs in order to see it. The hardware group's decision.

A level you set is driven exactly as set, flag or no flag. The flag governs the default and never overrides an instruction: set either level to anything other than the defaults and the pair is driven literally.

Two levels that land on one converter code are refused, by SetFailSafe() and by Configure(), the second because switching a channel's range after arming is how a line actually gets killed and SetFailSafe() alone cannot see it. The default can no longer produce that collision, so what the refusal catches now is a caller who sets two colliding levels explicitly, and a range change under a fail-safe that carries levels of its own. A fail-safe that sets no levels follows the new range instead.

GetFailSafe() answers what was written, never the resolved pair, so reading a configuration back and writing it again is idempotent and a later range change still moves the heartbeat with it.

A flag rather than a NaN sentinel because these floats round-trip through JSON, which writes a NaN as null and then throws reading it back, so a NaN mark would make a saved configuration unloadable. Across the C ABI the flag is optris_sdk_pif_fail_safe_config::default_to_range_endpoints, a byte taken from what was a two-byte reserved0, so sizeof is unchanged.

An analog or digital output carrying the heartbeat is driven even while SetOutputsBlocked(true) holds every other output at its inactive level: a heartbeat that stops when outputs are blocked reports a fault the camera does not have.

While all conditions pass, edges arrive at approximately the check interval, subject to the configured period. When any condition fails the stepping stops and the line flatlines wherever the last edge left it: the relay is no longer retriggered, coasts for about 1.1 s, and releases. Disarming with SetFailSafe({.enabled = false}) is the one case that does not flatline in place: the line is driven to its inactive level first, so a disabled fail-safe cannot be left sitting high where it would read as a healthy camera that has gone quiet. Moving the line to another destination parks the one it leaves the same way (a digital output's relay opens), and arming parks the new line first, so the first heartbeat is an edge.

On a digital output the edges are at least 100 ms apart, whatever period says: a digital output is a relay, and it changes a few times a second rather than at the frame rate.

System State Line (any destination)
OK, all conditions pass Alternating, an edge roughly every period
Error, any condition fails No edges; the level stops where it was
Disarmed by SetFailSafe() Parked at the inactive level

On a Stackable PIF

Two combinations are refused on a Stackable PIF, by SetFailSafe() and by Configure(), with PifError::kUnsupported and the reason in the message:

  • The dedicated line beside an analog output in Region of Interest or Internal Temperature. On an Xi 410 with a Stackable PIF (firmware 120) the host's per-frame analog writes moved the heartbeat off the fail-safe relay and onto the analog output, and the relay released. PIX Connect shows the same on that box. Nothing reads the relay back, so the SDK does not enter that state. A fail-safe on a digital output beside a Region of Interest output is accepted.
  • Frame Sync on an analog output. The box was measured to produce no pulse there.

Complete Example

#include <optrissdk.h>
#include <chrono>
#include <print>
#include <thread>

using namespace optris::sdk;

int main() {
  auto imager = Imager::Create();

  // Get the PIF controller.
  auto pif = imager->GetPif();
  if (!pif) {
    std::println("No PIF available on this device.");
    return 1;
  }

  // Put the heartbeat on the dedicated fail-safe terminals, at the
  // cadence the interface hardware is designed around. The dedicated
  // line has no index -- it is one terminal pair. Anything above
  // GetHardwareInfo().fail_safe_max_period is refused, not clamped.
  pif::PifFailSafeConfig fail_safe;
  fail_safe.enabled = true;
  fail_safe.signal = pif::PifSignal::kFailSafe;
  fail_safe.period = pif::kFailSafePeriodDefault;  // 100 ms
  try {
    pif->SetFailSafe(fail_safe);
  } catch (const pif::PifException &e) {
    std::println("Fail-safe not available: {}", e.what());
    return 1;
  }

  imager->Start();

  // Whether the line is keeping up is a separate question from
  // whether it was configured. Ask the line, not the configuration.
  const auto health = pif->GetFailSafeHealth();
  if (health.health != pif::FailSafeHealth::kBeating) {
    std::println("Fail-safe is not holding the relay: {}", health.detail);
  }

  // From here the line alternates on its own, driven by frames
  // arriving and the pipeline finishing them. Nothing in the
  // application has to keep it alive, and nothing in the application
  // can keep it alive once the camera stops.
  std::this_thread::sleep_for(std::chrono::seconds(5));

  // The application has its own trouble to report.
  imager->Device().InterruptFailSafe(true, "Application watchdog timeout");
  std::println("Fail-safe interrupted by client.");

  std::this_thread::sleep_for(std::chrono::seconds(2));
  imager->Device().InterruptFailSafe(false, "Application recovered");
  std::println("Fail-safe condition released.");

  std::this_thread::sleep_for(std::chrono::seconds(3));
  imager->Stop();

  return 0;
}