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
- Connection lifecycle
- USB
- Timeouts - How long before an open gives up - The seven open phases - Abandoning the wait does not stop the open - How long before a stream counts as stalled
- Whether the camera is calibrated
- What the SDK chose
- Complete example
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
- Enumerate:
EnumerateDevices()discovers available cameras. - Create:
Imager::Create(device)with aDeviceInfofrom enumeration, orImager::Create()for the first camera found. - Configure: set callbacks (
SetThermalCallback(),SetBgraCallback(), ...) and parameters. - Start:
Start()begins frame acquisition and processing. - Stream: frames arrive by callback, or are pulled with
AcquireFrame(). - 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); });
/* C: appended to the camera options, so the progress overload takes it. */ optris_sdk_camera_options options; optris_sdk_camera_options_init(&options, sizeof(options)); /* fills in 5000 and 3000 */ options.connect_timeout_ms = 2000; options.discovery_timeout_ms = 1000; optris_sdk_imager *imager = NULL; optris_sdk_status status = optris_sdk_imager_create_from_device_with_options_and_progress( &device, &options, on_phase, NULL, &imager); if (status == OPTRIS_SDK_ERROR_TIMEOUT) { /* Nothing answered: cable, subnet or firewall, not a wrong password. */ fprintf(stderr, "%s\n", optris_sdk_last_error_message()); }
// .NET: the same two values on CameraOptions. var options = new CameraOptions { ConnectTimeout = TimeSpan.FromSeconds(2), DiscoveryTimeout = TimeSpan.FromSeconds(1), }; try { await using var camera = await ThermalCamera.OpenAsync(device, options, phases, token); } catch (ConnectTimeoutException) { status.Text = $"Nothing answered at {device.Address}."; } catch (ThermalDeviceException error) { // Something was there and the open still failed. status.Text = error.Message; }
# Python: the same two values on CameraOptions, in seconds. options = optris_sdk.CameraOptions(connect_timeout_s=2.0, discovery_timeout_s=1.0) try: camera = optris_sdk.Camera.open(device, options=options, on_progress=show_phase) except optris_sdk.TimeoutError as e: # Nothing answered: cable, subnet or firewall, not a wrong password. print(e)
// Rust: the same two values on CameraOptions. let options = CameraOptions::new() .connect_timeout(Duration::from_secs(2))? .discovery_timeout(Duration::from_secs(1))?; match Camera::open_device_with_options_and_progress(&device, &options, show_phase) { Ok(camera) => run(camera), Err(e) if e.status() == Status::Timeout => { // Nothing answered: cable, subnet or firewall. eprintln!("{e}"); } Err(e) => eprintln!("{e}"), }
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);
/* How stale is the picture? This is the number that decides. */ uint32_t timeout_ms = 0; optris_sdk_imager_get_connection_timeout(imager, &timeout_ms); SetStaleAfter(ui, timeout_ms);
// How stale is the picture? This is the number that decides. TimeSpan timeout = camera.ConnectionTimeout; ui.SetStaleAfter(timeout);
# How stale is the picture? This is the number that decides. ui.set_stale_after(camera.connection_timeout_s)
// How stale is the picture? This is the number that decides. let timeout = camera.connection_timeout()?; ui.set_stale_after(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});
/* At open, for every camera this program opens: */ optris_sdk_camera_options options; optris_sdk_imager *camera = NULL; optris_sdk_camera_options_init(&options, sizeof(options)); options.connection_timeout_ms = 2000; optris_sdk_imager_create_with_options(&options, &camera); /* Or at any time afterwards: */ optris_sdk_imager_set_connection_timeout(camera, 1500);
// At open, for every camera this program opens: using ThermalCamera camera = ThermalCamera.Open(new CameraOptions { ConnectionTimeout = TimeSpan.FromSeconds(2), }); // Or at any time afterwards: camera.ConnectionTimeout = TimeSpan.FromMilliseconds(1500);
# At open, for every camera this program opens: options = optris_sdk.CameraOptions(connection_timeout_s=2.0) camera = optris_sdk.Camera.open(options=options) # Or at any time afterwards: camera.connection_timeout_s = 1.5
// At open, for every camera this program opens: let options = CameraOptions::new().connection_timeout(Duration::from_secs(2))?; let mut camera = Camera::open_with(&options)?; // Or at any time afterwards: camera.set_connection_timeout(Duration::from_millis(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()); }
optris_sdk_calibration_status status; char diagnosis[512]; optris_sdk_imager_get_calibration_status(imager, &status); if (status == OPTRIS_SDK_CALIBRATION_MISSING || status == OPTRIS_SDK_CALIBRATION_UNKNOWN) { /* Do not present these numbers as measurements. */ optris_sdk_imager_get_calibration_diagnosis(imager, diagnosis, sizeof(diagnosis), NULL); ShowMeasurementWarning(ui, diagnosis); }
if (camera.CalibrationStatus is CalibrationStatus.Missing or CalibrationStatus.Unknown) { // Do not present these numbers as measurements. ui.ShowMeasurementWarning(camera.CalibrationDiagnosis); }
if camera.calibration_status in (optris_sdk.CALIBRATION_MISSING, optris_sdk.CALIBRATION_UNKNOWN): # Do not present these numbers as measurements. ui.show_measurement_warning(camera.calibration_diagnosis)
if matches!( camera.calibration_status()?, CalibrationStatus::Missing | CalibrationStatus::Unknown ) { // Do not present these numbers as measurements. ui.show_measurement_warning(&camera.calibration_diagnosis()?); }
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); }
optris_sdk_pipeline_info info; optris_sdk_pipeline_info_init(&info, sizeof(info)); optris_sdk_imager_get_pipeline_info(imager, &info); /* For a support report: */ LogWrite(log, info.reason_text); LogWrite(log, info.streaming_backend); LogWrite(log, info.gpu_adapter); /* For the program to act on: */ if (info.reason == OPTRIS_SDK_PIPELINE_REASON_GPU_INIT_FAILED) { WarnAboutGpu(ui, info.reason_text); }
PipelineInfo info = camera.PipelineInfo; // For a support report: log.Write(info.ReasonText); log.Write(info.StreamingBackend); log.Write(info.GpuAdapter); // For the program to act on: if (info.Reason == PipelineReason.GpuInitFailed) { ui.WarnAboutGpu(info.ReasonText); }
info = camera.pipeline_info() # For a support report: log.write(info.reason_text) log.write(info.streaming_backend) log.write(info.gpu_adapter) # For the program to act on: if info.reason == optris_sdk.PIPELINE_REASON_GPU_INIT_FAILED: ui.warn_about_gpu(info.reason_text)
let info = camera.pipeline_info()?; // For a support report: log.write(&info.reason_text); log.write(&info.streaming_backend); log.write(&info.gpu_adapter); // For the program to act on: if info.reason == PipelineReason::GpuInitFailed { ui.warn_about_gpu(&info.reason_text); }
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 }
optris_sdk_gpu_info gpu; optris_sdk_gpu_info_init(&gpu, sizeof(gpu)); optris_sdk_get_gpu_info(&gpu); if (gpu.available) { SetGpuRow(ui, gpu.api, gpu.adapter); /* "Vulkan on NVIDIA RTX A1000" */ } else { SetGpuRowText(ui, gpu.unavailable_reason); /* never empty then */ }
SdkGpuInfo gpu = Sdk.GpuInfo; ui.SetGpuRow(gpu.Available ? $"{gpu.Api} on {gpu.Adapter}" // "Vulkan on NVIDIA RTX A1000" : gpu.UnavailableReason); // never empty when unavailable
gpu = optris_sdk.gpu_info() if gpu.available: ui.set_gpu_row(f"{gpu.api} on {gpu.adapter}") else: ui.set_gpu_row(gpu.unavailable_reason) # never empty when unavailable
let gpu = gpu_info()?; if gpu.available { ui.set_gpu_row(&format!("{} on {}", gpu.api, gpu.adapter)); } else { ui.set_gpu_row(&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; }
#include <stdio.h> #include "optris/sdk_c.h" /* Not the bool callback: 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. */ static void OTC_SDK_C_CALL OnStatus(optris_sdk_connection_status previous, optris_sdk_connection_status current, const char *message, void *user_data) { (void)user_data; printf("Connection: %d -> %d (%s)\n", (int)previous, (int)current, message); } static void OTC_SDK_C_CALL OnError(const char *message, void *user_data) { (void)user_data; printf("Error: %s\n", message); } static void OTC_SDK_C_CALL OnThermal(const optris_sdk_frame *f, void *user_data) { optris_sdk_frame_info info; (void)user_data; optris_sdk_frame_info_init(&info, sizeof(info)); /* Frames from before the startup calibration has finished arrive * too, and are not measurements. */ if (optris_sdk_frame_get_info(f, &info) == OPTRIS_SDK_OK && info.thermal_data_reliable) { printf("Frame: %ux%u max=%.1f C\n", info.width, info.height, (double)info.max_temp_c); } } int main(void) { optris_sdk_device_list *devices = NULL; optris_sdk_device_info device; optris_sdk_imager *camera = NULL; size_t count = 0; size_t i; /* Enumerate connected cameras. */ optris_sdk_enumerate_devices(NULL, &devices); optris_sdk_device_list_get_count(devices, &count); if (count == 0) { printf("No cameras found.\n"); optris_sdk_device_list_free(devices); return 1; } /* Print all found devices. */ for (i = 0; i < count; ++i) { optris_sdk_device_list_get(devices, i, &device); printf("%s (S/N %s)\n", device.model, device.serial); } /* Connect to the first camera. */ optris_sdk_device_list_get(devices, 0, &device); if (optris_sdk_imager_create_from_device(&device, &camera) != OPTRIS_SDK_OK) { fprintf(stderr, "%s\n", optris_sdk_last_error_message()); optris_sdk_device_list_free(devices); return 1; } optris_sdk_device_list_free(devices); optris_sdk_imager_set_connection_status_callback(camera, OnStatus, NULL); optris_sdk_imager_set_error_callback(camera, OnError, NULL); optris_sdk_imager_set_thermal_callback(camera, OnThermal, NULL); optris_sdk_imager_start(camera); getchar(); /* stream until Enter is pressed */ optris_sdk_imager_stop(camera); optris_sdk_imager_destroy(camera); return 0; }
using Optris.Sdk; // Enumerate connected cameras. IReadOnlyList<DeviceInfo> devices = Sdk.EnumerateDevices(); if (devices.Count == 0) { Console.WriteLine("No cameras found."); return; } // Print all found devices. foreach (DeviceInfo d in devices) { Console.WriteLine($"{d.Model} (S/N {d.Serial}) via {d.Connection}"); } // Connect to the first camera. await using ThermalCamera camera = ThermalCamera.Open(devices[0]); // Monitor the connection. The status pair tells a camera that is gone // from one that is open and no longer sending anything. camera.OnConnectionStatus(change => Console.WriteLine($"Connection: {change.Previous} -> {change.Current}")); camera.Start(); for (int i = 0; i < 100; i++) { using ThermalFrame frame = await camera.AcquireFrameAsync(TimeSpan.FromSeconds(2)); // Frames from before the startup calibration has finished // arrive too, and are not measurements. if (frame.Metadata.IsThermalDataReliable) { Console.WriteLine( $"Frame: {frame.Width}x{frame.Height} max={frame.MaxTemperature:F1} C"); } } camera.Stop();
import optris_sdk # Enumerate connected cameras. devices = optris_sdk.enumerate_devices() if not devices: raise SystemExit("No cameras found.") # Print all found devices. for d in devices: print(f"{d.model} (S/N {d.serial}) via " f"{optris_sdk.connection_name(d.connection)}") # Connect to the first camera. camera = optris_sdk.Camera.open(devices[0]) # Monitor the connection. The status pair tells a camera that is gone # from one that is open and no longer sending anything. camera.on_connection_status( lambda change: print(f"Connection: " f"{optris_sdk.connection_status_name(change.previous)}" f" -> " f"{optris_sdk.connection_status_name(change.current)}")) camera.on_error(lambda message: print(f"Error: {message}")) camera.start() for frame in camera.frames(100): # Frames from before the startup calibration has finished # arrive too, and are not measurements. if frame.thermal_data_reliable: print(f"Frame: {frame.width}x{frame.height} max={frame.max_c:.1f} C") camera.stop() camera.close()
use optris_sdk::{enumerate, Camera}; fn main() -> optris_sdk::Result<()> { // Enumerate connected cameras. let devices = enumerate()?; if devices.is_empty() { println!("No cameras found."); std::process::exit(1); } // Print all found devices. for d in &devices { println!("{} (S/N {}) via {:?}", d.model, d.serial, d.connection); } // Connect to the first camera. let mut camera = Camera::open_device(&devices[0])?; // Monitor the connection. The status pair tells a camera that is // gone from one that is open and no longer sending anything. camera.on_connection_status(|change| { println!("Connection: {:?} -> {:?}", change.previous, change.current); })?; camera.on_error(|message| println!("Error: {message}"))?; camera.on_thermal_frame(|frame| { // Frames from before the startup calibration has finished // arrive too, and are not measurements. if let Ok(info) = frame.info() { if info.thermal_data_reliable { println!("Frame: {}x{} max={:.1} C", info.width, info.height, info.max_temp_c); } } })?; camera.start()?; std::thread::sleep(std::time::Duration::from_secs(10)); camera.stop()?; Ok(()) }