OptrisOptrisDocumentation

Documentation/OTC SDK/Overviewv12.0

Device Communication

Opening a camera, the USB path, the two timeouts, and what the SDK decided for you while connecting.

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.

The device-communication chapter is three pages:

Page Question
Device Communication What does opening a camera involve, what does it do over USB, and how long does it wait?
Ethernet Cameras How do I reach one over the network, and set its address?
Dropped Connections It dropped out. What does the SDK do, and what do I have to do?

On this page

Overview

Two channels reach an Optris thermal camera:

  • Control: bidirectional, for commands and device status.
  • Streaming: unidirectional, for raw thermal data from the camera.

The data stream is uncompressed. Estimate bandwidth as width * height * 2 * framerate bytes per second, which matters when running several cameras on one host.

Connection lifecycle

  1. Enumerate: EnumerateDevices() discovers available cameras.
  2. Create: Imager::Create(device) with a DeviceInfo from enumeration, or Imager::Create() for the first camera found.
  3. Configure: set callbacks (SetThermalCallback(), SetBgraCallback(), ...) and parameters.
  4. Start: Start() begins frame acquisition and processing.
  5. Stream: frames arrive by callback, or are pulled with AcquireFrame().
  6. Stop: Stop() ends streaming.

The Imager destructor disconnects and releases every resource.

USB

Control

Control commands go over the Human Interface Device (HID) protocol. On Linux the SDK reaches that interface through libusb, claiming the camera's HID interface directly rather than through the kernel's hidraw driver. This is not selectable: the udev rule the SDK installs (90-otcsdk-hid-libusb.rules) keeps usbhid off that interface, which is what makes the claim possible and what lets a camera survive being unplugged and plugged back in. The build option for a hidraw backend was removed, because the kernel blocks hidraw on these cameras after a hotplug.

Streaming

USB cameras appear as USB video devices. The raw stream carries thermal data with metadata rows and columns that the SDK decodes internally.

Transfer mode Devices
Bulk Xi 80, Xi 320 MT, Xi 410, Xi 410 MT, Xi 640 ETH, Xi 1M
Isochronous every other device

That is the same list as the Ethernet one, and not by coincidence: the SDK asks one question for both, and on the current product line the cameras that offer Ethernet are exactly the ones that stream over USB bulk.

On Linux, isochronous devices use the V4L2 kernel driver. Bulk devices use the lower-level USB driver directly, because V4L2 does not support USB bulk transfers.

Timeouts

Two unrelated bounds share the word. The first bounds getting a camera open; the second bounds a camera that is already open and has gone quiet.

How long before an open gives up

Two bounds decide how long opening a network camera can take, and a failed open pays both, one after the other:

Option Default Covers Nothing answers
network.discovery_timeout 3 s asking the address who is there not fatal; the open goes on with the connection details already in hand
network.connect_timeout 5 s bringing the control channel up, retries included fatal

So an address nobody answers costs about eight seconds, not five. Shortening only one of them shortens a failed open by less than the arithmetic suggests.

Both are settable on the options every open takes, so an application showing "looking for the camera..." does not have to give up the bound in order to show it. They are also on ImagerConfig::network and optris_sdk_network_target.

// C++: on the configuration, as before.
ImagerConfig config;
config.network.connect_timeout = std::chrono::seconds{2};
config.network.discovery_timeout = std::chrono::seconds{1};

auto imager = Imager::Create(device, config, [](OpenPhase phase) {
  ui.ShowPhase(phase);
});

A timeout is not a refusal. An expired bound raises optris::sdk::ConnectTimeoutException in C++, returns OPTRIS_SDK_ERROR_TIMEOUT in C, and throws ConnectTimeoutException in .NET. A connection that was refused, meaning something is at that address and would not have you, stays DeviceException / OPTRIS_SDK_ERROR_DEVICE / ThermalDeviceException. The two need different things from an operator, and the message names the address and the limit either way. ConnectTimeoutException derives from the device exception in both languages, so code that only cares that the open failed needs no change.

Do not tune these down to make a slow site fail faster. An Ethernet camera on a loaded switch is not a broken camera. The defaults are comfortably above what a healthy open needs; a bound below that turns a slow network into an unusable one.

Nothing is left half open. When a bound expires the camera is not claimed, no handle is produced, and the next attempt starts from nothing. This is unlike cancelling an open through a CancellationToken, which stops you waiting but leaves the SDK finishing the open on its own thread; see ThermalCamera.OpenAsync.

Both bounds are ignored for a camera on USB, which has no connection to time out.

The seven open phases

Every open overload above takes a progress callback, called one phase at a time while the open runs. The seven phases are the same in all five surfaces:

Phase What is happening
Locating looking for the camera
CalibrationFromDevice reading calibration out of the camera itself
CalibrationFromDirectory copying it from the directory the caller named
CalibrationDownload fetching it from Optris
CalibrationReady calibration is in place
CalibrationMissing there is none, and the open is continuing anyway
Established connected
using var cancelling = new CancellationTokenSource();

var phases = new Progress<OpenPhase>(phase => status.Text = phase switch
{
    OpenPhase.Locating                 => "Looking for the camera...",
    OpenPhase.CalibrationFromDevice    => "Reading calibration from the camera...",
    OpenPhase.CalibrationFromDirectory => "Copying calibration...",
    OpenPhase.CalibrationDownload      => "Downloading calibration...",
    OpenPhase.CalibrationReady         => "Calibration ready",
    OpenPhase.CalibrationMissing       => "No calibration - readings will be invalid",
    OpenPhase.Established              => "Connected",
    _                                  => "Connecting...",
});

await using ThermalCamera camera =
    await ThermalCamera.OpenAsync(device, phases, cancelling.Token);

They are not steps to walk through. Every camera after its first open already has its calibration on disk and goes straight from Locating to Established; the calibration phases appear only when something is genuinely missing. On USB, Locating can arrive several times, because the SDK retries while USB enumeration settles. Treat a phase as "what is happening now", never as "step 3 of 6", and never build a progress bar out of the count.

CalibrationMissing is the one to handle rather than display and forget. It is a warning, not a failure: the open continues and hands back a working camera whose temperatures cannot be trusted. See Whether the camera is calibrated.

Abandoning the wait does not stop the open

The native open cannot be interrupted once it has begun: the connect path takes a lock on entry, releases it on return, and checks no flag in between. So a caller that gives up on the wait, by cancelling a token or by walking away from the call, abandons the wait and leaves the open running to completion on its own thread.

The cost is a window. Between abandoning the wait and the open actually finishing, the device is still claimed, so opening that same camera again inside the window fails as busy. Retry rather than report. The window is as long as the open had left to run: well under a second for a camera with calibration on disk, and potentially many seconds mid-download, which is why naming a calibration directory makes the window larger rather than smaller. Opening a different camera is unaffected.

// An operator who cancels and immediately retries the same camera
// can land inside that window. Retry rather than report.
try
{
    camera = await ThermalCamera.OpenAsync(device, phases, ct);
}
catch (ThermalDeviceException) when (retriedAfterCancel)
{
    await Task.Delay(TimeSpan.FromMilliseconds(500), ct);
    camera = await ThermalCamera.OpenAsync(device, phases, ct);
}

What happens to the camera that eventually finishes opening is the binding's business rather than the SDK's, and the answers differ: see The Optris SDK from C for .NET's.

How long before a stream counts as stalled

Stalled means "no frame for longer than the connection timeout". That timeout is not the SDK's: it comes from this camera's saved configuration on this machine, ten seconds from the factory but a per-machine file that may say anything. The same program watching the same camera model reports a stall after a different wait on a different PC, so an application that wants to tell a user how stale the picture is has to ask.

// How stale is the picture? This is the number that decides.
const auto timeout = imager->GetConnectionTimeout();
ui.SetStaleAfter(timeout);

Shortening it is the more useful half. It is the only control an application has over a camera that opens cleanly and then never delivers a frame: with the stock ten seconds, a program that reacts by re-opening waits ten seconds before it finds out it should.

// At open, for every camera this program opens:
ImagerConfig config;
config.connection_timeout = std::chrono::seconds{2};
auto imager = Imager::Create(config);

// Or at any time afterwards:
imager->SetConnectionTimeout(std::chrono::milliseconds{1500});

Nothing is written to disk: the saved file is the machine's setting, this is the application's, and it lasts as long as the imager does. It is finer than the file, which holds whole seconds; the frame path is polled every 50 ms, so anything above that is real. A zero or negative duration throws std::invalid_argument, because that is not a short wait but a stream that is stalled before it starts.

In .NET: ThermalCamera.ConnectionTimeout (get and set) and CameraOptions.ConnectionTimeout. In C: optris_sdk_imager_get_connection_timeout(), optris_sdk_imager_set_connection_timeout() and optris_sdk_camera_options::connection_timeout_ms.

Whether the camera is calibrated

A camera whose calibration files could not be found still opens, still streams, and still reports temperatures, and those temperatures are wrong. GetConnectionStatus() will not tell you: the link is perfectly healthy, and the link is all it reports.

if (!IsCalibrated(imager->GetCalibrationStatus())) {
  // Do not present these numbers as measurements.
  ui.ShowMeasurementWarning(imager->GetCalibrationDiagnosis());
}

Four answers, because they are not equivalent to whoever has to act on them:

CalibrationStatus Meaning
kUnknown Nobody has looked: not open, or a simulated or playback source
kCalibrated Every file was already on this machine
kAcquired Files were missing and were obtained, from the camera, a directory, or Optris. Fully calibrated; it needed a source to get there
kMissing Files could not be obtained. Streaming with wrong temperatures, every frame marked thermal_data_reliable false

GetCalibrationDiagnosis() is empty unless the status is kMissing, and then it names which source let this machine down: the directory named in ImagerConfig::calibration_path, the camera itself, or a download switched off by allow_calibration_download. On a factory PC behind a firewall that distinction is the whole of the problem.

A caller who set neither option still gets a source named. That case (no directory, download allowed, nothing reachable) is the most common one on a factory PC, and the report lists the sources the SDK tried on its own account: "the calibration files for camera 22042036 are not on this machine, and the camera itself and a download from Optris were tried without producing them." A machine with no route to the calibration service waits a bounded time rather than hanging: measured on a host whose packets to the service are dropped, the download gives up after 25 seconds and the open then continues; on one with no network configured at all, after 7 milliseconds.

The status is latched during the open and readable for as long as the imager lives, unlike the warning it replaces, which was one log line at open time.

In .NET: ThermalCamera.CalibrationStatus and ThermalCamera.CalibrationDiagnosis. In C: optris_sdk_imager_get_calibration_status() and optris_sdk_imager_get_calibration_diagnosis().

What the SDK chose

Three choices are made per camera as it opens: which pipeline computes its frames, which GPU adapter that pipeline runs on, and which streaming backend carries its data. All three are readable after the open returns.

const auto info = imager->Processing().Info();

// For a support report, unchanged:
log.Write(info.explanation);           // "CPU for a 4032-pixel frame (below 65536); ..."
log.Write(info.streaming_backend);     // "hal-v4l2"
log.Write(info.gpu_adapter);           // "NVIDIA RTX A1000", when on the GPU

// For the program to act on:
if (info.reason == PipelineReason::kGpuInitFailed) {
  // The one reason that is a fault rather than the SDK working as
  // designed: this machine was expected to compute on its GPU and is
  // not. Every other reason is a rule doing its job.
  ui.WarnAboutGpu(info.explanation);
}

Read it after the open returns, not from an open-progress callback: the pipeline is chosen twice during the open, once on frame size before the calibration has been read and again if that calibration turns out to need the CPU.

The reason comes in two forms on purpose. reason is a closed, stable enum an application can branch on; explanation is a sentence naming the actual numbers, for a person. Neither substitutes for the other: a string alone cannot be branched on without parsing English, and an enum alone throws away the specifics that make a support report actionable.

streaming_backend is what was actually built. streaming_backend_requested is non-empty only when the platform could not honour a request; "asked for hal-v4l2, got usb-bulk" is a supportable report and usb-bulk alone is not. streaming_backend_source says whether the name came from a default, OTC_STREAMING_BACKEND, or the saved configuration.

The GPU adapter is process-wide: the SDK keeps one shared GPU context for every camera, so it is the same adapter on every camera that has one. It is reported per camera because whether a camera has one is per camera. To ask the same question with no camera open, which is what an About box does:

const auto gpu = GetGpuInfo();
if (gpu.available) {
  ui.SetGpuRow(gpu.api + " on " + gpu.adapter);   // "Vulkan on NVIDIA RTX A1000"
} else {
  ui.SetGpuRow(gpu.unavailable_reason);           // never empty when unavailable
}

In .NET: ThermalCamera.PipelineInfo and Sdk.GpuInfo. In C: optris_sdk_imager_get_pipeline_info() and optris_sdk_get_gpu_info(), each with its _init companion.

Complete example

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

using namespace optris::sdk;

int main() {
  // Enumerate connected cameras.
  auto devices = EnumerateDevices();
  if (devices.empty()) {
    std::println("No cameras found.");
    return 1;
  }

  // Print all found devices.
  for (const auto& d : devices) {
    std::println("{} (S/N {}) via {}",
                 DeviceTypeToString(d.type),
                 d.serial,
                 ConnectionTypeToString(d.connection));
  }

  // Connect to the first camera.
  auto imager = Imager::Create(devices[0]);

  // Monitor the connection. Not SetConnectionCallback(): that one
  // reduces the whole story to a bool, and cannot tell a camera that
  // is gone from one that is open and no longer sending anything.
  imager->SetConnectionStatusCallback(
      [](const ConnectionStatusChange& change) {
        std::println("Connection: {} -> {}",
                     ToString(change.previous),
                     ToString(change.current));
      });

  imager->SetErrorCallback(
      [](const std::string& msg) {
        std::println("Error: {}", msg);
      });

  imager->SetThermalCallback(
      [](const ThermalFrame& f) {
        // Frames from before the startup calibration has finished
        // arrive too, and are not measurements.
        if (!f.GetMetadata().thermal_data_reliable) return;
        std::println("Frame: {}x{} max={:.1f} C",
                     f.GetWidth(), f.GetHeight(),
                     f.GetMaxTemperature());
      });

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

  return 0;
}